Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue-403 #404

Merged
merged 21 commits into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
1767bc4
WIP. Adding a new field: type to display or hidesome fields
cmoulliard May 12, 2023
cbcff11
WIP. Add a note to specify that a new test case is needed. #403
cmoulliard Sep 25, 2023
f78ad26
Add a new JS function able to collapse (or not) the fields according …
cmoulliard Sep 26, 2023
8461247
Adding the missing new parameter credential_type
cmoulliard Sep 26, 2023
61694ab
Adding the missing field: credentialType to the createCredential method
cmoulliard Sep 26, 2023
a3a3cb8
Format the code
cmoulliard Sep 27, 2023
d1d9f41
Passing the needed parameter: credentialType to the createCredential …
cmoulliard Sep 27, 2023
7ef275e
Adding the missing credential_type to the HTML Page test
cmoulliard Sep 27, 2023
480ca8e
Adding the missing trailing ;
cmoulliard Sep 27, 2023
c0e0d52
Reformating the java code
cmoulliard Sep 27, 2023
bd82908
Changing the action from type to select as this is a popup list
cmoulliard Sep 27, 2023
3b6e986
Creating 2 test cases able to test according to the type: basic or vault
cmoulliard Sep 27, 2023
12d6a1f
Copy the request.type to the credential.type
cmoulliard Sep 27, 2023
cfc1f25
Renaming the method to testCreateUserPasswordCredential as more meani…
cmoulliard Sep 27, 2023
c99074a
Renaming the wrong HTML name from serviceID to type
cmoulliard Sep 27, 2023
2cfa605
Fix wrong form name for the credential type
cmoulliard Sep 27, 2023
4f0a4f4
Reformat the code
cmoulliard Sep 27, 2023
238387f
Include also the Vault Path part of the table displayed
cmoulliard Sep 27, 2023
1d64fb1
Changing the name of the service
cmoulliard Sep 27, 2023
7bc00c0
Changing the name of the credential for vault test to credential2 and…
cmoulliard Sep 27, 2023
6701ff8
Adding the missing parameter: credential_type
cmoulliard Sep 27, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/e2e-atomic-fruits-vault-crossplane.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/e2e-atomic-fruits-vault.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/java/io/halkyon/model/Credential.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ public class CredentialRequest {
@FormParam
public String name;

@NotBlank
@FormParam
public String type;

@NotNull
@FormParam
public Long serviceId;
Expand Down
325 changes: 194 additions & 131 deletions app/src/main/resources/templates/credentials/form.html

Large diffs are not rendered by default.

9 changes: 6 additions & 3 deletions app/src/test/java/io/halkyon/ApplicationsPageTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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";

Expand All @@ -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
Expand Down Expand Up @@ -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";
Expand All @@ -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<String, String> newsecrets = new HashMap<>();
Expand Down
43 changes: 38 additions & 5 deletions app/src/test/java/io/halkyon/CredentialsPageTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@
public class CredentialsPageTest extends BaseTest {

@Test
public void testCreateNewCredential() {
public void testCreateNewBasicCredential() {
aureamunoz marked this conversation as resolved.
Show resolved Hide resolved
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");
Expand All @@ -26,12 +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.type("credential_username", "Admin");
page.type("credential_password", "Supersecret");
page.type("credential_vault_path", "myapps/vault-quickstart/private");

// submit credential
page.clickById("credential-button");

Expand All @@ -42,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);
Expand All @@ -56,12 +60,41 @@ 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
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");
Expand All @@ -85,7 +118,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
Expand Down
11 changes: 6 additions & 5 deletions app/src/test/java/io/halkyon/utils/TestUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -110,11 +110,12 @@ public static Application createApplication(String applicationName, String clust
return app;
}

public static Credential createCredential(String credentialName, 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("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);
Expand Down
20 changes: 12 additions & 8 deletions scripts/data/credentials.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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=""
Expand All @@ -35,6 +36,9 @@ parse_parameters() {
credential_name=*)
CREDENTIAL_NAME="${arg#*=}"
;;
credential_type=*)
CREDENTIAL_TYPE="${arg#*=}"
;;
service_name=*)
SERVICE_NAME="${arg#*=}"
;;
Expand Down Expand Up @@ -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}
Expand All @@ -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&params=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&params=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 \
Expand Down
Loading