added test saml advanced tab (#20880)

This commit is contained in:
Erik Jan de Wit 2023-06-12 12:52:45 +02:00 committed by GitHub
parent 9c9cd4cf21
commit c771890da8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 160 additions and 203 deletions

View file

@ -0,0 +1,59 @@
import LoginPage from "../support/pages/LoginPage";
import Masthead from "../support/pages/admin-ui/Masthead";
import ListingPage from "../support/pages/admin-ui/ListingPage";
import SidebarPage from "../support/pages/admin-ui/SidebarPage";
import adminClient from "../support/util/AdminClient";
import { keycloakBefore } from "../support/util/keycloak_hooks";
import { AdvancedSamlTab } from "../support/pages/admin-ui/manage/clients/client_details/tabs/AdvancedSamlTab";
import ClientDetailsPage from "../support/pages/admin-ui/manage/clients/client_details/ClientDetailsPage";
const loginPage = new LoginPage();
const masthead = new Masthead();
const sidebarPage = new SidebarPage();
const listingPage = new ListingPage();
const advancedTab = new AdvancedSamlTab();
describe("Clients Saml advanced tab", () => {
describe("Fine Grain SAML Endpoint Configuration", () => {
const clientName = "advanced-tab";
before(() => {
adminClient.createClient({
protocol: "saml",
clientId: clientName,
publicClient: false,
});
});
after(() => {
adminClient.deleteClient(clientName);
});
beforeEach(() => {
loginPage.logIn();
keycloakBefore();
sidebarPage.goToClients();
listingPage.searchItem(clientName).goToItemDetails(clientName);
new ClientDetailsPage().goToAdvancedTab();
});
it("Should Terms of service URL", () => {
const termsOfServiceUrl = "http://some.url/terms-of-service.html";
advancedTab.termsOfServiceUrl(termsOfServiceUrl).saveFineGrain();
masthead.checkNotificationMessage("Client successfully updated");
advancedTab
.termsOfServiceUrl("http://not.saveing.this/")
.revertFineGrain();
advancedTab.checkTermsOfServiceUrl(termsOfServiceUrl);
});
it("Invalid terms of service URL", () => {
advancedTab.termsOfServiceUrl("not a url").saveFineGrain();
masthead.checkNotificationMessage(
"Client could not be updated: Terms of service URL is not a valid URL"
);
});
});
});

View file

@ -0,0 +1,27 @@
import PageObject from "../../../../components/PageObject";
export class AdvancedSamlTab extends PageObject {
private termsOfServiceUrlId = "attributes.tosUri";
saveFineGrain() {
cy.findAllByTestId("fineGrainSave").click();
}
revertFineGrain() {
cy.findByTestId("fineGrainRevert").click();
}
termsOfServiceUrl(termsOfServiceUrl: string) {
cy.findAllByTestId(this.termsOfServiceUrlId).clear();
cy.findAllByTestId(this.termsOfServiceUrlId).type(termsOfServiceUrl);
return this;
}
checkTermsOfServiceUrl(termsOfServiceUrl: string) {
cy.findAllByTestId(this.termsOfServiceUrlId).should(
"have.value",
termsOfServiceUrl
);
return this;
}
}

View file

@ -1,11 +1,5 @@
import { FormGroup } from "@patternfly/react-core";
import { useFormContext } from "react-hook-form";
import { useTranslation } from "react-i18next";
import { HelpItem } from "ui-shared";
import { KeycloakTextInput } from "../../components/keycloak-text-input/KeycloakTextInput";
import { convertAttributeNameToForm } from "../../util";
import { FormFields } from "../ClientDetails";
import { TextControl } from "ui-shared";
type ApplicationUrlsProps = {
isDisabled?: boolean;
@ -13,70 +7,30 @@ type ApplicationUrlsProps = {
export const ApplicationUrls = (props: ApplicationUrlsProps) => {
const { t } = useTranslation("clients");
const { register } = useFormContext();
return (
<>
<FormGroup
label={t("logoUrl")}
fieldId="logoUrl"
labelIcon={
<HelpItem
helpText={t("clients-help:logoUrl")}
fieldLabelId="clients:logoUrl"
/>
}
>
<KeycloakTextInput
id="logoUrl"
type="url"
data-testid="logoUrl"
{...register(
convertAttributeNameToForm<FormFields>("attributes.logoUri")
)}
{...props}
/>
</FormGroup>
<FormGroup
label={t("policyUrl")}
fieldId="policyUrl"
labelIcon={
<HelpItem
helpText={t("clients-help:policyUrl")}
fieldLabelId="clients:policyUrl"
/>
}
>
<KeycloakTextInput
id="policyUrl"
data-testid="policyUrl"
type="url"
{...register(
convertAttributeNameToForm<FormFields>("attributes.policyUri")
)}
{...props}
/>
</FormGroup>
<FormGroup
label={t("termsOfServiceUrl")}
fieldId="termsOfServiceUrl"
labelIcon={
<HelpItem
helpText={t("clients-help:termsOfServiceUrl")}
fieldLabelId="clients:termsOfServiceUrl"
/>
}
>
<KeycloakTextInput
id="termsOfServiceUrl"
type="url"
data-testid="termsOfServiceUrl"
{...register(
convertAttributeNameToForm<FormFields>("attributes.tosUri")
)}
{...props}
/>
</FormGroup>
<TextControl
name="attributes.logoUri"
label={t("clients:logoUrl")}
labelIcon={t("clients-help:logoUrl")}
type="url"
{...props}
/>
<TextControl
name="attributes.policyUri"
label={t("clients:policyUrl")}
labelIcon={t("clients-help:policyUrl")}
type="url"
{...props}
/>
<TextControl
name="attributes.tosUri"
label={t("clients:termsOfServiceUrl")}
labelIcon={t("clients-help:termsOfServiceUrl")}
type="url"
{...props}
/>
</>
);
};

View file

@ -1,10 +1,8 @@
import { ActionGroup, Button, FormGroup } from "@patternfly/react-core";
import { useFormContext } from "react-hook-form";
import { ActionGroup, Button } from "@patternfly/react-core";
import { useTranslation } from "react-i18next";
import { FormAccess } from "../../components/form/FormAccess";
import { HelpItem } from "ui-shared";
import { KeycloakTextInput } from "../../components/keycloak-text-input/KeycloakTextInput";
import { TextControl } from "ui-shared";
import { ApplicationUrls } from "./ApplicationUrls";
type FineGrainSamlEndpointConfigProps = {
@ -17,146 +15,63 @@ export const FineGrainSamlEndpointConfig = ({
reset,
}: FineGrainSamlEndpointConfigProps) => {
const { t } = useTranslation("clients");
const { register } = useFormContext();
return (
<FormAccess role="manage-realm" isHorizontal>
<ApplicationUrls />
<FormGroup
<TextControl
name="attributes.saml_assertion_consumer_url_post"
label={t("assertionConsumerServicePostBindingURL")}
fieldId="assertionConsumerServicePostBindingURL"
labelIcon={
<HelpItem
helpText={t("clients-help:assertionConsumerServicePostBindingURL")}
fieldLabelId="clients:assertionConsumerServicePostBindingURL"
/>
}
>
<KeycloakTextInput
id="assertionConsumerServicePostBindingURL"
type="url"
{...register("attributes.saml_assertion_consumer_url_post")}
/>
</FormGroup>
<FormGroup
labelIcon={t("clients-help:assertionConsumerServicePostBindingURL")}
type="url"
/>
<TextControl
name="attributes.saml_assertion_consumer_url_redirect"
label={t("assertionConsumerServiceRedirectBindingURL")}
fieldId="assertionConsumerServiceRedirectBindingURL"
labelIcon={
<HelpItem
helpText={t(
"clients-help:assertionConsumerServiceRedirectBindingURL"
)}
fieldLabelId="clients:assertionConsumerServiceRedirectBindingURL"
/>
}
>
<KeycloakTextInput
id="assertionConsumerServiceRedirectBindingURL"
type="url"
{...register("attributes.saml_assertion_consumer_url_redirect")}
/>
</FormGroup>
<FormGroup
labelIcon={t("clients-help:assertionConsumerServiceRedirectBindingURL")}
type="url"
/>
<TextControl
name="attributes.saml_single_logout_service_url_post"
label={t("logoutServicePostBindingURL")}
fieldId="logoutServicePostBindingURL"
labelIcon={
<HelpItem
helpText={t("clients-help:logoutServicePostBindingURL")}
fieldLabelId="clients:logoutServicePostBindingURL"
/>
}
>
<KeycloakTextInput
id="logoutServicePostBindingURL"
type="url"
{...register("attributes.saml_single_logout_service_url_post")}
/>
</FormGroup>
<FormGroup
labelIcon={t("clients-help:logoutServicePostBindingURL")}
type="url"
/>
<TextControl
name="attributes.saml_single_logout_service_url_redirect"
label={t("logoutServiceRedirectBindingURL")}
fieldId="logoutServiceRedirectBindingURL"
labelIcon={
<HelpItem
helpText={t("clients-help:logoutServiceRedirectBindingURL")}
fieldLabelId="clients:logoutServiceRedirectBindingURL"
/>
}
>
<KeycloakTextInput
id="logoutServiceRedirectBindingURL"
type="url"
{...register("attributes.saml_single_logout_service_url_redirect")}
/>
</FormGroup>
<FormGroup
labelIcon={t("clients-help:logoutServiceRedirectBindingURL")}
type="url"
/>
<TextControl
name="attributes.saml_single_logout_service_url_soap"
label={t("logoutServiceSoapBindingUrl")}
fieldId="logoutServiceSoapBindingUrl"
labelIcon={
<HelpItem
helpText="clients-help:logoutServiceSoapBindingUrl"
fieldLabelId="clients:logoutServiceSoapBindingUrl"
/>
}
>
<KeycloakTextInput
id="logoutServiceSoapBindingUrl"
type="url"
{...register("attributes.saml_single_logout_service_url_soap")}
/>
</FormGroup>
<FormGroup
labelIcon={t("clients-help:logoutServiceSoapBindingUrl")}
type="url"
/>
<TextControl
name="attributes.saml_single_logout_service_url_artifact"
label={t("logoutServiceArtifactBindingUrl")}
fieldId="logoutServiceArtifactBindingUrl"
labelIcon={
<HelpItem
helpText={t("clients-help:logoutServiceArtifactBindingUrl")}
fieldLabelId="clients:logoutServiceArtifactBindingUrl"
/>
}
>
<KeycloakTextInput
id="logoutServiceArtifactBindingUrl"
type="url"
{...register("attributes.saml_single_logout_service_url_artifact")}
/>
</FormGroup>
<FormGroup
labelIcon={t("clients-help:logoutServiceArtifactBindingUrl")}
type="url"
/>
<TextControl
name="attributes.saml_artifact_binding_url"
label={t("artifactBindingUrl")}
fieldId="artifactBindingUrl"
labelIcon={
<HelpItem
helpText={t("clients-help:artifactBindingUrl")}
fieldLabelId="clients:artifactBindingUrl"
/>
}
>
<KeycloakTextInput
id="artifactBindingUrl"
type="url"
{...register("attributes.saml_artifact_binding_url")}
/>
</FormGroup>
<FormGroup
labelIcon={t("clients-help:artifactBindingUrl")}
type="url"
/>
<TextControl
name="attributes.saml_artifact_resolution_service_url"
label={t("artifactResolutionService")}
fieldId="artifactResolutionService"
labelIcon={
<HelpItem
helpText={t("clients-help:artifactResolutionService")}
fieldLabelId="clients:artifactResolutionService"
/>
}
>
<KeycloakTextInput
id="artifactResolutionService"
type="url"
{...register("attributes.saml_artifact_resolution_service_url")}
/>
</FormGroup>
labelIcon={t("clients-help:artifactResolutionService")}
type="url"
/>
<ActionGroup>
<Button variant="tertiary" onClick={save}>
<Button variant="tertiary" onClick={save} data-testid="fineGrainSave">
{t("common:save")}
</Button>
<Button variant="link" onClick={reset}>
<Button variant="link" onClick={reset} data-testid="fineGrainRevert">
{t("common:revert")}
</Button>
</ActionGroup>

View file

@ -1,4 +1,4 @@
import { ValidatedOptions } from "@patternfly/react-core";
import { TextInputProps, ValidatedOptions } from "@patternfly/react-core";
import {
FieldPath,
FieldValues,
@ -13,11 +13,12 @@ import { FormLabel } from "./FormLabel";
export type TextControlProps<
T extends FieldValues,
P extends FieldPath<T> = FieldPath<T>
> = UseControllerProps<T, P> & {
label: string;
labelIcon?: string;
isDisabled?: boolean;
};
> = UseControllerProps<T, P> &
TextInputProps & {
label: string;
labelIcon?: string;
isDisabled?: boolean;
};
export const TextControl = <
T extends FieldValues,
@ -49,6 +50,7 @@ export const TextControl = <
fieldState.error ? ValidatedOptions.error : ValidatedOptions.default
}
isDisabled={props.isDisabled}
{...props}
{...field}
/>
</FormLabel>