diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index eee160b..834ca04 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -23,7 +23,7 @@ jobs: - name: Install OSL env: - OSL_COMMIT: 78deaec4824587cf9d71efcf5c594b521e3ab167 + OSL_COMMIT: aeb83e39b3f5638e4a366c4d9c6fa881f630e72c run: | mkdir -p "$HOME/.local/bin" git clone --filter=blob:none https://git.rotur.dev/osl/.go /tmp/osl-source diff --git a/AGENTS.md b/AGENTS.md index e884e65..3ba9147 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -1,6 +1,6 @@ # AGENTS.md -mistwarp-api is the OSL backend behind https://api.mistwarp.org/v1, for the MistWarp community site and editor (scratch-gui). It needs OSL 3.0. Community data is in SQLite (`data/community.db`), other state is JSON under `data/`, and project files are in Cloudflare R2. +mistwarp-api is the OSL backend behind https://api.mistwarp.org/v1, for the MistWarp community site and editor (scratch-gui). It needs OSL 6.1. Community data is in SQLite (`data/community.db`), other state is JSON under `data/`, and project files are in Cloudflare R2. ## Where code goes diff --git a/README.md b/README.md index 09a1923..ec8c23b 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ It runs at `https://api.mistwarp.org/v1`. The editor and community site are [scr ## Getting started -You need OSL 3.0. +You need OSL 6.1. ```sh cp .env.example .env diff --git a/opal.json b/opal.json index e1069fb..be3259a 100644 --- a/opal.json +++ b/opal.json @@ -1,6 +1,6 @@ { "name": "mistwarp-api", - "version": "1.0.0", + "version": "1.0.1", "main": "main.osl", "scripts": { "dev": ["osl", "run", "main.osl"], diff --git a/src/admin/routes.osl b/src/admin/routes.osl index b2e58d6..4b472cf 100644 --- a/src/admin/routes.osl +++ b/src/admin/routes.osl @@ -1,11 +1,12 @@ +import "std:date" export { registerAdminRoutes } def registerAdminRoutes(*serve.Router api) ( - api.POST("/errors", serve.limitRequests(20, {window: 60000}), handleRecordSiteError) + api.POST("/errors", serve.rateLimit({requests: 20, window: date.minute}), handleRecordSiteError) api.GET("/stats", handlePublicStats) - api.POST("/events", serve.limitRequests(120, {window: 60000}), handleRecordFunnelEvent) + api.POST("/events", serve.rateLimit({requests: 120, window: date.minute}), handleRecordFunnelEvent) api.POST("/admin/reports/action", requireAdmin, handleReportAction) diff --git a/src/auth/routes.osl b/src/auth/routes.osl index 99a2d80..d2f9dc4 100644 --- a/src/auth/routes.osl +++ b/src/auth/routes.osl @@ -1,3 +1,4 @@ +import "std:date" export { registerAuthRoutes } @@ -7,7 +8,7 @@ def registerAuthRoutes(*serve.Router api) ( api.GET("/health/dependencies", handleDependencyHealth) api.POST("/auth", handleRoturAuth) - api.POST("/auth/editor-session", serve.limitRequests(600, {window: 3600000}), requireAuth, handleCreateEditorSession) + api.POST("/auth/editor-session", serve.rateLimit({requests: 600, window: date.hour}), requireAuth, handleCreateEditorSession) api.GET("/me", handleGetMe) api.POST("/logout", handleLogout) diff --git a/src/classroom/classroom-switch.test.osl b/src/classroom/classroom-switch.test.osl index 3df262c..d73576a 100644 --- a/src/classroom/classroom-switch.test.osl +++ b/src/classroom/classroom-switch.test.osl @@ -227,7 +227,10 @@ testing.assert(!classroomSessionAllowed("mwc_other"), "sessions of other student testing.assert(!classroomSessionAllowed("mwc_off"), "sessions of disabled students are refused") testing.assert(!classroomSessionAllowed("mwc_missing"), "sessions of deleted students are refused") -boolean classroomEnabled = true +def turnClassroomOn() ( + classroomEnabled = true +) +turnClassroomOn() testing.assert(call("GET", "/v1/classroom", "teen", "").status == 200, "with the flag on, every teacher can use Classroom") testing.assert(call("GET", "/v1/classroom/join/OTHER234", "", "").status == 200, "with the flag on, every join code works") testing.assert(call("POST", "/v1/classroom/login", "", "{\"studentId\":\"mwc_other\"}").status == 200, "with the flag on, every student can sign in") diff --git a/src/classroom/routes.osl b/src/classroom/routes.osl index 449f58a..286321f 100644 --- a/src/classroom/routes.osl +++ b/src/classroom/routes.osl @@ -1,24 +1,25 @@ +import "std:date" export { registerClassroomRoutes } def registerClassroomRoutes(*serve.Router api) ( - api.GET("/classroom/join/:code", serve.limitRequests(30, {window: 60000}), handleClassroomJoinInfo) - api.POST("/classroom/login", serve.limitRequests(20, {window: 60000}), handleClassroomLogin) + api.GET("/classroom/join/:code", serve.rateLimit({requests: 30, window: date.minute}), handleClassroomJoinInfo) + api.POST("/classroom/login", serve.rateLimit({requests: 20, window: date.minute}), handleClassroomLogin) api.GET("/classroom/available", handleClassroomAvailable) api.GET("/classroom", requireAuth, handleGetClassroom) - api.POST("/classroom/terms/accept", requireClassroomTeacher, serve.limitRequests(20, {window: 3600000}), handleAcceptClassroomTerms) + api.POST("/classroom/terms/accept", requireClassroomTeacher, serve.rateLimit({requests: 20, window: date.hour}), handleAcceptClassroomTerms) api.GET("/classroom/school", requireClassroomTeacher, handleGetSchool) api.GET("/classroom/school/audit", requireClassroomTeacher, handleGetSchoolAudit) - api.GET("/classroom/school/export", requireClassroomTeacher, serve.limitRequests(10, {window: 3600000}), handleExportSchool) + api.GET("/classroom/school/export", requireClassroomTeacher, serve.rateLimit({requests: 10, window: date.hour}), handleExportSchool) api.POST("/classroom/school/teachers", requireClassroomTeacher, requireClassroomTerms, handleAddSchoolTeacher) api.DELETE("/classroom/school/teachers/:teacher", requireClassroomTeacher, handleRemoveSchoolTeacher) api.PUT("/classroom/school/teachers/:teacher/admin", requireClassroomTeacher, handleSetSchoolAdmin) - api.POST("/classroom/billing/checkout", requireClassroomTeacher, requireClassroomTerms, serve.limitRequests(20, {window: 3600000}), handleClassroomCheckout) - api.POST("/classroom/billing/portal", requireClassroomTeacher, serve.limitRequests(30, {window: 3600000}), handleClassroomBillingPortal) + api.POST("/classroom/billing/checkout", requireClassroomTeacher, requireClassroomTerms, serve.rateLimit({requests: 20, window: date.hour}), handleClassroomCheckout) + api.POST("/classroom/billing/portal", requireClassroomTeacher, serve.rateLimit({requests: 30, window: date.hour}), handleClassroomBillingPortal) api.POST("/classroom/billing/webhook", handleStripeWebhook) - api.POST("/classroom/trial", requireClassroomTeacher, requireClassroomTerms, serve.limitRequests(10, {window: 3600000}), handleStartClassroomTrial) - api.POST("/classroom/classes", requireClassroomTeacher, requireClassroomTerms, serve.limitRequests(20, {window: 3600000}), handleCreateClass) + api.POST("/classroom/trial", requireClassroomTeacher, requireClassroomTerms, serve.rateLimit({requests: 10, window: date.hour}), handleStartClassroomTrial) + api.POST("/classroom/classes", requireClassroomTeacher, requireClassroomTerms, serve.rateLimit({requests: 20, window: date.hour}), handleCreateClass) api.GET("/classroom/classes/:id", requireClassroomTeacher, handleGetClass) api.PUT("/classroom/classes/:id", requireClassroomTeacher, handleUpdateClass) api.DELETE("/classroom/classes/:id", requireClassroomTeacher, handleDeleteClass) @@ -27,23 +28,23 @@ def registerClassroomRoutes(*serve.Router api) ( api.DELETE("/classroom/classes/:id/teachers/:teacher", requireClassroomTeacher, handleRemoveCoTeacher) api.POST("/classroom/classes/:id/transfer", requireClassroomTeacher, handleTransferClass) api.GET("/classroom/classes/:id/audit", requireClassroomTeacher, handleGetClassAudit) - api.GET("/classroom/classes/:id/export", requireClassroomTeacher, serve.limitRequests(30, {window: 3600000}), handleExportClass) + api.GET("/classroom/classes/:id/export", requireClassroomTeacher, serve.rateLimit({requests: 30, window: date.hour}), handleExportClass) api.GET("/classroom/classes/:id/groups", requireClassroomTeacher, handleListClassGroups) api.POST("/classroom/classes/:id/present", requireClassroomTeacher, requireClassroomTerms, handleStartPresentation) api.DELETE("/classroom/classes/:id/present", requireClassroomTeacher, handleStopPresentation) api.POST("/classroom/classes/:id/groups", requireClassroomTeacher, requireClassroomTerms, handleCreateClassGroup) api.DELETE("/classroom/classes/:id/groups/:gid", requireClassroomTeacher, handleDeleteClassGroup) - api.POST("/classroom/classes/:id/students", requireClassroomTeacher, requireClassroomTerms, serve.limitRequests(30, {window: 3600000}), handleCreateStudents) + api.POST("/classroom/classes/:id/students", requireClassroomTeacher, requireClassroomTerms, serve.rateLimit({requests: 30, window: date.hour}), handleCreateStudents) api.GET("/classroom/classes/:id/students/:sid", requireClassroomTeacher, handleGetClassStudent) - api.GET("/classroom/classes/:id/students/:sid/export", requireClassroomTeacher, serve.limitRequests(60, {window: 3600000}), handleExportClassStudent) + api.GET("/classroom/classes/:id/students/:sid/export", requireClassroomTeacher, serve.rateLimit({requests: 60, window: date.hour}), handleExportClassStudent) api.PUT("/classroom/classes/:id/students/:sid", requireClassroomTeacher, handleUpdateClassStudent) api.DELETE("/classroom/classes/:id/students/:sid", requireClassroomTeacher, handleDeleteClassStudent) api.POST("/classroom/classes/:id/students/:sid/reset", requireClassroomTeacher, handleResetStudentLogin) api.POST("/classroom/classes/:id/students/:sid/move", requireClassroomTeacher, handleMoveClassStudent) api.POST("/classroom/classes/:id/students/:sid/release", requireClassroomTeacher, requireClassroomTerms, handleReleaseStudent) api.DELETE("/classroom/classes/:id/students/:sid/release", requireClassroomTeacher, handleCancelStudentRelease) - api.GET("/classroom/claim/:code", serve.limitRequests(30, {window: 60000}), handleGetClaim) - api.POST("/classroom/claim/:code", requireAuth, serve.limitRequests(10, {window: 60000}), handleRedeemClaim) + api.GET("/classroom/claim/:code", serve.rateLimit({requests: 30, window: date.minute}), handleGetClaim) + api.POST("/classroom/claim/:code", requireAuth, serve.rateLimit({requests: 10, window: date.minute}), handleRedeemClaim) api.POST("/classroom/classes/:id/assignments", requireClassroomTeacher, requireClassroomTerms, handleCreateAssignment) api.GET("/classroom/classes/:id/assignments/:aid", requireClassroomTeacher, handleGetAssignment) api.PUT("/classroom/classes/:id/assignments/:aid", requireClassroomTeacher, handleUpdateAssignment) diff --git a/src/community/routes.osl b/src/community/routes.osl index ad0922c..d475a20 100644 --- a/src/community/routes.osl +++ b/src/community/routes.osl @@ -1,3 +1,4 @@ +import "std:date" export { registerCommunityRoutes, registerCommunityUploadRoutes @@ -28,7 +29,7 @@ def registerCommunityRoutes(*serve.Router api) ( api.POST("/roadmap/:id/vote", requireAuth, handleVoteIdea) api.PUT("/roadmap/:id", requireAdmin, handleUpdateIdea) api.GET("/roadmap/:id/comments", handleGetIdeaComments) - api.POST("/roadmap/:id/comments", requireAuth, requireGoodStanding, serve.limitRequests(30, {window: 60000}), handleCreateIdeaComment) + api.POST("/roadmap/:id/comments", requireAuth, requireGoodStanding, serve.rateLimit({requests: 30, window: date.minute}), handleCreateIdeaComment) api.DELETE("/roadmap/:id/comments/:cid", requireAuth, handleDeleteIdeaComment) api.PUT("/roadmap/:id/comments/:cid", requireAuth, handleEditIdeaComment) api.POST("/roadmap/:id/comments/:cid/react", requireAuth, handleReactIdeaComment) @@ -56,7 +57,7 @@ def registerCommunityRoutes(*serve.Router api) ( api.POST("/spaces/:id/results", requireAuth, handlePublishChallengeResults) api.POST("/spaces/:id/react", requireAuth, handleReactSpace) api.GET("/spaces/:id/comments", handleGetSpaceComments) - api.POST("/spaces/:id/comments", requireAuth, requireGoodStanding, serve.limitRequests(30, {window: 60000}), handleCreateSpaceComment) + api.POST("/spaces/:id/comments", requireAuth, requireGoodStanding, serve.rateLimit({requests: 30, window: date.minute}), handleCreateSpaceComment) api.DELETE("/spaces/:id/comments/:cid", requireAuth, handleDeleteSpaceComment) api.PUT("/spaces/:id/comments/:cid", requireAuth, handleEditSpaceComment) api.POST("/spaces/:id/comments/:cid/react", requireAuth, handleReactSpaceComment) @@ -69,15 +70,15 @@ def registerCommunityRoutes(*serve.Router api) ( api.POST("/projects/:id/save", requireAuth, handleSaveProject) api.DELETE("/projects/:id/save", requireAuth, handleUnsaveProject) - api.POST("/projects/:id/preview", requireAuth, serve.limitRequests(30, {window: 3600000}), handleCreatePreview) + api.POST("/projects/:id/preview", requireAuth, serve.rateLimit({requests: 30, window: date.hour}), handleCreatePreview) api.GET("/projects/:id/releases", handleListReleases) api.GET("/projects/:id/releases/:release/project.json", handleGetReleaseProjectJson) - api.POST("/projects/:id/releases", requireAuth, serve.limitRequests(30, {window: 3600000}), handleCreateRelease) + api.POST("/projects/:id/releases", requireAuth, serve.rateLimit({requests: 30, window: date.hour}), handleCreateRelease) api.DELETE("/projects/:id/releases/:release", requireAuth, handleDeleteRelease) api.POST("/projects/:id/contribute", requireAuth, handleCreateContribution) - api.POST("/projects/:id/diagnostics", serve.limitRequests(120, {window: 60000}), handleRecordDiagnostic) + api.POST("/projects/:id/diagnostics", serve.rateLimit({requests: 120, window: date.minute}), handleRecordDiagnostic) api.GET("/projects/:id/diagnostics", requireAuth, handleGetDiagnostics) - api.POST("/projects/:id/feedback", requireAuth, requireGoodStanding, serve.limitRequests(20, {window: 3600000}), handleCreateProjectFeedback) + api.POST("/projects/:id/feedback", requireAuth, requireGoodStanding, serve.rateLimit({requests: 20, window: date.hour}), handleCreateProjectFeedback) api.GET("/projects/:id/feedback", requireAuth, handleGetProjectFeedback) api.PUT("/projects/:id/feedback/:feedback", requireAuth, handleUpdateProjectFeedback) api.GET("/projects/:id/reviews", handleListProjectReviews) @@ -85,15 +86,15 @@ def registerCommunityRoutes(*serve.Router api) ( api.DELETE("/projects/:id/reviews/me", requireAuth, handleDeleteProjectReview) api.GET("/projects/:id/comments", handleGetProjectComments) - api.POST("/projects/:id/comments/donation/intent", requireAuth, requireGoodStanding, serve.limitRequests(30, {window: 60000}), handleProjectCommentDonationIntent) - api.POST("/projects/:id/comments", requireAuth, requireGoodStanding, serve.limitRequests(30, {window: 60000}), handleCreateProjectComment) + api.POST("/projects/:id/comments/donation/intent", requireAuth, requireGoodStanding, serve.rateLimit({requests: 30, window: date.minute}), handleProjectCommentDonationIntent) + api.POST("/projects/:id/comments", requireAuth, requireGoodStanding, serve.rateLimit({requests: 30, window: date.minute}), handleCreateProjectComment) api.DELETE("/projects/:id/comments/:cid", requireAuth, handleDeleteProjectComment) api.PUT("/projects/:id/comments/:cid", requireAuth, handleEditProjectComment) api.POST("/projects/:id/comments/:cid/react", requireAuth, handleReactProjectComment) api.POST("/projects/:id/comments/:cid/pin", requireAuth, handlePinProjectComment) api.GET("/bounties/:id/activity", handleGetBountyActivity) - api.POST("/bounties/:id/comments", requireAuth, requireGoodStanding, serve.limitRequests(30, {window: 60000}), handleCreateBountyComment) + api.POST("/bounties/:id/comments", requireAuth, requireGoodStanding, serve.rateLimit({requests: 30, window: date.minute}), handleCreateBountyComment) api.PUT("/bounties/:id/comments/:cid", requireAuth, handleEditBountyComment) api.DELETE("/bounties/:id/comments/:cid", requireAuth, handleDeleteBountyComment) api.POST("/bounties/:id/workers/me", requireAuth, requireGoodStanding, handleJoinBounty) @@ -111,7 +112,7 @@ def registerCommunityRoutes(*serve.Router api) ( api.GET("/users/:name/followers", handleGetUserFollowers) api.GET("/users/:name/following", handleGetUserFollowing) api.GET("/users/:name/comments", handleGetProfileComments) - api.POST("/users/:name/comments", requireAuth, requireGoodStanding, serve.limitRequests(30, {window: 60000}), handleCreateProfileComment) + api.POST("/users/:name/comments", requireAuth, requireGoodStanding, serve.rateLimit({requests: 30, window: date.minute}), handleCreateProfileComment) api.DELETE("/users/:name/comments/:cid", requireAuth, handleDeleteProfileComment) api.PUT("/users/:name/comments/:cid", requireAuth, handleEditProfileComment) api.POST("/users/:name/comments/:cid/react", requireAuth, handleReactProfileComment) @@ -119,16 +120,16 @@ def registerCommunityRoutes(*serve.Router api) ( api.GET("/news", handleGetNews) api.GET("/news/:id", handleGetNewsItem) - api.POST("/news/:id/view", serve.limitRequests(120, {window: 3600000}), handleViewNews) + api.POST("/news/:id/view", serve.rateLimit({requests: 120, window: date.hour}), handleViewNews) api.POST("/news", requireAdmin, handleCreateNews) api.PUT("/news/:id", requireAdmin, handleUpdateNews) api.DELETE("/news/:id", requireAdmin, handleDeleteNews) api.POST("/news/:id/react", requireAuth, handleReactNews) api.POST("/news/:id/poll", requireAuth, handleVoteNewsPoll) - api.POST("/report", requireAuth, serve.limitRequests(10, {window: 3600000}), handleCreateReport) - api.POST("/reports", requireAuth, serve.limitRequests(10, {window: 3600000}), handleCreateReport) - api.POST("/support", serve.limitRequests(5, {window: 3600000}), handleCreateSupportRequest) + api.POST("/report", requireAuth, serve.rateLimit({requests: 10, window: date.hour}), handleCreateReport) + api.POST("/reports", requireAuth, serve.rateLimit({requests: 10, window: date.hour}), handleCreateReport) + api.POST("/support", serve.rateLimit({requests: 5, window: date.hour}), handleCreateSupportRequest) api.GET("/admin/reports", requireAdmin, handleGetReports) api.GET("/admin/reports/evidence/:id", requireAdmin, handleGetReportEvidence) diff --git a/src/git/routes.osl b/src/git/routes.osl index 6e4ee46..89c650e 100644 --- a/src/git/routes.osl +++ b/src/git/routes.osl @@ -1,3 +1,4 @@ +import "std:date" export { registerGitRoutes } @@ -17,7 +18,7 @@ def registerGitRoutes(*serve.Router api) ( api.POST("/projects/:id/pulls", requireAuth, handleCreatePull) api.GET("/projects/:id/pulls/:index", handleGetPull) api.GET("/projects/:id/pulls/:index/timeline", handleGetPullTimeline) - api.POST("/projects/:id/pulls/:index/comments", requireAuth, requireGoodStanding, serve.limitRequests(30, {window: 60000}), handleCreatePullComment) + api.POST("/projects/:id/pulls/:index/comments", requireAuth, requireGoodStanding, serve.rateLimit({requests: 30, window: date.minute}), handleCreatePullComment) api.PUT("/projects/:id/pulls/:index/comments/:cid", requireAuth, handleEditPullComment) api.DELETE("/projects/:id/pulls/:index/comments/:cid", requireAuth, handleDeletePullComment) api.GET("/projects/:id/pulls/:index/diff", requireAuth, handleGetPullDiff) diff --git a/src/projects/project-refusal.osl b/src/projects/project-refusal.osl index fca8097..ebaf743 100644 --- a/src/projects/project-refusal.osl +++ b/src/projects/project-refusal.osl @@ -1,6 +1,6 @@ export {} -type Refusal ( +class Refusal ( number status = 0 string message = "" boolean hasBody = false diff --git a/src/projects/project-remix.osl b/src/projects/project-remix.osl index 4ce7eae..9f88900 100644 --- a/src/projects/project-remix.osl +++ b/src/projects/project-remix.osl @@ -118,7 +118,7 @@ def handleGetRemixTree(*serve.Context c) ( c.json(200, {ok: true, root: rootId, nodes: nodes}) ) -type ForkRequest ( +class ForkRequest ( string id = "" string username = "" string userId = "" @@ -128,7 +128,7 @@ type ForkRequest ( boolean enforceLimits = true ) -type PreparedFork ( +class PreparedFork ( object failure = {} object parent = {} byte[] history = [] @@ -137,7 +137,7 @@ type PreparedFork ( string holdKey = "" ) -type ForkOutcome ( +class ForkOutcome ( Refusal refusal = Refusal() object forked = {} string keptHoldKey = "" diff --git a/src/projects/project-update-lookups.osl b/src/projects/project-update-lookups.osl index 2358659..6d5e0b8 100644 --- a/src/projects/project-update-lookups.osl +++ b/src/projects/project-update-lookups.osl @@ -1,6 +1,6 @@ export {} -type UpdateLookups ( +class UpdateLookups ( boolean replay = false boolean missed = false object answers = {} diff --git a/src/projects/project-update-policy.osl b/src/projects/project-update-policy.osl index ccbc221..41449b8 100644 --- a/src/projects/project-update-policy.osl +++ b/src/projects/project-update-policy.osl @@ -1,6 +1,6 @@ export {} -type OwnerTransfer ( +class OwnerTransfer ( string fromId = "" string toId = "" object hold = {} diff --git a/src/projects/project-update.osl b/src/projects/project-update.osl index cef683e..1bbe5c5 100644 --- a/src/projects/project-update.osl +++ b/src/projects/project-update.osl @@ -1,6 +1,6 @@ export {} -type UpdateOutcome ( +class UpdateOutcome ( boolean saved = false object project = {} array previousTeam = [] diff --git a/src/projects/project-upload-policy.osl b/src/projects/project-upload-policy.osl index a970171..549e6fe 100644 --- a/src/projects/project-upload-policy.osl +++ b/src/projects/project-upload-policy.osl @@ -1,6 +1,6 @@ export {} -type UploadRequest ( +class UploadRequest ( boolean replaceHistory = false string expectedHead = "" string expectedEdited = "" @@ -17,7 +17,7 @@ type UploadRequest ( string mergeTreeToken = "" ) -type UploadHistory ( +class UploadHistory ( string currentHead = "" string baseHead = "" object info = {} @@ -31,7 +31,7 @@ type UploadHistory ( byte[] generatedWorkspace = [] ) -type HistoryIdentity ( +class HistoryIdentity ( string projectId = "" string remixParent = "" string baseCommit = "" diff --git a/src/projects/project-upload-publish.osl b/src/projects/project-upload-publish.osl index 0250cd9..4f866df 100644 --- a/src/projects/project-upload-publish.osl +++ b/src/projects/project-upload-publish.osl @@ -1,6 +1,6 @@ export {} -type UploadRollback ( +class UploadRollback ( array previousWorkspaceKeys = [] string ownerId = "" object hold = {} diff --git a/src/projects/project-upload-publish.test.osl b/src/projects/project-upload-publish.test.osl index c932f42..aff5c9c 100644 --- a/src/projects/project-upload-publish.test.osl +++ b/src/projects/project-upload-publish.test.osl @@ -8,7 +8,7 @@ import "std:fs" import "std:thread" import "./project-upload-publish.osl" -type UploadArchive ( +class UploadArchive ( def discard() ( return ) diff --git a/src/projects/project-upload-receive.osl b/src/projects/project-upload-receive.osl index 30329bf..35e532e 100644 --- a/src/projects/project-upload-receive.osl +++ b/src/projects/project-upload-receive.osl @@ -1,6 +1,6 @@ export {} -type UploadArchive ( +class UploadArchive ( byte[] data = [] string workId = "" string zipPath = "" diff --git a/src/projects/routes.osl b/src/projects/routes.osl index 30341cc..3a52849 100644 --- a/src/projects/routes.osl +++ b/src/projects/routes.osl @@ -1,3 +1,4 @@ +import "std:date" export { registerProjectRoutes, registerProjectUploadRoutes @@ -25,8 +26,8 @@ def registerProjectRoutes(*serve.Router api) ( api.GET("/leaderboard", handleLeaderboard) - api.POST("/projects", requireAuth, serve.limitRequests(30, {window: 3600000}), handleCreateProject) - api.POST("/projects/:id/live", requireAuth, serve.limitRequests(120, {window: 60000}), handleLiveCollaboration) + api.POST("/projects", requireAuth, serve.rateLimit({requests: 30, window: date.hour}), handleCreateProject) + api.POST("/projects/:id/live", requireAuth, serve.rateLimit({requests: 120, window: date.minute}), handleLiveCollaboration) api.POST("/projects/:id/assets/check", requireAuth, handleCheckProjectAssets) api.POST("/projects/:id/upload-parts", requireAuth, requireCurrentAgreement, handleCreateProjectUploadPart) api.POST("/projects/:id/upload-parts/:token/complete", requireAuth, requireCurrentAgreement, handleCompleteProjectUploadPart) @@ -55,7 +56,7 @@ def registerProjectRoutes(*serve.Router api) ( api.POST("/projects/:id/react", requireAuth, handleReactProject) api.GET("/projects/:id/remixes", handleGetRemixes) api.GET("/projects/:id/remixtree", handleGetRemixTree) - api.POST("/projects/:id/remix", requireAuth, serve.limitRequests(30, {window: 3600000}), handleRemixProject) + api.POST("/projects/:id/remix", requireAuth, serve.rateLimit({requests: 30, window: date.hour}), handleRemixProject) api.GET("/admin/extensions", requireAdmin, handleAdminGetExtensions) diff --git a/src/rotur/rotur-webhooks.test.osl b/src/rotur/rotur-webhooks.test.osl index dce374c..555a6aa 100644 --- a/src/rotur/rotur-webhooks.test.osl +++ b/src/rotur/rotur-webhooks.test.osl @@ -56,7 +56,10 @@ def completeRoturPayment(string reference, string requestId) ( ) import "./rotur-webhooks.osl" -string roturWebhooksFile = dir ++ "rotur-webhooks.json" +def useTestWebhooksFile() ( + roturWebhooksFile = dir ++ "rotur-webhooks.json" +) +useTestWebhooksFile() string body = "{\"id\":\"evt_1\",\"type\":\"user.left\",\"data\":{\"user_id\":\"u-sam\"}}" string signature = "v1=" ++ crypto.hmac("sha256", "whsec_test", "evt_1.1790000000." ++ body) diff --git a/src/storage/backpack.test.osl b/src/storage/backpack.test.osl index cfd2c85..2903205 100644 --- a/src/storage/backpack.test.osl +++ b/src/storage/backpack.test.osl @@ -9,9 +9,12 @@ import "std:thread" import "./backpack-policy.osl" string backpackDir = "/tmp/mistwarp-backpack-test/" -number maxBackpackItems = 10 -number maxBackpackBodyBytes = 1000 -number maxBackpackThumbnailBytes = 1000 +def useTestLimits() ( + maxBackpackItems = 10 + maxBackpackBodyBytes = 1000 + maxBackpackThumbnailBytes = 1000 +) +useTestLimits() boolean failing = false object written = {} diff --git a/src/storage/storage-ledger.test.osl b/src/storage/storage-ledger.test.osl index f87508d..d222180 100644 --- a/src/storage/storage-ledger.test.osl +++ b/src/storage/storage-ledger.test.osl @@ -236,8 +236,11 @@ thread.new(def() -> ( fakeLedger.run("127.0.0.1:18761") )) wait 0.3 -string ledgerSecret = secret -string ledgerBaseSetting = "http://127.0.0.1:18761/" +def pointLedgerAtStub() ( + ledgerSecret = secret + ledgerBaseSetting = "http://127.0.0.1:18761/" +) +pointLedgerAtStub() testing.assert(ledgerReady(), "with the secret and a loopback address, storage counts") def countedFor(string userId) object (