From 60e4676ac8844cd0342492407ca9a8cd97142250 Mon Sep 17 00:00:00 2001 From: Erik Jan de Wit Date: Tue, 12 Oct 2021 11:28:55 +0200 Subject: [PATCH] added saml keys tab (#1308) Co-authored-by: Jon Koops --- cypress/integration/clients_test.spec.ts | 57 ++++- src/clients/ClientDetails.tsx | 8 +- src/clients/add/CapabilityConfig.tsx | 4 +- src/clients/keys/Certificate.tsx | 52 +++++ src/clients/keys/GenerateKeyDialog.tsx | 141 ++++++++---- src/clients/keys/Keys.tsx | 21 +- src/clients/keys/SamlImportKeyDialog.tsx | 54 +++++ src/clients/keys/SamlKeys.tsx | 260 +++++++++++++++++++++++ src/clients/keys/SamlKeysDialog.tsx | 206 ++++++++++++++++++ src/clients/messages.ts | 23 ++ 10 files changed, 758 insertions(+), 68 deletions(-) create mode 100644 src/clients/keys/Certificate.tsx create mode 100644 src/clients/keys/SamlImportKeyDialog.tsx create mode 100644 src/clients/keys/SamlKeys.tsx create mode 100644 src/clients/keys/SamlKeysDialog.tsx diff --git a/cypress/integration/clients_test.spec.ts b/cypress/integration/clients_test.spec.ts index 63ca0d6b16..2b0de307e2 100644 --- a/cypress/integration/clients_test.spec.ts +++ b/cypress/integration/clients_test.spec.ts @@ -294,7 +294,6 @@ describe("Clients test", () => { cy.findByTestId("jump-link-capability-config").should("not.exist"); }); }); - describe("SAML test", () => { const samlClientName = "saml"; @@ -339,4 +338,60 @@ describe("Clients test", () => { masthead.checkNotificationMessage("Client successfully updated"); }); }); + + describe("SAML keys tab", () => { + const clientId = "saml-keys"; + + before(() => { + new AdminClient().createClient({ + clientId, + protocol: "saml", + }); + }); + + after(() => { + new AdminClient().deleteClient(clientId); + }); + + beforeEach(() => { + keycloakBefore(); + loginPage.logIn(); + sidebarPage.goToClients(); + listingPage.searchItem(clientId).goToItemDetails(clientId); + cy.get("#pf-tab-keys-keys").click(); + }); + + it("doesn't disable when no", () => { + cy.findByTestId("clientSignature").click({ force: true }); + + modalUtils + .checkModalTitle('Disable "Client signature required"') + .cancelModal(); + + cy.findAllByTestId("certificate").should("have.length", 1); + }); + + it("disable client signature", () => { + cy.findByTestId("clientSignature").click({ force: true }); + + modalUtils + .checkModalTitle('Disable "Client signature required"') + .confirmModal(); + + masthead.checkNotificationMessage("Client successfully updated"); + cy.findAllByTestId("certificate").should("have.length", 0); + }); + + it("should enable Encryption keys config", () => { + cy.findByTestId("encryptAssertions").click({ force: true }); + + cy.findByTestId("generate").click(); + masthead.checkNotificationMessage( + "New key pair and certificate generated successfully" + ); + + modalUtils.confirmModal(); + cy.findAllByTestId("certificate").should("have.length", 1); + }); + }); }); diff --git a/src/clients/ClientDetails.tsx b/src/clients/ClientDetails.tsx index 3b6cae799e..c1ca5699b6 100644 --- a/src/clients/ClientDetails.tsx +++ b/src/clients/ClientDetails.tsx @@ -53,6 +53,7 @@ import { ClientScopes } from "./scopes/ClientScopes"; import { EvaluateScopes } from "./scopes/EvaluateScopes"; import { ServiceAccount } from "./service-account/ServiceAccount"; import { isRealmClient, getProtocolName } from "./utils"; +import { SamlKeys } from "./keys/SamlKeys"; type ClientDetailHeaderProps = { onChange: (value: boolean) => void; @@ -349,7 +350,12 @@ export const ClientDetails = () => { eventKey="keys" title={{t("keys")}} > - save()} /> + {client.protocol === "openid-connect" && ( + + )} + {client.protocol === "saml" && ( + + )} )} {!client.publicClient && !isRealmClient(client) && ( diff --git a/src/clients/add/CapabilityConfig.tsx b/src/clients/add/CapabilityConfig.tsx index ae92d57169..db36ec06ba 100644 --- a/src/clients/add/CapabilityConfig.tsx +++ b/src/clients/add/CapabilityConfig.tsx @@ -248,7 +248,7 @@ export const CapabilityConfig = ({ hasNoPaddingTop > ( @@ -276,7 +276,7 @@ export const CapabilityConfig = ({ hasNoPaddingTop > ( diff --git a/src/clients/keys/Certificate.tsx b/src/clients/keys/Certificate.tsx new file mode 100644 index 0000000000..37c59f9500 --- /dev/null +++ b/src/clients/keys/Certificate.tsx @@ -0,0 +1,52 @@ +import React from "react"; +import { useTranslation } from "react-i18next"; +import { FormGroup, GenerateId, TextArea } from "@patternfly/react-core"; + +import type CertificateRepresentation from "@keycloak/keycloak-admin-client/lib/defs/certificateRepresentation"; +import { HelpItem } from "../../components/help-enabler/HelpItem"; + +type CertificateProps = Omit & { + plain?: boolean; +}; + +type CertificateDisplayProps = { + id: string; + keyInfo?: CertificateRepresentation; +}; + +const CertificateDisplay = ({ id, keyInfo }: CertificateDisplayProps) => ( +