From 2eb7e09a425abc96d03b6841a461bf5bb84bc4c1 Mon Sep 17 00:00:00 2001 From: Will Vedder Date: Tue, 21 Feb 2023 15:35:29 -0500 Subject: [PATCH 1/7] Renaming load to loadAssetsFromLocal --- src/commands/import.ts | 2 +- src/context/directory/index.ts | 2 +- src/context/yaml/index.ts | 2 +- test/context/directory/actions.test.js | 6 +++--- test/context/directory/attackProtection.test.js | 4 ++-- test/context/directory/branding.test.js | 6 +++--- test/context/directory/clientGrants.test.js | 6 +++--- test/context/directory/clients.test.js | 6 +++--- test/context/directory/connections.test.js | 10 +++++----- test/context/directory/context.test.js | 14 +++++++------- test/context/directory/databases.test.js | 10 +++++----- test/context/directory/emailProvider.test.js | 2 +- test/context/directory/emailTemplates.test.js | 6 +++--- .../directory/guardianFactorProviders.test.js | 2 +- .../directory/guardianFactorTemplates.test.js | 2 +- test/context/directory/guardianFactors.test.js | 2 +- .../guardianPhoneFactorMessageTypes.test.js | 2 +- .../guardianPhoneFactorSelectedProvider.test.js | 2 +- test/context/directory/guardianPolicies.test.js | 2 +- test/context/directory/hooks.test.js | 6 +++--- test/context/directory/migrations.test.js | 2 +- test/context/directory/organizations.test.js | 4 ++-- test/context/directory/pages.test.js | 8 ++++---- test/context/directory/prompts.test.ts | 6 +++--- test/context/directory/resourceServers.js | 6 +++--- test/context/directory/roles.test.js | 6 +++--- test/context/directory/rules.test.js | 6 +++--- test/context/directory/rulesConfigs.js | 6 +++--- test/context/directory/tenant.test.js | 4 ++-- test/context/directory/themes.test.js | 4 ++-- test/context/directory/triggers.test.js | 4 ++-- test/context/yaml/actions.test.js | 2 +- test/context/yaml/attackProtection.test.js | 2 +- test/context/yaml/branding.test.js | 2 +- test/context/yaml/clientGrants.test.js | 2 +- test/context/yaml/clients.test.js | 2 +- test/context/yaml/connections.test.js | 6 ++++-- test/context/yaml/context.test.js | 14 +++++++------- test/context/yaml/customDomains.test.ts | 2 +- test/context/yaml/databases.test.js | 4 ++-- test/context/yaml/emailProvider.test.js | 2 +- test/context/yaml/emailTemplates.test.js | 2 +- test/context/yaml/guardianFactorProviders.test.js | 2 +- test/context/yaml/guardianFactorTemplates.test.js | 2 +- test/context/yaml/guardianFactors.test.js | 2 +- .../yaml/guardianPhoneFactorMessageTypes.test.js | 2 +- .../guardianPhoneFactorSelectedProvider.test.js | 2 +- test/context/yaml/guardianPolicies.test.js | 4 ++-- test/context/yaml/hooks.test.js | 2 +- test/context/yaml/logStreams.test.js | 2 +- test/context/yaml/migrations.test.js | 2 +- test/context/yaml/organizations.test.js | 2 +- test/context/yaml/pages.test.js | 4 ++-- test/context/yaml/prompts.test.ts | 2 +- test/context/yaml/resourceServers.test.js | 2 +- test/context/yaml/roles.test.js | 2 +- test/context/yaml/rules.test.js | 2 +- test/context/yaml/rulesConfigs.test.js | 2 +- test/context/yaml/tenant.test.js | 4 ++-- test/context/yaml/themes.test.js | 4 ++-- test/context/yaml/triggers.test.js | 2 +- 61 files changed, 119 insertions(+), 117 deletions(-) diff --git a/src/commands/import.ts b/src/commands/import.ts index f84c85897..656a19e72 100644 --- a/src/commands/import.ts +++ b/src/commands/import.ts @@ -43,7 +43,7 @@ export default async function importCMD(params: ImportParams) { // Setup context and load const context = await setupContext(nconf.get()); - await context.load(); + await context.loadAssetsFromLocal(); const config = configFactory(); config.setProvider((key) => nconf.get(key)); diff --git a/src/context/directory/index.ts b/src/context/directory/index.ts index b2a97f491..6ede04971 100644 --- a/src/context/directory/index.ts +++ b/src/context/directory/index.ts @@ -47,7 +47,7 @@ export default class DirectoryContext { return loadFileAndReplaceKeywords(toLoad, this.mappings); } - async load(): Promise { + async loadAssetsFromLocal(): Promise { if (isDirectory(this.filePath)) { /* If this is a directory, look for each file in the directory */ log.info(`Processing directory ${this.filePath}`); diff --git a/src/context/yaml/index.ts b/src/context/yaml/index.ts index c546cbb33..f3d6bd178 100644 --- a/src/context/yaml/index.ts +++ b/src/context/yaml/index.ts @@ -52,7 +52,7 @@ export default class YAMLContext { return loadFileAndReplaceKeywords(path.resolve(toLoad), this.mappings); } - async load() { + async loadAssetsFromLocal() { // Allow to send object/json directly if (typeof this.configFile === 'object') { this.assets = this.configFile; diff --git a/test/context/directory/actions.test.js b/test/context/directory/actions.test.js index 945c530b1..20e9f8faf 100644 --- a/test/context/directory/actions.test.js +++ b/test/context/directory/actions.test.js @@ -95,7 +95,7 @@ describe('#directory context actions', () => { AUTH0_KEYWORD_REPLACE_MAPPINGS: { replace: 'test-action' }, }; const context = new Context(config, mockMgmtClient()); - await context.load(); + await context.loadAssetsFromLocal(); expect(context.assets.actions).to.deep.equal(actionsTarget); }); @@ -107,7 +107,7 @@ describe('#directory context actions', () => { AUTH0_KEYWORD_REPLACE_MAPPINGS: { replace: 'test-action' }, }; const context = new Context(config, mockMgmtClient()); - await context.load(); + await context.loadAssetsFromLocal(); expect(context.assets.actions).to.deep.equal(actionsTarget); }); @@ -119,7 +119,7 @@ describe('#directory context actions', () => { const context = new Context({ AUTH0_INPUT_FILE: repoDir }); const errorMessage = `Expected ${dir} to be a folder but got a file?`; - await expect(context.load()) + await expect(context.loadAssetsFromLocal()) .to.be.eventually.rejectedWith(Error) .and.have.property('message', errorMessage); }); diff --git a/test/context/directory/attackProtection.test.js b/test/context/directory/attackProtection.test.js index f4319e282..b5e3cf766 100644 --- a/test/context/directory/attackProtection.test.js +++ b/test/context/directory/attackProtection.test.js @@ -31,7 +31,7 @@ describe('#directory context attack-protection', () => { }; const context = new Context(config, mockMgmtClient()); - await context.load(); + await context.loadAssetsFromLocal(); const target = { breachedPasswordDetection: { @@ -84,7 +84,7 @@ describe('#directory context attack-protection', () => { const config = { AUTH0_INPUT_FILE: repoDir }; const context = new Context(config, mockMgmtClient()); - await context.load(); + await context.loadAssetsFromLocal(); const target = { breachedPasswordDetection: { diff --git a/test/context/directory/branding.test.js b/test/context/directory/branding.test.js index 85f778138..55ce908fc 100644 --- a/test/context/directory/branding.test.js +++ b/test/context/directory/branding.test.js @@ -39,7 +39,7 @@ describe('#directory context branding', () => { const config = { AUTH0_INPUT_FILE: dir, AUTH0_KEYWORD_REPLACE_MAPPINGS: { foo: 'bar' } }; const context = new Context(config, mockMgmtClient()); - await context.load(); + await context.loadAssetsFromLocal(); expect(context.assets.branding).to.be.an('object'); expect(context.assets.branding.templates).to.deep.equal([ @@ -66,7 +66,7 @@ describe('#directory context branding', () => { const config = { AUTH0_INPUT_FILE: dir, AUTH0_KEYWORD_REPLACE_MAPPINGS: { foo: 'bar' } }; const context = new Context(config, mockMgmtClient()); - await context.load(); + await context.loadAssetsFromLocal(); expect(context.assets.branding).to.deep.equal({ templates: [ @@ -88,7 +88,7 @@ describe('#directory context branding', () => { const config = { AUTH0_INPUT_FILE: dir, AUTH0_KEYWORD_REPLACE_MAPPINGS: { foo: 'bar' } }; const context = new Context(config, mockMgmtClient()); - await context.load(); + await context.loadAssetsFromLocal(); expect(context.assets.branding).to.deep.equal(JSON.parse(brandingSettings)); }); diff --git a/test/context/directory/clientGrants.test.js b/test/context/directory/clientGrants.test.js index 085ce62f9..ba6abbfd6 100644 --- a/test/context/directory/clientGrants.test.js +++ b/test/context/directory/clientGrants.test.js @@ -42,7 +42,7 @@ describe('#directory context clientGrants', () => { AUTH0_KEYWORD_REPLACE_MAPPINGS: { var: 'something' }, }; const context = new Context(config, mockMgmtClient()); - await context.load(); + await context.loadAssetsFromLocal(); expect(context.assets.clientGrants).to.deep.equal([ { @@ -88,7 +88,7 @@ describe('#directory context clientGrants', () => { AUTH0_KEYWORD_REPLACE_MAPPINGS: { var: 'something' }, }; const context = new Context(config, mockMgmtClient()); - await context.load(); + await context.loadAssetsFromLocal(); const target = [ { @@ -112,7 +112,7 @@ describe('#directory context clientGrants', () => { const context = new Context(config, mockMgmtClient()); const errorMessage = `Expected ${dir} to be a folder but got a file?`; - await expect(context.load()) + await expect(context.loadAssetsFromLocal()) .to.be.eventually.rejectedWith(Error) .and.have.property('message', errorMessage); }); diff --git a/test/context/directory/clients.test.js b/test/context/directory/clients.test.js index bc88f2d01..a1f12d115 100644 --- a/test/context/directory/clients.test.js +++ b/test/context/directory/clients.test.js @@ -29,7 +29,7 @@ describe('#directory context clients', () => { AUTH0_KEYWORD_REPLACE_MAPPINGS: { appType: 'spa' }, }; const context = new Context(config, mockMgmtClient()); - await context.load(); + await context.loadAssetsFromLocal(); const target = [ { app_type: 'spa', name: 'customLoginClient', custom_login_page: 'html code spa "spa"' }, @@ -55,7 +55,7 @@ describe('#directory context clients', () => { AUTH0_KEYWORD_REPLACE_MAPPINGS: { appType: 'spa' }, }; const context = new Context(config, mockMgmtClient()); - await context.load(); + await context.loadAssetsFromLocal(); const target = [{ app_type: 'spa', name: 'someClient' }]; @@ -72,7 +72,7 @@ describe('#directory context clients', () => { const context = new Context(config, mockMgmtClient()); const errorMessage = `Expected ${dir} to be a folder but got a file?`; - await expect(context.load()) + await expect(context.loadAssetsFromLocal()) .to.be.eventually.rejectedWith(Error) .and.have.property('message', errorMessage); }); diff --git a/test/context/directory/connections.test.js b/test/context/directory/connections.test.js index 1da456fd3..7df170cdd 100644 --- a/test/context/directory/connections.test.js +++ b/test/context/directory/connections.test.js @@ -29,7 +29,7 @@ describe('#directory context connections', () => { AUTH0_KEYWORD_REPLACE_MAPPINGS: { secret: 'test secret', var: 'something' }, }; const context = new Context(config, mockMgmtClient()); - await context.load(); + await context.loadAssetsFromLocal(); const target = [ { name: 'myad-waad', strategy: 'waad', var: 'something' }, @@ -62,7 +62,7 @@ describe('#directory context connections', () => { AUTH0_CONNECTIONS_DIRECTORY: customConnectionDirectory, }; const context = new Context(config, mockMgmtClient()); - await context.load(); + await context.loadAssetsFromLocal(); const target = [{ name: 'A Connection' }]; @@ -85,7 +85,7 @@ describe('#directory context connections', () => { AUTH0_KEYWORD_REPLACE_MAPPINGS: { var: 'something' }, }; const context = new Context(config, mockMgmtClient()); - await context.load(); + await context.loadAssetsFromLocal(); const target = [{ name: 'myad-waad', strategy: 'waad', var: 'something' }]; @@ -102,7 +102,7 @@ describe('#directory context connections', () => { const context = new Context(config, mockMgmtClient()); const errorMessage = `Expected ${dir} to be a folder but got a file?`; - await expect(context.load()) + await expect(context.loadAssetsFromLocal()) .to.be.eventually.rejectedWith(Error) .and.have.property('message', errorMessage); }); @@ -217,7 +217,7 @@ describe('#directory context connections', () => { mockMgmtClient() ); - await expect(context.load()).to.be.eventually.rejectedWith( + await expect(context.loadAssetsFromLocal()).to.be.eventually.rejectedWith( `Passwordless email template purportedly located at ${path.join( repoDir, 'connections', diff --git a/test/context/directory/context.test.js b/test/context/directory/context.test.js index 9a577e0a9..ab3fcf6b4 100644 --- a/test/context/directory/context.test.js +++ b/test/context/directory/context.test.js @@ -13,7 +13,7 @@ describe('#directory context validation', () => { cleanThenMkdir(dir); const context = new Context({ AUTH0_INPUT_FILE: dir }); - await context.load(); + await context.loadAssetsFromLocal(); expect(Object.keys(context.assets).length).to.equal(Object.keys(handlers).length + 1); Object.keys(context.assets).forEach((key) => { @@ -47,7 +47,7 @@ describe('#directory context validation', () => { AUTH0_EXCLUDED_DEFAULTS: ['emailProvider'], }; const context = new Context(config); - await context.load(); + await context.loadAssetsFromLocal(); expect(context.assets.exclude.rules).to.deep.equal(['rule']); expect(context.assets.exclude.clients).to.deep.equal(['client']); @@ -72,14 +72,14 @@ describe('#directory context validation', () => { AUTH0_INPUT_FILE: dir, AUTH0_EXCLUDED: ['tenant'], }); - await contextWithExclusion.load(); + await contextWithExclusion.loadAssetsFromLocal(); expect(contextWithExclusion.assets.tenant).to.equal(undefined); const contextWithoutExclusion = new Context({ AUTH0_INPUT_FILE: dir, AUTH0_EXCLUDED: [], // Not excluding tenant resource }); - await contextWithoutExclusion.load(); + await contextWithoutExclusion.loadAssetsFromLocal(); expect(contextWithoutExclusion.assets.tenant).to.deep.equal(tenantConfig); }); @@ -98,7 +98,7 @@ describe('#directory context validation', () => { AUTH0_INPUT_FILE: dir, AUTH0_INCLUDED_ONLY: ['tenant'], }); - await contextWithInclusion.load(); + await contextWithInclusion.loadAssetsFromLocal(); expect(contextWithInclusion.assets.tenant).to.deep.equal(tenantConfig); expect(contextWithInclusion.assets.actions).to.equal(undefined); // Arbitrary sample resources expect(contextWithInclusion.assets.clients).to.equal(undefined); // Arbitrary sample resources @@ -108,7 +108,7 @@ describe('#directory context validation', () => { const dir = path.resolve(testDataDir, 'directory', 'doesNotExist'); const context = new Context({ AUTH0_INPUT_FILE: dir }); const errorMessage = `Not sure what to do with, ${dir} as it is not a directory...`; - await expect(context.load()) + await expect(context.loadAssetsFromLocal()) .to.be.eventually.rejectedWith(Error) .and.have.property('message', errorMessage); }); @@ -128,7 +128,7 @@ describe('#directory context validation', () => { const context = new Context({ AUTH0_INPUT_FILE: link }); const errorMessage = `Not sure what to do with, ${link} as it is not a directory...`; - await expect(context.load()) + await expect(context.loadAssetsFromLocal()) .to.be.eventually.rejectedWith(Error) .and.have.property('message', errorMessage); }); diff --git a/test/context/directory/databases.test.js b/test/context/directory/databases.test.js index 7282da04d..30557d371 100644 --- a/test/context/directory/databases.test.js +++ b/test/context/directory/databases.test.js @@ -32,7 +32,7 @@ describe('#directory context databases', () => { const config = { AUTH0_INPUT_FILE: repoDir, AUTH0_KEYWORD_REPLACE_MAPPINGS: { env: 'test' } }; const context = new Context(config, mockMgmtClient()); - await context.load(); + await context.loadAssetsFromLocal(); expect(context.assets.databases).to.deep.equal([ { @@ -56,7 +56,7 @@ describe('#directory context databases', () => { const config = { AUTH0_INPUT_FILE: repoDir, AUTH0_KEYWORD_REPLACE_MAPPINGS: { env: 'test' } }; const context = new Context(config, mockMgmtClient()); - await context.load(); + await context.loadAssetsFromLocal(); expect(context.assets.databases).to.deep.equal([]); }); @@ -71,7 +71,7 @@ describe('#directory context databases', () => { const context = new Context(config, mockMgmtClient()); const errorMessage = `Expected ${dir} to be a folder but got a file?`; - await expect(context.load()) + await expect(context.loadAssetsFromLocal()) .to.be.eventually.rejectedWith(Error) .and.have.property('message', errorMessage); }); @@ -112,7 +112,7 @@ describe('#directory context databases', () => { const config = { AUTH0_INPUT_FILE: repoDir, AUTH0_KEYWORD_REPLACE_MAPPINGS: { env: 'test' } }; const context = new Context(config, mockMgmtClient()); - await context.load(); + await context.loadAssetsFromLocal(); expect(context.assets.databases).to.deep.equal([ { @@ -144,7 +144,7 @@ describe('#directory context databases', () => { const config = { AUTH0_INPUT_FILE: repoDir, AUTH0_KEYWORD_REPLACE_MAPPINGS: { env: 'test' } }; const context = new Context(config, mockMgmtClient()); - await context.load(); + await context.loadAssetsFromLocal(); expect(context.assets.databases).to.deep.equal([ { diff --git a/test/context/directory/emailProvider.test.js b/test/context/directory/emailProvider.test.js index 511b75805..af7a60a5e 100644 --- a/test/context/directory/emailProvider.test.js +++ b/test/context/directory/emailProvider.test.js @@ -20,7 +20,7 @@ describe('#directory context email provider', () => { const config = { AUTH0_INPUT_FILE: repoDir, AUTH0_KEYWORD_REPLACE_MAPPINGS: { env: 'test' } }; const context = new Context(config, mockMgmtClient()); - await context.load(); + await context.loadAssetsFromLocal(); expect(context.assets.emailProvider).to.deep.equal({ enabled: true, diff --git a/test/context/directory/emailTemplates.test.js b/test/context/directory/emailTemplates.test.js index 8278fa91e..1e0ca200d 100644 --- a/test/context/directory/emailTemplates.test.js +++ b/test/context/directory/emailTemplates.test.js @@ -42,7 +42,7 @@ describe('#directory context email templates', () => { const config = { AUTH0_INPUT_FILE: repoDir, AUTH0_KEYWORD_REPLACE_MAPPINGS: { env: 'test' } }; const context = new Context(config, mockMgmtClient()); - await context.load(); + await context.loadAssetsFromLocal(); expect(context.assets.emailTemplates).to.deep.equal(emailTemplaesTarget); }); @@ -60,7 +60,7 @@ describe('#directory context email templates', () => { createDir(dir, files); const config = { AUTH0_INPUT_FILE: repoDir, AUTH0_KEYWORD_REPLACE_MAPPINGS: { env: 'test' } }; const context = new Context(config, mockMgmtClient()); - await context.load(); + await context.loadAssetsFromLocal(); expect(context.assets.emailTemplates).to.deep.equal(emailTemplaesTarget); }); @@ -73,7 +73,7 @@ describe('#directory context email templates', () => { const context = new Context({ AUTH0_INPUT_FILE: repoDir }); const errorMessage = `Expected ${dir} to be a folder but got a file?`; - await expect(context.load()) + await expect(context.loadAssetsFromLocal()) .to.be.eventually.rejectedWith(Error) .and.have.property('message', errorMessage); }); diff --git a/test/context/directory/guardianFactorProviders.test.js b/test/context/directory/guardianFactorProviders.test.js index 6128d1dd3..67090fd30 100644 --- a/test/context/directory/guardianFactorProviders.test.js +++ b/test/context/directory/guardianFactorProviders.test.js @@ -25,7 +25,7 @@ describe('#directory context guardian factors providers provider', () => { const config = { AUTH0_INPUT_FILE: repoDir, AUTH0_KEYWORD_REPLACE_MAPPINGS: { env: 'test' } }; const context = new Context(config, mockMgmtClient()); - await context.load(); + await context.loadAssetsFromLocal(); expect(context.assets.guardianFactorProviders).to.deep.equal([ { diff --git a/test/context/directory/guardianFactorTemplates.test.js b/test/context/directory/guardianFactorTemplates.test.js index 8425fc739..38ab6ca7d 100644 --- a/test/context/directory/guardianFactorTemplates.test.js +++ b/test/context/directory/guardianFactorTemplates.test.js @@ -23,7 +23,7 @@ describe('#directory context guardian factors templates provider', () => { const config = { AUTH0_INPUT_FILE: repoDir, AUTH0_KEYWORD_REPLACE_MAPPINGS: { env: 'test' } }; const context = new Context(config, mockMgmtClient()); - await context.load(); + await context.loadAssetsFromLocal(); expect(context.assets.guardianFactorTemplates).to.deep.equal([ { diff --git a/test/context/directory/guardianFactors.test.js b/test/context/directory/guardianFactors.test.js index 51334b21e..9080bcbfc 100644 --- a/test/context/directory/guardianFactors.test.js +++ b/test/context/directory/guardianFactors.test.js @@ -26,7 +26,7 @@ describe('#directory context guardian factors provider', () => { const config = { AUTH0_INPUT_FILE: repoDir, AUTH0_KEYWORD_REPLACE_MAPPINGS: { env: 'test' } }; const context = new Context(config, mockMgmtClient()); - await context.load(); + await context.loadAssetsFromLocal(); expect(context.assets.guardianFactors).to.deep.equal([ { enabled: true, name: 'otp' }, diff --git a/test/context/directory/guardianPhoneFactorMessageTypes.test.js b/test/context/directory/guardianPhoneFactorMessageTypes.test.js index daa76d4c9..b1b8bfcd4 100644 --- a/test/context/directory/guardianPhoneFactorMessageTypes.test.js +++ b/test/context/directory/guardianPhoneFactorMessageTypes.test.js @@ -19,7 +19,7 @@ describe('#directory context guardian phone factor message types provider', () = const config = { AUTH0_INPUT_FILE: repoDir, AUTH0_KEYWORD_REPLACE_MAPPINGS: { env: 'test' } }; const context = new Context(config, mockMgmtClient()); - await context.load(); + await context.loadAssetsFromLocal(); expect(context.assets.guardianPhoneFactorMessageTypes).to.deep.equal({ message_types: ['sms', 'voice'], diff --git a/test/context/directory/guardianPhoneFactorSelectedProvider.test.js b/test/context/directory/guardianPhoneFactorSelectedProvider.test.js index f06ddddb1..5757edb47 100644 --- a/test/context/directory/guardianPhoneFactorSelectedProvider.test.js +++ b/test/context/directory/guardianPhoneFactorSelectedProvider.test.js @@ -19,7 +19,7 @@ describe('#directory context guardian phone factor selected provider', () => { const config = { AUTH0_INPUT_FILE: repoDir, AUTH0_KEYWORD_REPLACE_MAPPINGS: { env: 'test' } }; const context = new Context(config, mockMgmtClient()); - await context.load(); + await context.loadAssetsFromLocal(); expect(context.assets.guardianPhoneFactorSelectedProvider).to.deep.equal({ provider: 'twilio', diff --git a/test/context/directory/guardianPolicies.test.js b/test/context/directory/guardianPolicies.test.js index 65b68bba8..1656ef4b2 100644 --- a/test/context/directory/guardianPolicies.test.js +++ b/test/context/directory/guardianPolicies.test.js @@ -21,7 +21,7 @@ describe('#directory context guardian policies provider', () => { const config = { AUTH0_INPUT_FILE: repoDir, AUTH0_KEYWORD_REPLACE_MAPPINGS: { env: 'test' } }; const context = new Context(config, mockMgmtClient()); - await context.load(); + await context.loadAssetsFromLocal(); expect(context.assets.guardianPolicies).to.deep.equal({ policies: ['all-applications'], diff --git a/test/context/directory/hooks.test.js b/test/context/directory/hooks.test.js index cf7f09f70..7439eade2 100644 --- a/test/context/directory/hooks.test.js +++ b/test/context/directory/hooks.test.js @@ -43,7 +43,7 @@ describe('#directory context hooks', () => { AUTH0_KEYWORD_REPLACE_MAPPINGS: { hello: 'goodbye' }, }; const context = new Context(config, mockMgmtClient()); - await context.load(); + await context.loadAssetsFromLocal(); expect(context.assets.hooks).to.deep.equal(hooksTarget); }); @@ -58,7 +58,7 @@ describe('#directory context hooks', () => { AUTH0_KEYWORD_REPLACE_MAPPINGS: { hello: 'goodbye' }, }; const context = new Context(config, mockMgmtClient()); - await context.load(); + await context.loadAssetsFromLocal(); expect(context.assets.hooks).to.deep.equal(hooksTarget); }); @@ -71,7 +71,7 @@ describe('#directory context hooks', () => { const context = new Context({ AUTH0_INPUT_FILE: repoDir }); const errorMessage = `Expected ${dir} to be a folder but got a file?`; - await expect(context.load()) + await expect(context.loadAssetsFromLocal()) .to.be.eventually.rejectedWith(Error) .and.have.property('message', errorMessage); }); diff --git a/test/context/directory/migrations.test.js b/test/context/directory/migrations.test.js index 16fe258d7..93006fb60 100644 --- a/test/context/directory/migrations.test.js +++ b/test/context/directory/migrations.test.js @@ -25,7 +25,7 @@ describe('#directory context migrations', () => { AUTH0_KEYWORD_REPLACE_MAPPINGS: { env: 'test' }, }; const context = new Context(config, mockMgmtClient()); - await context.load(); + await context.loadAssetsFromLocal(); expect(context.assets.migrations).to.deep.equal(migrationsTarget); }); diff --git a/test/context/directory/organizations.test.js b/test/context/directory/organizations.test.js index 18e5c0276..f114efc56 100644 --- a/test/context/directory/organizations.test.js +++ b/test/context/directory/organizations.test.js @@ -24,7 +24,7 @@ describe('#directory context organizations', () => { const config = { AUTH0_INPUT_FILE: repoDir }; const context = new Context(config, mockMgmtClient()); - await context.load(); + await context.loadAssetsFromLocal(); const target = [ { @@ -89,7 +89,7 @@ describe('#directory context organizations', () => { const context = new Context(config, mockMgmtClient()); const errorMessage = `Expected ${dir} to be a folder but got a file?`; - await expect(context.load()) + await expect(context.loadAssetsFromLocal()) .to.be.eventually.rejectedWith(Error) .and.have.property('message', errorMessage); }); diff --git a/test/context/directory/pages.test.js b/test/context/directory/pages.test.js index 55823eb7a..467cb6f27 100644 --- a/test/context/directory/pages.test.js +++ b/test/context/directory/pages.test.js @@ -39,7 +39,7 @@ describe('#directory context pages', () => { const config = { AUTH0_INPUT_FILE: repoDir, AUTH0_KEYWORD_REPLACE_MAPPINGS: { env: 'test' } }; const context = new Context(config, mockMgmtClient()); - await context.load(); + await context.loadAssetsFromLocal(); expect(context.assets.pages).to.deep.equal(pagesTarget); }); @@ -57,7 +57,7 @@ describe('#directory context pages', () => { const config = { AUTH0_INPUT_FILE: repoDir }; const context = new Context(config, mockMgmtClient()); - await context.load(); + await context.loadAssetsFromLocal(); expect(context.assets.pages).to.deep.equal([ { @@ -84,7 +84,7 @@ describe('#directory context pages', () => { const config = { AUTH0_INPUT_FILE: repoDir, AUTH0_KEYWORD_REPLACE_MAPPINGS: { env: 'test' } }; const context = new Context(config, mockMgmtClient()); - await context.load(); + await context.loadAssetsFromLocal(); expect(context.assets.pages).to.deep.equal(pagesTarget); }); @@ -97,7 +97,7 @@ describe('#directory context pages', () => { const context = new Context({ AUTH0_INPUT_FILE: repoDir }); const errorMessage = `Expected ${dir} to be a folder but got a file?`; - await expect(context.load()) + await expect(context.loadAssetsFromLocal()) .to.be.eventually.rejectedWith(Error) .and.have.property('message', errorMessage); }); diff --git a/test/context/directory/prompts.test.ts b/test/context/directory/prompts.test.ts index 0c90914fe..295b8de38 100644 --- a/test/context/directory/prompts.test.ts +++ b/test/context/directory/prompts.test.ts @@ -59,7 +59,7 @@ describe('#directory context prompts', () => { }, }; const context = new Context(config, mockMgmtClient()); - await context.load(); + await context.loadAssetsFromLocal(); expect(context.assets.prompts).to.deep.equal({ universal_login_experience: 'classic', @@ -110,7 +110,7 @@ describe('#directory context prompts', () => { AUTH0_INPUT_FILE: promptsDirectory, }; const context = new Context(config, mockMgmtClient()); - await context.load(); + await context.loadAssetsFromLocal(); expect(context.assets.prompts).to.deep.equal({ ...mockPromptsSettings, customText: {} }); }); @@ -127,7 +127,7 @@ describe('#directory context prompts', () => { AUTH0_INPUT_FILE: promptsDirectory, }; const context = new Context(config, mockMgmtClient()); - await context.load(); + await context.loadAssetsFromLocal(); expect(context.assets.prompts).to.deep.equal({ customText: {} }); }); diff --git a/test/context/directory/resourceServers.js b/test/context/directory/resourceServers.js index a73e04c67..7301dfb74 100644 --- a/test/context/directory/resourceServers.js +++ b/test/context/directory/resourceServers.js @@ -32,7 +32,7 @@ describe('#directory context resourceServers', () => { const config = { AUTH0_INPUT_FILE: repoDir, AUTH0_KEYWORD_REPLACE_MAPPINGS: { env: 'test' } }; const context = new Context(config, mockMgmtClient()); - await context.load(); + await context.loadAssetsFromLocal(); expect(context.assets.resourceServers).to.deep.equal(resourceServersTarget); }); @@ -46,7 +46,7 @@ describe('#directory context resourceServers', () => { createDir(repoDir, { [constants.RESOURCE_SERVERS_DIRECTORY]: invalid }); const config = { AUTH0_INPUT_FILE: repoDir, AUTH0_KEYWORD_REPLACE_MAPPINGS: { env: 'test' } }; const context = new Context(config, mockMgmtClient()); - await context.load(); + await context.loadAssetsFromLocal(); expect(context.assets.resourceServers).to.deep.equal(resourceServersTarget); }); @@ -61,7 +61,7 @@ describe('#directory context resourceServers', () => { const context = new Context(config, mockMgmtClient()); const errorMessage = `Expected ${dir} to be a folder but got a file?`; - await expect(context.load()) + await expect(context.loadAssetsFromLocal()) .to.be.eventually.rejectedWith(Error) .and.have.property('message', errorMessage); }); diff --git a/test/context/directory/roles.test.js b/test/context/directory/roles.test.js index bee164885..4b36e3c3b 100644 --- a/test/context/directory/roles.test.js +++ b/test/context/directory/roles.test.js @@ -24,7 +24,7 @@ describe('#directory context roles', () => { const config = { AUTH0_INPUT_FILE: repoDir }; const context = new Context(config, mockMgmtClient()); - await context.load(); + await context.loadAssetsFromLocal(); const target = [ { @@ -66,7 +66,7 @@ describe('#directory context roles', () => { const config = { AUTH0_INPUT_FILE: repoDir }; const context = new Context(config, mockMgmtClient()); - await context.load(); + await context.loadAssetsFromLocal(); const target = [ { @@ -119,7 +119,7 @@ describe('#directory context roles', () => { const context = new Context(config, mockMgmtClient()); const errorMessage = `Expected ${dir} to be a folder but got a file?`; - await expect(context.load()) + await expect(context.loadAssetsFromLocal()) .to.be.eventually.rejectedWith(Error) .and.have.property('message', errorMessage); }); diff --git a/test/context/directory/rules.test.js b/test/context/directory/rules.test.js index 6afb239e6..d73f9b9a0 100644 --- a/test/context/directory/rules.test.js +++ b/test/context/directory/rules.test.js @@ -32,7 +32,7 @@ describe('#directory context rules', () => { AUTH0_KEYWORD_REPLACE_MAPPINGS: { hello: 'goodbye' }, }; const context = new Context(config, mockMgmtClient()); - await context.load(); + await context.loadAssetsFromLocal(); expect(context.assets.rules).to.deep.equal(rulesTarget); }); @@ -47,7 +47,7 @@ describe('#directory context rules', () => { AUTH0_KEYWORD_REPLACE_MAPPINGS: { hello: 'goodbye' }, }; const context = new Context(config, mockMgmtClient()); - await context.load(); + await context.loadAssetsFromLocal(); expect(context.assets.rules).to.deep.equal(rulesTarget); }); @@ -60,7 +60,7 @@ describe('#directory context rules', () => { const context = new Context({ AUTH0_INPUT_FILE: repoDir }); const errorMessage = `Expected ${dir} to be a folder but got a file?`; - await expect(context.load()) + await expect(context.loadAssetsFromLocal()) .to.be.eventually.rejectedWith(Error) .and.have.property('message', errorMessage); }); diff --git a/test/context/directory/rulesConfigs.js b/test/context/directory/rulesConfigs.js index 0445aaa0b..c8851816d 100644 --- a/test/context/directory/rulesConfigs.js +++ b/test/context/directory/rulesConfigs.js @@ -22,7 +22,7 @@ describe('#directory context rulesConfigs', () => { const config = { AUTH0_INPUT_FILE: repoDir, AUTH0_KEYWORD_REPLACE_MAPPINGS: { env: 'test' } }; const context = new Context(config, mockMgmtClient()); - await context.load(); + await context.loadAssetsFromLocal(); const target = [ { key: 'setting1', value: 'test' }, @@ -44,7 +44,7 @@ describe('#directory context rulesConfigs', () => { const config = { AUTH0_INPUT_FILE: repoDir, AUTH0_KEYWORD_REPLACE_MAPPINGS: { env: 'test' } }; const context = new Context(config, mockMgmtClient()); - await context.load(); + await context.loadAssetsFromLocal(); const target = [{ key: 'setting1', value: 'test' }]; @@ -61,7 +61,7 @@ describe('#directory context rulesConfigs', () => { const context = new Context(config, mockMgmtClient()); const errorMessage = `Expected ${dir} to be a folder but got a file?`; - await expect(context.load()) + await expect(context.loadAssetsFromLocal()) .to.be.eventually.rejectedWith(Error) .and.have.property('message', errorMessage); }); diff --git a/test/context/directory/tenant.test.js b/test/context/directory/tenant.test.js index a79e9dd6b..bed9470f7 100644 --- a/test/context/directory/tenant.test.js +++ b/test/context/directory/tenant.test.js @@ -32,7 +32,7 @@ describe('#directory context tenant', () => { AUTH0_KEYWORD_REPLACE_MAPPINGS: { env: 'test' }, }; const context = new Context(config, mockMgmtClient()); - await context.load(); + await context.loadAssetsFromLocal(); expect(context.assets.tenant).to.deep.equal(tenantTarget); }); @@ -58,7 +58,7 @@ describe('#directory context tenant', () => { AUTH0_KEYWORD_REPLACE_MAPPINGS: { env: 'test' }, }; const context = new Context(config, mockMgmtClient()); - await context.load(); + await context.loadAssetsFromLocal(); expect(context.assets.tenant).to.deep.equal(tenantTarget); }); diff --git a/test/context/directory/themes.test.js b/test/context/directory/themes.test.js index 30898dfd3..df409d472 100644 --- a/test/context/directory/themes.test.js +++ b/test/context/directory/themes.test.js @@ -19,7 +19,7 @@ describe('#directory context themes', () => { const config = { AUTH0_INPUT_FILE: dir, AUTH0_KEYWORD_REPLACE_MAPPINGS: { foo: 'bar' } }; const context = new Context(config, mockMgmtClient()); - await context.load(); + await context.loadAssetsFromLocal(); expect(context.assets.themes).to.be.an('Array'); expect(context.assets.themes).to.deep.equal([theme]); @@ -41,7 +41,7 @@ describe('#directory context themes', () => { const config = { AUTH0_INPUT_FILE: dir, AUTH0_KEYWORD_REPLACE_MAPPINGS: { foo: 'bar' } }; const context = new Context(config, mockMgmtClient()); - await context.load(); + await context.loadAssetsFromLocal(); expect(context.assets.themes).to.be.an('Array'); expect(context.assets.themes).to.deep.equal([theme1, theme2]); diff --git a/test/context/directory/triggers.test.js b/test/context/directory/triggers.test.js index a2dad492a..ea9b17dd7 100644 --- a/test/context/directory/triggers.test.js +++ b/test/context/directory/triggers.test.js @@ -47,7 +47,7 @@ describe('#directory context triggers', () => { createDir(repoDir, actionFiles); const config = { AUTH0_INPUT_FILE: repoDir }; const context = new Context(config, mockMgmtClient()); - await context.load(); + await context.loadAssetsFromLocal(); expect(context.assets.triggers).to.deep.equal(triggersTarget); }); @@ -59,7 +59,7 @@ describe('#directory context triggers', () => { const context = new Context({ AUTH0_INPUT_FILE: repoDir }); const errorMessage = `Expected ${dir} to be a folder but got a file?`; - await expect(context.load()) + await expect(context.loadAssetsFromLocal()) .to.be.eventually.rejectedWith(Error) .and.have.property('message', errorMessage); }); diff --git a/test/context/yaml/actions.test.js b/test/context/yaml/actions.test.js index 711ee309a..449ad2376 100644 --- a/test/context/yaml/actions.test.js +++ b/test/context/yaml/actions.test.js @@ -62,7 +62,7 @@ describe('#YAML context actions', () => { AUTH0_KEYWORD_REPLACE_MAPPINGS: { replace: 'test-action' }, }; const context = new Context(config, mockMgmtClient()); - await context.load(); + await context.loadAssetsFromLocal(); expect(context.assets.actions).to.deep.equal(target); }); diff --git a/test/context/yaml/attackProtection.test.js b/test/context/yaml/attackProtection.test.js index 0dab93f1b..6aa3f0b16 100644 --- a/test/context/yaml/attackProtection.test.js +++ b/test/context/yaml/attackProtection.test.js @@ -77,7 +77,7 @@ describe('#YAML context attack-protection', () => { const config = { AUTH0_INPUT_FILE: yamlFile }; const context = new Context(config, mockMgmtClient()); - await context.load(); + await context.loadAssetsFromLocal(); expect(context.assets.attackProtection).to.deep.equal(target); }); diff --git a/test/context/yaml/branding.test.js b/test/context/yaml/branding.test.js index e4beb4735..b233644ed 100644 --- a/test/context/yaml/branding.test.js +++ b/test/context/yaml/branding.test.js @@ -33,7 +33,7 @@ describe('#YAML context branding templates', () => { const config = { AUTH0_INPUT_FILE: yamlFile, AUTH0_KEYWORD_REPLACE_MAPPINGS: { foo: 'bar' } }; const context = new Context(config, mockMgmtClient()); - await context.load(); + await context.loadAssetsFromLocal(); expect(context.assets.branding).to.deep.equal({ colors: { page_background: '#0f5a1b', diff --git a/test/context/yaml/clientGrants.test.js b/test/context/yaml/clientGrants.test.js index 54a505e55..337905dad 100644 --- a/test/context/yaml/clientGrants.test.js +++ b/test/context/yaml/clientGrants.test.js @@ -33,7 +33,7 @@ describe('#YAML context client grants', () => { const config = { AUTH0_INPUT_FILE: yamlFile, AUTH0_KEYWORD_REPLACE_MAPPINGS: { ENV: 'test' } }; const context = new Context(config, mockMgmtClient()); - await context.load(); + await context.loadAssetsFromLocal(); expect(context.assets.clientGrants).to.deep.equal(target); }); diff --git a/test/context/yaml/clients.test.js b/test/context/yaml/clients.test.js index 03e435d5a..1e5f08a42 100644 --- a/test/context/yaml/clients.test.js +++ b/test/context/yaml/clients.test.js @@ -45,7 +45,7 @@ describe('#YAML context clients', () => { AUTH0_KEYWORD_REPLACE_MAPPINGS: { appType: 'spa' }, }; const context = new Context(config, mockMgmtClient()); - await context.load(); + await context.loadAssetsFromLocal(); expect(context.assets.clients).to.deep.equal(target); }); diff --git a/test/context/yaml/connections.test.js b/test/context/yaml/connections.test.js index fb7665e05..291389d61 100644 --- a/test/context/yaml/connections.test.js +++ b/test/context/yaml/connections.test.js @@ -97,7 +97,7 @@ describe('#YAML context connections', () => { }, }; const context = new Context(config, mockMgmtClient()); - await context.load(); + await context.loadAssetsFromLocal(); expect(context.assets.connections).to.deep.equal(target); }); @@ -128,7 +128,9 @@ describe('#YAML context connections', () => { mockMgmtClient() ); - await expect(context.load()).to.be.eventually.rejectedWith('Problem deploying connections'); + await expect(context.loadAssetsFromLocal()).to.be.eventually.rejectedWith( + 'Problem deploying connections' + ); }); it('should dump connections', async () => { diff --git a/test/context/yaml/context.test.js b/test/context/yaml/context.test.js index 663921fb1..87d34fe1f 100644 --- a/test/context/yaml/context.test.js +++ b/test/context/yaml/context.test.js @@ -16,7 +16,7 @@ describe('#YAML context validation', () => { const config = { AUTH0_INPUT_FILE: yaml }; const context = new Context(config, mockMgmtClient()); - await context.load(); + await context.loadAssetsFromLocal(); expect(context.assets.rules).to.deep.equal(null); expect(context.assets.databases).to.deep.equal(null); @@ -47,7 +47,7 @@ describe('#YAML context validation', () => { }; const context = new Context(config, mockMgmtClient()); - await context.load(); + await context.loadAssetsFromLocal(); expect(context.assets.exclude.rules).to.deep.equal(['rule']); expect(context.assets.exclude.clients).to.deep.equal(['client']); @@ -80,7 +80,7 @@ describe('#YAML context validation', () => { mockMgmtClient() ); - await contextWithExclusion.load(); + await contextWithExclusion.loadAssetsFromLocal(); exclusions.forEach((excludedResource) => { expect(contextWithExclusion.assets[excludedResource]).to.equal(null); // Ensure all excluded resources, defined or not, are null }); @@ -94,7 +94,7 @@ describe('#YAML context validation', () => { mockMgmtClient() ); - await contextWithoutExclusion.load(); + await contextWithoutExclusion.loadAssetsFromLocal(); expect(contextWithoutExclusion.assets.actions).to.deep.equal([]); expect(contextWithoutExclusion.assets.hooks).to.deep.equal([]); expect(contextWithoutExclusion.assets.rules).to.deep.equal([]); @@ -124,7 +124,7 @@ describe('#YAML context validation', () => { mockMgmtClient() ); - await contextWithInclusion.load(); + await contextWithInclusion.loadAssetsFromLocal(); expect(contextWithInclusion.assets.tenant).to.deep.equal({ enabled_locales: ['en'], }); @@ -141,14 +141,14 @@ describe('#YAML context validation', () => { const config = { AUTH0_INPUT_FILE: yaml }; const context = new Context(config, mockMgmtClient()); - await expect(context.load()).to.be.eventually.rejectedWith(Error); + await expect(context.loadAssetsFromLocal()).to.be.eventually.rejectedWith(Error); }); it('should error on bad file', async () => { const yaml = path.resolve(testDataDir, 'yaml', 'notexist.yml'); const config = { AUTH0_INPUT_FILE: yaml }; const context = new Context(config, mockMgmtClient()); - await expect(context.load()).to.be.eventually.rejectedWith(Error); + await expect(context.loadAssetsFromLocal()).to.be.eventually.rejectedWith(Error); }); it('should load relative file', async () => { diff --git a/test/context/yaml/customDomains.test.ts b/test/context/yaml/customDomains.test.ts index e35f502be..2eabf7a55 100644 --- a/test/context/yaml/customDomains.test.ts +++ b/test/context/yaml/customDomains.test.ts @@ -23,7 +23,7 @@ describe('#YAML context custom domains', () => { const config = { AUTH0_INPUT_FILE: yamlFile }; const context = new Context(config, mockMgmtClient()); - await context.load(); + await context.loadAssetsFromLocal(); expect(context.assets.customDomains).to.deep.equal([ { diff --git a/test/context/yaml/databases.test.js b/test/context/yaml/databases.test.js index 716f61727..e1cd50059 100644 --- a/test/context/yaml/databases.test.js +++ b/test/context/yaml/databases.test.js @@ -44,7 +44,7 @@ describe('#YAML context databases', () => { fs.writeFileSync(yamlFile, yaml); const context = new Context(config, mockMgmtClient()); - await context.load(); + await context.loadAssetsFromLocal(); expect(context.assets.databases).to.deep.equal(target); }); @@ -93,7 +93,7 @@ describe('#YAML context databases', () => { fs.writeFileSync(yamlFile, yaml); const context = new Context(config, mockMgmtClient()); - await context.load(); + await context.loadAssetsFromLocal(); expect(context.assets.databases).to.deep.equal(target); }); diff --git a/test/context/yaml/emailProvider.test.js b/test/context/yaml/emailProvider.test.js index 15656c2c8..1bc19a31f 100644 --- a/test/context/yaml/emailProvider.test.js +++ b/test/context/yaml/emailProvider.test.js @@ -37,7 +37,7 @@ describe('#YAML context email provider', () => { const config = { AUTH0_INPUT_FILE: yamlFile, AUTH0_KEYWORD_REPLACE_MAPPINGS: { ENV: 'test' } }; const context = new Context(config, mockMgmtClient()); - await context.load(); + await context.loadAssetsFromLocal(); expect(context.assets.emailProvider).to.deep.equal(target); }); diff --git a/test/context/yaml/emailTemplates.test.js b/test/context/yaml/emailTemplates.test.js index 29440d7fb..a430ab0dd 100644 --- a/test/context/yaml/emailTemplates.test.js +++ b/test/context/yaml/emailTemplates.test.js @@ -55,7 +55,7 @@ describe('#YAML context email templates', () => { const config = { AUTH0_INPUT_FILE: yamlFile, AUTH0_KEYWORD_REPLACE_MAPPINGS: { ENV: 'test' } }; const context = new Context(config, mockMgmtClient()); - await context.load(); + await context.loadAssetsFromLocal(); expect(context.assets.emailTemplates).to.deep.equal(target); }); diff --git a/test/context/yaml/guardianFactorProviders.test.js b/test/context/yaml/guardianFactorProviders.test.js index 2e67eae02..9d9ffd481 100644 --- a/test/context/yaml/guardianFactorProviders.test.js +++ b/test/context/yaml/guardianFactorProviders.test.js @@ -35,7 +35,7 @@ describe('#YAML context guardian factor provider provider', () => { const config = { AUTH0_INPUT_FILE: yamlFile, AUTH0_KEYWORD_REPLACE_MAPPINGS: { ENV: 'test' } }; const context = new Context(config, mockMgmtClient()); - await context.load(); + await context.loadAssetsFromLocal(); expect(context.assets.guardianFactorProviders).to.deep.equal(target); }); diff --git a/test/context/yaml/guardianFactorTemplates.test.js b/test/context/yaml/guardianFactorTemplates.test.js index 8c04fe313..e1d2051a9 100644 --- a/test/context/yaml/guardianFactorTemplates.test.js +++ b/test/context/yaml/guardianFactorTemplates.test.js @@ -31,7 +31,7 @@ describe('#YAML context guardian factors templates provider', () => { const config = { AUTH0_INPUT_FILE: yamlFile, AUTH0_KEYWORD_REPLACE_MAPPINGS: { ENV: 'test' } }; const context = new Context(config, mockMgmtClient()); - await context.load(); + await context.loadAssetsFromLocal(); expect(context.assets.guardianFactorTemplates).to.deep.equal(target); }); diff --git a/test/context/yaml/guardianFactors.test.js b/test/context/yaml/guardianFactors.test.js index d83aea1ca..e6e5bb0f0 100644 --- a/test/context/yaml/guardianFactors.test.js +++ b/test/context/yaml/guardianFactors.test.js @@ -38,7 +38,7 @@ describe('#YAML context guardian factors provider', () => { const config = { AUTH0_INPUT_FILE: yamlFile, AUTH0_KEYWORD_REPLACE_MAPPINGS: { ENV: 'test' } }; const context = new Context(config, mockMgmtClient()); - await context.load(); + await context.loadAssetsFromLocal(); expect(context.assets.guardianFactors).to.deep.equal(target); }); diff --git a/test/context/yaml/guardianPhoneFactorMessageTypes.test.js b/test/context/yaml/guardianPhoneFactorMessageTypes.test.js index f738ab0a6..2cbe3d5d5 100644 --- a/test/context/yaml/guardianPhoneFactorMessageTypes.test.js +++ b/test/context/yaml/guardianPhoneFactorMessageTypes.test.js @@ -27,7 +27,7 @@ describe('#YAML context guardian phone factor message types provider', () => { const config = { AUTH0_INPUT_FILE: yamlFile, AUTH0_KEYWORD_REPLACE_MAPPINGS: { ENV: 'test' } }; const context = new Context(config, mockMgmtClient()); - await context.load(); + await context.loadAssetsFromLocal(); expect(context.assets.guardianPhoneFactorMessageTypes).to.deep.equal(target); }); diff --git a/test/context/yaml/guardianPhoneFactorSelectedProvider.test.js b/test/context/yaml/guardianPhoneFactorSelectedProvider.test.js index b9660eae0..79e803142 100644 --- a/test/context/yaml/guardianPhoneFactorSelectedProvider.test.js +++ b/test/context/yaml/guardianPhoneFactorSelectedProvider.test.js @@ -25,7 +25,7 @@ describe('#YAML context guardian phone factor selected provider', () => { const config = { AUTH0_INPUT_FILE: yamlFile, AUTH0_KEYWORD_REPLACE_MAPPINGS: { ENV: 'test' } }; const context = new Context(config, mockMgmtClient()); - await context.load(); + await context.loadAssetsFromLocal(); expect(context.assets.guardianPhoneFactorSelectedProvider).to.deep.equal(target); }); diff --git a/test/context/yaml/guardianPolicies.test.js b/test/context/yaml/guardianPolicies.test.js index 4ad90ee22..69d25a540 100644 --- a/test/context/yaml/guardianPolicies.test.js +++ b/test/context/yaml/guardianPolicies.test.js @@ -26,7 +26,7 @@ describe('#YAML context guardian policies provider', () => { const config = { AUTH0_INPUT_FILE: yamlFile, AUTH0_KEYWORD_REPLACE_MAPPINGS: { ENV: 'test' } }; const context = new Context(config, mockMgmtClient()); - await context.load(); + await context.loadAssetsFromLocal(); expect(context.assets.guardianPolicies).to.deep.equal(target); }); @@ -48,7 +48,7 @@ describe('#YAML context guardian policies provider', () => { const config = { AUTH0_INPUT_FILE: yamlFile, AUTH0_KEYWORD_REPLACE_MAPPINGS: { ENV: 'test' } }; const context = new Context(config, mockMgmtClient()); - await context.load(); + await context.loadAssetsFromLocal(); expect(context.assets.guardianPolicies).to.deep.equal(target); }); diff --git a/test/context/yaml/hooks.test.js b/test/context/yaml/hooks.test.js index c6787033b..12b948459 100644 --- a/test/context/yaml/hooks.test.js +++ b/test/context/yaml/hooks.test.js @@ -40,7 +40,7 @@ describe('#YAML context hooks', () => { AUTH0_KEYWORD_REPLACE_MAPPINGS: { hello: 'test' }, }; const context = new Context(config, mockMgmtClient()); - await context.load(); + await context.loadAssetsFromLocal(); expect(context.assets.hooks).to.deep.equal(target); }); diff --git a/test/context/yaml/logStreams.test.js b/test/context/yaml/logStreams.test.js index f6b3f108f..8fe26d551 100644 --- a/test/context/yaml/logStreams.test.js +++ b/test/context/yaml/logStreams.test.js @@ -34,7 +34,7 @@ describe('#YAML context log streams', () => { const config = { AUTH0_INPUT_FILE: yamlFile }; const context = new Context(config, mockMgmtClient()); - await context.load(); + await context.loadAssetsFromLocal(); expect(context.assets.logStreams).to.deep.equal([ { diff --git a/test/context/yaml/migrations.test.js b/test/context/yaml/migrations.test.js index d7990adb7..3a8f894fa 100644 --- a/test/context/yaml/migrations.test.js +++ b/test/context/yaml/migrations.test.js @@ -27,7 +27,7 @@ describe('#YAML context migrations', () => { const config = { AUTH0_INPUT_FILE: yamlFile, AUTH0_KEYWORD_REPLACE_MAPPINGS: { ENV: 'test' } }; const context = new Context(config, mockMgmtClient()); - await context.load(); + await context.loadAssetsFromLocal(); expect(context.assets.migrations).to.deep.equal(target); }); diff --git a/test/context/yaml/organizations.test.js b/test/context/yaml/organizations.test.js index ca38b3f23..ab769ad9f 100644 --- a/test/context/yaml/organizations.test.js +++ b/test/context/yaml/organizations.test.js @@ -73,7 +73,7 @@ describe('#YAML context organizations', () => { const config = { AUTH0_INPUT_FILE: yamlFile }; const context = new Context(config, mockMgmtClient()); - await context.load(); + await context.loadAssetsFromLocal(); expect(context.assets.organizations).to.deep.equal(target); }); diff --git a/test/context/yaml/pages.test.js b/test/context/yaml/pages.test.js index f12397fb0..98877fb91 100644 --- a/test/context/yaml/pages.test.js +++ b/test/context/yaml/pages.test.js @@ -78,7 +78,7 @@ describe('#YAML context pages', () => { AUTH0_KEYWORD_REPLACE_MAPPINGS: { val1: 'env1', val2: 'env2' }, }; const context = new Context(config, mockMgmtClient()); - await context.load(); + await context.loadAssetsFromLocal(); expect(context.assets.pages).to.deep.equal(target); }); @@ -253,7 +253,7 @@ describe('#YAML context pages', () => { const config = { AUTH0_INPUT_FILE: yamlFile }; const context = new Context(config, mockMgmtClient()); - await context.load(); + await context.loadAssetsFromLocal(); expect(context.assets.pages).to.deep.equal(target); }); diff --git a/test/context/yaml/prompts.test.ts b/test/context/yaml/prompts.test.ts index b3392b86e..5621c068f 100644 --- a/test/context/yaml/prompts.test.ts +++ b/test/context/yaml/prompts.test.ts @@ -69,7 +69,7 @@ describe('#YAML context prompts', () => { const config = { AUTH0_INPUT_FILE: yamlFile }; const context = new Context(config, mockMgmtClient()); - await context.load(); + await context.loadAssetsFromLocal(); expect(context.assets.prompts).to.deep.equal({ customText: { diff --git a/test/context/yaml/resourceServers.test.js b/test/context/yaml/resourceServers.test.js index 3e66c86a2..8d2f9961b 100644 --- a/test/context/yaml/resourceServers.test.js +++ b/test/context/yaml/resourceServers.test.js @@ -45,7 +45,7 @@ describe('#YAML context resource servers', () => { AUTH0_KEYWORD_REPLACE_MAPPINGS: { name: 'my resource', identifier: 'http://myapi.com/api' }, }; const context = new Context(config, mockMgmtClient()); - await context.load(); + await context.loadAssetsFromLocal(); expect(context.assets.resourceServers).to.deep.equal(target); }); diff --git a/test/context/yaml/roles.test.js b/test/context/yaml/roles.test.js index 9f5882dee..680663977 100644 --- a/test/context/yaml/roles.test.js +++ b/test/context/yaml/roles.test.js @@ -53,7 +53,7 @@ describe('#YAML context roles', () => { const config = { AUTH0_INPUT_FILE: yamlFile }; const context = new Context(config, mockMgmtClient()); - await context.load(); + await context.loadAssetsFromLocal(); expect(context.assets.roles).to.deep.equal(target); }); diff --git a/test/context/yaml/rules.test.js b/test/context/yaml/rules.test.js index 8378dfe91..c8e27a867 100644 --- a/test/context/yaml/rules.test.js +++ b/test/context/yaml/rules.test.js @@ -40,7 +40,7 @@ describe('#YAML context rules', () => { AUTH0_KEYWORD_REPLACE_MAPPINGS: { hello: 'test' }, }; const context = new Context(config, mockMgmtClient()); - await context.load(); + await context.loadAssetsFromLocal(); expect(context.assets.rules).to.deep.equal(target); }); diff --git a/test/context/yaml/rulesConfigs.test.js b/test/context/yaml/rulesConfigs.test.js index c37d32a53..20a4a6b7e 100644 --- a/test/context/yaml/rulesConfigs.test.js +++ b/test/context/yaml/rulesConfigs.test.js @@ -23,7 +23,7 @@ describe('#YAML context rules configs', () => { const config = { AUTH0_INPUT_FILE: yamlFile }; const context = new Context(config, mockMgmtClient()); - await context.load(); + await context.loadAssetsFromLocal(); expect(context.assets.rulesConfigs).to.deep.equal(target); }); diff --git a/test/context/yaml/tenant.test.js b/test/context/yaml/tenant.test.js index 85a1dd926..23686cea6 100644 --- a/test/context/yaml/tenant.test.js +++ b/test/context/yaml/tenant.test.js @@ -31,7 +31,7 @@ describe('#YAML context tenant settings', () => { const config = { AUTH0_INPUT_FILE: yamlFile, AUTH0_KEYWORD_REPLACE_MAPPINGS: { ENV: 'test' } }; const context = new Context(config, mockMgmtClient()); - await context.load(); + await context.loadAssetsFromLocal(); expect(context.assets.tenant).to.deep.equal(target); }); @@ -56,7 +56,7 @@ describe('#YAML context tenant settings', () => { const config = { AUTH0_INPUT_FILE: yamlFile, AUTH0_KEYWORD_REPLACE_MAPPINGS: { ENV: 'test' } }; const context = new Context(config, mockMgmtClient()); - await context.load(); + await context.loadAssetsFromLocal(); expect(context.assets.tenant).to.deep.equal(target); }); diff --git a/test/context/yaml/themes.test.js b/test/context/yaml/themes.test.js index 87f54c7b7..b4f804df6 100644 --- a/test/context/yaml/themes.test.js +++ b/test/context/yaml/themes.test.js @@ -23,7 +23,7 @@ describe('#YAML context themes', () => { const config = { AUTH0_INPUT_FILE: yamlFile, AUTH0_KEYWORD_REPLACE_MAPPINGS: { foo: 'bar' } }; const context = new Context(config, mockMgmtClient()); - await context.load(); + await context.loadAssetsFromLocal(); expect(context.assets.themes).to.deep.equal([theme]); }); @@ -46,7 +46,7 @@ describe('#YAML context themes', () => { const config = { AUTH0_INPUT_FILE: yamlFile, AUTH0_KEYWORD_REPLACE_MAPPINGS: { foo: 'bar' } }; const context = new Context(config, mockMgmtClient()); - await context.load(); + await context.loadAssetsFromLocal(); expect(context.assets.themes).to.deep.equal([theme1, theme2]); }); diff --git a/test/context/yaml/triggers.test.js b/test/context/yaml/triggers.test.js index fc60f5073..1032c33d7 100644 --- a/test/context/yaml/triggers.test.js +++ b/test/context/yaml/triggers.test.js @@ -41,7 +41,7 @@ describe('#YAML context triggers', () => { const config = { AUTH0_INPUT_FILE: yamlFile }; const context = new Context(config, mockMgmtClient()); - await context.load(); + await context.loadAssetsFromLocal(); expect(context.assets.triggers).to.deep.equal(target); }); From 74d55d11ce7ea6bc28b4b43a9433bc9742fb5ff0 Mon Sep 17 00:00:00 2001 From: Will Vedder Date: Tue, 21 Feb 2023 15:43:45 -0500 Subject: [PATCH 2/7] Renaming load to loadAssetsFromAuth0 --- src/context/directory/index.ts | 2 +- src/context/yaml/index.ts | 2 +- src/tools/auth0/index.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/context/directory/index.ts b/src/context/directory/index.ts index 6ede04971..98eed2ab3 100644 --- a/src/context/directory/index.ts +++ b/src/context/directory/index.ts @@ -72,7 +72,7 @@ export default class DirectoryContext { async dump(): Promise { const auth0 = new Auth0(this.mgmtClient, this.assets, toConfigFn(this.config)); log.info('Loading Auth0 Tenant Data'); - await auth0.loadAll(); + await auth0.loadAssetsFromAuth0(); this.assets = auth0.assets; // Clean known read only fields diff --git a/src/context/yaml/index.ts b/src/context/yaml/index.ts index f3d6bd178..5b4260102 100644 --- a/src/context/yaml/index.ts +++ b/src/context/yaml/index.ts @@ -115,7 +115,7 @@ export default class YAMLContext { const auth0 = new Auth0(this.mgmtClient, this.assets, toConfigFn(this.config)); log.info('Loading Auth0 Tenant Data'); try { - await auth0.loadAll(); + await auth0.loadAssetsFromAuth0(); this.assets = auth0.assets; } catch (err) { const docUrl = diff --git a/src/tools/auth0/index.ts b/src/tools/auth0/index.ts index bda2f7cd0..02c470734 100644 --- a/src/tools/auth0/index.ts +++ b/src/tools/auth0/index.ts @@ -89,7 +89,7 @@ export default class Auth0 { await this.runStage('validate'); } - async loadAll(): Promise { + async loadAssetsFromAuth0(): Promise { // Populate assets from auth0 tenant await this.runStage('load'); } From 90f8758fd2f516ec2b079cb24022b07e8bc0edeb Mon Sep 17 00:00:00 2001 From: Will Vedder Date: Wed, 22 Feb 2023 08:32:16 -0500 Subject: [PATCH 3/7] integrating into export process --- src/context/directory/index.ts | 22 ++++++++++++++++++++-- src/context/yaml/index.ts | 26 +++++++++++++++++++++++--- 2 files changed, 43 insertions(+), 5 deletions(-) diff --git a/src/context/directory/index.ts b/src/context/directory/index.ts index 98eed2ab3..df2517390 100644 --- a/src/context/directory/index.ts +++ b/src/context/directory/index.ts @@ -7,6 +7,7 @@ import handlers, { DirectoryHandler } from './handlers'; import { isDirectory, isFile, stripIdentifiers, toConfigFn } from '../../utils'; import { Assets, Auth0APIClient, Config, AssetTypes } from '../../types'; import { filterOnlyIncludedResourceTypes } from '..'; +import { preserveKeywords } from '../../keywordPreservation'; type KeywordMappings = { [key: string]: (string | number)[] | string | number }; @@ -72,8 +73,25 @@ export default class DirectoryContext { async dump(): Promise { const auth0 = new Auth0(this.mgmtClient, this.assets, toConfigFn(this.config)); log.info('Loading Auth0 Tenant Data'); - await auth0.loadAssetsFromAuth0(); - this.assets = auth0.assets; + + await this.loadAssetsFromLocal(); + + const shouldPreserveKeywords = false; + if (shouldPreserveKeywords) { + const localAssets = { ...this.assets }; + //@ts-ignore + delete this['assets']; + + this.assets = auth0.assets; + + this.assets = preserveKeywords( + localAssets, + this.assets, + this.config.AUTH0_KEYWORD_REPLACE_MAPPINGS || {} + ); + } else { + this.assets = auth0.assets; + } // Clean known read only fields this.assets = cleanAssets(this.assets, this.config); diff --git a/src/context/yaml/index.ts b/src/context/yaml/index.ts index 5b4260102..2ac7c1f5f 100644 --- a/src/context/yaml/index.ts +++ b/src/context/yaml/index.ts @@ -9,6 +9,7 @@ import handlers, { YAMLHandler } from './handlers'; import cleanAssets from '../../readonly'; import { Assets, Config, Auth0APIClient, AssetTypes, KeywordMappings } from '../../types'; import { filterOnlyIncludedResourceTypes } from '..'; +import { preserveKeywords } from '../../keywordPreservation'; export default class YAMLContext { basePath: string; @@ -52,7 +53,7 @@ export default class YAMLContext { return loadFileAndReplaceKeywords(path.resolve(toLoad), this.mappings); } - async loadAssetsFromLocal() { + async loadAssetsFromLocal(shouldReplaceKeywords = true) { // Allow to send object/json directly if (typeof this.configFile === 'object') { this.assets = this.configFile; @@ -62,7 +63,11 @@ export default class YAMLContext { log.debug(`Loading YAML from ${fPath}`); Object.assign( this.assets, - yaml.load(keywordReplace(fs.readFileSync(fPath, 'utf8'), this.mappings)) || {} + yaml.load( + shouldReplaceKeywords + ? keywordReplace(fs.readFileSync(fPath, 'utf8'), this.mappings) + : fs.readFileSync(fPath, 'utf8') + ) || {} ); } catch (err) { log.debug(err.stack); @@ -116,7 +121,22 @@ export default class YAMLContext { log.info('Loading Auth0 Tenant Data'); try { await auth0.loadAssetsFromAuth0(); - this.assets = auth0.assets; + + const shouldPreserveKeywords = false; + if (shouldPreserveKeywords) { + await this.loadAssetsFromLocal(false); + const localAssets = { ...this.assets }; + //@ts-ignore + delete this['assets']; + + this.assets = preserveKeywords( + localAssets, + auth0.assets, + this.config.AUTH0_KEYWORD_REPLACE_MAPPINGS || {} + ); + } else { + this.assets = auth0.assets; + } } catch (err) { const docUrl = 'https://auth0.com/docs/deploy/deploy-cli-tool/create-and-configure-the-deploy-cli-application#modify-deploy-cli-application-scopes'; From 4bea2cd858ec850aa36c600dc265698f7f344029 Mon Sep 17 00:00:00 2001 From: Will Vedder Date: Wed, 22 Feb 2023 09:16:11 -0500 Subject: [PATCH 4/7] Adding config interpreter --- src/context/directory/index.ts | 5 ++++- src/context/yaml/index.ts | 5 ++++- src/types.ts | 1 + 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/context/directory/index.ts b/src/context/directory/index.ts index df2517390..fb82aadc2 100644 --- a/src/context/directory/index.ts +++ b/src/context/directory/index.ts @@ -76,7 +76,10 @@ export default class DirectoryContext { await this.loadAssetsFromLocal(); - const shouldPreserveKeywords = false; + const shouldPreserveKeywords = + //@ts-ignore because the string=>boolean conversion may not have happened if passed-in as env var + this.config.AUTH0_PRESERVE_KEYWORDS === 'true' || + this.config.AUTH0_PRESERVE_KEYWORDS === true; if (shouldPreserveKeywords) { const localAssets = { ...this.assets }; //@ts-ignore diff --git a/src/context/yaml/index.ts b/src/context/yaml/index.ts index 2ac7c1f5f..c92a8714e 100644 --- a/src/context/yaml/index.ts +++ b/src/context/yaml/index.ts @@ -122,7 +122,10 @@ export default class YAMLContext { try { await auth0.loadAssetsFromAuth0(); - const shouldPreserveKeywords = false; + const shouldPreserveKeywords = + //@ts-ignore because the string=>boolean conversion may not have happened if passed-in as env var + this.config.AUTH0_PRESERVE_KEYWORDS === 'true' || + this.config.AUTH0_PRESERVE_KEYWORDS === true; if (shouldPreserveKeywords) { await this.loadAssetsFromLocal(false); const localAssets = { ...this.assets }; diff --git a/src/types.ts b/src/types.ts index 0faf500e1..d10f6e242 100644 --- a/src/types.ts +++ b/src/types.ts @@ -205,6 +205,7 @@ export type Config = { AUTH0_ALLOW_DELETE: boolean; AUTH0_EXCLUDED?: AssetTypes[]; AUTH0_INCLUDED_ONLY?: AssetTypes[]; + AUTH0_PRESERVE_KEYWORDS: boolean; EXTENSION_SECRET: string; AUTH0_ACCESS_TOKEN?: string; AUTH0_BASE_PATH?: string; From 8fc84987ed7d16782ca7c5b7c5071681c9ce6ef0 Mon Sep 17 00:00:00 2001 From: Will Vedder Date: Wed, 22 Feb 2023 12:22:04 -0500 Subject: [PATCH 5/7] Disabling keyword replacement in certain cases --- src/context/directory/handlers/actions.ts | 10 ++- .../directory/handlers/attackProtection.ts | 15 ++++- src/context/directory/handlers/branding.ts | 10 ++- .../directory/handlers/clientGrants.ts | 7 +- src/context/directory/handlers/clients.ts | 5 +- src/context/directory/handlers/connections.ts | 5 +- .../directory/handlers/customDomains.ts | 5 +- .../directory/handlers/emailProvider.ts | 5 +- .../directory/handlers/emailTemplates.ts | 5 +- .../handlers/guardianFactorProviders.ts | 7 +- .../handlers/guardianFactorTemplates.ts | 7 +- .../directory/handlers/guardianFactors.ts | 7 +- .../guardianPhoneFactorMessageTypes.ts | 5 +- .../guardianPhoneFactorSelectedProvider.ts | 5 +- .../directory/handlers/guardianPolicies.ts | 5 +- src/context/directory/handlers/hooks.ts | 7 +- src/context/directory/handlers/logStreams.ts | 7 +- src/context/directory/handlers/migrations.ts | 5 +- .../directory/handlers/organizations.ts | 7 +- src/context/directory/handlers/pages.ts | 10 ++- src/context/directory/handlers/prompts.ts | 10 ++- .../directory/handlers/resourceServers.ts | 7 +- src/context/directory/handlers/roles.ts | 7 +- src/context/directory/handlers/rules.ts | 7 +- .../directory/handlers/rulesConfigs.ts | 7 +- src/context/directory/handlers/tenant.ts | 5 +- src/context/directory/handlers/themes.ts | 7 +- src/context/directory/handlers/triggers.ts | 7 +- src/context/directory/index.ts | 11 ++-- src/context/yaml/index.ts | 12 ++-- src/utils.ts | 13 +++- test/context/directory/context.test.js | 40 +++++++++++ test/context/yaml/context.test.js | 66 ++++++++++++++++++- test/utils.test.js | 4 +- 34 files changed, 291 insertions(+), 51 deletions(-) diff --git a/src/context/directory/handlers/actions.ts b/src/context/directory/handlers/actions.ts index e17416352..b14328214 100644 --- a/src/context/directory/handlers/actions.ts +++ b/src/context/directory/handlers/actions.ts @@ -19,11 +19,17 @@ function parse(context: DirectoryContext): ParsedActions { const files = getFiles(actionsFolder, ['.json']); const actions = files.map((file) => { - const action = { ...loadJSON(file, context.mappings) }; + const action = { + ...loadJSON(file, { + mappings: context.mappings, + disableKeywordReplacement: context.disableKeywordReplacement, + }), + }; const actionFolder = path.join(constants.ACTIONS_DIRECTORY, `${action.name}`); if (action.code) { - const toUnixPath = somePath => somePath.replace(/[\\/]+/g, '/').replace(/^([a-zA-Z]+:|\.\/)/, ''); + const toUnixPath = (somePath) => + somePath.replace(/[\\/]+/g, '/').replace(/^([a-zA-Z]+:|\.\/)/, ''); action.code = context.loadFile(toUnixPath(action.code), actionFolder); } diff --git a/src/context/directory/handlers/attackProtection.ts b/src/context/directory/handlers/attackProtection.ts index 678729243..e01e60d33 100644 --- a/src/context/directory/handlers/attackProtection.ts +++ b/src/context/directory/handlers/attackProtection.ts @@ -40,9 +40,18 @@ function parse(context: DirectoryContext): ParsedAttackProtection { }; } - const breachedPasswordDetection = loadJSON(files.breachedPasswordDetection, context.mappings); - const bruteForceProtection = loadJSON(files.bruteForceProtection, context.mappings); - const suspiciousIpThrottling = loadJSON(files.suspiciousIpThrottling, context.mappings); + const breachedPasswordDetection = loadJSON(files.breachedPasswordDetection, { + mappings: context.mappings, + disableKeywordReplacement: context.disableKeywordReplacement, + }); + const bruteForceProtection = loadJSON(files.bruteForceProtection, { + mappings: context.mappings, + disableKeywordReplacement: context.disableKeywordReplacement, + }); + const suspiciousIpThrottling = loadJSON(files.suspiciousIpThrottling, { + mappings: context.mappings, + disableKeywordReplacement: context.disableKeywordReplacement, + }); return { attackProtection: { diff --git a/src/context/directory/handlers/branding.ts b/src/context/directory/handlers/branding.ts index c59e25e89..173ca364b 100644 --- a/src/context/directory/handlers/branding.ts +++ b/src/context/directory/handlers/branding.ts @@ -16,7 +16,10 @@ function parse(context: DirectoryContext): ParsedBranding { const brandingSettings = (() => { if (isFile(brandingFile)) { - return loadJSON(brandingFile, context.mappings); + return loadJSON(brandingFile, { + mappings: context.mappings, + disableKeywordReplacement: context.disableKeywordReplacement, + }); } return null; @@ -31,7 +34,10 @@ function parse(context: DirectoryContext): ParsedBranding { const templatesDefinitionFiles = getFiles(brandingTemplatesFolder, ['.json']); const templates = templatesDefinitionFiles.map((templateDefinitionFile) => { - const definition = loadJSON(templateDefinitionFile, context.mappings); + const definition = loadJSON(templateDefinitionFile, { + mappings: context.mappings, + disableKeywordReplacement: context.disableKeywordReplacement, + }); definition.body = loadFileAndReplaceKeywords( path.join(brandingTemplatesFolder, definition.body), context.mappings diff --git a/src/context/directory/handlers/clientGrants.ts b/src/context/directory/handlers/clientGrants.ts index 2fb2ec398..7cf9265ea 100644 --- a/src/context/directory/handlers/clientGrants.ts +++ b/src/context/directory/handlers/clientGrants.ts @@ -24,7 +24,12 @@ function parse(context: DirectoryContext): ParsedClientGrants { const foundFiles = getFiles(grantsFolder, ['.json']); const clientGrants = foundFiles - .map((f) => loadJSON(f, context.mappings)) + .map((f) => + loadJSON(f, { + mappings: context.mappings, + disableKeywordReplacement: context.disableKeywordReplacement, + }) + ) .filter((p) => Object.keys(p).length > 0); // Filter out empty grants return { diff --git a/src/context/directory/handlers/clients.ts b/src/context/directory/handlers/clients.ts index 314ca4fa8..eb484fdb8 100644 --- a/src/context/directory/handlers/clients.ts +++ b/src/context/directory/handlers/clients.ts @@ -27,7 +27,10 @@ function parse(context: DirectoryContext): ParsedClients { const clients = foundFiles .map((f) => { - const client = loadJSON(f, context.mappings); + const client = loadJSON(f, { + mappings: context.mappings, + disableKeywordReplacement: context.disableKeywordReplacement, + }); if (client.custom_login_page) { const htmlFileName = path.join(clientsFolder, client.custom_login_page); diff --git a/src/context/directory/handlers/connections.ts b/src/context/directory/handlers/connections.ts index c0d228625..7a341931c 100644 --- a/src/context/directory/handlers/connections.ts +++ b/src/context/directory/handlers/connections.ts @@ -29,7 +29,10 @@ function parse(context: DirectoryContext): ParsedConnections { const connections = foundFiles .map((f) => { - const connection = loadJSON(f, context.mappings); + const connection = loadJSON(f, { + mappings: context.mappings, + disableKeywordReplacement: context.disableKeywordReplacement, + }); if (connection.strategy === 'email') { ensureProp(connection, 'options.email.body'); diff --git a/src/context/directory/handlers/customDomains.ts b/src/context/directory/handlers/customDomains.ts index b77153d1b..773cd2cbf 100644 --- a/src/context/directory/handlers/customDomains.ts +++ b/src/context/directory/handlers/customDomains.ts @@ -21,7 +21,10 @@ function parse(context: DirectoryContext): ParsedCustomDomains { const customDomainsFile = getCustomDomainsFile(context.filePath); return { - customDomains: loadJSON(customDomainsFile, context.mappings), + customDomains: loadJSON(customDomainsFile, { + mappings: context.mappings, + disableKeywordReplacement: context.disableKeywordReplacement, + }), }; } diff --git a/src/context/directory/handlers/emailProvider.ts b/src/context/directory/handlers/emailProvider.ts index d1fe710f9..21066093b 100644 --- a/src/context/directory/handlers/emailProvider.ts +++ b/src/context/directory/handlers/emailProvider.ts @@ -18,7 +18,10 @@ function parse(context: DirectoryContext): ParsedEmailProvider { if (isFile(providerFile)) { return { - emailProvider: loadJSON(providerFile, context.mappings), + emailProvider: loadJSON(providerFile, { + mappings: context.mappings, + disableKeywordReplacement: context.disableKeywordReplacement, + }), }; } diff --git a/src/context/directory/handlers/emailTemplates.ts b/src/context/directory/handlers/emailTemplates.ts index 2e2ef33fe..419d84a25 100644 --- a/src/context/directory/handlers/emailTemplates.ts +++ b/src/context/directory/handlers/emailTemplates.ts @@ -37,7 +37,10 @@ function parse(context: DirectoryContext): ParsedEmailTemplates { return []; } else { return { - ...loadJSON(meta, context.mappings), + ...loadJSON(meta, { + mappings: context.mappings, + disableKeywordReplacement: context.disableKeywordReplacement, + }), body: loadFileAndReplaceKeywords(html, context.mappings), }; } diff --git a/src/context/directory/handlers/guardianFactorProviders.ts b/src/context/directory/handlers/guardianFactorProviders.ts index cd02f9a73..4c6598753 100644 --- a/src/context/directory/handlers/guardianFactorProviders.ts +++ b/src/context/directory/handlers/guardianFactorProviders.ts @@ -20,7 +20,12 @@ function parse(context: DirectoryContext): ParsedGuardianFactorProviders { const foundFiles = getFiles(factorProvidersFolder, ['.json']); const guardianFactorProviders = foundFiles - .map((f) => loadJSON(f, context.mappings)) + .map((f) => + loadJSON(f, { + mappings: context.mappings, + disableKeywordReplacement: context.disableKeywordReplacement, + }) + ) .filter((p) => Object.keys(p).length > 0); // Filter out empty factorProvidersFolder return { diff --git a/src/context/directory/handlers/guardianFactorTemplates.ts b/src/context/directory/handlers/guardianFactorTemplates.ts index 93671267a..5b405d3c2 100644 --- a/src/context/directory/handlers/guardianFactorTemplates.ts +++ b/src/context/directory/handlers/guardianFactorTemplates.ts @@ -20,7 +20,12 @@ function parse(context: DirectoryContext): ParsedGuardianFactorTemplates { const foundFiles = getFiles(factorTemplatesFolder, ['.json']); const guardianFactorTemplates = foundFiles - .map((f) => loadJSON(f, context.mappings)) + .map((f) => + loadJSON(f, { + mappings: context.mappings, + disableKeywordReplacement: context.disableKeywordReplacement, + }) + ) .filter((p) => Object.keys(p).length > 0); // Filter out empty guardianFactorTemplates return { diff --git a/src/context/directory/handlers/guardianFactors.ts b/src/context/directory/handlers/guardianFactors.ts index 84556431e..acb4342d5 100644 --- a/src/context/directory/handlers/guardianFactors.ts +++ b/src/context/directory/handlers/guardianFactors.ts @@ -20,7 +20,12 @@ function parse(context: DirectoryContext): ParsedGuardianFactors { const foundFiles = getFiles(factorsFolder, ['.json']); const guardianFactors = foundFiles - .map((f) => loadJSON(f, context.mappings)) + .map((f) => + loadJSON(f, { + mappings: context.mappings, + disableKeywordReplacement: context.disableKeywordReplacement, + }) + ) .filter((p) => Object.keys(p).length > 0); // Filter out empty guardianFactors return { diff --git a/src/context/directory/handlers/guardianPhoneFactorMessageTypes.ts b/src/context/directory/handlers/guardianPhoneFactorMessageTypes.ts index a9bda924d..e87f6a192 100644 --- a/src/context/directory/handlers/guardianPhoneFactorMessageTypes.ts +++ b/src/context/directory/handlers/guardianPhoneFactorMessageTypes.ts @@ -19,7 +19,10 @@ function parse(context: DirectoryContext): ParsedGuardianFactorMessageTypes { } return { - guardianPhoneFactorMessageTypes: loadJSON(file, context.mappings), + guardianPhoneFactorMessageTypes: loadJSON(file, { + mappings: context.mappings, + disableKeywordReplacement: context.disableKeywordReplacement, + }), }; } diff --git a/src/context/directory/handlers/guardianPhoneFactorSelectedProvider.ts b/src/context/directory/handlers/guardianPhoneFactorSelectedProvider.ts index 5690ec08e..a5205dd0b 100644 --- a/src/context/directory/handlers/guardianPhoneFactorSelectedProvider.ts +++ b/src/context/directory/handlers/guardianPhoneFactorSelectedProvider.ts @@ -22,7 +22,10 @@ function parse(context: DirectoryContext): ParsedGuardianFactorSelectedProvider } return { - guardianPhoneFactorSelectedProvider: loadJSON(file, context.mappings), + guardianPhoneFactorSelectedProvider: loadJSON(file, { + mappings: context.mappings, + disableKeywordReplacement: context.disableKeywordReplacement, + }), }; } diff --git a/src/context/directory/handlers/guardianPolicies.ts b/src/context/directory/handlers/guardianPolicies.ts index 023bad668..fc5a1391c 100644 --- a/src/context/directory/handlers/guardianPolicies.ts +++ b/src/context/directory/handlers/guardianPolicies.ts @@ -19,7 +19,10 @@ function parse(context: DirectoryContext): ParsedGuardianPolicies { } return { - guardianPolicies: loadJSON(file, context.mappings), + guardianPolicies: loadJSON(file, { + mappings: context.mappings, + disableKeywordReplacement: context.disableKeywordReplacement, + }), }; } diff --git a/src/context/directory/handlers/hooks.ts b/src/context/directory/handlers/hooks.ts index c1e81f626..a74859428 100644 --- a/src/context/directory/handlers/hooks.ts +++ b/src/context/directory/handlers/hooks.ts @@ -17,7 +17,12 @@ function parse(context: DirectoryContext): ParsedHooks { const files = getFiles(hooksFolder, ['.json']); const hooks = files.map((f) => { - const hook = { ...loadJSON(f, context.mappings) }; + const hook = { + ...loadJSON(f, { + mappings: context.mappings, + disableKeywordReplacement: context.disableKeywordReplacement, + }), + }; if (hook.script) { hook.script = context.loadFile(hook.script, constants.HOOKS_DIRECTORY); } diff --git a/src/context/directory/handlers/logStreams.ts b/src/context/directory/handlers/logStreams.ts index 1894202c2..eb4f9ec9f 100644 --- a/src/context/directory/handlers/logStreams.ts +++ b/src/context/directory/handlers/logStreams.ts @@ -15,7 +15,12 @@ function parse(context: DirectoryContext): ParsedLogStreams { const foundFiles = getFiles(logStreamsDirectory, ['.json']); const logStreams = foundFiles - .map((f) => loadJSON(f, context.mappings)) + .map((f) => + loadJSON(f, { + mappings: context.mappings, + disableKeywordReplacement: context.disableKeywordReplacement, + }) + ) .filter((p) => Object.keys(p).length > 0); // Filter out empty rulesConfigs return { diff --git a/src/context/directory/handlers/migrations.ts b/src/context/directory/handlers/migrations.ts index 08e52cdb1..25a70e7eb 100644 --- a/src/context/directory/handlers/migrations.ts +++ b/src/context/directory/handlers/migrations.ts @@ -15,7 +15,10 @@ function parse(context: DirectoryContext): ParsedMigrations { if (!isFile(migrationsFile)) return { migrations: null }; /* eslint-disable camelcase */ - const migrations = loadJSON(migrationsFile, context.mappings); + const migrations = loadJSON(migrationsFile, { + mappings: context.mappings, + disableKeywordReplacement: context.disableKeywordReplacement, + }); return { migrations }; } diff --git a/src/context/directory/handlers/organizations.ts b/src/context/directory/handlers/organizations.ts index 5d7ba0836..9d54a7374 100644 --- a/src/context/directory/handlers/organizations.ts +++ b/src/context/directory/handlers/organizations.ts @@ -17,7 +17,12 @@ function parse(context: DirectoryContext): ParsedOrganizations { const files = getFiles(organizationsFolder, ['.json']); const organizations = files.map((f) => { - const org = { ...loadJSON(f, context.mappings) }; + const org = { + ...loadJSON(f, { + mappings: context.mappings, + disableKeywordReplacement: context.disableKeywordReplacement, + }), + }; return org; }); diff --git a/src/context/directory/handlers/pages.ts b/src/context/directory/handlers/pages.ts index bd4effbe1..30290dbd9 100644 --- a/src/context/directory/handlers/pages.ts +++ b/src/context/directory/handlers/pages.ts @@ -39,7 +39,10 @@ function parse(context: DirectoryContext): ParsedPages { if (!html && ['error_page', 'login'].includes(key)) { //Error pages don't require an HTML template, it is valid to redirect errors to URL return { - ...loadJSON(meta, context.mappings), + ...loadJSON(meta, { + mappings: context.mappings, + disableKeywordReplacement: context.disableKeywordReplacement, + }), html: '', }; } @@ -48,7 +51,10 @@ function parse(context: DirectoryContext): ParsedPages { return []; } return { - ...loadJSON(meta, context.mappings), + ...loadJSON(meta, { + mappings: context.mappings, + disableKeywordReplacement: context.disableKeywordReplacement, + }), html: loadFileAndReplaceKeywords(html, context.mappings), }; }); diff --git a/src/context/directory/handlers/prompts.ts b/src/context/directory/handlers/prompts.ts index ea9da463e..12fee4eae 100644 --- a/src/context/directory/handlers/prompts.ts +++ b/src/context/directory/handlers/prompts.ts @@ -32,13 +32,19 @@ function parse(context: DirectoryContext): ParsedPrompts { const promptsSettings = (() => { const promptsSettingsFile = getPromptsSettingsFile(promptsDirectory); if (!isFile(promptsSettingsFile)) return {}; - return loadJSON(promptsSettingsFile, context.mappings) as PromptSettings; + return loadJSON(promptsSettingsFile, { + mappings: context.mappings, + disableKeywordReplacement: context.disableKeywordReplacement, + }) as PromptSettings; })(); const customText = (() => { const customTextFile = getCustomTextFile(promptsDirectory); if (!isFile(customTextFile)) return {}; - return loadJSON(customTextFile, context.mappings) as AllPromptsByLanguage; + return loadJSON(customTextFile, { + mappings: context.mappings, + disableKeywordReplacement: context.disableKeywordReplacement, + }) as AllPromptsByLanguage; })(); return { diff --git a/src/context/directory/handlers/resourceServers.ts b/src/context/directory/handlers/resourceServers.ts index 7114932f7..244e03215 100644 --- a/src/context/directory/handlers/resourceServers.ts +++ b/src/context/directory/handlers/resourceServers.ts @@ -16,7 +16,12 @@ function parse(context: DirectoryContext): ParsedResourceServers { const foundFiles = getFiles(resourceServersFolder, ['.json']); const resourceServers = foundFiles - .map((f) => loadJSON(f, context.mappings)) + .map((f) => + loadJSON(f, { + mappings: context.mappings, + disableKeywordReplacement: context.disableKeywordReplacement, + }) + ) .filter((p) => Object.keys(p).length > 0); // Filter out empty resourceServers return { diff --git a/src/context/directory/handlers/roles.ts b/src/context/directory/handlers/roles.ts index 02eedcb48..719a5f4f5 100644 --- a/src/context/directory/handlers/roles.ts +++ b/src/context/directory/handlers/roles.ts @@ -17,7 +17,12 @@ function parse(context: DirectoryContext): ParsedRoles { const files = getFiles(rolesFolder, ['.json']); const roles = files.map((f) => { - const role = { ...loadJSON(f, context.mappings) }; + const role = { + ...loadJSON(f, { + mappings: context.mappings, + disableKeywordReplacement: context.disableKeywordReplacement, + }), + }; return role; }); diff --git a/src/context/directory/handlers/rules.ts b/src/context/directory/handlers/rules.ts index 992dfa99d..15bafcc14 100644 --- a/src/context/directory/handlers/rules.ts +++ b/src/context/directory/handlers/rules.ts @@ -18,7 +18,12 @@ function parse(context: DirectoryContext): ParsedRules { const files: string[] = getFiles(rulesFolder, ['.json']); const rules = files.map((f) => { - const rule = { ...loadJSON(f, context.mappings) }; + const rule = { + ...loadJSON(f, { + mappings: context.mappings, + disableKeywordReplacement: context.disableKeywordReplacement, + }), + }; if (rule.script) { rule.script = context.loadFile(rule.script, constants.RULES_DIRECTORY); } diff --git a/src/context/directory/handlers/rulesConfigs.ts b/src/context/directory/handlers/rulesConfigs.ts index 41da89a98..c5b2a235c 100644 --- a/src/context/directory/handlers/rulesConfigs.ts +++ b/src/context/directory/handlers/rulesConfigs.ts @@ -15,7 +15,12 @@ function parse(context: DirectoryContext): ParsedRulesConfigs { const foundFiles: string[] = getFiles(rulesConfigsFolder, ['.json']); const rulesConfigs = foundFiles - .map((f) => loadJSON(f, context.mappings)) + .map((f) => + loadJSON(f, { + mappings: context.mappings, + disableKeywordReplacement: context.disableKeywordReplacement, + }) + ) .filter((p) => Object.keys(p).length > 0); // Filter out empty rulesConfigs return { diff --git a/src/context/directory/handlers/tenant.ts b/src/context/directory/handlers/tenant.ts index 808bfd6dd..238c72c5d 100644 --- a/src/context/directory/handlers/tenant.ts +++ b/src/context/directory/handlers/tenant.ts @@ -33,7 +33,10 @@ function parse(context: DirectoryContext): ParsedTenant { session_lifetime?: number; idle_session_lifetime?: number; [key: string]: any; - } = loadJSON(tenantFile, context.mappings); + } = loadJSON(tenantFile, { + mappings: context.mappings, + disableKeywordReplacement: context.disableKeywordReplacement, + }); clearTenantFlags(tenant); diff --git a/src/context/directory/handlers/themes.ts b/src/context/directory/handlers/themes.ts index 04cf03ace..ba8c22ea7 100644 --- a/src/context/directory/handlers/themes.ts +++ b/src/context/directory/handlers/themes.ts @@ -21,9 +21,12 @@ function parse(context: DirectoryContext): ParsedThemes { } const themes = themeDefinitionsFiles.map( - (themeDefinitionsFile) => loadJSON(themeDefinitionsFile, context.mappings) as Theme + (themeDefinitionsFile) => + loadJSON(themeDefinitionsFile, { + mappings: context.mappings, + disableKeywordReplacement: context.disableKeywordReplacement, + }) as Theme ); - return { themes }; } diff --git a/src/context/directory/handlers/triggers.ts b/src/context/directory/handlers/triggers.ts index 81590b9ef..8fd62f2d5 100644 --- a/src/context/directory/handlers/triggers.ts +++ b/src/context/directory/handlers/triggers.ts @@ -17,7 +17,12 @@ function parse(context: DirectoryContext): ParsedTriggers { const files = getFiles(triggersFolder, ['.json']); - const triggers = { ...loadJSON(files[0], context.mappings) }; + const triggers = { + ...loadJSON(files[0], { + mappings: context.mappings, + disableKeywordReplacement: context.disableKeywordReplacement, + }), + }; return { triggers }; } diff --git a/src/context/directory/index.ts b/src/context/directory/index.ts index fb82aadc2..ffc7af643 100644 --- a/src/context/directory/index.ts +++ b/src/context/directory/index.ts @@ -18,12 +18,14 @@ export default class DirectoryContext { mappings: KeywordMappings; mgmtClient: Auth0APIClient; assets: Assets; + disableKeywordReplacement: boolean; constructor(config: Config, mgmtClient: Auth0APIClient) { this.filePath = config.AUTH0_INPUT_FILE; this.config = config; this.mappings = config.AUTH0_KEYWORD_REPLACE_MAPPINGS || {}; this.mgmtClient = mgmtClient; + this.disableKeywordReplacement = false; //@ts-ignore for now this.assets = {}; @@ -48,7 +50,8 @@ export default class DirectoryContext { return loadFileAndReplaceKeywords(toLoad, this.mappings); } - async loadAssetsFromLocal(): Promise { + async loadAssetsFromLocal(opts = { disableKeywordReplacement: false }): Promise { + this.disableKeywordReplacement = opts.disableKeywordReplacement; if (isDirectory(this.filePath)) { /* If this is a directory, look for each file in the directory */ log.info(`Processing directory ${this.filePath}`); @@ -74,7 +77,7 @@ export default class DirectoryContext { const auth0 = new Auth0(this.mgmtClient, this.assets, toConfigFn(this.config)); log.info('Loading Auth0 Tenant Data'); - await this.loadAssetsFromLocal(); + await this.loadAssetsFromLocal({ disableKeywordReplacement: true }); //Need to disable keyword replacement to retrieve the raw keyword markers (ex: ##KEYWORD##) const shouldPreserveKeywords = //@ts-ignore because the string=>boolean conversion may not have happened if passed-in as env var @@ -85,11 +88,9 @@ export default class DirectoryContext { //@ts-ignore delete this['assets']; - this.assets = auth0.assets; - this.assets = preserveKeywords( localAssets, - this.assets, + auth0.assets, this.config.AUTH0_KEYWORD_REPLACE_MAPPINGS || {} ); } else { diff --git a/src/context/yaml/index.ts b/src/context/yaml/index.ts index c92a8714e..05298ce0e 100644 --- a/src/context/yaml/index.ts +++ b/src/context/yaml/index.ts @@ -53,7 +53,7 @@ export default class YAMLContext { return loadFileAndReplaceKeywords(path.resolve(toLoad), this.mappings); } - async loadAssetsFromLocal(shouldReplaceKeywords = true) { + async loadAssetsFromLocal(opts = { disableKeywordReplacement: false }) { // Allow to send object/json directly if (typeof this.configFile === 'object') { this.assets = this.configFile; @@ -64,9 +64,9 @@ export default class YAMLContext { Object.assign( this.assets, yaml.load( - shouldReplaceKeywords - ? keywordReplace(fs.readFileSync(fPath, 'utf8'), this.mappings) - : fs.readFileSync(fPath, 'utf8') + opts.disableKeywordReplacement + ? fs.readFileSync(fPath, 'utf8') + : keywordReplace(fs.readFileSync(fPath, 'utf8'), this.mappings) ) || {} ); } catch (err) { @@ -110,7 +110,7 @@ export default class YAMLContext { }); } catch (err) { log.debug(err.stack); - throw new Error(`Problem deploying ${name}`); + throw new Error(`Problem deploying ${name}, ${err}`); } }) ); @@ -127,7 +127,7 @@ export default class YAMLContext { this.config.AUTH0_PRESERVE_KEYWORDS === 'true' || this.config.AUTH0_PRESERVE_KEYWORDS === true; if (shouldPreserveKeywords) { - await this.loadAssetsFromLocal(false); + await this.loadAssetsFromLocal({ disableKeywordReplacement: true }); const localAssets = { ...this.assets }; //@ts-ignore delete this['assets']; diff --git a/src/utils.ts b/src/utils.ts index 64c0af1a0..8ba3954d3 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -32,9 +32,18 @@ export function getFiles(folder: string, exts: string[]): string[] { return []; } -export function loadJSON(file: string, mappings: KeywordMappings): any { +export function loadJSON( + file: string, + opts: { disableKeywordReplacement: boolean; mappings: KeywordMappings } = { + disableKeywordReplacement: false, + mappings: {}, + } +): any { try { - const content = loadFileAndReplaceKeywords(file, mappings); + const content = loadFileAndReplaceKeywords( + file, + opts.disableKeywordReplacement ? {} : opts.mappings + ); return JSON.parse(content); } catch (e) { throw new Error(`Error parsing JSON from metadata file: ${file}, because: ${e.message}`); diff --git a/test/context/directory/context.test.js b/test/context/directory/context.test.js index ab3fcf6b4..ed1e51d71 100644 --- a/test/context/directory/context.test.js +++ b/test/context/directory/context.test.js @@ -132,4 +132,44 @@ describe('#directory context validation', () => { .to.be.eventually.rejectedWith(Error) .and.have.property('message', errorMessage); }); + + it('should preserve keywords when dumping', async () => { + const dir = path.resolve(testDataDir, 'yaml', 'dump'); + + const localTenantData = { + friendly_name: '##ENV## Tenant', + enabled_locales: '@@LANGUAGES@@', + }; + + cleanThenMkdir(dir); + const tenantFile = path.join(dir, 'tenant.json'); + fs.writeFileSync(tenantFile, JSON.stringify(localTenantData)); + + const context = new Context( + { + AUTH0_INPUT_FILE: dir, + AUTH0_PRESERVE_KEYWORDS: true, + AUTH0_INCLUDED_ONLY: ['tenant'], + AUTH0_KEYWORD_REPLACE_MAPPINGS: { + ENV: 'Production', + LANGUAGES: ['en', 'es'], + }, + }, + { + tenant: { + getSettings: async () => + new Promise((res) => + res({ + friendly_name: 'Production Tenant', + enabled_locales: ['en', 'es'], + }) + ), + }, + } + ); + await context.dump(); + const json = JSON.parse(fs.readFileSync(tenantFile)); + + expect(json).to.deep.equal(localTenantData); + }); }); diff --git a/test/context/yaml/context.test.js b/test/context/yaml/context.test.js index 87d34fe1f..3c6b405f3 100644 --- a/test/context/yaml/context.test.js +++ b/test/context/yaml/context.test.js @@ -16,7 +16,7 @@ describe('#YAML context validation', () => { const config = { AUTH0_INPUT_FILE: yaml }; const context = new Context(config, mockMgmtClient()); - await context.loadAssetsFromLocal(); + await context.loadAssetsFromLocal({ disableKeywordReplacement: false }); expect(context.assets.rules).to.deep.equal(null); expect(context.assets.databases).to.deep.equal(null); @@ -535,4 +535,68 @@ describe('#YAML context validation', () => { 'EXCLUDED_PROPS should NOT have any intersections with INCLUDED_PROPS. Intersections found: clients: client_secret, name' ); }); + + it('should preserve keywords when dumping', async () => { + const dir = path.resolve(testDataDir, 'yaml', 'dump'); + cleanThenMkdir(dir); + const tenantFile = path.join(dir, 'tenant.yml'); + + const localAssets = { + tenant: { + friendly_name: '##ENV## Tenant', + enabled_locales: '@@LANGUAGES@@', + }, + connections: [ + { + name: 'connection-1', + strategy: 'waad', + options: { + tenant_domain: '##DOMAIN##', + }, + }, + ], + }; + + fs.writeFileSync(tenantFile, jsYaml.dump(localAssets)); + const context = new Context( + { + AUTH0_INPUT_FILE: tenantFile, + AUTH0_PRESERVE_KEYWORDS: true, + AUTH0_INCLUDED_ONLY: ['tenant', 'connections'], + AUTH0_KEYWORD_REPLACE_MAPPINGS: { + ENV: 'Production', + LANGUAGES: ['en', 'es'], + DOMAIN: 'travel0.com', + }, + }, + { + tenant: { + getSettings: async () => + new Promise((res) => + res({ + friendly_name: 'Production Tenant', + enabled_locales: ['en', 'es'], + }) + ), + }, + connections: { + getAll: () => ({ + connections: [ + { + name: 'connection-1', + strategy: 'waad', + options: { + tenant_domain: 'travel0.com', + }, + }, + ], + }), + }, + } + ); + await context.dump(); + const yaml = jsYaml.load(fs.readFileSync(tenantFile)); + + expect(yaml).to.deep.equal(localAssets); + }); }); diff --git a/test/utils.test.js b/test/utils.test.js index 283bd3802..949218d4b 100644 --- a/test/utils.test.js +++ b/test/utils.test.js @@ -61,12 +61,12 @@ describe('#utils', function () { ]); }); - it('should load json', () => { + it('should load json and replace keywords', () => { const dir = path.join(testDataDir, 'utils', 'json'); cleanThenMkdir(dir); const file = path.join(dir, 'test1.json'); fs.writeFileSync(file, '{"test": "123", "env1": @@env1@@, "env2": "##env2##"}'); - expect(loadJSON(file, { env1: 'test1', env2: 'test2' })).to.deep.equal({ + expect(loadJSON(file, { mappings: { env1: 'test1', env2: 'test2' } })).to.deep.equal({ env1: 'test1', env2: 'test2', test: '123', From df66ab0729ad3e9f925c0b466e47e5c2fc1e1de9 Mon Sep 17 00:00:00 2001 From: Will Vedder Date: Wed, 22 Feb 2023 13:32:58 -0500 Subject: [PATCH 6/7] Fixing directory load --- src/context/directory/index.ts | 4 ++-- src/context/yaml/index.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/context/directory/index.ts b/src/context/directory/index.ts index ffc7af643..d8f5c9c49 100644 --- a/src/context/directory/index.ts +++ b/src/context/directory/index.ts @@ -76,8 +76,7 @@ export default class DirectoryContext { async dump(): Promise { const auth0 = new Auth0(this.mgmtClient, this.assets, toConfigFn(this.config)); log.info('Loading Auth0 Tenant Data'); - - await this.loadAssetsFromLocal({ disableKeywordReplacement: true }); //Need to disable keyword replacement to retrieve the raw keyword markers (ex: ##KEYWORD##) + await auth0.loadAssetsFromAuth0(); const shouldPreserveKeywords = //@ts-ignore because the string=>boolean conversion may not have happened if passed-in as env var @@ -85,6 +84,7 @@ export default class DirectoryContext { this.config.AUTH0_PRESERVE_KEYWORDS === true; if (shouldPreserveKeywords) { const localAssets = { ...this.assets }; + await this.loadAssetsFromLocal({ disableKeywordReplacement: true }); //Need to disable keyword replacement to retrieve the raw keyword markers (ex: ##KEYWORD##) //@ts-ignore delete this['assets']; diff --git a/src/context/yaml/index.ts b/src/context/yaml/index.ts index 05298ce0e..210b29219 100644 --- a/src/context/yaml/index.ts +++ b/src/context/yaml/index.ts @@ -127,7 +127,7 @@ export default class YAMLContext { this.config.AUTH0_PRESERVE_KEYWORDS === 'true' || this.config.AUTH0_PRESERVE_KEYWORDS === true; if (shouldPreserveKeywords) { - await this.loadAssetsFromLocal({ disableKeywordReplacement: true }); + await this.loadAssetsFromLocal({ disableKeywordReplacement: true }); //Need to disable keyword replacement to retrieve the raw keyword markers (ex: ##KEYWORD##) const localAssets = { ...this.assets }; //@ts-ignore delete this['assets']; From f1f6a407fc37ccecf427bffb59cd2ab9c5f9daea Mon Sep 17 00:00:00 2001 From: Will Vedder Date: Wed, 22 Feb 2023 14:07:27 -0500 Subject: [PATCH 7/7] Fixing directory load again --- src/context/directory/index.ts | 2 +- test/context/directory/context.test.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/context/directory/index.ts b/src/context/directory/index.ts index d8f5c9c49..12f52104c 100644 --- a/src/context/directory/index.ts +++ b/src/context/directory/index.ts @@ -83,8 +83,8 @@ export default class DirectoryContext { this.config.AUTH0_PRESERVE_KEYWORDS === 'true' || this.config.AUTH0_PRESERVE_KEYWORDS === true; if (shouldPreserveKeywords) { - const localAssets = { ...this.assets }; await this.loadAssetsFromLocal({ disableKeywordReplacement: true }); //Need to disable keyword replacement to retrieve the raw keyword markers (ex: ##KEYWORD##) + const localAssets = { ...this.assets }; //@ts-ignore delete this['assets']; diff --git a/test/context/directory/context.test.js b/test/context/directory/context.test.js index ed1e51d71..9bcbbfe0b 100644 --- a/test/context/directory/context.test.js +++ b/test/context/directory/context.test.js @@ -134,7 +134,7 @@ describe('#directory context validation', () => { }); it('should preserve keywords when dumping', async () => { - const dir = path.resolve(testDataDir, 'yaml', 'dump'); + const dir = path.resolve(testDataDir, 'directory', 'dump'); const localTenantData = { friendly_name: '##ENV## Tenant',