From 8c450d51da4041aec32f445d47ed03dfc0b0d613 Mon Sep 17 00:00:00 2001 From: Maidul Islam Date: Tue, 11 Apr 2023 17:49:45 -0700 Subject: [PATCH] add integration tests for service-tokens --- .../routes/v2/secrets.test.ts | 6 +- .../routes/v2/service-tokens.test.ts | 58 +++++++++++++++++++ 2 files changed, 61 insertions(+), 3 deletions(-) create mode 100644 backend/tests/integration-tests/routes/v2/service-tokens.test.ts diff --git a/backend/tests/integration-tests/routes/v2/secrets.test.ts b/backend/tests/integration-tests/routes/v2/secrets.test.ts index b380e9f9ce..bdfcf24f60 100644 --- a/backend/tests/integration-tests/routes/v2/secrets.test.ts +++ b/backend/tests/integration-tests/routes/v2/secrets.test.ts @@ -17,7 +17,7 @@ afterAll(async () => { describe("GET /api/v2/secrets", () => { describe("Get secrets via JTW with no personal secrets", () => { - test("should respond with a 200 status code", async () => { + test("should create secrets and read secrets via jwt", async () => { try { // get login details const loginResponse = await getJWTFromTestUser() @@ -108,11 +108,11 @@ describe("GET /api/v2/secrets", () => { }) describe("fetch secrets via service token with no personal secrets", () => { - test("should respond with a 200 status code", async () => { + test("should create secrets and read secrets via service token", async () => { // get login details const loginResponse = await getJWTFromTestUser() - // create creates + // create secrets const createSecretsResponse = await request(server) .post("/api/v2/secrets/batch") .set('Authorization', `Bearer ${loginResponse.token}`) diff --git a/backend/tests/integration-tests/routes/v2/service-tokens.test.ts b/backend/tests/integration-tests/routes/v2/service-tokens.test.ts new file mode 100644 index 0000000000..b011db36f8 --- /dev/null +++ b/backend/tests/integration-tests/routes/v2/service-tokens.test.ts @@ -0,0 +1,58 @@ +import request from 'supertest' +import main from '../../../../src/index' +import { getServiceTokenFromTestUser } from '../../../helper/helper'; +let server: any; + +beforeAll(async () => { + server = await main; +}); + +afterAll(async () => { + server.close(); +}); + +describe("GET /api/v2/service-token", () => { + describe("Get service token details", () => { + test("should respond create and get the details of a service token", async () => { + // generate a service token + const serviceToken = await getServiceTokenFromTestUser() + + // get the service token details + const serviceTokenDetails = await request(server) + .get("/api/v2/service-token") + .set('Authorization', `Bearer ${serviceToken}`) + + expect(serviceTokenDetails.body).toMatchObject({ + _id: expect.any(String), + name: 'test service token', + workspace: '63cefb15c8d3175601cfa989', + environment: 'dev', + user: { + _id: '63cefa6ec8d3175601cfa980', + email: 'test@localhost.local', + firstName: 'Jake', + lastName: 'Moni', + isMfaEnabled: false, + mfaMethods: expect.any(Array), + devices: [ + { + ip: expect.any(String), + userAgent: expect.any(String), + _id: expect.any(String), + }, + ], + createdAt: expect.any(String), + updatedAt: expect.any(String), + }, + lastUsed: expect.any(String), + expiresAt: expect.any(String), + encryptedKey: expect.any(String), + iv: expect.any(String), + tag: expect.any(String), + permissions: ['read'], + createdAt: expect.any(String), + updatedAt: expect.any(String), + }); + }) + }) +}) \ No newline at end of file