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

Ossmc Cypress tests #6892

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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: 5 additions & 1 deletion frontend/cypress.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { defineConfig } from 'cypress';
import { getAuthStrategy } from './cypress/plugins/setup';
import { getAuthStrategy, checkForOSSMC } from './cypress/plugins/setup';
import { addCucumberPreprocessorPlugin } from '@badeball/cypress-cucumber-preprocessor';
import browserify from '@badeball/cypress-cucumber-preprocessor/browserify';

Expand Down Expand Up @@ -38,6 +38,10 @@ export default defineConfig({
// env variable.
config.env.AUTH_PROVIDER = config.env.AUTH_PROVIDER || 'my_htpasswd_provider';
config.env.AUTH_STRATEGY = await getAuthStrategy(config.baseUrl!);
config.env.OSSMC_TAGS = config.env.TAGS?.includes('@ossmc') ? true : false;
config.env.OSSMC_URL = config.env.OSSMC_URL || '';

await checkForOSSMC(config.env.OSSMC_TAGS, config.env.OSSMC_URL);

return config;
},
Expand Down
1 change: 1 addition & 0 deletions frontend/cypress/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export CYPRESS_BASE_URL=<value> # defaults to http://localhost:300
export CYPRESS_USERNAME=<value> # defaults to jenkins, opt. kubeadmin
export CYPRESS_PASSWD=<value> # no defaults
export CYPRESS_AUTH_PROVIDER=<value> # defaults to my_htpasswd_provider
export CYPRESS_OSSMC_URL=<value> # defaults to empty string '', required when passing @ossmc TAG to Cypress suite. Example value: https://console-openshift-console.apps.demo1.openshift4-beta-abcorp.com
```

When running the Cypress tests for multi-cluster, both contexts for the kubectl/oc command must be specified.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,11 @@ Given('user is at administrator perspective', () => {

And('user visits base url', () => {
cy.visit('/')
})

Given('user is logged as administrator in Openshift Web Console', () => {
Cypress.Cookies.defaults({
preserve: 'some-ocp-web-console-cookie',
})
cy.loginOSSMC(USERNAME, PASSWD)
})
16 changes: 16 additions & 0 deletions frontend/cypress/integration/featureFiles/autohorization.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
@smoke
# don't change first line of this file - the tag is used for the test scripts to identify the test suite

Feature: authorization and smoke test for various platforms
Smoke to verify cy.login function is working for multiple platforms (Kiali, Openshift Web Console)

Scenario: Kiali console is visible after login
Given user is at administrator perspective
And user visits base url
Then user see console in URL

@ossmc
Scenario: Kiali plugin is visible in Openshift Web Console when logged as admin
Given user is logged as administrator in Openshift Web Console


16 changes: 0 additions & 16 deletions frontend/cypress/integration/featureFiles/kiali_cookie.feature

This file was deleted.

7 changes: 7 additions & 0 deletions frontend/cypress/plugins/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,10 @@ export async function getAuthStrategy(url: string) {
throw new Error(`Kiali API is not reachable at ${JSON.stringify(err.config.url)}`);
}
}

export async function checkForOSSMC(tags: string, ossmcUrl: string) {
if (tags && ossmcUrl == '') {
console.error(`ERROR: OSSMC_URL is not reachable at ${ossmcUrl}, set it by export CYPRESS_OSSMC_URL`);
throw new Error(`ERROR: OSSMC_URL is not reachable at ${ossmcUrl}, set it by export CYPRESS_OSSMC_URL`);
}
}
17 changes: 17 additions & 0 deletions frontend/cypress/support/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,17 @@ declare namespace Cypress {
* @param password
*/
login(username: string, password: string): Chainable<Subject>;

/**
* Login to OpenShift web console with the given username and password.
*
* Provider will be determined by the environment variable AUTH_PROVIDER
* and auth strategy is fetched from the Kiali API.
* OSSMC_URL is required to be set in the environment.
* @param username
* @param password
*/
loginOSSMC(username: string, password: string): Chainable<Subject>;

logout(): Chainable<Subject>;
}
Expand Down Expand Up @@ -214,6 +225,12 @@ Cypress.Commands.add('login', (username: string, password: string) => {
});
});

Cypress.Commands.add('loginOSSMC', () => {
cy.login(Cypress.env('USERNAME'), Cypress.env('PASSWD')); // we login to Kiali first the usual way
cy.visit(Cypress.env('OSSMC_URL'));
cy.log('we need to login into OpenShift Web Console using API I guess');
});

Cypress.Commands.add('getBySel', (selector: string, ...args: any) => cy.get(`[data-test="${selector}"]`, ...args));

Cypress.Commands.add('inputValidation', (id: string, text: string, valid = true) => {
Expand Down
1 change: 1 addition & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"precypress:run:junit": "npm run cypress:delete:reports",
"cypress": "cypress open -e TAGS=\"not @multi-cluster\"",
"cypress:mc": "cypress open -e TAGS=\"@multi-cluster\"",
"cypress:ossmc": "cypress open -e TAGS=\"@ossmc\"",
"cypress:run": "cypress run -e TAGS=\"@smoke\" && cypress run -e TAGS=\"not @crd-validation and not @multi-cluster and not @smoke\" && cypress run -e TAGS=\"@crd-validation and not @multi-cluster and not @smoke\"",
"cypress:run:smoke": "cypress run -e TAGS=\"@smoke\"",
"cypress:run:multi-cluster": "cypress run -e TAGS=\"not @crd-validation and @multi-cluster\"",
Expand Down