Skip to content

Commit

Permalink
Merge pull request #1042 from bcgov/dev
Browse files Browse the repository at this point in the history
release - two-tiered-hidden for API Directory
  • Loading branch information
rustyjux authored Apr 16, 2024
2 parents e61cbee + eb6e63d commit a9958fd
Show file tree
Hide file tree
Showing 13 changed files with 460 additions and 27 deletions.
22 changes: 13 additions & 9 deletions e2e/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,15 @@ Install Cypress on your local machine by following [these instructions](https://
- Clone the API Service Portal repository
- Run `./e2e $ npm i` to install all the dependencies

### Test data dependencies

Many tests cannot be run independently because they depend on state established by other tests. These dependencies are [documented](test-data-dependencies.md) to assist in running tests selectively.

### Running Cypress Locally

- `./e2e/cypress.json` contains the web app config. Update the file to use local or dev version of the portal for executing the tests
- `./e2e/cypress.config.ts` contains the web app config. Update the file to use local or dev version of the portal for executing the tests

- Recommendation is to use local version of portal. Use `docker-compose` to create local development environment
- Recommendation is to use local version of portal. Use `docker compose` to create local development environment

#### Cypress Test Runner

Expand All @@ -52,14 +56,14 @@ Install Cypress on your local machine by following [these instructions](https://

### Docker Compose

- Run `docker-compose up` to spin up a local development environment, which includes Cypress as one of the services and it executes all the tests and generates the HTML report
- Run `docker-compose down` to tear down the environment
- Run `docker compose up` to spin up a local development environment, which includes Cypress as one of the services and it executes all the tests and generates the HTML report
- Run `docker compose down` to tear down the environment

#### GitHub Actions

- Any new commit pushed to `util/*automation*` branch triggers job (`.github/workflows/aps-cypress-e2e.yaml`) and it spawns all the services including cypress to execute the test suite
- Any new commit pushed to a `cypress*` branch or `test`, triggers the job (`.github/workflows/aps-cypress-e2e.yaml`) and it spawns all the services including Cypress to execute the test suite

- The test results would be uploaded to `https://www.cypress.io/dashboard/`
- The test results would be uploaded to `https://www.cypress.io/dashboard/`, as well as attached as an artifact on the GitHub Action run.

## 3. Cypress on Windows

Expand All @@ -85,7 +89,7 @@ WSL 2 or your local machine are prefaced with `WSL` and `LM` respectively in the

### `WSL`: Build and Run Dev Environment

- Inside the `api-services-portal` directory, build and run the application by running `docker-compose up` at the project root.
- Inside the `api-services-portal` directory, build and run the application by running `docker compose up` at the project root.

### `LM`: Install E2E Testing Dependencies

Expand All @@ -97,13 +101,13 @@ WSL 2 or your local machine are prefaced with `WSL` and `LM` respectively in the

## 4. Creating Tests

After you run `npm run cy:open`, the Cypress console will open. Before continuing, ensure the `Electron` browser is selected from the drop-down list of available browsers (top-right corner of the Cypress test runner).
After you run `npm run cy:open`, the Cypress console will open. Before continuing, ensure the `Edge` browser is selected from the drop-down list of available browsers (top-right corner of the Cypress test runner).

Each test file defined in the `./e2e/cypress/tests` directory will be visible. Click on a test in order to run all test cases in that file. A new browser window will open and you will see your tests executed sequentially.

### Test File Naming Convention and Location

- Test files follow this naming convention: `<num>-<test-name>.spec.ts`. (e.g., `01-create-api.spec.ts`)
- Test files follow this naming convention: `<num>-<test-name>.cy.ts`. (e.g., `01-create-api.cy.ts`)
- Store the test files in the `./e2e/cypress/tests` directory.

### Test File Structure
Expand Down
11 changes: 10 additions & 1 deletion e2e/cypress/fixtures/apiowner.json
Original file line number Diff line number Diff line change
Expand Up @@ -782,5 +782,14 @@
},
"activityAt": "2022-09-20T20:37:30.570Z"
}
]
],
"twoTieredHidden": {
"product": {
"name": "Two Tiered Hidden Product",
"serviceName": "two-tier-service",
"environment": {
"name": "dev"
}
}
}
}
3 changes: 3 additions & 0 deletions e2e/cypress/fixtures/common-testdata.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,8 @@
"apiTest": {
"namespace": "gw-c3f31",
"delete_namespace": "testplatform"
},
"twoTieredHidden": {
"namespace": "two-tier-hidden"
}
}
79 changes: 79 additions & 0 deletions e2e/cypress/fixtures/tthidden-jwt.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
kind: Namespace
name: two-tier-hidden
displayName: two-tier-hidden Display Name
---
kind: GatewayService
name: two-tier-service-dev
tags: [ns.two-tier-hidden]
host: httpbin.org
port: 443
protocol: https
retries: 0
routes:
- name: two-tier-service-dev
tags: [ns.two-tier-hidden]
hosts:
- two-tier-service.dev.api.gov.bc.ca
methods:
- GET
strip_path: false
https_redirect_status_code: 426
path_handling: v0
request_buffering: true
response_buffering: true
plugins:
- name: jwt-keycloak
tags: [ns.two-tier-hidden, aps.two-tiered-hidden]
enabled: true
config:
allowed_iss:
- https://dev.loginproxy.gov.bc.ca/auth/realms/apigw
allowed_aud: ap-two-tier-hidden-default-dev
run_on_preflight: true
iss_key_grace_period: 10
maximum_expiration: 0
algorithm: RS256
claims_to_verify:
- exp
uri_param_names:
- jwt
cookie_names: []
scope: null
roles: null
realm_roles: null
client_roles: null
anonymous: ce26955a-cf08-4907-9427-12d01c8bd94c
consumer_match: true
consumer_match_claim: azp
consumer_match_claim_custom_id: true
consumer_match_ignore_not_found: false
- name: request-transformer
tags: [ns.two-tier-hidden]
enabled: true
config:
http_method: null
---
kind: DraftDataset
name: two-tier-service-dataset
title: Two-tier-service
organization: ministry-of-health
organizationUnit: public-health
notes: Some information about the two-tier-service service
tags: [two-tier-service, openapi]
license_title: Access Only
view_audience: Government
security_class: LOW-PUBLIC
record_publish_date: '2021-05-27'
---
kind: Product
name: Two Tiered Hidden Product
appId: 'LFH78YU956RE'
dataset: two-tier-service-dataset
environments:
- name: dev
active: true
approval: false
flow: kong-api-key-acl
appId: '506CB7CF'
services: [two-tier-service-dev]

62 changes: 62 additions & 0 deletions e2e/cypress/fixtures/tthidden-key-auth.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
kind: Namespace
name: two-tier-hidden
displayName: two-tier-hidden Display Name
---
kind: GatewayService
name: two-tier-service-dev
tags: [ns.two-tier-hidden]
host: httpbin.org
port: 443
protocol: https
retries: 0
routes:
- name: two-tier-service-dev
tags: [ns.two-tier-hidden]
hosts:
- two-tier-service.dev.api.gov.bc.ca
methods:
- GET
strip_path: false
https_redirect_status_code: 426
path_handling: v0
request_buffering: true
response_buffering: true
plugins:
- name: key-auth
tags: [ ns.two-tier-hidden, aps.two-tiered-hidden ]
protocols: [ http, https ]
config:
key_names: ["X-API-KEY"]
run_on_preflight: true
hide_credentials: true
key_in_body: false
anonymous: ce26955a-cf08-4907-9427-12d01c8bd94c
- name: acl
tags: [ ns.two-tier-hidden ]
config:
hide_groups_header: true
allow: [ "406CB7CF" ]
---
kind: DraftDataset
name: two-tier-service-dataset
title: Two-tier-service
organization: ministry-of-health
organizationUnit: public-health
notes: Some information about the two-tier-service service
tags: [two-tier-service, openapi]
license_title: Access Only
view_audience: Government
security_class: LOW-PUBLIC
record_publish_date: '2021-05-27'
---
kind: Product
name: Two Tiered Hidden Product
appId: 'LFH78YU956RE'
dataset: two-tier-service-dataset
environments:
- name: dev
active: true
approval: false
flow: kong-api-key-acl
appId: '506CB7CF'
services: [two-tier-service-dev]
11 changes: 11 additions & 0 deletions e2e/cypress/pageObjects/apiDirectory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,17 @@ class ApiDirectoryPage {
cy.get(ele).should('exist')
}

checkTwoTieredIcon(productName: string) {
const pname: string = productName.toLowerCase().replaceAll(' ', '-')
var ele: string = `[data-testid=two-tiered-icon-${pname}]`
cy.get(ele).should('exist')
}

checkTwoTieredHiddenButton() {
var ele: string = '[data-testid=request-access-button-two-tiered-hidden]'
cy.get(ele).should('exist')
}

addOrganizationAndOrgUnit(product: any) {
cy.contains('button', 'Add Organization').click({ force: true })
cy.get(this.orgDropDown).select(product.orgName)
Expand Down
134 changes: 134 additions & 0 deletions e2e/cypress/tests/09-update-product-env/09-two-tiered-hidden.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
import ApiDirectoryPage from '../../pageObjects/apiDirectory'
import HomePage from '../../pageObjects/home'
import LoginPage from '../../pageObjects/login'
import Products from '../../pageObjects/products'

describe('Verify Two Tiered Hidden', () => {
const login = new LoginPage()
const apiDir = new ApiDirectoryPage()
var nameSpace: string
let userSession: any
const home = new HomePage()
const pd = new Products()

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

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

it('authenticates Janis (api owner) to get the user session token', () => {
cy.get('@common-testdata').then(({ twoTieredHidden }: any) => {
cy.getUserSessionTokenValue(twoTieredHidden.namespace, false).then((value) => {
userSession = value
})
})
})

it('Check gwa config command to set environment', () => {
var cleanedUrl = Cypress.env('BASE_URL').replace(/^http?:\/\//i, '')
cy.executeCliCommand('gwa config set --host ' + cleanedUrl + ' --scheme http').then(
(response) => {
expect(response.stdout).to.contain('Config settings saved')
}
)
})

it('Check gwa config command to set token', () => {
cy.executeCliCommand('gwa config set --token ' + userSession).then((response) => {
expect(response.stdout).to.contain('Config settings saved')
})
})

it('create namespace with cli', () => {
cy.get('@common-testdata').then(({ twoTieredHidden }: any) => {
cy.executeCliCommand(
'gwa namespace create --name ' +
twoTieredHidden.namespace +
' --description="Two Tiered Hidden"'
).then((response) => {
expect(response.stdout).to.contain(twoTieredHidden.namespace)
})
})
})

it('Upload config for key-auth', () => {
cy.executeCliCommand('gwa apply -i ./cypress/fixtures/tthidden-key-auth.yml').then((response) => {
expect(response.stdout).to.contain('Gateway Services published');
})
})

it('Activates the namespace', () => {
cy.getUserSession().then(() => {
cy.get('@common-testdata').then(({ twoTieredHidden }: any) => {
nameSpace = twoTieredHidden.namespace
home.useNamespace(twoTieredHidden.namespace)
cy.get('@login').then(function (xhr: any) {
userSession = xhr.response.headers['x-auth-request-access-token']
})
})
})
})

it('Verify that product is formatted correctly in public directory', () => {
cy.visit(apiDir.path)
cy.get('@apiowner').then(({ twoTieredHidden }: any) => {
let product = twoTieredHidden.product
apiDir.selectProduct(product.serviceName)
apiDir.checkProductIcon(product.name, 'RiEarthFill')
apiDir.checkTwoTieredHiddenButton()
})
})

it('Verify that product is formatted correctly in your products page', () => {
cy.visit(apiDir.path)
apiDir.navigateToYourProduct()
cy.get('@apiowner').then(({ twoTieredHidden }: any) => {
let product = twoTieredHidden.product
apiDir.selectProduct(product.serviceName)
apiDir.checkProductIcon(product.name, 'RiEarthFill')
apiDir.checkTwoTieredHiddenButton()
})
})

it('Upload config for jwt-keycloak', () => {
cy.executeCliCommand('gwa apply -i ./cypress/fixtures/tthidden-jwt.yml').then((response) => {
expect(response.stdout).to.contain('Gateway Services published');
})
})

it('Verify that product is formatted correctly in public directory', () => {
cy.visit(apiDir.path)
cy.get('@apiowner').then(({ twoTieredHidden }: any) => {
let product = twoTieredHidden.product
apiDir.selectProduct(product.serviceName)
apiDir.checkProductIcon(product.name, 'RiEarthFill')
apiDir.checkTwoTieredHiddenButton()
})
})

it('Verify that product is formatted correctly in your products page', () => {
cy.visit(apiDir.path)
apiDir.navigateToYourProduct()
cy.get('@apiowner').then(({ twoTieredHidden }: any) => {
let product = twoTieredHidden.product
apiDir.selectProduct(product.serviceName)
apiDir.checkProductIcon(product.name, 'RiEarthFill')
apiDir.checkTwoTieredHiddenButton()
})
})

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

})
Loading

0 comments on commit a9958fd

Please sign in to comment.