mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-09-22 13:39:35 +00:00
add integ tests for service token with overrides
This commit is contained in:
38
backend/tests/data/batch-secrets-with-overrides.json
Normal file
38
backend/tests/data/batch-secrets-with-overrides.json
Normal file
@@ -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=="
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
// Helper functions for integration tests
|
// Helper functions for integration tests
|
||||||
|
|
||||||
|
import axiosInstance from "../../src/config/request";
|
||||||
import { Secret } from "../../src/models";
|
import { Secret } from "../../src/models";
|
||||||
import { testUserEmail, testUserPassword } from "../../src/utils/addDevelopmentUser";
|
import { testUserEmail, testUserPassword } from "../../src/utils/addDevelopmentUser";
|
||||||
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
// 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 serverPublicKey = loginOneRes.data.serverPublicKey;
|
||||||
const salt = loginOneRes.data.salt;
|
const salt = loginOneRes.data.salt;
|
||||||
|
|
||||||
@@ -53,7 +54,7 @@ export const getJWTFromTestUser = (): Promise<TokenData> => {
|
|||||||
clientProof
|
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)
|
resolve(response2.data)
|
||||||
})
|
})
|
||||||
@@ -68,7 +69,7 @@ export const getServiceTokenFromTestUser = async () => {
|
|||||||
key: randomBytes,
|
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",
|
'name': "test service token",
|
||||||
'workspaceId': testWorkspaceId,
|
'workspaceId': testWorkspaceId,
|
||||||
'environment': "dev",
|
'environment': "dev",
|
||||||
|
|||||||
@@ -3,7 +3,9 @@ import main from '../../../../src/index'
|
|||||||
import { testWorkspaceId } from '../../../../src/utils/addDevelopmentUser';
|
import { testWorkspaceId } from '../../../../src/utils/addDevelopmentUser';
|
||||||
import { deleteAllSecrets, getJWTFromTestUser, getServiceTokenFromTestUser } from '../../../helper/helper';
|
import { deleteAllSecrets, getJWTFromTestUser, getServiceTokenFromTestUser } from '../../../helper/helper';
|
||||||
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
// 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;
|
let server: any;
|
||||||
|
|
||||||
@@ -16,7 +18,7 @@ afterAll(async () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe("GET /api/v2/secrets", () => {
|
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 () => {
|
test("should create secrets and read secrets via jwt", async () => {
|
||||||
try {
|
try {
|
||||||
// get login details
|
// get login details
|
||||||
@@ -29,7 +31,7 @@ describe("GET /api/v2/secrets", () => {
|
|||||||
.send({
|
.send({
|
||||||
workspaceId: testWorkspaceId,
|
workspaceId: testWorkspaceId,
|
||||||
environment: "dev",
|
environment: "dev",
|
||||||
requests: batchSecretRequest
|
requests: batchSecretRequestWithNoOverride
|
||||||
})
|
})
|
||||||
|
|
||||||
expect(createSecretsResponse.statusCode).toBe(200)
|
expect(createSecretsResponse.statusCode).toBe(200)
|
||||||
@@ -105,94 +107,275 @@ describe("GET /api/v2/secrets", () => {
|
|||||||
await deleteAllSecrets()
|
await deleteAllSecrets()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
|
||||||
|
|
||||||
describe("fetch secrets via service token with no personal secrets", () => {
|
test("Get secrets via jwt when personal overrides exist", async () => {
|
||||||
test("should create secrets and read secrets via service token", async () => {
|
try {
|
||||||
// get login details
|
// get login details
|
||||||
const loginResponse = await getJWTFromTestUser()
|
const loginResponse = await getJWTFromTestUser()
|
||||||
|
|
||||||
// create secrets
|
// create creates
|
||||||
const createSecretsResponse = await request(server)
|
const createSecretsResponse = await request(server)
|
||||||
.post("/api/v2/secrets/batch")
|
.post("/api/v2/secrets/batch")
|
||||||
.set('Authorization', `Bearer ${loginResponse.token}`)
|
.set('Authorization', `Bearer ${loginResponse.token}`)
|
||||||
.send({
|
.send({
|
||||||
workspaceId: testWorkspaceId,
|
workspaceId: testWorkspaceId,
|
||||||
environment: "dev",
|
environment: "dev",
|
||||||
requests: batchSecretRequest
|
requests: batchSecretRequestWithOverrides
|
||||||
})
|
})
|
||||||
|
|
||||||
expect(createSecretsResponse.statusCode).toBe(200)
|
expect(createSecretsResponse.statusCode).toBe(200)
|
||||||
|
|
||||||
|
const getSecrets = await request(server)
|
||||||
|
.get("/api/v2/secrets")
|
||||||
|
.set('Authorization', `Bearer ${loginResponse.token}`)
|
||||||
|
.query({
|
||||||
|
workspaceId: testWorkspaceId,
|
||||||
|
environment: "dev"
|
||||||
|
})
|
||||||
|
|
||||||
// now use the service token to fetch secrets
|
expect(getSecrets.statusCode).toBe(200)
|
||||||
const serviceToken = await getServiceTokenFromTestUser()
|
expect(getSecrets.body).toHaveProperty("secrets")
|
||||||
|
expect(getSecrets.body.secrets).toHaveLength(2)
|
||||||
|
expect(getSecrets.body.secrets).toBeInstanceOf(Array);
|
||||||
|
|
||||||
const getSecrets = await request(server)
|
getSecrets.body.secrets.forEach((secret: any) => {
|
||||||
.get("/api/v2/secrets")
|
expect(secret).toHaveProperty('_id');
|
||||||
.set('Authorization', `Bearer ${serviceToken}`)
|
expect(secret._id).toBeTruthy();
|
||||||
.query({
|
|
||||||
workspaceId: testWorkspaceId,
|
|
||||||
environment: "dev"
|
|
||||||
})
|
|
||||||
|
|
||||||
expect(getSecrets.statusCode).toBe(200)
|
expect(secret).toHaveProperty('version');
|
||||||
expect(getSecrets.body).toHaveProperty("secrets")
|
expect(secret.version).toBeTruthy();
|
||||||
expect(getSecrets.body.secrets).toHaveLength(3)
|
|
||||||
expect(getSecrets.body.secrets).toBeInstanceOf(Array);
|
|
||||||
|
|
||||||
getSecrets.body.secrets.forEach((secret: any) => {
|
expect(secret).toHaveProperty('workspace');
|
||||||
expect(secret).toHaveProperty('_id');
|
expect(secret.workspace).toBeTruthy();
|
||||||
expect(secret._id).toBeTruthy();
|
|
||||||
|
|
||||||
expect(secret).toHaveProperty('version');
|
expect(secret).toHaveProperty('type');
|
||||||
expect(secret.version).toBeTruthy();
|
expect(secret.type).toBeTruthy();
|
||||||
|
|
||||||
expect(secret).toHaveProperty('workspace');
|
expect(secret).toHaveProperty('tags');
|
||||||
expect(secret.workspace).toBeTruthy();
|
expect(secret.tags).toHaveLength(0);
|
||||||
|
|
||||||
expect(secret).toHaveProperty('type');
|
expect(secret).toHaveProperty('environment');
|
||||||
expect(secret.type).toBeTruthy();
|
expect(secret.environment).toEqual("dev");
|
||||||
|
|
||||||
expect(secret).toHaveProperty('tags');
|
expect(secret).toHaveProperty('secretKeyCiphertext');
|
||||||
expect(secret.tags).toHaveLength(0);
|
expect(secret.secretKeyCiphertext).toBeTruthy();
|
||||||
|
|
||||||
expect(secret).toHaveProperty('environment');
|
expect(secret).toHaveProperty('secretKeyIV');
|
||||||
expect(secret.environment).toEqual("dev");
|
expect(secret.secretKeyIV).toBeTruthy();
|
||||||
|
|
||||||
expect(secret).toHaveProperty('secretKeyCiphertext');
|
expect(secret).toHaveProperty('secretKeyTag');
|
||||||
expect(secret.secretKeyCiphertext).toBeTruthy();
|
expect(secret.secretKeyTag).toBeTruthy();
|
||||||
|
|
||||||
expect(secret).toHaveProperty('secretKeyIV');
|
expect(secret).toHaveProperty('secretValueCiphertext');
|
||||||
expect(secret.secretKeyIV).toBeTruthy();
|
expect(secret.secretValueCiphertext).toBeTruthy();
|
||||||
|
|
||||||
expect(secret).toHaveProperty('secretKeyTag');
|
expect(secret).toHaveProperty('secretValueIV');
|
||||||
expect(secret.secretKeyTag).toBeTruthy();
|
expect(secret.secretValueIV).toBeTruthy();
|
||||||
|
|
||||||
expect(secret).toHaveProperty('secretValueCiphertext');
|
expect(secret).toHaveProperty('secretValueTag');
|
||||||
expect(secret.secretValueCiphertext).toBeTruthy();
|
expect(secret.secretValueTag).toBeTruthy();
|
||||||
|
|
||||||
expect(secret).toHaveProperty('secretValueIV');
|
expect(secret).toHaveProperty('secretCommentCiphertext');
|
||||||
expect(secret.secretValueIV).toBeTruthy();
|
expect(secret.secretCommentCiphertext).toBeFalsy();
|
||||||
|
|
||||||
expect(secret).toHaveProperty('secretValueTag');
|
expect(secret).toHaveProperty('secretCommentIV');
|
||||||
expect(secret.secretValueTag).toBeTruthy();
|
expect(secret.secretCommentIV).toBeTruthy();
|
||||||
|
|
||||||
expect(secret).toHaveProperty('secretCommentCiphertext');
|
expect(secret).toHaveProperty('secretCommentTag');
|
||||||
expect(secret.secretCommentCiphertext).toBeFalsy();
|
expect(secret.secretCommentTag).toBeTruthy();
|
||||||
|
|
||||||
expect(secret).toHaveProperty('secretCommentIV');
|
expect(secret).toHaveProperty('createdAt');
|
||||||
expect(secret.secretCommentIV).toBeTruthy();
|
expect(secret.createdAt).toBeTruthy();
|
||||||
|
|
||||||
expect(secret).toHaveProperty('secretCommentTag');
|
expect(secret).toHaveProperty('updatedAt');
|
||||||
expect(secret.secretCommentTag).toBeTruthy();
|
expect(secret.updatedAt).toBeTruthy();
|
||||||
|
});
|
||||||
expect(secret).toHaveProperty('createdAt');
|
} finally {
|
||||||
expect(secret.createdAt).toBeTruthy();
|
// clean up
|
||||||
|
await deleteAllSecrets()
|
||||||
expect(secret).toHaveProperty('updatedAt');
|
}
|
||||||
expect(secret.updatedAt).toBeTruthy();
|
|
||||||
});
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe("fetch secrets via service token", () => {
|
||||||
|
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)
|
||||||
|
|
||||||
|
// 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(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()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
// 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();
|
||||||
|
// });
|
||||||
|
// })
|
||||||
|
|
||||||
|
|
||||||
|
})
|
||||||
})
|
})
|
||||||
Reference in New Issue
Block a user