diff --git a/chaoscenter/cypress.config.js b/chaoscenter/cypress.config.js index 684ac022a..4e7378553 100644 --- a/chaoscenter/cypress.config.js +++ b/chaoscenter/cypress.config.js @@ -2,7 +2,7 @@ const { defineConfig } = require("cypress"); module.exports = defineConfig({ e2e: { - baseUrl: 'http://192.168.49.2:31353', + baseUrl: 'http://192.168.49.2:30829', requestTimeout: 60000, responseTimeout: 60000 }, diff --git a/chaoscenter/cypress/e2e/REST APIs/UserManagment.cy.js b/chaoscenter/cypress/e2e/REST APIs/UserManagment.cy.js index acabd9bdf..4fd3f5cfa 100644 --- a/chaoscenter/cypress/e2e/REST APIs/UserManagment.cy.js +++ b/chaoscenter/cypress/e2e/REST APIs/UserManagment.cy.js @@ -84,6 +84,26 @@ describe('Test Cases for User-Management', () => { it('Disable user', () => { const accessToken = localStorage.getItem('accessToken'); + //negative test case for disable user + const disable_payload1 = { + username: '123', + isDeactivate: true + }; + + cy.request({ + method: 'POST', + url: '/auth/update/state', + failOnStatusCode: false, + headers: { + Authorization: `Bearer ${accessToken}` + }, + body: disable_payload1, + }).then((response) => { + expect(response.body.error).to.equal('user does not exist'); + }); + + + //disable user const disable_payload = { username: user.username, isDeactivate: true diff --git a/chaoscenter/cypress/e2e/REST APIs/chaosProbes.cy.js b/chaoscenter/cypress/e2e/REST APIs/chaosProbes.cy.js index cb21a1c00..8b59ef1a9 100644 --- a/chaoscenter/cypress/e2e/REST APIs/chaosProbes.cy.js +++ b/chaoscenter/cypress/e2e/REST APIs/chaosProbes.cy.js @@ -15,7 +15,7 @@ describe('Testing http chaos Probes', () => { variables: { projectID: projectID, request: { - name: "exp1", + name: "exp1111", description: '', tags: [], type: 'httpProbe', @@ -45,7 +45,7 @@ describe('Testing http chaos Probes', () => { } }).then((response) => { expect(response.status).to.equal(200); - expect(response.body.data.addProbe.name).to.equal("exp1"); + expect(response.body.data.addProbe.name).to.equal("exp1111"); }); }); @@ -59,7 +59,7 @@ describe('Testing http chaos Probes', () => { variables: { projectID: projectID, request: { - name: "exp1", + name: "exp1111", description: '', tags: [], type: 'httpProbe', @@ -89,7 +89,7 @@ describe('Testing http chaos Probes', () => { } }).then((response) => { expect(response.status).to.equal(200); - expect(response.body.errors[0].message).to.equal('write exception: write errors: [E11000 duplicate key error collection: litmus.chaosProbes index: name_1 dup key: { name: "exp1" }]'); + expect(response.body.errors[0].message).to.equal('write exception: write errors: [E11000 duplicate key error collection: litmus.chaosProbes index: name_1 dup key: { name: "exp1111" }]'); }); }); @@ -101,7 +101,7 @@ describe('Testing http chaos Probes', () => { variables: { projectID: projectID, request: { - name: "exp1", + name: "exp1111", description: '', tags: [], type: 'httpProbe', @@ -138,11 +138,34 @@ describe('Testing http chaos Probes', () => { it('Delete chaos probe', () => { const accessToken = localStorage.getItem('accessToken'); const projectID = localStorage.getItem('projectID'); + + //negative test case for delete chaos probe + const deleteProbe_payload1 = { + operationName: 'deleteProbe', + variables: { + projectID: projectID, + probeName: "exp0" + }, + query: delete_httpprobe + } + + cy.request({ + method: 'POST', + url: '/api/query', + body: deleteProbe_payload1, + headers: { + Authorization: `Bearer ${accessToken}` + } + }).then((response) => { + expect(response.body.errors[0].message).to.equal('mongo: no documents in result'); + }); + + //delete chaos probe const deleteProbe_payload = { operationName: 'deleteProbe', variables: { projectID: projectID, - probeName: "exp1" + probeName: "exp1111" }, query: delete_httpprobe } @@ -176,7 +199,7 @@ describe('testing CMD chaos probes', () => { variables: { projectID: projectID, request: { - name: "exp2", + name: "exp2222", description: "", tags: [], type: "cmdProbe", @@ -209,7 +232,7 @@ describe('testing CMD chaos probes', () => { }, }).then((response) => { expect(response.status).to.equal(200); - expect(response.body.data.addProbe.name).to.equal("exp2"); + expect(response.body.data.addProbe.name).to.equal("exp2222"); }); }); @@ -221,7 +244,7 @@ describe('testing CMD chaos probes', () => { variables: { projectID: projectID, request: { - name: "exp2", + name: "exp2222", description: "", tags: [], type: "cmdProbe", @@ -253,7 +276,7 @@ describe('testing CMD chaos probes', () => { }, }).then((response) => { expect(response.status).to.equal(200); - expect(response.body.errors[0].message).to.equal('write exception: write errors: [E11000 duplicate key error collection: litmus.chaosProbes index: name_1 dup key: { name: "exp2" }]'); + expect(response.body.errors[0].message).to.equal('write exception: write errors: [E11000 duplicate key error collection: litmus.chaosProbes index: name_1 dup key: { name: "exp2222" }]'); }); }); @@ -266,7 +289,7 @@ describe('testing CMD chaos probes', () => { variables: { projectID: projectID, request: { - name: "exp2", + name: "exp2222", description: "", tags: [], type: "cmdProbe", @@ -309,12 +332,34 @@ describe('testing CMD chaos probes', () => { it('delete chaos probe', () => { const accessToken = localStorage.getItem('accessToken'); const projectID = localStorage.getItem('projectID'); + + //negative test case for delete chaos probe + const deleteCMDProbe_payload1 = { + operationName: "deleteProbe", + variables: { + projectID: projectID, + probeName: "exp0", + }, + query: delete_CMDprobe, + }; + + cy.request({ + method: "POST", + url: "/api/query", + body: deleteCMDProbe_payload1, + headers: { + Authorization: `Bearer ${accessToken}`, + }, + }).then((response) => { + expect(response.body.errors[0].message).to.equal('mongo: no documents in result'); + }); + //delete probe const deleteCMDProbe_payload = { operationName: "deleteProbe", variables: { projectID: projectID, - probeName: "exp2", + probeName: "exp2222", }, query: delete_CMDprobe, }; @@ -348,7 +393,7 @@ describe('testing prometheus chaos probes', () => { variables: { projectID: projectID, request: { - name: "exp3", + name: "exp3333", description: "", tags: [], type: "promProbe", @@ -382,7 +427,7 @@ describe('testing prometheus chaos probes', () => { }, }).then((response) => { expect(response.status).to.equal(200); - expect(response.body.data.addProbe.name).to.equal("exp3"); + expect(response.body.data.addProbe.name).to.equal("exp3333"); }); }); @@ -394,7 +439,7 @@ describe('testing prometheus chaos probes', () => { variables: { projectID: projectID, request: { - name: "exp3", + name: "exp3333", description: "", tags: [], type: "promProbe", @@ -428,7 +473,7 @@ describe('testing prometheus chaos probes', () => { }, }).then((response) => { expect(response.status).to.equal(200); - expect(response.body.errors[0].message).to.equal('write exception: write errors: [E11000 duplicate key error collection: litmus.chaosProbes index: name_1 dup key: { name: "exp3" }]'); + expect(response.body.errors[0].message).to.equal('write exception: write errors: [E11000 duplicate key error collection: litmus.chaosProbes index: name_1 dup key: { name: "exp3333" }]'); }); }); @@ -441,7 +486,7 @@ describe('testing prometheus chaos probes', () => { variables: { projectID: projectID, request: { - name: "exp3", + name: "exp3333", description: "", tags: [], type: "promProbe", @@ -485,12 +530,34 @@ describe('testing prometheus chaos probes', () => { it('delete chaos probe', () => { const accessToken = localStorage.getItem('accessToken'); const projectID = localStorage.getItem('projectID'); + + //negative test case for delete chaos probe + const deletePROMProbe_payload1 = { + operationName: "deleteProbe", + variables: { + projectID: projectID, + probeName: "exp0", + }, + query: delete_PROMProbe, + }; + + cy.request({ + method: "POST", + url: "/api/query", + body: deletePROMProbe_payload1, + headers: { + Authorization: `Bearer ${accessToken}`, + }, + }).then((response) => { + expect(response.body.errors[0].message).to.equal('mongo: no documents in result'); + }); + //delete probe - const deletePROMProbe_payload = { + const deletePROMProbe_payload = { operationName: "deleteProbe", variables: { projectID: projectID, - probeName: "exp3", + probeName: "exp3333", }, query: delete_PROMProbe, }; @@ -524,7 +591,7 @@ describe('testing kubernetes chaos probes', () => { variables: { projectID: projectID, request: { - name: "exp4", + name: "exp4444", description: "", tags: [], type: "k8sProbe", @@ -556,7 +623,7 @@ describe('testing kubernetes chaos probes', () => { }, }).then((response) => { expect(response.status).to.equal(200); - expect(response.body.data.addProbe.name).to.equal("exp4"); + expect(response.body.data.addProbe.name).to.equal("exp4444"); }); }); @@ -568,7 +635,7 @@ describe('testing kubernetes chaos probes', () => { variables: { projectID: projectID, request: { - name: "exp4", + name: "exp4444", description: "", tags: [], type: "k8sProbe", @@ -600,7 +667,7 @@ describe('testing kubernetes chaos probes', () => { }, }).then((response) => { expect(response.status).to.equal(200); - expect(response.body.errors[0].message).to.equal('write exception: write errors: [E11000 duplicate key error collection: litmus.chaosProbes index: name_1 dup key: { name: "exp4" }]'); + expect(response.body.errors[0].message).to.equal('write exception: write errors: [E11000 duplicate key error collection: litmus.chaosProbes index: name_1 dup key: { name: "exp4444" }]'); }); }); @@ -614,7 +681,7 @@ describe('testing kubernetes chaos probes', () => { variables: { projectID: projectID, request: { - name: "exp4", + name: "exp4444", description: "", tags: [], type: "k8sProbe", @@ -658,12 +725,34 @@ describe('testing kubernetes chaos probes', () => { it('delete chaos probe', () => { const accessToken = localStorage.getItem('accessToken'); const projectID = localStorage.getItem('projectID'); + + //negative test case for chaos probe + const delete_K8SProbe_payload1 = { + operationName: "deleteProbe", + variables: { + projectID: projectID, + probeName: "exp0", + }, + query: delete_k8sProbe, + }; + + cy.request({ + method: "POST", + url: "/api/query", + body: delete_K8SProbe_payload1, + headers: { + Authorization: `Bearer ${accessToken}`, + }, + }).then((response) => { + expect(response.body.errors[0].message).to.equal('mongo: no documents in result'); + }); + //delete probe const delete_K8SProbe_payload = { operationName: "deleteProbe", variables: { projectID: projectID, - probeName: "exp4", + probeName: "exp4444", }, query: delete_k8sProbe, }; diff --git a/chaoscenter/cypress/e2e/REST APIs/chaoshub.cy.js b/chaoscenter/cypress/e2e/REST APIs/chaoshub.cy.js new file mode 100644 index 000000000..05ea2680a --- /dev/null +++ b/chaoscenter/cypress/e2e/REST APIs/chaoshub.cy.js @@ -0,0 +1,193 @@ +import { add_hub,update_hub,delete_hub, list_hub } from "../../fixtures/chaoshub"; + +describe('testing chaoshub', () => { + + beforeEach(() => { + cy.restoreLocalStorage(); + cy.requestLogin(Cypress.env('username'),Cypress.env('password')); + }); + + afterEach(() => { + cy.saveLocalStorage(); + }); + + + it('testing ChaosHub functionality via REST APIs', () => { + const accessToken = localStorage.getItem('accessToken'); + const projectID = localStorage.getItem('projectID'); + + + //create chaosHub + const addPayload = { + operationName: 'addChaosHub', + variables: { + projectID: projectID, + request: { + name: 'testing', + repoBranch: 'master', + description: '', + tags: [], + authType: 'NONE', + isPrivate: false, + repoURL: 'https://github.com/litmuschaos/chaos-charts', + }, + }, + query: add_hub, + }; + + //create chaoshub + cy.request({ + method: 'POST', + url: '/api/query', + body: addPayload, + headers: { + Authorization: `Bearer ${accessToken}` + } + }).then((response) => { + expect(response.status).to.equal(200); + expect(response.body.data.addChaosHub.name).to.equal('testing'); + }); + + //get hub id + const listPayload = { + operationName: 'listChaosHub', + variables: { + projectID: projectID, + request: { filter: { chaosHubName: "" } } + }, + query: list_hub, + }; + + cy.request({ + method: 'POST', + url: '/api/query', + body: listPayload, + headers: { + Authorization: `Bearer ${accessToken}` + } + }).then((response) => { + expect(response.status).to.equal(200); + localStorage.setItem('hubID',response.body.data.listChaosHub[1].id); + }); + }); + + it('negative test case for chaoshub', () => { + const accessToken = localStorage.getItem('accessToken'); + const projectID = localStorage.getItem('projectID'); + + const addPayload = { + operationName: 'addChaosHub', + variables: { + projectID: projectID, + request: { + name: 'testing', + repoBranch: 'master', + description: '', + tags: [], + authType: 'NONE', + isPrivate: false, + repoURL: 'https://github.com/litmuschaos/chaos-charts', + }, + }, + query: add_hub, + }; + + //create chaoshub with same name + cy.request({ + method: 'POST', + url: '/api/query', + body: addPayload, + headers: { + Authorization: `Bearer ${accessToken}` + } + }).then((response) => { + expect(response.body.errors[0].message).to.equal('Name Already exists'); + }); + }); + + it('edit chaoshub', () => { + const accessToken = localStorage.getItem('accessToken'); + const projectID = localStorage.getItem('projectID'); + const hubID = localStorage.getItem('hubID'); + + const updatePayload = { + operationName: 'updateChaosHub', + variables: { + projectID: projectID, + request: { + id: hubID, + name: 'sample', + repoBranch: 'master', + description: '', + authType: 'NONE', + isPrivate: false, + repoURL: 'https://github.com/litmuschaos/chaos-charts', + sshPrivateKey: '', + sshPublicKey: '', + tags: [], + token: '' + } + }, + query: update_hub + }; + + cy.request({ + method: 'POST', + url: '/api/query', + body: updatePayload, + headers: { + Authorization: `Bearer ${accessToken}` + } + }).then((response) => { + expect(response.status).to.equal(200); + expect(response.body.data.updateChaosHub.name).to.equal("sample") + }); + }); + + it('delete chaoshub', () => { + const accessToken = localStorage.getItem('accessToken'); + const projectID = localStorage.getItem('projectID'); + const hubID = localStorage.getItem('hubID'); + + //Negative test case for delete chaosHub + const deletePayload1 = { + operationName: 'deleteChaosHub', + variables: { + hubID: '123', + projectID: projectID + }, + query: delete_hub + }; + cy.request({ + method: 'POST', + url: '/api/query', + body: deletePayload1, + headers: { + Authorization: `Bearer ${accessToken}` + } + }).then((response) => { + expect(response.body.errors[0].message).to.equal('mongo: no documents in result'); + }); + + + const deletePayload = { + operationName: 'deleteChaosHub', + variables: { + hubID: hubID, + projectID: projectID + }, + query: delete_hub + }; + cy.request({ + method: 'POST', + url: '/api/query', + body: deletePayload, + headers: { + Authorization: `Bearer ${accessToken}` + } + }).then((response) => { + expect(response.status).to.equal(200); + expect(response.body.data.deleteChaosHub).to.equal(true); + }); + }); +}) diff --git a/chaoscenter/cypress/e2e/REST APIs/chaosinfra.cy.js b/chaoscenter/cypress/e2e/REST APIs/chaosinfra.cy.js new file mode 100644 index 000000000..36935d4b9 --- /dev/null +++ b/chaoscenter/cypress/e2e/REST APIs/chaosinfra.cy.js @@ -0,0 +1,220 @@ +import { create_env, list_infra, register_infra, update_infra, delete_infra } from "../../fixtures/chaosinfra"; + +describe('testing chaosinfra via REST APIs', () => { + + beforeEach(() => { + cy.restoreLocalStorage(); + cy.requestLogin(Cypress.env('username'),Cypress.env('password')); + }); + + afterEach(() => { + cy.saveLocalStorage(); + }); + + + it('Create Environment and Chaos infra', () => { + const accessToken = localStorage.getItem('accessToken'); + const projectID = localStorage.getItem('projectID'); + + //create Environment + const createEnv_payload = { + operatioName: 'createEnvironment', + variables: { + projectID: projectID, + request: { + description: "", + environmentID: "exp99", + name: "exp99", + tags: [], + type: "NON_PROD" + } + }, + query: create_env + }; + + cy.request({ + method: 'POST', + url: '/api/query', + body: createEnv_payload, + headers: { + Authorization: `Bearer ${accessToken}` + } + }).then((response) => { + expect(response.status).to.equal(200); + expect(response.body.data.createEnvironment.name).to.equal("exp99"); + }); + + + //create Infra + const registerInfra_payload = { + operationName: 'registerInfra', + variables: { + projectID: projectID, + request: { + infraScope: 'cluster', + name: "exp99", + environmentID: "exp99", + description: '', + platformName: 'Kubernetes', + infraNamespace: 'litmus', + infraNsExists: false, + infraSaExists: false, + infrastructureType: 'Kubernetes', + serviceAccount: 'litmus', + skipSsl: false, + } + }, + query: register_infra + }; + + cy.request({ + method: 'POST', + url: '/api/query', + body: registerInfra_payload, + headers: { + Authorization: `Bearer ${accessToken}` + } + }).then((response) => { + expect(response.status).to.equal(200); + expect(response.body.data).to.have.property('registerInfra'); + }) + + + //get InfraID + const listInfra_payload = { + operationName: 'listInfras', + variables: { + projectID: projectID, + request: { environmentIDs: ["exp99"] }, + }, + query: list_infra + }; + + cy.request({ + method: 'POST', + url: '/api/query', + headers: { + Authorization: `Bearer ${accessToken}` + }, + body: listInfra_payload, + }).then((response) => { + expect(response.status).to.equal(200); + localStorage.setItem('infraID', response.body.data.listInfras.infras[0].infraID); + }); + }); + + + + it('Negative test case [Get error for creating environment with existing environment name', () => { + const accessToken = localStorage.getItem('accessToken'); + const projectID = localStorage.getItem('projectID'); + + //create Environment + const createEnv_payload = { + operatioName: 'createEnvironment', + variables: { + projectID: projectID, + request: { + description: "", + environmentID: "exp99", + name: "exp99", + tags: [], + type: "NON_PROD" + } + }, + query: create_env + }; + + //create environment with same name + cy.request({ + method: 'POST', + url: '/api/query', + body: createEnv_payload, + headers: { + Authorization: `Bearer ${accessToken}` + } + }).then((response) => { + expect(response.status).to.equal(200); + expect(response.body.errors[0].message).to.equal('write exception: write errors: [E11000 duplicate key error collection: litmus.environment index: environment_id_1 dup key: { environment_id: "exp99" }]'); + }); + }); + + it('Update chaos infra', () => { + const accessToken = localStorage.getItem('accessToken'); + const projectID = localStorage.getItem('projectID'); + const infraID = localStorage.getItem('infraID'); + + //update Infra + const updateInfra_payload = { + operationName: 'getInfraManifest', + variables: { + projectID: projectID, + infraID: infraID, + upgrade: true, + }, + query: update_infra, + }; + + cy.request({ + method: 'POST', + url: '/api/query', + headers: { + Authorization: `Bearer ${accessToken}` + }, + body: updateInfra_payload, + }).then((response) => { + expect(response.status).to.equal(200); + expect(response.body.data).to.have.property('getInfraManifest'); + }); + }); + + it('Disable chaos infra', () => { + const accessToken = localStorage.getItem('accessToken'); + const projectID = localStorage.getItem('projectID'); + const infraID = localStorage.getItem('infraID'); + + //negative test case for disable infra + const deleteInfra_payload1 = { + operationName: 'deleteInfra', + variables: { + projectID: projectID, + infraID: '123', + }, + query: delete_infra, + }; + + cy.request({ + method: 'POST', + url: '/api/query', + headers: { + Authorization: `Bearer ${accessToken}` + }, + body: deleteInfra_payload1, + }).then((response) => { + expect(response.body.errors[0].message).to.equal('mongo: no documents in result'); + }); + + + //disable Infra + const deleteInfra_payload = { + operationName: 'deleteInfra', + variables: { + projectID: projectID, + infraID: infraID, + }, + query: delete_infra, + }; + + cy.request({ + method: 'POST', + url: '/api/query', + headers: { + Authorization: `Bearer ${accessToken}` + }, + body: deleteInfra_payload, + }).then((response) => { + expect(response.status).to.equal(200); + expect(response.body.data.deleteInfra).to.equal("infra deleted successfully"); + }); + }); +}); diff --git a/chaoscenter/cypress/support/e2e.js b/chaoscenter/cypress/support/e2e.js index 83e15a5a6..5978a0ca1 100644 --- a/chaoscenter/cypress/support/e2e.js +++ b/chaoscenter/cypress/support/e2e.js @@ -1 +1,2 @@ -import './commands'; \ No newline at end of file +import './commands'; +import "cypress-localstorage-commands"; \ No newline at end of file diff --git a/chaoscenter/package-lock.json b/chaoscenter/package-lock.json index 8e981dc68..8e2b1bcb3 100644 --- a/chaoscenter/package-lock.json +++ b/chaoscenter/package-lock.json @@ -5,7 +5,8 @@ "packages": { "": { "devDependencies": { - "cypress": "^13.7.0" + "cypress": "^13.7.0", + "cypress-localstorage-commands": "^2.2.5" } }, "node_modules/@colors/colors": { @@ -585,6 +586,18 @@ "node": "^16.0.0 || ^18.0.0 || >=20.0.0" } }, + "node_modules/cypress-localstorage-commands": { + "version": "2.2.5", + "resolved": "https://registry.npmjs.org/cypress-localstorage-commands/-/cypress-localstorage-commands-2.2.5.tgz", + "integrity": "sha512-07zpwzWdY+uPi1NEHFhWQNylIJqRxR78Ile05L6WT8h1Gz0OaxgBSZRuzp+pqUni/3Pk4d2ieq/cSh++ZmujEA==", + "dev": true, + "engines": { + "node": ">=14.0.0" + }, + "peerDependencies": { + "cypress": ">=2.1.0" + } + }, "node_modules/dashdash": { "version": "1.14.1", "resolved": "https://registry.npmjs.org/dashdash/-/dashdash-1.14.1.tgz", diff --git a/chaoscenter/package.json b/chaoscenter/package.json index 9c7d7ef02..18371f8b7 100644 --- a/chaoscenter/package.json +++ b/chaoscenter/package.json @@ -1,5 +1,6 @@ { "devDependencies": { - "cypress": "^13.7.0" + "cypress": "^13.7.0", + "cypress-localstorage-commands": "^2.2.5" } }