Remove auth
This commit is contained in:
@ -1,65 +0,0 @@
|
||||
import request from 'supertest';
|
||||
|
||||
import createServer from '../createServer';
|
||||
import withRevokedToken from './utils/withRevokedToken';
|
||||
import withToken from './utils/withToken';
|
||||
|
||||
describe('The /_auth endpoint', () => {
|
||||
let server;
|
||||
beforeEach(() => {
|
||||
server = createServer();
|
||||
});
|
||||
|
||||
describe('POST /_auth', () => {
|
||||
it('creates a new auth token', done => {
|
||||
request(server)
|
||||
.post('/_auth')
|
||||
.end((err, res) => {
|
||||
expect(res.body).toHaveProperty('token');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('GET /_auth', () => {
|
||||
describe('with no auth', () => {
|
||||
it('echoes back null', done => {
|
||||
request(server)
|
||||
.get('/_auth')
|
||||
.end((err, res) => {
|
||||
expect(res.body).toHaveProperty('auth');
|
||||
expect(res.body.auth).toBe(null);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('with a revoked auth token', () => {
|
||||
it('echoes back null', done => {
|
||||
withRevokedToken({ some: { scope: true } }, token => {
|
||||
request(server)
|
||||
.get('/_auth?token=' + token)
|
||||
.end((err, res) => {
|
||||
expect(res.body).toHaveProperty('auth');
|
||||
expect(res.body.auth).toBe(null);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('with a valid auth token', () => {
|
||||
it('echoes back the auth payload', done => {
|
||||
withToken({ some: { scope: true } }, token => {
|
||||
request(server)
|
||||
.get('/_auth?token=' + token)
|
||||
.end((err, res) => {
|
||||
expect(res.body).toHaveProperty('auth');
|
||||
expect(typeof res.body.auth).toBe('object');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -1,89 +0,0 @@
|
||||
import request from 'supertest';
|
||||
|
||||
import createServer from '../createServer';
|
||||
import withAuthHeader from './utils/withAuthHeader';
|
||||
import withRevokedToken from './utils/withRevokedToken';
|
||||
import withToken from './utils/withToken';
|
||||
|
||||
describe('The /api/auth endpoint', () => {
|
||||
let server;
|
||||
beforeEach(() => {
|
||||
server = createServer();
|
||||
});
|
||||
|
||||
describe('POST /api/auth', () => {
|
||||
it('creates a new auth token', done => {
|
||||
request(server)
|
||||
.post('/api/auth')
|
||||
.end((err, res) => {
|
||||
expect(res.body).toHaveProperty('token');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('GET /api/auth', () => {
|
||||
describe('with no auth', () => {
|
||||
it('echoes back null', done => {
|
||||
request(server)
|
||||
.get('/api/auth')
|
||||
.end((err, res) => {
|
||||
expect(res.body).toHaveProperty('auth');
|
||||
expect(res.body.auth).toBe(null);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('with a revoked auth token', () => {
|
||||
it('echoes back null', done => {
|
||||
withRevokedToken({ some: { scope: true } }, token => {
|
||||
request(server)
|
||||
.get('/api/auth?token=' + token)
|
||||
.end((err, res) => {
|
||||
expect(res.body).toHaveProperty('auth');
|
||||
expect(res.body.auth).toBe(null);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('with a valid auth token', () => {
|
||||
describe('in the query string', () => {
|
||||
it('echoes back the auth payload', done => {
|
||||
const scopes = { some: { scope: true } };
|
||||
|
||||
withToken(scopes, token => {
|
||||
request(server)
|
||||
.get('/api/auth?token=' + token)
|
||||
.end((err, res) => {
|
||||
expect(res.body).toHaveProperty('auth');
|
||||
expect(res.body.auth).toBeDefined();
|
||||
expect(res.body.auth.scopes).toMatchObject(scopes);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('in the Authorization header', () => {
|
||||
it('echoes back the auth payload', done => {
|
||||
const scopes = { some: { scope: true } };
|
||||
|
||||
withAuthHeader(scopes, header => {
|
||||
request(server)
|
||||
.get('/api/auth')
|
||||
.set({ Authorization: header })
|
||||
.end((err, res) => {
|
||||
expect(res.body).toHaveProperty('auth');
|
||||
expect(res.body.auth).toBeDefined();
|
||||
expect(res.body.auth.scopes).toMatchObject(scopes);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -1,3 +0,0 @@
|
||||
import closeDatabase from './utils/closeDatabase';
|
||||
|
||||
afterAll(closeDatabase);
|
||||
@ -1,5 +0,0 @@
|
||||
import data from '../../utils/data';
|
||||
|
||||
export default function closeDatabase() {
|
||||
data.quit();
|
||||
}
|
||||
@ -1,11 +0,0 @@
|
||||
import withToken from './withToken';
|
||||
|
||||
function encodeBase64(token) {
|
||||
return Buffer.from(token).toString('base64');
|
||||
}
|
||||
|
||||
export default function withAuthHeader(scopes, done) {
|
||||
withToken(scopes, token => {
|
||||
done(encodeBase64(token));
|
||||
});
|
||||
}
|
||||
@ -1,10 +0,0 @@
|
||||
import { revokeToken } from '../../utils/auth';
|
||||
import withToken from './withToken';
|
||||
|
||||
export default function withRevokedToken(scopes, done) {
|
||||
withToken(scopes, token => {
|
||||
revokeToken(token).then(() => {
|
||||
done(token);
|
||||
});
|
||||
});
|
||||
}
|
||||
@ -1,5 +0,0 @@
|
||||
import { createToken } from '../../utils/auth';
|
||||
|
||||
export default function withToken(scopes, done) {
|
||||
createToken(scopes).then(done);
|
||||
}
|
||||
Reference in New Issue
Block a user