From 3694dad23c87286bbcdc116d95174c99f6e1112b Mon Sep 17 00:00:00 2001
From: Dominik Kawka <31955648+dominikkawka@users.noreply.github.com>
Date: Mon, 3 Oct 2022 12:00:26 +0100
Subject: [PATCH] import client tests (#3452)
---
.../admin-ui/cypress/e2e/clients_test.spec.ts | 41 ++++++++++++++++
.../import-identical-client.json | 48 +++++++++++++++++++
.../src/clients/ClientDescription.tsx | 1 +
apps/admin-ui/src/clients/ClientsSection.tsx | 1 +
.../json-file-upload/FileUploadForm.tsx | 1 +
5 files changed, 92 insertions(+)
create mode 100644 apps/admin-ui/cypress/fixtures/partial-import-test-data/import-identical-client.json
diff --git a/apps/admin-ui/cypress/e2e/clients_test.spec.ts b/apps/admin-ui/cypress/e2e/clients_test.spec.ts
index a1b8143b76..58b86794b2 100644
--- a/apps/admin-ui/cypress/e2e/clients_test.spec.ts
+++ b/apps/admin-ui/cypress/e2e/clients_test.spec.ts
@@ -432,6 +432,47 @@ describe("Clients test", () => {
});
initialAccessTokenTab.shouldBeEmpty();
});
+
+ it("Should fail to create imported client with empty ID", () => {
+ commonPage.sidebar().goToClients();
+ commonPage.masthead().closeAllAlertMessages();
+ cy.findByTestId("importClient").click();
+ cy.findByTestId("kc-client-id").click();
+ cy.findByText("Save").click();
+ cy.findByText("Required field");
+ });
+
+ const identicalClientId = "identical";
+ it("Should fail to create client with same ID", () => {
+ commonPage.sidebar().goToClients();
+ commonPage.tableToolbarUtils().createClient();
+
+ createClientPage.fillClientData(identicalClientId).continue().save();
+
+ commonPage.masthead().closeAllAlertMessages();
+ commonPage.sidebar().goToClients();
+ cy.findByTestId("importClient").click();
+ cy.findByTestId("realm-file").selectFile(
+ "cypress/fixtures/partial-import-test-data/import-identical-client.json",
+ { action: "drag-drop" }
+ );
+
+ cy.wait(1000);
+ //cy.findByTestId("realm-file").contains('"clientId": "identical"')
+ cy.findByTestId("kc-client-id").click();
+ cy.findByText("Save").click();
+ commonPage
+ .masthead()
+ .checkNotificationMessage(
+ "Could not import client: Client identical already exists",
+ true
+ );
+ });
+
+ it("should delete 'identical' client id", () => {
+ commonPage.sidebar().goToClients();
+ adminClient.deleteClient(identicalClientId);
+ });
});
describe("Roles tab test", () => {
diff --git a/apps/admin-ui/cypress/fixtures/partial-import-test-data/import-identical-client.json b/apps/admin-ui/cypress/fixtures/partial-import-test-data/import-identical-client.json
new file mode 100644
index 0000000000..33ef9c6008
--- /dev/null
+++ b/apps/admin-ui/cypress/fixtures/partial-import-test-data/import-identical-client.json
@@ -0,0 +1,48 @@
+{
+ "clientId": "identical",
+ "name": "",
+ "description": "",
+ "surrogateAuthRequired": false,
+ "enabled": true,
+ "alwaysDisplayInConsole": false,
+ "clientAuthenticatorType": "client-secret",
+ "redirectUris": [],
+ "webOrigins": [],
+ "notBefore": 0,
+ "bearerOnly": false,
+ "consentRequired": false,
+ "standardFlowEnabled": true,
+ "implicitFlowEnabled": false,
+ "directAccessGrantsEnabled": true,
+ "serviceAccountsEnabled": false,
+ "publicClient": true,
+ "frontchannelLogout": true,
+ "protocol": "openid-connect",
+ "attributes": {
+ "oidc.ciba.grant.enabled": "false",
+ "oauth2.device.authorization.grant.enabled": "false",
+ "backchannel.logout.session.required": "true",
+ "backchannel.logout.revoke.offline.tokens": "false"
+ },
+ "authenticationFlowBindingOverrides": {},
+ "fullScopeAllowed": true,
+ "nodeReRegistrationTimeout": -1,
+ "defaultClientScopes": [
+ "web-origins",
+ "acr",
+ "roles",
+ "profile",
+ "email"
+ ],
+ "optionalClientScopes": [
+ "address",
+ "phone",
+ "offline_access",
+ "microprofile-jwt"
+ ],
+ "access": {
+ "view": true,
+ "configure": true,
+ "manage": true
+ }
+}
\ No newline at end of file
diff --git a/apps/admin-ui/src/clients/ClientDescription.tsx b/apps/admin-ui/src/clients/ClientDescription.tsx
index 9ca8919824..ce6c569e0d 100644
--- a/apps/admin-ui/src/clients/ClientDescription.tsx
+++ b/apps/admin-ui/src/clients/ClientDescription.tsx
@@ -40,6 +40,7 @@ export const ClientDescription = ({
ref={register({ required: true })}
type="text"
id="kc-client-id"
+ data-testid="kc-client-id"
name="clientId"
validated={
errors.clientId ? ValidatedOptions.error : ValidatedOptions.default
diff --git a/apps/admin-ui/src/clients/ClientsSection.tsx b/apps/admin-ui/src/clients/ClientsSection.tsx
index 5e51fdf34e..fce06ec55e 100644
--- a/apps/admin-ui/src/clients/ClientsSection.tsx
+++ b/apps/admin-ui/src/clients/ClientsSection.tsx
@@ -125,6 +125,7 @@ export default function ClientsSection() {
)}
variant="link"
+ data-testid="importClient"
>
{t("importClient")}
diff --git a/apps/admin-ui/src/components/json-file-upload/FileUploadForm.tsx b/apps/admin-ui/src/components/json-file-upload/FileUploadForm.tsx
index 9037835054..68a7a0f61b 100644
--- a/apps/admin-ui/src/components/json-file-upload/FileUploadForm.tsx
+++ b/apps/admin-ui/src/components/json-file-upload/FileUploadForm.tsx
@@ -127,6 +127,7 @@ export const FileUploadForm = ({
helperText={t(helpText)}
>