diff options
| author | Robert Pluim | 2019-08-07 14:07:07 +0200 |
|---|---|---|
| committer | Robert Pluim | 2019-08-07 14:07:07 +0200 |
| commit | bc1cf28da5532c6052eade7b5d19bb59e7e1f7bf (patch) | |
| tree | fbfebc7b64482a7836d46662645836dfecf02b07 /test | |
| parent | 76662cc47d0dd1482442914d0b1f5011f0c86c5e (diff) | |
| download | emacs-bc1cf28da5532c6052eade7b5d19bb59e7e1f7bf.tar.gz emacs-bc1cf28da5532c6052eade7b5d19bb59e7e1f7bf.zip | |
Change nsm-should-check to look at local subnets
* lisp/net/nsm.el (nsm-network-same-subnet): New function. Checks
if an ip address is in the same subnet as another one.
(nsm-should-check): Use nsm-network-same-subnet to see if we're
connecting to a local subnet machine. Remove checks for RFC1918 addresses.
* test/lisp/net/nsm-tests.el: New file. Test nsm-should-check functionality.
Diffstat (limited to 'test')
| -rw-r--r-- | test/lisp/net/nsm-tests.el | 69 |
1 files changed, 69 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 | ||