test(api): Remove old tests and introduce new, better ones
Some checks failed
CodeQL Scan / Analyze (javascript-typescript) (push) Failing after 6s
Build Docker Images / lint (push) Successful in 50s
Build Docker Images / check (push) Successful in 1m24s
Build Docker Images / tests (push) Failing after 8s
Build Docker Images / build (server, Dockerfile, ${{ github.repository_owner }}/server) (push) Has been skipped
Build Docker Images / build (worker, Worker.Dockerfile, ${{ github.repository_owner }}/worker) (push) Has been skipped
Deploy Docs to GitHub Pages / build (push) Failing after 15s
Mirror to Codeberg / Mirror (push) Failing after 0s
Deploy Docs to GitHub Pages / Deploy (push) Has been skipped
Nix Build / check (push) Failing after 33m5s

This commit is contained in:
Jesse Wierzbinski 2025-03-23 03:34:17 +01:00
parent f1ef85b314
commit ec506241f0
No known key found for this signature in database
23 changed files with 819 additions and 1001 deletions

View file

@ -1,55 +0,0 @@
import type { Application } from "@versia/kit/db";
/**
* Check if an OAuth application is valid for a route
* @param application The OAuth application
* @param routeScopes The scopes required for the route
* @returns Whether the OAuth application is valid for the route
*/
export const checkIfOauthIsValid = (
application: Application,
routeScopes: string[],
): boolean => {
if (routeScopes.length === 0) {
return true;
}
const hasAllWriteScopes =
application.data.scopes.split(" ").includes("write:*") ||
application.data.scopes.split(" ").includes("write");
const hasAllReadScopes =
application.data.scopes.split(" ").includes("read:*") ||
application.data.scopes.split(" ").includes("read");
if (hasAllWriteScopes && hasAllReadScopes) {
return true;
}
let nonMatchedScopes = routeScopes;
if (hasAllWriteScopes) {
// Filter out all write scopes as valid
nonMatchedScopes = routeScopes.filter(
(scope) => !scope.startsWith("write:"),
);
}
if (hasAllReadScopes) {
// Filter out all read scopes as valid
nonMatchedScopes = routeScopes.filter(
(scope) => !scope.startsWith("read:"),
);
}
// If there are still scopes left, check if they match
// If there are no scopes left, return true
if (nonMatchedScopes.length === 0) {
return true;
}
// If there are scopes left, check if they match
return nonMatchedScopes.every((scope) =>
application.data.scopes.split(" ").includes(scope),
);
};