Skip to content
Newer
Older
100644 404 lines (378 sloc) 18.2 KB
59697b4 @ahyatt Initial checkin of files. These files were initially part of the
authored May 6, 2012
1 ;;; websocket-test.el --- Unit tests for the websocket layer
2
3 ;; Copyright (c) 2010 Andrew Hyatt
4 ;;
5 ;; Author: Andrew Hyatt <ahyatt at gmail dot com>
6 ;; Maintainer: Andrew Hyatt <ahyatt at gmail dot com>
7 ;;
8 ;; This program is free software; you can redistribute it and/or
9 ;; modify it under the terms of the GNU General Public License as
10 ;; published by the Free Software Foundation; either version 2 of the
11 ;; License, or (at your option) any later version.
12 ;;
13 ;; This program is distributed in the hope that it will be useful, but
14 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 ;; General Public License for more details.
17 ;;
18 ;; You should have received a copy of the GNU General Public License
19 ;; along with this program; if not, write to the Free Software
20 ;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 ;; 02110-1301, USA.
22
23 ;;; Commentary:
24 ;; This defines and runs ert unit tests. You can download ert from:
25 ;; http://github.com/ohler/ert, it also comes with Emacs 24 and above.
26
27 (require 'ert)
9d8794a @tkf Suppress compilation warning in websocket-test.el
tkf authored May 7, 2012
28 (require 'websocket)
29 (eval-when-compile (require 'cl))
59697b4 @ahyatt Initial checkin of files. These files were initially part of the
authored May 6, 2012
30
45245a4 @tkf Add test websocket-genbytes-length
tkf authored May 7, 2012
31 (ert-deftest websocket-genbytes-length ()
32 (loop repeat 100
82e85aa @ahyatt Fix test for websocket-genbytes
authored May 22, 2012
33 do (should (= (string-bytes (websocket-genbytes 16)) 16))))
45245a4 @tkf Add test websocket-genbytes-length
tkf authored May 6, 2012
34
b5bbce1 @ahyatt Add a function to calculate the accept header expected.
authored May 6, 2012
35 (ert-deftest websocket-calculate-accept ()
36 ;; This example comes straight from RFC 6455
37 (should
38 (equal "s3pPLMBiTxaQ9kYGzzhZRbK+xOo="
237b190 @ahyatt Various whitespace changes
authored May 24, 2012
39 (websocket-calculate-accept "dGhlIHNhbXBsZSBub25jZQ=="))))
b5bbce1 @ahyatt Add a function to calculate the accept header expected.
authored May 7, 2012
40
f4e1aa8 @ahyatt Add helper functions for websocket-get-opcode and
authored May 17, 2012
41 (defconst websocket-test-hello "\x81\x05\x48\x65\x6c\x6c\x6f"
42 "'Hello' string example, taken from the RFC.")
237b190 @ahyatt Various whitespace changes
authored May 25, 2012
43
4c8dbe2 @ahyatt Implement masking and unmasking.
authored May 19, 2012
44 (defconst websocket-test-masked-hello
45 "\x81\x85\x37\xfa\x21\x3d\x7f\x9f\x4d\x51\x58"
46 "'Hello' masked string example, taken from the RFC.")
f4e1aa8 @ahyatt Add helper functions for websocket-get-opcode and
authored May 17, 2012
47
39f1f28 @tkf Force test to pass in 32-bit Emacs
tkf authored Jul 9, 2012
48 (defconst websocket-test-64-bit-p
49 (calc-eval '("2^32 <= $") 'pred most-positive-fixnum))
50
b948e95 @ahyatt Fixed payload len logic, and rewrote the bit-grabbing bits to just
authored May 18, 2012
51 (ert-deftest websocket-get-bytes ()
52 (should (equal #x5 (websocket-get-bytes "\x5" 1)))
53 (should (equal #x101 (websocket-get-bytes "\x1\x1" 2)))
39f1f28 @tkf Force test to pass in 32-bit Emacs
tkf authored Jul 9, 2012
54 (let ((f (lambda () (websocket-get-bytes "\x0\x0\x0\x1\x0\x0\x0\x1" 8))))
55 (if websocket-test-64-bit-p
56 (should (equal #x100000001 (funcall f)))
57 (should-error (funcall f))))
b948e95 @ahyatt Fixed payload len logic, and rewrote the bit-grabbing bits to just
authored May 19, 2012
58 (should-error (websocket-get-bytes "\x0\x0\x0" 3))
59 (should-error (websocket-get-bytes "\x0" 2)))
60
f4e1aa8 @ahyatt Add helper functions for websocket-get-opcode and
authored May 17, 2012
61 (ert-deftest websocket-get-opcode ()
62 (should (equal 'text (websocket-get-opcode websocket-test-hello))))
63
64 (ert-deftest websocket-get-payload-len ()
b948e95 @ahyatt Fixed payload len logic, and rewrote the bit-grabbing bits to just
authored May 19, 2012
65 (should (equal '(5 . 1)
66 (websocket-get-payload-len
67 (substring websocket-test-hello 1))))
f4e1aa8 @ahyatt Add helper functions for websocket-get-opcode and
authored May 17, 2012
68 (should (equal '(200 . 3)
69 (websocket-get-payload-len
b948e95 @ahyatt Fixed payload len logic, and rewrote the bit-grabbing bits to just
authored May 19, 2012
70 (bindat-pack '((:len u8) (:val u16))
71 `((:len . 126)
f4e1aa8 @ahyatt Add helper functions for websocket-get-opcode and
authored May 17, 2012
72 (:val . 200))))))
73 ;; we don't want to hit up any limits even on strange emacs builds,
74 ;; so this test has a pretty small test value
75 (should (equal '(70000 . 9)
76 (websocket-get-payload-len
b948e95 @ahyatt Fixed payload len logic, and rewrote the bit-grabbing bits to just
authored May 19, 2012
77 (bindat-pack '((:len u8) (:val vec 2 u32))
78 `((:len . 127)
f4e1aa8 @ahyatt Add helper functions for websocket-get-opcode and
authored May 17, 2012
79 (:val . [0 70000])))))))
ae51a78 @ahyatt Code to read a frame. Does not yet support masking.
authored May 18, 2012
80
81 (ert-deftest websocket-read-frame ()
7900cda @ahyatt Return the length of the websocket frame from websocket-read-frame.
authored May 20, 2012
82 (should (equal (make-websocket-frame :opcode 'text :payload "Hello"
b0a2970 @ahyatt Add completep in frame
authored May 21, 2012
83 :length (length websocket-test-hello)
84 :completep t)
4c8dbe2 @ahyatt Implement masking and unmasking.
authored May 19, 2012
85 (websocket-read-frame websocket-test-hello)))
7900cda @ahyatt Return the length of the websocket frame from websocket-read-frame.
authored May 20, 2012
86 (should (equal (make-websocket-frame :opcode 'text :payload "Hello"
b0a2970 @ahyatt Add completep in frame
authored May 22, 2012
87 :length (length websocket-test-hello)
88 :completep t)
7900cda @ahyatt Return the length of the websocket frame from websocket-read-frame.
authored May 20, 2012
89 (websocket-read-frame (concat websocket-test-hello
90 "should-not-be-read"))))
91 (should (equal (make-websocket-frame :opcode 'text :payload "Hello"
b0a2970 @ahyatt Add completep in frame
authored May 22, 2012
92 :length (length websocket-test-masked-hello)
93 :completep t)
51b5764 @ahyatt Ensure the websocket frame is complete, and return NIL if not.
authored May 19, 2012
94 (websocket-read-frame websocket-test-masked-hello)))
b0a2970 @ahyatt Add completep in frame
authored May 22, 2012
95 (should (equal (make-websocket-frame :opcode 'text :payload "Hello"
96 :length (length websocket-test-hello)
97 :completep nil)
1081075 @ahyatt More whitespace changes
authored May 25, 2012
98 (websocket-read-frame
99 (concat (unibyte-string
100 (logand (string-to-char
101 (substring websocket-test-hello 0 1))
102 127))
103 (substring websocket-test-hello 1)))))
51b5764 @ahyatt Ensure the websocket frame is complete, and return NIL if not.
authored May 20, 2012
104 (dotimes (i (- (length websocket-test-hello) 1))
105 (should-not (websocket-read-frame
106 (substring websocket-test-hello 0
107 (- (length websocket-test-hello) (+ i 1))))))
108 (dotimes (i (- (length websocket-test-masked-hello) 1))
109 (should-not (websocket-read-frame
110 (substring websocket-test-masked-hello 0
111 (- (length websocket-test-masked-hello) (+ i 1)))))))
8da9119 @ahyatt Separate out the handshake verification logic, and test it. Look for
authored May 20, 2012
112
fb26aa7 @ahyatt Make the API more like W3C's API.
authored May 31, 2012
113 (defun websocket-test-header-with-lines (&rest lines)
114 (mapconcat 'identity (append lines '("\r\n")) "\r\n"))
8da9119 @ahyatt Separate out the handshake verification logic, and test it. Look for
authored May 20, 2012
115
6c42988 @ahyatt Check for HTTP 101 response code, and if there is any failure in the
authored Jun 2, 2012
116 (ert-deftest websocket-verify-response-code ()
117 (should (websocket-verify-response-code "HTTP/1.1 101"))
118 (should-error (websocket-verify-response-code "HTTP/1.1 400"))
119 (should-error (websocket-verify-response-code "HTTP/1.1 200")))
120
fb26aa7 @ahyatt Make the API more like W3C's API.
authored Jun 1, 2012
121 (ert-deftest websocket-verify-headers ()
122 (let ((accept "Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=")
123 (invalid-accept "Sec-WebSocket-Accept: bad")
124 (upgrade "Upgrade: websocket")
125 (connection "Connection: upgrade")
126 (ws (websocket-inner-create
127 :conn "fake-conn" :url "ws://foo/bar"
128 :accept-string "s3pPLMBiTxaQ9kYGzzhZRbK+xOo="))
129 (ws-with-protocol
130 (websocket-inner-create
131 :conn "fake-conn" :url "ws://foo/bar"
132 :accept-string "s3pPLMBiTxaQ9kYGzzhZRbK+xOo="
881c6ca @ahyatt Implement support for specifying extensions.
authored Jun 1, 2012
133 :protocol "myprotocol"))
134 (ws-with-extensions
135 (websocket-inner-create
136 :conn "fake-conn" :url "ws://foo/bar"
137 :accept-string "s3pPLMBiTxaQ9kYGzzhZRbK+xOo="
138 :extensions '("ext1" "ext2"))))
fb26aa7 @ahyatt Make the API more like W3C's API.
authored Jun 1, 2012
139 (should (websocket-verify-headers
140 ws
141 (websocket-test-header-with-lines accept upgrade connection)))
142 (should-error
143 (websocket-verify-headers
144 ws
145 (websocket-test-header-with-lines invalid-accept upgrade connection)))
146 (should-error (websocket-verify-headers
147 ws
148 (websocket-test-header-with-lines upgrade connection)))
149 (should-error (websocket-verify-headers
150 ws
151 (websocket-test-header-with-lines accept connection)))
152 (should-error (websocket-verify-headers
153 ws
154 (websocket-test-header-with-lines accept upgrade)))
155 (should-error (websocket-verify-headers
156 ws-with-protocol
157 (websocket-test-header-with-lines accept upgrade connection)))
158 (should-error
159 (websocket-verify-headers
160 ws-with-protocol
161 (websocket-test-header-with-lines accept upgrade connection
162 "Sec-Websocket-Protocol: foo")))
163 (should
164 (websocket-verify-headers
165 ws-with-protocol
166 (websocket-test-header-with-lines accept upgrade connection
881c6ca @ahyatt Implement support for specifying extensions.
authored Jun 2, 2012
167 "Sec-Websocket-Protocol: myprotocol")))
168 (should-error
169 (websocket-verify-headers
170 ws-with-extensions
171 (websocket-test-header-with-lines accept upgrade connection
172 "Sec-Websocket-Extensions: foo")))
173 (should
174 (websocket-verify-headers
175 ws-with-extensions
176 (websocket-test-header-with-lines
177 accept upgrade connection "Sec-Websocket-Extensions: ext1, ext2; a=1")))
178 (should (equal '("ext1" "ext2; a=1")
179 (websocket-server-extensions ws-with-extensions)))
180 (should
181 (websocket-verify-headers
182 ws-with-extensions
183 (websocket-test-header-with-lines accept upgrade connection
184 "Sec-Websocket-Extensions: ext1"
185 "Sec-Websocket-Extensions: ext2; a=1")))
186 (should (equal '("ext1" "ext2; a=1")
187 (websocket-server-extensions ws-with-extensions)))))
188
189 (ert-deftest websocket-create-headers ()
190 (let ((system-name "mysystem")
191 (base-headers (concat "Host: www.example.com\r\n"
192 "Upgrade: websocket\r\n"
193 "Connection: Upgrade\r\n"
194 "Sec-WebSocket-Key: key\r\n"
195 "Origin: mysystem\r\n"
196 "Sec-WebSocket-Version: 13\r\n")))
197 (should (equal (concat base-headers "\r\n")
198 (websocket-create-headers "ws://www.example.com/path"
199 "key" nil nil)))
200 (should (equal (concat base-headers
201 "Sec-WebSocket-Protocol: protocol\r\n\r\n")
202 (websocket-create-headers "ws://www.example.com/path"
203 "key" "protocol" nil)))
204 (should (equal
205 (concat base-headers
206 "Sec-WebSocket-Extensions: ext1; a; b=2, ext2\r\n\r\n")
207 (websocket-create-headers "ws://www.example.com/path"
208 "key" nil
209 '(("ext1" . ("a" "b=2"))
210 ("ext2")))))))
3a7798f @ahyatt Added frame processing, and more of the structure to use it.
authored May 20, 2012
211
212 (ert-deftest websocket-process-frame ()
213 (let* ((sent)
214 (processed)
215 (deleted)
fb26aa7 @ahyatt Make the API more like W3C's API.
authored Jun 1, 2012
216 (websocket (websocket-inner-create
217 :conn t :url t
218 :on-message (lambda (websocket frame)
219 (setq
220 processed
221 (websocket-frame-payload frame)))
222 :accept-string t)))
3a7798f @ahyatt Added frame processing, and more of the structure to use it.
authored May 21, 2012
223 (dolist (opcode '(text binary continuation))
224 (setq processed nil)
225 (should (equal
226 "hello"
227 (progn
14e94a4 @ahyatt Revamp how error processing works, increasing user control and
authored Jul 14, 2012
228 (funcall (websocket-process-frame
229 websocket
230 (make-websocket-frame :opcode opcode :payload "hello")))
3a7798f @ahyatt Added frame processing, and more of the structure to use it.
authored May 21, 2012
231 processed))))
232 (setq sent nil)
233 (flet ((websocket-send (websocket content) (setq sent content)))
234 (should (equal
7bc2aae @ahyatt Make websocket-send work on frames, and use it to send pongs.
authored May 21, 2012
235 (make-websocket-frame :opcode 'pong :completep t)
3a7798f @ahyatt Added frame processing, and more of the structure to use it.
authored May 21, 2012
236 (progn
14e94a4 @ahyatt Revamp how error processing works, increasing user control and
authored Jul 14, 2012
237 (funcall (websocket-process-frame websocket
238 (make-websocket-frame :opcode 'ping)))
3a7798f @ahyatt Added frame processing, and more of the structure to use it.
authored May 21, 2012
239 sent))))
240 (flet ((delete-process (conn) (setq deleted t)))
241 (should (progn
14e94a4 @ahyatt Revamp how error processing works, increasing user control and
authored Jul 14, 2012
242 (funcall
243 (websocket-process-frame websocket
244 (make-websocket-frame :opcode 'close)))
3a7798f @ahyatt Added frame processing, and more of the structure to use it.
authored May 21, 2012
245 deleted)))))
2148c5a @ahyatt Create the websocket-to-bytes function, to encode a number in a
authored May 21, 2012
246
14e94a4 @ahyatt Revamp how error processing works, increasing user control and
authored Jul 14, 2012
247 (ert-deftest websocket-process-frame-error-handling ()
248 (let* ((error-called)
249 (websocket (websocket-inner-create
250 :conn t :url t :accept-string t
251 :on-message (lambda (websocket frame)
252 (message "In on-message")
253 (error "err"))
254 :on-error (lambda (ws type err)
255 (should (eq 'on-message type))
256 (setq error-called t)))))
257 (funcall (websocket-process-frame websocket
258 (make-websocket-frame :opcode 'text
259 :payload "hello")))
260 (should error-called)))
261
2148c5a @ahyatt Create the websocket-to-bytes function, to encode a number in a
authored May 22, 2012
262 (ert-deftest websocket-to-bytes ()
263 ;; We've tested websocket-get-bytes by itself, now we can use it to
264 ;; help test websocket-to-bytes.
265 (should (equal 30 (websocket-get-bytes (websocket-to-bytes 30 1) 1)))
266 (should (equal 300 (websocket-get-bytes (websocket-to-bytes 300 2) 2)))
39f1f28 @tkf Force test to pass in 32-bit Emacs
tkf authored Jul 9, 2012
267 (let ((f (lambda () (websocket-to-bytes 70000 8))))
268 (if websocket-test-64-bit-p
269 (should (equal 70000 (websocket-get-bytes (funcall f) 8)))
270 (should-error (funcall f))))
2148c5a @ahyatt Create the websocket-to-bytes function, to encode a number in a
authored May 22, 2012
271 (should-error (websocket-to-bytes 30 3))
cf885f0 @ahyatt Fix issue on < 64-bit systems in packing an 8 byte value.
authored Jul 7, 2012
272 (should-error (websocket-to-bytes 300 1))
273 ;; I'd like to test the error for 32-byte systems on 8-byte lengths,
274 ;; but elisp does not allow us to temporarily set constants such as
275 ;; most-positive-fixnum.
276 )
2148c5a @ahyatt Create the websocket-to-bytes function, to encode a number in a
authored May 22, 2012
277
3596d84 @ahyatt Write and test websocket-encode-frame.
authored May 21, 2012
278 (ert-deftest websocket-encode-frame ()
279 ;; We've tested websocket-read-frame, now we can use that to help
280 ;; test websocket-encode-frame.
655cf1e @ahyatt Support outbound masking
authored May 22, 2012
281 (let ((websocket-mask-frames nil))
282 (should (equal
283 websocket-test-hello
284 (websocket-encode-frame
285 (make-websocket-frame :opcode 'text :payload "Hello" :completep t))))
39f1f28 @tkf Force test to pass in 32-bit Emacs
tkf authored Jul 9, 2012
286 (dolist (len (if websocket-test-64-bit-p '(200 70000) '(200 60000)))
237b190 @ahyatt Various whitespace changes
authored May 25, 2012
287 (let ((long-string (make-string len ?x)))
288 (should (equal long-string
289 (websocket-frame-payload
290 (websocket-read-frame
291 (websocket-encode-frame
1081075 @ahyatt More whitespace changes
authored May 26, 2012
292 (make-websocket-frame :opcode 'text
293 :payload long-string)))))))))
655cf1e @ahyatt Support outbound masking
authored May 23, 2012
294 (let ((websocket-mask-frames t))
295 (flet ((websocket-genbytes (n) (substring websocket-test-masked-hello 2 6)))
237b190 @ahyatt Various whitespace changes
authored May 25, 2012
296 (should (equal websocket-test-masked-hello
297 (websocket-encode-frame
1081075 @ahyatt More whitespace changes
authored May 26, 2012
298 (make-websocket-frame :opcode 'text :payload "Hello"
299 :completep t))))))
3596d84 @ahyatt Write and test websocket-encode-frame.
authored May 22, 2012
300 (should-not
301 (websocket-frame-completep
302 (websocket-read-frame
1081075 @ahyatt More whitespace changes
authored May 26, 2012
303 (websocket-encode-frame (make-websocket-frame :opcode 'text
304 :payload "Hello"
305 :completep nil)))))
0e04e15 @ahyatt Fix issue with encoding & decoding non-payload frames, and fix the
authored May 24, 2012
306 (dolist (opcode '(close ping pong))
3596d84 @ahyatt Write and test websocket-encode-frame.
authored May 22, 2012
307 (should (equal
308 opcode
309 (websocket-frame-opcode
310 (websocket-read-frame
0e04e15 @ahyatt Fix issue with encoding & decoding non-payload frames, and fix the
authored May 25, 2012
311 (websocket-encode-frame (make-websocket-frame :opcode opcode
312 :completep t))))))))
3596d84 @ahyatt Write and test websocket-encode-frame.
authored May 22, 2012
313
33ff92c @ahyatt Update websocket-close and test
authored May 25, 2012
314 (ert-deftest websocket-close ()
315 (let ((sent-frames))
316 (flet ((websocket-send (websocket frame) (push frame sent-frames))
317 (websocket-openp (websocket) t)
318 (kill-buffer (buffer))
319 (process-buffer (conn)))
fb26aa7 @ahyatt Make the API more like W3C's API.
authored Jun 1, 2012
320 (websocket-close (websocket-inner-create
321 :conn "fake-conn"
322 :url t
323 :accept-string t))
33ff92c @ahyatt Update websocket-close and test
authored May 26, 2012
324 (should (equal sent-frames (list
325 (make-websocket-frame :opcode 'close
326 :completep t)))))))
b89e002 @ahyatt Test for websocket-outer-filter, plus removing some useless code from…
authored May 25, 2012
327
328 (ert-deftest websocket-outer-filter ()
fb26aa7 @ahyatt Make the API more like W3C's API.
authored Jun 1, 2012
329 (let* ((fake-ws (websocket-inner-create
330 :conn t :url t :accept-string t
331 :on-open (lambda (websocket)
332 (should (eq (websocket-ready-state websocket)
333 'open))
334 (setq open-callback-called t)
14e94a4 @ahyatt Revamp how error processing works, increasing user control and
authored Jul 14, 2012
335 (error "Ignore me!"))
336 :on-error (lambda (ws type err))))
b89e002 @ahyatt Test for websocket-outer-filter, plus removing some useless code from…
authored May 26, 2012
337 (processed-frames)
338 (frame1 (make-websocket-frame :opcode 'text :payload "foo" :completep t
339 :length 9))
340 (frame2 (make-websocket-frame :opcode 'text :payload "bar" :completep t
341 :length 9))
078fbf3 @ahyatt Implemented onopen callback. Soon to be renamed.
authored May 29, 2012
342 (open-callback-called)
b89e002 @ahyatt Test for websocket-outer-filter, plus removing some useless code from…
authored May 26, 2012
343 (websocket-frames
344 (concat
345 (websocket-encode-frame frame1)
346 (websocket-encode-frame frame2))))
14e94a4 @ahyatt Revamp how error processing works, increasing user control and
authored Jul 14, 2012
347 (flet ((websocket-process-frame
348 (websocket frame)
349 (lexical-let ((frame frame))
350 (lambda () (push frame processed-frames))))
6c42988 @ahyatt Check for HTTP 101 response code, and if there is any failure in the
authored Jun 3, 2012
351 (websocket-verify-response-code (output) t)
fb26aa7 @ahyatt Make the API more like W3C's API.
authored Jun 1, 2012
352 (websocket-verify-headers (websocket output) t))
b89e002 @ahyatt Test for websocket-outer-filter, plus removing some useless code from…
authored May 26, 2012
353 (websocket-outer-filter fake-ws "Sec-")
fb26aa7 @ahyatt Make the API more like W3C's API.
authored Jun 1, 2012
354 (should (eq (websocket-ready-state fake-ws) 'connecting))
078fbf3 @ahyatt Implemented onopen callback. Soon to be renamed.
authored May 30, 2012
355 (should-not open-callback-called)
b89e002 @ahyatt Test for websocket-outer-filter, plus removing some useless code from…
authored May 26, 2012
356 (websocket-outer-filter fake-ws "WebSocket-Accept: acceptstring")
078fbf3 @ahyatt Implemented onopen callback. Soon to be renamed.
authored May 30, 2012
357 (should-not open-callback-called)
b89e002 @ahyatt Test for websocket-outer-filter, plus removing some useless code from…
authored May 26, 2012
358 (websocket-outer-filter fake-ws (concat
359 "\r\n\r\n"
360 (substring websocket-frames 0 2)))
078fbf3 @ahyatt Implemented onopen callback. Soon to be renamed.
authored May 30, 2012
361 (should open-callback-called)
b89e002 @ahyatt Test for websocket-outer-filter, plus removing some useless code from…
authored May 26, 2012
362 (websocket-outer-filter fake-ws (substring websocket-frames 2))
4040ae0 @jscheid Add test case for bugfix in 8513a7e.
jscheid authored Aug 5, 2012
363 (should (equal (list frame2 frame1) processed-frames)))
364 (flet ((websocket-ready-state (websocket) 'connecting)
365 (websocket-close (websocket)))
366 (should (equal "Bad HTTP response code while opening websocket connection: 500"
367 (car (cdr (should-error
368 (websocket-outer-filter fake-ws "HTTP/1.1 500\r\n\r\n")))))))))
6c42988 @ahyatt Check for HTTP 101 response code, and if there is any failure in the
authored Jun 3, 2012
369
370 (ert-deftest websocket-outer-filter-bad-connection ()
371 (let* ((on-open-calledp)
372 (websocket-closed-calledp)
373 (fake-ws (websocket-inner-create
374 :conn t :url t :accept-string t
375 :on-open (lambda (websocket)
376 (setq on-open-calledp t)))))
377 (flet ((websocket-verify-response-code (output) t)
378 (websocket-verify-headers (websocket output) (error "Bad headers!"))
379 (websocket-close (websocket) (setq websocket-closed-calledp t)))
380 (condition-case err
381 (progn (websocket-outer-filter fake-ws "HTTP/1.1 101\r\n\r\n")
382 (error "Should have thrown an error!"))
383 (error
384 (should-not on-open-calledp)
385 (should websocket-closed-calledp))))))
a5f1895 @ahyatt Re-apply the error handling, removed by accident during the merge.
authored May 26, 2012
386
d2e4272 @ahyatt Check frame validity, and test it as part of websocket-send
authored May 26, 2012
387 (ert-deftest websocket-send ()
fb26aa7 @ahyatt Make the API more like W3C's API.
authored Jun 1, 2012
388 (let ((ws (websocket-inner-create :conn t :url t :accept-string t)))
d2e4272 @ahyatt Check frame validity, and test it as part of websocket-send
authored May 27, 2012
389 (flet ((websocket-ensure-connected (websocket))
390 (websocket-openp (websocket) t)
391 (process-send-string (conn string)))
392 ;; Just make sure there is no error.
393 (websocket-send ws (make-websocket-frame :opcode 'ping
394 :completep t)))
395 (should-error (websocket-send ws
396 (make-websocket-frame :opcode 'text )))
397 (should-error (websocket-send ws
398 (make-websocket-frame :opcode 'close
399 :payload "bye!"
400 :completep t)))
401 (should-error (websocket-send ws
402 (make-websocket-frame :opcode :close)))))
403
Something went wrong with that request. Please try again.