75 lines
2.2 KiB
JavaScript
75 lines
2.2 KiB
JavaScript
|
|
/* global describe, before, it, after */
|
||
|
|
|
||
|
|
'use strict';
|
||
|
|
|
||
|
|
const BoxError = require('../boxerror.js'),
|
||
|
|
common = require('./common.js'),
|
||
|
|
expect = require('expect.js'),
|
||
|
|
oidcClients = require('../oidcclients.js'),
|
||
|
|
safe = require('safetydance');
|
||
|
|
|
||
|
|
describe('OIDC Clients', function () {
|
||
|
|
const { setup, cleanup } = common;
|
||
|
|
|
||
|
|
before(setup);
|
||
|
|
after(cleanup);
|
||
|
|
|
||
|
|
let id, secret;
|
||
|
|
const CLIENT_0 = {
|
||
|
|
name: 'test client 0',
|
||
|
|
tokenSignatureAlgorithm: 'RS256',
|
||
|
|
loginRedirectUri: 'http://foo.bar',
|
||
|
|
appId: 'someappid'
|
||
|
|
};
|
||
|
|
|
||
|
|
it('can add oidc client', async function () {
|
||
|
|
const result = await oidcClients.add(CLIENT_0);
|
||
|
|
id = result.id;
|
||
|
|
secret = result.secret;
|
||
|
|
expect(id).to.be.a('string');
|
||
|
|
expect(secret).to.be.a('string');
|
||
|
|
});
|
||
|
|
|
||
|
|
it('cannot get client', async function () {
|
||
|
|
const client = await oidcClients.get(id);
|
||
|
|
expect(client.appId).to.be('someappid');
|
||
|
|
expect(client.secret).to.be(secret);
|
||
|
|
});
|
||
|
|
|
||
|
|
it('cannot get random client', async function () {
|
||
|
|
const client = await oidcClients.get('random');
|
||
|
|
expect(client).to.be(null);
|
||
|
|
});
|
||
|
|
|
||
|
|
it('can list clients', async function () {
|
||
|
|
const clients = await oidcClients.list();
|
||
|
|
expect(clients.length).to.be(1);
|
||
|
|
expect(clients[0].secret).to.be(secret);
|
||
|
|
});
|
||
|
|
|
||
|
|
it('can update client', async function () {
|
||
|
|
const clientCopy = Object.assign({}, CLIENT_0);
|
||
|
|
clientCopy.name = 'newname';
|
||
|
|
await oidcClients.update(id, clientCopy);
|
||
|
|
|
||
|
|
const client = await oidcClients.get(id);
|
||
|
|
expect(client.name).to.be('newname');
|
||
|
|
});
|
||
|
|
|
||
|
|
it('cannot update random client', async function () {
|
||
|
|
const clientCopy = Object.assign({}, CLIENT_0);
|
||
|
|
clientCopy.name = 'newname';
|
||
|
|
const [error] = await safe(oidcClients.update('random', clientCopy));
|
||
|
|
expect(error.reason).to.be(BoxError.NOT_FOUND);
|
||
|
|
});
|
||
|
|
|
||
|
|
it('can del client', async function () {
|
||
|
|
await oidcClients.del(id);
|
||
|
|
});
|
||
|
|
|
||
|
|
it('cannot del random client', async function () {
|
||
|
|
const [error] = await safe(oidcClients.del(id));
|
||
|
|
expect(error.reason).to.be(BoxError.NOT_FOUND);
|
||
|
|
});
|
||
|
|
});
|