Skip to content

Commit

Permalink
control-service: allow delete-all-secrets command (#2523)
Browse files Browse the repository at this point in the history
Fix a bug which prevents the delete-all-secrets cli command to work.

Signed-off-by: Dako Dakov <[email protected]>
  • Loading branch information
dakodakov authored Aug 7, 2023
1 parent a4bce83 commit ec50067
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,18 @@ public void testSetDataJobSecrets() throws Exception {
Assertions.assertEquals(secrets, readResult);
}

@Test
public void testSetEmptyDataJobSecrets() throws Exception {
Map<String, Object> temp = new HashMap<>();

Map<String, Object> secrets = Collections.unmodifiableMap(temp);

vaultJobSecretService.updateJobSecrets("testJob2", secrets);

Map<String, Object> readResult = vaultJobSecretService.readJobSecrets("testJob2");
Assertions.assertEquals(secrets, readResult);
}

@Test
void testUpdateJobSecretsLimit() throws JsonProcessingException {
Map<String, Object> temp = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ public VaultJobSecretsService(VaultOperations vaultOperations) {
public void updateJobSecrets(String jobName, Map<String, Object> secrets) {

checkJobName(jobName);
checkJobSecretsMap(jobName, secrets);

Versioned<VaultJobSecrets> readResponse =
vaultOperations.opsForVersionedKeyValue(SECRET).get(jobName, VaultJobSecrets.class);
Expand Down Expand Up @@ -102,10 +101,4 @@ private void checkJobName(String jobName) {
throw new DataJobSecretsException(jobName, "Data Job Name cannot be blank");
}
}

private void checkJobSecretsMap(String jobName, Map<String, Object> secrets) {
if (secrets == null || secrets.isEmpty()) {
throw new DataJobSecretsException(jobName, "Secrets parameter cannot be null or empty");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ void testUpdateJobSecretsNulls() throws JsonProcessingException {
String blankJobName = " ";
String nullJobName = null;
Map<String, Object> secrets = new HashMap<>();
Map<String, Object> nullSecrets = new HashMap<>();

Throwable t =
assertThrows(
Expand All @@ -120,20 +119,5 @@ void testUpdateJobSecretsNulls() throws JsonProcessingException {
() -> secretsService.updateJobSecrets(nullJobName, secrets));

Assert.assertThat(t.getMessage(), CoreMatchers.containsString("Data Job Name cannot be blank"));

t =
assertThrowsExactly(
DataJobSecretsException.class, () -> secretsService.updateJobSecrets(jobName, secrets));

Assert.assertThat(
t.getMessage(), CoreMatchers.containsString("Secrets parameter cannot be null or empty"));

t =
assertThrowsExactly(
DataJobSecretsException.class,
() -> secretsService.updateJobSecrets(jobName, nullSecrets));

Assert.assertThat(
t.getMessage(), CoreMatchers.containsString("Secrets parameter cannot be null or empty"));
}
}

0 comments on commit ec50067

Please sign in to comment.