Skip to content

Commit

Permalink
Merge branch 'master' into gh-845-guardian-keyword-preservation
Browse files Browse the repository at this point in the history
  • Loading branch information
willvedd authored Nov 22, 2023
2 parents 75281b4 + 672094d commit 20845da
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 27 deletions.
60 changes: 36 additions & 24 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion src/context/yaml/handlers/clientGrants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,17 @@ async function parse(context: YAMLContext): Promise<ParsedClientGrants> {
}

async function dump(context: YAMLContext): Promise<ParsedClientGrants> {
const { clientGrants, clients } = context.assets;
let { clientGrants, clients } = context.assets;

if (!clientGrants) return { clientGrants: null };

if (clients === undefined) {
clients = await context.mgmtClient.clients.getAll({
paginate: true,
include_totals: true,
});
}

// Convert client_id to the client name for readability
return {
clientGrants: clientGrants.map((grant) => {
Expand Down
3 changes: 2 additions & 1 deletion src/context/yaml/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
wrapArrayReplaceMarkersInQuotes,
Auth0,
} from '../../tools';
import pagedClient from '../../tools/auth0/client';

import log from '../../logger';
import { isFile, toConfigFn, stripIdentifiers, formatResults, recordsSorter } from '../../utils';
Expand All @@ -29,7 +30,7 @@ export default class YAMLContext {
this.configFile = config.AUTH0_INPUT_FILE;
this.config = config;
this.mappings = config.AUTH0_KEYWORD_REPLACE_MAPPINGS || {};
this.mgmtClient = mgmtClient
this.mgmtClient = pagedClient(mgmtClient);
this.disableKeywordReplacement = false;

//@ts-ignore because the assets property gets filled out throughout
Expand Down
49 changes: 48 additions & 1 deletion test/context/yaml/clientGrants.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,58 @@ describe('#YAML context client grants', () => {
it('should dump client grants', async () => {
const context = new Context({ AUTH0_INPUT_FILE: './test.yml' }, mockMgmtClient());
const clientGrants = [
{ audience: 'https://test.myapp.com/api/v1', client_id: 'My M2M', scope: ['update:account'] },
{
audience: 'https://test.myapp.com/api/v1',
client_id: 'client-id',
scope: ['update:account'],
},
];
context.assets.clientGrants = clientGrants;

const dumped = await handler.dump(context);
expect(dumped).to.deep.equal({ clientGrants });
});

it('should dump client grants and replace client ID with client name if clients in assets', async () => {
const context = new Context({ AUTH0_INPUT_FILE: './test.yml' }, mockMgmtClient());
const clientGrants = [
{
audience: 'https://test.myapp.com/api/v1',
client_id: 'client-id-1',
scope: ['update:account'],
},
];
context.assets.clientGrants = clientGrants;
context.assets.clients = [{ client_id: 'client-id-1', name: 'Client 1' }];

const dumped = await handler.dump(context);
const expected = (() => {
const ret = clientGrants;
ret[0].client_id = 'Client 1';
return { clientGrants: ret };
})();
expect(dumped).to.deep.equal(expected);
});

it('should dump client grants and replace client ID with client name even if clients not in assets', async () => {
const mockMgmt = mockMgmtClient();
mockMgmt.clients.getAll = () => [[{ client_id: 'client-id-1', name: 'Client 1' }]];
const context = new Context({ AUTH0_INPUT_FILE: './test.yml' }, mockMgmt);
const clientGrants = [
{
audience: 'https://test.myapp.com/api/v1',
client_id: 'client-id-1',
scope: ['update:account'],
},
];
context.assets.clientGrants = clientGrants;

const dumped = await handler.dump(context);
const expected = (() => {
const ret = clientGrants;
ret[0].client_id = 'Client 1';
return { clientGrants: ret };
})();
expect(dumped).to.deep.equal(expected);
});
});

0 comments on commit 20845da

Please sign in to comment.