1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-25 00:07:47 +01:00

refactor: simplify e2e auth (#803)

This commit is contained in:
olav 2022-03-24 09:38:41 +01:00 committed by GitHub
parent bf41e50a99
commit 82972498f8
5 changed files with 28 additions and 33 deletions

View File

@ -17,7 +17,6 @@ jobs:
- name: Run Cypress
uses: cypress-io/github-action@v2
with:
env: AUTH_TOKEN=${{ secrets.UNLEASH_TOKEN }}
config: baseUrl=${{ github.event.deployment_status.target_url }}
record: true
spec: cypress/integration/auth/auth.spec.ts

View File

@ -17,7 +17,7 @@ jobs:
- name: Run Cypress
uses: cypress-io/github-action@v2
with:
env: AUTH_TOKEN=${{ secrets.UNLEASH_TOKEN }}
env: AUTH_USER=test@unleash-e2e.com
config: baseUrl=${{ github.event.deployment_status.target_url }}
record: true
spec: cypress/integration/feature/feature.spec.ts

View File

@ -1,7 +1,6 @@
/// <reference types="cypress" />
const username = 'test@test.com';
const password = 'qY70$NDcJNXA';
export {};
describe('auth', () => {
it('renders the password login', () => {
@ -15,17 +14,16 @@ describe('auth', () => {
type: 'password',
},
});
cy.visit('/');
cy.intercept('POST', '/auth/simple/login', req => {
expect(req.body.username).to.equal(username);
expect(req.body.password).to.equal(password);
expect(req.body.username).to.equal('admin');
expect(req.body.password).to.equal('unleash4all');
}).as('passwordLogin');
cy.get('[data-test="LOGIN_EMAIL_ID"]').type(username);
cy.get('[data-test="LOGIN_PASSWORD_ID"]').type(password);
cy.get('[data-test="LOGIN_EMAIL_ID"]').type('admin');
cy.get('[data-test="LOGIN_PASSWORD_ID"]').type('unleash4all');
cy.get("[data-test='LOGIN_BUTTON']").click();
});
@ -40,15 +38,15 @@ describe('auth', () => {
type: 'password',
},
});
cy.visit('/');
cy.get('[data-test="LOGIN_EMAIL_ID"]').should('not.exist');
cy.get('[data-test="LOGIN_PASSWORD_ID"]').should('not.exist');
});
it('renders google auth when options are specified', () => {
const ssoPath = '/auth/google/login';
cy.intercept('GET', '/api/admin/user', {
statusCode: 401,
body: {
@ -77,6 +75,7 @@ describe('auth', () => {
it('renders oidc auth when options are specified', () => {
const ssoPath = '/auth/oidc/login';
cy.intercept('GET', '/api/admin/user', {
statusCode: 401,
body: {
@ -105,6 +104,7 @@ describe('auth', () => {
it('renders saml auth when options are specified', () => {
const ssoPath = '/auth/saml/login';
cy.intercept('GET', '/api/admin/user', {
statusCode: 401,
body: {
@ -149,6 +149,7 @@ describe('auth', () => {
it('renders demo auth correctly', () => {
const email = 'hello@hello.com';
cy.intercept('GET', '/api/admin/user', {
statusCode: 401,
body: {
@ -171,6 +172,7 @@ describe('auth', () => {
it('renders email auth correctly', () => {
const email = 'hello@hello.com';
cy.intercept('GET', '/api/admin/user', {
statusCode: 401,
body: {

View File

@ -5,12 +5,13 @@ import { activeSplashIds } from '../../../src/component/splash/splash';
const randomId = String(Math.random()).split('.')[1];
const featureToggleName = `unleash-e2e-${randomId}`;
const enterprise = Boolean(Cypress.env('ENTERPRISE'));
const passwordAuth = Cypress.env('PASSWORD_AUTH');
const authToken = Cypress.env('AUTH_TOKEN');
const baseUrl = Cypress.config().baseUrl;
let strategyId = '';
const AUTH_USER = Cypress.env('AUTH_USER');
const AUTH_PASSWORD = Cypress.env('AUTH_PASSWORD');
const ENTERPRISE = Boolean(Cypress.env('ENTERPRISE'));
describe('feature', () => {
before(() => {
// Visit all splash pages to mark them as seen.
@ -23,29 +24,24 @@ describe('feature', () => {
cy.request({
method: 'DELETE',
url: `${baseUrl}/api/admin/features/${featureToggleName}`,
headers: { Authorization: authToken },
});
cy.request({
method: 'DELETE',
url: `${baseUrl}/api/admin/archive/${featureToggleName}`,
headers: { Authorization: authToken },
});
});
beforeEach(() => {
disableFeatureStrategiesProductionGuard();
cy.visit('/');
cy.get('[data-test="LOGIN_EMAIL_ID"]').type(AUTH_USER);
if (passwordAuth) {
cy.get('[data-test="LOGIN_EMAIL_ID"]').type('test@test.com');
cy.get('[data-test="LOGIN_PASSWORD_ID"]').type('qY70$NDcJNXA');
cy.get("[data-test='LOGIN_BUTTON']").click();
} else {
cy.get('[data-test=LOGIN_EMAIL_ID]').type('test@unleash-e2e.com');
cy.get('[data-test=LOGIN_BUTTON]').click();
if (AUTH_PASSWORD) {
cy.get('[data-test="LOGIN_PASSWORD_ID"]').type(AUTH_PASSWORD);
}
// Wait for the login redirects to complete.
cy.get("[data-test='LOGIN_BUTTON']").click();
// Wait for the login redirect to complete.
cy.get('[data-test=HEADER_USER_AVATAR');
});
@ -107,7 +103,7 @@ describe('feature', () => {
.click()
.type('{leftarrow}'.repeat(20));
if (enterprise) {
if (ENTERPRISE) {
cy.get('[data-test=ADD_CONSTRAINT_ID]').click();
cy.get('[data-test=CONSTRAINT_AUTOCOMPLETE_ID]')
.type('{downArrow}'.repeat(1))
@ -124,7 +120,7 @@ describe('feature', () => {
expect(req.body.parameters.stickiness).to.equal('default');
expect(req.body.parameters.rollout).to.equal('30');
if (enterprise) {
if (ENTERPRISE) {
expect(req.body.constraints.length).to.equal(1);
} else {
expect(req.body.constraints.length).to.equal(0);
@ -170,7 +166,7 @@ describe('feature', () => {
expect(req.body.parameters.stickiness).to.equal('sessionId');
expect(req.body.parameters.rollout).to.equal('60');
if (enterprise) {
if (ENTERPRISE) {
expect(req.body.constraints.length).to.equal(1);
} else {
expect(req.body.constraints.length).to.equal(0);
@ -210,7 +206,7 @@ describe('feature', () => {
`/projects/default/features/${featureToggleName}/strategies/create?environmentId=development&strategyName=userWithId`
);
if (enterprise) {
if (ENTERPRISE) {
cy.get('[data-test=ADD_CONSTRAINT_ID]').click();
cy.get('[data-test=CONSTRAINT_AUTOCOMPLETE_ID]')
.type('{downArrow}'.repeat(1))
@ -233,7 +229,7 @@ describe('feature', () => {
expect(req.body.parameters.userIds.length).to.equal(11);
if (enterprise) {
if (ENTERPRISE) {
expect(req.body.constraints.length).to.equal(1);
} else {
expect(req.body.constraints.length).to.equal(0);

View File

@ -33,9 +33,7 @@
"prepare": "yarn run build",
"fmt": "prettier src --write --loglevel warn",
"fmt:check": "prettier src --check",
"e2e": "yarn run cypress open --config baseUrl='http://localhost:3000' --env PASSWORD_AUTH=true,AUTH_TOKEN=$AUTH_TOKEN",
"e2e:heroku": "yarn run cypress open --config baseUrl='http://localhost:3000' --env PASSWORD_AUTH=false,AUTH_TOKEN=$AUTH_TOKEN",
"e2e:enterprise": "yarn run cypress open --config baseUrl='http://localhost:3000' --env PASSWORD_AUTH=true,ENTERPRISE=true,AUTH_TOKEN=$AUTH_TOKEN"
"e2e": "yarn run cypress open --config baseUrl='http://localhost:3000' --env AUTH_USER=admin,AUTH_PASSWORD=unleash4all"
},
"devDependencies": {
"@material-ui/core": "4.12.3",