diff --git a/src/api/routes/membership.ts b/src/api/routes/membership.ts index d4ef179c..73f8a933 100644 --- a/src/api/routes/membership.ts +++ b/src/api/routes/membership.ts @@ -15,14 +15,14 @@ import { getEntraIdToken } from "api/functions/entraId.js"; import { genericConfig, roleArns } from "common/config.js"; import { getRoleCredentials } from "api/functions/sts.js"; import { SecretsManagerClient } from "@aws-sdk/client-secrets-manager"; -import { DynamoDBClient, QueryCommand } from "@aws-sdk/client-dynamodb"; +import { DynamoDBClient } from "@aws-sdk/client-dynamodb"; import rateLimiter from "api/plugins/rateLimiter.js"; import { createCheckoutSession } from "api/functions/stripe.js"; import { getSecretValue } from "api/plugins/auth.js"; import stripe, { Stripe } from "stripe"; import { AvailableSQSFunctions, SQSPayload } from "common/types/sqsMessage.js"; import { SendMessageCommand, SQSClient } from "@aws-sdk/client-sqs"; -import rawbody, { RawBodyPluginOptions } from "fastify-raw-body"; +import rawbody from "fastify-raw-body"; const NONMEMBER_CACHE_SECONDS = 1800; // 30 minutes const MEMBER_CACHE_SECONDS = 43200; // 12 hours @@ -73,7 +73,7 @@ const membershipPlugin: FastifyPluginAsync = async (fastify, _options) => { Body: undefined; Params: { netId: string }; }>("/checkout/:netId", async (request, reply) => { - const netId = request.params.netId; + const netId = request.params.netId.toLowerCase(); if (!validateNetId(netId)) { throw new ValidationError({ message: `${netId} is not a valid Illinois NetID!`, @@ -147,7 +147,7 @@ const membershipPlugin: FastifyPluginAsync = async (fastify, _options) => { Querystring: { list?: string }; Params: { netId: string }; }>("/:netId", async (request, reply) => { - const netId = request.params.netId; + const netId = request.params.netId.toLowerCase(); const list = request.query.list || "acmpaid"; if (!validateNetId(netId)) { throw new ValidationError({ diff --git a/tests/live/membership.test.ts b/tests/live/membership.test.ts index e14c5d26..6ae0db1f 100644 --- a/tests/live/membership.test.ts +++ b/tests/live/membership.test.ts @@ -20,6 +20,30 @@ describe("Membership API basic checks", async () => { expect(wasCached(response.headers.get("x-acm-data-source"))).toBe(true); }); + test( + "Test that getting member with non-standard casing succeeds", + { timeout: 3000 }, + async () => { + const response = await fetch( + `${baseEndpoint}/api/v1/membership/DSingh14`, + { + method: "GET", + }, + ); + + expect(response.status).toBe(200); + + const responseBody = await response.json(); + expect(responseBody).toStrictEqual({ + netId: "dsingh14", + isPaidMember: true, + }); + + const wasCached = (value: string | null) => value && value !== "aad"; + + expect(wasCached(response.headers.get("x-acm-data-source"))).toBe(true); + }, + ); test( "Test that getting non-members succeeds", { timeout: 3000 },