Skip to content

Commit 6d5d640

Browse files
EthM370devksingh4
andauthored
Linkry Test Suite (#121)
* Linkry test suite updated * Minor fix * Linkry test suite updated * Minor fix * Force unit tests to run * change base branch * Linkry test suite addition & fixes --------- Co-authored-by: Dev Singh <[email protected]>
1 parent 0cce635 commit 6d5d640

File tree

9 files changed

+578
-38
lines changed

9 files changed

+578
-38
lines changed

src/api/routes/linkry.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,9 @@ const linkryRoutes: FastifyPluginAsync = async (fastify, _options) => {
495495
setUserGroups,
496496
);
497497
if (mutualGroups.size == 0) {
498-
throw new NotFoundError({ endpointName: request.url });
498+
throw new UnauthorizedError({
499+
message: "You have not been delegated access.",
500+
});
499501
}
500502
}
501503
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}`)
@@ -227,7 +227,7 @@ describe("ETag Lifecycle Tests", () => {
227227
Items: [],
228228
});
229229

230-
const testJwt = createJwt(undefined, "0");
230+
const testJwt = createJwt(undefined, ["0"]);
231231

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

316-
const testJwt = createJwt(undefined, "0");
316+
const testJwt = createJwt(undefined, ["0"]);
317317

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

416-
const testJwt = createJwt(undefined, "0");
416+
const testJwt = createJwt(undefined, ["0"]);
417417

418418
// 1. Check initial etag for all events is 0
419419
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)