handle error code < 500 in error handler (#1916)
* handle error code < 500 in error handler also: fixes: #378 * Update src/context/RealmsContext.tsx Co-authored-by: Jon Koops <jonkoops@gmail.com> * fixed import * fixed tests Co-authored-by: Jon Koops <jonkoops@gmail.com>
This commit is contained in:
parent
9d9388a7ea
commit
b4738bf897
6 changed files with 76 additions and 25 deletions
|
@ -2,13 +2,19 @@ import ListingPage from "../support/pages/admin_console/ListingPage";
|
||||||
import LoginPage from "../support/pages/LoginPage";
|
import LoginPage from "../support/pages/LoginPage";
|
||||||
import SidebarPage from "../support/pages/admin_console/SidebarPage";
|
import SidebarPage from "../support/pages/admin_console/SidebarPage";
|
||||||
import Masthead from "../support/pages/admin_console/Masthead";
|
import Masthead from "../support/pages/admin_console/Masthead";
|
||||||
import { keycloakBefore } from "../support/util/keycloak_hooks";
|
import {
|
||||||
|
keycloakBefore,
|
||||||
|
keycloakBeforeEach,
|
||||||
|
} from "../support/util/keycloak_hooks";
|
||||||
|
|
||||||
const loginPage = new LoginPage();
|
const loginPage = new LoginPage();
|
||||||
const masthead = new Masthead();
|
const masthead = new Masthead();
|
||||||
|
const listingPage = new ListingPage();
|
||||||
|
const sidebarPage = new SidebarPage();
|
||||||
|
|
||||||
const logOutTest = () => {
|
const logOutTest = () => {
|
||||||
it("logs out", () => {
|
it("logs out", () => {
|
||||||
|
sidebarPage.waitForPageLoad();
|
||||||
masthead.signOut();
|
masthead.signOut();
|
||||||
loginPage.isLogInPage();
|
loginPage.isLogInPage();
|
||||||
});
|
});
|
||||||
|
@ -16,6 +22,7 @@ const logOutTest = () => {
|
||||||
|
|
||||||
const goToAcctMgtTest = () => {
|
const goToAcctMgtTest = () => {
|
||||||
it("opens manage account and returns to admin console", () => {
|
it("opens manage account and returns to admin console", () => {
|
||||||
|
sidebarPage.waitForPageLoad();
|
||||||
masthead.accountManagement();
|
masthead.accountManagement();
|
||||||
cy.contains("Welcome to Keycloak Account Management");
|
cy.contains("Welcome to Keycloak Account Management");
|
||||||
cy.get("#landingReferrerLink").click({ force: true });
|
cy.get("#landingReferrerLink").click({ force: true });
|
||||||
|
@ -24,17 +31,18 @@ const goToAcctMgtTest = () => {
|
||||||
};
|
};
|
||||||
|
|
||||||
describe("Masthead tests in desktop mode", () => {
|
describe("Masthead tests in desktop mode", () => {
|
||||||
beforeEach(() => {
|
before(() => {
|
||||||
keycloakBefore();
|
keycloakBefore();
|
||||||
loginPage.logIn();
|
loginPage.logIn();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
keycloakBeforeEach();
|
||||||
|
});
|
||||||
|
|
||||||
goToAcctMgtTest();
|
goToAcctMgtTest();
|
||||||
|
|
||||||
it("disables header help and form field help", () => {
|
it("disables header help and form field help", () => {
|
||||||
const sidebarPage = new SidebarPage();
|
|
||||||
const listingPage = new ListingPage();
|
|
||||||
|
|
||||||
sidebarPage.goToClientScopes();
|
sidebarPage.goToClientScopes();
|
||||||
listingPage.goToItemDetails("address");
|
listingPage.goToItemDetails("address");
|
||||||
|
|
||||||
|
@ -51,12 +59,16 @@ describe("Masthead tests in desktop mode", () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("Masthead tests with kebab menu", () => {
|
describe("Masthead tests with kebab menu", () => {
|
||||||
beforeEach(() => {
|
before(() => {
|
||||||
keycloakBefore();
|
keycloakBefore();
|
||||||
loginPage.logIn();
|
loginPage.logIn();
|
||||||
masthead.setMobileMode(true);
|
masthead.setMobileMode(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
keycloakBeforeEach();
|
||||||
|
});
|
||||||
|
|
||||||
it("shows kabab and hides regular menu", () => {
|
it("shows kabab and hides regular menu", () => {
|
||||||
masthead.checkKebabShown();
|
masthead.checkKebabShown();
|
||||||
});
|
});
|
||||||
|
|
|
@ -3,7 +3,10 @@ import SidebarPage from "../support/pages/admin_console/SidebarPage";
|
||||||
import LoginPage from "../support/pages/LoginPage";
|
import LoginPage from "../support/pages/LoginPage";
|
||||||
import PartialImportModal from "../support/pages/admin_console/configure/realm_settings/PartialImportModal";
|
import PartialImportModal from "../support/pages/admin_console/configure/realm_settings/PartialImportModal";
|
||||||
import RealmSettings from "../support/pages/admin_console/configure/realm_settings/RealmSettings";
|
import RealmSettings from "../support/pages/admin_console/configure/realm_settings/RealmSettings";
|
||||||
import { keycloakBefore } from "../support/util/keycloak_hooks";
|
import {
|
||||||
|
keycloakBefore,
|
||||||
|
keycloakBeforeEach,
|
||||||
|
} from "../support/util/keycloak_hooks";
|
||||||
import AdminClient from "../support/util/AdminClient";
|
import AdminClient from "../support/util/AdminClient";
|
||||||
|
|
||||||
describe("Partial import test", () => {
|
describe("Partial import test", () => {
|
||||||
|
@ -14,11 +17,13 @@ describe("Partial import test", () => {
|
||||||
const modal = new PartialImportModal();
|
const modal = new PartialImportModal();
|
||||||
const realmSettings = new RealmSettings();
|
const realmSettings = new RealmSettings();
|
||||||
|
|
||||||
beforeEach(() => {
|
before(() => {
|
||||||
keycloakBefore();
|
keycloakBefore();
|
||||||
loginPage.logIn();
|
loginPage.logIn();
|
||||||
sidebarPage.waitForPageLoad();
|
});
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
keycloakBeforeEach();
|
||||||
// doing this from the UI has the added bonus of putting you in the test realm
|
// doing this from the UI has the added bonus of putting you in the test realm
|
||||||
sidebarPage.goToCreateRealm();
|
sidebarPage.goToCreateRealm();
|
||||||
createRealmPage.fillRealmName(TEST_REALM).createRealm();
|
createRealmPage.fillRealmName(TEST_REALM).createRealm();
|
||||||
|
@ -43,6 +48,7 @@ describe("Partial import test", () => {
|
||||||
modal.open();
|
modal.open();
|
||||||
cy.get(".pf-c-code-editor__code textarea").type("{}");
|
cy.get(".pf-c-code-editor__code textarea").type("{}");
|
||||||
modal.importButton().should("be.disabled");
|
modal.importButton().should("be.disabled");
|
||||||
|
modal.cancelButton().click();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Displays user options after multi-realm import", () => {
|
it("Displays user options after multi-realm import", () => {
|
||||||
|
@ -81,6 +87,7 @@ describe("Partial import test", () => {
|
||||||
cy.contains("2 records added");
|
cy.contains("2 records added");
|
||||||
cy.contains("customer-portal");
|
cy.contains("customer-portal");
|
||||||
cy.contains("customer-portal2");
|
cy.contains("customer-portal2");
|
||||||
|
modal.closeButton().click();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Displays user options after realmless import and does the import", () => {
|
it("Displays user options after realmless import and does the import", () => {
|
||||||
|
|
|
@ -30,6 +30,10 @@ export default class GroupModal {
|
||||||
return cy.findByTestId("cancel-button");
|
return cy.findByTestId("cancel-button");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
closeButton() {
|
||||||
|
return cy.findByTestId("close-button");
|
||||||
|
}
|
||||||
|
|
||||||
usersCheckbox() {
|
usersCheckbox() {
|
||||||
return cy.findByTestId("users-checkbox");
|
return cy.findByTestId("users-checkbox");
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,8 @@ import React, {
|
||||||
useMemo,
|
useMemo,
|
||||||
useState,
|
useState,
|
||||||
} from "react";
|
} from "react";
|
||||||
|
import axios from "axios";
|
||||||
|
|
||||||
import { RecentUsed } from "../components/realm-selector/recent-used";
|
import { RecentUsed } from "../components/realm-selector/recent-used";
|
||||||
import useRequiredContext from "../utils/useRequiredContext";
|
import useRequiredContext from "../utils/useRequiredContext";
|
||||||
import { useAdminClient, useFetch } from "./auth/AdminClient";
|
import { useAdminClient, useFetch } from "./auth/AdminClient";
|
||||||
|
@ -33,7 +35,21 @@ export const RealmsProvider: FunctionComponent = ({ children }) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
useFetch(
|
useFetch(
|
||||||
() => adminClient.realms.find({ briefRepresentation: true }),
|
async () => {
|
||||||
|
try {
|
||||||
|
return await adminClient.realms.find({ briefRepresentation: true });
|
||||||
|
} catch (error) {
|
||||||
|
if (
|
||||||
|
axios.isAxiosError(error) &&
|
||||||
|
error.response &&
|
||||||
|
error.response.status < 500
|
||||||
|
) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
},
|
||||||
(realms) => updateRealms(realms),
|
(realms) => updateRealms(realms),
|
||||||
[]
|
[]
|
||||||
);
|
);
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
|
import React, { createContext, FunctionComponent, useState } from "react";
|
||||||
|
|
||||||
import type { ServerInfoRepresentation } from "@keycloak/keycloak-admin-client/lib/defs/serverInfoRepesentation";
|
import type { ServerInfoRepresentation } from "@keycloak/keycloak-admin-client/lib/defs/serverInfoRepesentation";
|
||||||
import React, { createContext, FunctionComponent } from "react";
|
|
||||||
import { DataLoader } from "../../components/data-loader/DataLoader";
|
|
||||||
import { sortProviders } from "../../util";
|
import { sortProviders } from "../../util";
|
||||||
import useRequiredContext from "../../utils/useRequiredContext";
|
import useRequiredContext from "../../utils/useRequiredContext";
|
||||||
import { useAdminClient } from "../auth/AdminClient";
|
import { useAdminClient, useFetch } from "../auth/AdminClient";
|
||||||
|
|
||||||
export const ServerInfoContext = createContext<
|
export const ServerInfoContext = createContext<
|
||||||
ServerInfoRepresentation | undefined
|
ServerInfoRepresentation | undefined
|
||||||
|
@ -17,16 +17,23 @@ export const useLoginProviders = () => {
|
||||||
|
|
||||||
export const ServerInfoProvider: FunctionComponent = ({ children }) => {
|
export const ServerInfoProvider: FunctionComponent = ({ children }) => {
|
||||||
const adminClient = useAdminClient();
|
const adminClient = useAdminClient();
|
||||||
const loader = async () => {
|
const [serverInfo, setServerInfo] = useState<ServerInfoRepresentation>({});
|
||||||
return await adminClient.serverInfo.find();
|
|
||||||
};
|
useFetch(
|
||||||
|
async () => {
|
||||||
|
try {
|
||||||
|
return await adminClient.serverInfo.find();
|
||||||
|
} catch (error) {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
},
|
||||||
|
setServerInfo,
|
||||||
|
[]
|
||||||
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<DataLoader loader={loader}>
|
<ServerInfoContext.Provider value={serverInfo}>
|
||||||
{(serverInfo) => (
|
{children}
|
||||||
<ServerInfoContext.Provider value={serverInfo}>
|
</ServerInfoContext.Provider>
|
||||||
{children}
|
|
||||||
</ServerInfoContext.Provider>
|
|
||||||
)}
|
|
||||||
</DataLoader>
|
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
@ -26,12 +26,13 @@ import { xor } from "lodash-es";
|
||||||
|
|
||||||
import { useRealm } from "../context/realm-context/RealmContext";
|
import { useRealm } from "../context/realm-context/RealmContext";
|
||||||
import { useServerInfo } from "../context/server-info/ServerInfoProvider";
|
import { useServerInfo } from "../context/server-info/ServerInfoProvider";
|
||||||
|
|
||||||
import "./dashboard.css";
|
|
||||||
import { toUpperCase } from "../util";
|
import { toUpperCase } from "../util";
|
||||||
import { HelpItem } from "../components/help-enabler/HelpItem";
|
import { HelpItem } from "../components/help-enabler/HelpItem";
|
||||||
import environment from "../environment";
|
import environment from "../environment";
|
||||||
|
|
||||||
|
import "./dashboard.css";
|
||||||
|
import { KeycloakSpinner } from "../components/keycloak-spinner/KeycloakSpinner";
|
||||||
|
|
||||||
const EmptyDashboard = () => {
|
const EmptyDashboard = () => {
|
||||||
const { t } = useTranslation("dashboard");
|
const { t } = useTranslation("dashboard");
|
||||||
const { realm } = useRealm();
|
const { realm } = useRealm();
|
||||||
|
@ -74,6 +75,10 @@ const Dashboard = () => {
|
||||||
return serverInfo.profileInfo?.previewFeatures?.includes(feature);
|
return serverInfo.profileInfo?.previewFeatures?.includes(feature);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (Object.keys(serverInfo).length === 0) {
|
||||||
|
return <KeycloakSpinner />;
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<PageSection variant="light">
|
<PageSection variant="light">
|
||||||
|
|
Loading…
Reference in a new issue