diff options
| author | Robert Pluim | 2022-07-25 12:17:07 +0200 |
|---|---|---|
| committer | Robert Pluim | 2022-07-26 14:16:07 +0200 |
| commit | fc1b7b720b5771a330f36e9a52688d73b790e478 (patch) | |
| tree | e76b4285a5ad8dc7ed744cd4280ef90fb8b1c622 /test/src | |
| parent | dfa16cadc18930fad76fa6113750eaa27d367e72 (diff) | |
| download | emacs-fc1b7b720b5771a330f36e9a52688d73b790e478.tar.gz emacs-fc1b7b720b5771a330f36e9a52688d73b790e478.zip | |
Teach 'network-lookup-address-info' to validate numeric addresses
* src/process.c (Fnetwork_lookup_address_info): Add optional 'hints'
argument, pass AI_NUMERICHOST to 'getaddrinfo' if it's 'numeric'.
(syms_of_process): Add 'numeric' symbol.
* doc/lispref/processes.texi (Misc Network): Expunge passive voice.
Update 'network-lookup-address-info' description.
* test/src/process-tests.el (lookup-hints-specification):
(lookup-hints-values): Test new functionality.
* etc/NEWS: Announce change.
Diffstat (limited to 'test/src')
| -rw-r--r-- | test/src/process-tests.el | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/test/src/process-tests.el b/test/src/process-tests.el index f1ed7e18d5b..aab95b2d733 100644 --- a/test/src/process-tests.el +++ b/test/src/process-tests.el | |||
| @@ -378,6 +378,58 @@ See Bug#30460." | |||
| 378 | (when (ipv6-is-available) | 378 | (when (ipv6-is-available) |
| 379 | (should (network-lookup-address-info "localhost" 'ipv6))))) | 379 | (should (network-lookup-address-info "localhost" 'ipv6))))) |
| 380 | 380 | ||
| 381 | (ert-deftest lookup-hints-specification () | ||
| 382 | "`network-lookup-address-info' should only accept valid hints arg." | ||
| 383 | (should-error (network-lookup-address-info "1.1.1.1" nil t)) | ||
| 384 | (should-error (network-lookup-address-info "1.1.1.1" 'ipv4 t)) | ||
| 385 | (should (network-lookup-address-info "1.1.1.1" nil 'numeric)) | ||
| 386 | (should (network-lookup-address-info "1.1.1.1" 'ipv4 'numeric)) | ||
| 387 | (when (ipv6-is-available) | ||
| 388 | (should-error (network-lookup-address-info "::1" nil t)) | ||
| 389 | (should-error (network-lookup-address-info "::1" 'ipv6 't)) | ||
| 390 | (should (network-lookup-address-info "::1" nil 'numeric)) | ||
| 391 | (should (network-lookup-address-info "::1" 'ipv6 'numeric)))) | ||
| 392 | |||
| 393 | (ert-deftest lookup-hints-values () | ||
| 394 | "`network-lookup-address-info' should succeed/fail in looking up various numeric IP addresses." | ||
| 395 | (let ((ipv4-invalid-addrs | ||
| 396 | '("localhost" "343.1.2.3" "1.2.3.4.5")) | ||
| 397 | ;; These are valid for IPv4 but invalid for IPv6 | ||
| 398 | (ipv4-addrs | ||
| 399 | '("127.0.0.1" "127.0.1" "127.1" "127" "1" "0" | ||
| 400 | "0xe3010203" "0xe3.1.2.3" "227.0x1.2.3" | ||
| 401 | "034300201003" "0343.1.2.3" "227.001.2.3")) | ||
| 402 | (ipv6-only-invalid-addrs | ||
| 403 | '("fe80:1" "e301:203:1" "e301::203::1" | ||
| 404 | "1:2:3:4:5:6:7:8:9" "0xe301:203::1" | ||
| 405 | "343:10001:2::3" | ||
| 406 | ;; "00343:1:2::3" is invalid on GNU/Linux and FreeBSD, but | ||
| 407 | ;; valid on macOS. macOS is wrong here, but such is life. | ||
| 408 | )) | ||
| 409 | ;; These are valid for IPv6 but invalid for IPv4 | ||
| 410 | (ipv6-addrs | ||
| 411 | '("fe80::1" "e301::203:1" "e301:203::1" | ||
| 412 | "e301:0203::1" "::1" "::0" | ||
| 413 | "0343:1:2::3" "343:001:2::3"))) | ||
| 414 | (dolist (a ipv4-invalid-addrs) | ||
| 415 | (should-not (network-lookup-address-info a nil 'numeric)) | ||
| 416 | (should-not (network-lookup-address-info a 'ipv4 'numeric))) | ||
| 417 | (dolist (a ipv6-addrs) | ||
| 418 | (should-not (network-lookup-address-info a 'ipv4 'numeric))) | ||
| 419 | (dolist (a ipv4-addrs) | ||
| 420 | (should (network-lookup-address-info a nil 'numeric)) | ||
| 421 | (should (network-lookup-address-info a 'ipv4 'numeric))) | ||
| 422 | (when (ipv6-is-available) | ||
| 423 | (dolist (a ipv4-addrs) | ||
| 424 | (should-not (network-lookup-address-info a 'ipv6 'numeric))) | ||
| 425 | (dolist (a ipv6-only-invalid-addrs) | ||
| 426 | (should-not (network-lookup-address-info a 'ipv6 'numeric))) | ||
| 427 | (dolist (a ipv6-addrs) | ||
| 428 | (should (network-lookup-address-info a nil 'numeric)) | ||
| 429 | (should (network-lookup-address-info a 'ipv6 'numeric)) | ||
| 430 | (should (network-lookup-address-info (upcase a) nil 'numeric)) | ||
| 431 | (should (network-lookup-address-info (upcase a) 'ipv6 'numeric)))))) | ||
| 432 | |||
| 381 | (ert-deftest lookup-unicode-domains () | 433 | (ert-deftest lookup-unicode-domains () |
| 382 | "Unicode domains should fail." | 434 | "Unicode domains should fail." |
| 383 | (skip-unless internet-is-working) | 435 | (skip-unless internet-is-working) |