Skip to content

Commit 4712254

Browse files
committed
Linkry test suite updated
1 parent b6bb60d commit 4712254

File tree

9 files changed

+354
-28
lines changed

9 files changed

+354
-28
lines changed

src/api/routes/linkry.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,9 @@ const linkryRoutes: FastifyPluginAsync = async (fastify, _options) => {
488488
setUserGroups,
489489
);
490490
if (mutualGroups.size == 0) {
491-
throw new NotFoundError({ endpointName: request.url });
491+
throw new UnauthorizedError({
492+
message: "You have not been delegated access.",
493+
});
492494
}
493495
}
494496
return reply.status(200).send(item);

tests/unit/auth.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const ddbMock = mockClient(SecretsManagerClient);
1919

2020
const app = await init();
2121
const jwt_secret = secretObject["jwt_key"];
22-
export function createJwt(date?: Date, group?: string, email?: string) {
22+
export function createJwt(date?: Date, groups?: string[], email?: string) {
2323
let modifiedPayload = {
2424
...jwtPayload,
2525
email: email || jwtPayload.email,
@@ -36,8 +36,8 @@ export function createJwt(date?: Date, group?: string, email?: string) {
3636
};
3737
}
3838

39-
if (group) {
40-
modifiedPayload.groups = [group];
39+
if (groups) {
40+
modifiedPayload.groups = groups;
4141
}
4242
return jwt.sign(modifiedPayload, jwt_secret, { algorithm: "HS256" });
4343
}

tests/unit/eventPost.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ test("Sad path: Not authenticated", async () => {
4848

4949
test("Sad path: Authenticated but not authorized", async () => {
5050
await app.ready();
51-
const testJwt = createJwt(undefined, "1");
51+
const testJwt = createJwt(undefined, ["1"]);
5252
const response = await supertest(app.server)
5353
.post("/api/v1/events")
5454
.set("Authorization", `Bearer ${testJwt}`)
@@ -66,7 +66,7 @@ test("Sad path: Authenticated but not authorized", async () => {
6666
});
6767
test("Sad path: Prevent empty body request", async () => {
6868
await app.ready();
69-
const testJwt = createJwt(undefined, "0");
69+
const testJwt = createJwt(undefined, ["0"]);
7070
const response = await supertest(app.server)
7171
.post("/api/v1/events")
7272
.set("Authorization", `Bearer ${testJwt}`)
@@ -226,7 +226,7 @@ describe("ETag Lifecycle Tests", () => {
226226
Items: [],
227227
});
228228

229-
const testJwt = createJwt(undefined, "0");
229+
const testJwt = createJwt(undefined, ["0"]);
230230

231231
// 1. Check initial etag for all events is 0
232232
const initialAllResponse = await app.inject({
@@ -312,7 +312,7 @@ describe("ETag Lifecycle Tests", () => {
312312
Items: [],
313313
});
314314

315-
const testJwt = createJwt(undefined, "0");
315+
const testJwt = createJwt(undefined, ["0"]);
316316

317317
// 1. Create an event
318318
const eventResponse = await supertest(app.server)
@@ -412,7 +412,7 @@ describe("ETag Lifecycle Tests", () => {
412412
Items: [],
413413
});
414414

415-
const testJwt = createJwt(undefined, "0");
415+
const testJwt = createJwt(undefined, ["0"]);
416416

417417
// 1. Check initial etag for all events is 0
418418
const initialAllResponse = await app.inject({

tests/unit/events.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ test("ETag should increment after event creation", async () => {
5050
Items: [],
5151
});
5252

53-
const testJwt = createJwt(undefined, "0");
53+
const testJwt = createJwt(undefined, ["0"]);
5454

5555
// 1. Check initial etag for all events is 0
5656
const initialAllResponse = await app.inject({
@@ -138,7 +138,7 @@ test("Should return 304 Not Modified when If-None-Match header matches ETag", as
138138
Items: [],
139139
});
140140

141-
const testJwt = createJwt(undefined, "0");
141+
const testJwt = createJwt(undefined, ["0"]);
142142

143143
// 1. First GET request to establish ETag
144144
const initialResponse = await app.inject({
@@ -188,7 +188,7 @@ test("Should return 304 Not Modified when If-None-Match header matches quoted ET
188188
Items: [],
189189
});
190190

191-
const testJwt = createJwt(undefined, "0");
191+
const testJwt = createJwt(undefined, ["0"]);
192192

193193
// 1. First GET request to establish ETag
194194
const initialResponse = await app.inject({
@@ -238,7 +238,7 @@ test("Should NOT return 304 when ETag has changed", async () => {
238238
Items: [],
239239
});
240240

241-
const testJwt = createJwt(undefined, "0");
241+
const testJwt = createJwt(undefined, ["0"]);
242242

243243
// 1. Initial GET to establish ETag
244244
const initialResponse = await app.inject({
@@ -313,7 +313,7 @@ test("Should handle 304 responses for individual event endpoints", async () => {
313313
ddbMock.on(PutItemCommand).resolves({});
314314

315315
// Create an event
316-
const testJwt = createJwt(undefined, "0");
316+
const testJwt = createJwt(undefined, ["0"]);
317317
const eventResponse = await supertest(app.server)
318318
.post("/api/v1/events")
319319
.set("Authorization", `Bearer ${testJwt}`)

0 commit comments

Comments
 (0)