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

Update e2e tests #859

Draft
wants to merge 9 commits into
base: dev
Choose a base branch
from
Draft
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
18 changes: 9 additions & 9 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -204,15 +204,15 @@ jobs:
org.opencontainers.image.vendor=RADAR-base
org.opencontainers.image.licenses=Apache-2.0

# # placeholder for testing
# - name: End to end tests (docker image)
# id: e2e-prod-docker
# run: |
# cp src/test/resources/config/keystore.p12 src/main/docker/etc/config
# ./gradlew -Pprod buildDocker -x test -x javadocJar
# docker-compose -f src/main/docker/app.yml up -d
# yarn run e2e-prod
# docker-compose -f src/main/docker/app.yml down -v
# placeholder for testing
- name: End to end tests (docker image)
id: e2e-prod-docker
run: |
cp src/test/resources/config/keystore.p12 src/main/docker/etc/config
./gradlew -Pprod buildDocker -x test -x javadocJar
docker-compose -f src/main/docker/managementportal_local/docker-compose.yml up -d
yarn run e2e-prod
docker-compose -f src/main/docker/managementportal_local/docker-compose.yml down -v

# Temp fix
# https://github.com/docker/build-push-action/issues/252
Expand Down
10 changes: 8 additions & 2 deletions cypress.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
{
"retries": 3,
"integrationFolder": "src/test/javascript/e2e/cypress/integration",
"supportFile": false,
"supportFile": "src/test/javascript/e2e/cypress/support/index.js",
"video": false,
"experimentalSessionSupport": true,
"screenshotsFolder": "src/test/javascript/e2e/cypress/screenshots",
"pluginsFile": false,
"fixturesFolder": false,
"baseUrl": "http://localhost:8081"
"baseUrl": "http://localhost:8081",
"experimentalSessionAndOrigin": true,
"chromeWebSecurity": false,
"env": {
"username": "[email protected]",
"secret": "secret123"
}
}
2 changes: 1 addition & 1 deletion src/main/docker/app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ services:
oryd/kratos-selfservice-ui-node
environment:
- LOG_LEAK_SENSITIVE_VALUES=true
- KRATOS_PUBLIC_URL=http://kratos:4433
- KRATOS_PUBLIC_URL=http://localhost:4433
- KRATOS_ADMIN_URL=http://kratos:4434
- SECURITY_MODE=standalone
- KRATOS_BROWSER_URL=http://127.0.0.1:4433
Expand Down
20 changes: 10 additions & 10 deletions src/main/docker/etc/config/kratos/kratos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ dsn: memory

serve:
public:
base_url: http://127.0.0.1:4433/
base_url: http://localhost:4433/
admin:
base_url: http://kratos:4434/

selfservice:
default_browser_return_url: http://127.0.0.1:3000/
default_browser_return_url: http://localhost:3000/
allowed_return_urls:
- "http://127.0.0.1:3000/"
- "http://127.0.0.1:8080/"
Expand Down Expand Up @@ -43,34 +43,34 @@ selfservice:

flows:
error:
ui_url: http://127.0.0.1:3000/error
ui_url: http://localhost:3000/error

settings:
ui_url: http://127.0.0.1:3000/settings
ui_url: http://localhost:3000/settings

recovery:
enabled: true
ui_url: http://127.0.0.1:3000/recovery
ui_url: http://localhost:3000/recovery
use: link

verification:
# our current flow necessitates that users reset their password after they activate an account in managementportal,
# this works as verification
ui_url: http://127.0.0.1:3000/verification
ui_url: http://localhost:3000/verification
enabled: true
use: link
after:
default_browser_return_url: http://127.0.0.1:3000
default_browser_return_url: http://localhost:3000

logout:
after:
default_browser_return_url: http://127.0.0.1:3000/login
default_browser_return_url: http://localhost:3000/login

login:
ui_url: http://127.0.0.1:3000/login
ui_url: http://localhost:3000/login

registration:
ui_url: http://127.0.0.1:3000/registration
ui_url: http://localhost:3000/registration
after:
password:
hooks:
Expand Down
2 changes: 1 addition & 1 deletion src/main/docker/ory_stack.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ services:
- KRATOS_PUBLIC_URL=http://kratos:4433
- KRATOS_ADMIN_URL=http://kratos:4434
- SECURITY_MODE=standalone
- KRATOS_BROWSER_URL=http://127.0.0.1:4433
- KRATOS_BROWSER_URL=http://localhost:4433
- COOKIE_SECRET=unsafe_cookie_secret
- CSRF_COOKIE_NAME=radar
- CSRF_COOKIE_SECRET=unsafe_csrf_cookie_secret
Expand Down
Original file line number Diff line number Diff line change
@@ -1,43 +1,17 @@
import * as navBarPage from '../util/nav-bar';
import { login } from "../util/login";
import { login } from '../util/login';

describe('account', () => {
beforeEach(() => {
cy.visit('./');
});

it('should fail to login with bad password', () => {
cy.get('h1').first()
.should('have.text', 'Welcome to RADAR Management Portal');

navBarPage.clickOnAccountMenu();
navBarPage.clickOnSignIn();

cy.get('#username').type('admin');
cy.get('#password').type('foo');
cy.get('button[type=submit]').click();

let msg = 'Failed to sign in! Please check your credentials and try again.';
cy.get('.alert-danger').first().should('have.text', msg);
cy.get('#username').clear();
cy.get('#password').clear();
before(() => {
login();
});

it('should login successfully with admin account', () => {
login('admin', 'admin')
cy.get('.alert-success').first()
.should('have.text', 'You are logged in as user "admin".');
});

it('should be able to update settings', () => {
login('admin', 'admin')
navBarPage.clickOnAccountMenu();
navBarPage.clickOnEntity('settings');

cy.get('h2').first()
.should('have.text', 'User settings for [admin]');

cy.get('button[type=submit]').click();

cy.get('.alert-success').first()
.should('have.text', 'Settings saved!');
cy.get('#account-menu').first()
.should('have.text', 'Account');
});
});
20 changes: 4 additions & 16 deletions src/test/javascript/e2e/cypress/integration/util/login.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,5 @@
import * as navBarPage from "./nav-bar";

export function login(username = "admin", password = "admin") {
cy.session([username, password], () => {
cy.visit('/');
navBarPage.clickOnAccountMenu();
navBarPage.clickOnSignIn();
cy.get('.modal-content h1').first().should('have.text', 'Sign in');
cy.get('#username').type(username);
cy.get('#password').type(password);
cy.get('button[type=submit]').click();
cy.get('.alert-success span').should('exist');
}, { validate() {
cy.getCookie('SESSION').should('exist')}
})
cy.visit('/');
export function login() {
cy.login(Cypress.env('username'), Cypress.env('secret'));
cy.wait(2000);
cy.visit('managementportal/');
}
43 changes: 43 additions & 0 deletions src/test/javascript/e2e/cypress/support/commands.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
export const IDENTITY_SERVER = 'http://localhost:4433'

Cypress.Commands.add('initiateLoginFlow', () => {
return cy.request({
method: 'GET',
url: IDENTITY_SERVER + '/self-service/login/browser',
followRedirect: false
}).then((response) => {
const redirectUrl = new URL(response.headers['location']);
const flow = redirectUrl.searchParams.get('flow');
return cy.request({
method: 'GET',
url: redirectUrl.href
}).then((htmlResponse) => {
const csrfToken = Cypress.$(htmlResponse.body).find('input[name="csrf_token"]').val();
return { flow, csrfToken };
});
});
});

Cypress.Commands.add('getCSRFToken', () => {
return cy.get('input[name="csrf_token"]').then((input) => input.val());
});

Cypress.Commands.add('login', (identifier, password) => {
cy.session([identifier, password], () => {
cy.initiateLoginFlow().then(({flow, csrfToken}) => {
cy.request({
method: 'POST',
url: IDENTITY_SERVER + `/self-service/login?flow=${flow}`,
body: {
identifier: identifier,
password: password,
csrf_token: csrfToken,
method: 'password'
},
headers: {
'Content-Type': 'application/json'
}
});
});
});
});
1 change: 1 addition & 0 deletions src/test/javascript/e2e/cypress/support/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import './commands';
Loading