Skip to content

Commit e1e35dc

Browse files
committed
Add givenName and surname to authenticated membership response
1 parent 5d62df0 commit e1e35dc

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

src/api/routes/membership.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,16 @@ const membershipPlugin: FastifyPluginAsync = async (fastify, _options) => {
107107
"application/json": {
108108
schema: z
109109
.object({
110+
givenName: z.string().min(1),
111+
surname: z.string().min(1),
110112
netId: illinoisNetId,
111113
list: z.optional(z.string().min(1)),
112114
isPaidMember: z.boolean(),
113115
})
114116
.meta({
115117
example: {
118+
givenName: "Robert",
119+
surname: "Jones",
116120
netId: "rjjones",
117121
isPaidMember: false,
118122
},
@@ -148,6 +152,8 @@ const membershipPlugin: FastifyPluginAsync = async (fastify, _options) => {
148152
});
149153
if (result) {
150154
return reply.header("X-ACM-Data-Source", "cache").send({
155+
givenName,
156+
surname,
151157
netId,
152158
list: list === "acmpaid" ? undefined : list,
153159
isPaidMember: result.isMember,
@@ -167,6 +173,8 @@ const membershipPlugin: FastifyPluginAsync = async (fastify, _options) => {
167173
logger: request.log,
168174
});
169175
return reply.header("X-ACM-Data-Source", "dynamo").send({
176+
givenName,
177+
surname,
170178
netId,
171179
list,
172180
isPaidMember: isMember,
@@ -186,7 +194,7 @@ const membershipPlugin: FastifyPluginAsync = async (fastify, _options) => {
186194
});
187195
return reply
188196
.header("X-ACM-Data-Source", "dynamo")
189-
.send({ netId, isPaidMember: true });
197+
.send({ givenName, surname, netId, isPaidMember: true });
190198
}
191199
const entraIdToken = await getEntraIdToken({
192200
clients: await getAuthorizedClients(),
@@ -210,7 +218,7 @@ const membershipPlugin: FastifyPluginAsync = async (fastify, _options) => {
210218
});
211219
reply
212220
.header("X-ACM-Data-Source", "aad")
213-
.send({ netId, isPaidMember: true });
221+
.send({ givenName, surname, netId, isPaidMember: true });
214222
await setPaidMembershipInTable(netId, fastify.dynamoClient);
215223
return;
216224
}
@@ -223,7 +231,7 @@ const membershipPlugin: FastifyPluginAsync = async (fastify, _options) => {
223231
});
224232
return reply
225233
.header("X-ACM-Data-Source", "aad")
226-
.send({ netId, isPaidMember: false });
234+
.send({ givenName, surname, netId, isPaidMember: false });
227235
},
228236
);
229237
fastify.withTypeProvider<FastifyZodOpenApiTypeProvider>().get(

tests/unit/membership.test.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ describe("Test membership routes", async () => {
4747
expect(response.headers).toHaveProperty("x-acm-data-source");
4848
expect(response.headers["x-acm-data-source"]).toEqual("aad");
4949
expect(responseDataJson).toEqual({
50+
givenName: "Infra",
51+
surname: "Testing",
5052
netId: "fjkldk99",
5153
isPaidMember: false,
5254
});
@@ -64,7 +66,12 @@ describe("Test membership routes", async () => {
6466
const responseDataJson = (await response.json()) as EventGetResponse;
6567
expect(response.headers).toHaveProperty("x-acm-data-source");
6668
expect(response.headers["x-acm-data-source"]).toEqual("dynamo");
67-
expect(responseDataJson).toEqual({ netId: "valid", isPaidMember: true });
69+
expect(responseDataJson).toEqual({
70+
givenName: "Infra",
71+
surname: "Testing",
72+
netId: "valid",
73+
isPaidMember: true,
74+
});
6875
});
6976

7077
test("Test getting non-member", async () => {

0 commit comments

Comments
 (0)