Skip to content

Commit

Permalink
fix: Only redirect to relative paths when authentication expires (#18714
Browse files Browse the repository at this point in the history
)

* Only redirect to relative paths

* Fix redirect test
  • Loading branch information
geido authored Feb 15, 2022
1 parent 342c55b commit 8027f5f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,8 @@ export default class SupersetClientClass {
}

redirectUnauthorized() {
window.location.href = `/login?next=${window.location.href}`;
window.location.href = `/login?next=${
window.location.pathname + window.location.search
}`;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -501,11 +501,16 @@ describe('SupersetClientClass', () => {

it('should redirect Unauthorized', async () => {
const mockRequestUrl = 'https://host/get/url';
const mockRequestPath = '/get/url';
const mockRequestSearch = '?param=1&param=2';
const { location } = window;
// @ts-ignore
delete window.location;
// @ts-ignore
window.location = { href: mockRequestUrl };
window.location = {
pathname: mockRequestPath,
search: mockRequestSearch,
};
const authSpy = jest
.spyOn(SupersetClientClass.prototype, 'ensureAuth')
.mockImplementation();
Expand All @@ -523,7 +528,9 @@ describe('SupersetClientClass', () => {
error = err;
} finally {
const redirectURL = window.location.href;
expect(redirectURL).toBe(`/login?next=${mockRequestUrl}`);
expect(redirectURL).toBe(
`/login?next=${mockRequestPath + mockRequestSearch}`,
);
expect(error.status).toBe(401);
}

Expand Down

0 comments on commit 8027f5f

Please sign in to comment.