@wiajs/request 3.0.1 → 3.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/.github/ISSUE_TEMPLATE.md +0 -56
- package/.github/PULL_REQUEST_TEMPLATE.md +0 -13
- package/.github/stale.yml +0 -19
- package/.swcrc +0 -57
- package/.travis.yml +0 -21
- package/CONTRIBUTING.md +0 -81
- package/biome.json +0 -44
- package/codecov.yml +0 -2
- package/disabled.appveyor.yml +0 -36
- package/examples/README.md +0 -135
- package/gulpfile.js +0 -71
- package/release.sh +0 -45
- package/tests/browser/karma.conf.js +0 -57
- package/tests/browser/ssl/ca.crt +0 -14
- package/tests/browser/ssl/server.crt +0 -14
- package/tests/browser/ssl/server.key +0 -15
- package/tests/browser/start.js +0 -37
- package/tests/browser/test.js +0 -34
- package/tests/fixtures/har.json +0 -158
- package/tests/googledoodle.jpg +0 -0
- package/tests/server.js +0 -142
- package/tests/squid.conf +0 -76
- package/tests/ssl/ca/README.md +0 -8
- package/tests/ssl/ca/ca.cnf +0 -20
- package/tests/ssl/ca/ca.crl +0 -0
- package/tests/ssl/ca/ca.crt +0 -17
- package/tests/ssl/ca/ca.csr +0 -13
- package/tests/ssl/ca/ca.key +0 -18
- package/tests/ssl/ca/ca.srl +0 -1
- package/tests/ssl/ca/client-enc.key +0 -30
- package/tests/ssl/ca/client.cnf +0 -20
- package/tests/ssl/ca/client.crt +0 -20
- package/tests/ssl/ca/client.csr +0 -18
- package/tests/ssl/ca/client.key +0 -27
- package/tests/ssl/ca/gen-all-certs.sh +0 -6
- package/tests/ssl/ca/gen-client.sh +0 -25
- package/tests/ssl/ca/gen-localhost.sh +0 -22
- package/tests/ssl/ca/gen-server.sh +0 -18
- package/tests/ssl/ca/localhost.cnf +0 -20
- package/tests/ssl/ca/localhost.crt +0 -20
- package/tests/ssl/ca/localhost.csr +0 -18
- package/tests/ssl/ca/localhost.js +0 -33
- package/tests/ssl/ca/localhost.key +0 -27
- package/tests/ssl/ca/server.cnf +0 -19
- package/tests/ssl/ca/server.crt +0 -25
- package/tests/ssl/ca/server.csr +0 -29
- package/tests/ssl/ca/server.js +0 -34
- package/tests/ssl/ca/server.key +0 -51
- package/tests/ssl/npm-ca.crt +0 -16
- package/tests/ssl/test.crt +0 -15
- package/tests/ssl/test.key +0 -15
- package/tests/test-agent.js +0 -102
- package/tests/test-agentOptions.js +0 -51
- package/tests/test-api.js +0 -33
- package/tests/test-aws.js +0 -123
- package/tests/test-baseUrl.js +0 -133
- package/tests/test-basic-auth.js +0 -221
- package/tests/test-bearer-auth.js +0 -187
- package/tests/test-body.js +0 -154
- package/tests/test-cookies.js +0 -130
- package/tests/test-defaults.js +0 -340
- package/tests/test-digest-auth.js +0 -232
- package/tests/test-emptyBody.js +0 -56
- package/tests/test-errors.js +0 -108
- package/tests/test-event-forwarding.js +0 -39
- package/tests/test-follow-all-303.js +0 -45
- package/tests/test-follow-all.js +0 -57
- package/tests/test-form-data-error.js +0 -85
- package/tests/test-form-data.js +0 -133
- package/tests/test-form-urlencoded.js +0 -73
- package/tests/test-form.js +0 -101
- package/tests/test-gzip.js +0 -296
- package/tests/test-har.js +0 -175
- package/tests/test-hawk.js +0 -187
- package/tests/test-headers.js +0 -305
- package/tests/test-http-signature.js +0 -110
- package/tests/test-httpModule.js +0 -112
- package/tests/test-https.js +0 -116
- package/tests/test-isUrl.js +0 -120
- package/tests/test-json-request.js +0 -117
- package/tests/test-localAddress.js +0 -49
- package/tests/test-multipart-encoding.js +0 -147
- package/tests/test-multipart.js +0 -129
- package/tests/test-node-debug.js +0 -95
- package/tests/test-oauth.js +0 -721
- package/tests/test-onelineproxy.js +0 -61
- package/tests/test-option-reuse.js +0 -54
- package/tests/test-options-convenience-method.js +0 -52
- package/tests/test-params.js +0 -101
- package/tests/test-piped-redirect.js +0 -55
- package/tests/test-pipes.js +0 -383
- package/tests/test-pool.js +0 -148
- package/tests/test-promise.js +0 -53
- package/tests/test-proxy-connect.js +0 -80
- package/tests/test-proxy.js +0 -304
- package/tests/test-qs.js +0 -135
- package/tests/test-redirect-auth.js +0 -131
- package/tests/test-redirect-complex.js +0 -93
- package/tests/test-redirect.js +0 -449
- package/tests/test-rfc3986.js +0 -106
- package/tests/test-stream.js +0 -36
- package/tests/test-timeout.js +0 -260
- package/tests/test-timing.js +0 -147
- package/tests/test-toJSON.js +0 -45
- package/tests/test-tunnel.js +0 -466
- package/tests/test-unix.js +0 -74
- package/tests/unicycle.jpg +0 -0
package/tests/test-aws.js
DELETED
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
var request = require('../index')
|
|
4
|
-
var server = require('./server')
|
|
5
|
-
var tape = require('tape')
|
|
6
|
-
|
|
7
|
-
var s = server.createServer()
|
|
8
|
-
|
|
9
|
-
var path = '/aws.json'
|
|
10
|
-
|
|
11
|
-
s.on(path, function (req, res) {
|
|
12
|
-
res.writeHead(200, {
|
|
13
|
-
'Content-Type': 'application/json'
|
|
14
|
-
})
|
|
15
|
-
res.end(JSON.stringify(req.headers))
|
|
16
|
-
})
|
|
17
|
-
|
|
18
|
-
tape('setup', function (t) {
|
|
19
|
-
s.listen(0, function () {
|
|
20
|
-
t.end()
|
|
21
|
-
})
|
|
22
|
-
})
|
|
23
|
-
|
|
24
|
-
tape('default behaviour: aws-sign2 without sign_version key', function (t) {
|
|
25
|
-
var options = {
|
|
26
|
-
url: s.url + path,
|
|
27
|
-
aws: {
|
|
28
|
-
key: 'my_key',
|
|
29
|
-
secret: 'my_secret'
|
|
30
|
-
},
|
|
31
|
-
json: true
|
|
32
|
-
}
|
|
33
|
-
request(options, function (err, res, body) {
|
|
34
|
-
t.error(err)
|
|
35
|
-
t.ok(body.authorization)
|
|
36
|
-
t.notOk(body['x-amz-date'])
|
|
37
|
-
t.end()
|
|
38
|
-
})
|
|
39
|
-
})
|
|
40
|
-
|
|
41
|
-
tape('aws-sign4 options', function (t) {
|
|
42
|
-
var options = {
|
|
43
|
-
url: s.url + path,
|
|
44
|
-
aws: {
|
|
45
|
-
key: 'my_key',
|
|
46
|
-
secret: 'my_secret',
|
|
47
|
-
sign_version: 4
|
|
48
|
-
},
|
|
49
|
-
json: true
|
|
50
|
-
}
|
|
51
|
-
request(options, function (err, res, body) {
|
|
52
|
-
t.error(err)
|
|
53
|
-
t.ok(body.authorization)
|
|
54
|
-
t.ok(body['x-amz-date'])
|
|
55
|
-
t.notok(body['x-amz-security-token'])
|
|
56
|
-
t.end()
|
|
57
|
-
})
|
|
58
|
-
})
|
|
59
|
-
|
|
60
|
-
tape('aws-sign4 options with session token', function (t) {
|
|
61
|
-
var options = {
|
|
62
|
-
url: s.url + path,
|
|
63
|
-
aws: {
|
|
64
|
-
key: 'my_key',
|
|
65
|
-
secret: 'my_secret',
|
|
66
|
-
session: 'session',
|
|
67
|
-
sign_version: 4
|
|
68
|
-
},
|
|
69
|
-
json: true
|
|
70
|
-
}
|
|
71
|
-
request(options, function (err, res, body) {
|
|
72
|
-
t.error(err)
|
|
73
|
-
t.ok(body.authorization)
|
|
74
|
-
t.ok(body['x-amz-date'])
|
|
75
|
-
t.ok(body['x-amz-security-token'])
|
|
76
|
-
t.end()
|
|
77
|
-
})
|
|
78
|
-
})
|
|
79
|
-
|
|
80
|
-
tape('aws-sign4 options with service', function (t) {
|
|
81
|
-
var serviceName = 'UNIQUE_SERVICE_NAME'
|
|
82
|
-
var options = {
|
|
83
|
-
url: s.url + path,
|
|
84
|
-
aws: {
|
|
85
|
-
key: 'my_key',
|
|
86
|
-
secret: 'my_secret',
|
|
87
|
-
sign_version: 4,
|
|
88
|
-
service: serviceName
|
|
89
|
-
},
|
|
90
|
-
json: true
|
|
91
|
-
}
|
|
92
|
-
request(options, function (err, res, body) {
|
|
93
|
-
t.error(err)
|
|
94
|
-
t.ok(body.authorization.includes(serviceName))
|
|
95
|
-
t.end()
|
|
96
|
-
})
|
|
97
|
-
})
|
|
98
|
-
|
|
99
|
-
tape('aws-sign4 with additional headers', function (t) {
|
|
100
|
-
var options = {
|
|
101
|
-
url: s.url + path,
|
|
102
|
-
headers: {
|
|
103
|
-
'X-Custom-Header': 'custom'
|
|
104
|
-
},
|
|
105
|
-
aws: {
|
|
106
|
-
key: 'my_key',
|
|
107
|
-
secret: 'my_secret',
|
|
108
|
-
sign_version: 4
|
|
109
|
-
},
|
|
110
|
-
json: true
|
|
111
|
-
}
|
|
112
|
-
request(options, function (err, res, body) {
|
|
113
|
-
t.error(err)
|
|
114
|
-
t.ok(body.authorization.includes('x-custom-header'))
|
|
115
|
-
t.end()
|
|
116
|
-
})
|
|
117
|
-
})
|
|
118
|
-
|
|
119
|
-
tape('cleanup', function (t) {
|
|
120
|
-
s.close(function () {
|
|
121
|
-
t.end()
|
|
122
|
-
})
|
|
123
|
-
})
|
package/tests/test-baseUrl.js
DELETED
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
var http = require('http')
|
|
4
|
-
var request = require('../index')
|
|
5
|
-
var tape = require('tape')
|
|
6
|
-
var url = require('url')
|
|
7
|
-
|
|
8
|
-
var s = http.createServer(function (req, res) {
|
|
9
|
-
if (req.url === '/redirect/') {
|
|
10
|
-
res.writeHead(302, {
|
|
11
|
-
location: '/'
|
|
12
|
-
})
|
|
13
|
-
} else {
|
|
14
|
-
res.statusCode = 200
|
|
15
|
-
res.setHeader('X-PATH', req.url)
|
|
16
|
-
}
|
|
17
|
-
res.end('ok')
|
|
18
|
-
})
|
|
19
|
-
|
|
20
|
-
function addTest (baseUrl, uri, expected) {
|
|
21
|
-
tape('test baseurl="' + baseUrl + '" uri="' + uri + '"', function (t) {
|
|
22
|
-
request(uri, { baseUrl: baseUrl }, function (err, resp, body) {
|
|
23
|
-
t.equal(err, null)
|
|
24
|
-
t.equal(body, 'ok')
|
|
25
|
-
t.equal(resp.headers['x-path'], expected)
|
|
26
|
-
t.end()
|
|
27
|
-
})
|
|
28
|
-
})
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
function addTests () {
|
|
32
|
-
addTest(s.url, '', '/')
|
|
33
|
-
addTest(s.url + '/', '', '/')
|
|
34
|
-
addTest(s.url, '/', '/')
|
|
35
|
-
addTest(s.url + '/', '/', '/')
|
|
36
|
-
addTest(s.url + '/api', '', '/api')
|
|
37
|
-
addTest(s.url + '/api/', '', '/api/')
|
|
38
|
-
addTest(s.url + '/api', '/', '/api/')
|
|
39
|
-
addTest(s.url + '/api/', '/', '/api/')
|
|
40
|
-
addTest(s.url + '/api', 'resource', '/api/resource')
|
|
41
|
-
addTest(s.url + '/api/', 'resource', '/api/resource')
|
|
42
|
-
addTest(s.url + '/api', '/resource', '/api/resource')
|
|
43
|
-
addTest(s.url + '/api/', '/resource', '/api/resource')
|
|
44
|
-
addTest(s.url + '/api', 'resource/', '/api/resource/')
|
|
45
|
-
addTest(s.url + '/api/', 'resource/', '/api/resource/')
|
|
46
|
-
addTest(s.url + '/api', '/resource/', '/api/resource/')
|
|
47
|
-
addTest(s.url + '/api/', '/resource/', '/api/resource/')
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
tape('setup', function (t) {
|
|
51
|
-
s.listen(0, function () {
|
|
52
|
-
s.url = 'http://localhost:' + this.address().port
|
|
53
|
-
addTests()
|
|
54
|
-
tape('cleanup', function (t) {
|
|
55
|
-
s.close(function () {
|
|
56
|
-
t.end()
|
|
57
|
-
})
|
|
58
|
-
})
|
|
59
|
-
t.end()
|
|
60
|
-
})
|
|
61
|
-
})
|
|
62
|
-
|
|
63
|
-
tape('baseUrl', function (t) {
|
|
64
|
-
request('resource', {
|
|
65
|
-
baseUrl: s.url
|
|
66
|
-
}, function (err, resp, body) {
|
|
67
|
-
t.equal(err, null)
|
|
68
|
-
t.equal(body, 'ok')
|
|
69
|
-
t.end()
|
|
70
|
-
})
|
|
71
|
-
})
|
|
72
|
-
|
|
73
|
-
tape('baseUrl defaults', function (t) {
|
|
74
|
-
var withDefaults = request.defaults({
|
|
75
|
-
baseUrl: s.url
|
|
76
|
-
})
|
|
77
|
-
withDefaults('resource', function (err, resp, body) {
|
|
78
|
-
t.equal(err, null)
|
|
79
|
-
t.equal(body, 'ok')
|
|
80
|
-
t.end()
|
|
81
|
-
})
|
|
82
|
-
})
|
|
83
|
-
|
|
84
|
-
tape('baseUrl and redirects', function (t) {
|
|
85
|
-
request('/', {
|
|
86
|
-
baseUrl: s.url + '/redirect'
|
|
87
|
-
}, function (err, resp, body) {
|
|
88
|
-
t.equal(err, null)
|
|
89
|
-
t.equal(body, 'ok')
|
|
90
|
-
t.equal(resp.headers['x-path'], '/')
|
|
91
|
-
t.end()
|
|
92
|
-
})
|
|
93
|
-
})
|
|
94
|
-
|
|
95
|
-
tape('error when baseUrl is not a String', function (t) {
|
|
96
|
-
request('resource', {
|
|
97
|
-
baseUrl: url.parse(s.url + '/path')
|
|
98
|
-
}, function (err, resp, body) {
|
|
99
|
-
t.notEqual(err, null)
|
|
100
|
-
t.equal(err.message, 'options.baseUrl must be a string')
|
|
101
|
-
t.end()
|
|
102
|
-
})
|
|
103
|
-
})
|
|
104
|
-
|
|
105
|
-
tape('error when uri is not a String', function (t) {
|
|
106
|
-
request(url.parse('resource'), {
|
|
107
|
-
baseUrl: s.url + '/path'
|
|
108
|
-
}, function (err, resp, body) {
|
|
109
|
-
t.notEqual(err, null)
|
|
110
|
-
t.equal(err.message, 'options.uri must be a string when using options.baseUrl')
|
|
111
|
-
t.end()
|
|
112
|
-
})
|
|
113
|
-
})
|
|
114
|
-
|
|
115
|
-
tape('error on baseUrl and uri with scheme', function (t) {
|
|
116
|
-
request(s.url + '/path/ignoring/baseUrl', {
|
|
117
|
-
baseUrl: s.url + '/path/'
|
|
118
|
-
}, function (err, resp, body) {
|
|
119
|
-
t.notEqual(err, null)
|
|
120
|
-
t.equal(err.message, 'options.uri must be a path when using options.baseUrl')
|
|
121
|
-
t.end()
|
|
122
|
-
})
|
|
123
|
-
})
|
|
124
|
-
|
|
125
|
-
tape('error on baseUrl and uri with scheme-relative url', function (t) {
|
|
126
|
-
request(s.url.slice('http:'.length) + '/path/ignoring/baseUrl', {
|
|
127
|
-
baseUrl: s.url + '/path/'
|
|
128
|
-
}, function (err, resp, body) {
|
|
129
|
-
t.notEqual(err, null)
|
|
130
|
-
t.equal(err.message, 'options.uri must be a path when using options.baseUrl')
|
|
131
|
-
t.end()
|
|
132
|
-
})
|
|
133
|
-
})
|
package/tests/test-basic-auth.js
DELETED
|
@@ -1,221 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
var assert = require('assert')
|
|
4
|
-
var http = require('http')
|
|
5
|
-
var request = require('../index')
|
|
6
|
-
var tape = require('tape')
|
|
7
|
-
|
|
8
|
-
var numBasicRequests = 0
|
|
9
|
-
var basicServer
|
|
10
|
-
|
|
11
|
-
tape('setup', function (t) {
|
|
12
|
-
basicServer = http.createServer(function (req, res) {
|
|
13
|
-
numBasicRequests++
|
|
14
|
-
|
|
15
|
-
var ok
|
|
16
|
-
|
|
17
|
-
if (req.headers.authorization) {
|
|
18
|
-
if (req.headers.authorization === 'Basic ' + Buffer.from('user:pass').toString('base64')) {
|
|
19
|
-
ok = true
|
|
20
|
-
} else if (req.headers.authorization === 'Basic ' + Buffer.from('user:').toString('base64')) {
|
|
21
|
-
ok = true
|
|
22
|
-
} else if (req.headers.authorization === 'Basic ' + Buffer.from(':pass').toString('base64')) {
|
|
23
|
-
ok = true
|
|
24
|
-
} else if (req.headers.authorization === 'Basic ' + Buffer.from('user:pâss').toString('base64')) {
|
|
25
|
-
ok = true
|
|
26
|
-
} else {
|
|
27
|
-
// Bad auth header, don't send back WWW-Authenticate header
|
|
28
|
-
ok = false
|
|
29
|
-
}
|
|
30
|
-
} else {
|
|
31
|
-
// No auth header, send back WWW-Authenticate header
|
|
32
|
-
ok = false
|
|
33
|
-
res.setHeader('www-authenticate', 'Basic realm="Private"')
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
if (req.url === '/post/') {
|
|
37
|
-
var expectedContent = 'key=value'
|
|
38
|
-
req.on('data', function (data) {
|
|
39
|
-
assert.equal(data, expectedContent)
|
|
40
|
-
})
|
|
41
|
-
assert.equal(req.method, 'POST')
|
|
42
|
-
assert.equal(req.headers['content-length'], '' + expectedContent.length)
|
|
43
|
-
assert.equal(req.headers['content-type'], 'application/x-www-form-urlencoded')
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
if (ok) {
|
|
47
|
-
res.end('ok')
|
|
48
|
-
} else {
|
|
49
|
-
res.statusCode = 401
|
|
50
|
-
res.end('401')
|
|
51
|
-
}
|
|
52
|
-
}).listen(0, function () {
|
|
53
|
-
basicServer.port = this.address().port
|
|
54
|
-
basicServer.url = 'http://localhost:' + basicServer.port
|
|
55
|
-
t.end()
|
|
56
|
-
})
|
|
57
|
-
})
|
|
58
|
-
|
|
59
|
-
tape('sendImmediately - false', function (t) {
|
|
60
|
-
var r = request({
|
|
61
|
-
'method': 'GET',
|
|
62
|
-
'uri': basicServer.url + '/test/',
|
|
63
|
-
'auth': {
|
|
64
|
-
'user': 'user',
|
|
65
|
-
'pass': 'pass',
|
|
66
|
-
'sendImmediately': false
|
|
67
|
-
}
|
|
68
|
-
}, function (error, res, body) {
|
|
69
|
-
t.error(error)
|
|
70
|
-
t.equal(r._auth.user, 'user')
|
|
71
|
-
t.equal(res.statusCode, 200)
|
|
72
|
-
t.equal(numBasicRequests, 2)
|
|
73
|
-
t.end()
|
|
74
|
-
})
|
|
75
|
-
})
|
|
76
|
-
|
|
77
|
-
tape('sendImmediately - true', function (t) {
|
|
78
|
-
// If we don't set sendImmediately = false, request will send basic auth
|
|
79
|
-
var r = request({
|
|
80
|
-
'method': 'GET',
|
|
81
|
-
'uri': basicServer.url + '/test2/',
|
|
82
|
-
'auth': {
|
|
83
|
-
'user': 'user',
|
|
84
|
-
'pass': 'pass'
|
|
85
|
-
}
|
|
86
|
-
}, function (error, res, body) {
|
|
87
|
-
t.error(error)
|
|
88
|
-
t.equal(r._auth.user, 'user')
|
|
89
|
-
t.equal(res.statusCode, 200)
|
|
90
|
-
t.equal(numBasicRequests, 3)
|
|
91
|
-
t.end()
|
|
92
|
-
})
|
|
93
|
-
})
|
|
94
|
-
|
|
95
|
-
tape('credentials in url', function (t) {
|
|
96
|
-
var r = request({
|
|
97
|
-
'method': 'GET',
|
|
98
|
-
'uri': basicServer.url.replace(/:\/\//, '$&user:pass@') + '/test2/'
|
|
99
|
-
}, function (error, res, body) {
|
|
100
|
-
t.error(error)
|
|
101
|
-
t.equal(r._auth.user, 'user')
|
|
102
|
-
t.equal(res.statusCode, 200)
|
|
103
|
-
t.equal(numBasicRequests, 4)
|
|
104
|
-
t.end()
|
|
105
|
-
})
|
|
106
|
-
})
|
|
107
|
-
|
|
108
|
-
tape('POST request', function (t) {
|
|
109
|
-
var r = request({
|
|
110
|
-
'method': 'POST',
|
|
111
|
-
'form': { 'key': 'value' },
|
|
112
|
-
'uri': basicServer.url + '/post/',
|
|
113
|
-
'auth': {
|
|
114
|
-
'user': 'user',
|
|
115
|
-
'pass': 'pass',
|
|
116
|
-
'sendImmediately': false
|
|
117
|
-
}
|
|
118
|
-
}, function (error, res, body) {
|
|
119
|
-
t.error(error)
|
|
120
|
-
t.equal(r._auth.user, 'user')
|
|
121
|
-
t.equal(res.statusCode, 200)
|
|
122
|
-
t.equal(numBasicRequests, 6)
|
|
123
|
-
t.end()
|
|
124
|
-
})
|
|
125
|
-
})
|
|
126
|
-
|
|
127
|
-
tape('user - empty string', function (t) {
|
|
128
|
-
t.doesNotThrow(function () {
|
|
129
|
-
var r = request({
|
|
130
|
-
'method': 'GET',
|
|
131
|
-
'uri': basicServer.url + '/allow_empty_user/',
|
|
132
|
-
'auth': {
|
|
133
|
-
'user': '',
|
|
134
|
-
'pass': 'pass',
|
|
135
|
-
'sendImmediately': false
|
|
136
|
-
}
|
|
137
|
-
}, function (error, res, body) {
|
|
138
|
-
t.error(error)
|
|
139
|
-
t.equal(r._auth.user, '')
|
|
140
|
-
t.equal(res.statusCode, 200)
|
|
141
|
-
t.equal(numBasicRequests, 8)
|
|
142
|
-
t.end()
|
|
143
|
-
})
|
|
144
|
-
})
|
|
145
|
-
})
|
|
146
|
-
|
|
147
|
-
tape('pass - undefined', function (t) {
|
|
148
|
-
t.doesNotThrow(function () {
|
|
149
|
-
var r = request({
|
|
150
|
-
'method': 'GET',
|
|
151
|
-
'uri': basicServer.url + '/allow_undefined_password/',
|
|
152
|
-
'auth': {
|
|
153
|
-
'user': 'user',
|
|
154
|
-
'pass': undefined,
|
|
155
|
-
'sendImmediately': false
|
|
156
|
-
}
|
|
157
|
-
}, function (error, res, body) {
|
|
158
|
-
t.error(error)
|
|
159
|
-
t.equal(r._auth.user, 'user')
|
|
160
|
-
t.equal(res.statusCode, 200)
|
|
161
|
-
t.equal(numBasicRequests, 10)
|
|
162
|
-
t.end()
|
|
163
|
-
})
|
|
164
|
-
})
|
|
165
|
-
})
|
|
166
|
-
|
|
167
|
-
tape('pass - utf8', function (t) {
|
|
168
|
-
t.doesNotThrow(function () {
|
|
169
|
-
var r = request({
|
|
170
|
-
'method': 'GET',
|
|
171
|
-
'uri': basicServer.url + '/allow_undefined_password/',
|
|
172
|
-
'auth': {
|
|
173
|
-
'user': 'user',
|
|
174
|
-
'pass': 'pâss',
|
|
175
|
-
'sendImmediately': false
|
|
176
|
-
}
|
|
177
|
-
}, function (error, res, body) {
|
|
178
|
-
t.error(error)
|
|
179
|
-
t.equal(r._auth.user, 'user')
|
|
180
|
-
t.equal(r._auth.pass, 'pâss')
|
|
181
|
-
t.equal(res.statusCode, 200)
|
|
182
|
-
t.equal(numBasicRequests, 12)
|
|
183
|
-
t.end()
|
|
184
|
-
})
|
|
185
|
-
})
|
|
186
|
-
})
|
|
187
|
-
|
|
188
|
-
tape('auth method', function (t) {
|
|
189
|
-
var r = request
|
|
190
|
-
.get(basicServer.url + '/test/')
|
|
191
|
-
.auth('user', '', false)
|
|
192
|
-
.on('response', function (res) {
|
|
193
|
-
t.equal(r._auth.user, 'user')
|
|
194
|
-
t.equal(res.statusCode, 200)
|
|
195
|
-
t.equal(numBasicRequests, 14)
|
|
196
|
-
t.end()
|
|
197
|
-
})
|
|
198
|
-
})
|
|
199
|
-
|
|
200
|
-
tape('get method', function (t) {
|
|
201
|
-
var r = request.get(basicServer.url + '/test/',
|
|
202
|
-
{
|
|
203
|
-
auth: {
|
|
204
|
-
user: 'user',
|
|
205
|
-
pass: '',
|
|
206
|
-
sendImmediately: false
|
|
207
|
-
}
|
|
208
|
-
}, function (err, res) {
|
|
209
|
-
t.equal(r._auth.user, 'user')
|
|
210
|
-
t.equal(err, null)
|
|
211
|
-
t.equal(res.statusCode, 200)
|
|
212
|
-
t.equal(numBasicRequests, 16)
|
|
213
|
-
t.end()
|
|
214
|
-
})
|
|
215
|
-
})
|
|
216
|
-
|
|
217
|
-
tape('cleanup', function (t) {
|
|
218
|
-
basicServer.close(function () {
|
|
219
|
-
t.end()
|
|
220
|
-
})
|
|
221
|
-
})
|
|
@@ -1,187 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
var assert = require('assert')
|
|
4
|
-
var http = require('http')
|
|
5
|
-
var request = require('../index')
|
|
6
|
-
var tape = require('tape')
|
|
7
|
-
|
|
8
|
-
var numBearerRequests = 0
|
|
9
|
-
var bearerServer
|
|
10
|
-
|
|
11
|
-
tape('setup', function (t) {
|
|
12
|
-
bearerServer = http.createServer(function (req, res) {
|
|
13
|
-
numBearerRequests++
|
|
14
|
-
|
|
15
|
-
var ok
|
|
16
|
-
|
|
17
|
-
if (req.headers.authorization) {
|
|
18
|
-
if (req.headers.authorization === 'Bearer theToken') {
|
|
19
|
-
ok = true
|
|
20
|
-
} else {
|
|
21
|
-
// Bad auth header, don't send back WWW-Authenticate header
|
|
22
|
-
ok = false
|
|
23
|
-
}
|
|
24
|
-
} else {
|
|
25
|
-
// No auth header, send back WWW-Authenticate header
|
|
26
|
-
ok = false
|
|
27
|
-
res.setHeader('www-authenticate', 'Bearer realm="Private"')
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
if (req.url === '/post/') {
|
|
31
|
-
var expectedContent = 'data_key=data_value'
|
|
32
|
-
req.on('data', function (data) {
|
|
33
|
-
assert.equal(data, expectedContent)
|
|
34
|
-
})
|
|
35
|
-
assert.equal(req.method, 'POST')
|
|
36
|
-
assert.equal(req.headers['content-length'], '' + expectedContent.length)
|
|
37
|
-
assert.equal(req.headers['content-type'], 'application/x-www-form-urlencoded')
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
if (ok) {
|
|
41
|
-
res.end('ok')
|
|
42
|
-
} else {
|
|
43
|
-
res.statusCode = 401
|
|
44
|
-
res.end('401')
|
|
45
|
-
}
|
|
46
|
-
}).listen(0, function () {
|
|
47
|
-
bearerServer.url = 'http://localhost:' + this.address().port
|
|
48
|
-
t.end()
|
|
49
|
-
})
|
|
50
|
-
})
|
|
51
|
-
|
|
52
|
-
tape('bearer auth', function (t) {
|
|
53
|
-
request({
|
|
54
|
-
'method': 'GET',
|
|
55
|
-
'uri': bearerServer.url + '/test/',
|
|
56
|
-
'auth': {
|
|
57
|
-
'bearer': 'theToken',
|
|
58
|
-
'sendImmediately': false
|
|
59
|
-
}
|
|
60
|
-
}, function (error, res, body) {
|
|
61
|
-
t.error(error)
|
|
62
|
-
t.equal(res.statusCode, 200)
|
|
63
|
-
t.equal(numBearerRequests, 2)
|
|
64
|
-
t.end()
|
|
65
|
-
})
|
|
66
|
-
})
|
|
67
|
-
|
|
68
|
-
tape('bearer auth with default sendImmediately', function (t) {
|
|
69
|
-
// If we don't set sendImmediately = false, request will send bearer auth
|
|
70
|
-
request({
|
|
71
|
-
'method': 'GET',
|
|
72
|
-
'uri': bearerServer.url + '/test2/',
|
|
73
|
-
'auth': {
|
|
74
|
-
'bearer': 'theToken'
|
|
75
|
-
}
|
|
76
|
-
}, function (error, res, body) {
|
|
77
|
-
t.error(error)
|
|
78
|
-
t.equal(res.statusCode, 200)
|
|
79
|
-
t.equal(numBearerRequests, 3)
|
|
80
|
-
t.end()
|
|
81
|
-
})
|
|
82
|
-
})
|
|
83
|
-
|
|
84
|
-
tape('', function (t) {
|
|
85
|
-
request({
|
|
86
|
-
'method': 'POST',
|
|
87
|
-
'form': { 'data_key': 'data_value' },
|
|
88
|
-
'uri': bearerServer.url + '/post/',
|
|
89
|
-
'auth': {
|
|
90
|
-
'bearer': 'theToken',
|
|
91
|
-
'sendImmediately': false
|
|
92
|
-
}
|
|
93
|
-
}, function (error, res, body) {
|
|
94
|
-
t.error(error)
|
|
95
|
-
t.equal(res.statusCode, 200)
|
|
96
|
-
t.equal(numBearerRequests, 5)
|
|
97
|
-
t.end()
|
|
98
|
-
})
|
|
99
|
-
})
|
|
100
|
-
|
|
101
|
-
tape('using .auth, sendImmediately = false', function (t) {
|
|
102
|
-
request
|
|
103
|
-
.get(bearerServer.url + '/test/')
|
|
104
|
-
.auth(null, null, false, 'theToken')
|
|
105
|
-
.on('response', function (res) {
|
|
106
|
-
t.equal(res.statusCode, 200)
|
|
107
|
-
t.equal(numBearerRequests, 7)
|
|
108
|
-
t.end()
|
|
109
|
-
})
|
|
110
|
-
})
|
|
111
|
-
|
|
112
|
-
tape('using .auth, sendImmediately = true', function (t) {
|
|
113
|
-
request
|
|
114
|
-
.get(bearerServer.url + '/test/')
|
|
115
|
-
.auth(null, null, true, 'theToken')
|
|
116
|
-
.on('response', function (res) {
|
|
117
|
-
t.equal(res.statusCode, 200)
|
|
118
|
-
t.equal(numBearerRequests, 8)
|
|
119
|
-
t.end()
|
|
120
|
-
})
|
|
121
|
-
})
|
|
122
|
-
|
|
123
|
-
tape('bearer is a function', function (t) {
|
|
124
|
-
request({
|
|
125
|
-
'method': 'GET',
|
|
126
|
-
'uri': bearerServer.url + '/test/',
|
|
127
|
-
'auth': {
|
|
128
|
-
'bearer': function () { return 'theToken' },
|
|
129
|
-
'sendImmediately': false
|
|
130
|
-
}
|
|
131
|
-
}, function (error, res, body) {
|
|
132
|
-
t.error(error)
|
|
133
|
-
t.equal(res.statusCode, 200)
|
|
134
|
-
t.equal(numBearerRequests, 10)
|
|
135
|
-
t.end()
|
|
136
|
-
})
|
|
137
|
-
})
|
|
138
|
-
|
|
139
|
-
tape('bearer is a function, path = test2', function (t) {
|
|
140
|
-
// If we don't set sendImmediately = false, request will send bearer auth
|
|
141
|
-
request({
|
|
142
|
-
'method': 'GET',
|
|
143
|
-
'uri': bearerServer.url + '/test2/',
|
|
144
|
-
'auth': {
|
|
145
|
-
'bearer': function () { return 'theToken' }
|
|
146
|
-
}
|
|
147
|
-
}, function (error, res, body) {
|
|
148
|
-
t.error(error)
|
|
149
|
-
t.equal(res.statusCode, 200)
|
|
150
|
-
t.equal(numBearerRequests, 11)
|
|
151
|
-
t.end()
|
|
152
|
-
})
|
|
153
|
-
})
|
|
154
|
-
|
|
155
|
-
tape('no auth method', function (t) {
|
|
156
|
-
request({
|
|
157
|
-
'method': 'GET',
|
|
158
|
-
'uri': bearerServer.url + '/test2/',
|
|
159
|
-
'auth': {
|
|
160
|
-
'bearer': undefined
|
|
161
|
-
}
|
|
162
|
-
}, function (error, res, body) {
|
|
163
|
-
t.equal(error.message, 'no auth mechanism defined')
|
|
164
|
-
t.end()
|
|
165
|
-
})
|
|
166
|
-
})
|
|
167
|
-
|
|
168
|
-
tape('null bearer', function (t) {
|
|
169
|
-
request({
|
|
170
|
-
'method': 'GET',
|
|
171
|
-
'uri': bearerServer.url + '/test2/',
|
|
172
|
-
'auth': {
|
|
173
|
-
'bearer': null
|
|
174
|
-
}
|
|
175
|
-
}, function (error, res, body) {
|
|
176
|
-
t.error(error)
|
|
177
|
-
t.equal(res.statusCode, 401)
|
|
178
|
-
t.equal(numBearerRequests, 13)
|
|
179
|
-
t.end()
|
|
180
|
-
})
|
|
181
|
-
})
|
|
182
|
-
|
|
183
|
-
tape('cleanup', function (t) {
|
|
184
|
-
bearerServer.close(function () {
|
|
185
|
-
t.end()
|
|
186
|
-
})
|
|
187
|
-
})
|