Skip to content

Commit

Permalink
Remove Limit section in API directory for LOC (#1009)
Browse files Browse the repository at this point in the history
* Remove Limit section in API directory for LOC

* Added functionality for two-tiered-hidden tag

* Added aps. to front of tag

* Added Cypress tests for two-tiered-hidden scenario

* fix ref to keycloak for docker compose

* Update e2e/cypress/tests/09-update-product-env/09-two-tiered-hidden.cy.ts

Co-authored-by: Russell Vinegar <38586679+rustyjux@users.noreply.github.com>

* fix test errors, dataset as part of Product yaml, positive assertion for request access button

* Bool for two-tiered-hidden button tag

---------

Co-authored-by: Russell Vinegar <38586679+rustyjux@users.noreply.github.com>
  • Loading branch information
Elson9 and rustyjux committed Apr 15, 2024
1 parent 306844e commit eb6e63d
Show file tree
Hide file tree
Showing 12 changed files with 341 additions and 21 deletions.
6 changes: 3 additions & 3 deletions e2e/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ Many tests cannot be run independently because they depend on state established

### 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

Expand Down Expand Up @@ -89,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 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 eb6e63d

Please sign in to comment.