Skip to content

Commit 53f2e01

Browse files
committed
only use CoreOrganizationList for events/ical
1 parent 3497cc8 commit 53f2e01

File tree

4 files changed

+34
-25
lines changed

4 files changed

+34
-25
lines changed

src/api/routes/events.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import "zod-openapi/extend";
22
import { FastifyPluginAsync, FastifyRequest } from "fastify";
33
import { AppRoles } from "../../common/roles.js";
44
import { z } from "zod";
5-
import { AllOrganizationList } from "@acm-uiuc/js-shared";
5+
import { CoreOrganizationList } from "@acm-uiuc/js-shared";
66
import {
77
DeleteItemCommand,
88
GetItemCommand,
@@ -111,7 +111,7 @@ const baseSchema = z.object({
111111
description: "Google Maps link for easy navigation to the event location.",
112112
example: "https://maps.app.goo.gl/dwbBBBkfjkgj8gvA8",
113113
}),
114-
host: z.enum(AllOrganizationList as [string, ...string[]]),
114+
host: z.enum(CoreOrganizationList as [string, ...string[]]),
115115
featured: z.boolean().default(false).openapi({
116116
description:
117117
"Whether or not the event should be shown on the ACM @ UIUC website home page (and added to Discord, as available).",
@@ -165,7 +165,7 @@ const eventsPlugin: FastifyPluginAsyncZodOpenApi = async (
165165
"If true, only get events which are marked as featured.",
166166
}),
167167
host: z
168-
.enum(AllOrganizationList as [string, ...string[]])
168+
.enum(CoreOrganizationList as [string, ...string[]])
169169
.optional()
170170
.openapi({
171171
description: "Retrieve events only for a specific host.",

src/api/routes/ics.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import ical, {
1414
} from "ical-generator";
1515
import moment from "moment";
1616
import { getVtimezoneComponent } from "@touch4it/ical-timezones";
17-
import { AllOrganizationList } from "@acm-uiuc/js-shared";
17+
import { CoreOrganizationList } from "@acm-uiuc/js-shared";
1818
import { CLIENT_HTTP_CACHE_POLICY, EventRepeatOptions } from "./events.js";
1919
import rateLimiter from "api/plugins/rateLimiter.js";
2020
import { getCacheCounter } from "api/functions/cache.js";
@@ -43,7 +43,7 @@ function generateHostName(host: string) {
4343

4444
const icalPlugin: FastifyPluginAsync = async (fastify, _options) => {
4545
fastify.register(rateLimiter, {
46-
limit: AllOrganizationList.length,
46+
limit: CoreOrganizationList.length,
4747
duration: 30,
4848
rateLimitIdentifier: "ical",
4949
});
@@ -53,7 +53,7 @@ const icalPlugin: FastifyPluginAsync = async (fastify, _options) => {
5353
schema: withTags(["iCalendar Integration"], {
5454
params: z.object({
5555
host: z
56-
.optional(z.enum(AllOrganizationList as [string, ...string[]]))
56+
.optional(z.enum(CoreOrganizationList as [string, ...string[]]))
5757
.openapi({ description: "Host to get calendar for." }),
5858
}),
5959
summary:
@@ -87,7 +87,7 @@ const icalPlugin: FastifyPluginAsync = async (fastify, _options) => {
8787
reply.header("etag", etag);
8888
}
8989
if (host) {
90-
if (!AllOrganizationList.includes(host)) {
90+
if (!CoreOrganizationList.includes(host)) {
9191
throw new ValidationError({
9292
message: `Invalid host parameter "${host}" in path.`,
9393
});

src/common/policies/events.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { string, z } from "zod";
22
import { createPolicy } from "./evaluator.js";
3-
import { AllOrganizationList } from "@acm-uiuc/js-shared";
3+
import { CoreOrganizationList } from "@acm-uiuc/js-shared";
44
import { FastifyRequest } from "fastify";
55

66
export const hostRestrictionPolicy = createPolicy(
77
"EventsHostRestrictionPolicy",
8-
z.object({ host: z.array(z.enum(AllOrganizationList)) }),
8+
z.object({ host: z.array(z.enum(CoreOrganizationList)) }),
99
(request: FastifyRequest & { username?: string }, params) => {
1010
if (request.method === "GET") {
1111
return {

tests/live/ical.test.ts

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
import { expect, test } from "vitest";
2-
import { AllOrganizationList } from "@acm-uiuc/js-shared";
1+
import { describe, expect, test } from "vitest";
2+
import { CoreOrganizationList } from "@acm-uiuc/js-shared";
33
import ical from "node-ical";
44
const baseEndpoint = `https://core.aws.qa.acmuiuc.org`;
55

66
const delay = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));
77

88
const fetchWithRateLimit = async (url: string) => {
99
const response = await fetch(url);
10-
expect(response.status).toBe(200);
1110

1211
// Check rate limit headers
1312
const remaining = parseInt(
@@ -26,19 +25,29 @@ const fetchWithRateLimit = async (url: string) => {
2625
return response;
2726
};
2827

29-
test("Get calendars with rate limit handling", { timeout: 45000 }, async () => {
30-
for (const org of AllOrganizationList) {
31-
const response = await fetchWithRateLimit(
32-
`${baseEndpoint}/api/v1/ical/${org}`,
33-
);
34-
expect(response.status).toBe(200);
35-
expect(response.headers.get("Content-Disposition")).toEqual(
36-
'attachment; filename="calendar.ics"',
37-
);
38-
const calendar = ical.sync.parseICS(await response.text());
39-
expect(calendar["vcalendar"]["type"]).toEqual("VCALENDAR");
40-
}
41-
});
28+
describe(
29+
"Get calendars per organization with rate limit handling",
30+
{ timeout: 450000 },
31+
async () => {
32+
for (const org of CoreOrganizationList) {
33+
test(`Get ${org} calendar`, async () => {
34+
await delay(Math.random() * 200);
35+
const response = await fetchWithRateLimit(
36+
`${baseEndpoint}/api/v1/ical/${org}`,
37+
);
38+
if (!response.ok) {
39+
console.log(response);
40+
}
41+
expect(response.status).toBe(200);
42+
expect(response.headers.get("Content-Disposition")).toEqual(
43+
'attachment; filename="calendar.ics"',
44+
);
45+
const calendar = ical.sync.parseICS(await response.text());
46+
expect(calendar["vcalendar"]["type"]).toEqual("VCALENDAR");
47+
});
48+
}
49+
},
50+
);
4251

4352
test("Check that the ical base works", { timeout: 45000 }, async () => {
4453
const response = await fetchWithRateLimit(

0 commit comments

Comments
 (0)