Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
0e07227
Password Policy Tenant and Project Changes
pragatimodi Mar 13, 2023
d97386a
Adding unit tests for PasswordPolicyAuthConfig
pragatimodi Mar 13, 2023
d154481
Adding Project Config Unit Tests
pragatimodi Mar 14, 2023
828e820
Tenant Unit Tests
pragatimodi Mar 14, 2023
db00ab1
Lint fixes
pragatimodi Mar 14, 2023
62a444f
`npm run api-extractor:local` changes
pragatimodi Mar 14, 2023
a83afc5
1. `npm run api-extractor:local` changes
pragatimodi Mar 14, 2023
7bdbee0
Revert formatting changes
pragatimodi Mar 14, 2023
cf0f30e
Lint changes
pragatimodi Mar 14, 2023
a3af073
Line break lint changes
pragatimodi Mar 14, 2023
1e3a22b
`eslint --fix .` fixes
pragatimodi Mar 14, 2023
4254ddc
1. Changing type of passwordPolicies to PasswordPolicyConfig on Tenan…
pragatimodi Mar 15, 2023
3fc71f8
Minor changes
pragatimodi Mar 17, 2023
537db9e
Changes with approved config
pragatimodi Mar 29, 2023
0291c80
Merge branch 'password-policy' of https://github.com/firebase/firebas…
pragatimodi Mar 29, 2023
46084d1
Merge branch 'master' of https://github.com/firebase/firebase-admin-n…
pragatimodi Mar 30, 2023
b0a01d1
Undo package-lock.json changes
pragatimodi Mar 30, 2023
7ed0df0
Undo package-lock.json changes
pragatimodi Mar 30, 2023
e87cf4b
Undo package-lock.json changes
pragatimodi Mar 30, 2023
ea5edda
Update package-lock.json
pragatimodi Mar 30, 2023
8e7f520
Lint fixes
pragatimodi Mar 30, 2023
f01df33
Merge branch 'password-policy' of https://github.com/firebase/firebas…
pragatimodi Mar 30, 2023
eebc816
Cleanup
pragatimodi Mar 30, 2023
3098765
Merge remote-tracking branch 'origin/password-policy' into password-p…
pragatimodi Mar 30, 2023
e6a881f
Revert package-lock.json
pragatimodi Mar 30, 2023
d112cc6
Update project-config.ts
pragatimodi Mar 30, 2023
b5858c2
Minor formatting
pragatimodi Apr 4, 2023
6645095
Descriptive constants
pragatimodi Apr 4, 2023
a5453cd
Lint fixes
pragatimodi Apr 4, 2023
15022a6
Fix import
pragatimodi Apr 4, 2023
f2289e1
Update test/integration/auth.spec.ts
pragatimodi Apr 4, 2023
ce5d8bc
Apply suggestions from code review
pragatimodi Apr 4, 2023
222196d
Apply suggestions from code review
pragatimodi Apr 5, 2023
2db1735
Integration tests fix
pragatimodi Apr 5, 2023
cfaab07
Merge branch 'password-policy' of https://github.com/firebase/firebas…
pragatimodi Apr 5, 2023
5d0317f
Small fix
pragatimodi Apr 5, 2023
908c874
Reset password policy in integration tests to prevent breaking changes
pragatimodi Apr 6, 2023
f07a561
lint fix
pragatimodi Apr 6, 2023
7f98afd
Merge branch 'master' into password-policy
pragatimodi Apr 6, 2023
088dc00
Merge branch 'master' of https://github.com/firebase/firebase-admin-n…
pragatimodi Apr 24, 2023
363088e
package-lock.json undo changes
pragatimodi Apr 24, 2023
3eab3f6
update merge
pragatimodi Apr 24, 2023
18e6342
lint fixes
pragatimodi Apr 24, 2023
52dafbb
merge fixes
pragatimodi Apr 24, 2023
cb6cf64
Update package-lock.json
pragatimodi Apr 24, 2023
1eed89b
Update package.json
pragatimodi Apr 24, 2023
4db418e
Allow enforcementState `OFF` with default constraints
pragatimodi Apr 25, 2023
9206fa2
Lint fixes
pragatimodi Apr 25, 2023
a5b9188
Merge branch 'password-policy' of https://github.com/firebase/firebas…
pragatimodi Apr 25, 2023
0bdf730
Merge branch 'master' into password-policy
lahirumaramba May 2, 2023
2fd709a
Adding recaptcha to server request
pragatimodi May 3, 2023
59ba4ed
Fill default passwordPolicyVersions values
pragatimodi May 4, 2023
694a336
Lint fix
pragatimodi May 4, 2023
295d71c
Merge branch 'master' into password-policy
pragatimodi May 4, 2023
b4d7907
remove debug logging
pragatimodi May 4, 2023
1a4df37
Merge branch 'password-policy' of https://github.com/firebase/firebas…
pragatimodi May 4, 2023
3897bb2
Merge branch 'master' into password-policy
lahirumaramba May 23, 2023
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
Adding Project Config Unit Tests
  • Loading branch information
pragatimodi committed Mar 14, 2023
commit d154481c69b6aba136e2c5c5892c5989c8d96152
38 changes: 20 additions & 18 deletions src/auth/auth-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1632,7 +1632,7 @@ export interface PasswordPolicyVersionConfig {
* Constraints to enforce on user passwords.
*/
export interface PasswordPolicyConstraints {
requiredCharacters?: RequireCharactersConfig;
requiredCharacters?: RequiredCharactersConfig;
/**
* Minimum password length. Range from 6 to 30
*/
Expand All @@ -1646,7 +1646,7 @@ export interface PasswordPolicyConstraints {
/**
* Required characters to be enforced on the password policy
*/
export interface RequireCharactersConfig {
export interface RequiredCharactersConfig {
/**
* The password must contain an upper case character
*/
Expand Down Expand Up @@ -1717,6 +1717,7 @@ export class PasswordPolicyAuthConfig implements PasswordPolicyConfig {
* @param options - The options object to validate.
*/
public static validate(options: PasswordPolicyConfig): void {
console.log("OPTIONS= ", JSON.stringify(options))
const validKeys = {
enforcementState: true,
forceUpgradeOnSignin: true,
Expand All @@ -1738,9 +1739,9 @@ export class PasswordPolicyAuthConfig implements PasswordPolicyConfig {
}
}
// Validate content.
if (typeof options.enforcementState !== 'undefined' &&
options.enforcementState !== 'ENFORCE' &&
options.enforcementState !== 'OFF') {
if (typeof options.enforcementState === 'undefined' ||
!(options.enforcementState === 'ENFORCE' ||
options.enforcementState === 'OFF')) {
throw new FirebaseAuthError(
AuthClientErrorCode.INVALID_CONFIG,
'"PasswordPolicyConfig.enforcementState" must be either "ENFORCE" or "OFF".',
Expand All @@ -1752,7 +1753,7 @@ export class PasswordPolicyAuthConfig implements PasswordPolicyConfig {
if (!validator.isBoolean(options.forceUpgradeOnSignin)) {
throw new FirebaseAuthError(
AuthClientErrorCode.INVALID_CONFIG,
'"PasswordPolicyConfig.forceUpgradeOnSignin" must be a boolean',
'"PasswordPolicyConfig.forceUpgradeOnSignin" must be a boolean.',
);
}
}
Expand All @@ -1762,14 +1763,14 @@ export class PasswordPolicyAuthConfig implements PasswordPolicyConfig {
if (!validator.isArray(options.passwordPolicyVersions)) {
throw new FirebaseAuthError(
AuthClientErrorCode.INVALID_CONFIG,
'"PassworPolicyConfig.passwordPolicyVersions" must be a non-empty array',
'"PassworPolicyConfig.passwordPolicyVersions" must be a non-empty array.',
);
}

if (options.enforcementState === 'ENFORCE' && options.passwordPolicyVersions.length < 1) {
throw new FirebaseAuthError(
AuthClientErrorCode.INVALID_CONFIG,
'"PassworPolicyConfig.passwordPolicyVersions" must be a non-empty array',
'"PassworPolicyConfig.passwordPolicyVersions" must be a non-empty array.',
);
}

Expand All @@ -1780,7 +1781,7 @@ export class PasswordPolicyAuthConfig implements PasswordPolicyConfig {
if (!validator.isNonNullObject(policyVersion)) {
throw new FirebaseAuthError(
AuthClientErrorCode.INVALID_CONFIG,
'"PasswordPolicyConfig" must be a non-null object.',
'"Constraints" must be specified.',
);
}
// Check for unsupported attributes.
Expand All @@ -1798,7 +1799,8 @@ export class PasswordPolicyAuthConfig implements PasswordPolicyConfig {
minLength: true,
maxLength: true,
};
if (!validator.isNonNullObject(policyVersion.constraints)) {
if (typeof policyVersion.constraints !== 'object' ||
!validator.isNonNullObject(policyVersion.constraints)) {
throw new FirebaseAuthError(
AuthClientErrorCode.INVALID_CONFIG,
'"PasswordPolicyConfig.constraints" must be a non-null object.',
Expand All @@ -1809,7 +1811,7 @@ export class PasswordPolicyAuthConfig implements PasswordPolicyConfig {
if (!(key in validConstraintKeys)) {
throw new FirebaseAuthError(
AuthClientErrorCode.INVALID_CONFIG,
`"${key}" is not a valid PasswordPolicyConfig.PasswordPolicyVersions.Constraints parameter.`,
`"${key}" is not a valid PasswordPolicyConfig.passwordPolicyVersions.constraints parameter.`,
);
}
}
Expand Down Expand Up @@ -1856,50 +1858,50 @@ export class PasswordPolicyAuthConfig implements PasswordPolicyConfig {
numeric: true,
nonAlphanumeric: true,
};
if (!validator.isNonNullObject(policyVersion.constraints.requiredCharacters)) {
if (!(typeof policyVersion.constraints.requiredCharacters === 'object')) {
throw new FirebaseAuthError(
AuthClientErrorCode.INVALID_CONFIG,
'"PasswordPolicyConfig.constraints.requiredCharacters" must be a non-null object.',
'"PasswordPolicyConfig.constraints.requiredCharacters" must be a valid object.',
);
}
// Check for unsupported attributes.
for (const key in policyVersion.constraints.requiredCharacters) {
if (!(key in validCharKeys)) {
throw new FirebaseAuthError(
AuthClientErrorCode.INVALID_CONFIG,
`"${key}" is not a valid PasswordPolicyConfig.PasswordPolicyVersions.Constraints.RequireCharacters parameter.`,
`"${key}" is not a valid RequiredCharacters parameter.`,
);
}
}
if (typeof policyVersion.constraints.requiredCharacters.uppercase !== undefined &&
!validator.isBoolean(policyVersion.constraints.requiredCharacters.uppercase)) {
throw new FirebaseAuthError(
AuthClientErrorCode.INVALID_CONFIG,
'"PasswordPolicyConfig.constraints.requiredCharacters.uppercase" must be a boolean.',
'"PasswordPolicyConfig.passwordPolicyVersions.constraints.requiredCharacters.uppercase" must be a boolean.',
);
}

if (typeof policyVersion.constraints.requiredCharacters.lowercase !== undefined &&
!validator.isBoolean(policyVersion.constraints.requiredCharacters.lowercase)) {
throw new FirebaseAuthError(
AuthClientErrorCode.INVALID_CONFIG,
'"PasswordPolicyConfig.constraints.requiredCharacters.lowercase" must be a boolean.',
'"PasswordPolicyConfig.passwordPolicyVersions.constraints.requiredCharacters.lowercase" must be a boolean.',
);
}

if (typeof policyVersion.constraints.requiredCharacters.nonAlphanumeric !== undefined &&
!validator.isBoolean(policyVersion.constraints.requiredCharacters.nonAlphanumeric)) {
throw new FirebaseAuthError(
AuthClientErrorCode.INVALID_CONFIG,
'"PasswordPolicyConfig.constraints.requiredCharacters.nonAlphanumeric" must be a boolean.',
'"PasswordPolicyConfig.passwordPolicyVersions.constraints.requiredCharacters.nonAlphanumeric" must be a boolean.',
);
}

if (typeof policyVersion.constraints.requiredCharacters.numeric !== undefined &&
!validator.isBoolean(policyVersion.constraints.requiredCharacters.numeric)) {
throw new FirebaseAuthError(
AuthClientErrorCode.INVALID_CONFIG,
'"PasswordPolicyConfig.constraints.requiredCharacters.numeric" must be a boolean.',
'"PasswordPolicyConfig.passwordPolicyVersions.constraints.requiredCharacters.numeric" must be a boolean.',
);
}
});
Expand Down
1 change: 1 addition & 0 deletions src/auth/project-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ export class ProjectConfig {

// Validate Password policy Config if provided
if (typeof request.passwordPolicyConfig !== 'undefined') {
console.log("REQ= ", JSON.stringify(request.passwordPolicyConfig));
PasswordPolicyAuthConfig.validate(request.passwordPolicyConfig);
}
}
Expand Down
Loading