-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Optional CORS headers, disabled by default
- Loading branch information
Showing
3 changed files
with
110 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
const assert = require('assert'); | ||
|
||
describe('CORS', function() { | ||
|
||
describe('false (default)', function() { | ||
|
||
let server; | ||
before(function() { | ||
server = this.helpers.createServer({ | ||
lightning: { backend: 'dummy', config: {} }, | ||
}); | ||
return server.onReady(); | ||
}); | ||
|
||
after(function() { | ||
if (server) return server.close(); | ||
}); | ||
|
||
describe('OPTIONS *', function() { | ||
|
||
it('response error', function() { | ||
return this.helpers.request('options', { | ||
url: server.getCallbackUrl(), | ||
}).then(result => { | ||
const { response, body } = result; | ||
assert.strictEqual(response.statusCode, 404); | ||
assert.ok(!response.headers['allow']); | ||
assert.ok(!response.headers['access-control-allow-origin']); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('GET /status', function() { | ||
|
||
it('response does not include CORS headers', function() { | ||
return this.helpers.request('get', { | ||
url: server.getUrl('/status'), | ||
}).then(result => { | ||
const { response, body } = result; | ||
assert.strictEqual(response.statusCode, 200); | ||
assert.ok(!response.headers['access-control-allow-origin']); | ||
assert.deepStrictEqual(body, { | ||
status: 'OK', | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('true', function() { | ||
|
||
let server; | ||
before(function() { | ||
server = this.helpers.createServer({ | ||
lightning: { backend: 'dummy', config: {} }, | ||
cors: true, | ||
}); | ||
return server.onReady(); | ||
}); | ||
|
||
after(function() { | ||
if (server) return server.close(); | ||
}); | ||
|
||
describe('OPTIONS *', function() { | ||
|
||
it('empty response with correct headers', function() { | ||
return this.helpers.request('options', { | ||
url: server.getCallbackUrl(), | ||
}).then(result => { | ||
const { response, body } = result; | ||
assert.strictEqual(response.statusCode, 200); | ||
assert.strictEqual(response.headers['allow'], 'OPTIONS, GET, HEAD'); | ||
assert.strictEqual(response.headers['access-control-allow-origin'], '*'); | ||
assert.strictEqual(body, ''); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('GET /status', function() { | ||
|
||
it('response includes CORS headers', function() { | ||
return this.helpers.request('get', { | ||
url: server.getUrl('/status'), | ||
}).then(result => { | ||
const { response, body } = result; | ||
assert.strictEqual(response.statusCode, 200); | ||
assert.strictEqual(response.headers['access-control-allow-origin'], '*'); | ||
assert.deepStrictEqual(body, { | ||
status: 'OK', | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |