Skip to content

Commit

Permalink
Merge pull request #704 from bcgov/dev
Browse files Browse the repository at this point in the history
Cypress automation updates
  • Loading branch information
ikethecoder committed Jan 10, 2023
2 parents c1b20be + e8cd83e commit d89cd92
Show file tree
Hide file tree
Showing 14 changed files with 276 additions and 44 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/aps-cypress-e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ jobs:
docker build -t gwa-api:e2e .
- name: Checkout Portal
uses: actions/checkout@v2
- name: Build Docker Images
run: |
docker-compose build
- name: Spin up API Services Portal and Run E2E Tests
run: |
export CY_EXECUTION_ENV=${{ env.EXECUTION_ENV }}
Expand Down
13 changes: 7 additions & 6 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -143,32 +143,33 @@ services:
networks:
- aps-net
kong-migrations:
image: kong:latest
image: kong:kong-local
command: kong migrations bootstrap
depends_on:
- kong-db
environment: *common-variables
networks:
- aps-net
restart: on-failure
build:
context: local/kong
dockerfile: Dockerfile
kong-migrations-up:
image: kong:latest
image: kong:kong-local
command: kong migrations up && kong migrations finish
depends_on:
- kong-db
- kong-migrations
environment: *common-variables
networks:
- aps-net
restart: on-failure
kong:
image: kong:latest
image: kong:kong-local
container_name: kong
depends_on:
- kong-migrations
- kong-migrations-up
build:
context: local/kong
dockerfile: Dockerfile
environment:
<<: *common-variables
KONG_ADMIN_ACCESS_LOG: /dev/stdout
Expand Down
2 changes: 1 addition & 1 deletion e2e/cypress/fixtures/developer.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
"clientIdSecret_invalid": {
"product": {
"name": "Client Credentials Test Product",
"environment": "other"
"environment": "sandbox"
},
"application": {
"name": "Client ID and Secret App for invalid auth",
Expand Down
23 changes: 12 additions & 11 deletions e2e/cypress/pageObjects/products.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,18 +187,19 @@ class Products {

updateDatasetNameToCatelogue(productName: string, env: string) {
this.editProduct(productName)
const search_input: string = productName.slice(0, 1)
cy.get(this.catelogueDropDown).type(search_input + '{enter}', {
const search_input: string = productName.slice(0, 3)
cy.get(this.catelogueDropDown).type(search_input + '{downArrow}' + '{enter}', {
force: true,
})
cy.get(this.catelogueDropDownMenu)
.find('div')
.find('p')
.each(($e1, index, $list) => {
if ($e1.text() === productName) {
cy.wrap($e1).click()
}
})
delay: 500
}, )
// cy.get(this.catelogueDropDownMenu)
// .find('div')
// .find('p')
// .each(($e1, index, $list) => {
// if ($e1.text() === productName) {
// cy.wrap($e1).click()
// }
// })
this.updateProduct()
}

Expand Down
25 changes: 10 additions & 15 deletions e2e/cypress/tests/10-activity-feed/02-activity-feed-failure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,22 +43,17 @@ describe('Make the access request for invalid profile', () => {
})
})

it('Creates an access request', (done) => {
cy.visit(apiDir.path)
cy.get('@developer').then(({ clientCredentials, accessRequest }: any) => {
let product = clientCredentials.clientIdSecret_invalid.product
let app = clientCredentials.clientIdSecret_invalid.application
// it('Creates an access request', (done) => {
// cy.visit(apiDir.path)
// cy.get('@developer').then(({ clientCredentials, accessRequest }: any) => {
// let product = clientCredentials.clientIdSecret_invalid.product
// let app = clientCredentials.clientIdSecret_invalid.application

apiDir.createAccessRequest(product, app, accessRequest)
ma.clickOnGenerateSecretButton()
ma.closeRequestAccessPopUp()
cy.on('uncaught:exception', (err, runnable) => {
expect(err.message).to.include('The following error originated from your application code, not from Cypress')
done()
return false
})
})
})
// apiDir.createAccessRequest(product, app, accessRequest)
// ma.clickOnGenerateSecretButton()
// // ma.closeRequestAccessPopUp()
// })
// })
})

describe('Create API, Product, and Authorization Profiles; Apply Auth Profiles to Product Environments', () => {
Expand Down
36 changes: 29 additions & 7 deletions local/kong/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
FROM kong:2.5.0
FROM kong:2.8.3

USER root

RUN apk add git
RUN apk add git ethtool strace

ARG PLUGIN_VERSION=1.1.0-1
ARG FORCE_BUILD=1
ARG PLUGIN_VERSION=1.1.1-1
ARG PLUGIN_OIDC_VERSION=1.2.4-2
ARG PLUGIN_OIDC_CONSUMER_VERSION=0.0.1-0
ARG PLUGIN_UPSTREAM_BASIC_VERSION=1.0.0-1
ARG FORCE_BUILD=8

RUN git clone https://github.com/ikethecoder/kong-plugin-upstream-auth-basic.git
RUN (cd kong-plugin-upstream-auth-basic && luarocks make && luarocks pack kong-plugin-upstream-auth-basic ${PLUGIN_UPSTREAM_BASIC_VERSION})

RUN luarocks install lua-resty-openidc
RUN git clone -b v${PLUGIN_OIDC_VERSION} https://github.com/revomatico/kong-oidc.git
RUN (cd kong-oidc && luarocks make && luarocks pack kong-oidc ${PLUGIN_OIDC_VERSION})

RUN git clone https://github.com/ikethecoder/kong-oidc-consumer.git
RUN (cd kong-oidc-consumer && luarocks make && luarocks pack kong-oidc-consumer ${PLUGIN_OIDC_CONSUMER_VERSION})

RUN git clone https://github.com/ikethecoder/kong-plugin-jwt-keycloak.git
RUN (cd kong-plugin-jwt-keycloak && luarocks make && luarocks pack kong-plugin-jwt-keycloak ${PLUGIN_VERSION})
Expand All @@ -17,12 +30,21 @@ RUN git clone -b hotfix/ips-not-always-string https://github.com/bcgov/gwa-ip-an
RUN (cd gwa-ip-anonymity && ./devBuild.sh)

RUN luarocks install lua-resty-jwt 0.2.2-0 \
&& luarocks install lua-resty-openidc 1.6.1-1 \
&& luarocks install kong-oidc \
&& luarocks install lua-resty-session 2.26-1 \
&& luarocks install lua-resty-openidc 1.7.5-1 \
&& luarocks install kong-spec-expose \
&& luarocks install kong-upstream-jwt \
&& luarocks install kong-plugin-referer \
&& luarocks install kong-upstream-jwt \
&& luarocks install kong-oidc/kong-oidc-${PLUGIN_OIDC_VERSION}.all.rock \
&& luarocks install kong-plugin-upstream-auth-basic/kong-plugin-upstream-auth-basic-${PLUGIN_UPSTREAM_BASIC_VERSION}.all.rock \
&& luarocks install kong-oidc-consumer/kong-oidc-consumer-${PLUGIN_OIDC_CONSUMER_VERSION}.all.rock \
&& luarocks install kong-plugin-jwt-keycloak/kong-plugin-jwt-keycloak-${PLUGIN_VERSION}.all.rock

RUN git clone https://github.com/Kong/priority-updater.git
RUN (cd priority-updater/template/plugin && KONG_PRIORITY=902 KONG_PRIORITY_NAME=rate-limiting /usr/local/openresty/luajit/bin/luajit ../priority.lua)
RUN (cd priority-updater/template/plugin && KONG_PRIORITY=1010 KONG_PRIORITY_NAME=jwt-keycloak /usr/local/openresty/luajit/bin/luajit ../priority.lua)

USER kong

ENV KONG_PLUGINS="bundled, oidc, bcgov-gwa-endpoint, gwa-ip-anonymity, kong-spec-expose, referer, jwt-keycloak"
ENV KONG_PLUGINS="bundled, jwt-keycloak_1010, rate-limiting_902, oidc, oidc-consumer, bcgov-gwa-endpoint, gwa-ip-anonymity, kong-spec-expose, kong-upstream-jwt, referer, jwt-keycloak, kong-upstream-jwt, upstream-auth-basic"
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

query GET_APPLICATION_SERVICES($appId: String!) {
query GetApplicationServices($appId: String!) {
myServiceAccesses(where: { application: { appId: $appId } }) {
id
name
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

mutation UpdateApplication($id: ID!, $data: ApplicationUpdateInput) {
updateApplication(id: $id, data: $data) {
id
}
}
7 changes: 5 additions & 2 deletions src/mocks/handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import {
import {
allApplicationsHandler,
createApplicationHandler,
getApplicationServicesHandler,
removeApplicationHandler,
updateApplicationHandler,
} from './resolvers/applications';
import {
allProductsByNamespaceHandler,
Expand Down Expand Up @@ -168,8 +170,7 @@ export const handlers = [
return res(
ctx.status(200),
ctx.json({
user: null,
// user: { ...mark, namespace },
user: { ...personas.mark, namespace },
})
);
}),
Expand Down Expand Up @@ -238,7 +239,9 @@ export const handlers = [
keystone.mutation('UpdateEnvironment', updateEnvironmentHandler),
// Applications
keystone.query('MyApplications', allApplicationsHandler),
keystone.query('GetApplicationServices', getApplicationServicesHandler),
keystone.mutation('AddApplication', createApplicationHandler),
keystone.mutation('UpdateApplication', updateApplicationHandler),
keystone.mutation('RemoveApplication', removeApplicationHandler),
// Services
keystone.query('GetServices', allServicesHandler),
Expand Down
49 changes: 49 additions & 0 deletions src/mocks/resolvers/applications.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,37 @@ export const allApplicationsHandler = (req, res, ctx) => {
);
};

export const getApplicationServicesHandler = (req, res, ctx) => {
if (req.variables.appId !== 'ABC123') {
return res(
ctx.data({
myServiceAccesses: [],
})
);
}
return res(
ctx.data({
myServiceAccesses: [
{
id: 'sa1',
name: '123123-123ADSFSD',
active: true,
application: {
name: 'Demo App',
},
productEnvironment: {
id: 'pe1',
name: 'dev',
product: {
name: 'My Pharma API',
},
},
},
],
})
);
};

export const createApplicationHandler = (req, res, ctx) => {
if (req.variables.name === 'error') {
return res(
Expand All @@ -75,6 +106,24 @@ export const createApplicationHandler = (req, res, ctx) => {
);
};

export const updateApplicationHandler = (req, res, ctx) => {
const { id, data } = req.variables;
const cached = applications.get(id);

applications.set(id, {
...cached,
...data,
});

return res(
ctx.data({
updateApplication: {
id,
},
})
);
};

export const removeApplicationHandler = (req, res, ctx) => {
const { id } = req.variables;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const ApplicationServices: React.FC<ApplicationServicesProps> = ({ appId }) => {
export default ApplicationServices;

const query = gql`
query GET_APPLICATION_SERVICES($appId: String!) {
query GetApplicationServices($appId: String!) {
myServiceAccesses(where: { application: { appId: $appId } }) {
id
name
Expand Down
Loading

0 comments on commit d89cd92

Please sign in to comment.