unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
blob 94ba49ab487998ce1a3fe44f829d27acfc140b6f 4051 bytes (raw)
name: test/lisp/net/socks-tests.el 	 # note: path name is non-authoritative(*)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
 
;;; socks-tests.el --- tests for SOCKS -*- coding: utf-8; lexical-binding: t; -*-

;;; Commentary:

;; | (let ((default-directory (expand-file-name "../..")))
;; |   (compile "make lisp/net/socks-tests.log"))

;;; Code:

(require 'socks)
(require 'url-http)

;; This ran successfully against curl 7.71 with the following options:
;; $ curl --verbose -U foo:bar --proxy socks5h://127.0.0.1:10080 example.com
(defun socks-tests-fake-server ()
  (let* ((lines '(([5 2 0 2] . [5 2]) ; Emacs
                  ([5 3 0 1 2] . [5 2]) ; curl (+ gssapi)
                  ([1 3 #x66 #x6f #x6f 3 #x62 #x61 #x72] . [1 0])
                  ([5 1 0 3 11 ?e ?x ?a ?m ?p ?l ?e ?. ?c ?o ?m 0 80]
                   . [5 0 0 1 0 0 0 0 0 0])))
         (sentinel '(lambda (proc event)
                      (message "[%s]: %s" proc event)
                      (unless (string-match-p "^open" event)
                        (message "Quitting")
                        (kill-emacs 0))))
         (content (concat "HTTP/1.1 200 OK\r\n"
                          "Content-Type: text/plain; charset=UTF-8\r\n"
                          "Content-Length: 13\r\n\r\n"
                          "Hello World!\n"))
         (filter `(lambda (proc line)
                    (let* ((content ,content)
                           (resp (or (assoc-default (vconcat line) test-lines)
                                     (when (string-prefix-p "GET /" line)
                                       content))))
                      (message "-> %s" line)
                      (message "<- %s" resp)
                      (process-send-string proc (concat resp)))))
         (program `(progn
                     (defvar test-lines ',lines)
                     (let ((proc (make-network-process :server 1
                                                       :buffer (current-buffer)
                                                       :filter ,filter
                                                       :sentinel ,sentinel
                                                       :name "testnet"
                                                       :family 'ipv4
                                                       :coding 'raw-text
                                                       :host "127.0.0.1"
                                                       :service 10080)))
                       (message "[%s] Listening on 127.0.0.1:10080" proc)
                       (while (process-live-p proc)
                         (sleep-for 1)))))
         (buffer (generate-new-buffer "*fake-socks-server*"))
         (server (start-process "fake-socks-server" buffer
                                (concat invocation-directory invocation-name)
                                "-Q" "--batch" "--eval" (format "%S" program))))
    (set-process-query-on-exit-flag server nil)
    (with-current-buffer buffer
      (while (not (string-match-p "Listening" (buffer-string)))
        (sleep-for 0.1)))
    server))

(ert-deftest socks-tests-auth-filter-canned-e2e ()
  ;; 0.31 secs on my machine but marked as expensive because involves IO
  :tags '(:expensive-test)
  (let* ((socks-server `("fake-server" "127.0.0.1" 10080 5))
         (socks-username "foo")
         (socks-password "bar")
         (url-gateway-method 'socks)
         (url (url-generic-parse-url "http://example.com"))
         (server (socks-tests-fake-server))
         ;;
         done
         ;;
         (cb (lambda (&rest _r)
               (goto-char (point-min))
               (should (search-forward "Hello World" nil t))
               (message "Found: %S" (buffer-substring (line-beginning-position)
                                                      (line-end-position)))
               (setq done t))))
    (ignore url-gateway-method)
    (ert-info ("Connect to HTTP endpoint over SOCKS5 with USER/PASS method")
      (url-http url cb '(nil))
      (while (not done) (sleep-for 0.1)))
    (delete-process server)
    (kill-buffer (process-buffer server))))

;;; socks-tests.el ends here

debug log:

solving 94ba49ab487 ...
found 94ba49ab487 in https://yhetil.org/emacs-bugs/87pn2ht4pk.fsf_-_@neverwas.me/

applying [1/1] https://yhetil.org/emacs-bugs/87pn2ht4pk.fsf_-_@neverwas.me/
diff --git a/test/lisp/net/socks-tests.el b/test/lisp/net/socks-tests.el
new file mode 100644
index 00000000000..94ba49ab487

Checking patch test/lisp/net/socks-tests.el...
Applied patch test/lisp/net/socks-tests.el cleanly.

index at:
100644 94ba49ab487998ce1a3fe44f829d27acfc140b6f	test/lisp/net/socks-tests.el

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).