Skip to content

Commit

Permalink
Add tests for Revoke Environment access and Delete consumer feature
Browse files Browse the repository at this point in the history
  • Loading branch information
nirajCITZ committed Oct 23, 2023
1 parent 53822ba commit 547a843
Show file tree
Hide file tree
Showing 15 changed files with 427 additions and 15 deletions.
10 changes: 10 additions & 0 deletions e2e/cypress/fixtures/developer.json
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,16 @@
"environment": "dev"
}
},
"deleteResources":{
"application": {
"name": "Delete-Auto Test App",
"description": "Test application for auto test"
},
"product": {
"name": "Delete-Auto Test Product",
"environment": "dev"
}
},
"elevatedAccess":{
"application": {
"name": "Request for Elevated Acess",
Expand Down
34 changes: 34 additions & 0 deletions e2e/cypress/fixtures/service-plugin_A.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
services:
- name: a-service-for-newplatform
host: httpbin.org
tags: [ns.newplatform.test]
port: 443
protocol: https
retries: 0
routes:
- name: a-service-for-newplatform-route
tags: [ns.newplatform.test]
hosts:
- a-service-for-newplatform.api.gov.bc.ca
paths:
- /
methods:
- GET
strip_path: false
https_redirect_status_code: 426
path_handling: v0

plugins:
- name: key-auth
tags: [ ns.newplatform.test ]
protocols: [ http, https ]
config:
key_names: ["X-API-KEY"]
run_on_preflight: true
hide_credentials: true
key_in_body: false
- name: acl
tags: [ ns.newplatform.test ]
config:
hide_groups_header: true
allow: [ "406CB7CF" ]
34 changes: 34 additions & 0 deletions e2e/cypress/fixtures/service-plugin_B.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
services:
- name: a-service-for-newplatform-test
host: httpbin.org
tags: [ns.newplatform.test]
port: 443
protocol: https
retries: 0
routes:
- name: a-service-for-newplatform-test-route
tags: [ns.newplatform.test]
hosts:
- a-service-for-newplatform-test.api.gov.bc.ca
paths:
- /
methods:
- GET
strip_path: false
https_redirect_status_code: 426
path_handling: v0

plugins:
- name: key-auth
tags: [ ns.newplatform.test ]
protocols: [ http, https ]
config:
key_names: ["X-API-KEY"]
run_on_preflight: true
hide_credentials: true
key_in_body: false
- name: acl
tags: [ ns.newplatform.test ]
config:
hide_groups_header: true
allow: [ "9AA97172" ]
11 changes: 10 additions & 1 deletion e2e/cypress/pageObjects/consumers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export default class ConsumersPage {
linkConsumerToNamespaceBtn: string = '[data-testid="link-consumer-namespace"]'
userNameTxt: string = '[data-testid="link-consumer-username"]'
linkBtn: string = '[data-testid="link-consumer-link-btn"]'
productDetails: string = '[data-testid="product-list-table"]'

clickOnRateLimitingOption() {
cy.get(this.rateLimitingOption, { timeout: 2000 }).click()
Expand Down Expand Up @@ -202,7 +203,7 @@ export default class ConsumersPage {
}

editConsumerDialog() {
cy.get('[data-testid="product-list-table"]').then($button => {
cy.get(this.productDetails).then($button => {
if ($button.is(':visible')) {
cy.contains('Edit').first().click()
}
Expand Down Expand Up @@ -374,4 +375,12 @@ export default class ConsumersPage {
getText() {
cy.get('[data-testid="all-consumer-control-tbl"]').find('tr').last().find('td').first().find('a').as('inputValue')
}

revokeProductEnvAccess(prodEnv: any) {
cy.get(this.productDetails).find('tr').each(($row) => {
if ($row.find('td:nth-child(1)').text() == prodEnv) {
cy.wrap($row).find('button').last().click({ force: true })
}
})
}
}
19 changes: 14 additions & 5 deletions e2e/cypress/support/auth-commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,17 +241,26 @@ Cypress.Commands.add('getServiceOrRouteID', (configType: string, host: string) =
}).then((res) => {
expect(res.status).to.eq(200)
if (config === 'routes') {
cy.saveState(config + 'ID', Cypress._.get((Cypress._.filter(res.body.data, ["hosts", [host+".api.gov.bc.ca"]]))[0], 'id'))
cy.saveState(config + 'ID', Cypress._.get((Cypress._.filter(res.body.data, ["hosts", [host + ".api.gov.bc.ca"]]))[0], 'id'))
}
else {
cy.saveState(config + 'ID', Cypress._.get((Cypress._.filter(res.body.data, ["name", host]))[0], 'id'))
}
})
})

Cypress.Commands.add('publishApi', (fileName: string, namespace: string, flag?: boolean) => {
Cypress.Commands.add('publishApi', (fileNames: any, namespace: string, flag?: boolean) => {
let fixtureFile = flag ? "state/regen" : "state/store";
cy.log('< Publish API')
let fileName = ''
if (fileNames instanceof Array) {
for (const filepath of fileNames) {
fileName = fileName + ' ./cypress/fixtures/' + filepath;
}
}
else {
fileName = ' ./cypress/fixtures/' + fileNames
}
const requestName: string = 'publishAPI'
cy.fixture(fixtureFile).then((creds: any) => {
const serviceAcctCreds = JSON.parse(creds.credentials)
Expand All @@ -263,7 +272,7 @@ Cypress.Commands.add('publishApi', (fileName: string, namespace: string, flag?:
cy.executeCliCommand('gwa config set --token ' + res.body.access_token).then((response) => {
{
expect(response.stdout).to.contain("Config settings saved")
cy.executeCliCommand('gwa pg ./cypress/fixtures/' + fileName).then((response) => {
cy.executeCliCommand('gwa pg ' + fileName).then((response) => {
expect(response.stdout).to.contain("Gateway config published")
})
}
Expand Down Expand Up @@ -502,7 +511,7 @@ Cypress.Commands.add('updatePropertiesOfPluginFile', (filename: string, property
if (propertyName === "config.anonymous") {
obj.plugins[0].config.anonymous = propertyValue
}
else if (propertyName === "tags"){
else if (propertyName === "tags") {
obj.plugins[0][propertyName] = propertyValue
}
else {
Expand Down Expand Up @@ -573,7 +582,7 @@ Cypress.Commands.add('forceVisit', (url: string) => {
});
});

Cypress.Commands.add('updateJsonBoby', (json: any, key: string, newValue: string):any => {
Cypress.Commands.add('updateJsonBoby', (json: any, key: string, newValue: string): any => {
json[key] = newValue
return json
});
Expand Down
2 changes: 1 addition & 1 deletion e2e/cypress/support/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ declare namespace Cypress {
client_secret: string
): Chainable<Cypress.Response<any>>

publishApi(fileName: string, namespace: string, flag?: boolean): Chainable<Cypress.Response<any>>
publishApi(fileNames: string[], namespace: string, flag?: boolean): Chainable<Cypress.Response<any>>

getServiceOrRouteID(configType: string, host: string
): Chainable<Cypress.Response<any>>
Expand Down
13 changes: 11 additions & 2 deletions e2e/cypress/tests/01-api-key/01-create-api.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,18 @@ describe('Create API Spec', () => {
sa.saveServiceAcctCreds()
})

it('Verify gwa gateway publish multiple config file', () => {
cy.get('@apiowner').then(({ namespace }: any) => {
debugger
cy.publishApi(['service-plugin_A.yml','service-plugin_B.yml'], namespace).then((response: any) => {
expect(response.stdout).to.contain('Gateway config published');
})
})
})

it('publishes a new API for Dev environment to Kong Gateway', () => {
cy.get('@apiowner').then(({ namespace }: any) => {
cy.publishApi('service.yml', namespace).then((response: any) => {
cy.publishApi(['service.yml'], namespace).then((response: any) => {
expect(response.stdout).to.contain('Sync successful');
})
})
Expand Down Expand Up @@ -103,7 +112,7 @@ describe('Create API Spec', () => {
})
})

it('update the Dataset in BC Data Catelogue to appear the API in the Directory', () => {
it('update the Dataset in BC Data Catalogue to appear the API in the Directory', () => {
cy.visit(pd.path)
cy.get('@apiowner').then(({ product }: any) => {
pd.updateDatasetNameToCatelogue(product.name, product.environment.name)
Expand Down
91 changes: 91 additions & 0 deletions e2e/cypress/tests/01-api-key/10-revoke-access.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import ConsumersPage from '../../pageObjects/consumers'
import LoginPage from '../../pageObjects/login'
import HomePage from '../../pageObjects/home'
import ProductPage from '../../pageObjects/products'

describe('Revoke product environment access for Kong API spec', () => {
const login = new LoginPage()
const consumers = new ConsumersPage()
const home = new HomePage()

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

beforeEach(() => {
cy.preserveCookies()
cy.fixture('access-manager').as('access-manager')
cy.fixture('apiowner').as('apiowner')
cy.fixture('developer').as('developer')
cy.fixture('state/store').as('store')
})

it('authenticates Mark (Access-Manager)', () => {
cy.get('@apiowner').then(({ namespace }: any) => {
cy.get('@access-manager').then(({ user }: any) => {
cy.login(user.credentials.username, user.credentials.password)
home.useNamespace(namespace);
})
})
})

it('Navigate to Consumer page and filter the product', () => {
cy.get('@apiowner').then(({ product }: any) => {
cy.visit(consumers.path);
consumers.filterConsumerByTypeAndValue('Products', product.name)
})
})

it('Click on the first consumer', () => {
consumers.clickOnTheFirstConsumerID()
})

it('Revoke access for Test environment', () => {
cy.wait(1000)
consumers.revokeProductEnvAccess('Test')
})

it('Verify the confirmation message once the access is revoked', () => {
cy.verifyToastMessage("Product Revoked")
})

it('Navigate to Consumer page and filter the product', () => {
cy.get('@apiowner').then(({ product }: any) => {
cy.visit(consumers.path);
consumers.filterConsumerByTypeAndValue('Products', product.name)
})
})

it('Click on the first consumer', () => {
consumers.clickOnTheFirstConsumerID()
})

it('Click on Grant Access button', () => {
cy.wait(1000)
consumers.clickOnGrantAccessBtn()
})

it('Grant Access to Test environment', () => {
cy.get('@apiowner').then(({ product }: any) => {
consumers.grantAccessToGivenProductEnvironment(product.name, product.test_environment.name)
})
})

it('Verify that API is accessible with the generated API Key for Test environment', () => {
cy.get('@apiowner').then(({ product }: any) => {
cy.makeKongRequest(product.test_environment.config.serviceName, 'GET').then((response) => {
cy.log(response)
expect(response.status).to.be.equal(200)
})
})
})

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

})
Original file line number Diff line number Diff line change
Expand Up @@ -235,4 +235,62 @@ describe('Verify the selected client scoped is not displayed in assigned default
cy.deleteAllCookies()
})

})
})

// describe('Revoke product environment access for Client Credential authorization spec', () => {
// const login = new LoginPage()
// const consumers = new ConsumersPage()
// const home = new HomePage()

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

// beforeEach(() => {
// cy.preserveCookies()
// cy.fixture('access-manager').as('access-manager')
// cy.fixture('apiowner').as('apiowner')
// cy.fixture('developer').as('developer')
// cy.fixture('state/store').as('store')
// })

// it('authenticates Mark (Access-Manager)', () => {
// cy.get('@apiowner').then(({ clientCredentials }: any) => {
// cy.get('@access-manager').then(({ user }: any) => {
// cy.login(user.credentials.username, user.credentials.password)
// home.useNamespace(clientCredentials.namespace);
// })
// })
// })

// it('Navigate to Consumer page and filter the product', () => {
// cy.get('@apiowner').then(({ clientCredentials }: any) => {
// cy.visit(consumers.path);
// let product = clientCredentials.clientIdSecret.product
// consumers.filterConsumerByTypeAndValue('Products', product.name)
// })
// })

// it('Click on the first consumer', () => {
// consumers.clickOnTheFirstConsumerID()
// })

// it('Revoke access for Test environment', () => {
// cy.wait(1000)
// consumers.revokeProductEnvAccess('Test')
// })

// it('Verify the confirmation message once the access is revoked', () => {
// cy.verifyToastMessage("Product Revoked")
// })


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

// })
2 changes: 1 addition & 1 deletion e2e/cypress/tests/10-clear-resources/01-create-api.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ describe('Create API Spec for Delete Resources', () => {
cy.visit(pd.path)
cy.get('@apiowner').then(({ deleteResources }: any) => {
pd.editProductEnvironment(deleteResources.product.name, deleteResources.product.environment.name)
pd.editProductEnvironmentConfig(deleteResources.product.environment.config)
pd.editProductEnvironmentConfig(deleteResources.product.environment.config, false, false)
pd.generateKongPluginConfig(deleteResources.product.name, deleteResources.product.environment.name, 'service-clear-resources.yml')
})
})
Expand Down
Loading

0 comments on commit 547a843

Please sign in to comment.