You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by jl...@apache.org on 2026/07/22 17:34:50 UTC
(superset) branch master updated: fix(superset_app_root): when used with oauth (#38033)
This is an automated email from the ASF dual-hosted git repository.
sadpandajoe pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/superset.git
The following commit(s) were added to refs/heads/master by this push:
new 894c0191d64 fix(superset_app_root): when used with oauth (#38033)
894c0191d64 is described below
commit 894c0191d647bffaba25b22d94fdd9710dca829e
Author: Grégoire <gr...@gmail.com>
AuthorDate: Wed Jul 22 19:34:43 2026 +0200
fix(superset_app_root): when used with oauth (#38033)
Signed-off-by: Grégoire Bellon-Gervais <gr...@docaposte.fr>
Co-authored-by: Evan Rusackas <ev...@preset.io>
Co-authored-by: Claude Opus 4.8 <no...@anthropic.com>
---
superset-frontend/src/features/home/RightMenu.tsx | 4 +-
superset-frontend/src/pages/Login/Login.test.tsx | 281 +++++++++++++++++----
superset-frontend/src/pages/Login/index.tsx | 5 +-
.../src/pages/Register/Register.test.tsx | 105 +++++++-
superset-frontend/src/utils/pathUtils.test.ts | 18 ++
superset/app.py | 8 +
6 files changed, 363 insertions(+), 58 deletions(-)
diff --git a/superset-frontend/src/features/home/RightMenu.tsx b/superset-frontend/src/features/home/RightMenu.tsx
index ea19845e2f4..9e69b469e80 100644
--- a/superset-frontend/src/features/home/RightMenu.tsx
+++ b/superset-frontend/src/features/home/RightMenu.tsx
@@ -532,9 +532,7 @@ const RightMenu = ({
userItems.push({
key: 'logout',
label: (
- <Typography.Link
- href={ensureAppRoot(navbarRight.user_logout_url)}
- >
+ <Typography.Link href={navbarRight.user_logout_url}>
{t('Logout')}
</Typography.Link>
),
diff --git a/superset-frontend/src/pages/Login/Login.test.tsx b/superset-frontend/src/pages/Login/Login.test.tsx
index 3a20d9c70b8..e2bd6c3be95 100644
--- a/superset-frontend/src/pages/Login/Login.test.tsx
+++ b/superset-frontend/src/pages/Login/Login.test.tsx
@@ -31,27 +31,26 @@ const defaultBootstrapData = {
},
};
-const mockApplicationRoot = jest.fn<string, []>(() => '');
+jest.mock('src/utils/getBootstrapData', () => ({
+ __esModule: true,
+ default: jest.fn(() => defaultBootstrapData),
+}));
-jest.mock('src/utils/getBootstrapData', () => {
- const actual = jest.requireActual<
- typeof import('src/utils/getBootstrapData')
- >('src/utils/getBootstrapData');
- return {
- __esModule: true,
- ...actual,
- default: jest.fn(() => defaultBootstrapData),
- applicationRoot: () => mockApplicationRoot(),
- };
-});
+const mockEnsureAppRoot = jest.fn((...args: string[]) => args[0]);
+jest.mock('src/utils/pathUtils', () => ({
+ ensureAppRoot: (...args: string[]) => mockEnsureAppRoot(...args),
+}));
const mockGetBootstrapData = getBootstrapData as jest.Mock;
beforeEach(() => {
mockGetBootstrapData.mockReturnValue(defaultBootstrapData);
- mockApplicationRoot.mockReturnValue('');
+ mockEnsureAppRoot.mockClear();
+ mockEnsureAppRoot.mockImplementation((path: string) => path);
});
+// --- DB / LDAP Auth tests ---
+
test('should render login form elements', () => {
render(<Login />, { useRedux: true });
expect(screen.getByTestId('login-form')).toBeInTheDocument();
@@ -92,51 +91,231 @@ test('should render SAML provider buttons', () => {
expect(screen.getByText('Sign in with Onelogin')).toBeInTheDocument();
});
-const samlBootstrapData = {
- common: {
- conf: {
- AUTH_TYPE: 5,
- AUTH_PROVIDERS: [{ name: 'okta', icon: 'okta' }],
- AUTH_USER_REGISTRATION: false,
+test('should call ensureAppRoot for login endpoint on DB auth', () => {
+ render(<Login />, { useRedux: true });
+ expect(mockEnsureAppRoot).toHaveBeenCalledWith('/login/');
+});
+
+// --- OAuth tests ---
+
+test('should render OAuth provider buttons when AUTH_TYPE is OAuth', () => {
+ mockGetBootstrapData.mockReturnValue({
+ common: {
+ conf: {
+ AUTH_TYPE: 4,
+ AUTH_PROVIDERS: [
+ { name: 'google', icon: 'google' },
+ { name: 'github', icon: 'github' },
+ ],
+ AUTH_USER_REGISTRATION: false,
+ },
},
- },
-};
+ });
+ render(<Login />, { useRedux: true });
+ expect(
+ screen.getByRole('link', { name: /Sign in with Google/ }),
+ ).toBeInTheDocument();
+ expect(
+ screen.getByRole('link', { name: /Sign in with Github/ }),
+ ).toBeInTheDocument();
+});
+
+test('should not render username/password fields for OAuth auth type', () => {
+ mockGetBootstrapData.mockReturnValue({
+ common: {
+ conf: {
+ AUTH_TYPE: 4,
+ AUTH_PROVIDERS: [{ name: 'google', icon: 'google' }],
+ AUTH_USER_REGISTRATION: false,
+ },
+ },
+ });
+ render(<Login />, { useRedux: true });
+ expect(screen.queryByTestId('username-input')).not.toBeInTheDocument();
+ expect(screen.queryByTestId('password-input')).not.toBeInTheDocument();
+ expect(screen.queryByTestId('login-button')).not.toBeInTheDocument();
+});
+
+test('should call ensureAppRoot for OAuth provider login URLs', () => {
+ mockGetBootstrapData.mockReturnValue({
+ common: {
+ conf: {
+ AUTH_TYPE: 4,
+ AUTH_PROVIDERS: [
+ { name: 'google', icon: 'google' },
+ { name: 'github', icon: 'github' },
+ ],
+ AUTH_USER_REGISTRATION: false,
+ },
+ },
+ });
+ render(<Login />, { useRedux: true });
+ expect(mockEnsureAppRoot).toHaveBeenCalledWith('/login/google');
+ expect(mockEnsureAppRoot).toHaveBeenCalledWith('/login/github');
+});
+
+// --- OID tests ---
-test('provider login links are root-relative on root deployments', () => {
- mockGetBootstrapData.mockReturnValue(samlBootstrapData);
+test('should render OID provider buttons when AUTH_TYPE is OID', () => {
+ mockGetBootstrapData.mockReturnValue({
+ common: {
+ conf: {
+ AUTH_TYPE: 0,
+ AUTH_PROVIDERS: [
+ { name: 'google', url: 'https://accounts.google.com' },
+ ],
+ AUTH_USER_REGISTRATION: false,
+ },
+ },
+ });
render(<Login />, { useRedux: true });
expect(
- screen.getByRole('link', { name: /sign in with okta/i }),
- ).toHaveAttribute('href', '/login/okta');
+ screen.getByRole('link', { name: /Sign in with Google/ }),
+ ).toBeInTheDocument();
});
-test('provider login links carry the application root on subdirectory deployments', () => {
- mockApplicationRoot.mockReturnValue('/superset');
- mockGetBootstrapData.mockReturnValue(samlBootstrapData);
+test('should not render username/password fields for OID auth type', () => {
+ mockGetBootstrapData.mockReturnValue({
+ common: {
+ conf: {
+ AUTH_TYPE: 0,
+ AUTH_PROVIDERS: [
+ { name: 'google', url: 'https://accounts.google.com' },
+ ],
+ AUTH_USER_REGISTRATION: false,
+ },
+ },
+ });
+ render(<Login />, { useRedux: true });
+ expect(screen.queryByTestId('username-input')).not.toBeInTheDocument();
+ expect(screen.queryByTestId('password-input')).not.toBeInTheDocument();
+});
+
+// --- Registration button tests ---
+
+test('should render register button when AUTH_USER_REGISTRATION is enabled', () => {
+ mockGetBootstrapData.mockReturnValue({
+ common: {
+ conf: {
+ AUTH_TYPE: 1,
+ AUTH_PROVIDERS: [],
+ AUTH_USER_REGISTRATION: true,
+ },
+ },
+ });
+ render(<Login />, { useRedux: true });
+ expect(screen.getByTestId('register-button')).toBeInTheDocument();
+});
+
+test('should not render register button when AUTH_USER_REGISTRATION is disabled', () => {
+ render(<Login />, { useRedux: true });
+ expect(screen.queryByTestId('register-button')).not.toBeInTheDocument();
+});
+
+// --- ensureAppRoot / SUPERSET_APP_ROOT tests ---
+
+test('should prefix OAuth provider URLs with application root', () => {
+ mockEnsureAppRoot.mockImplementation(
+ (path: string) => `/superset${path.startsWith('/') ? path : `/${path}`}`,
+ );
+ mockGetBootstrapData.mockReturnValue({
+ common: {
+ conf: {
+ AUTH_TYPE: 4,
+ AUTH_PROVIDERS: [{ name: 'google', icon: 'google' }],
+ AUTH_USER_REGISTRATION: false,
+ },
+ },
+ });
+ render(<Login />, { useRedux: true });
+ const googleLink = screen.getByRole('link', {
+ name: /Sign in with Google/,
+ });
+ expect(googleLink).toHaveAttribute('href', '/superset/login/google');
+});
+
+test('should prefix multiple OAuth provider URLs with application root', () => {
+ mockEnsureAppRoot.mockImplementation(
+ (path: string) => `/app${path.startsWith('/') ? path : `/${path}`}`,
+ );
+ mockGetBootstrapData.mockReturnValue({
+ common: {
+ conf: {
+ AUTH_TYPE: 4,
+ AUTH_PROVIDERS: [
+ { name: 'google', icon: 'google' },
+ { name: 'github', icon: 'github' },
+ ],
+ AUTH_USER_REGISTRATION: false,
+ },
+ },
+ });
render(<Login />, { useRedux: true });
expect(
- screen.getByRole('link', { name: /sign in with okta/i }),
- ).toHaveAttribute('href', '/superset/login/okta');
-});
-
-test('provider login links preserve the next param under a subdirectory', () => {
- mockApplicationRoot.mockReturnValue('/superset');
- mockGetBootstrapData.mockReturnValue(samlBootstrapData);
- const next = '/superset/dashboard/1/';
- window.history.replaceState(
- {},
- '',
- `/superset/login/?next=${encodeURIComponent(next)}`,
+ screen.getByRole('link', { name: /Sign in with Google/ }),
+ ).toHaveAttribute('href', '/app/login/google');
+ expect(
+ screen.getByRole('link', { name: /Sign in with Github/ }),
+ ).toHaveAttribute('href', '/app/login/github');
+});
+
+test('should prefix register URL with application root', () => {
+ mockEnsureAppRoot.mockImplementation(
+ (path: string) => `/superset${path.startsWith('/') ? path : `/${path}`}`,
+ );
+ mockGetBootstrapData.mockReturnValue({
+ common: {
+ conf: {
+ AUTH_TYPE: 1,
+ AUTH_PROVIDERS: [],
+ AUTH_USER_REGISTRATION: true,
+ },
+ },
+ });
+ render(<Login />, { useRedux: true });
+ expect(screen.getByTestId('register-button')).toHaveAttribute(
+ 'href',
+ '/superset/register/',
);
- try {
- render(<Login />, { useRedux: true });
- expect(
- screen.getByRole('link', { name: /sign in with okta/i }),
- ).toHaveAttribute(
- 'href',
- `/superset/login/okta?next=${encodeURIComponent(next)}`,
- );
- } finally {
- window.history.replaceState({}, '', '/');
- }
+});
+
+test('should prefix OID provider URLs with application root', () => {
+ mockEnsureAppRoot.mockImplementation(
+ (path: string) => `/superset${path.startsWith('/') ? path : `/${path}`}`,
+ );
+ mockGetBootstrapData.mockReturnValue({
+ common: {
+ conf: {
+ AUTH_TYPE: 0,
+ AUTH_PROVIDERS: [
+ { name: 'google', url: 'https://accounts.google.com' },
+ ],
+ AUTH_USER_REGISTRATION: false,
+ },
+ },
+ });
+ render(<Login />, { useRedux: true });
+ expect(
+ screen.getByRole('link', { name: /Sign in with Google/ }),
+ ).toHaveAttribute('href', '/superset/login/google');
+});
+
+test('should use ensureAppRoot for all generated URLs with deep application root', () => {
+ mockEnsureAppRoot.mockImplementation(
+ (path: string) =>
+ `/my-org/superset${path.startsWith('/') ? path : `/${path}`}`,
+ );
+ mockGetBootstrapData.mockReturnValue({
+ common: {
+ conf: {
+ AUTH_TYPE: 4,
+ AUTH_PROVIDERS: [{ name: 'google', icon: 'google' }],
+ AUTH_USER_REGISTRATION: false,
+ },
+ },
+ });
+ render(<Login />, { useRedux: true });
+ expect(
+ screen.getByRole('link', { name: /Sign in with Google/ }),
+ ).toHaveAttribute('href', '/my-org/superset/login/google');
});
diff --git a/superset-frontend/src/pages/Login/index.tsx b/superset-frontend/src/pages/Login/index.tsx
index 76ecac675ed..9d2452905e1 100644
--- a/superset-frontend/src/pages/Login/index.tsx
+++ b/superset-frontend/src/pages/Login/index.tsx
@@ -96,7 +96,10 @@ export default function Login() {
}, []);
const loginEndpoint = useMemo(
- () => (nextUrl ? `/login/?next=${encodeURIComponent(nextUrl)}` : '/login/'),
+ () =>
+ ensureAppRoot(
+ nextUrl ? `/login/?next=${encodeURIComponent(nextUrl)}` : '/login/',
+ ),
[nextUrl],
);
diff --git a/superset-frontend/src/pages/Register/Register.test.tsx b/superset-frontend/src/pages/Register/Register.test.tsx
index d870bc527ce..c56c2434a0f 100644
--- a/superset-frontend/src/pages/Register/Register.test.tsx
+++ b/superset-frontend/src/pages/Register/Register.test.tsx
@@ -17,18 +17,24 @@
* under the License.
*/
import { render, screen } from 'spec/helpers/testing-library';
-import { MemoryRouter } from 'react-router-dom';
+import { MemoryRouter, Route } from 'react-router-dom';
+import getBootstrapData from 'src/utils/getBootstrapData';
import Register from './index';
jest.mock('src/utils/getBootstrapData', () => ({
__esModule: true,
- default: () => ({
+ default: jest.fn(() => ({
common: {
conf: {
RECAPTCHA_PUBLIC_KEY: '',
},
},
- }),
+ })),
+}));
+
+const mockEnsureAppRoot = jest.fn((...args: string[]) => args[0]);
+jest.mock('src/utils/pathUtils', () => ({
+ ensureAppRoot: (...args: string[]) => mockEnsureAppRoot(...args),
}));
jest.mock('react-google-recaptcha', () => ({
@@ -36,6 +42,20 @@ jest.mock('react-google-recaptcha', () => ({
default: () => <div data-test="captcha-input" />,
}));
+const mockGetBootstrapData = getBootstrapData as jest.Mock;
+
+beforeEach(() => {
+ mockGetBootstrapData.mockReturnValue({
+ common: {
+ conf: {
+ RECAPTCHA_PUBLIC_KEY: '',
+ },
+ },
+ });
+ mockEnsureAppRoot.mockClear();
+ mockEnsureAppRoot.mockImplementation((path: string) => path);
+});
+
const renderRegister = () =>
render(
<MemoryRouter>
@@ -43,6 +63,17 @@ const renderRegister = () =>
</MemoryRouter>,
);
+const renderActivated = () =>
+ render(
+ <MemoryRouter initialEntries={['/register/activation/abc123']}>
+ <Route path="/register/activation/:activationHash">
+ <Register />
+ </Route>
+ </MemoryRouter>,
+ );
+
+// --- Registration form tests ---
+
test('should render register form elements', () => {
renderRegister();
@@ -80,3 +111,71 @@ test('should render input placeholders', () => {
expect(screen.getByPlaceholderText('Password')).toBeInTheDocument();
expect(screen.getByPlaceholderText('Confirm password')).toBeInTheDocument();
});
+
+// --- Recaptcha tests ---
+
+test('should not render captcha when RECAPTCHA_PUBLIC_KEY is empty', () => {
+ renderRegister();
+ expect(screen.queryByTestId('captcha-input')).not.toBeInTheDocument();
+});
+
+test('should render captcha when RECAPTCHA_PUBLIC_KEY is set', () => {
+ mockGetBootstrapData.mockReturnValue({
+ common: {
+ conf: {
+ RECAPTCHA_PUBLIC_KEY: 'test-key-123',
+ },
+ },
+ });
+ renderRegister();
+ expect(screen.getByTestId('captcha-input')).toBeInTheDocument();
+});
+
+// --- Activation success page tests ---
+
+test('should render activation success page when activationHash is present', () => {
+ renderActivated();
+ expect(screen.getByText('Registration successful')).toBeInTheDocument();
+ expect(
+ screen.getByText(
+ 'Your account is activated. You can log in with your credentials.',
+ ),
+ ).toBeInTheDocument();
+ expect(screen.getByTestId('login-button')).toBeInTheDocument();
+});
+
+test('should not render registration form on activation page', () => {
+ renderActivated();
+ expect(screen.queryByTestId('username-input')).not.toBeInTheDocument();
+ expect(screen.queryByTestId('register-button')).not.toBeInTheDocument();
+});
+
+test('should call ensureAppRoot for login link on activation page', () => {
+ renderActivated();
+ expect(mockEnsureAppRoot).toHaveBeenCalledWith('/login/');
+});
+
+// --- ensureAppRoot / SUPERSET_APP_ROOT tests ---
+
+test('should prefix login link with application root on activation page', () => {
+ mockEnsureAppRoot.mockImplementation(
+ (path: string) => `/superset${path.startsWith('/') ? path : `/${path}`}`,
+ );
+ renderActivated();
+ expect(screen.getByTestId('login-button')).toHaveAttribute(
+ 'href',
+ '/superset/login/',
+ );
+});
+
+test('should prefix login link with deep application root on activation page', () => {
+ mockEnsureAppRoot.mockImplementation(
+ (path: string) =>
+ `/my-org/superset${path.startsWith('/') ? path : `/${path}`}`,
+ );
+ renderActivated();
+ expect(screen.getByTestId('login-button')).toHaveAttribute(
+ 'href',
+ '/my-org/superset/login/',
+ );
+});
diff --git a/superset-frontend/src/utils/pathUtils.test.ts b/superset-frontend/src/utils/pathUtils.test.ts
index 7018e2b23d3..d87bfc5923f 100644
--- a/superset-frontend/src/utils/pathUtils.test.ts
+++ b/superset-frontend/src/utils/pathUtils.test.ts
@@ -83,6 +83,24 @@ test('ensureAppRoot should handle paths with query strings', async () => {
);
});
+test('ensureAppRoot should not double-prefix paths already containing application root', async () => {
+ const customData = {
+ common: {
+ application_root: '/superset/',
+ },
+ };
+ document.body.innerHTML = `<div id="app" data-bootstrap='${JSON.stringify(customData)}'></div>`;
+ jest.resetModules();
+
+ await import('./getBootstrapData');
+ const { ensureAppRoot } = await import('./pathUtils');
+
+ expect(ensureAppRoot('/superset/logout/')).toBe('/superset/logout/');
+ expect(ensureAppRoot('/superset/login/?next=%2Fsuperset%2F')).toBe(
+ '/superset/login/?next=%2Fsuperset%2F',
+ );
+});
+
test('makeUrl should create URL with default application root', async () => {
document.body.innerHTML = '';
jest.resetModules();
diff --git a/superset/app.py b/superset/app.py
index 80bce030362..fb7ba012b7a 100644
--- a/superset/app.py
+++ b/superset/app.py
@@ -72,6 +72,14 @@ def create_app(
# value of app_root so things work out of the box
if not app.config["STATIC_ASSETS_PREFIX"]:
app.config["STATIC_ASSETS_PREFIX"] = app_root
+ # Prefix APP_ICON with the static assets prefix so the brand logo
+ # resolves in subdirectory and CDN deployments alike. Using
+ # STATIC_ASSETS_PREFIX (which defaults to app_root just above)
+ # honours a custom CDN/static prefix when the operator sets one.
+ if app.config.get("APP_ICON", "").startswith("/static/"):
+ app.config["APP_ICON"] = (
+ f"{app.config['STATIC_ASSETS_PREFIX']}{app.config['APP_ICON']}"
+ )
if app.config["APPLICATION_ROOT"] == "/":
app.config["APPLICATION_ROOT"] = app_root