Skip to content

Commit

Permalink
Merge pull request #1130 from bcgov/cypress/ns-to-gw-new-features
Browse files Browse the repository at this point in the history
Cypress/ns to gw new features
  • Loading branch information
rustyjux authored Aug 14, 2024
2 parents df8537b + ff77d4a commit 689928a
Show file tree
Hide file tree
Showing 27 changed files with 616 additions and 64 deletions.
10 changes: 9 additions & 1 deletion .github/workflows/aps-cypress-e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,15 @@ jobs:
run: |
FAILURE_COUNT=$(cat ${{ github.workspace }}/e2e/results/bcgov-aps-e2e-report.json | jq '.stats.failures')
if [[ "$FAILURE_COUNT" -gt 0 ]]; then
FAILED_TESTS=$(jq -r '.results[] | {file: .file, suites: .suites[]} | .suites as $suite | {file: .file, failed_tests: ($suite.tests[] | select(.fail == true) | {title})} | select(.failed_tests != null) | "- " + (.file | split("/") | .[2:] | join("/")) + " - " + .failed_tests.title' ${{ github.workspace }}/e2e/results/bcgov-aps-e2e-report.json)
FAILED_TESTS=$(jq -r '
.results[] |
(.file | split("/") | .[2:] | join("/")) as $file |
.. |
.tests? // empty |
.[] |
select(.fail == true) |
"- " + $file + " - " + .title
' ${{ github.workspace }}/e2e/results/bcgov-aps-e2e-report.json)
STATS=$(cat ${{ github.workspace }}/e2e/results/bcgov-aps-e2e-report.json | jq -r '.stats | to_entries | map("\(.key)\t\(.value)") | .[]' | column -t)
echo -e "Stats: $STATS\n\nFailed Tests:\n$FAILED_TESTS\n\nRun Link: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" > msg
export MSG=$(cat msg)
Expand Down
1 change: 1 addition & 0 deletions e2e/cypress.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export default defineConfig({
'./cypress/tests/17-*/*.ts',
'./cypress/tests/18-*/*.ts',
'./cypress/tests/19-*/*.ts',
'./cypress/tests/20-*/*.ts',
]
return config
},
Expand Down
2 changes: 1 addition & 1 deletion e2e/cypress/fixtures/api.json
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@
"owner": "janis@idir"
},
"shared_IDP_update_body": {
"name": "Sample Shared IdP",
"name": "Sample Shared IdP updated",
"description": "A Shared IdP for Teams to use",
"flow": "client-credentials",
"clientAuthenticator": "client-secret",
Expand Down
23 changes: 22 additions & 1 deletion e2e/cypress/fixtures/common-testdata.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"namespace": "gw-16a3a"
},
"orgAssignment": {
"namespace": "gw-f016e"
"namespace": "gw-f6a4d"
},
"orgAssignmentMultipleAdmin": {
"namespace": "orgassignment1"
Expand Down Expand Up @@ -81,5 +81,26 @@
},
"twoTieredHidden": {
"namespace": "two-tier-hidden"
},
"serviceAvailability": {
"namespace": "service-avail"
},
"myGateways": {
"namespace1": {
"gatewayId": "gw-apple",
"displayName": "Apple"
},
"namespace2": {
"gatewayId": "gw-banana",
"displayName": "Banana"
},
"namespace3": {
"gatewayId": "gw-date",
"displayName": "Cherry"
},
"namespace4": {
"gatewayId": "gw-cherry",
"displayName": "Cherry"
}
}
}
19 changes: 19 additions & 0 deletions e2e/cypress/fixtures/service-availability.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
kind: GatewayService
name: taken-service-name
host: httpbin.org
tags: [ns.service-avail]
port: 446
protocol: https
retries: 0
routes:
- name: taken-service-name
tags: [ns.service-avail]
hosts:
- taken-service-name.api.gov.bc.ca
paths:
- /
methods:
- GET
strip_path: false
https_redirect_status_code: 426
path_handling: v0
1 change: 1 addition & 0 deletions e2e/cypress/pageObjects/apiDirectory.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

class ApiDirectoryPage {
path: string = '/devportal/api-directory'
yourProductsPath: string = '/devportal/api-directory/your-products'
rqstAccessBtn: string = '[data-testid=request-access-button]'
appSelect: string = '[data-testid=access-application-select]'
additionalNotes: string = '[data-testid=access-rqst-add-notes-text]'
Expand Down
3 changes: 3 additions & 0 deletions e2e/cypress/pageObjects/namespace.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
class NameSpacePage {
path: string = '/manager/gateways'
listPath: string = 'manager/gateways/list'
detailPath: string = '/manager/gateways/detail'
getStartedPath: string = '/manager/gateways/get-started'
listFilterSelect: string = '[data-testid="ns-filter-select"]'
gatewayServiceLink: string = '[data-testid="ns-manage-link-Gateway Services"]'
productsLink: string = '[data-testid="ns-manage-link-Gateway Services"]'
consumersLink: string = '[data-testid="ns-manage-link-Consumers"]'
Expand Down
30 changes: 20 additions & 10 deletions e2e/cypress/support/auth-commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,16 @@ Cypress.Commands.add('createGateway', (gatewayid?: string, displayname?: string)
)
})

Cypress.Commands.add('deleteGatewayCli', (gatewayid: string, force: boolean = false) => {
cy.executeCliCommand('gwa config set gateway ' + gatewayid).then(() => {
cy.executeCliCommand(`gwa gateway destroy ${force ? '--force' : ''}`).then(
(response) => {
console.log(response)
expect(response.stdout).to.contain('Gateway destroyed: ' + gatewayid)
})
})
})

Cypress.Commands.add('activateGateway', (gatewayId: string, checkNoNamespace: boolean = false) => {
const getAllNsQuery = `
query GetNamespaces {
Expand Down Expand Up @@ -209,7 +219,7 @@ Cypress.Commands.add('resetCredential', (accessRole: string) => {

Cypress.Commands.add(
'getUserSessionTokenValue',
(namespace: string, isNamespaceSelected?: boolean) => {
(namespace: string = 'ns', isNamespaceSelected?: boolean) => {
const login = new LoginPage()
const home = new HomePage()
const na = new NamespaceAccessPage()
Expand All @@ -219,16 +229,16 @@ Cypress.Commands.add(
cy.fixture('apiowner').as('apiowner')
cy.preserveCookies()
cy.visit(login.path)
cy.interceptUserSession().then(() => {
cy.get('@apiowner').then(({ user }: any) => {
cy.login(user.credentials.username, user.credentials.password)
cy.log('Logged in!')
// cy.activateGateway(apiTest.namespace)
if (isNamespaceSelected || undefined) {
cy.activateGateway(namespace)
}
cy.get('@apiowner').then(({ user }: any) => {
cy.login(user.credentials.username, user.credentials.password)
cy.log('Logged in!')
// cy.activateGateway(apiTest.namespace)
if (isNamespaceSelected || undefined) {
cy.activateGateway(namespace)
}
cy.getUserSession().then(() => {
cy.get('@login').then(function (xhr: any) {
userSession = xhr.response.headers['x-auth-request-access-token']
userSession = xhr.headers['x-auth-request-access-token']
return userSession
})
})
Expand Down
2 changes: 2 additions & 0 deletions e2e/cypress/support/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ declare namespace Cypress {
displayname?: string,
): Chainable<any>

deleteGatewayCli(gatewayid: string, force: boolean): Chainable<any>

activateGateway(
gatewayId: string,
checkNoNamespace?: boolean
Expand Down
74 changes: 74 additions & 0 deletions e2e/cypress/tests/01-api-key/00-get-started.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import LoginPage from '../../pageObjects/login'
import NameSpacePage from '../../pageObjects/namespace'
const cleanedUrl = Cypress.env('BASE_URL').replace(/^http?:\/\//i, "");

// Elements of this page must be checked when there are no Gateways, so this test comes first of all
describe('Gateway Get Started page', () => {
const login = new LoginPage()
const ns = new NameSpacePage()
let userSession: any
let namespace: string

before(() => {
cy.visit('/')
cy.deleteAllCookies()
cy.reload(true)
cy.resetState()
})

beforeEach(() => {
cy.preserveCookies()
cy.fixture('apiowner').as('apiowner')
cy.fixture('common-testdata').as('common-testdata')
})

it('authenticates Janis (api owner) to get the user session token', () => {
cy.getUserSessionTokenValue('', false).then((value) => {
userSession = value
})
})

it('Set token with gwa config command', () => {
cy.exec('gwa config set --token ' + userSession, { timeout: 3000, failOnNonZeroExit: false }).then((response) => {
expect(response.stdout).to.contain("Config settings saved")
});
})

it('Set environment with gwa config command', () => {
cy.executeCliCommand('gwa config set --host ' + cleanedUrl + ' --scheme http').then((response) => {
expect(response.stdout).to.contain("Config settings saved")
});
})

it('Check for redirect to Get Started page', () => {
cy.visit(ns.path)
cy.url().should('include', '/manager/gateways/get-started')
})

it('Check for box that says "No gateways"', () => {
cy.get('[data-testid="no-gateways"]').should('exist')
})

it('Create a namespace', () => {
cy.createGateway().then((response) => {
namespace = response.gatewayId
})
})

it('Check for banner that says "You have gateways"', () => {
cy.reload()
cy.get('[data-testid="no-gateways"]').should('not.exist')
cy.get('[data-testid="you-have-gateways-banner"]').should('exist')
})

it('Cleanup: delete namespace', () => {
cy.deleteGatewayCli(namespace, true)
})

after(() => {
cy.logout()
cy.clearLocalStorage({ log: true })
cy.deleteAllCookies()
})

})
7 changes: 0 additions & 7 deletions e2e/cypress/tests/01-api-key/01-create-api.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,6 @@ describe('Create API Spec', () => {
})
})

// TODO: Update this test to use gwa cli (if not covered in other tests)
// it('Verify for invalid namespace name', () => {
// cy.get('@apiowner').then(({ invalid_namespace }: any) => {
// home.validateNamespaceName(invalid_namespace)
// })
// })

it('creates a new service account', () => {
cy.visit(sa.path)
cy.get('@apiowner').then(({ serviceAccount }: any) => {
Expand Down
8 changes: 0 additions & 8 deletions e2e/cypress/tests/09-update-product-env/06-shared-idp.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,6 @@ describe('Update IDP issuer for shared IDP profile', () => {
})
})

it('Prepare the Request Specification for the API', () => {
cy.get('@api').then(({ authorizationProfiles }: any) => {
cy.setHeaders(authorizationProfiles.headers)
cy.setAuthorizationToken(userSession)
cy.setRequestBody(authorizationProfiles.shared_IDP_body)
})
})

it('Prepare the Request Specification for the API', () => {
cy.get('@api').then(({ authorizationProfiles }: any) => {
cy.setHeaders(authorizationProfiles.headers)
Expand Down
44 changes: 38 additions & 6 deletions e2e/cypress/tests/10-clear-resources/05-delete-resources.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@ import NameSpacePage from '../../pageObjects/namespace'
import Products from '../../pageObjects/products'
import ServiceAccountsPage from '../../pageObjects/serviceAccounts'

const cleanedUrl = Cypress.env('BASE_URL').replace(/^http?:\/\//i, "");

describe('Delete created resources', () => {
const login = new LoginPage()
const home = new HomePage()
const sa = new ServiceAccountsPage()
const pd = new Products()
const ns = new NameSpacePage
let flag: boolean
let userSession: any

before(() => {
cy.visit('/')
Expand All @@ -30,6 +33,9 @@ describe('Delete created resources', () => {
cy.get('@common-testdata').then(({ deleteResources }: any) => {
cy.login(user.credentials.username, user.credentials.password)
cy.activateGateway(deleteResources.namespace);
cy.getUserSessionTokenValue(deleteResources.namespace, false).then((value) => {
userSession = value
})
})
})
})
Expand Down Expand Up @@ -57,11 +63,21 @@ describe('Delete created resources', () => {
sa.deleteAllServiceAccounts()
})

it('Delete Namespace', () => {
it('Set token with gwa config command', () => {
cy.exec('gwa config set --token ' + userSession, { timeout: 3000, failOnNonZeroExit: false }).then((response) => {
expect(response.stdout).to.contain("Config settings saved")
});
})

it('Set environment with gwa config command', () => {
cy.executeCliCommand('gwa config set --host ' + cleanedUrl + ' --scheme http').then((response) => {
expect(response.stdout).to.contain("Config settings saved")
});
})

it('Delete Namespace (CLI)', () => {
cy.get('@common-testdata').then(({ deleteResources }: any) => {
cy.visit(ns.detailPath)
ns.deleteNamespace(deleteResources.namespace)
cy.wait(10000)
cy.deleteGatewayCli(deleteResources.namespace, true)
});
});

Expand All @@ -71,14 +87,30 @@ describe('Delete created resources', () => {
cy.wrap(null).then(() => {
return cy.getGateways();
}).then((result) => {
console.log(result);
const namespaceNames = result.map((ns: { name: any }) => ns.name);
console.log(namespaceNames);
expect(namespaceNames).to.not.include(deleteResources.namespace);
});
});
});

it('Verify delete namespace works from the UI', () => {
cy.createGateway().then((response) => {
const namespace = response.gatewayId
cy.log('New namespace created: ' + namespace)
cy.activateGateway(namespace);
cy.visit(ns.detailPath)
ns.deleteNamespace(namespace)

cy.visit('/')
cy.wrap(null).then(() => {
return cy.getGateways();
}).then((result) => {
const namespaceNames = result.map((ns: { name: any }) => ns.name);
expect(namespaceNames).to.not.include(namespace);
});
});
});

after(() => {
cy.logout()

Expand Down
Loading

0 comments on commit 689928a

Please sign in to comment.