Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add test
  • Loading branch information
kevinthecheung committed Jun 27, 2023
commit 6a0fbdd072c73f4dc5f5cca38753cb53eaf215d5
118 changes: 72 additions & 46 deletions test/unit/auth/auth-config.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1239,60 +1239,86 @@ describe('OIDCConfig', () => {
});
});
});
describe('PasswordPolicyAuthConfig',() => {
describe('constructor',() => {
const validConfig = new PasswordPolicyAuthConfig({
passwordPolicyEnforcementState: 'ENFORCE',
});

describe('PasswordPolicyAuthConfig',() => {
describe('constructor',() => {
const validConfig = new PasswordPolicyAuthConfig({
passwordPolicyEnforcementState: 'ENFORCE',
passwordPolicyVersions: [
{
customStrengthOptions: {
containsNumericCharacter: true,
containsLowercaseCharacter: true,
containsNonAlphanumericCharacter: true,
containsUppercaseCharacter: true,
minPasswordLength: 8,
maxPasswordLength: 30,
},
},
],
forceUpgradeOnSignin: true,
});

it('should throw an error on missing state',() => {
expect(() => new PasswordPolicyAuthConfig({
passwordPolicyVersions: [
{
customStrengthOptions: {
containsNumericCharacter: true,
containsLowercaseCharacter: true,
containsNonAlphanumericCharacter: true,
containsUppercaseCharacter: true,
minPasswordLength: 8,
maxPasswordLength: 30,
},
},
customStrengthOptions: {},
}
],
forceUpgradeOnSignin: true,
});
} as any)).to.throw('INTERNAL ASSERT FAILED: Invalid password policy configuration response');
});

it('should throw an error on missing state',() => {
expect(() => new PasswordPolicyAuthConfig({
passwordPolicyVersions: [
{
customStrengthOptions: {},
}
],
} as any)).to.throw('INTERNAL ASSERT FAILED: Invalid password policy configuration response');
});
it('should set readonly property "enforcementState" to ENFORCE on state enforced',() => {
expect(validConfig.enforcementState).to.equal('ENFORCE');
});

it('should set readonly property "enforcementState" to ENFORCE on state enforced',() => {
expect(validConfig.enforcementState).to.equal('ENFORCE');
it('should set readonly property "enforcementState" to OFF on state disabling',() => {
const offStateConfig=new PasswordPolicyAuthConfig({
passwordPolicyEnforcementState: 'OFF',
});
expect(offStateConfig.enforcementState).to.equal('OFF');
});

it('should set readonly property "enforcementState" to OFF on state disabling',() => {
const offStateConfig=new PasswordPolicyAuthConfig({
passwordPolicyEnforcementState: 'OFF',
});
expect(offStateConfig.enforcementState).to.equal('OFF');
});
it('should set readonly property "constraints"',() => {
const expectedConstraints: CustomStrengthOptionsConfig = {
requireUppercase: true,
requireLowercase: true,
requireNonAlphanumeric: true,
requireNumeric: true,
minLength: 8,
maxLength: 30,
}
expect(validConfig.constraints).to.deep.equal(expectedConstraints);
});

it('should set readonly property "constraints"',() => {
const expectedConstraints: CustomStrengthOptionsConfig = {
requireUppercase: true,
requireLowercase: true,
requireNonAlphanumeric: true,
requireNumeric: true,
minLength: 8,
maxLength: 30,
}
expect(validConfig.constraints).to.deep.equal(expectedConstraints);
});
it('should set readonly property "forceUpgradeOnSignin"',() => {
expect(validConfig.forceUpgradeOnSignin).to.deep.equal(true);
});
});

it('should set readonly property "forceUpgradeOnSignin"',() => {
expect(validConfig.forceUpgradeOnSignin).to.deep.equal(true);
describe('buildServerRequest()', () => {
it('should return server request with default constraints', () => {
expect(PasswordPolicyAuthConfig.buildServerRequest({
enforcementState: 'ENFORCE',
constraints: {},
})).to.deep.equal({
passwordPolicyEnforcementState: 'ENFORCE',
forceUpgradeOnSignin: false,
passwordPolicyVersions: [
{
customStrengthOptions: {
containsLowercaseCharacter: false,
containsUppercaseCharacter: false,
containsNumericCharacter: false,
containsNonAlphanumericCharacter: false,
minPasswordLength: 6,
maxPasswordLength: 4096,
}
}
]
});
});
});});
});
});