-
Notifications
You must be signed in to change notification settings - Fork 80
/
misc.js
91 lines (83 loc) · 3.31 KB
/
misc.js
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
'use strict';
const assert = require('../../utils/assert.js');
const preq = require('preq');
const Server = require('../../utils/server.js');
function getHeader(res, name) {
if (res.rawHeaders.indexOf(name) === -1) {
return undefined;
}
return res.rawHeaders[res.rawHeaders.indexOf(name) + 1];
}
describe('router - misc', function() {
this.timeout(100000);
const server = new Server();
before(() => server.start());
after(() => server.stop());
it('should deny access to /{domain}/sys', () => {
return preq.get({uri: `${server.config.hostPort}/en.wikipedia.org/sys/table`})
.catch((err) => {
assert.deepEqual(err.status, 403);
});
});
it('should set a request ID for each sub-request and return it', () => {
assert.recordRequests();
return preq.get({
uri: `${server.config.bucketURL('en.wikipedia.beta.wmflabs.org')}/html/Foobar`,
headers: {
'Cache-Control': 'no-cache'
}
})
.then((res) => {
const reqId = res.headers['x-request-id'];
assert.notDeepEqual(reqId, undefined, 'Request ID not returned');
assert.findRequests(() => {}).forEach((req) => {
assert.deepEqual(req.headers['x-request-id'], reqId, 'Request ID mismatch');
});
})
.finally(() => assert.cleanupRecorder());
});
it('should honour the provided request ID', () => {
assert.recordRequests();
const reqId = 'b6c17ea83d634b31bb28d60aae1caaac';
return preq.get({
uri: `${server.config.bucketURL('en.wikipedia.beta.wmflabs.org')}/html/Foobar`,
headers: {
'X-Request-Id': reqId
}
}).then((res) => {
assert.deepEqual(res.headers['x-request-id'], reqId, 'Returned request ID does not match the sent one');
assert.findRequests(() => true).forEach((req) => {
assert.deepEqual(getHeader(req, 'x-request-id'), reqId, 'Request ID mismatch');
});
})
.finally(() => assert.cleanupRecorder());
});
it('should set the request ID for a 404', () => {
const reqId = '9c54ff673d634b31bb28d60aae1cb43c';
assert.recordRequests();
return preq.get({
uri: `${server.config.bucketURL('en.wikipedia.beta.wmflabs.org')}/foo-bucket/Foobar`,
headers: {
'X-Request-Id': reqId
}
}).then((res) => {
throw new Error(`Expected a 404, got ${res.status}`);
}, (err) => {
assert.deepEqual(err.headers['x-request-id'], reqId, 'Returned request ID does not match the sent one');
assert.findRequests(() => true).forEach((req) => {
assert.deepEqual(getHeader(req, 'x-request-id'), reqId, 'Request ID mismatch');
});
})
.finally(() => assert.cleanupRecorder());
});
it('should truncate body upon HEAD request', () => {
return preq.head({
uri: `${server.config.bucketURL('en.wikipedia.beta.wmflabs.org')}/html/Foobar`
})
.then((res) => {
assert.deepEqual(res.status, 200);
assert.deepEqual(res.headers['content-length'], undefined);
assert.deepEqual(res.body, '');
});
});
});