Skip to content

Commit c65eeb5

Browse files
authored
Convert NetIDs to lowercase when checking membership (#88)
* convert netids to lowercase when checking membership * Remove unused/nonexistent imports
1 parent fcaf5ff commit c65eeb5

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

src/api/routes/membership.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ import { getEntraIdToken } from "api/functions/entraId.js";
1515
import { genericConfig, roleArns } from "common/config.js";
1616
import { getRoleCredentials } from "api/functions/sts.js";
1717
import { SecretsManagerClient } from "@aws-sdk/client-secrets-manager";
18-
import { DynamoDBClient, QueryCommand } from "@aws-sdk/client-dynamodb";
18+
import { DynamoDBClient } from "@aws-sdk/client-dynamodb";
1919
import rateLimiter from "api/plugins/rateLimiter.js";
2020
import { createCheckoutSession } from "api/functions/stripe.js";
2121
import { getSecretValue } from "api/plugins/auth.js";
2222
import stripe, { Stripe } from "stripe";
2323
import { AvailableSQSFunctions, SQSPayload } from "common/types/sqsMessage.js";
2424
import { SendMessageCommand, SQSClient } from "@aws-sdk/client-sqs";
25-
import rawbody, { RawBodyPluginOptions } from "fastify-raw-body";
25+
import rawbody from "fastify-raw-body";
2626

2727
const NONMEMBER_CACHE_SECONDS = 1800; // 30 minutes
2828
const MEMBER_CACHE_SECONDS = 43200; // 12 hours
@@ -73,7 +73,7 @@ const membershipPlugin: FastifyPluginAsync = async (fastify, _options) => {
7373
Body: undefined;
7474
Params: { netId: string };
7575
}>("/checkout/:netId", async (request, reply) => {
76-
const netId = request.params.netId;
76+
const netId = request.params.netId.toLowerCase();
7777
if (!validateNetId(netId)) {
7878
throw new ValidationError({
7979
message: `${netId} is not a valid Illinois NetID!`,
@@ -147,7 +147,7 @@ const membershipPlugin: FastifyPluginAsync = async (fastify, _options) => {
147147
Querystring: { list?: string };
148148
Params: { netId: string };
149149
}>("/:netId", async (request, reply) => {
150-
const netId = request.params.netId;
150+
const netId = request.params.netId.toLowerCase();
151151
const list = request.query.list || "acmpaid";
152152
if (!validateNetId(netId)) {
153153
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)