From 96018fe24dbab8c1f0dbf31c120a088f1998519f Mon Sep 17 00:00:00 2001 From: "F. Jason Park" Date: Fri, 5 Feb 2021 19:41:04 -0800 Subject: [PATCH 2/2] Preserve numeric addresses in socks-send-command * lisp/net/socks.el: (socks-send-command): * test/lisp/net/socks-tests.el: (socks-tests-v4-basic): --- lisp/net/socks.el | 2 +- test/lisp/net/socks-tests.el | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/lisp/net/socks.el b/lisp/net/socks.el index 96fafc826b8..019fadd1440 100644 --- a/lisp/net/socks.el +++ b/lisp/net/socks.el @@ -393,7 +393,7 @@ socks-send-command (let ((addr (cond ((or (= atype socks-address-type-v4) (= atype socks-address-type-v6)) - address) + (encode-coding-string address 'latin-1)) ((= atype socks-address-type-name) (format "%c%s" (length address) address)) (t diff --git a/test/lisp/net/socks-tests.el b/test/lisp/net/socks-tests.el index d2c21094e7f..7112f42a67c 100644 --- a/test/lisp/net/socks-tests.el +++ b/test/lisp/net/socks-tests.el @@ -183,6 +183,26 @@ socks-tests-perform-hello-world-http-request (kill-buffer buf) (ignore url-gateway-method))) +;; Unlike curl, socks.el includes the ID field (but otherwise matches): +;; $ curl --proxy socks4://127.0.0.1:1080 example.com + +(ert-deftest socks-tests-v4-basic () + "Show correct preparation of SOCKS4 connect command." + (let ((socks-server '("server" "127.0.0.1" 10079 4)) + (url-user-agent "Test/4-basic") + (socks-tests-canned-server-patterns + `(([4 1 0 80 93 184 216 34 ?f ?o ?o 0] . [0 90 0 0 0 0 0 0]) + ,socks-tests--hello-world-http-request-pattern)) + socks-nslookup-program) + (ert-info ("Make HTTP request over SOCKS4") + (cl-letf (((symbol-function 'socks-nslookup-host) + (lambda (host) + (should (equal host "example.com")) + (list 93 184 216 34))) + ((symbol-function 'user-full-name) + (lambda () "foo"))) + (socks-tests-perform-hello-world-http-request))))) + ;; Replace first pattern below with ([5 3 0 1 2] . [5 2]) to validate ;; against curl 7.71 with the following options: ;; $ curl --verbose -U foo:bar --proxy socks5h://127.0.0.1:10080 example.com -- 2.29.2