url_spec.js
2.77 KB
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
var needle = require('../'),
sinon = require('sinon'),
should = require('should'),
http = require('http'),
helpers = require('./helpers');
var port = 3456;
describe('urls', function() {
var server, url;
function send_request(cb) {
return needle.get(url, cb);
}
before(function(done){
server = helpers.server({ port: port }, done);
})
after(function(done) {
server.close(done);
})
describe('null URL', function(){
it('throws', function(){
(function() {
send_request()
}).should.throw();
})
})
describe('invalid protocol', function(){
before(function() {
url = 'foo://google.com/what'
})
it('does not throw', function(done) {
(function() {
send_request(function(err) {
done();
})
}).should.not.throw()
})
it('returns an error', function(done) {
send_request(function(err) {
err.should.be.an.Error;
err.code.should.match(/ENOTFOUND|EADDRINFO|EAI_AGAIN/)
done();
})
})
})
describe('invalid host', function(){
before(function() {
url = 'http://s1\\\u0002.com/'
})
it('fails', function(done) {
(function() {
send_request(function(){ })
}.should.throw(TypeError))
done()
})
})
/*
describe('invalid path', function(){
before(function() {
url = 'http://www.google.com\\\/x\\\ %^&*() /x2.com/'
})
it('fails', function(done) {
send_request(function(err) {
err.should.be.an.Error;
done();
})
})
})
*/
describe('valid protocol and path', function() {
before(function() {
url = 'http://localhost:' + port + '/foo';
})
it('works', function(done) {
send_request(function(err){
should.not.exist(err);
done();
})
})
})
describe('no protocol but with slashes and valid path', function() {
before(function() {
url = '//localhost:' + port + '/foo';
})
it('works', function(done) {
send_request(function(err){
should.not.exist(err);
done();
})
})
})
describe('no protocol nor slashes and valid path', function() {
before(function() {
url = 'localhost:' + port + '/foo';
})
it('works', function(done) {
send_request(function(err){
should.not.exist(err);
done();
})
})
})
describe('double encoding', function() {
var path = '/foo?email=' + encodeURIComponent('what-ever@Example.Com');
before(function() {
url = 'localhost:' + port + path
});
it('should not occur', function(done) {
send_request(function(err, res) {
should.not.exist(err);
should(res.req.path).be.exactly(path);
done();
});
});
})
})