From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: "J.P." Newsgroups: gmane.emacs.bugs Subject: bug#45162: [PATCH] Fixup Re: bug#45162: 28.0.50; Messages scrambled by socks-filter Date: Sat, 09 Jan 2021 06:16:39 -0800 Message-ID: <87ft3a6vqw.fsf@neverwas.me> References: <87r1nxu840.fsf@neverwas.me> <87sg8c8ic5.fsf@gnus.org> <87pn2ht4pk.fsf_-_@neverwas.me> <87y2h4ykz8.fsf@gnus.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="28032"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) Cc: 45162@debbugs.gnu.org To: Lars Ingebrigtsen Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Jan 09 15:17:12 2021 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kyF3H-000738-Pl for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 09 Jan 2021 15:17:11 +0100 Original-Received: from localhost ([::1]:52906 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kyF3G-000719-RG for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 09 Jan 2021 09:17:10 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:39846) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kyF38-00070z-PP for bug-gnu-emacs@gnu.org; Sat, 09 Jan 2021 09:17:02 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:39835) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kyF38-0000xs-IB for bug-gnu-emacs@gnu.org; Sat, 09 Jan 2021 09:17:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1kyF38-0006VG-Ba for bug-gnu-emacs@gnu.org; Sat, 09 Jan 2021 09:17:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: "J.P." Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 09 Jan 2021 14:17:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 45162 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch fixed Original-Received: via spool by 45162-submit@debbugs.gnu.org id=B45162.161020180824973 (code B ref 45162); Sat, 09 Jan 2021 14:17:02 +0000 Original-Received: (at 45162) by debbugs.gnu.org; 9 Jan 2021 14:16:48 +0000 Original-Received: from localhost ([127.0.0.1]:51381 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kyF2u-0006Uj-AH for submit@debbugs.gnu.org; Sat, 09 Jan 2021 09:16:48 -0500 Original-Received: from mail-108-mta163.mxroute.com ([136.175.108.163]:36057) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kyF2s-0006Ub-Hv for 45162@debbugs.gnu.org; Sat, 09 Jan 2021 09:16:47 -0500 Original-Received: from filter003.mxroute.com ([168.235.111.26] 168-235-111-26.cloud.ramnode.com) (Authenticated sender: mN4UYu2MZsgR) by mail-108-mta163.mxroute.com (ZoneMTA) with ESMTPSA id 176e781a59d0007603.001 for <45162@debbugs.gnu.org> (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES128-GCM-SHA256); Sat, 09 Jan 2021 14:16:42 +0000 X-Zone-Loop: f23161b58a9120f49b1b8fbbc7f5ca4e0c71dedf46d2 X-Originating-IP: [168.235.111.26] Original-Received: from eagle.mxlogin.com (23-92-74-70.static.hvvc.us [23.92.74.70]) by filter003.mxroute.com (Postfix) with ESMTPS id 1AE3160061; Sat, 9 Jan 2021 14:16:41 +0000 (UTC) In-Reply-To: <87y2h4ykz8.fsf@gnus.org> (Lars Ingebrigtsen's message of "Thu, 07 Jan 2021 13:44:59 +0100") X-AuthUser: masked@neverwas.me X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:197548 Archived-At: --=-=-= Content-Type: text/plain Just got my paperwork sorted, yay! (Famous last words.) I've attempted to rework the test as suggested. It now runs in process instead of spawning another Emacs. I wasn't sure whether having url-http as a dependency made sense but left it as is. Happy to change whatever needs changing. Thanks again, J.P. --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-Create-new-test-file-for-socks.el.patch >From 9b89dcdc8702afaebff61708be4c5d6da90d1108 Mon Sep 17 00:00:00 2001 From: "F. Jason Park" Date: Sat, 9 Jan 2021 02:52:08 -0800 Subject: [PATCH] Create new test file for socks.el * test/lisp/net/socks-tests.el (socks-tests-auth-filter-url-http): Add SOCKS5 authentication test and fake server. Requires url-http. --- test/lisp/net/socks-tests.el | 103 +++++++++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 test/lisp/net/socks-tests.el diff --git a/test/lisp/net/socks-tests.el b/test/lisp/net/socks-tests.el new file mode 100644 index 00000000000..b378ed2964e --- /dev/null +++ b/test/lisp/net/socks-tests.el @@ -0,0 +1,103 @@ +;;; socks-tests.el --- tests for SOCKS -*- coding: utf-8; lexical-binding: t; -*- + +;; Copyright (C) 2021 Free Software Foundation, Inc. + +;; This file is part of GNU Emacs. + +;; GNU Emacs is free software: you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; GNU Emacs is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with GNU Emacs. If not, see . + +;;; Commentary: + +;;; Code: + +(require 'socks) +(require 'url-http) + +(defvar socks-tests-canned-server-port nil) + +(defun socks-tests-canned-server-create (verbatim patterns) + "Create a fake SOCKS server and return the process. + +`VERBATIM' and `PATTERNS' are dotted alists containing responses. +Requests are tried in order. On failure, an error is raised." + (let* ((buf (generate-new-buffer "*canned-socks-server*")) + (filt (lambda (proc line) + (let ((resp (or (assoc-default line verbatim + (lambda (k s) ; s is line + (string= (concat k) s))) + (assoc-default line patterns + (lambda (p s) + (string-match-p p s)))))) + (unless resp + (error "Unknown request: %s" line)) + (let ((print-escape-control-characters t)) + (princ (format "<- %s\n" (prin1-to-string line)) buf) + (princ (format "-> %s\n" (prin1-to-string resp)) buf)) + (process-send-string proc (concat resp))))) + (srv (make-network-process :server 1 + :buffer buf + :filter filt + :name "server" + :family 'ipv4 + :host 'local + :service socks-tests-canned-server-port))) + (set-process-query-on-exit-flag srv nil) + (princ (format "[%s] Listening on localhost:10080\n" srv) buf) + srv)) + +;; Add ([5 3 0 1 2] . [5 2]) to the `verbatim' list below to validate +;; against curl 7.71 with the following options: +;; $ curl --verbose -U foo:bar --proxy socks5h://127.0.0.1:10080 example.com +;; +;; If later implementing version 4a, try these: +;; [4 1 0 80 0 0 0 1 0 ?e ?x ?a ?m ?p ?l ?e ?. ?c ?o ?m 0] . [0 90 0 0 0 0 0 0] +;; $ curl --verbose --proxy socks4a://127.0.0.1:10080 example.com + +(ert-deftest socks-tests-auth-filter-url-http () + "Verify correct handling of SOCKS5 user/pass authentication." + (let* ((socks-server '("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")) + (verbatim '(([5 2 0 2] . [5 2]) + ([1 3 ?f ?o ?o 3 ?b ?a ?r] . [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]))) + (patterns + `(("^GET /" . ,(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")))) + (socks-tests-canned-server-port 10080) + (server (socks-tests-canned-server-create verbatim patterns)) + (tries 10) + ;; + done + ;; + (cb (lambda (&rest _r) + (goto-char (point-min)) + (should (search-forward "Hello World" nil t)) + (setq done t))) + (buf (url-http url cb '(nil)))) + (ert-info ("Connect to HTTP endpoint over SOCKS5 with USER/PASS method") + (while (and (not done) (< 0 (cl-decf tries))) ; cl-lib via url-http + (sleep-for 0.1))) + (should done) + (delete-process server) + (kill-buffer (process-buffer server)) + (kill-buffer buf) + (ignore url-gateway-method))) + +;;; socks-tests.el ends here -- 2.29.2 --=-=-=--