Experimental port to Firebase hosting
This commit is contained in:
@ -1,39 +0,0 @@
|
||||
const AuthAPI = require('../AuthAPI');
|
||||
|
||||
describe('Auth API', () => {
|
||||
beforeEach(done => {
|
||||
AuthAPI.removeAllRevokedTokens().then(() => done(), done);
|
||||
});
|
||||
|
||||
it('creates tokens with the right scopes', done => {
|
||||
const scopes = {
|
||||
blacklist: {
|
||||
add: true,
|
||||
remove: true
|
||||
}
|
||||
};
|
||||
|
||||
AuthAPI.createToken(scopes).then(token => {
|
||||
AuthAPI.verifyToken(token).then(payload => {
|
||||
expect(payload.jti).toEqual(expect.any(String));
|
||||
expect(payload.iss).toEqual(expect.any(String));
|
||||
expect(payload.iat).toEqual(expect.any(Number));
|
||||
expect(payload.scopes).toMatchObject(scopes);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('refuses to verify revoked tokens', done => {
|
||||
const scopes = {};
|
||||
|
||||
AuthAPI.createToken(scopes).then(token => {
|
||||
AuthAPI.revokeToken(token).then(() => {
|
||||
AuthAPI.verifyToken(token).then(payload => {
|
||||
expect(payload).toBe(null);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
@ -1,24 +0,0 @@
|
||||
const BlacklistAPI = require('../BlacklistAPI');
|
||||
|
||||
describe('Blacklist API', () => {
|
||||
beforeEach(done => {
|
||||
BlacklistAPI.removeAllPackages().then(() => done(), done);
|
||||
});
|
||||
|
||||
it('adds and removes packages to/from the blacklist', done => {
|
||||
const packageName = 'bad-package';
|
||||
|
||||
BlacklistAPI.addPackage(packageName).then(() => {
|
||||
BlacklistAPI.getPackages().then(packageNames => {
|
||||
expect(packageNames).toEqual([packageName]);
|
||||
|
||||
BlacklistAPI.removePackage(packageName).then(() => {
|
||||
BlacklistAPI.getPackages().then(packageNames => {
|
||||
expect(packageNames).toEqual([]);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
@ -1,8 +1,8 @@
|
||||
const request = require('supertest');
|
||||
import request from 'supertest';
|
||||
|
||||
const createServer = require('../createServer');
|
||||
const withRevokedToken = require('./utils/withRevokedToken');
|
||||
const withToken = require('./utils/withToken');
|
||||
import createServer from '../createServer';
|
||||
import withRevokedToken from './utils/withRevokedToken';
|
||||
import withToken from './utils/withToken';
|
||||
|
||||
describe('The /_auth endpoint', () => {
|
||||
let server;
|
||||
|
@ -1,8 +1,8 @@
|
||||
const request = require('supertest');
|
||||
import request from 'supertest';
|
||||
|
||||
const createServer = require('../createServer');
|
||||
const clearBlacklist = require('./utils/clearBlacklist');
|
||||
const withToken = require('./utils/withToken');
|
||||
import createServer from '../createServer';
|
||||
import clearBlacklist from './utils/clearBlacklist';
|
||||
import withToken from './utils/withToken';
|
||||
|
||||
describe('The /_blacklist endpoint', () => {
|
||||
let server;
|
||||
|
@ -1,6 +1,6 @@
|
||||
const request = require('supertest');
|
||||
import request from 'supertest';
|
||||
|
||||
const createServer = require('../createServer');
|
||||
import createServer from '../createServer';
|
||||
|
||||
describe('The /_publicKey endpoint', () => {
|
||||
let server;
|
||||
|
@ -1,9 +1,9 @@
|
||||
const request = require('supertest');
|
||||
import request from 'supertest';
|
||||
|
||||
const createServer = require('../createServer');
|
||||
const withAuthHeader = require('./utils/withAuthHeader');
|
||||
const withRevokedToken = require('./utils/withRevokedToken');
|
||||
const withToken = require('./utils/withToken');
|
||||
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;
|
||||
|
@ -1,8 +1,8 @@
|
||||
const request = require('supertest');
|
||||
import request from 'supertest';
|
||||
|
||||
const createServer = require('../createServer');
|
||||
const clearBlacklist = require('./utils/clearBlacklist');
|
||||
const withToken = require('./utils/withToken');
|
||||
import createServer from '../createServer';
|
||||
import clearBlacklist from './utils/clearBlacklist';
|
||||
import withToken from './utils/withToken';
|
||||
|
||||
describe('The /api/blacklist endpoint', () => {
|
||||
let server;
|
||||
|
@ -1,6 +1,6 @@
|
||||
const request = require('supertest');
|
||||
import request from 'supertest';
|
||||
|
||||
const createServer = require('../createServer');
|
||||
import createServer from '../createServer';
|
||||
|
||||
describe('The /api/publicKey endpoint', () => {
|
||||
let server;
|
||||
|
@ -1,9 +1,8 @@
|
||||
const request = require('supertest');
|
||||
import request from 'supertest';
|
||||
|
||||
const createServer = require('../createServer');
|
||||
|
||||
const clearBlacklist = require('./utils/clearBlacklist');
|
||||
const withBlacklist = require('./utils/withBlacklist');
|
||||
import createServer from '../createServer';
|
||||
import clearBlacklist from './utils/clearBlacklist';
|
||||
import withBlacklist from './utils/withBlacklist';
|
||||
|
||||
describe('The server', () => {
|
||||
let server;
|
||||
|
@ -1,3 +1,3 @@
|
||||
const closeDatabase = require('./utils/closeDatabase');
|
||||
import closeDatabase from './utils/closeDatabase';
|
||||
|
||||
afterAll(closeDatabase);
|
||||
|
@ -1,7 +1,5 @@
|
||||
const BlacklistAPI = require('../../BlacklistAPI');
|
||||
import { removeAllPackages } from '../../utils/blacklist';
|
||||
|
||||
function clearBlacklist(done) {
|
||||
BlacklistAPI.removeAllPackages().then(done, done);
|
||||
export default function clearBlacklist(done) {
|
||||
removeAllPackages().then(done, done);
|
||||
}
|
||||
|
||||
module.exports = clearBlacklist;
|
||||
|
@ -1,7 +1,5 @@
|
||||
const data = require('../../utils/data');
|
||||
import data from '../../utils/data';
|
||||
|
||||
function closeDatabase() {
|
||||
export default function closeDatabase() {
|
||||
data.quit();
|
||||
}
|
||||
|
||||
module.exports = closeDatabase;
|
||||
|
@ -1,13 +1,11 @@
|
||||
const withToken = require('./withToken');
|
||||
import withToken from './withToken';
|
||||
|
||||
function encodeBase64(token) {
|
||||
return Buffer.from(token).toString('base64');
|
||||
}
|
||||
|
||||
function withAuthHeader(scopes, done) {
|
||||
export default function withAuthHeader(scopes, done) {
|
||||
withToken(scopes, token => {
|
||||
done(encodeBase64(token));
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = withAuthHeader;
|
||||
|
@ -1,7 +1,5 @@
|
||||
const BlacklistAPI = require('../../BlacklistAPI');
|
||||
import { addPackage } from '../../utils/blacklist';
|
||||
|
||||
function withBlacklist(blacklist, done) {
|
||||
Promise.all(blacklist.map(BlacklistAPI.addPackage)).then(done);
|
||||
export default function withBlacklist(blacklist, done) {
|
||||
Promise.all(blacklist.map(addPackage)).then(done);
|
||||
}
|
||||
|
||||
module.exports = withBlacklist;
|
||||
|
@ -1,12 +1,10 @@
|
||||
const withToken = require('./withToken');
|
||||
const AuthAPI = require('../../AuthAPI');
|
||||
import { revokeToken } from '../../utils/auth';
|
||||
import withToken from './withToken';
|
||||
|
||||
function withRevokedToken(scopes, done) {
|
||||
export default function withRevokedToken(scopes, done) {
|
||||
withToken(scopes, token => {
|
||||
AuthAPI.revokeToken(token).then(() => {
|
||||
revokeToken(token).then(() => {
|
||||
done(token);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = withRevokedToken;
|
||||
|
@ -1,7 +1,5 @@
|
||||
const AuthAPI = require('../../AuthAPI');
|
||||
import { createToken } from '../../utils/auth';
|
||||
|
||||
function withToken(scopes, done) {
|
||||
AuthAPI.createToken(scopes).then(done);
|
||||
export default function withToken(scopes, done) {
|
||||
createToken(scopes).then(done);
|
||||
}
|
||||
|
||||
module.exports = withToken;
|
||||
|
Reference in New Issue
Block a user