Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

add integration tests for service-tokens

Maidul Islam8c450d51da40
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: '[email protected]',
+ 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