Skip to content

Commit 6798cb3

Browse files
committed
Add password policy endpoint in auth
* Add password policy endpoint in auth to allow fetching the password policy for the project/tenant
1 parent 7ad5341 commit 6798cb3

File tree

2 files changed

+27
-6
lines changed

2 files changed

+27
-6
lines changed

packages/auth/src/api/password_policy/get_password_policy.test.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ import { FirebaseError } from '@firebase/util';
2929
use(chaiAsPromised);
3030

3131
describe('api/password_policy/getPasswordPolicy', () => {
32+
const TEST_MIN_PASSWORD_LENGTH = 6;
33+
const TEST_ALLOWED_NON_ALPHANUMERIC_CHARS = ['!'];
34+
const TEST_SCHEMA_VERSION = 1;
35+
3236
let auth: TestAuth;
3337

3438
beforeEach(async () => {
@@ -41,16 +45,20 @@ describe('api/password_policy/getPasswordPolicy', () => {
4145
it('should GET to the correct endpoint', async () => {
4246
const mock = mockEndpoint(Endpoint.GET_PASSWORD_POLICY, {
4347
customStrengthOptions: {
44-
minPasswordLength: 6
48+
minPasswordLength: TEST_MIN_PASSWORD_LENGTH
4549
},
46-
allowedNonAlphanumericCharacters: ['!'],
47-
schemaVersion: 1
50+
allowedNonAlphanumericCharacters: TEST_ALLOWED_NON_ALPHANUMERIC_CHARS,
51+
schemaVersion: TEST_SCHEMA_VERSION
4852
});
4953

5054
const response = await _getPasswordPolicy(auth);
51-
expect(response.customStrengthOptions.minPasswordLength).to.eql(6);
52-
expect(response.allowedNonAlphanumericCharacters).to.eql(['!']);
53-
expect(response.schemaVersion).to.eql(1);
55+
expect(response.customStrengthOptions.minPasswordLength).to.eql(
56+
TEST_MIN_PASSWORD_LENGTH
57+
);
58+
expect(response.allowedNonAlphanumericCharacters).to.eql(
59+
TEST_ALLOWED_NON_ALPHANUMERIC_CHARS
60+
);
61+
expect(response.schemaVersion).to.eql(TEST_SCHEMA_VERSION);
5462
expect(mock.calls[0].method).to.eq('GET');
5563
expect(mock.calls[0].headers!.get(HttpHeader.X_CLIENT_VERSION)).to.eq(
5664
'testSDK/0.0.0'

packages/auth/src/api/password_policy/get_password_policy.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,16 @@ import {
2323
} from '../index';
2424
import { Auth } from '../../model/public_types';
2525

26+
/**
27+
* Request object for fetching the password policy.
28+
*/
2629
export interface GetPasswordPolicyRequest {
2730
tenantId?: string;
2831
}
2932

33+
/**
34+
* Response object for fetching the password policy.
35+
*/
3036
export interface GetPasswordPolicyResponse {
3137
customStrengthOptions: {
3238
minPasswordLength?: number;
@@ -40,6 +46,13 @@ export interface GetPasswordPolicyResponse {
4046
schemaVersion: number;
4147
}
4248

49+
/**
50+
* Fetches the password policy for the currently set tenant or the project if no tenant is set.
51+
*
52+
* @param auth Auth object.
53+
* @param request Password policy request.
54+
* @returns Password policy response.
55+
*/
4356
export async function _getPasswordPolicy(
4457
auth: Auth,
4558
request: GetPasswordPolicyRequest = {}

0 commit comments

Comments
 (0)