libwebsocket 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,122 +0,0 @@
1
- require 'test_helper'
2
-
3
- class TestRequest76 < Test::Unit::TestCase
4
-
5
- def test_parse
6
- req = LibWebSocket::Request.new
7
- assert !req.done?
8
- assert req.parse('')
9
- assert req.parse("GET /demo HTTP/1.1\x0d\x0a")
10
- assert_equal 'fields', req.state
11
-
12
- assert req.parse("Upgrade: WebSocket\x0d\x0a")
13
- assert_equal 'fields', req.state
14
- assert req.parse("Connection: Upgrade\x0d\x0a")
15
- assert_equal 'fields', req.state
16
- assert req.parse("Host: example.com\x0d\x0a")
17
- assert_equal 'fields', req.state
18
- assert req.parse("Origin: http://example.com\x0d\x0a")
19
- assert_equal 'fields', req.state
20
- assert req.parse(
21
- "Sec-WebSocket-Key1: 18x 6]8vM;54 *(5: { U1]8 z [ 8\x0d\x0a")
22
- assert req.parse(
23
- "Sec-WebSocket-Key2: 1_ tx7X d < nw 334J702) 7]o}` 0\x0d\x0a")
24
- assert_equal 'fields', req.state
25
- assert req.parse("\x0d\x0aTm[K T2u")
26
- assert_equal 'done', req.state
27
- assert_equal 155712099, req.number1
28
- assert_equal 173347027, req.number2
29
- assert_equal 'Tm[K T2u', req.challenge
30
-
31
- assert_equal 76, req.version
32
- assert_equal '/demo', req.resource_name
33
- assert_equal 'example.com', req.host
34
- assert_equal 'http://example.com', req.origin
35
- assert_equal 'fQJ,fN/4F4!~K~MH', req.checksum
36
- assert_equal 76, req.version
37
- assert_equal '/demo', req.resource_name
38
- assert_equal 'example.com', req.host
39
- assert_equal 'http://example.com', req.origin
40
- assert_equal 'fQJ,fN/4F4!~K~MH', req.checksum
41
-
42
- req = LibWebSocket::Request.new
43
- assert req.parse("GET /demo HTTP/1.1\x0d\x0a")
44
- assert req.parse("Upgrade: WebSocket\x0d\x0a")
45
- assert req.parse("Connection: Upgrade\x0d\x0a")
46
- assert req.parse("Host: example.com\x0d\x0a")
47
- assert req.parse("Origin: http://example.com\x0d\x0a")
48
- assert req.parse("Sec-WebSocket-Protocol: sample\x0d\x0a")
49
- assert req.parse(
50
- "Sec-WebSocket-Key1: 18x 6]8vM;54 *(5: { U1]8 z [ 8\x0d\x0a")
51
- assert req.parse(
52
- "Sec-WebSocket-Key2: 1_ tx7X d < nw 334J702) 7]o}` 0\x0d\x0a")
53
- assert req.parse("\x0d\x0aTm[K T2u")
54
- assert req.done?
55
- assert_equal 'sample', req.subprotocol
56
- end
57
-
58
- def test_checksum
59
- req = LibWebSocket::Request.new(
60
- :host => 'example.com',
61
- :resource_name => '/demo',
62
- :key1 => '18x 6]8vM;54 *(5: { U1]8 z [ 8',
63
- :key2 => '1_ tx7X d < nw 334J702) 7]o}` 0',
64
- :challenge => 'Tm[K T2u'
65
- )
66
- assert_equal req.to_s, "GET /demo HTTP/1.1\x0d\x0a" +
67
- "Upgrade: WebSocket\x0d\x0a" +
68
- "Connection: Upgrade\x0d\x0a" +
69
- "Host: example.com\x0d\x0a" +
70
- "Origin: http://example.com\x0d\x0a" +
71
- "Sec-WebSocket-Key1: 18x 6]8vM;54 *(5: { U1]8 z [ 8\x0d\x0a" +
72
- "Sec-WebSocket-Key2: 1_ tx7X d < nw 334J702) 7]o}` 0\x0d\x0a" +
73
- "Content-Length: 8\x0d\x0a" +
74
- "\x0d\x0a" +
75
- "Tm[K T2u"
76
- assert_equal "fQJ,fN/4F4!~K~MH", req.checksum
77
-
78
- req = LibWebSocket::Request.new(
79
- :host => 'example.com',
80
- :resource_name => '/demo',
81
- :subprotocol => 'sample',
82
- :key1 => '18x 6]8vM;54 *(5: { U1]8 z [ 8',
83
- :key2 => '1_ tx7X d < nw 334J702) 7]o}` 0',
84
- :challenge => 'Tm[K T2u'
85
- )
86
- assert_equal req.to_s, "GET /demo HTTP/1.1\x0d\x0a" +
87
- "Upgrade: WebSocket\x0d\x0a" +
88
- "Connection: Upgrade\x0d\x0a" +
89
- "Host: example.com\x0d\x0a" +
90
- "Origin: http://example.com\x0d\x0a" +
91
- "Sec-WebSocket-Protocol: sample\x0d\x0a" +
92
- "Sec-WebSocket-Key1: 18x 6]8vM;54 *(5: { U1]8 z [ 8\x0d\x0a" +
93
- "Sec-WebSocket-Key2: 1_ tx7X d < nw 334J702) 7]o}` 0\x0d\x0a" +
94
- "Content-Length: 8\x0d\x0a" +
95
- "\x0d\x0a" +
96
- "Tm[K T2u";
97
- assert_equal "fQJ,fN/4F4!~K~MH", req.checksum
98
-
99
- req = LibWebSocket::Request.new(
100
- :host => 'example.com',
101
- :resource_name => '/demo',
102
- :key1 => '55 997',
103
- :key2 => '3 3 64 98',
104
- :challenge => "\x00\x09\x68\x32\x00\x78\xc7\x10"
105
- )
106
- assert_equal req.checksum, "\xc4\x15\xc2\xc8\x29\x5c\x94\x8a\x95\xb9\x4d\xec\x5b\x1d\x33\xce"
107
- end
108
-
109
- def test_to_s
110
- req = LibWebSocket::Request.new(
111
- :host => 'example.com',
112
- :resource_name => '/demo'
113
- )
114
- req.to_s
115
- assert req.number1
116
- assert req.key1
117
- assert req.number2
118
- assert req.key2
119
- assert_equal 8, req.challenge.length
120
- assert_equal 16, req.checksum.length
121
- end
122
- end
@@ -1,26 +0,0 @@
1
- require 'test_helper'
2
-
3
- class TestRequestCommon < Test::Unit::TestCase
4
-
5
- def test_parse
6
- req = LibWebSocket::Request.new
7
- assert !req.done?
8
- assert_nil req.parse("foo\x0d\x0a")
9
- assert_equal 'error', req.state
10
- assert_equal 'Wrong request line', req.error
11
-
12
- req = LibWebSocket::Request.new
13
- assert req.parse("GET /demo HTTP/1.1\x0d\x0a")
14
- assert req.parse("Upgrade: WebSocket\x0d\x0a")
15
- assert req.parse("Connection: Upgrade\x0d\x0a")
16
- assert req.parse("Origin: http://example.com\x0d\x0a")
17
- assert_nil req.parse("\x0d\x0a")
18
- assert_equal 'error', req.state
19
-
20
- req = LibWebSocket::Request.new
21
- assert_nil req.parse('x' * (1024 * 10))
22
- assert_equal 'error', req.state
23
- assert_equal 'Message is too long', req.error
24
- end
25
-
26
- end
@@ -1,80 +0,0 @@
1
- require 'test_helper'
2
-
3
- class TestResponse75 < Test::Unit::TestCase
4
-
5
- def test_to_s
6
- res = LibWebSocket::Response.new
7
- res.version = 75
8
- res.host = 'example.com'
9
- assert_equal res.to_s, "HTTP/1.1 101 WebSocket Protocol Handshake\x0d\x0a" +
10
- "Upgrade: WebSocket\x0d\x0a" +
11
- "Connection: Upgrade\x0d\x0a" +
12
- "WebSocket-Origin: http://example.com\x0d\x0a" +
13
- "WebSocket-Location: ws://example.com/\x0d\x0a" +
14
- "\x0d\x0a"
15
-
16
- res = LibWebSocket::Response.new
17
- res.version = 75
18
- res.host = 'example.com'
19
- res.subprotocol = 'sample'
20
- assert_equal res.to_s, "HTTP/1.1 101 WebSocket Protocol Handshake\x0d\x0a" +
21
- "Upgrade: WebSocket\x0d\x0a" +
22
- "Connection: Upgrade\x0d\x0a" +
23
- "WebSocket-Protocol: sample\x0d\x0a" +
24
- "WebSocket-Origin: http://example.com\x0d\x0a" +
25
- "WebSocket-Location: ws://example.com/\x0d\x0a" +
26
- "\x0d\x0a";
27
-
28
- res = LibWebSocket::Response.new
29
- res.version = 75
30
- res.host = 'example.com'
31
- res.secure = true
32
- assert_equal res.to_s, "HTTP/1.1 101 WebSocket Protocol Handshake\x0d\x0a" +
33
- "Upgrade: WebSocket\x0d\x0a" +
34
- "Connection: Upgrade\x0d\x0a" +
35
- "WebSocket-Origin: http://example.com\x0d\x0a" +
36
- "WebSocket-Location: wss://example.com/\x0d\x0a" +
37
- "\x0d\x0a";
38
-
39
- res = LibWebSocket::Response.new
40
- res.version = 75
41
- res.host = 'example.com'
42
- res.resource_name = '/demo'
43
- res.origin = 'file://'
44
- res.cookie = {:name => 'foo', :value => 'bar', :path => '/'}
45
-
46
- assert_equal res.to_s, "HTTP/1.1 101 WebSocket Protocol Handshake\x0d\x0a" +
47
- "Upgrade: WebSocket\x0d\x0a" +
48
- "Connection: Upgrade\x0d\x0a" +
49
- "WebSocket-Origin: file://\x0d\x0a" +
50
- "WebSocket-Location: ws://example.com/demo\x0d\x0a" +
51
- "Set-Cookie: foo=bar; Path=/; Version=1\x0d\x0a" +
52
- "\x0d\x0a";
53
- end
54
-
55
- def test_parse
56
- res = LibWebSocket::Response.new
57
- res.parse("HTTP/1.1 101 WebSocket Protocol Handshake\x0d\x0a")
58
- res.parse("Upgrade: WebSocket\x0d\x0a")
59
- res.parse("Connection: Upgrade\x0d\x0a")
60
- res.parse("WebSocket-Protocol: sample\x0d\x0a")
61
- res.parse("WebSocket-Origin: file://\x0d\x0a")
62
- res.parse("WebSocket-Location: ws://example.com/demo\x0d\x0a")
63
- res.parse("\x0d\x0a\x00foo\xff")
64
- assert res.done?
65
- assert_equal 75, res.version
66
- assert_equal 'sample', res.subprotocol
67
-
68
- message = "HTTP/1.1 101 WebSocket Protocol Handshake\x0d\x0a" +
69
- "Upgrade: WebSocket\x0d\x0a" +
70
- "Connection: Upgrade\x0d\x0a" +
71
- "WebSocket-Origin: file://\x0d\x0a" +
72
- "WebSocket-Location: ws://example.com/demo\x0d\x0a" +
73
- "\x0d\x0a\x00foo\xff"
74
- res = LibWebSocket::Response.new
75
- assert res.parse(message)
76
- assert res.done?
77
- assert_equal 75, res.version
78
- end
79
-
80
- end
@@ -1,115 +0,0 @@
1
- require 'test_helper'
2
-
3
- class TestResponse76 < Test::Unit::TestCase
4
-
5
- def test_parse
6
- res = LibWebSocket::Response.new
7
- assert res.parse("HTTP/1.1 101 WebSocket Protocol Handshake\x0d\x0a")
8
- assert res.parse("Upgrade: WebSocket\x0d\x0a")
9
- assert res.parse("Connection: Upgrade\x0d\x0a")
10
- assert res.parse("Sec-WebSocket-Origin: file://\x0d\x0a")
11
- assert res.parse("Sec-WebSocket-Location: ws://example.com/demo\x0d\x0a")
12
- assert res.parse("\x0d\x0a")
13
- assert res.parse("0st3Rl&q-2ZU^weu")
14
- assert res.done?
15
- assert_equal '0st3Rl&q-2ZU^weu', res.checksum
16
- assert !res.secure
17
- assert_equal 'example.com', res.host
18
- assert_equal '/demo', res.resource_name
19
- assert_equal 'file://', res.origin
20
-
21
- res = LibWebSocket::Response.new
22
- assert res.parse("HTTP/1.1 101 WebSocket Protocol Handshake\x0d\x0a")
23
- assert res.parse("Upgrade: WebSocket\x0d\x0a")
24
- assert res.parse("Connection: Upgrade\x0d\x0a")
25
- assert res.parse("Sec-WebSocket-Protocol: sample\x0d\x0a")
26
- assert res.parse("Sec-WebSocket-Origin: file://\x0d\x0a")
27
- assert res.parse("Sec-WebSocket-Location: ws://example.com/demo\x0d\x0a")
28
- assert res.parse("\x0d\x0a")
29
- assert res.parse("0st3Rl&q-2ZU^weu")
30
- assert res.done?
31
- assert_equal 'sample', res.subprotocol
32
-
33
- res = LibWebSocket::Response.new
34
- message = "HTTP/1.1 101 WebSocket Protocol Handshake\x0d\x0a" +
35
- "Upgrade: WebSocket\x0d\x0a" +
36
- "Connection: Upgrade\x0d\x0a"
37
- assert res.parse(message)
38
- message = "Sec-WebSocket-Origin: file://\x0d\x0a" +
39
- "Sec-WebSocket-Location: ws://example.com/demo\x0d\x0a" +
40
- "\x0d\x0a" +
41
- "0st3Rl&q-2ZU^weu\x00foo\xff"
42
- assert res.parse(message)
43
- assert res.done?
44
- end
45
-
46
- def test_to_s
47
- res = LibWebSocket::Response.new(
48
- :host => 'example.com',
49
- :resource_name => '/demo',
50
- :origin => 'file://',
51
- :number1 => 777_007_543,
52
- :number2 => 114_997_259,
53
- :challenge => "\x47\x30\x22\x2D\x5A\x3F\x47\x58"
54
- )
55
- assert_equal res.to_s, "HTTP/1.1 101 WebSocket Protocol Handshake\x0d\x0a" +
56
- "Upgrade: WebSocket\x0d\x0a" +
57
- "Connection: Upgrade\x0d\x0a" +
58
- "Sec-WebSocket-Origin: file://\x0d\x0a" +
59
- "Sec-WebSocket-Location: ws://example.com/demo\x0d\x0a" +
60
- "\x0d\x0a" +
61
- "0st3Rl&q-2ZU^weu"
62
-
63
- res = LibWebSocket::Response.new(
64
- :host => 'example.com',
65
- :resource_name => '/demo',
66
- :origin => 'file://',
67
- :subprotocol => 'sample',
68
- :number1 => 777_007_543,
69
- :number2 => 114_997_259,
70
- :challenge => "\x47\x30\x22\x2D\x5A\x3F\x47\x58"
71
- );
72
- assert_equal res.to_s, "HTTP/1.1 101 WebSocket Protocol Handshake\x0d\x0a" +
73
- "Upgrade: WebSocket\x0d\x0a" +
74
- "Connection: Upgrade\x0d\x0a" +
75
- "Sec-WebSocket-Protocol: sample\x0d\x0a" +
76
- "Sec-WebSocket-Origin: file://\x0d\x0a" +
77
- "Sec-WebSocket-Location: ws://example.com/demo\x0d\x0a" +
78
- "\x0d\x0a" +
79
- "0st3Rl&q-2ZU^weu"
80
-
81
- res = LibWebSocket::Response.new(
82
- :secure => true,
83
- :host => 'example.com',
84
- :resource_name => '/demo',
85
- :origin => 'file://',
86
- :number1 => 777_007_543,
87
- :number2 => 114_997_259,
88
- :challenge => "\x47\x30\x22\x2D\x5A\x3F\x47\x58"
89
- )
90
- assert_equal res.to_s, "HTTP/1.1 101 WebSocket Protocol Handshake\x0d\x0a" +
91
- "Upgrade: WebSocket\x0d\x0a" +
92
- "Connection: Upgrade\x0d\x0a" +
93
- "Sec-WebSocket-Origin: file://\x0d\x0a" +
94
- "Sec-WebSocket-Location: wss://example.com/demo\x0d\x0a" +
95
- "\x0d\x0a" +
96
- "0st3Rl&q-2ZU^weu"
97
-
98
- res = LibWebSocket::Response.new(
99
- :host => 'example.com',
100
- :resource_name => '/demo',
101
- :origin => 'file://',
102
- :key1 => "18x 6]8vM;54 *(5: { U1]8 z [ 8",
103
- :key2 => "1_ tx7X d < nw 334J702) 7]o}` 0",
104
- :challenge => "Tm[K T2u"
105
- )
106
- assert_equal res.to_s, "HTTP/1.1 101 WebSocket Protocol Handshake\x0d\x0a" +
107
- "Upgrade: WebSocket\x0d\x0a" +
108
- "Connection: Upgrade\x0d\x0a" +
109
- "Sec-WebSocket-Origin: file://\x0d\x0a" +
110
- "Sec-WebSocket-Location: ws://example.com/demo\x0d\x0a" +
111
- "\x0d\x0a" +
112
- "fQJ,fN/4F4!~K~MH"
113
- end
114
-
115
- end
@@ -1,17 +0,0 @@
1
- require 'test_helper'
2
-
3
- class TestResponseCommon < Test::Unit::TestCase
4
-
5
- def test_parse
6
- res = LibWebSocket::Response.new
7
- res.parse("foo\x0d\x0a")
8
- assert_equal 'error', res.state
9
- assert_equal 'Wrong response line', res.error
10
-
11
- res = LibWebSocket::Response.new
12
- assert_nil res.parse('x' * (1024 * 10))
13
- assert_equal 'error', res.state
14
- assert_equal 'Message is too long', res.error
15
- end
16
-
17
- end
@@ -1,55 +0,0 @@
1
- require 'test_helper'
2
-
3
- class TestURL < Test::Unit::TestCase
4
-
5
- def test_parse
6
- url = LibWebSocket::URL.new
7
- assert url.parse('ws://example.com')
8
- assert !url.secure
9
- assert_equal 'example.com', url.host
10
- assert_equal '/', url.resource_name
11
-
12
- url = LibWebSocket::URL.new
13
- assert url.parse('ws://example.com/')
14
- assert !url.secure
15
- assert_equal 'example.com', url.host
16
- assert_equal '/', url.resource_name
17
-
18
- url = LibWebSocket::URL.new
19
- assert url.parse('ws://example.com/demo')
20
- assert !url.secure
21
- assert_equal 'example.com', url.host
22
- assert_equal '/demo', url.resource_name
23
-
24
- url = LibWebSocket::URL.new
25
- assert url.parse('ws://example.com:3000')
26
- assert !url.secure
27
- assert_equal 'example.com', url.host
28
- assert_equal '3000', url.port
29
- assert_equal '/', url.resource_name
30
-
31
- url = LibWebSocket::URL.new
32
- assert url.parse('ws://example.com/demo?foo=bar')
33
- assert !url.secure
34
- assert_equal 'example.com', url.host
35
- assert_equal '/demo?foo=bar', url.resource_name
36
- end
37
-
38
- def test_to_s
39
- url = LibWebSocket::URL.new(:host => 'foo.com', :secure => true);
40
- assert_equal 'wss://foo.com/', url.to_s
41
-
42
- url = LibWebSocket::URL.new(
43
- :host => 'foo.com',
44
- :resource_name => '/demo'
45
- )
46
- assert_equal 'ws://foo.com/demo', url.to_s
47
-
48
- url = LibWebSocket::URL.new(
49
- :host => 'foo.com',
50
- :port => 3000
51
- )
52
- assert_equal 'ws://foo.com:3000/', url.to_s
53
- end
54
-
55
- end