Skip to content

Commit

Permalink
fix: throw exception if SAS token secret is null (#256)
Browse files Browse the repository at this point in the history
* fix: throw exception if SAS token secret is null

* checkstyle
  • Loading branch information
paullatzelsperger authored Sep 9, 2024
1 parent 805e639 commit a9d7bd3
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ public DataSink createSink(DataFlowStartMessage request) {
var requestId = request.getId();

var secret = vault.resolveSecret(dataAddress.getKeyName());

if (secret == null) {
throw new EdcException("SAS token for the Azure Blob DataSink not found in Vault (alias = '%s')".formatted(dataAddress.getKeyName()));
}

var token = typeManager.readValue(secret, AzureSasToken.class);
var folderName = dataAddress.getStringProperty(AzureBlobStoreSchema.FOLDER_NAME);
var blobName = dataAddress.getStringProperty(AzureBlobStoreSchema.BLOB_NAME);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@
import java.util.concurrent.Executors;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.eclipse.edc.azure.blob.testfixtures.AzureStorageTestFixtures.createAccountName;
import static org.eclipse.edc.azure.blob.testfixtures.AzureStorageTestFixtures.createBlobName;
import static org.eclipse.edc.azure.blob.testfixtures.AzureStorageTestFixtures.createBlobPrefix;
import static org.eclipse.edc.azure.blob.testfixtures.AzureStorageTestFixtures.createContainerName;
import static org.eclipse.edc.azure.blob.testfixtures.AzureStorageTestFixtures.createRequest;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

Expand All @@ -54,7 +54,8 @@ class AzureStorageDataSinkFactoryTest {

private final String accountName = createAccountName();
private final String containerName = createContainerName();
private final String blobName = createBlobName();


private final String blobPrefix = createBlobPrefix();
private final String keyName = "test-keyname";
private final AzureSasToken token = new AzureSasToken("test-writeonly-sas", new Random().nextLong());
Expand Down Expand Up @@ -135,6 +136,21 @@ void createSink_whenValidRequest_succeeds() {

@Test
void createSink_whenInvalidRequest_fails() {
assertThrows(EdcException.class, () -> factory.createSink(invalidRequest.build()));
assertThatThrownBy(() -> factory.createSink(invalidRequest.build()))
.isInstanceOf(EdcException.class)
.hasMessageContaining("AzureStorage destination address is invalid: Invalid account name, the name may not be null, empty or blank");
}

@Test
void createSink_whenSecretNotFoundRequest_fails() {
when(vault.resolveSecret(anyString())).thenReturn(null);
var validRequest = request.destinationDataAddress(dataAddress
.property(AzureBlobStoreSchema.ACCOUNT_NAME, accountName)
.property(AzureBlobStoreSchema.CONTAINER_NAME, containerName)
.keyName(keyName)
.build());
assertThatThrownBy(() -> factory.createSink(validRequest.build()))
.isInstanceOf(EdcException.class)
.hasMessageStartingWith("SAS token for the Azure Blob DataSink not found in Vault");
}
}

0 comments on commit a9d7bd3

Please sign in to comment.