|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +const request = require('supertest'); |
| 4 | +let app; |
| 5 | + |
| 6 | +before(() => { |
| 7 | + app = request(require('../../examples/server')); // eslint-disable-line global-require |
| 8 | +}); |
| 9 | + |
| 10 | +describe('Acceptance Server', () => { |
| 11 | + it('accepts unauthenticated user', done => { |
| 12 | + app.get('/') |
| 13 | + .set('x-forwarded-for', '123.456.789') |
| 14 | + .expect(200) |
| 15 | + .expect('X-User-Auth', 'false') |
| 16 | + .expect('X-RateLimit-Limit', '100') |
| 17 | + .expect('X-RateLimit-Remaining', '99') |
| 18 | + .expect('X-RateLimit-Reset', /[0-9]{10}/) |
| 19 | + .expect('Hello guest (123.456.789)', done); |
| 20 | + }); |
| 21 | + |
| 22 | + it('authenticates user with valid Authorization header', done => { |
| 23 | + app.get('/') |
| 24 | + .set('Authorization', 'Token foo_app1_dev') |
| 25 | + .expect(200) |
| 26 | + .expect('X-User-Auth', 'true') |
| 27 | + .expect('X-User-Provider', 'FOO') |
| 28 | + .expect('X-RateLimit-Limit', '500') |
| 29 | + .expect('X-RateLimit-Remaining', '499') |
| 30 | + .expect('X-RateLimit-Reset', /[0-9]{10}/) |
| 31 | + .expect('Hello FOO (foo_app1)', done); |
| 32 | + }); |
| 33 | + |
| 34 | + it('authenticates user with valid api_key query param', done => { |
| 35 | + app.get('/?api_key=foo_app1_dev') |
| 36 | + .expect(200) |
| 37 | + .expect('X-User-Auth', 'true') |
| 38 | + .expect('X-User-Provider', 'FOO') |
| 39 | + .expect('X-RateLimit-Limit', '500') |
| 40 | + .expect('X-RateLimit-Remaining', '499') |
| 41 | + .expect('X-RateLimit-Reset', /[0-9]{10}/) |
| 42 | + .expect('Hello FOO (foo_app1)', done); |
| 43 | + }); |
| 44 | +}); |
0 commit comments