From 719d8e2179eb69721a280538aa86a80e8e0e1dc4 Mon Sep 17 00:00:00 2001 From: elraphty Date: Sun, 21 Apr 2024 22:39:06 +0100 Subject: [PATCH] fixed cypress test not passing and added auth --- .gitignore | 3 ++- auth/auth.go | 4 +--- cypress/e2e/01_workspaces.cy.ts | 36 +++++++++++++++------------------ routes/person.go | 2 +- 4 files changed, 20 insertions(+), 25 deletions(-) diff --git a/.gitignore b/.gitignore index 2aa675c79..e3c2f4d2c 100644 --- a/.gitignore +++ b/.gitignore @@ -14,4 +14,5 @@ node_modules/ node_modules yarn.lock -frontend/app/coverage \ No newline at end of file +frontend/app/coverage +cypress/screenshots \ No newline at end of file diff --git a/auth/auth.go b/auth/auth.go index 8bfa5345f..7a80df7fc 100644 --- a/auth/auth.go +++ b/auth/auth.go @@ -170,10 +170,8 @@ func ConnectionCodeContext(next http.Handler) http.Handler { // CypressContext allows testing for cypress func CypressContext(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - token := r.Header.Get("token") - if IsFreePass() { - ctx := context.WithValue(r.Context(), ContextKey, token) + ctx := context.WithValue(r.Context(), ContextKey, "") next.ServeHTTP(w, r.WithContext(ctx)) } else { fmt.Println("Endpoint is for testing only : test endpoint") diff --git a/cypress/e2e/01_workspaces.cy.ts b/cypress/e2e/01_workspaces.cy.ts index 4fe8982c2..08861aaa6 100644 --- a/cypress/e2e/01_workspaces.cy.ts +++ b/cypress/e2e/01_workspaces.cy.ts @@ -3,27 +3,26 @@ import { User, HostName, Workspaces } from '../support/objects/objects'; describe('Create Workspaces', () => { it('passes', () => { - cy.upsertlogin(User).then(value => - { + cy.upsertlogin(User).then(value => { //Create 3 Workspaces cy.request({ method: 'POST', url: `${HostName}/workspaces/`, - headers: { 'x-jwt': `${ value }` }, + headers: { 'x-jwt': `${value}` }, body: Workspaces[0] }).its('body').should('have.property', 'name', Workspaces[0].name.trim()); cy.request({ method: 'POST', url: `${HostName}/workspaces/`, - headers: { 'x-jwt': `${ value }` }, + headers: { 'x-jwt': `${value}` }, body: Workspaces[1] }); cy.request({ method: 'POST', url: `${HostName}/workspaces/`, - headers: { 'x-jwt': `${ value }` }, + headers: { 'x-jwt': `${value}` }, body: Workspaces[2] }); }) @@ -32,17 +31,16 @@ describe('Create Workspaces', () => { describe('Edit Mission', () => { it('passes', () => { - cy.upsertlogin(User).then(value => - { + cy.upsertlogin(User).then(value => { //Create 3 Workspaces cy.request({ method: 'POST', url: `${HostName}/workspaces/mission`, - headers: { 'x-jwt': `${ value }` }, - body: { + headers: { 'x-jwt': `${value}` }, + body: { uuid: Workspaces[0].uuid, mission: 'This is a sample mission for workspace' - } + } }).then((resp) => { expect(resp.status).to.eq(200) }) @@ -53,17 +51,16 @@ describe('Edit Mission', () => { describe('Edit Tactics', () => { it('passes', () => { - cy.upsertlogin(User).then(value => - { + cy.upsertlogin(User).then(value => { //Create 3 Workspaces cy.request({ method: 'POST', url: `${HostName}/workspaces/tactics`, - headers: { 'x-jwt': `${ value }` }, - body: { + headers: { 'x-jwt': `${value}` }, + body: { uuid: Workspaces[0].uuid, mission: 'This is a sample tactics and objectives for workspace' - } + } }).then((resp) => { expect(resp.status).to.eq(200) }) @@ -74,17 +71,16 @@ describe('Edit Tactics', () => { describe('Edit Schematics Url', () => { it('passes', () => { - cy.upsertlogin(User).then(value => - { + cy.upsertlogin(User).then(value => { //Create 3 Workspaces cy.request({ method: 'POST', url: `${HostName}/workspaces/schematicurl`, - headers: { 'x-jwt': `${ value }` }, - body: { + headers: { 'x-jwt': `${value}` }, + body: { uuid: Workspaces[0].uuid, mission: 'This is a sample schematic url for workspaces' - } + } }).then((resp) => { expect(resp.status).to.eq(200) }) diff --git a/routes/person.go b/routes/person.go index 4b9a15ec3..f60fb6f21 100644 --- a/routes/person.go +++ b/routes/person.go @@ -20,7 +20,7 @@ func PersonRoutes() chi.Router { r.Group(func(r chi.Router) { r.Use(auth.CypressContext) - r.Post("/test", peopleHandler.UpsertLogin) + r.Post("/upsertlogin", peopleHandler.UpsertLogin) }) r.Group(func(r chi.Router) {