From 9bc069ff56befd92c0204201078c08dbcd480d6d Mon Sep 17 00:00:00 2001 From: mertmit Date: Wed, 25 Sep 2024 01:30:02 +0000 Subject: [PATCH 1/4] test: use xc-token instead of xc-auth --- tests/playwright/setup/index.ts | 15 ++++++++++++++- .../playwright/tests/db/features/swagger.spec.ts | 2 +- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/tests/playwright/setup/index.ts b/tests/playwright/setup/index.ts index f763595162..1075dc506f 100644 --- a/tests/playwright/setup/index.ts +++ b/tests/playwright/setup/index.ts @@ -149,6 +149,7 @@ const workerCount = [0, 0, 0, 0, 0, 0, 0, 0]; export interface NcContext { base: BaseType; token: string; + apiToken: string; dbType?: string; workerId?: string; rootUser: UserType & { password: string }; @@ -208,6 +209,17 @@ async function localInit({ }, }); + let apiToken = null; + + const apiTokens = await api.orgTokens.list(); + + if (apiTokens.list.length > 0) { + apiToken = apiTokens.list[0].token; + } else { + const { token: createdToken } = await api.orgTokens.create({ description: 'test' }); + apiToken = createdToken; + } + // const workspaceTitle_old = `ws_pgExtREST${+workerId - 1}`; const workspaceTitle = `ws_pgExtREST${workerId}`; const baseTitle = `pgExtREST${workerId}`; @@ -363,7 +375,7 @@ async function localInit({ // get current user information const user = await api.auth.me(); - return { data: { base, user, workspace, token, api }, status: 200 }; + return { data: { base, user, workspace, token, api, apiToken }, status: 200 }; } catch (e) { console.error(`Error resetting base: ${process.env.TEST_PARALLEL_INDEX}`, e); return { data: {}, status: 500 }; @@ -497,6 +509,7 @@ const setup = async ({ return { base, token, + apiToken: response.data.apiToken, dbType, workerId, rootUser, diff --git a/tests/playwright/tests/db/features/swagger.spec.ts b/tests/playwright/tests/db/features/swagger.spec.ts index 3da2f4697b..a028ace25d 100644 --- a/tests/playwright/tests/db/features/swagger.spec.ts +++ b/tests/playwright/tests/db/features/swagger.spec.ts @@ -24,7 +24,7 @@ test.describe('Swagger', () => { // authorize with token information await swagger.locator('.btn.authorize').click(); - await swagger.locator('.modal-ux').locator('input').first().fill(context.token); + await swagger.locator('.modal-ux').locator('input').first().fill(context.apiToken); await swagger.locator('.btn.modal-btn.auth.authorize.button').first().click(); await swagger.locator('.close-modal').click(); From a0ceb4b86b085ba34995091cd3fbd3a2c8927ad9 Mon Sep 17 00:00:00 2001 From: Raju Udava <86527202+dstala@users.noreply.github.com> Date: Wed, 25 Sep 2024 01:30:03 +0000 Subject: [PATCH 2/4] fix: use of xc-token instead of xc-auth --- tests/playwright/setup/demoTable.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/playwright/setup/demoTable.ts b/tests/playwright/setup/demoTable.ts index 3705e55cbb..cc7aa2759b 100644 --- a/tests/playwright/setup/demoTable.ts +++ b/tests/playwright/setup/demoTable.ts @@ -175,7 +175,7 @@ async function createDemoTable({ api = new Api({ baseURL: `http://localhost:8080/`, headers: { - 'xc-auth': context.token, + 'xc-token': context.apiToken, }, }); From 4fd54382a4714a91a11488e78d64a68a09a5b26b Mon Sep 17 00:00:00 2001 From: Raju Udava <86527202+dstala@users.noreply.github.com> Date: Wed, 25 Sep 2024 01:30:03 +0000 Subject: [PATCH 3/4] fix: pw for api tokens --- .../usersAccounts/accountTokenManagement.spec.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tests/playwright/tests/db/usersAccounts/accountTokenManagement.spec.ts b/tests/playwright/tests/db/usersAccounts/accountTokenManagement.spec.ts index e6d61f3e49..2b214ffeb5 100644 --- a/tests/playwright/tests/db/usersAccounts/accountTokenManagement.spec.ts +++ b/tests/playwright/tests/db/usersAccounts/accountTokenManagement.spec.ts @@ -2,6 +2,7 @@ import { test } from '@playwright/test'; import { AccountPage } from '../../../pages/Account'; import { AccountTokenPage } from '../../../pages/Account/Token'; import setup, { unsetup } from '../../../setup'; +import { Api } from 'nocodb-sdk'; test.describe('Token Management', () => { let accountTokenPage: AccountTokenPage; @@ -20,6 +21,19 @@ test.describe('Token Management', () => { }); test('Create and Delete token', async () => { + // Init SDK using token + const api = new Api({ + baseURL: `http://localhost:8080/`, + headers: { + 'xc-auth': context.token, + }, + }); + + const apiTokens = await api.orgTokens.list(); + if (apiTokens.list.length > 0) { + await api.orgTokens.delete(apiTokens.list[0].id); + } + test.slow(); const parallelId = process.env.TEST_PARALLEL_INDEX ?? '0'; await accountTokenPage.goto(); From c7c483516e3069903553ab63749b0a7d2f932d6c Mon Sep 17 00:00:00 2001 From: Raju Udava <86527202+dstala@users.noreply.github.com> Date: Thu, 26 Sep 2024 11:14:37 +0530 Subject: [PATCH 4/4] fix: remove xc-auth from swagger authorize Signed-off-by: Raju Udava <86527202+dstala@users.noreply.github.com> --- packages/nocodb/src/schema/swagger-v2.json | 12 ++++++------ packages/nocodb/src/schema/swagger.json | 11 ++++++++++- .../src/services/api-docs/swagger/swagger-base.json | 6 ------ .../services/api-docs/swaggerV2/swagger-base.json | 6 ------ 4 files changed, 16 insertions(+), 19 deletions(-) diff --git a/packages/nocodb/src/schema/swagger-v2.json b/packages/nocodb/src/schema/swagger-v2.json index 36d1298fa0..98a5b646b9 100644 --- a/packages/nocodb/src/schema/swagger-v2.json +++ b/packages/nocodb/src/schema/swagger-v2.json @@ -22535,23 +22535,23 @@ } }, "parameters": { - "xc-auth": { - "name": "xc-auth", + "xc-token": { + "name": "xc-token", "in": "header", "required": true, "schema": { "type": "string" }, - "description": "Auth Token is a JWT Token generated based on the logged-in user. By default, the token is only valid for 10 hours. However, you can change the value by defining it using environment variable NC_JWT_EXPIRES_IN." + "description": "API Token. Refer [here](https://docs.nocodb.com/account-settings/api-tokens/) to know more" }, - "xc-token": { - "name": "xc-token", + "xc-auth": { + "name": "xc-auth", "in": "header", "required": true, "schema": { "type": "string" }, - "description": "API Token. Refer [here](https://docs.nocodb.com/account-settings/api-tokens/) to know more" + "description": "Auth Token is a JWT Token generated based on the logged-in user. By default, the token is only valid for 10 hours. However, you can change the value by defining it using environment variable NC_JWT_EXPIRES_IN." } } } diff --git a/packages/nocodb/src/schema/swagger.json b/packages/nocodb/src/schema/swagger.json index c0b31098db..3feb763c8d 100644 --- a/packages/nocodb/src/schema/swagger.json +++ b/packages/nocodb/src/schema/swagger.json @@ -27626,10 +27626,19 @@ } }, "parameters": { + "xc-token": { + "name": "xc-token", + "in": "header", + "required": true, + "schema": { + "type": "string" + }, + "description": "API Token. Refer [here](https://docs.nocodb.com/account-settings/api-tokens/) to know more" + }, "xc-auth": { "name": "xc-auth", "in": "header", - "required": false, + "required": true, "schema": { "type": "string" }, diff --git a/packages/nocodb/src/services/api-docs/swagger/swagger-base.json b/packages/nocodb/src/services/api-docs/swagger/swagger-base.json index b7096249f8..6a77e839b6 100644 --- a/packages/nocodb/src/services/api-docs/swagger/swagger-base.json +++ b/packages/nocodb/src/services/api-docs/swagger/swagger-base.json @@ -71,12 +71,6 @@ } }, "securitySchemes": { - "xcAuth": { - "type": "apiKey", - "in": "header", - "name": "xc-auth", - "description": "JWT access token" - }, "xcToken": { "type": "apiKey", "in": "header", diff --git a/packages/nocodb/src/services/api-docs/swaggerV2/swagger-base.json b/packages/nocodb/src/services/api-docs/swaggerV2/swagger-base.json index a8ec46234e..05b9ec18e0 100644 --- a/packages/nocodb/src/services/api-docs/swaggerV2/swagger-base.json +++ b/packages/nocodb/src/services/api-docs/swaggerV2/swagger-base.json @@ -70,12 +70,6 @@ } }, "securitySchemes": { - "xcAuth": { - "type": "apiKey", - "in": "header", - "name": "xc-auth", - "description": "JWT access token" - }, "xcToken": { "type": "apiKey", "in": "header",