Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
22 changes: 21 additions & 1 deletion src/multi-factor-auth/fixtures/list-factors.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,27 @@
"totp": {
"issuer": "WorkOS",
"user": "some_user"
}
},
"user_id": "user_01H5JQDV7R7ATEYZDEG0W5PRYS"
},
{
"object": "authentication_factor",
"id": "auth_factor_5678",
"created_at": "2022-03-15T20:39:19.892Z",
"updated_at": "2022-03-15T20:39:19.892Z",
"type": "sms",
"sms": {
"phone_number": "+15555555555"
},
"user_id": "user_01H5JQDV7R7ATEYZDEG0W5PRYS"
},
{
"object": "authentication_factor",
"id": "auth_factor_9012",
"created_at": "2022-03-15T20:39:19.892Z",
"updated_at": "2022-03-15T20:39:19.892Z",
"type": "generic_otp",
"user_id": "user_01H5JQDV7R7ATEYZDEG0W5PRYS"
}
],
"list_metadata": {
Expand Down
2 changes: 1 addition & 1 deletion src/multi-factor-auth/interfaces/factor.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
TotpWithSecretsResponse,
} from './totp.interface';

type FactorType = 'sms' | 'totp' | 'generic_otp';
export type FactorType = 'sms' | 'totp' | 'generic_otp';

export interface Factor {
object: 'authentication_factor';
Expand Down
20 changes: 20 additions & 0 deletions src/multi-factor-auth/multi-factor-auth.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,26 @@ describe('MFA', () => {
issuer: 'WorkOS',
user: 'some_user',
},
userId: 'user_01H5JQDV7R7ATEYZDEG0W5PRYS',
},
{
object: 'authentication_factor',
id: 'auth_factor_5678',
createdAt: '2022-03-15T20:39:19.892Z',
updatedAt: '2022-03-15T20:39:19.892Z',
type: 'sms',
sms: {
phoneNumber: '+15555555555',
},
userId: 'user_01H5JQDV7R7ATEYZDEG0W5PRYS',
},
{
object: 'authentication_factor',
id: 'auth_factor_9012',
createdAt: '2022-03-15T20:39:19.892Z',
updatedAt: '2022-03-15T20:39:19.892Z',
type: 'generic_otp',
userId: 'user_01H5JQDV7R7ATEYZDEG0W5PRYS',
},
],
listMetadata: {
Expand Down
22 changes: 21 additions & 1 deletion src/user-management/fixtures/list-factors.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,27 @@
"totp": {
"issuer": "WorkOS",
"user": "some_user"
}
},
"user_id": "user_01H5JQDV7R7ATEYZDEG0W5PRYS"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fixture is unreferenced — the only list-factors import in the tree is multi-factor-auth.spec.ts:16 pulling ./fixtures/list-factors.json, which resolves to the MFA copy.

Updating it reads as added coverage but contributes none. Worth deleting the file, or leaving a note on why it's kept.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As of 6cf80fd the fixture is no longer unreferenced — the new src/user-management/serializers/authentication-factor.serializer.spec.ts imports it and exercises deserializeFactor against all three factor types, so it now contributes coverage of the fixed deserializer directly.

},
{
"object": "authentication_factor",
"id": "auth_factor_5678",
"created_at": "2022-03-15T20:39:19.892Z",
"updated_at": "2022-03-15T20:39:19.892Z",
"type": "sms",
"sms": {
"phone_number": "+15555555555"
},
"user_id": "user_01H5JQDV7R7ATEYZDEG0W5PRYS"
},
{
"object": "authentication_factor",
"id": "auth_factor_9012",
"created_at": "2022-03-15T20:39:19.892Z",
"updated_at": "2022-03-15T20:39:19.892Z",
"type": "generic_otp",
"user_id": "user_01H5JQDV7R7ATEYZDEG0W5PRYS"
}
],
"list_metadata": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
import { FactorType } from '../../multi-factor-auth/interfaces/factor.interface';
import {
Sms,
SmsResponse,
} from '../../multi-factor-auth/interfaces/sms.interface';
import {
Totp,
TotpResponse,
TotpWithSecrets,
TotpWithSecretsResponse,
} from '../../multi-factor-auth/interfaces/totp.interface';

export type AuthenticationFactorType = FactorType;

export interface AuthenticationFactor {
object: 'authentication_factor';
id: string;
createdAt: string;
updatedAt: string;
type: 'totp';
totp: Totp;
type: AuthenticationFactorType;
sms?: Sms;
totp?: Totp;
userId: string;
}

Expand All @@ -30,8 +38,9 @@ export interface AuthenticationFactorResponse {
id: string;
created_at: string;
updated_at: string;
type: 'totp';
totp: TotpResponse;
type: AuthenticationFactorType;
sms?: SmsResponse;
totp?: TotpResponse;
user_id: string;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { deserializeFactor } from './authentication-factor.serializer';
import { AuthenticationFactorResponse } from '../interfaces/authentication-factor.interface';
import listFactorsFixture from '../fixtures/list-factors.json';

describe('deserializeFactor', () => {
it('deserializes totp, sms, and generic_otp factors', () => {
const factors = listFactorsFixture.data.map((factor) =>
deserializeFactor(factor as AuthenticationFactorResponse),
);

expect(factors).toEqual([
{
object: 'authentication_factor',
id: 'auth_factor_1234',
createdAt: '2022-03-15T20:39:19.892Z',
updatedAt: '2022-03-15T20:39:19.892Z',
type: 'totp',
totp: {
issuer: 'WorkOS',
user: 'some_user',
},
userId: 'user_01H5JQDV7R7ATEYZDEG0W5PRYS',
},
{
object: 'authentication_factor',
id: 'auth_factor_5678',
createdAt: '2022-03-15T20:39:19.892Z',
updatedAt: '2022-03-15T20:39:19.892Z',
type: 'sms',
sms: {
phoneNumber: '+15555555555',
},
userId: 'user_01H5JQDV7R7ATEYZDEG0W5PRYS',
},
{
object: 'authentication_factor',
id: 'auth_factor_9012',
createdAt: '2022-03-15T20:39:19.892Z',
updatedAt: '2022-03-15T20:39:19.892Z',
type: 'generic_otp',
userId: 'user_01H5JQDV7R7ATEYZDEG0W5PRYS',
},
]);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
AuthenticationFactorWithSecrets,
AuthenticationFactorWithSecretsResponse,
} from '../interfaces/authentication-factor.interface';
import { deserializeSms } from '../../multi-factor-auth/serializers/sms.serializer';
import {
deserializeTotp,
deserializeTotpWithSecrets,
Expand All @@ -17,7 +18,8 @@ export const deserializeFactor = (
createdAt: factor.created_at,
updatedAt: factor.updated_at,
type: factor.type,
totp: deserializeTotp(factor.totp),
...(factor.sms ? { sms: deserializeSms(factor.sms) } : {}),
...(factor.totp ? { totp: deserializeTotp(factor.totp) } : {}),
userId: factor.user_id,
});

Expand Down