From cb7f8a1eb8fc58d6e8767f2d7ddcc8f056af98eb Mon Sep 17 00:00:00 2001 From: zkldi Date: Sat, 6 Nov 2021 21:28:40 +0000 Subject: [PATCH] More test fixes... --- .../router/api/v1/clients/router.test.ts | 35 ++++++++++++++++++- .../server/router/api/v1/oauth/router.test.ts | 2 +- .../src/server/router/api/v1/oauth/router.ts | 2 +- 3 files changed, 36 insertions(+), 3 deletions(-) diff --git a/server/src/server/router/api/v1/clients/router.test.ts b/server/src/server/router/api/v1/clients/router.test.ts index 28def226c..72e79ac4f 100644 --- a/server/src/server/router/api/v1/clients/router.test.ts +++ b/server/src/server/router/api/v1/clients/router.test.ts @@ -1,6 +1,7 @@ import db from "external/mongo/db"; +import { UserAuthLevels, APITokenDocument, TachiAPIClientDocument } from "tachi-common"; import { ServerConfig } from "lib/setup/config"; -import { APITokenDocument, TachiAPIClientDocument } from "tachi-common"; + import t from "tap"; import { CreateFakeAuthCookie } from "test-utils/fake-auth"; import mockApi from "test-utils/mock-api"; @@ -114,6 +115,9 @@ t.test("POST /api/v1/clients/create", async (t) => { name: "Hello World", redirectUri: "https://example.com/callback", permissions: ["customise_profile"], + webhookUri: null, + apiKeyTemplate: null, + apiKeyFilename: null, }) .set("Cookie", cookie); @@ -135,6 +139,9 @@ t.test("POST /api/v1/clients/create", async (t) => { name: "2", redirectUri: "https://example.com/callback", permissions: ["customise_profile"], + webhookUri: null, + apiKeyTemplate: null, + apiKeyFilename: null, }) .set("Cookie", cookie); @@ -146,6 +153,9 @@ t.test("POST /api/v1/clients/create", async (t) => { name: "2".repeat(100), redirectUri: "https://example.com/callback", permissions: ["customise_profile"], + webhookUri: null, + apiKeyTemplate: null, + apiKeyFilename: null, }) .set("Cookie", cookie); @@ -161,6 +171,9 @@ t.test("POST /api/v1/clients/create", async (t) => { name: "Hello World", redirectUri: "ftp://example.com/callback", permissions: ["customise_profile"], + webhookUri: null, + apiKeyTemplate: null, + apiKeyFilename: null, }) .set("Cookie", cookie); @@ -176,6 +189,9 @@ t.test("POST /api/v1/clients/create", async (t) => { name: "Hello World", redirectUri: "http://example.com/callback", permissions: ["permission_that_doesnt_exist"], + webhookUri: null, + apiKeyTemplate: null, + apiKeyFilename: null, }) .set("Cookie", cookie); @@ -185,6 +201,17 @@ t.test("POST /api/v1/clients/create", async (t) => { }); t.test("Should cap a user at OAUTH_CLIENT_CAP.", async (t) => { + await db.users.update( + { + id: 1, + }, + { + $set: { + authLevel: UserAuthLevels.USER, + }, + } + ); + for (let i = 0; i < ServerConfig.OAUTH_CLIENT_CAP; i++) { // eslint-disable-next-line no-await-in-loop await mockApi @@ -193,6 +220,9 @@ t.test("POST /api/v1/clients/create", async (t) => { name: "Hello World", redirectUri: "https://example.com/callback", permissions: ["customise_profile"], + webhookUri: null, + apiKeyTemplate: null, + apiKeyFilename: null, }) .set("Cookie", cookie); } @@ -203,6 +233,9 @@ t.test("POST /api/v1/clients/create", async (t) => { name: "Hello World", redirectUri: "https://example.com/callback", permissions: ["customise_profile"], + webhookUri: null, + apiKeyTemplate: null, + apiKeyFilename: null, }) .set("Cookie", cookie); diff --git a/server/src/server/router/api/v1/oauth/router.test.ts b/server/src/server/router/api/v1/oauth/router.test.ts index df5cd5e30..f55c9563e 100644 --- a/server/src/server/router/api/v1/oauth/router.test.ts +++ b/server/src/server/router/api/v1/oauth/router.test.ts @@ -23,7 +23,7 @@ t.test("POST /api/v1/oauth/token", (t) => { t.not(tokenDoc, null); t.equal(tokenDoc?.userID, 1); - t.equal(tokenDoc?.fromOAuth2Client, "OAUTH2_CLIENT_ID"); + t.equal(tokenDoc?.fromAPIClient, "OAUTH2_CLIENT_ID"); t.strictSame( tokenDoc?.permissions, { diff --git a/server/src/server/router/api/v1/oauth/router.ts b/server/src/server/router/api/v1/oauth/router.ts index 653eb738e..247679288 100644 --- a/server/src/server/router/api/v1/oauth/router.ts +++ b/server/src/server/router/api/v1/oauth/router.ts @@ -73,7 +73,7 @@ router.post( identifier: `${client.name} Token`, // converts ["a","b"] to {a: true, b: true}. permissions: Object.fromEntries(client.requestedPermissions.map((e) => [e, true])), - fromOAuth2Client: client.clientID, + fromAPIClient: client.clientID, }; // Now we can actually register the api key (lol)