Skip to content

Commit 71c59a7

Browse files
committed
fix code
1 parent fc847e6 commit 71c59a7

File tree

3 files changed

+58
-2
lines changed

3 files changed

+58
-2
lines changed

src/api/functions/membership.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { marshall } from "@aws-sdk/util-dynamodb";
77
import { genericConfig } from "common/config.js";
88
import { FastifyBaseLogger } from "fastify";
99
import { isUserInGroup } from "./entraId.js";
10+
import { EntraGroupError } from "common/errors/index.js";
1011

1112
export async function checkPaidMembership(
1213
endpoint: string,
@@ -58,7 +59,14 @@ export async function checkPaidMembershipFromEntra(
5859
entraToken: string,
5960
paidMemberGroup: string,
6061
): Promise<boolean> {
61-
return isUserInGroup(entraToken, `${netId}@illinois.edu`, paidMemberGroup);
62+
try {
63+
return isUserInGroup(entraToken, `${netId}@illinois.edu`, paidMemberGroup);
64+
} catch (e) {
65+
if (e instanceof EntraGroupError) {
66+
return false;
67+
}
68+
throw e;
69+
}
6270
}
6371

6472
export async function setPaidMembershipInTable(

src/api/functions/validation.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ export function validateEmail(email: string): boolean {
88

99
export function validateNetId(netId: string): boolean {
1010
const regex = /^[a-zA-Z]{2}[a-zA-Z\-]*(?:[2-9]|[1-9][0-9]{1,2})?$/;
11-
return regex.test(netId);
11+
return netId.length <= 8 && regex.test(netId);
1212
}

tests/live/membership.test.ts

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import { expect, test, describe } from "vitest";
2+
3+
const baseEndpoint = `https://core.aws.qa.acmuiuc.org`;
4+
5+
describe("Membership API basic checks", async () => {
6+
test("Test that getting member succeeds", { timeout: 3000 }, async () => {
7+
const response = await fetch(`${baseEndpoint}/api/v1/membership/dsingh14`, {
8+
method: "GET",
9+
});
10+
11+
expect(response.status).toBe(200);
12+
13+
const responseBody = await response.json();
14+
expect(responseBody).toStrictEqual({
15+
netId: "dsingh14",
16+
isPaidMember: true,
17+
});
18+
expect(response.headers.get("x-acm-data-source")).toBe("dynamo");
19+
});
20+
test(
21+
"Test that getting non-members succeeds",
22+
{ timeout: 3000 },
23+
async () => {
24+
const response = await fetch(`${baseEndpoint}/api/v1/membership/zzzz`, {
25+
method: "GET",
26+
});
27+
28+
expect(response.status).toBe(200);
29+
30+
const responseBody = await response.json();
31+
expect(responseBody).toStrictEqual({
32+
netId: "zzzz",
33+
isPaidMember: false,
34+
});
35+
expect(response.headers.get("x-acm-data-source")).toBe("aad");
36+
},
37+
);
38+
test("Test that invalid NetID is rejected", { timeout: 3000 }, async () => {
39+
const response = await fetch(
40+
`${baseEndpoint}/api/v1/membership/dsafdsfdsfsdafsfsdfasfsfsfds`,
41+
{
42+
method: "GET",
43+
},
44+
);
45+
46+
expect(response.status).toBe(400);
47+
});
48+
});

0 commit comments

Comments
 (0)