unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
blob 0c31a86146ba77828e34b2dde1727750bd067088 5595 bytes (raw)
name: test/lisp/gnus/mm-url-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
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
 
;;; mm-url-tests.el ---  -*- lexical-binding:t -*-

;; Copyright (C) 2021-2023 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 <https://www.gnu.org/licenses/>.

;;; Commentary:

;;; Code:

(require 'ert)
(require 'mm-url)


(ert-deftest test-mm-url--encode-multipart-form-file ()
  (should
   (equal
    (mm-url--encode-multipart-form-file '(("name"         . "a")
					  ("filename"     . "b")
					  ("filedata"     . "c\n")
					  ("content-type" . "d")))
    '("Content-Disposition: form-data; name=\"a\"; filename=\"b\""
      "Content-Type: d; charset=utf-8"
      "Content-Transfer-Encoding: binary"
      ""    ;; completely blank line to separate headers from content
      "c\n"))))

(ert-deftest test-mm-url--encode-multipart-form-name-value ()
  (should (equal (mm-url--encode-multipart-form-name-value "a" "b")
		 '("Content-Disposition: form-data; name=\"a\""
		   ""
		   "b"))))

(ert-deftest test-mm-url--encode-multipart-form-submit ()
  (should
   (equal (mm-url--encode-multipart-form-submit)
	  (list "Content-Disposition: form-data; name=\"submit\""
		""
		"Submit"))))

(ert-deftest test-mm-url--encode-multipart-form-datum ()
  (should
   (equal
    (mm-url--encode-multipart-form-datum "--BOUNDARY" '("submit"))
    '("--BOUNDARY"
      "Content-Disposition: form-data; name=\"submit\""
      ""
      "Submit"))))

(ert-deftest test-mm-url-encode-multipart-form-data-nil ()
  (should
   (string=
    (mm-url-encode-multipart-form-data '() "BOUNDARY")
    "--BOUNDARY--\r\n")))

(ert-deftest test-mm-url-encode-multipart-form-data--name-value ()
  (should
   (string=
    (mm-url-encode-multipart-form-data
     '(("name" . "value")) "BOUNDARY")
    (concat "--BOUNDARY\r\n"
	    "Content-Disposition: form-data; name=\"name\"\r\n"
	    "\r\n"
	    "value\r\n"
	    "--BOUNDARY--\r\n"))))

(ert-deftest test-mm-url-encode-multipart-form-data--submit ()
  (should
   (string=
    (mm-url-encode-multipart-form-data '(("submit")) "BOUNDARY")
    (concat "--BOUNDARY\r\n"
	    "Content-Disposition: form-data; name=\"submit\"\r\n"
	    "\r\n"
	    "Submit\r\n"
	    "--BOUNDARY--\r\n"))))

(ert-deftest test-mm-url-encode-multipart-form-data--file ()
  (should
   (string=
    (mm-url-encode-multipart-form-data
     '(("file" . (("name"         . "a")
		  ("filename"     . "b")
		  ("content-type" . "c")
		  ("filedata"     . "d\n"))))
     "BOUNDARY")
    (concat
     "--BOUNDARY\r\n"
     "Content-Disposition: form-data; name=\"a\"; filename=\"b\"\r\n"
     "Content-Type: c; charset=utf-8\r\n"
     "Content-Transfer-Encoding: binary\r\n"
     "\r\n"

     ;; file content
     "d\n"

     ;; rfc 2046 section 5
     ;; https://www.rfc-editor.org/rfc/rfc2046#section-5
     ;; "The boundary delimiter MUST occur at the beginning of a
     ;; line, i.e., following a CRLF, and the initial CRLF is
     ;; considered to be attached to the boundary delimiter line
     ;; rather than part of the preceding part."
     "\r\n"

     "--BOUNDARY--\r\n"))))

(ert-deftest test-mm-url-encode-multipart-form-data--all-parts ()
  (should
   (string=
    (mm-url-encode-multipart-form-data
     '(("name" . "value")
       ("submit")
       ("file" . (("name"         . "a")
		  ("filename"     . "b")
		  ("content-type" . "c")
		  ("filedata"     . "d"))))
     "BOUNDARY")
    (concat
     "--BOUNDARY\r\n"
     "Content-Disposition: form-data; name=\"name\"\r\n"
     "\r\n"
     "value\r\n"
     "--BOUNDARY\r\n"
     "Content-Disposition: form-data; name=\"submit\"\r\n"
     "\r\n"
     "Submit\r\n"
     "--BOUNDARY\r\n"
     "Content-Disposition: form-data; name=\"a\"; filename=\"b\"\r\n"
     "Content-Type: c; charset=utf-8\r\n"
     "Content-Transfer-Encoding: binary\r\n"
     "\r\n"

     ;; file content
     "d"

     ;; rfc 2046 section 5
     ;; the \r\n is attached to the boundary below it
     "\r\n"
     "--BOUNDARY--\r\n"))))

(ert-deftest test-mm-url-encode-multipart-form-data-two-files ()
  (should
   (string=
    (mm-url-encode-multipart-form-data
     '(("file" . (("name"         . "a")
		  ("filename"     . "b")
		  ("content-type" . "c")
		  ("filedata"     . "d\n")))
       ("file" . (("name"         . "e")
		  ("filename"     . "f")
		  ("content-type" . "g")
		  ("filedata"     . "h\n"))))
     "BOUNDARY")
    (concat
     "--BOUNDARY\r\n"
     "Content-Disposition: form-data; name=\"a\"; filename=\"b\"\r\n"
     "Content-Type: c; charset=utf-8\r\n"
     "Content-Transfer-Encoding: binary\r\n"
     "\r\n"

     ;; file content
     "d\n"

     ;; rfc2046 section 5
     ;; the \r\n is attached to the boundary below it
     "\r\n"
     "--BOUNDARY\r\n"
     "Content-Disposition: form-data; name=\"e\"; filename=\"f\"\r\n"
     "Content-Type: g; charset=utf-8\r\n"
     "Content-Transfer-Encoding: binary\r\n"
     "\r\n"

     ;; file content
     "h\n"

     ;; rfc 2046 section 5
     ;; the \r\n is attached to the boundary below it
     "\r\n"
     "--BOUNDARY--\r\n"))))


;;; mm-url-tests.el ends here

debug log:

solving 0c31a86146b ...
found 0c31a86146b in https://yhetil.org/emacs-bugs/CACT2Oni-ABRW4kUVLZgNqZa3_X04+60=wzefARWW0N3dQQqM3w@mail.gmail.com/

applying [1/1] https://yhetil.org/emacs-bugs/CACT2Oni-ABRW4kUVLZgNqZa3_X04+60=wzefARWW0N3dQQqM3w@mail.gmail.com/
diff --git a/test/lisp/gnus/mm-url-tests.el b/test/lisp/gnus/mm-url-tests.el
new file mode 100644
index 00000000000..0c31a86146b

Checking patch test/lisp/gnus/mm-url-tests.el...
Applied patch test/lisp/gnus/mm-url-tests.el cleanly.

index at:
100644 0c31a86146ba77828e34b2dde1727750bd067088	test/lisp/gnus/mm-url-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).