diff --git a/.changeset/wild-gifts-move.md b/.changeset/wild-gifts-move.md new file mode 100644 index 000000000..777bab73e --- /dev/null +++ b/.changeset/wild-gifts-move.md @@ -0,0 +1,5 @@ +--- +'@forgerock/javascript-sdk': patch +--- + +Add support for KBA `allowUserDefinedQuestions` flag diff --git a/e2e/autoscript-apps/src/register-basic/autoscript.ts b/e2e/autoscript-apps/src/register-basic/autoscript.ts index 6254ddc00..1db5195d1 100644 --- a/e2e/autoscript-apps/src/register-basic/autoscript.ts +++ b/e2e/autoscript-apps/src/register-basic/autoscript.ts @@ -89,11 +89,19 @@ function autoscript() { console.log(`Predefined Question1: ${pdq1}`); console.log(`Predefined Question 2: ${pdq2}`); - kbCb1.setQuestion('What is your favorite color?'); + const isAllowedUserDefinedQuestions1 = kbCb1.isAllowedUserDefinedQuestions(); + const isAllowedUserDefinedQuestions2 = kbCb2.isAllowedUserDefinedQuestions(); + console.log(`kbCb1 is allowed user defined questions: ${isAllowedUserDefinedQuestions1}`); + console.log(`kbCb2 is allowed user defined questions: ${isAllowedUserDefinedQuestions2}`); + + kbCb1.setQuestion(pdq1); kbCb1.setAnswer('Red'); - kbCb2.setQuestion('Who was your first employer?'); - kbCb2.setAnswer('AAA Engineering'); + kbCb2.setQuestion('Who was your first pet?'); + kbCb2.setAnswer('Fluffy'); + + const customQuestion = kbCb2.getInputValue(); + console.log(`Custom Question from kbCb2: ${customQuestion}`); console.log('Handle TermsAndConditionsCallback'); const tcCb = step.getCallbackOfType('TermsAndConditionsCallback'); diff --git a/e2e/autoscript-suites/src/suites/register-basic.lc.test.ts b/e2e/autoscript-suites/src/suites/register-basic.lc.test.ts index 1725d55d1..20292a0e0 100644 --- a/e2e/autoscript-suites/src/suites/register-basic.lc.test.ts +++ b/e2e/autoscript-suites/src/suites/register-basic.lc.test.ts @@ -16,7 +16,7 @@ test.describe('Test basic registration flow', () => { const un = v4(); const email = `${un}@me.com`; - test(`should register user successfully and then log ou`, async ({ page, browserName }) => { + test(`should register user successfully and then log out`, async ({ page, browserName }) => { const { messageArray } = await setupAndGo(page, browserName, 'register-basic/', { un, email, @@ -33,6 +33,8 @@ test.describe('Test basic registration flow', () => { // expect(messageArray.includes('Prompt 6: Age')).toBe(true); expect(messageArray.includes('Prompt 7: Select a security question')).toBe(true); expect(messageArray.includes(`Predefined Question1: What's your favorite color?`)).toBe(true); + expect(messageArray.includes(`kbCb2 is allowed user defined questions: true`)).toBe(true); + expect(messageArray.includes(`Custom Question from kbCb2: Who was your first pet?`)).toBe(true); expect(messageArray.includes('Terms version: 0.0')).toBe(true); expect( messageArray.includes( diff --git a/e2e/mock-api/src/app/response.registration.js b/e2e/mock-api/src/app/response.registration.js index 527147371..a986ffad7 100644 --- a/e2e/mock-api/src/app/response.registration.js +++ b/e2e/mock-api/src/app/response.registration.js @@ -181,6 +181,10 @@ export default { name: 'predefinedQuestions', value: [`What's your favorite color?`, 'Who was your first employer?'], }, + { + name: 'allowUserDefinedQuestions', + value: true, + }, ], input: [ { name: 'IDToken8question', value: '' }, @@ -196,6 +200,10 @@ export default { name: 'predefinedQuestions', value: [`What's your favorite color?`, 'Who was your first employer?'], }, + { + name: 'allowUserDefinedQuestions', + value: true, + }, ], input: [ { name: 'IDToken9question', value: '' }, diff --git a/packages/javascript-sdk/src/fr-auth/callbacks/kba-create-callback.ts b/packages/javascript-sdk/src/fr-auth/callbacks/kba-create-callback.ts index f10c9edc5..254434934 100644 --- a/packages/javascript-sdk/src/fr-auth/callbacks/kba-create-callback.ts +++ b/packages/javascript-sdk/src/fr-auth/callbacks/kba-create-callback.ts @@ -36,6 +36,13 @@ class KbaCreateCallback extends FRCallback { return this.getOutputByName('predefinedQuestions', []); } + /** + * Gets whether the user can define questions. + */ + public isAllowedUserDefinedQuestions(): boolean { + return this.getOutputByName('allowUserDefinedQuestions', false); + } + /** * Sets the callback's security question. */