aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorLars Ingebrigtsen2019-08-23 04:49:52 +0200
committerLars Ingebrigtsen2019-08-23 04:49:52 +0200
commit53cb3d3e0ddb666dc5b7774957ca863c668213cb (patch)
tree011cf32acf25b0cd86debf5b3c22be289e60bd87 /test
parentb4d3a882a8423e81c418fc56b7a9677f5582fcc7 (diff)
parent29d485fb768fbe375d60fd80cb2dbdbd90f3becc (diff)
downloademacs-53cb3d3e0ddb666dc5b7774957ca863c668213cb.tar.gz
emacs-53cb3d3e0ddb666dc5b7774957ca863c668213cb.zip
Merge remote-tracking branch 'origin/netsec'
Diffstat (limited to 'test')
-rw-r--r--test/lisp/net/nsm-tests.el69
-rw-r--r--test/src/process-tests.el29
2 files changed, 98 insertions, 0 deletions
diff --git a/test/lisp/net/nsm-tests.el b/test/lisp/net/nsm-tests.el
new file mode 100644
index 00000000000..bf6ac04b527
--- /dev/null
+++ b/test/lisp/net/nsm-tests.el
@@ -0,0 +1,69 @@
1;;; network-stream-tests.el --- tests for network security manager -*- lexical-binding: t; -*-
2
3;; Copyright (C) 2019 Free Software Foundation, Inc.
4
5;; Author: Robert Pluim <rpluim@gmail.com>
6
7;; This file is part of GNU Emacs.
8
9;; GNU Emacs is free software: you can redistribute it and/or modify
10;; it under the terms of the GNU General Public License as published by
11;; the Free Software Foundation, either version 3 of the License, or
12;; (at your option) any later version.
13
14;; GNU Emacs is distributed in the hope that it will be useful,
15;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17;; GNU General Public License for more details.
18
19;; You should have received a copy of the GNU General Public License
20;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
21
22;;; Commentary:
23
24
25;;; Code:
26
27(require 'nsm)
28(eval-when-compile (require 'cl-lib))
29
30(ert-deftest nsm-check-local-subnet-ipv4 ()
31 "Check that nsm can be avoided for local subnets."
32 (let ((local-ip '[172 26 128 160 0])
33 (mask '[255 255 255 0 0])
34
35 (wrong-length-mask '[255 255 255])
36 (wrong-mask '[255 255 255 255 0])
37 (remote-ip-yes '[172 26 128 161 0])
38 (remote-ip-no '[172 26 129 161 0]))
39
40 (should (eq t (nsm-network-same-subnet local-ip mask remote-ip-yes)))
41 (should (eq nil (nsm-network-same-subnet local-ip mask remote-ip-no)))
42 (should-error (nsm-network-same-subnet local-ip wrong-length-mask remote-ip-yes))
43 (should (eq nil (nsm-network-same-subnet local-ip wrong-mask remote-ip-yes)))
44 (should (eq t (nsm-should-check "google.com")))
45 (should (eq t (nsm-should-check "127.1")))
46 (should (eq t (nsm-should-check "localhost")))
47 (let ((nsm-trust-local-network t))
48 (should (eq t (nsm-should-check "google.com")))
49 (should (eq nil (nsm-should-check "127.1")))
50 (should (eq nil (nsm-should-check "localhost"))))))
51
52;; FIXME This will never return true, since
53;; network-interface-list only gives the primary address of each
54;; interface, which will be the IPv4 one
55(defun nsm-ipv6-is-available ()
56 (and (featurep 'make-network-process '(:family ipv6))
57 (cl-rassoc-if
58 (lambda (elt)
59 (eq 9 (length elt)))
60 (network-interface-list))))
61
62(ert-deftest nsm-check-local-subnet-ipv6 ()
63 (skip-unless (nsm-ipv6-is-available))
64 (should (eq t (nsm-should-check "::1")))
65 (let ((nsm-trust-local-network t))
66 (should (eq nil (nsm-should-check "::1")))))
67
68
69;;; nsm-tests.el ends here
diff --git a/test/src/process-tests.el b/test/src/process-tests.el
index 7745fccaf9d..724da1c3e72 100644
--- a/test/src/process-tests.el
+++ b/test/src/process-tests.el
@@ -22,6 +22,7 @@
22;;; Code: 22;;; Code:
23 23
24(require 'ert) 24(require 'ert)
25(require 'puny)
25 26
26;; Timeout in seconds; the test fails if the timeout is reached. 27;; Timeout in seconds; the test fails if the timeout is reached.
27(defvar process-test-sentinel-wait-timeout 2.0) 28(defvar process-test-sentinel-wait-timeout 2.0)
@@ -322,5 +323,33 @@ See Bug#30460."
322 invocation-directory)) 323 invocation-directory))
323 :stop t))) 324 :stop t)))
324 325
326(ert-deftest lookup-family-specification ()
327 "network-lookup-address-info should only accept valid family symbols."
328 (should-error (network-lookup-address-info "google.com" 'both))
329 (should (network-lookup-address-info "google.com" 'ipv4))
330 (should (network-lookup-address-info "google.com" 'ipv6)))
331
332(ert-deftest lookup-unicode-domains ()
333 "Unicode domains should fail"
334 (should-error (network-lookup-address-info "faß.de"))
335 (should (length (network-lookup-address-info (puny-encode-domain "faß.de")))))
336
337(ert-deftest unibyte-domain-name ()
338 "Unibyte domain names should work"
339 (should (length (network-lookup-address-info (string-to-unibyte "google.com")))))
340
341(ert-deftest lookup-google ()
342 "Check that we can look up google IP addresses"
343 (let ((addresses-both (network-lookup-address-info "google.com"))
344 (addresses-v4 (network-lookup-address-info "google.com" 'ipv4))
345 (addresses-v6 (network-lookup-address-info "google.com" 'ipv6)))
346 (should (length addresses-both))
347 (should (length addresses-v4))
348 (should (length addresses-v6))))
349
350(ert-deftest non-existent-lookup-failure ()
351 "Check that looking up non-existent domain returns nil"
352 (should (eq nil (network-lookup-address-info "emacs.invalid"))))
353
325(provide 'process-tests) 354(provide 'process-tests)
326;; process-tests.el ends here. 355;; process-tests.el ends here.