Skip to content

Commit cb5f0ae

Browse files
authored
Increase live test coverage (#408)
1 parent 3af7200 commit cb5f0ae

File tree

5 files changed

+196
-72
lines changed

5 files changed

+196
-72
lines changed

tests/live/iam.test.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ import {
88
import { allAppRoles, AppRoles } from "../../src/common/roles.js";
99
import { getBaseEndpoint } from "./utils.js";
1010
import { environmentConfig, genericConfig } from "../../src/common/config.js";
11-
11+
const token = await createJwt();
1212
const baseEndpoint = getBaseEndpoint();
13+
1314
test("getting groups", { timeout: 10000 }, async () => {
14-
const token = await createJwt();
1515
const response = await fetch(`${baseEndpoint}/api/v1/iam/groups`, {
1616
method: "GET",
1717
headers: {
@@ -35,7 +35,6 @@ test("getting groups", { timeout: 10000 }, async () => {
3535
});
3636

3737
test("getting members of a group", async () => {
38-
const token = await createJwt();
3938
const response = await fetch(
4039
`${baseEndpoint}/api/v1/iam/groups/ff25ec56-6a33-420d-bdb0-51d8a3920e46`,
4140
{
@@ -59,7 +58,6 @@ test("getting members of a group", async () => {
5958
});
6059

6160
test("inviting users to tenant", { timeout: 60000 }, async () => {
62-
const token = await createJwt();
6361
const response = await fetch(`${baseEndpoint}/api/v1/iam/inviteUsers`, {
6462
method: "POST",
6563
headers: {
@@ -79,7 +77,6 @@ test("inviting users to tenant", { timeout: 60000 }, async () => {
7977
});
8078

8179
test("getting group roles", async () => {
82-
const token = await createJwt();
8380
const response = await fetch(`${baseEndpoint}/api/v1/iam/groups/0/roles`, {
8481
method: "GET",
8582
headers: {

tests/live/linkry.test.ts

Lines changed: 87 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
11
import { describe, expect, test } from "vitest";
2-
import { getBaseEndpoint, makeRandomString } from "./utils.js";
2+
import {
3+
createJwt,
4+
getBaseEndpoint,
5+
makeRandomString,
6+
sleep,
7+
} from "./utils.js";
8+
import { randomUUID } from "node:crypto";
39

410
const baseEndpoint = getBaseEndpoint("go");
11+
const coreBaseEndpoint = getBaseEndpoint("core");
512
const baseEndpointInfra = getBaseEndpoint("infra.go");
13+
const token = await createJwt();
14+
const linkId = `live-${randomUUID()}`;
615

716
describe("Linkry live tests", async () => {
817
test("Linkry health check", async () => {
@@ -24,3 +33,80 @@ describe("Linkry live tests", async () => {
2433
expect(response.url).toBe("https://www.acm.illinois.edu/404");
2534
});
2635
});
36+
37+
describe("Linkry normal link lifecycle", { sequential: true }, async () => {
38+
test("Create a short link", async () => {
39+
const response = await fetch(`${coreBaseEndpoint}/api/v1/linkry/redir`, {
40+
method: "POST",
41+
headers: {
42+
Authorization: `Bearer ${token}`,
43+
"Content-Type": "application/json",
44+
},
45+
body: JSON.stringify({
46+
slug: linkId,
47+
access: [],
48+
redirect: "https://www.google.com/",
49+
}),
50+
});
51+
expect(response.status).toBe(201);
52+
// Make sure link propogates
53+
await sleep(1000);
54+
const redirResponse = await fetch(`${baseEndpoint}/${linkId}`);
55+
expect(redirResponse.status).toBe(200);
56+
expect(redirResponse.redirected).toBe(true);
57+
expect(redirResponse.url).toBe("https://www.google.com/");
58+
});
59+
test("Delete a short link", async () => {
60+
let response;
61+
response = await fetch(
62+
`${coreBaseEndpoint}/api/v1/linkry/redir/${linkId}`,
63+
{
64+
method: "DELETE",
65+
headers: {
66+
Authorization: `Bearer ${token}`,
67+
},
68+
},
69+
);
70+
expect(response.status).toBe(204);
71+
});
72+
});
73+
74+
describe("Linkry org link lifecycle", { sequential: true }, async () => {
75+
test("Create a short link", async () => {
76+
const response = await fetch(
77+
`${coreBaseEndpoint}/api/v1/linkry/orgs/C01/redir`,
78+
{
79+
method: "POST",
80+
headers: {
81+
Authorization: `Bearer ${token}`,
82+
"Content-Type": "application/json",
83+
},
84+
body: JSON.stringify({
85+
slug: linkId,
86+
access: [],
87+
redirect: "https://www.google.com/",
88+
}),
89+
},
90+
);
91+
expect(response.status).toBe(201);
92+
// Make sure link propogates
93+
await sleep(1000);
94+
const redirResponse = await fetch(`${baseEndpointInfra}/${linkId}`);
95+
expect(redirResponse.status).toBe(200);
96+
expect(redirResponse.redirected).toBe(true);
97+
expect(redirResponse.url).toBe("https://www.google.com/");
98+
});
99+
test("Delete a short link", async () => {
100+
let response;
101+
response = await fetch(
102+
`${coreBaseEndpoint}/api/v1/linkry/orgs/C01/redir/${linkId}`,
103+
{
104+
method: "DELETE",
105+
headers: {
106+
Authorization: `Bearer ${token}`,
107+
},
108+
},
109+
);
110+
expect(response.status).toBe(204);
111+
});
112+
});

tests/live/logging.test.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { describe, expect, test } from "vitest";
2+
import { createJwt, getBaseEndpoint } from "./utils.js";
3+
4+
const baseEndpoint = getBaseEndpoint();
5+
const token = await createJwt();
6+
7+
describe("Audit log get tests", async () => {
8+
test("Getting the audit log succeeds", async () => {
9+
const oneHourAgo = new Date(Date.now() - 60 * 60 * 1000).getTime();
10+
const now = new Date().getTime();
11+
12+
const path = `${baseEndpoint}/api/v1/logs/iam/?start=${oneHourAgo}&end=${now}`;
13+
const response = await fetch(path, {
14+
method: "GET",
15+
headers: {
16+
Authorization: `Bearer ${token}`,
17+
},
18+
});
19+
expect(response.status).toEqual(200);
20+
const body = await response.json();
21+
expect(Array.isArray(body)).toBe(true);
22+
});
23+
});

tests/live/membership.test.ts

Lines changed: 80 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { expect, test, describe } from "vitest";
22
import { createJwt, getBaseEndpoint } from "./utils.js";
3-
import { randomUUID } from "node:crypto";
43

54
const baseEndpoint = getBaseEndpoint();
65
const token = await createJwt();
@@ -234,76 +233,91 @@ describe("Membership API basic checks", async () => {
234233
);
235234
});
236235

237-
test("External Membership List lifecycle test", async () => {
236+
describe("External Membership List lifecycle", { sequential: true }, () => {
238237
const unixTimestampSeconds = Math.floor(Date.now() / 1000);
239238
const listId = `livetest-${unixTimestampSeconds}`;
240-
let response = await fetch(
241-
`${baseEndpoint}/api/v1/membership/externalList/${listId}`,
242-
{
243-
method: "PATCH",
244-
headers: {
245-
authorization: `Bearer ${token}`,
246-
"content-type": "application/json",
239+
240+
test("should create list and add initial member", async () => {
241+
const response = await fetch(
242+
`${baseEndpoint}/api/v1/membership/externalList/${listId}`,
243+
{
244+
method: "PATCH",
245+
headers: {
246+
authorization: `Bearer ${token}`,
247+
"content-type": "application/json",
248+
},
249+
body: JSON.stringify({
250+
add: ["acmtest2"],
251+
remove: [],
252+
}),
247253
},
248-
body: JSON.stringify({
249-
add: ["acmtest2"],
250-
remove: [],
251-
}),
252-
},
253-
);
254-
expect(response.status).toBe(201);
255-
response = await fetch(
256-
`${baseEndpoint}/api/v1/membership/externalList/${listId}`,
257-
{
258-
method: "GET",
259-
headers: {
260-
authorization: `Bearer ${token}`,
261-
"content-type": "application/json",
254+
);
255+
expect(response.status).toBe(201);
256+
});
257+
258+
test("should retrieve list with initial member", async () => {
259+
const response = await fetch(
260+
`${baseEndpoint}/api/v1/membership/externalList/${listId}`,
261+
{
262+
method: "GET",
263+
headers: {
264+
authorization: `Bearer ${token}`,
265+
"content-type": "application/json",
266+
},
262267
},
263-
},
264-
);
265-
let responseJson = await response.json();
266-
expect(responseJson).toStrictEqual(["acmtest2"]);
267-
response = await fetch(
268-
`${baseEndpoint}/api/v1/membership/externalList/${listId}`,
269-
{
270-
method: "PATCH",
271-
headers: {
272-
authorization: `Bearer ${token}`,
273-
"content-type": "application/json",
268+
);
269+
const responseJson = await response.json();
270+
expect(responseJson).toStrictEqual(["acmtest2"]);
271+
});
272+
273+
test("should add new member and remove existing member", async () => {
274+
const response = await fetch(
275+
`${baseEndpoint}/api/v1/membership/externalList/${listId}`,
276+
{
277+
method: "PATCH",
278+
headers: {
279+
authorization: `Bearer ${token}`,
280+
"content-type": "application/json",
281+
},
282+
body: JSON.stringify({
283+
add: ["acmtest3"],
284+
remove: ["acmtest2"],
285+
}),
274286
},
275-
body: JSON.stringify({
276-
add: ["acmtest3"],
277-
remove: ["acmtest2"],
278-
}),
279-
},
280-
);
281-
expect(response.status).toEqual(201);
282-
response = await fetch(
283-
`${baseEndpoint}/api/v1/membership/externalList/${listId}`,
284-
{
285-
method: "GET",
286-
headers: {
287-
authorization: `Bearer ${token}`,
288-
"content-type": "application/json",
287+
);
288+
expect(response.status).toEqual(201);
289+
});
290+
291+
test("should retrieve list with updated member", async () => {
292+
const response = await fetch(
293+
`${baseEndpoint}/api/v1/membership/externalList/${listId}`,
294+
{
295+
method: "GET",
296+
headers: {
297+
authorization: `Bearer ${token}`,
298+
"content-type": "application/json",
299+
},
289300
},
290-
},
291-
);
292-
responseJson = await response.json();
293-
expect(responseJson).toStrictEqual(["acmtest3"]);
294-
response = await fetch(
295-
`${baseEndpoint}/api/v1/membership/externalList/${listId}`,
296-
{
297-
method: "PATCH",
298-
headers: {
299-
authorization: `Bearer ${token}`,
300-
"content-type": "application/json",
301+
);
302+
const responseJson = await response.json();
303+
expect(responseJson).toStrictEqual(["acmtest3"]);
304+
});
305+
306+
test("should remove final member", async () => {
307+
const response = await fetch(
308+
`${baseEndpoint}/api/v1/membership/externalList/${listId}`,
309+
{
310+
method: "PATCH",
311+
headers: {
312+
authorization: `Bearer ${token}`,
313+
"content-type": "application/json",
314+
},
315+
body: JSON.stringify({
316+
remove: ["acmtest3"],
317+
add: [],
318+
}),
301319
},
302-
body: JSON.stringify({
303-
remove: ["acmtest3"],
304-
add: [],
305-
}),
306-
},
307-
);
308-
expect(response.status).toEqual(201);
320+
);
321+
expect(response.status).toEqual(201);
322+
});
309323
});

tests/live/utils.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,3 +97,7 @@ export function makeRandomString(length: number) {
9797
}
9898
return result;
9999
}
100+
101+
export function sleep(ms: number): Promise<void> {
102+
return new Promise((resolve) => setTimeout(resolve, ms));
103+
}

0 commit comments

Comments
 (0)