Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cypress astra local #1022

Merged
merged 52 commits into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from 40 commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
16ecb6d
Merge pull request #581 from bcgov/dev
ikethecoder Sep 30, 2022
9759c11
Merge pull request #605 from bcgov/dev
ikethecoder Oct 19, 2022
d4be57f
Merge pull request #611 from bcgov/dev
ikethecoder Oct 19, 2022
7e4d1a9
Merge pull request #616 from bcgov/dev
ikethecoder Oct 25, 2022
671b218
Merge pull request #623 from bcgov/dev
ikethecoder Oct 29, 2022
ff834c2
Merge pull request #670 from bcgov/dev
ikethecoder Dec 30, 2022
cbcac10
Merge pull request #677 from bcgov/dev
ikethecoder Jan 3, 2023
67b941a
Merge pull request #681 from bcgov/dev
ikethecoder Jan 4, 2023
110e90f
Merge pull request #688 from bcgov/dev
ikethecoder Jan 6, 2023
c1b20be
Merge pull request #691 from bcgov/dev
ikethecoder Jan 6, 2023
d89cd92
Merge pull request #704 from bcgov/dev
ikethecoder Jan 10, 2023
5303314
Merge pull request #706 from bcgov/dev
ikethecoder Jan 11, 2023
2cbdd3e
Merge pull request #707 from bcgov/dev
ikethecoder Jan 11, 2023
d0d8ab2
Merge pull request #723 from bcgov/dev
ikethecoder Jan 20, 2023
89e4bf4
Merge pull request #759 from bcgov/dev
ikethecoder Feb 22, 2023
bed9a70
Merge pull request #763 from bcgov/dev
ikethecoder Feb 22, 2023
e3bf9bb
Merge pull request #774 from bcgov/dev
ikethecoder Mar 9, 2023
c227da7
Merge pull request #778 from bcgov/dev
ikethecoder Mar 12, 2023
fe74bcd
Merge pull request #782 from bcgov/dev
ikethecoder Mar 14, 2023
f4a6ff0
Merge pull request #807 from bcgov/dev
ikethecoder May 17, 2023
13035f4
Merge pull request #820 from bcgov/dev
ikethecoder May 18, 2023
b236ea7
Merge pull request #826 from bcgov/dev
ikethecoder Jun 8, 2023
42cfcc7
Merge pull request #835 from bcgov/dev
ikethecoder Jun 12, 2023
9301fd1
Merge pull request #849 from bcgov/dev
ikethecoder Jul 12, 2023
a09f38c
Merge pull request #897 from bcgov/dev
ikethecoder Sep 8, 2023
359f97c
Merge pull request #907 from bcgov/dev
ikethecoder Sep 15, 2023
3077112
Merge pull request #914 from bcgov/dev
ikethecoder Sep 18, 2023
d6f212a
Merge pull request #955 from bcgov/dev
Elson9 Nov 7, 2023
336178f
Merge pull request #959 from bcgov/dev
ikethecoder Nov 8, 2023
29fbea3
Merge pull request #963 from bcgov/dev
ikethecoder Dec 5, 2023
a070d5f
Merge pull request #971 from bcgov/dev
ikethecoder Dec 6, 2023
c3d417a
Merge branch 'dev' into test
ikethecoder Dec 18, 2023
bd8e74f
Merge branch 'dev' into test
ikethecoder Dec 28, 2023
859778b
Merge pull request #999 from bcgov/dev
rustyjux Mar 1, 2024
e67727f
Merge pull request #1004 from bcgov/dev
ikethecoder Mar 6, 2024
2e40387
Merge pull request #1008 from bcgov/dev
ikethecoder Mar 7, 2024
b53799e
Update make API request call as per new design
nirajCITZ Mar 26, 2024
11d7ee2
Update APS-API test to call Astra and update keycloak docker image in…
nirajCITZ Mar 27, 2024
c6885fe
Update aps-cypress-e2e.yaml
nirajCITZ Mar 27, 2024
1e87b67
Dataset formatting fix (#1016)
ikethecoder Mar 26, 2024
a2df507
delete cypress/downloads and clear scanResult
rustyjux Apr 2, 2024
cb82251
exclude astra artifacts in gitignore
rustyjux Apr 2, 2024
f07b898
rename addToAstraScanIdList function for clarity
rustyjux Apr 2, 2024
b030312
rename response data
rustyjux Apr 3, 2024
0d7c628
delete commented out code for downloading gwa cli
rustyjux Apr 10, 2024
3ee84e8
create Jira issues w/ Astra scan results
rustyjux Apr 10, 2024
25b53b5
quick test of astra GHA
rustyjux Apr 10, 2024
9bf6ec3
remove test file
rustyjux Apr 10, 2024
e7faa27
uncomment other GHA steps
rustyjux Apr 10, 2024
4347b07
add exit 1 if failures on Cypress tests
rustyjux Apr 10, 2024
e0396e0
added if: so Astra upload runs if Cypress fails
rustyjux Apr 10, 2024
820c7b5
if: failure to only check Astra if Cypress fails
rustyjux Apr 10, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .github/workflows/aps-cypress-e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@ jobs:
name: test-results
path: ${{ github.workspace }}/e2e/results/report

- name: Upload E2E Code Coverage Report
uses: actions/upload-artifact@v2
with:
name: code-coverage
path: ${{ github.workspace }}/e2e/coverage

- name: SonarCloud Scan
uses: sonarsource/sonarcloud-github-action@master
with:
Expand Down
30 changes: 28 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ x-common-variables: &common-variables

services:
keycloak:
image: jboss/keycloak:15.1.1
image: quay.io/keycloak/keycloak:15.1.1
container_name: keycloak
hostname: keycloak
depends_on:
Expand Down Expand Up @@ -237,5 +237,31 @@ services:
- aps-net
profiles:
- testsuite
astra-mongo:
image: mongo:4.2.2
container_name: astra-mongo
ports:
- '27017:27017'
networks:
aps-net:
aliases:
- mongo.localtest.me
astra-gui:
build:
context: local/astra
container_name: astra-gui
restart: always
environment:
MONGO_PORT_27017_TCP_ADDR: astra-mongo
networks:
aps-net:
aliases:
- astra.localtest.me
depends_on:
- astra-mongo
links:
- astra-mongo:mongo
ports:
- '8094:8094'
networks:
aps-net: {}
aps-net: {}
3 changes: 2 additions & 1 deletion e2e/cypress.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ export default defineConfig({
'./cypress/tests/14-*/*.ts',
'./cypress/tests/15-*/*.ts',
'./cypress/tests/16-*/*.ts',
'./cypress/tests/17-*/*.ts'
'./cypress/tests/17-*/*.ts',
'./cypress/tests/18-*/*.ts'
]
return config
},
Expand Down
Binary file added e2e/cypress/downloads/downloads.html
Binary file not shown.
4 changes: 4 additions & 0 deletions e2e/cypress/fixtures/state/scanID.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"items": [
]
}
1 change: 1 addition & 0 deletions e2e/cypress/fixtures/state/scanResult.json

Large diffs are not rendered by default.

43 changes: 38 additions & 5 deletions e2e/cypress/support/auth-commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -422,17 +422,50 @@ Cypress.Commands.add('setAuthorizationToken', (token: string) => {
})

Cypress.Commands.add('makeAPIRequest', (endPoint: string, methodType: string) => {

let body = {}

let requestData: any = {}
if (methodType.toUpperCase() === 'PUT' || methodType.toUpperCase() === 'POST') {
body = requestBody
}
return cy.request({
url: Cypress.env('BASE_URL') + '/' + endPoint,
method: methodType,
body: body,

requestData['appname'] = "Test1"
requestData['url'] = Cypress.env('BASE_URL') + '/' + endPoint
requestData['headers'] = headers
requestData['body'] = ""
requestData['method'] = methodType

cy.request({
url: 'http://astra.localtest.me:8094/scan/',
method: 'POST',
body: requestData,
headers: headers,
failOnStatusCode: false
}).then((response1) => {
// Second API request
cy.request({
url: Cypress.env('BASE_URL') + '/' + endPoint,
method: methodType,
body: body,
headers: headers,
failOnStatusCode: false
}).then((response2) => {
// You can also return data or use it in further tests
const responseData = {
data1: response1,
data2: response2,
};
// cy.addToGlobalList(response2.body.status)
return responseData;
})
});
})

Cypress.Commands.add('makeAPIRequestForScanResult', (scanID: string) => {
return cy.request({
url: 'http://astra.localtest.me:8094/alerts/' + scanID,
method: 'GET',
failOnStatusCode: false
})
})

Expand Down
6 changes: 6 additions & 0 deletions e2e/cypress/support/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,5 +101,11 @@ declare namespace Cypress {
updateJsonBoby(json: any, key: string, newValue: string):Chainable<any>

deleteFileInE2EFolder(fileName: string):Chainable<any>

addToGlobalList(item: any):Chainable<any>

checkAstraScanResultForVulnerability():Chainable<any>

makeAPIRequestForScanResult(scanID: string): Chainable<Cypress.Response<any>>
}
}
45 changes: 45 additions & 0 deletions e2e/cypress/support/util-commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,21 @@ Cypress.Commands.add('deleteFileInE2EFolder', (fileName: string) => {
}
});

Cypress.Commands.add('addToGlobalList', (item) => {
cy.readFile('cypress/fixtures/state/scanID.json').then((fileContent) => {
// Initialize the list if it doesn't exist
const items = fileContent.items || [];

// Append the new item to the list
items.push(item);

// Create an object with the updated list
const updatedData = { items };

// Write the updated object back to the file
cy.writeFile('cypress/fixtures/state/scanID.json', updatedData);
});
});

Cypress.Commands.add('replaceWord', (originalString: string, wordToReplace: string, replacementWord: string)=> {
// Create a regular expression with the 'g' flag for global search
Expand All @@ -180,4 +195,34 @@ Cypress.Commands.add('replaceWord', (originalString: string, wordToReplace: stri
replacedString = originalString.replace(regex, replacementWord);

return replacedString;
})

Cypress.Commands.add('checkAstraScanResultForVulnerability', () => {
let aggregatedData = {};
let existingData: any = [];
let flag = false
cy.readFile('cypress/fixtures/state/scanID.json').then((fileContent) => {
fileContent.items.forEach((item: string) => {
// Perform an action based on each item in the array
cy.makeAPIRequestForScanResult(item).then((response) => {
const newResponse = JSON.parse(JSON.stringify(response.body));
existingData.push(newResponse);
});
});
}).then(() => {
cy.writeFile('cypress/fixtures/state/scanResult.json', JSON.stringify(existingData))
for (var i = 0; i < existingData.length; i++) {
var jsonObject = existingData[i];
for (var j = 0; i < jsonObject.length; i++) {
if (jsonObject[j].hasOwnProperty("impact") &&
["High", "Medium"].includes(jsonObject[j]["impact"])) {
flag = true;
}
}
}
}).then(()=>{
if (flag){
assert.fail("Some of the results have high or medium severity security vulnerabilities. Please check the result file for more details.");
}
})
})
4 changes: 2 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 @@ -102,8 +102,8 @@ it('Verify gwa gateway publish multiple config file', () => {
cy.get('@api').then(({ organization }: any) => {
cy.setHeaders(organization.headers)
cy.setAuthorizationToken(userSession)
cy.makeAPIRequest(organization.endPoint + '/' + organization.orgName + '/' + organization.orgExpectedList.name + '/namespaces/' + nameSpace, 'PUT').then((response) => {
expect(response.status).to.be.equal(200)
cy.makeAPIRequest(organization.endPoint + '/' + organization.orgName + '/' + organization.orgExpectedList.name + '/namespaces/' + nameSpace, 'PUT').then((response:any) => {
expect(response.data2.status).to.be.equal(200)
})
})
})
Expand Down
4 changes: 2 additions & 2 deletions e2e/cypress/tests/01-api-key/09-gwa-get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ describe('Verify GWA get commands', () => {
cy.get('@api').then(({ apiDirectory }: any) => {
cy.setHeaders(apiDirectory.headers)
cy.setAuthorizationToken(userSession)
cy.makeAPIRequest(apiDirectory.endPoint + '/' + _namespace + '/directory', 'GET').then((res) => {
resObj = res.body[0]
cy.makeAPIRequest(apiDirectory.endPoint + '/' + _namespace + '/directory', 'GET').then((res:any) => {
resObj = res.data2.body[0]
Cypress._.isEqual(resObj, JSON.parse(response.stdout)[0])
})
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ describe('Create API, Product, and Authorization Profiles; Apply Auth Profiles t
cy.get('@api').then(({ organization }: any) => {
cy.setHeaders(organization.headers)
cy.setAuthorizationToken(userSession)
cy.makeAPIRequest(organization.endPoint + '/' + organization.orgName + '/' + organization.orgExpectedList.name + '/namespaces/' + nameSpace, 'PUT').then((response) => {
expect(response.status).to.be.equal(200)
cy.makeAPIRequest(organization.endPoint + '/' + organization.orgName + '/' + organization.orgExpectedList.name + '/namespaces/' + nameSpace, 'PUT').then((response:any) => {
expect(response.data2.status).to.be.equal(200)
})
})
})
Expand Down
10 changes: 5 additions & 5 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 @@ -56,9 +56,9 @@ describe('Apply Shared IDP while creating Authorization Profile', () => {

it('Publish the Shared IDP profile', () => {
cy.get('@common-testdata').then(({ namespace }: any) => {
cy.makeAPIRequest('ds/api/v2/namespaces/' + namespace + '/issuers', 'PUT').then((response) => {
expect(response.status).to.be.equal(200)
expect(response.body.result).to.be.contain('created')
cy.makeAPIRequest('ds/api/v2/namespaces/' + namespace + '/issuers', 'PUT').then((response:any) => {
expect(response.data2.status).to.be.equal(200)
expect(response.data2.body.result).to.be.contain('created')
})
})
})
Expand Down Expand Up @@ -121,8 +121,8 @@ describe('Update IDP issuer for shared IDP profile', () => {

it('Put the resource and verify the success code in the response', () => {
cy.get('@common-testdata').then(({ namespace }: any) => {
cy.makeAPIRequest('ds/api/v2/namespaces/' + namespace + '/issuers', 'PUT').then((response) => {
expect(response.status).to.be.equal(200)
cy.makeAPIRequest('ds/api/v2/namespaces/' + namespace + '/issuers', 'PUT').then((response:any) => {
expect(response.data2.status).to.be.equal(200)
})
})
})
Expand Down
4 changes: 2 additions & 2 deletions e2e/cypress/tests/10-clear-resources/01-create-api.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ describe('Create API Spec for Delete Resources', () => {
cy.get('@api').then(({ organization }: any) => {
cy.setHeaders(organization.headers)
cy.setAuthorizationToken(userSession)
cy.makeAPIRequest(organization.endPoint + '/' + organization.orgName + '/' + organization.orgExpectedList.name + '/namespaces/' + namespace, 'PUT').then((response) => {
expect(response.status).to.be.equal(200)
cy.makeAPIRequest(organization.endPoint + '/' + organization.orgName + '/' + organization.orgExpectedList.name + '/namespaces/' + namespace, 'PUT').then((response:any) => {
expect(response.data2.status).to.be.equal(200)
})
})
})
Expand Down
12 changes: 6 additions & 6 deletions e2e/cypress/tests/11-activity-feed/01-activity-feed.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ describe('API Tests for Activity report', () => {

it('Get the resource and verify the success code in the response', () => {
cy.get('@api').then(({ namespaces }: any) => {
cy.makeAPIRequest(namespaces.endPoint + "/" + nameSpace + "/activity?first=100", 'GET').then((res) => {
expect(res.status).to.be.equal(200)
response = res.body
cy.makeAPIRequest(namespaces.endPoint + "/" + nameSpace + "/activity?first=100", 'GET').then((res:any) => {
expect(res.data2.status).to.be.equal(200)
response = res.data2.body
})
})
})
Expand All @@ -80,9 +80,9 @@ describe('Generate activity response from APS V2 API', () => {

it('Get the resource and verify the success code in the response', () => {
cy.get('@api').then(({ namespaces }: any) => {
cy.makeAPIRequest(namespaces.endPoint + "/" + nameSpace + "/activity?first=100", 'GET').then((res) => {
expect(res.status).to.be.equal(200)
response = res.body
cy.makeAPIRequest(namespaces.endPoint + "/" + nameSpace + "/activity?first=100", 'GET').then((res:any) => {
expect(res.data2.status).to.be.equal(200)
response = res.data2.body
})
})
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@ describe('Create API, Product, and Authorization Profiles; Apply Auth Profiles t

it('Get the resource and verify the success code in the response', () => {
cy.get('@api').then(({ namespaces }: any) => {
cy.makeAPIRequest(namespaces.endPoint + "/" + nameSpace + "/activity?first=100", 'GET').then((res) => {
expect(res.status).to.be.equal(200)
response = res.body
cy.makeAPIRequest(namespaces.endPoint + "/" + nameSpace + "/activity?first=100", 'GET').then((res:any) => {
expect(res.data2.status).to.be.equal(200)
response = res.data2.body
})
})
})
Expand Down
4 changes: 2 additions & 2 deletions e2e/cypress/tests/12-access-permission/01-create-api.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ describe('Create API Spec', () => {
cy.get('@api').then(({ organization }: any) => {
cy.setHeaders(organization.headers)
cy.setAuthorizationToken(userSession)
cy.makeAPIRequest(organization.endPoint + '/' + organization.orgName + '/' + organization.orgExpectedList.name + '/namespaces/' + namespace, 'PUT').then((response) => {
expect(response.status).to.be.equal(200)
cy.makeAPIRequest(organization.endPoint + '/' + organization.orgName + '/' + organization.orgExpectedList.name + '/namespaces/' + namespace, 'PUT').then((response:any) => {
expect(response.data2.status).to.be.equal(200)
})
})
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ describe('Verify Content Publish Permission', () => {

it('Verify that the document is not published without "Content.Publish" permission', () => {
cy.get('@api').then(({ documentation }: any) => {
cy.makeAPIRequest(documentation.endPoint, 'PUT').then((response) => {
expect(response.status).to.be.equal(401)
expect(response.body.message).contain('Missing authorization scope')
cy.makeAPIRequest(documentation.endPoint, 'PUT').then((response:any) => {
expect(response.data2.status).to.be.equal(401)
expect(response.data2.body.message).contain('Missing authorization scope')
})
})
})
Expand Down
4 changes: 2 additions & 2 deletions e2e/cypress/tests/15-aps-api/01-create-api.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ describe('Create API Spec', () => {
cy.get('@api').then(({ organization }: any) => {
cy.setHeaders(organization.headers)
cy.setAuthorizationToken(userSession)
cy.makeAPIRequest(organization.endPoint + '/' + organization.orgName + '/' + organization.orgExpectedList.name + '/namespaces/' + namespace, 'PUT').then((response) => {
expect(response.status).to.be.equal(200)
cy.makeAPIRequest(organization.endPoint + '/' + organization.orgName + '/' + organization.orgExpectedList.name + '/namespaces/' + namespace, 'PUT').then((response:any) => {
expect(response.data2.status).to.be.equal(200)
})
})
})
Expand Down
Loading
Loading