Skip to content

Commit

Permalink
SecretClient doesn't seem to be retrieving managed secrets (#830)
Browse files Browse the repository at this point in the history
- Fixes the list key and list secret endpoints to contain managed entities as well
- Fixes the list deleted key and list deleted secret endpoints to return managed entities
- Updates converter logic to include managed flag in case managed entities are listed
- Updates Codecov links in Readmes
- Updates tests
- Adds new steps to verify managed flags in end-to-end tests

Resolves #827
{minor}

Signed-off-by: Esta Nagy <nagyesta@gmail.com>
  • Loading branch information
nagyesta authored Jan 12, 2024
1 parent 5f68977 commit 05a4e36
Show file tree
Hide file tree
Showing 25 changed files with 134 additions and 74 deletions.
2 changes: 1 addition & 1 deletion lowkey-vault-app/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
[![latest-release](https://img.shields.io/github/v/tag/nagyesta/lowkey-vault?color=blue&logo=git&label=releases&sort=semver)](https://github.com/nagyesta/lowkey-vault/releases)
[![Docker Hub](https://img.shields.io/docker/v/nagyesta/lowkey-vault?label=docker%20hub&logo=docker&sort=semver)](https://hub.docker.com/r/nagyesta/lowkey-vault)
[![JavaCI](https://img.shields.io/github/actions/workflow/status/nagyesta/lowkey-vault/gradle.yml?logo=github&branch=main)](https://github.com/nagyesta/lowkey-vault/actions/workflows/gradle.yml)
[![codecov](https://img.shields.io/codecov/c/github/nagyesta/lowkey-vault?label=Coverage&flag=app&token=3ZZ9Q4S5WW)](https://img.shields.io/codecov/c/github/nagyesta/lowkey-vault?label=Coverage&flag=app&token=3ZZ9Q4S5WW)
[![codecov](https://img.shields.io/codecov/c/github/nagyesta/lowkey-vault?label=Coverage&flag=app&token=3ZZ9Q4S5WW)](https://app.codecov.io/gh/nagyesta/lowkey-vault?flags%5B0%5D=app)
[![badge-abort-mission-armed-green](https://raw.githubusercontent.com/nagyesta/abort-mission/wiki_assets/.github/assets/badge-abort-mission-armed-green.svg)](https://github.com/nagyesta/abort-mission)

# Lowkey Vault - App
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ protected KeyVaultItemListModel<I> getPageOfItemVersions(
@SuppressWarnings("SameParameterValue")
protected KeyVaultItemListModel<I> getPageOfItems(final URI baseUri, final PaginationContext pagination) {
final S entityVaultFake = getVaultByUri(baseUri);
final List<E> allItems = entityVaultFake.getEntities().listLatestNonManagedEntities();
final List<E> allItems = entityVaultFake.getEntities().listLatestEntities();
final List<I> items = filterList(pagination.getLimit(), pagination.getOffset(), allItems,
source -> registry.itemConverter(apiVersion()).convert(source, baseUri));
final URI nextUri = PaginationContext.builder()
Expand All @@ -161,7 +161,7 @@ protected KeyVaultItemListModel<I> getPageOfItems(final URI baseUri, final Pagin
@SuppressWarnings("SameParameterValue")
protected KeyVaultItemListModel<DI> getPageOfDeletedItems(final URI baseUri, final PaginationContext pagination) {
final S entityVaultFake = getVaultByUri(baseUri);
final List<E> allItems = entityVaultFake.getDeletedEntities().listLatestNonManagedEntities();
final List<E> allItems = entityVaultFake.getDeletedEntities().listLatestEntities();
final List<DI> items = filterList(pagination.getLimit(), pagination.getOffset(), allItems,
source -> registry.itemConverter(apiVersion()).convertDeleted(source, baseUri));
final URI nextUri = PaginationContext.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,19 +100,17 @@ private VaultBackupModel backupVault(final VaultService vaultService, final Vaul

private Map<String, KeyBackupList> mapKeys(final VaultFake vaultFake) {
return vaultFake.keyVaultFake().getEntities()
.listLatestEntities().stream()
//exclude managed entities as certificates will take care of those
.filter(r -> !r.isManaged())
.listLatestNonManagedEntities().stream()
.map(ReadOnlyKeyVaultKeyEntity::getId)
.map(VersionedKeyEntityId::id)
.collect(Collectors.toMap(Function.identity(), name -> backupKey(vaultFake.baseUri(), name)));
}

private Map<String, SecretBackupList> mapSecrets(final VaultFake vaultFake) {
return vaultFake.secretVaultFake().getEntities()
.listLatestEntities().stream()
//exclude managed entities as certificates will take care of those
.filter(r -> !r.isManaged())
.listLatestNonManagedEntities().stream()
.map(ReadOnlyKeyVaultSecretEntity::getId)
.map(VersionedSecretEntityId::id)
.collect(Collectors.toMap(Function.identity(), name -> backupSecret(vaultFake.baseUri(), name)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ protected <M extends KeyVaultKeyItemModel> M mapActiveFields(
model.setKeyId(convertKeyId(source, vaultUri));
model.setAttributes(registry.propertiesConverter(supportedVersions().last()).convert(source, vaultUri));
model.setTags(source.getTags());
if (source.isManaged()) {
model.setManaged(true);
}
return model;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ protected <M extends KeyVaultSecretItemModel> M mapActiveFields(
model.setId(convertSecretId(source, vaultUri));
model.setAttributes(registry.propertiesConverter(supportedVersions().last()).convert(source, vaultUri));
model.setTags(source.getTags());
if (source.isManaged()) {
model.setManaged(true);
}
return model;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ void testGetKeysShouldReturnEntryWhenKeyIsFound(
.thenReturn(recoverableDays);
final CreateKeyRequest request = createRequest(operations, expiry, notBefore);
final ReadOnlyKeyVaultKeyEntity entity = createEntity(VERSIONED_KEY_ENTITY_ID_1_VERSION_1, request);
when(entities.listLatestNonManagedEntities())
when(entities.listLatestEntities())
.thenReturn(List.of(entity));
final KeyVaultKeyItemModel keyItemModel = keyVaultKeyItemModel(baseUri.asUri(HTTPS_LOCALHOST_8443), Map.of());
when(keyEntityToV72KeyItemModelConverter.convert(same(entity), eq(HTTPS_LOCALHOST_8443)))
Expand All @@ -594,7 +594,7 @@ void testGetKeysShouldReturnEntryWhenKeyIsFound(
verify(vaultFake).getRecoverableDays();
verify(keyVaultFake, atLeastOnce()).getEntities();
verify(keyVaultFake, never()).getDeletedEntities();
verify(entities).listLatestNonManagedEntities();
verify(entities).listLatestEntities();
verify(keyEntityToV72KeyItemModelConverter).convert(same(entity), eq(HTTPS_LOCALHOST_8443));
}

Expand All @@ -614,7 +614,7 @@ void testGetKeysShouldReturnNextLinkWhenNotOnLastPage(
.thenReturn(recoverableDays);
final CreateKeyRequest request = createRequest(operations, expiry, notBefore);
final ReadOnlyKeyVaultKeyEntity entity = createEntity(VERSIONED_KEY_ENTITY_ID_1_VERSION_1, request);
when(entities.listLatestNonManagedEntities())
when(entities.listLatestEntities())
.thenReturn(List.of(entity, entity, entity));
final KeyVaultKeyItemModel keyItemModel = keyVaultKeyItemModel(baseUri.asUri(HTTPS_LOCALHOST_8443), Map.of());
when(keyEntityToV72KeyItemModelConverter.convert(same(entity), eq(HTTPS_LOCALHOST_8443)))
Expand All @@ -639,7 +639,7 @@ void testGetKeysShouldReturnNextLinkWhenNotOnLastPage(
verify(vaultFake).getRecoverableDays();
verify(keyVaultFake, atLeastOnce()).getEntities();
verify(keyVaultFake, never()).getDeletedEntities();
verify(entities).listLatestNonManagedEntities();
verify(entities).listLatestEntities();
verify(keyEntityToV72KeyItemModelConverter).convert(same(entity), eq(HTTPS_LOCALHOST_8443));
}

Expand All @@ -661,7 +661,7 @@ void testGetDeletedKeysShouldReturnEntryWhenKeyIsFound(
final ReadOnlyKeyVaultKeyEntity entity = createEntity(VERSIONED_KEY_ENTITY_ID_1_VERSION_1, request);
entity.setDeletedDate(TIME_10_MINUTES_AGO);
entity.setScheduledPurgeDate(TIME_IN_10_MINUTES);
when(entities.listLatestNonManagedEntities())
when(entities.listLatestEntities())
.thenReturn(List.of(entity));
final DeletedKeyVaultKeyItemModel keyItemModel = deletedKeyVaultKeyItemModel(baseUri, Map.of());
when(keyEntityToV72KeyItemModelConverter.convertDeleted(same(entity), eq(HTTPS_LOCALHOST_8443)))
Expand All @@ -684,7 +684,7 @@ void testGetDeletedKeysShouldReturnEntryWhenKeyIsFound(
verify(vaultFake).getRecoverableDays();
verify(keyVaultFake, atLeastOnce()).getDeletedEntities();
verify(keyVaultFake, never()).getEntities();
verify(entities).listLatestNonManagedEntities();
verify(entities).listLatestEntities();
verify(keyEntityToV72KeyItemModelConverter).convertDeleted(same(entity), eq(HTTPS_LOCALHOST_8443));
}

Expand Down Expand Up @@ -749,7 +749,7 @@ void testGetDeletedKeysShouldReturnNextLinkWhenNotOnLastPage(
final ReadOnlyKeyVaultKeyEntity entity = createEntity(VERSIONED_KEY_ENTITY_ID_1_VERSION_1, request);
entity.setDeletedDate(TIME_10_MINUTES_AGO);
entity.setScheduledPurgeDate(TIME_IN_10_MINUTES);
when(entities.listLatestNonManagedEntities())
when(entities.listLatestEntities())
.thenReturn(List.of(entity, entity, entity));
final DeletedKeyVaultKeyItemModel keyItemModel = deletedKeyVaultKeyItemModel(baseUri, Map.of());
when(keyEntityToV72KeyItemModelConverter.convertDeleted(same(entity), eq(HTTPS_LOCALHOST_8443)))
Expand All @@ -774,7 +774,7 @@ void testGetDeletedKeysShouldReturnNextLinkWhenNotOnLastPage(
verify(vaultFake).getRecoverableDays();
verify(keyVaultFake, atLeastOnce()).getDeletedEntities();
verify(keyVaultFake, never()).getEntities();
verify(entities).listLatestNonManagedEntities();
verify(entities).listLatestEntities();
verify(keyEntityToV72KeyItemModelConverter).convertDeleted(same(entity), eq(HTTPS_LOCALHOST_8443));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ void testGetSecretsShouldReturnEntryWhenSecretIsFound(
.thenReturn(recoverableDays);
final CreateSecretRequest request = createRequest(expiry, notBefore);
final ReadOnlyKeyVaultSecretEntity entity = createEntity(VERSIONED_SECRET_ENTITY_ID_1_VERSION_1, request);
when(entities.listLatestNonManagedEntities())
when(entities.listLatestEntities())
.thenReturn(List.of(entity));
final KeyVaultSecretItemModel secretItemModel = keyVaultSecretItemModel(baseUri.asUri(HTTPS_LOCALHOST_8443), Map.of());
when(secretEntityToV72SecretItemModelConverter.convert(same(entity), eq(HTTPS_LOCALHOST_8443)))
Expand All @@ -561,7 +561,7 @@ void testGetSecretsShouldReturnEntryWhenSecretIsFound(
verify(vaultFake).getRecoverableDays();
verify(secretVaultFake, atLeastOnce()).getEntities();
verify(secretVaultFake, never()).getDeletedEntities();
verify(entities).listLatestNonManagedEntities();
verify(entities).listLatestEntities();
verify(secretEntityToV72SecretItemModelConverter).convert(same(entity), eq(HTTPS_LOCALHOST_8443));
}

Expand All @@ -581,7 +581,7 @@ void testGetSecretsShouldReturnNextLinkWhenNotOnLastPage(
.thenReturn(recoverableDays);
final CreateSecretRequest request = createRequest(expiry, notBefore);
final ReadOnlyKeyVaultSecretEntity entity = createEntity(VERSIONED_SECRET_ENTITY_ID_1_VERSION_1, request);
when(entities.listLatestNonManagedEntities())
when(entities.listLatestEntities())
.thenReturn(List.of(entity, entity, entity));
final KeyVaultSecretItemModel secretItemModel = keyVaultSecretItemModel(baseUri.asUri(HTTPS_LOCALHOST_8443), Map.of());
when(secretEntityToV72SecretItemModelConverter.convert(same(entity), eq(HTTPS_LOCALHOST_8443)))
Expand All @@ -606,7 +606,7 @@ void testGetSecretsShouldReturnNextLinkWhenNotOnLastPage(
verify(vaultFake).getRecoverableDays();
verify(secretVaultFake, atLeastOnce()).getEntities();
verify(secretVaultFake, never()).getDeletedEntities();
verify(entities).listLatestNonManagedEntities();
verify(entities).listLatestEntities();
verify(secretEntityToV72SecretItemModelConverter).convert(same(entity), eq(HTTPS_LOCALHOST_8443));
}

Expand All @@ -629,7 +629,7 @@ void testGetDeletedSecretsShouldReturnEntryWhenSecretIsFound(
final ReadOnlyKeyVaultSecretEntity entity = createEntity(VERSIONED_SECRET_ENTITY_ID_1_VERSION_1, request);
entity.setDeletedDate(TIME_10_MINUTES_AGO);
entity.setScheduledPurgeDate(TIME_IN_10_MINUTES);
when(entities.listLatestNonManagedEntities())
when(entities.listLatestEntities())
.thenReturn(List.of(entity));
final DeletedKeyVaultSecretItemModel secretItemModel = deletedKeyVaultSecretItemModel(baseUri, Map.of());
when(secretEntityToV72SecretItemModelConverter.convertDeleted(same(entity), eq(HTTPS_LOCALHOST_8443)))
Expand All @@ -652,7 +652,7 @@ void testGetDeletedSecretsShouldReturnEntryWhenSecretIsFound(
verify(vaultFake).getRecoverableDays();
verify(secretVaultFake, atLeastOnce()).getDeletedEntities();
verify(secretVaultFake, never()).getEntities();
verify(entities).listLatestNonManagedEntities();
verify(entities).listLatestEntities();
verify(secretEntityToV72SecretItemModelConverter).convertDeleted(same(entity), eq(HTTPS_LOCALHOST_8443));
}

Expand All @@ -674,7 +674,7 @@ void testGetDeletedSecretsShouldReturnNextLinkWhenNotOnLastPage(
final ReadOnlyKeyVaultSecretEntity entity = createEntity(VERSIONED_SECRET_ENTITY_ID_1_VERSION_1, request);
entity.setDeletedDate(TIME_10_MINUTES_AGO);
entity.setScheduledPurgeDate(TIME_IN_10_MINUTES);
when(entities.listLatestNonManagedEntities())
when(entities.listLatestEntities())
.thenReturn(List.of(entity, entity, entity));
final DeletedKeyVaultSecretItemModel secretItemModel = deletedKeyVaultSecretItemModel(baseUri, Map.of());
when(secretEntityToV72SecretItemModelConverter.convertDeleted(same(entity), eq(HTTPS_LOCALHOST_8443)))
Expand All @@ -699,7 +699,7 @@ void testGetDeletedSecretsShouldReturnNextLinkWhenNotOnLastPage(
verify(vaultFake).getRecoverableDays();
verify(secretVaultFake, atLeastOnce()).getDeletedEntities();
verify(secretVaultFake, never()).getEntities();
verify(entities).listLatestNonManagedEntities();
verify(entities).listLatestEntities();
verify(secretEntityToV72SecretItemModelConverter).convertDeleted(same(entity), eq(HTTPS_LOCALHOST_8443));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,7 @@ void testGetKeysShouldReturnEntryWhenKeyIsFound(
.thenReturn(recoverableDays);
final CreateKeyRequest request = createRequest(operations, expiry, notBefore);
final ReadOnlyKeyVaultKeyEntity entity = createEntity(VERSIONED_KEY_ENTITY_ID_1_VERSION_1, request);
when(entities.listLatestNonManagedEntities())
when(entities.listLatestEntities())
.thenReturn(List.of(entity));
final KeyVaultKeyItemModel keyItemModel = keyVaultKeyItemModel(baseUri.asUri(HTTPS_LOCALHOST_8443), Map.of());
when(keyEntityToV72KeyItemModelConverter.convert(same(entity), eq(HTTPS_LOCALHOST_8443)))
Expand All @@ -605,7 +605,7 @@ void testGetKeysShouldReturnEntryWhenKeyIsFound(
verify(vaultFake).getRecoverableDays();
verify(keyVaultFake, atLeastOnce()).getEntities();
verify(keyVaultFake, never()).getDeletedEntities();
verify(entities).listLatestNonManagedEntities();
verify(entities).listLatestEntities();
verify(keyEntityToV72KeyItemModelConverter).convert(same(entity), eq(HTTPS_LOCALHOST_8443));
}

Expand All @@ -625,7 +625,7 @@ void testGetKeysShouldReturnNextLinkWhenNotOnLastPage(
.thenReturn(recoverableDays);
final CreateKeyRequest request = createRequest(operations, expiry, notBefore);
final ReadOnlyKeyVaultKeyEntity entity = createEntity(VERSIONED_KEY_ENTITY_ID_1_VERSION_1, request);
when(entities.listLatestNonManagedEntities())
when(entities.listLatestEntities())
.thenReturn(List.of(entity, entity, entity));
final KeyVaultKeyItemModel keyItemModel = keyVaultKeyItemModel(baseUri.asUri(HTTPS_LOCALHOST_8443), Map.of());
when(keyEntityToV72KeyItemModelConverter.convert(same(entity), eq(HTTPS_LOCALHOST_8443)))
Expand All @@ -650,7 +650,7 @@ void testGetKeysShouldReturnNextLinkWhenNotOnLastPage(
verify(vaultFake).getRecoverableDays();
verify(keyVaultFake, atLeastOnce()).getEntities();
verify(keyVaultFake, never()).getDeletedEntities();
verify(entities).listLatestNonManagedEntities();
verify(entities).listLatestEntities();
verify(keyEntityToV72KeyItemModelConverter).convert(same(entity), eq(HTTPS_LOCALHOST_8443));
}

Expand All @@ -672,7 +672,7 @@ void testGetDeletedKeysShouldReturnEntryWhenKeyIsFound(
final ReadOnlyKeyVaultKeyEntity entity = createEntity(VERSIONED_KEY_ENTITY_ID_1_VERSION_1, request);
entity.setDeletedDate(TIME_10_MINUTES_AGO);
entity.setScheduledPurgeDate(TIME_IN_10_MINUTES);
when(entities.listLatestNonManagedEntities())
when(entities.listLatestEntities())
.thenReturn(List.of(entity));
final DeletedKeyVaultKeyItemModel keyItemModel = deletedKeyVaultKeyItemModel(baseUri, Map.of());
when(keyEntityToV72KeyItemModelConverter.convertDeleted(same(entity), eq(HTTPS_LOCALHOST_8443)))
Expand All @@ -695,7 +695,7 @@ void testGetDeletedKeysShouldReturnEntryWhenKeyIsFound(
verify(vaultFake).getRecoverableDays();
verify(keyVaultFake, atLeastOnce()).getDeletedEntities();
verify(keyVaultFake, never()).getEntities();
verify(entities).listLatestNonManagedEntities();
verify(entities).listLatestEntities();
verify(keyEntityToV72KeyItemModelConverter).convertDeleted(same(entity), eq(HTTPS_LOCALHOST_8443));
}

Expand Down Expand Up @@ -760,7 +760,7 @@ void testGetDeletedKeysShouldReturnNextLinkWhenNotOnLastPage(
final ReadOnlyKeyVaultKeyEntity entity = createEntity(VERSIONED_KEY_ENTITY_ID_1_VERSION_1, request);
entity.setDeletedDate(TIME_10_MINUTES_AGO);
entity.setScheduledPurgeDate(TIME_IN_10_MINUTES);
when(entities.listLatestNonManagedEntities())
when(entities.listLatestEntities())
.thenReturn(List.of(entity, entity, entity));
final DeletedKeyVaultKeyItemModel keyItemModel = deletedKeyVaultKeyItemModel(baseUri, Map.of());
when(keyEntityToV72KeyItemModelConverter.convertDeleted(same(entity), eq(HTTPS_LOCALHOST_8443)))
Expand All @@ -785,7 +785,7 @@ void testGetDeletedKeysShouldReturnNextLinkWhenNotOnLastPage(
verify(vaultFake).getRecoverableDays();
verify(keyVaultFake, atLeastOnce()).getDeletedEntities();
verify(keyVaultFake, never()).getEntities();
verify(entities).listLatestNonManagedEntities();
verify(entities).listLatestEntities();
verify(keyEntityToV72KeyItemModelConverter).convertDeleted(same(entity), eq(HTTPS_LOCALHOST_8443));
}

Expand Down
Loading

0 comments on commit 05a4e36

Please sign in to comment.