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

[Backport 2.19] Fix CI failures related to security plugin download #2175

Merged
merged 1 commit into from
Jan 31, 2025
Merged
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
2 changes: 1 addition & 1 deletion .github/workflows/cypress-test-multiauth-e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ jobs:
config:
idp:
entity_id: urn:example:idp
metadata_url: http://localhost:7000/metadata
metadata_url: http://[::1]:7000/metadata
sp:
entity_id: https://localhost:9200
kibana_url: http://localhost:5601${{ matrix.basePath }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/cypress-test-saml-e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ jobs:
config:
idp:
entity_id: urn:example:idp
metadata_url: http://localhost:7000/metadata
metadata_url: http://[::1]:7000/metadata
sp:
entity_id: https://localhost:9200
kibana_url: http://localhost:5601${{ matrix.basePath }}
Expand Down
146 changes: 116 additions & 30 deletions test/cypress/e2e/saml/saml_auth_test.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,36 +29,70 @@

// Avoid Cypress lock onto the ipv4 range, so fake `visit()` before `request()`.
// See: https://github.com/cypress-io/cypress/issues/25397#issuecomment-1402556488
cy.visit(`http://localhost:5601${basePath}`);
if (Cypress.env('loginMethod') === 'saml_multiauth') {
cy.visit(`http://localhost:5601${basePath}`);
} else {
cy.request(`http://localhost:5601${basePath}`);
}

cy.createRoleMapping(ALL_ACCESS_ROLE, samlUserRoleMapping);
cy.clearCookies();
cy.clearLocalStorage();
});

beforeEach(() => {
cy.intercept('GET', '**/**', (req) => {
// Replace [::1] with localhost in the request URL and headers
if (req.url.includes('[::1]')) {
req.url = req.url.replace(/\[::1\]/g, 'localhost');
}

req.on('response', (res) => {
if (res && res.headers) {
Object.keys(res.headers).forEach((key) => {
if (typeof res.headers[key] === 'string' && res.headers[key].includes('[::1]')) {
res.headers[key] = res.headers[key].replace(/\[::1\]/g, 'localhost');
}
});
}
return res;
});
});
});

afterEach(() => {
cy.clearCookies();
cy.clearLocalStorage();
});

describe('Log in via SAML', () => {
const samlLogin = () => {
if (Cypress.env('loginMethod') === 'saml_multiauth') {
cy.loginWithSamlMultiauth();
} else {
cy.loginWithSaml();
}
const loginWithSamlMultiauth = () => {
cy.get('a[aria-label="saml_login_button"]').should('be.visible');
cy.get('a[aria-label="saml_login_button"]').should('be.visible').click();
cy.origin('http://localhost:7000', () => {
cy.get('input[id=userName]').should('be.visible');
cy.get('button[id=btn-sign-in]').should('be.visible').click();
});
};

it('Login to app/opensearch_dashboards_overview#/ when SAML is enabled', () => {
localStorage.setItem('opendistro::security::tenant::saved', '"__user__"');
localStorage.setItem('home:newThemeModal:show', 'false');

cy.visit(`http://localhost:5601${basePath}/app/opensearch_dashboards_overview`, {
failOnStatusCode: false,
});

samlLogin();
if (Cypress.env('loginMethod') === 'saml_multiauth') {
cy.visit(`http://localhost:5601${basePath}/app/opensearch_dashboards_overview`, {
failOnStatusCode: false,
});
loginWithSamlMultiauth();
} else {
cy.origin('http://localhost:7000', { args: { basePath } }, ({ basePath }) => {
cy.visit(`http://localhost:5601${basePath}/app/opensearch_dashboards_overview`, {
failOnStatusCode: false,
});
cy.get('input[id=userName]').should('be.visible');
cy.get('button[id=btn-sign-in]').should('be.visible').click();
});
}

cy.get('#osdOverviewPageHeader__title').should('be.visible');
cy.getCookie('security_authentication').should('exist');
Expand All @@ -68,11 +102,20 @@
localStorage.setItem('opendistro::security::tenant::saved', '"__user__"');
localStorage.setItem('home:newThemeModal:show', 'false');

cy.visit(`http://localhost:5601${basePath}/app/dev_tools#/console`, {
failOnStatusCode: false,
});

samlLogin();
if (Cypress.env('loginMethod') === 'saml_multiauth') {
cy.visit(`http://localhost:5601${basePath}/app/dev_tools#/console`, {
failOnStatusCode: false,
});
loginWithSamlMultiauth();
} else {
cy.origin('http://localhost:7000', { args: { basePath } }, ({ basePath }) => {
cy.visit(`http://localhost:5601${basePath}/app/dev_tools#/console`, {
failOnStatusCode: false,
});
cy.get('input[id=userName]').should('be.visible');
cy.get('button[id=btn-sign-in]').should('be.visible').click();
});
}

cy.get('a.euiBreadcrumb--last').contains('Dev Tools');
cy.getCookie('security_authentication').should('exist');
Expand All @@ -84,11 +127,20 @@

const urlWithHash = `http://localhost:5601${basePath}/app/security-dashboards-plugin#/getstarted`;

cy.visit(urlWithHash, {
failOnStatusCode: false,
});

samlLogin();
if (Cypress.env('loginMethod') === 'saml_multiauth') {
cy.visit(urlWithHash, {
failOnStatusCode: false,
});
loginWithSamlMultiauth();
} else {
cy.origin('http://localhost:7000', { args: { urlWithHash } }, ({ urlWithHash }) => {
cy.visit(urlWithHash, {
failOnStatusCode: false,
});
cy.get('input[id=userName]').should('be.visible');
cy.get('button[id=btn-sign-in]').should('be.visible').click();
});
}

cy.get('h1').contains('Get started');
cy.getCookie('security_authentication').should('exist');
Expand All @@ -97,14 +149,23 @@
it('Tenancy persisted after logout in SAML', () => {
localStorage.setItem('home:newThemeModal:show', 'false');

cy.visit(`http://localhost:5601${basePath}/app/opensearch_dashboards_overview`, {
failOnStatusCode: false,
});

samlLogin();
if (Cypress.env('loginMethod') === 'saml_multiauth') {
cy.visit(`http://localhost:5601${basePath}/app/opensearch_dashboards_overview`, {
failOnStatusCode: false,
});
loginWithSamlMultiauth();
} else {
cy.origin('http://localhost:7000', { args: { basePath } }, ({ basePath }) => {
cy.visit(`http://localhost:5601${basePath}/app/opensearch_dashboards_overview`, {
failOnStatusCode: false,
});
cy.get('input[id=userName]').should('be.visible');
cy.get('button[id=btn-sign-in]').should('be.visible').click();
});
}

cy.get('#private').should('be.enabled');
cy.get('#private').click({ force: true });

Check warning on line 168 in test/cypress/e2e/saml/saml_auth_test.spec.js

View workflow job for this annotation

GitHub Actions / Run unit tests (ubuntu-latest)

Do not use force on click and type calls

Check warning on line 168 in test/cypress/e2e/saml/saml_auth_test.spec.js

View workflow job for this annotation

GitHub Actions / Run unit tests (ubuntu-latest)

Do not use force on click and type calls

Check warning on line 168 in test/cypress/e2e/saml/saml_auth_test.spec.js

View workflow job for this annotation

GitHub Actions / Run unit tests (windows-latest)

Do not use force on click and type calls

Check warning on line 168 in test/cypress/e2e/saml/saml_auth_test.spec.js

View workflow job for this annotation

GitHub Actions / Run unit tests (windows-latest)

Do not use force on click and type calls

cy.get('button[data-test-subj="confirm"]').click();

Expand All @@ -114,7 +175,20 @@

cy.get('button[data-test-subj^="log-out-"]').click();

samlLogin();
if (Cypress.env('loginMethod') === 'saml_multiauth') {
cy.visit(`http://localhost:5601${basePath}/app/opensearch_dashboards_overview`, {
failOnStatusCode: false,
});
loginWithSamlMultiauth();
} else {
cy.origin('http://localhost:7000', { args: { basePath } }, ({ basePath }) => {
cy.visit(`http://localhost:5601${basePath}/app/opensearch_dashboards_overview`, {
failOnStatusCode: false,
});
cy.get('input[id=userName]').should('be.visible');
cy.get('button[id=btn-sign-in]').should('be.visible').click();
});
}

cy.get('#user-icon-btn').should('be.visible');
cy.get('#user-icon-btn').click();
Expand All @@ -131,8 +205,20 @@
// since the Shorten URL api is return's set-cookie header for admin user.
cy.clearCookies().then(() => {
const gotoUrl = `http://localhost:5601${basePath}/goto/${response.urlId}?security_tenant=global`;
cy.visit(gotoUrl);
samlLogin();
if (Cypress.env('loginMethod') === 'saml_multiauth') {
cy.visit(gotoUrl, {
failOnStatusCode: false,
});
loginWithSamlMultiauth();
} else {
cy.origin('http://localhost:7000', { args: { gotoUrl } }, ({ gotoUrl }) => {
cy.visit(gotoUrl, {
failOnStatusCode: false,
});
cy.get('input[id=userName]').should('be.visible');
cy.get('button[id=btn-sign-in]').should('be.visible').click();
});
}
cy.getCookie('security_authentication').should('exist');
});
});
Expand Down
12 changes: 0 additions & 12 deletions test/cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,18 +79,6 @@ Cypress.Commands.add('createRoleMapping', (roleID, rolemappingJson) => {
});
});

Cypress.Commands.add('loginWithSaml', () => {
cy.get('input[id=userName]').should('be.visible');
cy.get('button[id=btn-sign-in]').should('be.visible').click();
});

Cypress.Commands.add('loginWithSamlMultiauth', () => {
cy.get('a[aria-label="saml_login_button"]').should('be.visible');
cy.get('a[aria-label="saml_login_button"]').should('be.visible').click();
cy.get('input[id=userName]').should('be.visible');
cy.get('button[id=btn-sign-in]').should('be.visible').click();
});

if (Cypress.env('LOGIN_AS_ADMIN')) {
// Define custom cy.visit() only if LOGIN_AS_ADMIN is true
Cypress.Commands.overwrite('visit', (orig, url, options = {}) => {
Expand Down
Loading