Skip to content

Commit 0774d35

Browse files
committed
convert netids to lowercase when checking membership
1 parent fcaf5ff commit 0774d35

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

src/api/routes/membership.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { FastifyPluginAsync } from "fastify";
99
import {
1010
BaseError,
1111
InternalServerError,
12+
NotImplementedError,
1213
ValidationError,
1314
} from "common/errors/index.js";
1415
import { getEntraIdToken } from "api/functions/entraId.js";
@@ -23,6 +24,7 @@ import stripe, { Stripe } from "stripe";
2324
import { AvailableSQSFunctions, SQSPayload } from "common/types/sqsMessage.js";
2425
import { SendMessageCommand, SQSClient } from "@aws-sdk/client-sqs";
2526
import rawbody, { RawBodyPluginOptions } from "fastify-raw-body";
27+
import { ListModificationPatchRequest } from "common/types/membership.js";
2628

2729
const NONMEMBER_CACHE_SECONDS = 1800; // 30 minutes
2830
const MEMBER_CACHE_SECONDS = 43200; // 12 hours
@@ -73,7 +75,7 @@ const membershipPlugin: FastifyPluginAsync = async (fastify, _options) => {
7375
Body: undefined;
7476
Params: { netId: string };
7577
}>("/checkout/:netId", async (request, reply) => {
76-
const netId = request.params.netId;
78+
const netId = request.params.netId.toLowerCase();
7779
if (!validateNetId(netId)) {
7880
throw new ValidationError({
7981
message: `${netId} is not a valid Illinois NetID!`,
@@ -147,7 +149,7 @@ const membershipPlugin: FastifyPluginAsync = async (fastify, _options) => {
147149
Querystring: { list?: string };
148150
Params: { netId: string };
149151
}>("/:netId", async (request, reply) => {
150-
const netId = request.params.netId;
152+
const netId = request.params.netId.toLowerCase();
151153
const list = request.query.list || "acmpaid";
152154
if (!validateNetId(netId)) {
153155
throw new ValidationError({

tests/live/membership.test.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,30 @@ describe("Membership API basic checks", async () => {
2020

2121
expect(wasCached(response.headers.get("x-acm-data-source"))).toBe(true);
2222
});
23+
test(
24+
"Test that getting member with non-standard casing succeeds",
25+
{ timeout: 3000 },
26+
async () => {
27+
const response = await fetch(
28+
`${baseEndpoint}/api/v1/membership/DSingh14`,
29+
{
30+
method: "GET",
31+
},
32+
);
33+
34+
expect(response.status).toBe(200);
35+
36+
const responseBody = await response.json();
37+
expect(responseBody).toStrictEqual({
38+
netId: "dsingh14",
39+
isPaidMember: true,
40+
});
41+
42+
const wasCached = (value: string | null) => value && value !== "aad";
43+
44+
expect(wasCached(response.headers.get("x-acm-data-source"))).toBe(true);
45+
},
46+
);
2347
test(
2448
"Test that getting non-members succeeds",
2549
{ timeout: 3000 },

0 commit comments

Comments
 (0)