Skip to content

Commit

Permalink
Replace the SAML default embedded route redirects with a new default …
Browse files Browse the repository at this point in the history
…route redirect. (#171)

* Saml url default path changes to wz-home

* Added pretier

* Resolve test

* Repair tests
  • Loading branch information
JuanGarriuz authored Jan 23, 2025
1 parent fb160a3 commit d82d4cf
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 13 deletions.
7 changes: 3 additions & 4 deletions server/auth/types/saml/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export class SamlAuthRoutes {
if (request.auth.isAuthenticated) {
return response.redirected({
headers: {
location: `${this.coreSetup.http.basePath.serverBasePath}/app/opensearch-dashboards`,
location: `${this.coreSetup.http.basePath.serverBasePath}/app/wz-home`,
},
});
}
Expand Down Expand Up @@ -118,8 +118,7 @@ export class SamlAuthRoutes {
if (cookie) {
requestId = cookie.saml?.requestId || '';
nextUrl =
cookie.saml?.nextUrl ||
`${this.coreSetup.http.basePath.serverBasePath}/app/opensearch-dashboards`;
cookie.saml?.nextUrl || `${this.coreSetup.http.basePath.serverBasePath}/app/wz-home`;
redirectHash = cookie.saml?.redirectHash || false;
}
if (!requestId) {
Expand Down Expand Up @@ -251,7 +250,7 @@ export class SamlAuthRoutes {
this.sessionStorageFactory.asScoped(request).set(cookie);
return response.redirected({
headers: {
location: `${this.coreSetup.http.basePath.serverBasePath}/app/opensearch-dashboards`,
location: `${this.coreSetup.http.basePath.serverBasePath}/app/wz-home`,
},
});
} catch (error) {
Expand Down
3 changes: 1 addition & 2 deletions server/auth/types/saml/saml_auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@ export class SamlAuthentication extends AuthenticationType {

private generateNextUrl(request: OpenSearchDashboardsRequest): string {
let path =
this.coreSetup.http.basePath.serverBasePath +
(request.url.pathname || '/app/opensearch-dashboards');
this.coreSetup.http.basePath.serverBasePath + (request.url.pathname || '/app/wz-home');
if (request.url.search) {
path += request.url.search;
}
Expand Down
14 changes: 7 additions & 7 deletions test/cypress/e2e/saml/saml_auth_test.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ before(() => {

// 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}`);
cy.visit(`http://localhost:7000${basePath}`);

cy.createRoleMapping(ALL_ACCESS_ROLE, samlUserRoleMapping);
cy.clearCookies();
Expand All @@ -50,11 +50,11 @@ describe('Log in via SAML', () => {
}
};

it('Login to app/opensearch_dashboards_overview#/ when SAML is enabled', () => {
it('Login to app/wz-home_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`, {
cy.visit(`http://localhost:7000${basePath}/app/wz-home_overview`, {
failOnStatusCode: false,
});

Expand All @@ -68,7 +68,7 @@ describe('Log in via SAML', () => {
localStorage.setItem('opendistro::security::tenant::saved', '"__user__"');
localStorage.setItem('home:newThemeModal:show', 'false');

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

Expand All @@ -82,7 +82,7 @@ describe('Log in via SAML', () => {
localStorage.setItem('opendistro::security::tenant::saved', '"__user__"');
localStorage.setItem('home:newThemeModal:show', 'false');

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

cy.visit(urlWithHash, {
failOnStatusCode: false,
Expand All @@ -97,7 +97,7 @@ describe('Log in via SAML', () => {
it('Tenancy persisted after logout in SAML', () => {
localStorage.setItem('home:newThemeModal:show', 'false');

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

Expand Down Expand Up @@ -133,7 +133,7 @@ describe('Log in via SAML', () => {
// We need to explicitly clear cookies,
// 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`;
const gotoUrl = `http://localhost:7000${basePath}/goto/${response.urlId}?security_tenant=global`;
cy.visit(gotoUrl);
samlLogin();
cy.getCookie('security_authentication').should('exist');
Expand Down

0 comments on commit d82d4cf

Please sign in to comment.