mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(secretsmanager): split the "all" filter value into words (#8388)
This commit is contained in:
1 parent
6971626d82
commit
d6cf46ba3d
3 files changed
+123
-6
No files matched your search
@@ -1887,4 +1887,22 @@ class SecretsManagerJsonHandlerTest {
|
||||
() -> handler.handle("CreateSecret", req, REGION));
|
||||
assertThat(ex.getErrorCode(), is("InvalidParameterException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void listSecretsAllFilterSplitsValueIntoWords() {
|
||||
ObjectNode createReq = MAPPER.createObjectNode();
|
||||
createReq.put("Name", "database");
|
||||
createReq.put("Description", "production credentials");
|
||||
handler.handle("CreateSecret", createReq, REGION);
|
||||
ObjectNode otherReq = MAPPER.createObjectNode();
|
||||
otherReq.put("Name", "unrelated");
|
||||
handler.handle("CreateSecret", otherReq, REGION);
|
||||
|
||||
ObjectNode listReq = MAPPER.createObjectNode();
|
||||
listReq.putArray("Filters").addObject().put("Key", "all").putArray("Values").add("database production");
|
||||
ObjectNode listed = (ObjectNode) handler.handle("ListSecrets", listReq, REGION).getEntity();
|
||||
|
||||
assertThat(listed.get("SecretList").size(), is(1));
|
||||
assertThat(listed.get("SecretList").get(0).get("Name").asText(), is("database"));
|
||||
}
|
||||
}
|
||||
@@ -1801,4 +1801,73 @@ class SecretsManagerServiceTest {
|
||||
assertEquals(List.of("AWSCURRENT"), after.getVersions().get(current).getVersionStages());
|
||||
assertEquals(current, after.getCurrentVersionId());
|
||||
}
|
||||
|
||||
@Test
|
||||
void listSecretsAllFilterSplitsValueIntoWords() {
|
||||
service.createSecret("database", "v", null, "production credentials", null, null, REGION);
|
||||
service.createSecret("unrelated", "v", null, "nothing here", null, null, REGION);
|
||||
List<SecretsManagerService.Filter> filters =
|
||||
List.of(new SecretsManagerService.Filter("all", List.of("Database PRODUCTION")));
|
||||
|
||||
List<Secret> found = service.listSecrets(REGION, filters);
|
||||
|
||||
assertEquals(List.of("database"), found.stream().map(Secret::getName).toList());
|
||||
}
|
||||
|
||||
@Test
|
||||
void listSecretsAllFilterMatchesWordPrefixInTagsAndNegates() {
|
||||
service.createSecret("alpha", "v", null, null, null, List.of(new Secret.Tag("Team", "Platform")), REGION);
|
||||
service.createSecret("beta", "v", null, null, null, null, REGION);
|
||||
|
||||
List<Secret> tagged = service.listSecrets(REGION,
|
||||
List.of(new SecretsManagerService.Filter("all", List.of("zzz plat"))));
|
||||
List<Secret> others = service.listSecrets(REGION,
|
||||
List.of(new SecretsManagerService.Filter("all", List.of("!plat zzz"))));
|
||||
|
||||
assertEquals(List.of("alpha"), tagged.stream().map(Secret::getName).toList());
|
||||
assertEquals(List.of("beta"), others.stream().map(Secret::getName).toList());
|
||||
}
|
||||
|
||||
@Test
|
||||
void batchGetSecretValueByFiltersAllFilterSplitsValueIntoWords() {
|
||||
service.createSecret("database", "v1", null, "production credentials", null, null, REGION);
|
||||
service.createSecret("unrelated", "v2", null, "nothing here", null, null, REGION);
|
||||
|
||||
List<SecretsManagerService.BatchSecretValue> found = service.batchGetSecretValueByFilters(
|
||||
List.of(new SecretsManagerService.Filter("all", List.of("database production"))), REGION);
|
||||
|
||||
assertEquals(List.of("database"), found.stream().map(SecretsManagerService.BatchSecretValue::name).toList());
|
||||
}
|
||||
|
||||
@Test
|
||||
void allFilterKeepsANumberFollowedByLettersAsOneWord() {
|
||||
service.createSecret("db2prod", "v1", null, null, null, null, REGION);
|
||||
service.createSecret("prod2db", "v2", null, null, null, null, REGION);
|
||||
|
||||
List<Secret> found = service.listSecrets(REGION,
|
||||
List.of(new SecretsManagerService.Filter("all", List.of("prod"))));
|
||||
|
||||
assertEquals(List.of("prod2db"), found.stream().map(Secret::getName).toList());
|
||||
}
|
||||
|
||||
@Test
|
||||
void allFilterWithEmptyValueMatchesEverySecretAndItsNegationMatchesNone() {
|
||||
service.createSecret("alpha", "v1", null, null, null, null, REGION);
|
||||
service.createSecret("beta", "v2", null, "some description", null, null, REGION);
|
||||
|
||||
List<Secret> listedEmpty = service.listSecrets(REGION,
|
||||
List.of(new SecretsManagerService.Filter("all", List.of(""))));
|
||||
List<Secret> listedNegated = service.listSecrets(REGION,
|
||||
List.of(new SecretsManagerService.Filter("all", List.of("!"))));
|
||||
List<SecretsManagerService.BatchSecretValue> batchEmpty = service.batchGetSecretValueByFilters(
|
||||
List.of(new SecretsManagerService.Filter("all", List.of(""))), REGION);
|
||||
List<SecretsManagerService.BatchSecretValue> batchNegated = service.batchGetSecretValueByFilters(
|
||||
List.of(new SecretsManagerService.Filter("all", List.of("!"))), REGION);
|
||||
|
||||
assertEquals(List.of("alpha", "beta"), listedEmpty.stream().map(Secret::getName).sorted().toList());
|
||||
assertEquals(List.of(), listedNegated.stream().map(Secret::getName).toList());
|
||||
assertEquals(List.of("alpha", "beta"),
|
||||
batchEmpty.stream().map(SecretsManagerService.BatchSecretValue::name).sorted().toList());
|
||||
assertEquals(List.of(), batchNegated.stream().map(SecretsManagerService.BatchSecretValue::name).toList());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user