Skip to content

Commit

Permalink
fix errors
Browse files Browse the repository at this point in the history
  • Loading branch information
saralk committed Jun 24, 2024
1 parent cb217aa commit 6255c00
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export async function addMfaAppMethodPost(
otp: code,
credential: authAppSecret,
mfaMethod: {
priorityIdentifier: "SECONDARY",
priorityIdentifier: "BACKUP",
mfaMethodType: "AUTH_APP",
},
accessToken: req.session.user.tokens.accessToken,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ describe("addMfaAppMethodPost", () => {
mfaIdentifier: 1,
methodVerified: true,
mfaMethodType: "AUTH_APP",
priorityIdentifier: "SECONDARY",
priorityIdentifier: "BACKUP",
},
})
);
Expand All @@ -136,7 +136,7 @@ describe("addMfaAppMethodPost", () => {
email: "test@test.com",
otp: "123456",
credential: "AAAAAAAAAAAAAAAAAAAA",
mfaMethod: { priorityIdentifier: "SECONDARY", mfaMethodType: "AUTH_APP" },
mfaMethod: { priorityIdentifier: "BACKUP", mfaMethodType: "AUTH_APP" },
accessToken: "token",
sourceIp: "127.0.0.1",
sessionId: "session_id",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export function addMfaMethodGet(req: Request, res: Response): void {
}

if (userMethods.length === 1) {
if (userMethods[0].mfaMethodType === "AUTH_APP") {
if (userMethods[0].method.mfaMethodType === "AUTH_APP") {
res.render(ADD_METHOD_TEMPLATE, {
mfaMethods: [],
message: req.t("pages.addMfaMethod.backup.sms.message"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export function changeAuthenticatorAppPost(
const sessionDetails = await generateSessionDetails(req, res);
let isAuthenticatorAppUpdated = false;
const authAppMFAMethod: MfaMethod = req.session.mfaMethods.find(
(mfa) => mfa.mfaMethodType === "AUTH_APP"
(mfa) => mfa.method.mfaMethodType === "AUTH_APP"
);
if (authAppMFAMethod) {
updateInput.mfaMethod = authAppMFAMethod;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,11 @@ describe("change authenticator app controller", () => {
methodVerified: true,
endPoint: "PHONE",
mfaMethodType: "SMS",
priorityIdentifier: "PRIMARY",
priorityIdentifier: "DEFAULT",
},
{
mfaIdentifier: 2,
priorityIdentifier: "SECONDARY",
priorityIdentifier: "BACKUP",
mfaMethodType: "AUTH_APP",
methodVerified: true,
},
Expand Down Expand Up @@ -150,11 +150,11 @@ describe("change authenticator app controller", () => {
methodVerified: true,
endPoint: "PHONE",
mfaMethodType: "SMS",
priorityIdentifier: "PRIMARY",
priorityIdentifier: "DEFAULT",
},
{
mfaIdentifier: 2,
priorityIdentifier: "SECONDARY",
priorityIdentifier: "BACKUP",
mfaMethodType: "AUTH_APP",
methodVerified: true,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,11 @@ describe("changeAuthenticatorAppService", () => {

const mfaMethod: MfaMethod = {
mfaIdentifier: 2,
priorityIdentifier: "SECONDARY",
mfaMethodType: "AUTH_APP",
endPoint: "1Password",
priorityIdentifier: "BACKUP",
method: {
mfaMethodType: "AUTH_APP",
endPoint: "1Password",
},
methodVerified: true,
};

Expand Down
22 changes: 12 additions & 10 deletions src/components/security/security-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ export async function securityGet(req: Request, res: Response): Promise<void> {
? req.session.mfaMethods.map((method) => {
let text: string, linkText: string, linkHref: string;

if (method.mfaMethodType === "SMS") {
const phoneNumber = getLastNDigits(method.endPoint, 4);
if (method.method.mfaMethodType === "SMS") {
const phoneNumber = getLastNDigits(method.method.endPoint, 4);
text = req
.t(
"pages.security.mfaSection.supportChangeMfa.defaultMethod.phoneNumber.title"
Expand All @@ -35,7 +35,7 @@ export async function securityGet(req: Request, res: Response): Promise<void> {
"pages.security.mfaSection.supportChangeMfa.defaultMethod.phoneNumber.change"
);
linkHref = `${PATH_DATA.ENTER_PASSWORD.url}?type=changePhoneNumber`;
} else if (method.mfaMethodType === "AUTH_APP") {
} else if (method.method.mfaMethodType === "AUTH_APP") {
text = req.t(
"pages.security.mfaSection.supportChangeMfa.defaultMethod.app.title"
);
Expand All @@ -45,7 +45,7 @@ export async function securityGet(req: Request, res: Response): Promise<void> {
linkHref = `${PATH_DATA.ENTER_PASSWORD.url}?type=changeAuthenticatorApp`;
} else {
throw new Error(
`Unexpected mfaMethodType: ${method.mfaMethodType}`
`Unexpected mfaMethodType: ${method.method.mfaMethodType}`
);
}

Expand All @@ -64,8 +64,8 @@ export async function securityGet(req: Request, res: Response): Promise<void> {
value: string,
actions = {};

if (method.mfaMethodType === "SMS") {
const phoneNumber = getLastNDigits(method.endPoint, 4);
if (method.method.mfaMethodType === "SMS") {
const phoneNumber = getLastNDigits(method.method.endPoint, 4);
key = req.t(
"pages.security.mfaSection.summaryList.phoneNumber.title"
);
Expand All @@ -84,7 +84,7 @@ export async function securityGet(req: Request, res: Response): Promise<void> {
},
],
};
} else if (method.mfaMethodType === "AUTH_APP") {
} else if (method.method.mfaMethodType === "AUTH_APP") {
key = req.t("pages.security.mfaSection.summaryList.app.title");
value = req.t("pages.security.mfaSection.summaryList.app.value");

Expand All @@ -102,7 +102,7 @@ export async function securityGet(req: Request, res: Response): Promise<void> {
};
} else {
throw new Error(
`Unexpected mfaMethodType: ${method.mfaMethodType}`
`Unexpected mfaMethodType: ${method.method.mfaMethodType}`
);
}

Expand All @@ -125,11 +125,13 @@ export async function securityGet(req: Request, res: Response): Promise<void> {
? supportChangeMfa() &&
req.session.mfaMethods.length > 1 &&
req.session.mfaMethods.find(
(m) => m.mfaMethodType === "SMS" && m.priorityIdentifier === "PRIMARY"
(m) =>
m.method.mfaMethodType === "SMS" && m.priorityIdentifier === "DEFAULT"
) &&
req.session.mfaMethods.find(
(m) =>
m.mfaMethodType === "AUTH_APP" && m.priorityIdentifier === "SECONDARY"
m.method.mfaMethodType === "AUTH_APP" &&
m.priorityIdentifier === "BACKUP"
)
: false;

Expand Down
12 changes: 8 additions & 4 deletions src/middleware/mfa-methods-legacy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ export function legacyMfaMethodsMiddleware(
{
mfaIdentifier: 1,
priorityIdentifier: "DEFAULT",
mfaMethodType: "SMS",
endPoint: req.session.user.phoneNumber,
method: {
mfaMethodType: "SMS",
endPoint: req.session.user.phoneNumber,
},
methodVerified: true,
},
];
Expand All @@ -20,8 +22,10 @@ export function legacyMfaMethodsMiddleware(
{
mfaIdentifier: 1,
priorityIdentifier: "DEFAULT",
mfaMethodType: "AUTH_APP",
endPoint: "Authenticator app",
method: {
mfaMethodType: "AUTH_APP",
endPoint: "Authenticator app",
},
methodVerified: true,
},
];
Expand Down
2 changes: 1 addition & 1 deletion src/utils/mfa/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export interface MfaMethod {
method: {
mfaMethodType: MfaMethodType;
endPoint?: string;
}
};
methodVerified: boolean;
}

Expand Down
22 changes: 15 additions & 7 deletions src/utils/test/mfa-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,10 @@ describe("MFA Function", () => {
const mfaMethod: MfaMethod = {
mfaIdentifier: 111111,
methodVerified: true,
endPoint: phoneNumber,
mfaMethodType: "SMS",
method: {
endPoint: phoneNumber,
mfaMethodType: "SMS",
},
priorityIdentifier: "DEFAULT",
};

Expand Down Expand Up @@ -273,7 +275,9 @@ describe("MFA Function", () => {
const mfaMethod: MfaMethod = {
mfaIdentifier: 111111,
methodVerified: true,
mfaMethodType: "AUTH_APP",
method: {
mfaMethodType: "AUTH_APP",
},
priorityIdentifier: "DEFAULT",
};

Expand Down Expand Up @@ -318,8 +322,10 @@ describe("MFA Function", () => {
const mfaMethod: MfaMethod = {
mfaIdentifier: 111111,
methodVerified: true,
endPoint: "PHONE",
mfaMethodType: "SMS",
method: {
endPoint: "PHONE",
mfaMethodType: "SMS",
},
priorityIdentifier: "DEFAULT",
};

Expand Down Expand Up @@ -379,8 +385,10 @@ describe("MFA Function", () => {
const mfaMethod: MfaMethod = {
mfaIdentifier: 111111,
methodVerified: true,
endPoint: "PHONE",
mfaMethodType: "SMS",
method: {
endPoint: "PHONE",
mfaMethodType: "SMS",
},
priorityIdentifier: "DEFAULT",
};

Expand Down

0 comments on commit 6255c00

Please sign in to comment.