Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
frederikprijck committed Aug 30, 2023
1 parent 5014c10 commit 9fd5767
Show file tree
Hide file tree
Showing 37 changed files with 794 additions and 1,022 deletions.
42 changes: 36 additions & 6 deletions test/context/context.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { setupContext, filterOnlyIncludedResourceTypes } from '../../src/context
import directoryContext from '../../src/context/directory';
import yamlContext from '../../src/context/yaml';
import { cleanThenMkdir, testDataDir, createDir } from '../utils';
import {AuthApiError} from "auth0";

chai.use(chaiAsPromised);
chai.use(sinonChai);
Expand All @@ -20,6 +21,35 @@ const config = {
AUTH0_ACCESS_TOKEN: 'fake',
};

export const TEST_PRIVATE_KEY = `-----BEGIN PRIVATE KEY-----
MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDx+hc8imR4soBV
9WD9bRey14VqzZfCvEAYbSWctLeZz9xhz+kP+mWxHvv07wi3/ZiYcVYgOYIhxbnt
ugNp78oCFUEsdRrdq2juHlqBtjaYpINQSOqNaKUBt3JRkPPxRLyhwCZ6HJVYy5Wp
4bG6c8eimbglDY4ZwTfUxu1wk3TvMJr9H8tSLwox666NDpxx4ga6kJ06wromShQH
bCS8WlQKI7CpMbnUSrgNJO6QOvu0N97Szl7UwHFVTEuSvDvMGuUPE+Bn4zbrQVSV
Go4oqyTchSR7+9xBpzq36OzXM6zSZqmovJuSzMbCXbBjQlo4s61wvnOLhT3D8Z44
c5VE52frAgMBAAECggEALCx3qXmqNc6AVzDgb+NGfEOT+5dkqQwst0jVoPHswouL
s998sIoJnngFjwVEFjKZdNrb2i4lb3zlIFzg2qoHurGeoDsQmH7+PNoVs7BL7zm5
LyLgjsgXt2SB3hoULmtZ9D1byNcG/JrNy6GEDIGuZCSj1T/QPStkwdc+6VpB8pgW
E8D7jCt40Tik2neYQkDnY775kGAHGWEqpdPCwm+KOnuE1fHx/jk38lmUgYNjKq0h
JK6Ncjen1X+ZsYfGx4dALWG4cqo3lE0YXXuHuvjJV3aVfzH8t7W4fuZ4+8xvdhhV
F4br5FimWLbTe2qT4lSpadkbLm3aBlSUR7eAP0BlwQKBgQD5ayZpP5OMp1zfa4hA
fM8nVUEaVLkRwFK5NChfjHGiaye2RjrnIorXMsFxXjEscgTn2Ux9CgcBhp1fTBhy
6cmhkp1talAIqLBivNQJT0YTfA+uHrHTTyMfEUgsMzPiiAg7FV7BCG6xd/nsk3yg
ZUfoXefrhq9LIHsJx7cK12VViQKBgQD4XKvwYmX5t7fZFBPd7dv5ZrcMHQnBMHd7
is3QhgyKuEgVDzKQ9SA004I9iSvcI3dE/npj31P39N5bbuvYTh4WR/SR4VvXavNG
AqUR7wm8jTlbiWEPgF9MxC24zaa07Kbxs+P8XT/7wWuijf6+baSFgxQMb80fUArv
7guKikCo0wKBgCUn3DIDoZRrfj9eQo7wyN9gKPGmO2e0kd47MeSCBI+gjOrvbWjv
UWWbjwu3b3Xiim6LhYR/EOoeRqViraW4xCvIrqEVHFUd5CDhZmj4oUTXz3It6mnD
OUUwiuLiwdD2WNuMZHA3NF5FtDqVAhTW4a5xBtKkXsq/TPT5BoCb8+GZAoGAUWAD
0gpbgTuJ2G10qPWDaq8V8Lke9haMP4VWNCmHuHfy3juRhN9cAxL+DG2CWmmgbZG3
xjtpRsgLhwfL7J6DyyceYiHltqpLNTgun7ajiQz4qx5TGAImt39bv75aDdOwS2d2
nrxq93EDdEp0Gi7QhhJRolWLbuQKAV0MmQL9dpMCgYEA5+ug3CDI/jyTHG4ZEVoG
qmIg7QoHrVEmZrvCMiFw8bbuBvoMnvu1o1zfvAkNrDfibZyxYKHzSqgeVPQShvLa
P6JCu67ieCGP8C8CMFiQhJ9n4sYGnkzkz67NpkHSzDPA6DfvG4pYuvBQRIefnhYh
IDGpghhKHMV2DAyzeM4cDU8=
-----END PRIVATE KEY-----`;

describe('#context loader validation', async () => {
it('should error on bad file', async () => {
await expect(setupContext(config), 'import').to.be.eventually.rejectedWith(Error);
Expand All @@ -46,9 +76,9 @@ describe('#context loader validation', async () => {
const result = await expect(
setupContext({ ...tmpConfig, AUTH0_INPUT_FILE: dir }),
'import'
).to.be.eventually.rejectedWith(Error);
).to.be.eventually.rejectedWith(AuthApiError);

expect(result).to.be.an('object').that.has.property('name').which.eq('access_denied');
expect(result).to.be.an('error').that.has.property('error').which.eq('access_denied');
});

it('should error while attempting private key JWT generation, but pass validation with client signing key', async () => {
Expand All @@ -72,7 +102,7 @@ describe('#context loader validation', async () => {
expect(result)
.to.be.an('Error')
.that.has.property('message')
.which.eq('secretOrPrivateKey must be an asymmetric key when using RS256');
.which.eq('"pkcs8" must be PKCS#8 formatted string');
});

it('should error while attempting private key JWT generation because of incorrect value for algorithm, but pass validation with client signing key', async () => {
Expand All @@ -82,7 +112,7 @@ describe('#context loader validation', async () => {
cleanThenMkdir(dir);
createDir(dir, {
'.': {
'private.pem': 'some-invalid-private-key',
'private.pem': TEST_PRIVATE_KEY,
},
});

Expand All @@ -97,7 +127,7 @@ describe('#context loader validation', async () => {
expect(result)
.to.be.an('Error')
.that.has.property('message')
.which.eq('"algorithm" must be a valid string enum value');
.which.eq('alg bad value for algorithm is not supported either by JOSE or your javascript runtime');
});

it('should error when secret, private key and auth token are all absent', async () => {
Expand Down Expand Up @@ -155,7 +185,7 @@ describe('#context loader validation', async () => {
expect(loaded).to.be.an.instanceof(yamlContext);

const userAgent =
loaded.mgmtClient.rules.resource.restClient.restClient.options.headers['User-agent'];
loaded.mgmtClient.configuration.headers['User-agent'];

expect(userAgent).to.contain('deploy-cli');
expect(userAgent).to.contain('node.js');
Expand Down
16 changes: 7 additions & 9 deletions test/context/directory/clientGrants.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { constants } from '../../../src/tools';

import Context from '../../../src/context/directory';
import handler from '../../../src/context/directory/handlers/clientGrants';
import { cleanThenMkdir, testDataDir, createDir, mockMgmtClient } from '../../utils';
import { cleanThenMkdir, testDataDir, createDir, mockMgmtClient, mockPagedData } from '../../utils';
import { getFiles, loadJSON } from '../../../src/utils';

describe('#directory context clientGrants', () => {
Expand Down Expand Up @@ -124,8 +124,8 @@ describe('#directory context clientGrants', () => {
{
...mockMgmtClient(),
clients: {
getAll: () => [
[
getAll: (params) =>
mockPagedData(params, 'clients', [
{
client_id: 'client-id-1',
name: 'Primary M2M',
Expand All @@ -134,12 +134,11 @@ describe('#directory context clientGrants', () => {
client_id: 'client-id-2',
name: 'Secondary M2M',
},
],
],
]),
},
resourceServers: {
getAll: () => [
[
getAll: (params) =>
mockPagedData(params, 'resource_servers', [
{
id: 'resource-server-1',
name: 'Payments Service',
Expand All @@ -150,8 +149,7 @@ describe('#directory context clientGrants', () => {
name: 'Auth0 Management API',
identifier: 'https://travel0.us.auth0.com/api/v2',
},
],
],
]),
},
}
);
Expand Down
8 changes: 5 additions & 3 deletions test/context/directory/context.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,14 @@ describe('#directory context validation', () => {
},
},
{
tenant: {
tenants: {
getSettings: async () =>
new Promise((res) =>
res({
friendly_name: 'Production Tenant',
enabled_locales: ['en', 'es'],
data: {
friendly_name: 'Production Tenant',
enabled_locales: ['en', 'es'],
}
})
),
},
Expand Down
47 changes: 0 additions & 47 deletions test/context/directory/migrations.test.js

This file was deleted.

20 changes: 9 additions & 11 deletions test/context/yaml/context.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import jsYaml from 'js-yaml';
import { expect } from 'chai';

import Context from '../../../src/context/yaml';
import { cleanThenMkdir, testDataDir, mockMgmtClient } from '../../utils';
import { cleanThenMkdir, testDataDir, mockMgmtClient, mockPagedData } from '../../utils';

describe('#YAML context validation', () => {
it('should do nothing on empty yaml', async () => {
Expand Down Expand Up @@ -247,7 +247,6 @@ describe('#YAML context validation', () => {
guardianFactors: [],
guardianFactorProviders: [],
guardianFactorTemplates: [],
migrations: {},
guardianPhoneFactorMessageTypes: { message_types: ['sms'] },
guardianPhoneFactorSelectedProvider: { provider: 'twilio' },
guardianPolicies: { policies: [] },
Expand Down Expand Up @@ -359,7 +358,6 @@ describe('#YAML context validation', () => {
guardianFactors: [],
guardianFactorProviders: [],
guardianFactorTemplates: [],
migrations: {},
guardianPhoneFactorMessageTypes: { message_types: ['sms'] },
guardianPhoneFactorSelectedProvider: { provider: 'twilio' },
guardianPolicies: { policies: [] },
Expand Down Expand Up @@ -472,7 +470,6 @@ describe('#YAML context validation', () => {
guardianFactors: [],
guardianFactorProviders: [],
guardianFactorTemplates: [],
migrations: {},
guardianPhoneFactorMessageTypes: { message_types: ['sms'] },
guardianPhoneFactorSelectedProvider: { provider: 'twilio' },
guardianPolicies: { policies: [] },
Expand Down Expand Up @@ -565,27 +562,28 @@ describe('#YAML context validation', () => {
},
},
{
tenant: {
tenants: {
getSettings: async () =>
new Promise((res) =>
res({
friendly_name: 'Production Tenant',
enabled_locales: ['en', 'es'],
data: {
friendly_name: 'Production Tenant',
enabled_locales: ['en', 'es'],
},
})
),
},
connections: {
getAll: () => ({
connections: [
getAll: (params) =>
mockPagedData(params, 'connections', [
{
name: 'connection-1',
strategy: 'waad',
options: {
tenant_domain: 'travel0.com',
},
},
],
}),
]),
},
}
);
Expand Down
58 changes: 0 additions & 58 deletions test/context/yaml/migrations.test.js

This file was deleted.

Loading

0 comments on commit 9fd5767

Please sign in to comment.