From 000b36df6bdb29c99d918507ac13673d950af092 Mon Sep 17 00:00:00 2001 From: kushalshit27 <43465488+kushalshit27@users.noreply.github.com> Date: Mon, 3 Feb 2025 22:24:22 +0530 Subject: [PATCH 01/12] feat: add experimental early access feature command --- src/args.ts | 7 +++++++ src/commands/export.ts | 9 +++++++++ src/commands/import.ts | 9 +++++++++ src/context/index.ts | 15 +++++++++++++++ src/tools/auth0/handlers/prompts.ts | 16 ++++++++++------ src/types.ts | 1 + 6 files changed, 51 insertions(+), 6 deletions(-) diff --git a/src/args.ts b/src/args.ts index 4555df055..bc2252e8e 100644 --- a/src/args.ts +++ b/src/args.ts @@ -9,6 +9,7 @@ type SharedParams = { secret?: string; base_path?: string; // Necessary when package imported as Node module config?: Partial; + experimental_ea?: boolean; }; type ImportSpecificParams = { @@ -43,6 +44,12 @@ function getParams(): CliParams { describe: 'A url for proxying requests, only set this if you are behind a proxy.', type: 'string', }) + .option('experimental_ea', { + alias: 'ea', + describe: 'This will enable supoort experimental early access of features/resource types.', + type: 'boolean', + default: false, + }) .command(['import', 'deploy'], 'Deploy Configuration', { input_file: { alias: 'i', diff --git a/src/commands/export.ts b/src/commands/export.ts index 9c721d94d..6427ae75d 100644 --- a/src/commands/export.ts +++ b/src/commands/export.ts @@ -17,6 +17,7 @@ export default async function exportCMD(params: ExportParams) { export_ids: exportIds, secret: clientSecret, env: shouldInheritEnv = false, + experimental_ea: experimentalEA, } = params; if (shouldInheritEnv) { @@ -44,6 +45,14 @@ export default async function exportCMD(params: ExportParams) { overrides.AUTH0_EXPORT_IDENTIFIERS = exportIds; } + // Overrides AUTH0_INCLUDE_EXPERIMENTAL_EA is experimental_ea passed in command line + if (experimentalEA) { + overrides.AUTH0_EXPERIMENTAL_EA = experimentalEA; + + // nconf.overrides() sometimes doesn't work, so we need to set it manually to ensure it's set + nconf.set('AUTH0_EXPERIMENTAL_EA', experimentalEA); + } + // Check output folder if (!isDirectory(outputFolder)) { log.info(`Creating ${outputFolder}`); diff --git a/src/commands/import.ts b/src/commands/import.ts index ce81bc2ad..527d972c9 100644 --- a/src/commands/import.ts +++ b/src/commands/import.ts @@ -13,6 +13,7 @@ export default async function importCMD(params: ImportParams) { config: configObj, env: shouldInheritEnv = false, secret: clientSecret, + experimental_ea: experimentalEA, } = params; if (shouldInheritEnv) { @@ -39,6 +40,14 @@ export default async function importCMD(params: ImportParams) { overrides.AUTH0_CLIENT_SECRET = clientSecret; } + // Overrides AUTH0_INCLUDE_EXPERIMENTAL_EA is experimental_ea passed in command line + if (experimentalEA) { + overrides.AUTH0_EXPERIMENTAL_EA = experimentalEA; + + // nconf.overrides() sometimes doesn't work, so we need to set it manually to ensure it's set + nconf.set('AUTH0_EXPERIMENTAL_EA', experimentalEA); + } + nconf.overrides(overrides); // Setup context and load diff --git a/src/context/index.ts b/src/context/index.ts index 86267c60b..f44ea8845 100644 --- a/src/context/index.ts +++ b/src/context/index.ts @@ -26,6 +26,8 @@ const nonPrimitiveProps: (keyof Config)[] = [ 'INCLUDED_PROPS', ]; +const EA_FEATURES = ['ACUL', 'wewewe']; + export const setupContext = async ( config: Config, command: 'import' | 'export' @@ -132,6 +134,19 @@ export const setupContext = async ( } })(config); + ((config: Config) => { + // Check if experimental early access features are enabled + if (config.AUTH0_EXPERIMENTAL_EA) { + log.warn( + `Experimental early access ${ + EA_FEATURES.length === 1 + ? 'feature [' + EA_FEATURES.join('') + '] is' + : 'features [' + EA_FEATURES.join(',') + '] are' + } enabled. These are in a pre-release state and may change in future release.` + ); + } + })(config); + const accessToken = await (async (): Promise => { const { AUTH0_DOMAIN, diff --git a/src/tools/auth0/handlers/prompts.ts b/src/tools/auth0/handlers/prompts.ts index 7ce85c44b..f923cc4f1 100644 --- a/src/tools/auth0/handlers/prompts.ts +++ b/src/tools/auth0/handlers/prompts.ts @@ -347,11 +347,15 @@ export default class PromptsHandler extends DefaultHandler { partials, }; - try { - const screenRenderers = await this.getPromptScreenSettings(); - prompts.screenRenderers = screenRenderers; - } catch (error) { - log.warn(`Unable to fetch screen renderers: ${error}`); + const includeExperimentalEA = this.config('AUTH0_EXPERIMENTAL_EA') || false; + + if (includeExperimentalEA) { + try { + const screenRenderers = await this.getPromptScreenSettings(); + prompts.screenRenderers = screenRenderers; + } catch (error) { + log.warn(`Unable to fetch screen renderers: ${error}`); + } } return prompts; @@ -608,7 +612,7 @@ export default class PromptsHandler extends DefaultHandler { } else { updatePayload = { ...updatePrams, - rendering_mode + rendering_mode, }; } diff --git a/src/types.ts b/src/types.ts index 95dbd15d9..2d2c7b2ba 100644 --- a/src/types.ts +++ b/src/types.ts @@ -78,6 +78,7 @@ export type Config = { AUTH0_EXCLUDED_CONNECTIONS?: string[]; AUTH0_EXCLUDED_RESOURCE_SERVERS?: string[]; AUTH0_EXCLUDED_DEFAULTS?: string[]; + AUTH0_EXPERIMENTAL_EA: boolean; }; // TODO: replace with a more accurate representation of the Config type export type Asset = { [key: string]: any }; From b2017c26df24423f0cd62c80a6d58dda3276b572 Mon Sep 17 00:00:00 2001 From: kushalshit27 <43465488+kushalshit27@users.noreply.github.com> Date: Tue, 4 Feb 2025 10:45:43 +0530 Subject: [PATCH 02/12] refine unit test for prompts --- src/context/index.ts | 2 +- src/tools/auth0/handlers/prompts.ts | 8 +- test/context/directory/prompts.test.ts | 243 ++++++++++--------- test/context/yaml/context.test.js | 21 +- test/tools/auth0/handlers/databases.tests.js | 6 +- test/tools/auth0/handlers/prompts.tests.ts | 13 +- test/utils.js | 14 +- 7 files changed, 172 insertions(+), 135 deletions(-) diff --git a/src/context/index.ts b/src/context/index.ts index f44ea8845..7cf7b7e08 100644 --- a/src/context/index.ts +++ b/src/context/index.ts @@ -26,7 +26,7 @@ const nonPrimitiveProps: (keyof Config)[] = [ 'INCLUDED_PROPS', ]; -const EA_FEATURES = ['ACUL', 'wewewe']; +const EA_FEATURES = ['ACUL']; export const setupContext = async ( config: Config, diff --git a/src/tools/auth0/handlers/prompts.ts b/src/tools/auth0/handlers/prompts.ts index f923cc4f1..d832faa56 100644 --- a/src/tools/auth0/handlers/prompts.ts +++ b/src/tools/auth0/handlers/prompts.ts @@ -531,8 +531,12 @@ export default class PromptsHandler extends DefaultHandler { await this.updateCustomTextSettings(customText); await this.updateCustomPromptsPartials(partials); - // Update screen renderers - await this.updateScreenRenderers(screenRenderers); + const includeExperimentalEA = this.config('AUTH0_EXPERIMENTAL_EA') || false; + + if (includeExperimentalEA) { + // Update screen renderers + await this.updateScreenRenderers(screenRenderers); + } this.updated += 1; this.didUpdate(prompts); diff --git a/test/context/directory/prompts.test.ts b/test/context/directory/prompts.test.ts index f6018a491..705de2b08 100644 --- a/test/context/directory/prompts.test.ts +++ b/test/context/directory/prompts.test.ts @@ -15,7 +15,10 @@ import { const dir = path.join(testDataDir, 'directory', 'promptsDump'); const promptsDirectory = path.join(dir, constants.PROMPTS_DIRECTORY); -const promptsScreenSettingsDirectory = path.join(promptsDirectory, constants.PROMPTS_SCREEN_RENDER_DIRECTORY); +const promptsScreenSettingsDirectory = path.join( + promptsDirectory, + constants.PROMPTS_SCREEN_RENDER_DIRECTORY +); const promptsSettingsFile = 'prompts.json'; const customTextFile = 'custom-text.json'; @@ -83,62 +86,64 @@ describe('#directory context prompts', () => { const settingsfiles = { [constants.PROMPTS_SCREEN_RENDER_DIRECTORY]: { [signupIdSettingsFile]: JSON.stringify({ - 'prompt': 'signup-id', - 'screen': 'signup-id', - 'rendering_mode': 'standard', - 'context_configuration': [], - 'default_head_tags_disabled': false, - 'head_tags': [ + prompt: 'signup-id', + screen: 'signup-id', + rendering_mode: 'standard', + context_configuration: [], + default_head_tags_disabled: false, + head_tags: [ { - 'tag': 'script', - 'attributes': { - 'src': 'URL_TO_YOUR_ASSET', - 'async': true, - 'defer': true, - 'integrity': [ - 'ASSET_SHA' - ] - } - } - ] + tag: 'script', + attributes: { + src: 'URL_TO_YOUR_ASSET', + async: true, + defer: true, + integrity: ['ASSET_SHA'], + }, + }, + ], }), [loginIdSettingsFile]: JSON.stringify({ - 'prompt': 'login-id', - 'screen': 'login-id', - 'rendering_mode': 'advanced', - 'context_configuration': [], - 'default_head_tags_disabled': false, - 'head_tags': [ + prompt: 'login-id', + screen: 'login-id', + rendering_mode: 'advanced', + context_configuration: [], + default_head_tags_disabled: false, + head_tags: [ { - 'tag': 'script', - 'attributes': { - 'src': 'http://127.0.0.1:8080/index.js', - 'defer': true - } + tag: 'script', + attributes: { + src: 'http://127.0.0.1:8080/index.js', + defer: true, + }, }, { - 'tag': 'link', - 'attributes': { - 'rel': 'stylesheet', - 'href': 'http://127.0.0.1:8090/index.css' - } + tag: 'link', + attributes: { + rel: 'stylesheet', + href: 'http://127.0.0.1:8090/index.css', + }, }, { - 'tag': 'meta', - 'attributes': { - 'name': 'viewport', - 'content': 'width=device-width, initial-scale=1' - } - } - ] + tag: 'meta', + attributes: { + name: 'viewport', + content: 'width=device-width, initial-scale=1', + }, + }, + ], }), - } + }, }; const repoDir = path.join(testDataDir, 'directory', 'prompts'); createDir(repoDir, files); - const settingsDir = path.join(repoDir,constants.PROMPTS_DIRECTORY, constants.PROMPTS_SCREEN_RENDER_DIRECTORY); + const settingsDir = path.join( + repoDir, + constants.PROMPTS_DIRECTORY, + constants.PROMPTS_SCREEN_RENDER_DIRECTORY + ); createDir(settingsDir, settingsfiles); const partialsDir = path.join( @@ -169,13 +174,15 @@ describe('#directory context prompts', () => { ); const signupIdSettingsFiles = { - 'signup-id_signup-id.json': '{ "prompt": "signup-id", "screen": "signup-id", "rendering_mode": "advanced","default_head_tags_disabled": false,' + + 'signup-id_signup-id.json': + '{ "prompt": "signup-id", "screen": "signup-id", "rendering_mode": "advanced","default_head_tags_disabled": false,' + '"context_configuration": [ "branding.settings", "branding.themes.default"], "head_tags": [{"attributes": {"async": true, "defer": true , ' + '"integrity": ["sha512-v2CJ7UaYy4JwqLDIrZUI/4hqeoQieOmAZNXBeQyjo21dadnwR+8ZaIJVT8EE2iyI61OV8e6M8PP2/4hpQINQ/g=="], "src": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js"}, "tag": "script"}]}', - 'login-id_login-id.json': '{ "prompt": "login-id", "screen": "login-id", "rendering_mode": "standard", "context_configuration": [],"default_head_tags_disabled": false}', + 'login-id_login-id.json': + '{ "prompt": "login-id", "screen": "login-id", "rendering_mode": "standard", "context_configuration": [],"default_head_tags_disabled": false}', }; - createDir(repoDir, { [screenSettingsDir]:signupIdSettingsFiles }); + createDir(repoDir, { [screenSettingsDir]: signupIdSettingsFiles }); const config = { AUTH0_INPUT_FILE: repoDir, @@ -227,32 +234,32 @@ describe('#directory context prompts', () => { }, screenRenderers: [ { - 'prompt': 'login-id', - 'screen': 'login-id', - 'rendering_mode': 'standard', - 'context_configuration': [], - 'default_head_tags_disabled': false, + prompt: 'login-id', + screen: 'login-id', + rendering_mode: 'standard', + context_configuration: [], + default_head_tags_disabled: false, }, { - 'prompt': 'signup-id', - 'screen': 'signup-id', - 'rendering_mode': 'advanced', - 'context_configuration': ['branding.settings','branding.themes.default'], - 'default_head_tags_disabled': false, - 'head_tags': [ + prompt: 'signup-id', + screen: 'signup-id', + rendering_mode: 'advanced', + context_configuration: ['branding.settings', 'branding.themes.default'], + default_head_tags_disabled: false, + head_tags: [ { - 'tag': 'script', - 'attributes': { - 'src': 'https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js', - 'async': true, - 'defer': true, - 'integrity': [ - 'sha512-v2CJ7UaYy4JwqLDIrZUI/4hqeoQieOmAZNXBeQyjo21dadnwR+8ZaIJVT8EE2iyI61OV8e6M8PP2/4hpQINQ/g==' - ] - } - } - ] - } + tag: 'script', + attributes: { + src: 'https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js', + async: true, + defer: true, + integrity: [ + 'sha512-v2CJ7UaYy4JwqLDIrZUI/4hqeoQieOmAZNXBeQyjo21dadnwR+8ZaIJVT8EE2iyI61OV8e6M8PP2/4hpQINQ/g==', + ], + }, + }, + ], + }, ], }); }); @@ -504,32 +511,32 @@ describe('#directory context prompts', () => { }, screenRenderers: [ { - 'prompt': 'login-id', - 'screen': 'login-id', - 'rendering_mode': 'standard', - 'context_configuration': [], - 'default_head_tags_disabled': false, + prompt: 'login-id', + screen: 'login-id', + rendering_mode: 'standard', + context_configuration: [], + default_head_tags_disabled: false, }, { - 'prompt': 'signup-id', - 'screen': 'signup-id', - 'rendering_mode': 'advanced', - 'context_configuration': ['branding.settings','branding.themes.default'], - 'default_head_tags_disabled': false, - 'head_tags': [ + prompt: 'signup-id', + screen: 'signup-id', + rendering_mode: 'advanced', + context_configuration: ['branding.settings', 'branding.themes.default'], + default_head_tags_disabled: false, + head_tags: [ { - 'tag': 'script', - 'attributes': { - 'src': 'https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js', - 'async': true, - 'defer': true, - 'integrity': [ - 'sha512-v2CJ7UaYy4JwqLDIrZUI/4hqeoQieOmAZNXBeQyjo21dadnwR+8ZaIJVT8EE2iyI61OV8e6M8PP2/4hpQINQ/g==' - ] - } - } - ] - } + tag: 'script', + attributes: { + src: 'https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js', + async: true, + defer: true, + integrity: [ + 'sha512-v2CJ7UaYy4JwqLDIrZUI/4hqeoQieOmAZNXBeQyjo21dadnwR+8ZaIJVT8EE2iyI61OV8e6M8PP2/4hpQINQ/g==', + ], + }, + }, + ], + }, ], }; @@ -579,33 +586,37 @@ describe('#directory context prompts', () => { identifier_first: context.assets.prompts.identifier_first, }); - expect(loadJSON(path.join(promptsScreenSettingsDirectory, loginIdSettingsFile), {})).to.deep.equal({ - 'prompt': 'login-id', - 'screen': 'login-id', - 'rendering_mode': 'standard', - 'context_configuration': [], - 'default_head_tags_disabled': false, + expect( + loadJSON(path.join(promptsScreenSettingsDirectory, loginIdSettingsFile), {}) + ).to.deep.equal({ + prompt: 'login-id', + screen: 'login-id', + rendering_mode: 'standard', + context_configuration: [], + default_head_tags_disabled: false, }); - expect(loadJSON(path.join(promptsScreenSettingsDirectory, signupIdSettingsFile), {})).to.deep.equal({ - 'prompt': 'signup-id', - 'screen': 'signup-id', - 'rendering_mode': 'advanced', - 'context_configuration': ['branding.settings','branding.themes.default'], - 'default_head_tags_disabled': false, - 'head_tags': [ + expect( + loadJSON(path.join(promptsScreenSettingsDirectory, signupIdSettingsFile), {}) + ).to.deep.equal({ + prompt: 'signup-id', + screen: 'signup-id', + rendering_mode: 'advanced', + context_configuration: ['branding.settings', 'branding.themes.default'], + default_head_tags_disabled: false, + head_tags: [ { - 'tag': 'script', - 'attributes': { - 'src': 'https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js', - 'async': true, - 'defer': true, - 'integrity': [ - 'sha512-v2CJ7UaYy4JwqLDIrZUI/4hqeoQieOmAZNXBeQyjo21dadnwR+8ZaIJVT8EE2iyI61OV8e6M8PP2/4hpQINQ/g==' - ] - } - } - ] + tag: 'script', + attributes: { + src: 'https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js', + async: true, + defer: true, + integrity: [ + 'sha512-v2CJ7UaYy4JwqLDIrZUI/4hqeoQieOmAZNXBeQyjo21dadnwR+8ZaIJVT8EE2iyI61OV8e6M8PP2/4hpQINQ/g==', + ], + }, + }, + ], }); }); }); diff --git a/test/context/yaml/context.test.js b/test/context/yaml/context.test.js index d084c2564..991f7e03c 100644 --- a/test/context/yaml/context.test.js +++ b/test/context/yaml/context.test.js @@ -234,7 +234,11 @@ describe('#YAML context validation', () => { { body: './emailTemplates/mfa_oob_code.html', enabled: true, template: 'mfa_oob_code' }, { body: './emailTemplates/password_reset.html', enabled: true, template: 'password_reset' }, { body: './emailTemplates/reset_email.html', enabled: true, template: 'reset_email' }, - { body: './emailTemplates/reset_email_by_code.html',enabled: true,template: 'reset_email_by_code' }, + { + body: './emailTemplates/reset_email_by_code.html', + enabled: true, + template: 'reset_email_by_code', + }, { body: './emailTemplates/stolen_credentials.html', enabled: true, @@ -293,7 +297,6 @@ describe('#YAML context validation', () => { prompts: { customText: {}, partials: {}, - screenRenderers: [], }, customDomains: [], themes: [], @@ -310,6 +313,7 @@ describe('#YAML context validation', () => { const tenantFile = path.join(dir, 'tenant.yml'); const config = { AUTH0_INPUT_FILE: tenantFile, + AUTH0_EXPERIMENTAL_EA: true, AUTH0_EXCLUDED_DEFAULTS: ['emailProvider'], }; const context = new Context(config, mockMgmtClient()); @@ -352,7 +356,11 @@ describe('#YAML context validation', () => { { body: './emailTemplates/mfa_oob_code.html', enabled: true, template: 'mfa_oob_code' }, { body: './emailTemplates/password_reset.html', enabled: true, template: 'password_reset' }, { body: './emailTemplates/reset_email.html', enabled: true, template: 'reset_email' }, - { body: './emailTemplates/reset_email_by_code.html',enabled: true,template: 'reset_email_by_code' }, + { + body: './emailTemplates/reset_email_by_code.html', + enabled: true, + template: 'reset_email_by_code', + }, { body: './emailTemplates/stolen_credentials.html', enabled: true, @@ -471,7 +479,11 @@ describe('#YAML context validation', () => { { body: './emailTemplates/mfa_oob_code.html', enabled: true, template: 'mfa_oob_code' }, { body: './emailTemplates/password_reset.html', enabled: true, template: 'password_reset' }, { body: './emailTemplates/reset_email.html', enabled: true, template: 'reset_email' }, - { body: './emailTemplates/reset_email_by_code.html',enabled: true,template: 'reset_email_by_code' }, + { + body: './emailTemplates/reset_email_by_code.html', + enabled: true, + template: 'reset_email_by_code', + }, { body: './emailTemplates/stolen_credentials.html', enabled: true, @@ -529,7 +541,6 @@ describe('#YAML context validation', () => { prompts: { customText: {}, partials: {}, - screenRenderers: [], }, logStreams: [], customDomains: [], diff --git a/test/tools/auth0/handlers/databases.tests.js b/test/tools/auth0/handlers/databases.tests.js index 89791839b..68325d4a9 100644 --- a/test/tools/auth0/handlers/databases.tests.js +++ b/test/tools/auth0/handlers/databases.tests.js @@ -865,7 +865,7 @@ describe('#databases handler', () => { active: true, }, profile_required: true, - verification_method:'link' + verification_method: 'link', }, username: { signup: { @@ -1098,7 +1098,7 @@ describe('#databases handler', () => { active: true, }, profile_required: true, - verification_method:'otp', + verification_method: 'otp', }, username: { signup: { @@ -1481,7 +1481,7 @@ describe('#databases handler', () => { active: true, }, profile_required: true, - verification_method:'link', + verification_method: 'link', }, username: { signup: { diff --git a/test/tools/auth0/handlers/prompts.tests.ts b/test/tools/auth0/handlers/prompts.tests.ts index b63e9a1a1..01a1200e6 100644 --- a/test/tools/auth0/handlers/prompts.tests.ts +++ b/test/tools/auth0/handlers/prompts.tests.ts @@ -13,6 +13,14 @@ const mockPromptsSettings = { }; describe('#prompts handler', () => { + const config = function (key) { + return config.data && config.data[key]; + }; + + config.data = { + AUTH0_EXPERIMENTAL_EA: true, + }; + describe('#prompts process', () => { it('should get prompts settings, custom texts, template partials and screen renderer', async () => { const supportedLanguages: Language[] = ['es', 'fr', 'en']; @@ -120,6 +128,7 @@ describe('#prompts handler', () => { const handler = new promptsHandler({ client: auth0, + config: config, }); const getCustomPartial = sinon.stub(handler, 'getCustomPartial'); @@ -187,6 +196,7 @@ describe('#prompts handler', () => { const handler = new promptsHandler({ client: auth0, + config: config, }); sinon.stub(handler, 'updateCustomPartials').callsFake(() => { didCallUpdatePartials = true; @@ -296,6 +306,7 @@ describe('#prompts handler', () => { const handler = new promptsHandler({ client: auth0, + config: config, }); sinon.stub(handler, 'updateCustomPartials').callsFake(() => { @@ -349,7 +360,7 @@ describe('#prompts handler', () => { }), }; - const handler = new promptsHandler({ client: auth0 }); + const handler = new promptsHandler({ client: auth0, config: config }); const getCustomPartial = sinon.stub(handler, 'getCustomPartial'); getCustomPartial.withArgs({ prompt: 'login' }).resolves({}); getCustomPartial.withArgs({ prompt: 'login-id' }).resolves({}); diff --git a/test/utils.js b/test/utils.js index 4017a9781..77aed0955 100644 --- a/test/utils.js +++ b/test/utils.js @@ -16,14 +16,14 @@ export const testDataDir = path.resolve(localDir, 'testData'); export function mockPagedData(params, key, data) { return params?.include_totals ? { - data: { - [key]: data, - total: data?.length || 0, - }, - } + data: { + [key]: data, + total: data?.length || 0, + }, + } : { - data, - }; + data, + }; } export function mockMgmtClient() { From bc5823f1d723975e5f6db1242114aa39bb03b945 Mon Sep 17 00:00:00 2001 From: kushalshit27 <43465488+kushalshit27@users.noreply.github.com> Date: Tue, 4 Feb 2025 10:53:14 +0530 Subject: [PATCH 03/12] lint fix --- test/utils.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/test/utils.js b/test/utils.js index 77aed0955..4017a9781 100644 --- a/test/utils.js +++ b/test/utils.js @@ -16,14 +16,14 @@ export const testDataDir = path.resolve(localDir, 'testData'); export function mockPagedData(params, key, data) { return params?.include_totals ? { - data: { - [key]: data, - total: data?.length || 0, - }, - } + data: { + [key]: data, + total: data?.length || 0, + }, + } : { - data, - }; + data, + }; } export function mockMgmtClient() { From a076896b8f09e839a3a11bc8ddc04115b42ce4c7 Mon Sep 17 00:00:00 2001 From: kushalshit27 <43465488+kushalshit27@users.noreply.github.com> Date: Tue, 4 Feb 2025 11:11:24 +0530 Subject: [PATCH 04/12] update doc --- docs/using-as-cli.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/docs/using-as-cli.md b/docs/using-as-cli.md index 6b80ba033..e0c13b8f8 100644 --- a/docs/using-as-cli.md +++ b/docs/using-as-cli.md @@ -34,6 +34,10 @@ Boolean. Enables more verbose error logging; useful during troubleshooting. Defa A url for proxying requests. Only set this if you are behind a proxy. +### `--experimental-ea`, `--ea` + +Boolean. Enables early access Auth0 resources support and experimental features. + ### Examples ```shell @@ -71,6 +75,10 @@ A url for proxying requests. Only set this if you are behind a proxy. Boolean. Enables more verbose error logging; useful during troubleshooting. Default: `false`. +### `--experimental-ea`, `--ea` + +Boolean. Enables early access Auth0 resources support and experimental features. + ### Examples ```shell From 517fec5a43722b76145e3affba0289f91aa8fd6b Mon Sep 17 00:00:00 2001 From: kushalshit27 <43465488+kushalshit27@users.noreply.github.com> Date: Tue, 4 Feb 2025 13:40:18 +0530 Subject: [PATCH 05/12] update unit test --- src/tools/auth0/handlers/prompts.ts | 1 + test/tools/auth0/handlers/prompts.tests.ts | 107 +++++++++++++++++++++ 2 files changed, 108 insertions(+) diff --git a/src/tools/auth0/handlers/prompts.ts b/src/tools/auth0/handlers/prompts.ts index d832faa56..dbb91aa90 100644 --- a/src/tools/auth0/handlers/prompts.ts +++ b/src/tools/auth0/handlers/prompts.ts @@ -533,6 +533,7 @@ export default class PromptsHandler extends DefaultHandler { const includeExperimentalEA = this.config('AUTH0_EXPERIMENTAL_EA') || false; + console.log('CLOG: includeExperimentalEA', includeExperimentalEA); if (includeExperimentalEA) { // Update screen renderers await this.updateScreenRenderers(screenRenderers); diff --git a/test/tools/auth0/handlers/prompts.tests.ts b/test/tools/auth0/handlers/prompts.tests.ts index 01a1200e6..6e023509a 100644 --- a/test/tools/auth0/handlers/prompts.tests.ts +++ b/test/tools/auth0/handlers/prompts.tests.ts @@ -335,6 +335,111 @@ describe('#prompts handler', () => { expect(numberOfUpdatePartialsCalls).to.equal(3); }); + it('should update prompts settings and custom text/partials, not screen renderer settings when AUTH0_EXPERIMENTAL_EA=false', async () => { + let didCallUpdatePromptsSettings = false; + let didCallUpdateCustomText = false; + let didCallUpdatePartials = false; + let numberOfUpdateCustomTextCalls = 0; + let numberOfUpdatePartialsCalls = 0; + let didCallUpdateScreenRenderer = false; + + const customTextToSet = { + en: { + login: { + buttonText: 'button text2', + description: 'description text', + title: 'title text', + }, + 'mfa-webauthn': {}, + }, + fr: { + login: { + buttonText: 'french button text', + description: 'french description text', + title: 'french title text', + }, + }, + }; + + const partialsToSet: Prompts['partials'] = { + login: { + login: { + 'form-content-start': '
TEST
', + }, + }, + 'signup-id': { + 'signup-id': { + 'form-content-start': '
TEST
', + }, + }, + 'signup-password': { + 'signup-password': { + 'form-content-start': '
TEST
', + }, + }, + }; + const screenRenderersToSet: Prompts['screenRenderers'] = []; + + const auth0 = { + prompts: { + updateCustomTextByLanguage: () => { + didCallUpdateCustomText = true; + numberOfUpdateCustomTextCalls++; + return Promise.resolve({ data: {} }); + }, + update: (data) => { + didCallUpdatePromptsSettings = true; + expect(data).to.deep.equal(mockPromptsSettings); + return Promise.resolve({ data }); + }, + updateRendering: () => { + didCallUpdateScreenRenderer = true; + return Promise.resolve({ data: {} }); + }, + _getRestClient: (endpoint) => ({ + get: (...options) => Promise.resolve({ endpoint, method: 'get', options }), + }), + }, + pool: new PromisePoolExecutor({ + concurrencyLimit: 3, + frequencyLimit: 1000, + frequencyWindow: 1000, // 1 sec + }), + }; + + config.data.AUTH0_EXPERIMENTAL_EA = false; + + const handler = new promptsHandler({ + client: auth0, + config: config, + }); + + sinon.stub(handler, 'updateCustomPartials').callsFake(() => { + didCallUpdatePartials = true; + numberOfUpdatePartialsCalls++; + return Promise.resolve({}); + }); + + const stageFn = Object.getPrototypeOf(handler).processChanges; + + await stageFn.apply(handler, [ + { + prompts: { + ...mockPromptsSettings, + customText: customTextToSet, + partials: partialsToSet, + screenRenderers: screenRenderersToSet, + }, + }, + ]); + expect(didCallUpdatePromptsSettings).to.equal(true); + expect(didCallUpdateCustomText).to.equal(true); + expect(didCallUpdatePartials).to.equal(true); + expect(didCallUpdateScreenRenderer).to.equal(false); + expect(numberOfUpdateCustomTextCalls).to.equal(3); + expect(numberOfUpdatePartialsCalls).to.equal(3); + }); + it('should not fail if tenant languages or partials are undefined', async () => { const auth0 = { tenants: { @@ -360,6 +465,8 @@ describe('#prompts handler', () => { }), }; + config.data.AUTH0_EXPERIMENTAL_EA = true; + const handler = new promptsHandler({ client: auth0, config: config }); const getCustomPartial = sinon.stub(handler, 'getCustomPartial'); getCustomPartial.withArgs({ prompt: 'login' }).resolves({}); From aefd05e4f6026c23746779887ff7af404a80e505 Mon Sep 17 00:00:00 2001 From: kushalshit27 <43465488+kushalshit27@users.noreply.github.com> Date: Tue, 4 Feb 2025 14:23:28 +0530 Subject: [PATCH 06/12] update unit test --- test/configFactory.test.ts | 41 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 test/configFactory.test.ts diff --git a/test/configFactory.test.ts b/test/configFactory.test.ts new file mode 100644 index 000000000..9d77332ea --- /dev/null +++ b/test/configFactory.test.ts @@ -0,0 +1,41 @@ +import { expect } from 'chai'; +import { configFactory, ConfigFunction } from '../src/configFactory'; +import { Config } from '../src/types'; + +describe('configFactory', () => { + let config: ReturnType; + + beforeEach(() => { + config = configFactory(); + }); + + it('should set and get configuration values', () => { + config.setValue('someKey' as keyof Config, 'someValue'); + expect(config('someKey' as keyof Config)).to.equal('someValue'); + }); + + it('should throw an error if no provider is set and key is not in settings', () => { + expect(() => config('someKey' as keyof Config)).to.throw( + 'A configuration provider has not been set' + ); + }); + + it('should use the provider function to get configuration values', () => { + const providerFunction: ConfigFunction = (key) => { + if ((key as string) === 'someKey') return 'providedValue'; + return null; + }; + config.setProvider(providerFunction); + expect(config('someKey' as keyof Config)).to.equal('providedValue'); + }); + + it('should prioritize settings over provider function', () => { + config.setValue('someKey' as keyof Config, 'someValue'); + const providerFunction: ConfigFunction = (key) => { + if ((key as string) === 'someKey') return 'providedValue'; + return null; + }; + config.setProvider(providerFunction); + expect(config('someKey' as keyof Config)).to.equal('someValue'); + }); +}); From ca1f2c889a0102f316bef318a00e477d4017e2e3 Mon Sep 17 00:00:00 2001 From: kushalshit27 <43465488+kushalshit27@users.noreply.github.com> Date: Tue, 4 Feb 2025 14:45:54 +0530 Subject: [PATCH 07/12] update doc --- docs/using-as-cli.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/using-as-cli.md b/docs/using-as-cli.md index e0c13b8f8..2a699e564 100644 --- a/docs/using-as-cli.md +++ b/docs/using-as-cli.md @@ -34,7 +34,7 @@ Boolean. Enables more verbose error logging; useful during troubleshooting. Defa A url for proxying requests. Only set this if you are behind a proxy. -### `--experimental-ea`, `--ea` +### `--experimental_ea`, `--ea` Boolean. Enables early access Auth0 resources support and experimental features. @@ -75,7 +75,7 @@ A url for proxying requests. Only set this if you are behind a proxy. Boolean. Enables more verbose error logging; useful during troubleshooting. Default: `false`. -### `--experimental-ea`, `--ea` +### `--experimental_ea`, `--ea` Boolean. Enables early access Auth0 resources support and experimental features. From a21355686844434a7da4e70b9806733969b43f4a Mon Sep 17 00:00:00 2001 From: kushalshit27 <43465488+kushalshit27@users.noreply.github.com> Date: Tue, 4 Feb 2025 15:15:58 +0530 Subject: [PATCH 08/12] update doc --- docs/using-as-cli.md | 8 ++++---- src/args.ts | 1 - 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/docs/using-as-cli.md b/docs/using-as-cli.md index 2a699e564..1257f02c6 100644 --- a/docs/using-as-cli.md +++ b/docs/using-as-cli.md @@ -34,9 +34,9 @@ Boolean. Enables more verbose error logging; useful during troubleshooting. Defa A url for proxying requests. Only set this if you are behind a proxy. -### `--experimental_ea`, `--ea` +### `--experimental_ea` -Boolean. Enables early access Auth0 resources support and experimental features. +Boolean. Enables early access Auth0 resources support and experimental features. Default: `false`. ### Examples @@ -75,9 +75,9 @@ A url for proxying requests. Only set this if you are behind a proxy. Boolean. Enables more verbose error logging; useful during troubleshooting. Default: `false`. -### `--experimental_ea`, `--ea` +### `--experimental_ea` -Boolean. Enables early access Auth0 resources support and experimental features. +Boolean. Enables early access Auth0 resources support and experimental features. Default: `false`. ### Examples diff --git a/src/args.ts b/src/args.ts index bc2252e8e..c7a48c889 100644 --- a/src/args.ts +++ b/src/args.ts @@ -45,7 +45,6 @@ function getParams(): CliParams { type: 'string', }) .option('experimental_ea', { - alias: 'ea', describe: 'This will enable supoort experimental early access of features/resource types.', type: 'boolean', default: false, From ad849eed96875bb7920f5dc355c30a4982186404 Mon Sep 17 00:00:00 2001 From: kushalshit27 <43465488+kushalshit27@users.noreply.github.com> Date: Wed, 5 Feb 2025 16:02:57 +0530 Subject: [PATCH 09/12] remove clog --- src/tools/auth0/handlers/prompts.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/tools/auth0/handlers/prompts.ts b/src/tools/auth0/handlers/prompts.ts index dbb91aa90..d832faa56 100644 --- a/src/tools/auth0/handlers/prompts.ts +++ b/src/tools/auth0/handlers/prompts.ts @@ -533,7 +533,6 @@ export default class PromptsHandler extends DefaultHandler { const includeExperimentalEA = this.config('AUTH0_EXPERIMENTAL_EA') || false; - console.log('CLOG: includeExperimentalEA', includeExperimentalEA); if (includeExperimentalEA) { // Update screen renderers await this.updateScreenRenderers(screenRenderers); From 09ae8d8e6f5c29f3104d2e720dbedb9151911aeb Mon Sep 17 00:00:00 2001 From: kushalshit27 <43465488+kushalshit27@users.noreply.github.com> Date: Wed, 5 Feb 2025 18:20:17 +0530 Subject: [PATCH 10/12] update documentation for experimental features and add logging instruction --- docs/using-as-cli.md | 4 ++-- src/context/index.ts | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/docs/using-as-cli.md b/docs/using-as-cli.md index 1257f02c6..0f28d6287 100644 --- a/docs/using-as-cli.md +++ b/docs/using-as-cli.md @@ -36,7 +36,7 @@ A url for proxying requests. Only set this if you are behind a proxy. ### `--experimental_ea` -Boolean. Enables early access Auth0 resources support and experimental features. Default: `false`. +Boolean. When enabled, gain early access Auth0 resources support and experimental features. Default: `false`. ### Examples @@ -77,7 +77,7 @@ Boolean. Enables more verbose error logging; useful during troubleshooting. Defa ### `--experimental_ea` -Boolean. Enables early access Auth0 resources support and experimental features. Default: `false`. +Boolean. When enabled, gain early access Auth0 resources support and experimental features. Default: `false`. ### Examples diff --git a/src/context/index.ts b/src/context/index.ts index 7cf7b7e08..1d846e990 100644 --- a/src/context/index.ts +++ b/src/context/index.ts @@ -144,6 +144,10 @@ export const setupContext = async ( : 'features [' + EA_FEATURES.join(',') + '] are' } enabled. These are in a pre-release state and may change in future release.` ); + } else { + log.info( + 'To enable experimental early access features use --experimental_ea flag or set AUTH0_EXPERIMENTAL_EA=true in configuration JSON.' + ); } })(config); From 526b3b232a74ac7a933192c432856659092586ea Mon Sep 17 00:00:00 2001 From: kushalshit27 <43465488+kushalshit27@users.noreply.github.com> Date: Wed, 5 Feb 2025 18:41:44 +0530 Subject: [PATCH 11/12] update test: should dump tenant.yaml without defaults as AUTH0_EXPERIMENTAL_EA=false --- test/context/yaml/context.test.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/context/yaml/context.test.js b/test/context/yaml/context.test.js index 991f7e03c..6420404c6 100644 --- a/test/context/yaml/context.test.js +++ b/test/context/yaml/context.test.js @@ -313,7 +313,6 @@ describe('#YAML context validation', () => { const tenantFile = path.join(dir, 'tenant.yml'); const config = { AUTH0_INPUT_FILE: tenantFile, - AUTH0_EXPERIMENTAL_EA: true, AUTH0_EXCLUDED_DEFAULTS: ['emailProvider'], }; const context = new Context(config, mockMgmtClient()); @@ -419,7 +418,6 @@ describe('#YAML context validation', () => { prompts: { customText: {}, partials: {}, - screenRenderers: [], }, customDomains: [], themes: [], From e5c8f2acdb867a5293fd11ea00a1247d170373d7 Mon Sep 17 00:00:00 2001 From: Ramya Anusri <62586490+ramya18101@users.noreply.github.com> Date: Wed, 5 Feb 2025 18:57:27 +0530 Subject: [PATCH 12/12] Include new screens to support ACUL (#1028) Co-authored-by: Kushal <43465488+kushalshit27@users.noreply.github.com> --- src/tools/constants.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/tools/constants.ts b/src/tools/constants.ts index fbd8ea829..142a3013f 100644 --- a/src/tools/constants.ts +++ b/src/tools/constants.ts @@ -222,6 +222,10 @@ const constants = { 'email-identifier-challenge': ['email-identifier-challenge'], passkeys: ['passkey-enrollment', 'passkey-enrollment-local'], captcha: ['interstitial-captcha'], + login: ['login'], + signup: ['signup'], + 'reset-password': ['reset-password-request', 'reset-password-email', 'reset-password', 'reset-password-success', 'reset-password-error'], + } as PromptScreenMapping, };