From 1767bc43f1013aefae0f2b4cf179208a3cd1f669 Mon Sep 17 00:00:00 2001 From: Charles Moulliard Date: Fri, 12 May 2023 17:39:48 +0200 Subject: [PATCH 01/21] WIP. Adding a new field: type to display or hidesome fields Signed-off-by: Charles Moulliard --- app/src/main/java/io/halkyon/model/Credential.java | 2 ++ .../resource/requests/CredentialRequest.java | 4 ++++ .../main/resources/templates/credentials/form.html | 14 +++++++++++++- 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/io/halkyon/model/Credential.java b/app/src/main/java/io/halkyon/model/Credential.java index f1f1b886..add7bede 100644 --- a/app/src/main/java/io/halkyon/model/Credential.java +++ b/app/src/main/java/io/halkyon/model/Credential.java @@ -38,6 +38,8 @@ public class Credential extends PanacheEntityBase { @JoinColumn(name = "service_id", nullable = false) public Service service; + public String type; + public String vaultKvPath; public String username; diff --git a/app/src/main/java/io/halkyon/resource/requests/CredentialRequest.java b/app/src/main/java/io/halkyon/resource/requests/CredentialRequest.java index 3caa5f8b..6731b0ce 100644 --- a/app/src/main/java/io/halkyon/resource/requests/CredentialRequest.java +++ b/app/src/main/java/io/halkyon/resource/requests/CredentialRequest.java @@ -16,6 +16,10 @@ public class CredentialRequest { @FormParam public String name; + @NotBlank + @FormParam + public String type; + @NotNull @FormParam public Long serviceId; diff --git a/app/src/main/resources/templates/credentials/form.html b/app/src/main/resources/templates/credentials/form.html index abc1a9b0..e3abdb42 100644 --- a/app/src/main/resources/templates/credentials/form.html +++ b/app/src/main/resources/templates/credentials/form.html @@ -11,6 +11,16 @@

Update Credential

{/if} +
+ +
+ +
+
@@ -31,6 +41,7 @@

Update Credential

+
@@ -43,7 +54,8 @@

Update Credential

-
+
+
From cbcff117f187c775caeb3342ecfa9c9dcd5cadc8 Mon Sep 17 00:00:00 2001 From: cmoulliard Date: Mon, 25 Sep 2023 19:20:49 +0200 Subject: [PATCH 02/21] WIP. Add a note to specify that a new test case is needed. #403 Signed-off-by: cmoulliard --- app/src/main/resources/templates/credentials/form.html | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/resources/templates/credentials/form.html b/app/src/main/resources/templates/credentials/form.html index e3abdb42..c22b3e38 100644 --- a/app/src/main/resources/templates/credentials/form.html +++ b/app/src/main/resources/templates/credentials/form.html @@ -14,6 +14,7 @@

Update Credential

+ -
- -
- - -
-
-
- -
- -
-
-
- -
- -
-
-
-
- -
- -
-
-
- -
- -
-
-
-
- -
- -
-
-
- - - - - - - - - - - - - - - - {#for param in credential.params} - - - - - - {/for} - -
NameValue
- - - - - -
{param.paramName}{param.paramValue} - - -
-
-
-
-
- -
-
- -
-
- Back -
-
-
-
- - {/body} + // Attach the event listener to the select element + document.getElementById("credential_type").addEventListener("change", handleSelectChange); + + function addParameterRow() { + var nameInput = document.getElementById("new-param-name"); + var valueInput = document.getElementById("new-param-value"); + var table = document.getElementById("credential-params"); + + // hidden input for form + var formInput = document.createElement("input"); + formInput.type = "hidden"; + formInput.name = "params"; + formInput.value = nameInput.value + ":" + valueInput.value; + + // delete button + var button = document.createElement("button"); + button.setAttribute("class", "btn btn-secondary"); + button.type = "button"; + button.innerHTML = "Delete"; + button.setAttribute("onclick", "deleteParameterRow(this)"); + + var newRow = table.insertRow(-1); + var cell1 = newRow.insertCell(0); + var cell2 = newRow.insertCell(1); + var cell3 = newRow.insertCell(2); + cell1.innerHTML = nameInput.value; + cell2.innerHTML = valueInput.value; + cell3.appendChild(button); + cell3.appendChild(formInput); + + nameInput.value = ""; + valueInput.value = ""; + } + + function deleteParameterRow(row) { + var i = row.parentNode.parentNode.rowIndex; + document.getElementById("credential-params").deleteRow(i - 1); + } + + {/body} {/include} \ No newline at end of file From 84612476c6f990f71573bce177aeb5c0e726a95d Mon Sep 17 00:00:00 2001 From: cmoulliard Date: Tue, 26 Sep 2023 16:30:49 +0200 Subject: [PATCH 04/21] Adding the missing new parameter credential_type Signed-off-by: cmoulliard --- .../e2e-atomic-fruits-vault-crossplane.yml | 2 +- .github/workflows/e2e-atomic-fruits-vault.yml | 2 +- scripts/data/credentials.sh | 20 +++++++++++-------- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/.github/workflows/e2e-atomic-fruits-vault-crossplane.yml b/.github/workflows/e2e-atomic-fruits-vault-crossplane.yml index e55b8417..ccc15b95 100644 --- a/.github/workflows/e2e-atomic-fruits-vault-crossplane.yml +++ b/.github/workflows/e2e-atomic-fruits-vault-crossplane.yml @@ -85,7 +85,7 @@ jobs: ./scripts/data/services.sh url=$PRIMAZA_URL service_name=activemq-artemis version=2.26 type=activemq endpoint=tcp:8161 ./scripts/data/services.sh url=$PRIMAZA_URL service_name=mariadb version=10.9 type=mariadb endpoint=tcp:3306 - ./scripts/data/credentials.sh url=$PRIMAZA_URL credential_name=fruits_database-vault-creds service_name=postgresql vault_kv=primaza/fruits + ./scripts/data/credentials.sh url=$PRIMAZA_URL credential_type=vault credential_name=fruits_database-vault-creds service_name=postgresql vault_kv=primaza/fruits - name: Installing Vault run: | diff --git a/.github/workflows/e2e-atomic-fruits-vault.yml b/.github/workflows/e2e-atomic-fruits-vault.yml index d600e989..c8b0f118 100644 --- a/.github/workflows/e2e-atomic-fruits-vault.yml +++ b/.github/workflows/e2e-atomic-fruits-vault.yml @@ -84,7 +84,7 @@ jobs: ./scripts/data/services.sh url=$PRIMAZA_URL service_name=activemq-artemis version=2.26 type=activemq endpoint=tcp:8161 ./scripts/data/services.sh url=$PRIMAZA_URL service_name=mariadb version=10.9 type=mariadb endpoint=tcp:3306 - ./scripts/data/credentials.sh url=$PRIMAZA_URL credential_name=fruits_database-vault-creds service_name=postgresql vault_kv=primaza/fruits + ./scripts/data/credentials.sh url=$PRIMAZA_URL credential_type=vault credential_name=fruits_database-vault-creds service_name=postgresql vault_kv=primaza/fruits - name: Installing Vault run: | diff --git a/scripts/data/credentials.sh b/scripts/data/credentials.sh index fc3fc924..6cc77600 100755 --- a/scripts/data/credentials.sh +++ b/scripts/data/credentials.sh @@ -18,6 +18,7 @@ NO_WAIT=true # Default parameter values DEFAULT_PRIMAZA_URL="localhost:8080" +DEFAULT_CREDENTIAL_TYPE="basic" DEFAULT_CREDENTIAL_NAME="" DEFAULT_SERVICE_NAME="" DEFAULT_USERNAME="" @@ -35,6 +36,9 @@ parse_parameters() { credential_name=*) CREDENTIAL_NAME="${arg#*=}" ;; + credential_type=*) + CREDENTIAL_TYPE="${arg#*=}" + ;; service_name=*) SERVICE_NAME="${arg#*=}" ;; @@ -65,6 +69,7 @@ parse_parameters "$@" # Set defaults if parameters are not provided PRIMAZA_URL=${PRIMAZA_URL:-$DEFAULT_PRIMAZA_URL} CREDENTIAL_NAME=${CREDENTIAL_NAME:-$DEFAULT_CREDENTIAL_NAME} +CREDENTIAL_TYPE=${CREDENTIAL_TYPE:-$DEFAULT_CREDENTIAL_TYPE} SERVICE_ID=${SERVICE_ID:-$DEFAULT_SERVICE_ID} SERVICE_NAME=${SERVICE_NAME:-$DEFAULT_SERVICE_NAME} USERNAME=${USERNAME:-$DEFAULT_USERNAME} @@ -83,14 +88,13 @@ else note "Service id found: $SERVICE_ID" fi -if [ -z "$USERNAME" ] && [ -z "$PASSWORD" ]; then - BODY="name=$CREDENTIAL_NAME&serviceId=$SERVICE_ID&vaultKvPath=primaza/fruits" -else - BODY="name=$CREDENTIAL_NAME&serviceId=$SERVICE_ID&username=$USERNAME&password=$PASSWORD¶ms=database:$DATABASE_NAME" -fi - -note "Creating the credential using as body: $BODY" -note "curl -X POST -s -k -d \"${BODY}\" ${PRIMAZA_URL}/credentials" >&2 +case $CREDENTIAL_TYPE in + basic) + BODY="type=$CREDENTIAL_TYPE&name=$CREDENTIAL_NAME&serviceId=$SERVICE_ID&username=$USERNAME&password=$PASSWORD¶ms=database:$DATABASE_NAME" + ;; + vault) + BODY="type=$CREDENTIAL_TYPE&name=$CREDENTIAL_NAME&serviceId=$SERVICE_ID&vaultKvPath=$VAULT_KV" +esac RESPONSE=$(curl -s -k -o response.txt -w '%{http_code}' \ -X POST \ From 61694ab018555791e9fa26c0a2c284db1a4d5538 Mon Sep 17 00:00:00 2001 From: cmoulliard Date: Tue, 26 Sep 2023 16:45:28 +0200 Subject: [PATCH 05/21] Adding the missing field: credentialType to the createCredential method Signed-off-by: cmoulliard --- app/src/test/java/io/halkyon/ApplicationsPageTest.java | 9 ++++++--- app/src/test/java/io/halkyon/CredentialsPageTest.java | 4 ++-- app/src/test/java/io/halkyon/utils/TestUtils.java | 3 ++- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/app/src/test/java/io/halkyon/ApplicationsPageTest.java b/app/src/test/java/io/halkyon/ApplicationsPageTest.java index dc41c8c5..56d7ec1b 100644 --- a/app/src/test/java/io/halkyon/ApplicationsPageTest.java +++ b/app/src/test/java/io/halkyon/ApplicationsPageTest.java @@ -148,13 +148,14 @@ public void testBindApplication() throws ClusterConnectException { String claimName = prefix + "claim"; String serviceName = prefix + "service"; String credentialName = prefix + "credential"; + String credentialType = "basic"; String appName = prefix + "app"; // mock data configureMockServiceFor(clusterName, "testbind", "1111", "ns1"); configureMockApplicationFor(clusterName, appName, "image2", "ns1"); // create data Service service = createService(serviceName, "version", "type", "testbind:1111"); - createCredential(credentialName, service.id, "user1", "pass1", null); + createCredential(credentialName, credentialType, service.id, "user1", "pass1", null); createCluster(clusterName, "host:9999"); serviceDiscoveryJob.execute(); // this action will change the service to available Claim claim = createClaim(claimName, serviceName + "-version"); @@ -209,6 +210,7 @@ public void testBindApplicationUsingServiceFromAnotherCluster() throws ClusterCo String claimName = prefix + "claim"; String serviceName = prefix + "service"; String credentialName = prefix + "credential"; + String credentialType = "basic"; String appName = prefix + "app"; String externalServiceIp = serviceName + "ip"; @@ -218,7 +220,7 @@ public void testBindApplicationUsingServiceFromAnotherCluster() throws ClusterCo // create data Service service = createService(serviceName, "version", "type", "testbind:1111"); - createCredential(credentialName, service.id, "user1", "pass1", null); + createCredential(credentialName, credentialType, service.id, "user1", "pass1", null); createCluster(clusterNameOfService, "host:9999"); createCluster(clusterNameOfApplication, "host:9999"); serviceDiscoveryJob.execute(); // this action will change the service to available @@ -314,6 +316,7 @@ public void testBindApplicationGettingCredentialsFromVault() throws ClusterConne String claimName = prefix + "claim"; String serviceName = prefix + "service"; String credentialName = prefix + "credential"; + String credentialType = "vault"; String appName = prefix + "app"; String username = "user1"; String password = "pass1"; @@ -323,7 +326,7 @@ public void testBindApplicationGettingCredentialsFromVault() throws ClusterConne configureMockApplicationFor(clusterName, appName, "image2", "ns1"); // create data Service service = createService(serviceName, "version", "type", "testbind:1111"); - createCredential(credentialName, service.id, null, null, "myapps/app"); + createCredential(credentialName, credentialType, service.id, null, null, "myapps/app"); createCluster(clusterName, "host:9999"); Map newsecrets = new HashMap<>(); diff --git a/app/src/test/java/io/halkyon/CredentialsPageTest.java b/app/src/test/java/io/halkyon/CredentialsPageTest.java index f7b77d01..e1e3ede5 100644 --- a/app/src/test/java/io/halkyon/CredentialsPageTest.java +++ b/app/src/test/java/io/halkyon/CredentialsPageTest.java @@ -61,7 +61,7 @@ public void testEditCredentialFromPage() { // Create data String prefix = "CredentialsPageTest-testEditCredentialFromPage-"; Service service = createService(prefix + "service", "8", "type"); - Credential credential = createCredential(prefix + "credential", service.id, "user", "pass", + Credential credential = createCredential(prefix + "credential", "basic", service.id, "user", "pass", "myapps/vault-quickstart/private"); // Go to the page page.goTo("/credentials"); @@ -85,7 +85,7 @@ public void testEditCredentialFromPage() { public void testDeleteCredential() { String prefix = "CredentialsPageTest-testDeleteCredential-"; Service service = createService(prefix + "service", "8", "postgresql"); - Credential credential = createCredential(prefix + "credential", service.id, "user", "pass", + Credential credential = createCredential(prefix + "credential", "basic", service.id, "user", "pass", "myapps/vault-quickstart/private"); // When, we go to the credentials page diff --git a/app/src/test/java/io/halkyon/utils/TestUtils.java b/app/src/test/java/io/halkyon/utils/TestUtils.java index 8ccd99e2..c0105e3b 100644 --- a/app/src/test/java/io/halkyon/utils/TestUtils.java +++ b/app/src/test/java/io/halkyon/utils/TestUtils.java @@ -110,9 +110,10 @@ public static Application createApplication(String applicationName, String clust return app; } - public static Credential createCredential(String credentialName, long serviceId, String username, String password, + public static Credential createCredential(String credentialName, String credentialType, long serviceId, String username, String password, String vaultPath) { given().contentType(MediaType.APPLICATION_FORM_URLENCODED).formParam("name", credentialName) + .formParam("credentialType",credentialType) .formParam("serviceId", serviceId).formParam("username", username).formParam("password", password) .formParam("vaultKvPath", vaultPath).when().post("/credentials").then().statusCode(201); From a3a3cb8b03deebd0984391a4f89b430d6f0875c7 Mon Sep 17 00:00:00 2001 From: cmoulliard Date: Wed, 27 Sep 2023 09:36:38 +0200 Subject: [PATCH 06/21] Format the code Signed-off-by: cmoulliard --- app/src/test/java/io/halkyon/utils/TestUtils.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/src/test/java/io/halkyon/utils/TestUtils.java b/app/src/test/java/io/halkyon/utils/TestUtils.java index c0105e3b..92fcef04 100644 --- a/app/src/test/java/io/halkyon/utils/TestUtils.java +++ b/app/src/test/java/io/halkyon/utils/TestUtils.java @@ -110,12 +110,12 @@ public static Application createApplication(String applicationName, String clust return app; } - public static Credential createCredential(String credentialName, String credentialType, long serviceId, String username, String password, - String vaultPath) { + public static Credential createCredential(String credentialName, String credentialType, long serviceId, + String username, String password, String vaultPath) { given().contentType(MediaType.APPLICATION_FORM_URLENCODED).formParam("name", credentialName) - .formParam("credentialType",credentialType) - .formParam("serviceId", serviceId).formParam("username", username).formParam("password", password) - .formParam("vaultKvPath", vaultPath).when().post("/credentials").then().statusCode(201); + .formParam("credentialType", credentialType).formParam("serviceId", serviceId) + .formParam("username", username).formParam("password", password).formParam("vaultKvPath", vaultPath) + .when().post("/credentials").then().statusCode(201); return given().contentType(MediaType.APPLICATION_JSON).get("/credentials/name/" + credentialName).then() .statusCode(200).extract().as(Credential.class); From d1d9f417d95d3291c536ceaa4cf84a3e9874895e Mon Sep 17 00:00:00 2001 From: cmoulliard Date: Wed, 27 Sep 2023 09:39:34 +0200 Subject: [PATCH 07/21] Passing the needed parameter: credentialType to the createCredential method Signed-off-by: cmoulliard --- app/src/test/java/io/halkyon/utils/TestUtils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/test/java/io/halkyon/utils/TestUtils.java b/app/src/test/java/io/halkyon/utils/TestUtils.java index 92fcef04..cff98da1 100644 --- a/app/src/test/java/io/halkyon/utils/TestUtils.java +++ b/app/src/test/java/io/halkyon/utils/TestUtils.java @@ -48,7 +48,7 @@ public static Service createService(String serviceName, String serviceVersion, S public static Service createServiceWithCredential(String serviceName, String serviceVersion, String serviceType, String endpoint) { Service service = createService(serviceName, serviceVersion, serviceType, endpoint); - createCredential(serviceName + "-credential", service.id, "username", "password", null); + createCredential(serviceName + "-credential", "basic", service.id, "username", "password", null); return service; } From 7ef275e358d7b8405c9233bd78b27583cde0e00e Mon Sep 17 00:00:00 2001 From: cmoulliard Date: Wed, 27 Sep 2023 10:49:48 +0200 Subject: [PATCH 08/21] Adding the missing credential_type to the HTML Page test Signed-off-by: cmoulliard --- app/src/test/java/io/halkyon/CredentialsPageTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/test/java/io/halkyon/CredentialsPageTest.java b/app/src/test/java/io/halkyon/CredentialsPageTest.java index e1e3ede5..8d8c78ae 100644 --- a/app/src/test/java/io/halkyon/CredentialsPageTest.java +++ b/app/src/test/java/io/halkyon/CredentialsPageTest.java @@ -29,6 +29,7 @@ public void testCreateNewCredential() { // set data page.select("credential_service", "postgresql-credential1-8"); page.type("credential_name", "Credential1"); + page.type("credential_type","basic") page.type("credential_username", "Admin"); page.type("credential_password", "Supersecret"); page.type("credential_vault_path", "myapps/vault-quickstart/private"); From 480ca8e8a160ffeb97e368eb0354c513998c3ce3 Mon Sep 17 00:00:00 2001 From: cmoulliard Date: Wed, 27 Sep 2023 10:52:28 +0200 Subject: [PATCH 09/21] Adding the missing trailing ; Signed-off-by: cmoulliard --- app/src/test/java/io/halkyon/CredentialsPageTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/test/java/io/halkyon/CredentialsPageTest.java b/app/src/test/java/io/halkyon/CredentialsPageTest.java index 8d8c78ae..658a3f95 100644 --- a/app/src/test/java/io/halkyon/CredentialsPageTest.java +++ b/app/src/test/java/io/halkyon/CredentialsPageTest.java @@ -29,7 +29,7 @@ public void testCreateNewCredential() { // set data page.select("credential_service", "postgresql-credential1-8"); page.type("credential_name", "Credential1"); - page.type("credential_type","basic") + page.type("credential_type","basic"); page.type("credential_username", "Admin"); page.type("credential_password", "Supersecret"); page.type("credential_vault_path", "myapps/vault-quickstart/private"); From c0e0d528bca13842e952b94a79a6960e2a5464f8 Mon Sep 17 00:00:00 2001 From: cmoulliard Date: Wed, 27 Sep 2023 10:54:26 +0200 Subject: [PATCH 10/21] Reformating the java code Signed-off-by: cmoulliard --- app/src/test/java/io/halkyon/CredentialsPageTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/test/java/io/halkyon/CredentialsPageTest.java b/app/src/test/java/io/halkyon/CredentialsPageTest.java index 658a3f95..65576aca 100644 --- a/app/src/test/java/io/halkyon/CredentialsPageTest.java +++ b/app/src/test/java/io/halkyon/CredentialsPageTest.java @@ -29,7 +29,7 @@ public void testCreateNewCredential() { // set data page.select("credential_service", "postgresql-credential1-8"); page.type("credential_name", "Credential1"); - page.type("credential_type","basic"); + page.type("credential_type", "basic"); page.type("credential_username", "Admin"); page.type("credential_password", "Supersecret"); page.type("credential_vault_path", "myapps/vault-quickstart/private"); From bd82908d4c7434af02cf5f1f58a3993ed2d2bf40 Mon Sep 17 00:00:00 2001 From: cmoulliard Date: Wed, 27 Sep 2023 11:02:43 +0200 Subject: [PATCH 11/21] Changing the action from type to select as this is a popup list Signed-off-by: cmoulliard --- app/src/test/java/io/halkyon/CredentialsPageTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/test/java/io/halkyon/CredentialsPageTest.java b/app/src/test/java/io/halkyon/CredentialsPageTest.java index 65576aca..d4d408ae 100644 --- a/app/src/test/java/io/halkyon/CredentialsPageTest.java +++ b/app/src/test/java/io/halkyon/CredentialsPageTest.java @@ -29,7 +29,7 @@ public void testCreateNewCredential() { // set data page.select("credential_service", "postgresql-credential1-8"); page.type("credential_name", "Credential1"); - page.type("credential_type", "basic"); + page.select("credential_type", "basic"); page.type("credential_username", "Admin"); page.type("credential_password", "Supersecret"); page.type("credential_vault_path", "myapps/vault-quickstart/private"); From 3b6e9860560960fe22ae5d5c5dbfd3291592c785 Mon Sep 17 00:00:00 2001 From: cmoulliard Date: Wed, 27 Sep 2023 11:16:13 +0200 Subject: [PATCH 12/21] Creating 2 test cases able to test according to the type: basic or vault Signed-off-by: cmoulliard --- .../java/io/halkyon/CredentialsPageTest.java | 40 +++++++++++++++++-- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/app/src/test/java/io/halkyon/CredentialsPageTest.java b/app/src/test/java/io/halkyon/CredentialsPageTest.java index d4d408ae..b7f9e4fb 100644 --- a/app/src/test/java/io/halkyon/CredentialsPageTest.java +++ b/app/src/test/java/io/halkyon/CredentialsPageTest.java @@ -15,9 +15,12 @@ public class CredentialsPageTest extends BaseTest { @Test - public void testCreateNewCredential() { + public void testCreateNewBasicCredential() { createService("postgresql-credential1", "8", "postgresql"); page.goTo("/credentials/new"); + + page.select("credential_type", "basic"); + // add param a=1 page.type("new-param-name", "a"); page.type("new-param-value", "1"); @@ -26,13 +29,13 @@ public void testCreateNewCredential() { page.type("new-param-name", "b"); page.type("new-param-value", "2"); page.clickById("add-param-to-credential-button"); + // set data page.select("credential_service", "postgresql-credential1-8"); page.type("credential_name", "Credential1"); - page.select("credential_type", "basic"); page.type("credential_username", "Admin"); page.type("credential_password", "Supersecret"); - page.type("credential_vault_path", "myapps/vault-quickstart/private"); + // submit credential page.clickById("credential-button"); @@ -43,7 +46,7 @@ public void testCreateNewCredential() { .as(Credential.class); assertEquals("Admin", credential.username); assertEquals("Supersecret", credential.password); - assertEquals("myapps/vault-quickstart/private", credential.vaultKvPath); + assertEquals(2, credential.params.size()); assertEquals("a", credential.params.get(0).paramName); assertEquals("1", credential.params.get(0).paramValue); @@ -57,6 +60,35 @@ public void testCreateNewCredential() { assertEquals("Credential1", service.credentials.get(0).name); } + @Test + public void testCreateNewVaultCredential() { + createService("postgresql-credential1", "8", "postgresql"); + page.goTo("/credentials/new"); + + page.select("credential_type", "vault"); + + // set data + page.select("credential_service", "postgresql-credential1-8"); + page.type("credential_name", "Credential1"); + + page.type("credential_vault_path", "myapps/vault-quickstart/private"); + // submit credential + page.clickById("credential-button"); + + // then, the new credential should be listed: + page.goTo("/credentials"); + page.assertContentContains("Credential1"); + Credential credential = given().when().get("/credentials/name/Credential1").then().statusCode(200).extract() + .as(Credential.class); + assertEquals("myapps/vault-quickstart/private", credential.vaultKvPath); + + // and the service should have been linked to it. + Service service = given().when().get("/services/name/postgresql-credential1").then().statusCode(200).extract() + .as(Service.class); + assertEquals(1, service.credentials.size()); + assertEquals("Credential1", service.credentials.get(0).name); + } + @Test public void testEditCredentialFromPage() { // Create data From 12d6a1f457d2a798da780a5bf44d7e35cdb5e94e Mon Sep 17 00:00:00 2001 From: cmoulliard Date: Wed, 27 Sep 2023 14:02:08 +0200 Subject: [PATCH 13/21] Copy the request.type to the credential.type Signed-off-by: cmoulliard --- app/src/main/java/io/halkyon/services/CredentialService.java | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/java/io/halkyon/services/CredentialService.java b/app/src/main/java/io/halkyon/services/CredentialService.java index 533a2f0f..375987f2 100644 --- a/app/src/main/java/io/halkyon/services/CredentialService.java +++ b/app/src/main/java/io/halkyon/services/CredentialService.java @@ -59,6 +59,7 @@ private Credential mergeEntities(Credential old, Credential edited) { public Credential initializeCredential(CredentialRequest request) { Credential credential = new Credential(); credential.name = request.name; + credential.type = request.type; credential.username = request.username; credential.password = request.password; if (request.vaultKvPath != null) { From cfc1f25e10415102ef4a5181bac1fa6a88b0b90a Mon Sep 17 00:00:00 2001 From: cmoulliard Date: Wed, 27 Sep 2023 14:05:05 +0200 Subject: [PATCH 14/21] Renaming the method to testCreateUserPasswordCredential as more meaningfull Signed-off-by: cmoulliard --- app/src/test/java/io/halkyon/CredentialsPageTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/test/java/io/halkyon/CredentialsPageTest.java b/app/src/test/java/io/halkyon/CredentialsPageTest.java index b7f9e4fb..7465df13 100644 --- a/app/src/test/java/io/halkyon/CredentialsPageTest.java +++ b/app/src/test/java/io/halkyon/CredentialsPageTest.java @@ -15,7 +15,7 @@ public class CredentialsPageTest extends BaseTest { @Test - public void testCreateNewBasicCredential() { + public void testCreateUserPasswordCredential() { createService("postgresql-credential1", "8", "postgresql"); page.goTo("/credentials/new"); From c99074a41eaaba8e6d1ad724b3f5b453d1b5d595 Mon Sep 17 00:00:00 2001 From: cmoulliard Date: Wed, 27 Sep 2023 15:22:50 +0200 Subject: [PATCH 15/21] Renaming the wrong HTML name from serviceID to type Signed-off-by: cmoulliard --- app/src/main/resources/templates/credentials/form.html | 2 +- app/src/test/java/io/halkyon/CredentialsPageTest.java | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/app/src/main/resources/templates/credentials/form.html b/app/src/main/resources/templates/credentials/form.html index 8528f3e5..38a884f0 100644 --- a/app/src/main/resources/templates/credentials/form.html +++ b/app/src/main/resources/templates/credentials/form.html @@ -18,7 +18,7 @@

Update Credential

-