Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.
TypeScript acmeagentsai-agentscertificate-managementdevsecopsenvironment-variableskubernetesopen-sourcepampkipostgresprivate-caprivileged-access-managementsecret-managementsecret-managersecretssecrets-managementsecuritysecurity-toolsvault
add integ tests for service token with overrides
Maidul Islamc7a402c4cb48
diff --git a/backend/tests/data/batch-secrets.json b/backend/tests/data/batch-secrets-no-override.jsonsimilarity index 100%rename from backend/tests/data/batch-secrets.jsonrename to backend/tests/data/batch-secrets-no-override.jsondiff --git a/backend/tests/data/batch-secrets-with-overrides.json b/backend/tests/data/batch-secrets-with-overrides.jsonnew file mode 100644index 0000000000..6173289aa4--- /dev/null+++ b/backend/tests/data/batch-secrets-with-overrides.json@@ -0,0 +1,38 @@+[+ {+ "method": "POST",+ "secret": {+ "workspace": "63cefb15c8d3175601cfa989",+ "type": "shared",+ "environment": "dev",+ "secretKeyCiphertext": "IVMtGWE=",+ "secretKeyIV": "BDsG7/ylk7mT8MrIMn0e7w==",+ "secretKeyTag": "1ujy08fctmZ1xTXMYr23UQ==",+ "secretValueCiphertext": "I9psUg==",+ "secretValueIV": "W+DJETpCerHkFv8AR9Fv4w==",+ "secretValueTag": "yODOeN3HBr/usly4VSMt9w==",+ "secretCommentCiphertext": "",+ "secretCommentIV": "QET7oX2ZiuLDSzwrkeL2Ig==",+ "secretCommentTag": "6P3xeA9eO+3Wp66ROHXgfg=="+ }+ },+ {+ "method": "POST",+ "secret": {+ "workspace": "63cefb15c8d3175601cfa989",+ "type": "personal",+ "user": "63cefa6ec8d3175601cfa980",+ "tags": [],+ "environment": "dev",+ "secretKeyCiphertext": "Q7lyRO8=",+ "secretKeyIV": "yz8koc3d63ywJMiGXpCNSw==",+ "secretKeyTag": "j2bMQ2d4sDZKA0OaKM5SXA==",+ "secretValueCiphertext": "X4kaiShmtGZt",+ "secretValueIV": "p/GdbksLVveNLsV3vz5GLA==",+ "secretValueTag": "//dhRL+pagecavHJCtMPWg==",+ "secretCommentCiphertext": "",+ "secretCommentIV": "7eYJzuilvjQPutqrqbd2MQ==",+ "secretCommentTag": "LpPv9K0Hhd5noE39Zu9U+w=="+ }+ }+]\ No newline at end of filediff --git a/backend/tests/helper/helper.ts b/backend/tests/helper/helper.tsindex 483f1a5ce5..4f3371d55a 100644--- a/backend/tests/helper/helper.ts+++ b/backend/tests/helper/helper.ts@@ -1,5 +1,6 @@// Helper functions for integration tests+import axiosInstance from "../../src/config/request";import { Secret } from "../../src/models";import { testUserEmail, testUserPassword } from "../../src/utils/addDevelopmentUser";// eslint-disable-next-line @typescript-eslint/no-var-requires@@ -38,7 +39,7 @@ export const getJWTFromTestUser = (): Promise<TokenData> => {}- const loginOneRes = await axios.post('http://localhost:4000/api/v1/auth/login1', reqBody);+ const loginOneRes = await axiosInstance.post('http://localhost:4000/api/v1/auth/login1', reqBody);const serverPublicKey = loginOneRes.data.serverPublicKey;const salt = loginOneRes.data.salt;@@ -53,7 +54,7 @@ export const getJWTFromTestUser = (): Promise<TokenData> => {clientProof}- const response2 = await axios.post('http://localhost:4000/api/v1/auth/login2', reqBody2);+ const response2 = await axiosInstance.post('http://localhost:4000/api/v1/auth/login2', reqBody2);resolve(response2.data)})@@ -68,7 +69,7 @@ export const getServiceTokenFromTestUser = async () => {key: randomBytes,});- const newServiceToken = await axios.post('http://localhost:4000/api/v2/service-token/', {+ const newServiceToken = await axiosInstance.post('http://localhost:4000/api/v2/service-token/', {'name': "test service token",'workspaceId': testWorkspaceId,'environment': "dev",diff --git a/backend/tests/integration-tests/routes/v2/secrets.test.ts b/backend/tests/integration-tests/routes/v2/secrets.test.tsindex bdfcf24f60..0ceda45de9 100644--- a/backend/tests/integration-tests/routes/v2/secrets.test.ts+++ b/backend/tests/integration-tests/routes/v2/secrets.test.ts@@ -3,7 +3,9 @@ import main from '../../../../src/index'import { testWorkspaceId } from '../../../../src/utils/addDevelopmentUser';import { deleteAllSecrets, getJWTFromTestUser, getServiceTokenFromTestUser } from '../../../helper/helper';// eslint-disable-next-line @typescript-eslint/no-var-requires-const batchSecretRequest = require('../../../data/batch-secrets.json');+const batchSecretRequestWithNoOverride = require('../../../data/batch-secrets-no-override.json');+// eslint-disable-next-line @typescript-eslint/no-var-requires+const batchSecretRequestWithOverrides = require('../../../data/batch-secrets-with-overrides.json');let server: any;@@ -16,7 +18,7 @@ afterAll(async () => {});describe("GET /api/v2/secrets", () => {- describe("Get secrets via JTW with no personal secrets", () => {+ describe("Get secrets via JTW", () => {test("should create secrets and read secrets via jwt", async () => {try {// get login details@@ -29,7 +31,7 @@ describe("GET /api/v2/secrets", () => {.send({workspaceId: testWorkspaceId,environment: "dev",- requests: batchSecretRequest+ requests: batchSecretRequestWithNoOverride})expect(createSecretsResponse.statusCode).toBe(200)@@ -105,94 +107,275 @@ describe("GET /api/v2/secrets", () => {await deleteAllSecrets()}})- })- describe("fetch secrets via service token with no personal secrets", () => {- test("should create secrets and read secrets via service token", async () => {- // get login details- const loginResponse = await getJWTFromTestUser()+ test("Get secrets via jwt when personal overrides exist", async () => {+ try {+ // get login details+ const loginResponse = await getJWTFromTestUser()++ // create creates+ const createSecretsResponse = await request(server)+ .post("/api/v2/secrets/batch")+ .set('Authorization', `Bearer ${loginResponse.token}`)+ .send({+ workspaceId: testWorkspaceId,+ environment: "dev",+ requests: batchSecretRequestWithOverrides+ })++ expect(createSecretsResponse.statusCode).toBe(200)++ const getSecrets = await request(server)+ .get("/api/v2/secrets")+ .set('Authorization', `Bearer ${loginResponse.token}`)+ .query({+ workspaceId: testWorkspaceId,+ environment: "dev"+ })++ expect(getSecrets.statusCode).toBe(200)+ expect(getSecrets.body).toHaveProperty("secrets")+ expect(getSecrets.body.secrets).toHaveLength(2)+ expect(getSecrets.body.secrets).toBeInstanceOf(Array);++ getSecrets.body.secrets.forEach((secret: any) => {+ expect(secret).toHaveProperty('_id');+ expect(secret._id).toBeTruthy();++ expect(secret).toHaveProperty('version');+ expect(secret.version).toBeTruthy();++ expect(secret).toHaveProperty('workspace');+ expect(secret.workspace).toBeTruthy();++ expect(secret).toHaveProperty('type');+ expect(secret.type).toBeTruthy();++ expect(secret).toHaveProperty('tags');+ expect(secret.tags).toHaveLength(0);++ expect(secret).toHaveProperty('environment');+ expect(secret.environment).toEqual("dev");++ expect(secret).toHaveProperty('secretKeyCiphertext');+ expect(secret.secretKeyCiphertext).toBeTruthy();++ expect(secret).toHaveProperty('secretKeyIV');+ expect(secret.secretKeyIV).toBeTruthy();++ expect(secret).toHaveProperty('secretKeyTag');+ expect(secret.secretKeyTag).toBeTruthy();++ expect(secret).toHaveProperty('secretValueCiphertext');+ expect(secret.secretValueCiphertext).toBeTruthy();++ expect(secret).toHaveProperty('secretValueIV');+ expect(secret.secretValueIV).toBeTruthy();++ expect(secret).toHaveProperty('secretValueTag');+ expect(secret.secretValueTag).toBeTruthy();++ expect(secret).toHaveProperty('secretCommentCiphertext');+ expect(secret.secretCommentCiphertext).toBeFalsy();++ expect(secret).toHaveProperty('secretCommentIV');+ expect(secret.secretCommentIV).toBeTruthy();++ expect(secret).toHaveProperty('secretCommentTag');+ expect(secret.secretCommentTag).toBeTruthy();++ expect(secret).toHaveProperty('createdAt');+ expect(secret.createdAt).toBeTruthy();++ expect(secret).toHaveProperty('updatedAt');+ expect(secret.updatedAt).toBeTruthy();+ });+ } finally {+ // clean up+ await deleteAllSecrets()+ }+ })+ })- // create secrets- const createSecretsResponse = await request(server)- .post("/api/v2/secrets/batch")- .set('Authorization', `Bearer ${loginResponse.token}`)- .send({- workspaceId: testWorkspaceId,- environment: "dev",- requests: batchSecretRequest- })+ describe("fetch secrets via service token", () => {+ test("Get secrets via jwt when personal overrides exist", async () => {+ try {+ // get login details+ const loginResponse = await getJWTFromTestUser()- expect(createSecretsResponse.statusCode).toBe(200)+ // create creates+ const createSecretsResponse = await request(server)+ .post("/api/v2/secrets/batch")+ .set('Authorization', `Bearer ${loginResponse.token}`)+ .send({+ workspaceId: testWorkspaceId,+ environment: "dev",+ requests: batchSecretRequestWithOverrides+ })+ expect(createSecretsResponse.statusCode).toBe(200)- // now use the service token to fetch secrets- const serviceToken = await getServiceTokenFromTestUser()+ // now use the service token to fetch secrets+ const serviceToken = await getServiceTokenFromTestUser()- const getSecrets = await request(server)- .get("/api/v2/secrets")- .set('Authorization', `Bearer ${serviceToken}`)- .query({- workspaceId: testWorkspaceId,- environment: "dev"- })+ const getSecrets = await request(server)+ .get("/api/v2/secrets")+ .set('Authorization', `Bearer ${serviceToken}`)+ .query({+ workspaceId: testWorkspaceId,+ environment: "dev"+ })- expect(getSecrets.statusCode).toBe(200)- expect(getSecrets.body).toHaveProperty("secrets")- expect(getSecrets.body.secrets).toHaveLength(3)- expect(getSecrets.body.secrets).toBeInstanceOf(Array);+ expect(getSecrets.statusCode).toBe(200)+ expect(getSecrets.body).toHaveProperty("secrets")+ expect(getSecrets.body.secrets).toHaveLength(2)+ expect(getSecrets.body.secrets).toBeInstanceOf(Array);- getSecrets.body.secrets.forEach((secret: any) => {- expect(secret).toHaveProperty('_id');- expect(secret._id).toBeTruthy();+ getSecrets.body.secrets.forEach((secret: any) => {+ expect(secret).toHaveProperty('_id');+ expect(secret._id).toBeTruthy();- expect(secret).toHaveProperty('version');- expect(secret.version).toBeTruthy();+ expect(secret).toHaveProperty('version');+ expect(secret.version).toBeTruthy();- expect(secret).toHaveProperty('workspace');- expect(secret.workspace).toBeTruthy();+ expect(secret).toHaveProperty('workspace');+ expect(secret.workspace).toBeTruthy();- expect(secret).toHaveProperty('type');- expect(secret.type).toBeTruthy();+ expect(secret).toHaveProperty('type');+ expect(secret.type).toBeTruthy();- expect(secret).toHaveProperty('tags');- expect(secret.tags).toHaveLength(0);+ expect(secret).toHaveProperty('tags');+ expect(secret.tags).toHaveLength(0);- expect(secret).toHaveProperty('environment');- expect(secret.environment).toEqual("dev");+ expect(secret).toHaveProperty('environment');+ expect(secret.environment).toEqual("dev");- expect(secret).toHaveProperty('secretKeyCiphertext');- expect(secret.secretKeyCiphertext).toBeTruthy();+ expect(secret).toHaveProperty('secretKeyCiphertext');+ expect(secret.secretKeyCiphertext).toBeTruthy();- expect(secret).toHaveProperty('secretKeyIV');- expect(secret.secretKeyIV).toBeTruthy();+ expect(secret).toHaveProperty('secretKeyIV');+ expect(secret.secretKeyIV).toBeTruthy();- expect(secret).toHaveProperty('secretKeyTag');- expect(secret.secretKeyTag).toBeTruthy();+ expect(secret).toHaveProperty('secretKeyTag');+ expect(secret.secretKeyTag).toBeTruthy();- expect(secret).toHaveProperty('secretValueCiphertext');- expect(secret.secretValueCiphertext).toBeTruthy();+ expect(secret).toHaveProperty('secretValueCiphertext');+ expect(secret.secretValueCiphertext).toBeTruthy();- expect(secret).toHaveProperty('secretValueIV');- expect(secret.secretValueIV).toBeTruthy();+ expect(secret).toHaveProperty('secretValueIV');+ expect(secret.secretValueIV).toBeTruthy();- expect(secret).toHaveProperty('secretValueTag');- expect(secret.secretValueTag).toBeTruthy();+ expect(secret).toHaveProperty('secretValueTag');+ expect(secret.secretValueTag).toBeTruthy();- expect(secret).toHaveProperty('secretCommentCiphertext');- expect(secret.secretCommentCiphertext).toBeFalsy();+ expect(secret).toHaveProperty('secretCommentCiphertext');+ expect(secret.secretCommentCiphertext).toBeFalsy();- expect(secret).toHaveProperty('secretCommentIV');- expect(secret.secretCommentIV).toBeTruthy();+ expect(secret).toHaveProperty('secretCommentIV');+ expect(secret.secretCommentIV).toBeTruthy();- expect(secret).toHaveProperty('secretCommentTag');- expect(secret.secretCommentTag).toBeTruthy();+ expect(secret).toHaveProperty('secretCommentTag');+ expect(secret.secretCommentTag).toBeTruthy();- expect(secret).toHaveProperty('createdAt');- expect(secret.createdAt).toBeTruthy();+ expect(secret).toHaveProperty('createdAt');+ expect(secret.createdAt).toBeTruthy();- expect(secret).toHaveProperty('updatedAt');- expect(secret.updatedAt).toBeTruthy();- });+ expect(secret).toHaveProperty('updatedAt');+ expect(secret.updatedAt).toBeTruthy();+ });+ } finally {+ // clean up+ await deleteAllSecrets()+ }})++ // test("should create secrets and read secrets via service token when no overrides", async () => {+ // // get login details+ // const loginResponse = await getJWTFromTestUser()++ // // create secrets+ // const createSecretsResponse = await request(server)+ // .post("/api/v2/secrets/batch")+ // .set('Authorization', `Bearer ${loginResponse.token}`)+ // .send({+ // workspaceId: testWorkspaceId,+ // environment: "dev",+ // requests: batchSecretRequestWithNoOverride+ // })++ // expect(createSecretsResponse.statusCode).toBe(200)+++ // // now use the service token to fetch secrets+ // const serviceToken = await getServiceTokenFromTestUser()++ // const getSecrets = await request(server)+ // .get("/api/v2/secrets")+ // .set('Authorization', `Bearer ${serviceToken}`)+ // .query({+ // workspaceId: testWorkspaceId,+ // environment: "dev"+ // })++ // expect(getSecrets.statusCode).toBe(200)+ // expect(getSecrets.body).toHaveProperty("secrets")+ // expect(getSecrets.body.secrets).toHaveLength(3)+ // expect(getSecrets.body.secrets).toBeInstanceOf(Array);++ // getSecrets.body.secrets.forEach((secret: any) => {+ // expect(secret).toHaveProperty('_id');+ // expect(secret._id).toBeTruthy();++ // expect(secret).toHaveProperty('version');+ // expect(secret.version).toBeTruthy();++ // expect(secret).toHaveProperty('workspace');+ // expect(secret.workspace).toBeTruthy();++ // expect(secret).toHaveProperty('type');+ // expect(secret.type).toBeTruthy();++ // expect(secret).toHaveProperty('tags');+ // expect(secret.tags).toHaveLength(0);++ // expect(secret).toHaveProperty('environment');+ // expect(secret.environment).toEqual("dev");++ // expect(secret).toHaveProperty('secretKeyCiphertext');+ // expect(secret.secretKeyCiphertext).toBeTruthy();++ // expect(secret).toHaveProperty('secretKeyIV');+ // expect(secret.secretKeyIV).toBeTruthy();++ // expect(secret).toHaveProperty('secretKeyTag');+ // expect(secret.secretKeyTag).toBeTruthy();++ // expect(secret).toHaveProperty('secretValueCiphertext');+ // expect(secret.secretValueCiphertext).toBeTruthy();++ // expect(secret).toHaveProperty('secretValueIV');+ // expect(secret.secretValueIV).toBeTruthy();++ // expect(secret).toHaveProperty('secretValueTag');+ // expect(secret.secretValueTag).toBeTruthy();++ // expect(secret).toHaveProperty('secretCommentCiphertext');+ // expect(secret.secretCommentCiphertext).toBeFalsy();++ // expect(secret).toHaveProperty('secretCommentIV');+ // expect(secret.secretCommentIV).toBeTruthy();++ // expect(secret).toHaveProperty('secretCommentTag');+ // expect(secret.secretCommentTag).toBeTruthy();++ // expect(secret).toHaveProperty('createdAt');+ // expect(secret.createdAt).toBeTruthy();++ // expect(secret).toHaveProperty('updatedAt');+ // expect(secret.updatedAt).toBeTruthy();+ // });+ // })++})})\ No newline at end of file