-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement GrpcStorageImpl#*HmacKey
* GrpcStorageImpl#createHmacKey * GrpcStorageImpl#getHmacKey * GrpcStorageImpl#updateHmacKey * GrpcStorageImpl#deleteHmacKey Add tests for each Hmac method to ITGrpcTest
- Loading branch information
1 parent
317d3ec
commit 4d94420
Showing
6 changed files
with
156 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,12 +24,19 @@ | |
import com.google.cloud.storage.Bucket; | ||
import com.google.cloud.storage.BucketFixture; | ||
import com.google.cloud.storage.BucketInfo; | ||
import com.google.cloud.storage.HmacKey; | ||
import com.google.cloud.storage.HmacKey.HmacKeyMetadata; | ||
import com.google.cloud.storage.HmacKey.HmacKeyState; | ||
import com.google.cloud.storage.ServiceAccount; | ||
import com.google.cloud.storage.Storage.CreateHmacKeyOption; | ||
import com.google.cloud.storage.Storage.ListHmacKeysOption; | ||
import com.google.cloud.storage.StorageFixture; | ||
import com.google.cloud.storage.StorageOptions; | ||
import com.google.cloud.storage.conformance.retry.CleanupStrategy; | ||
import com.google.cloud.storage.conformance.retry.TestBench; | ||
import com.google.cloud.storage.testing.RemoteStorageHelper; | ||
import com.google.common.collect.ImmutableList; | ||
import java.util.stream.IntStream; | ||
import java.util.stream.StreamSupport; | ||
import org.junit.ClassRule; | ||
import org.junit.Test; | ||
|
@@ -86,4 +93,67 @@ public void listBuckets() { | |
|
||
assertThat(bucketNames).contains(bucketFixture.getBucketInfo().getName()); | ||
} | ||
|
||
@Test | ||
public void createHmacKey() { | ||
ServiceAccount serviceAccount = ServiceAccount.of("[email protected]"); | ||
HmacKey hmacKey = storageFixture.getInstance().createHmacKey(serviceAccount); | ||
assertThat(hmacKey).isNotNull(); | ||
assertThat(hmacKey.getSecretKey()).isNotNull(); | ||
assertThat(hmacKey.getMetadata().getServiceAccount()).isEqualTo(serviceAccount); | ||
} | ||
|
||
@Test | ||
public void getHmacKey() { | ||
ServiceAccount serviceAccount = ServiceAccount.of("[email protected]"); | ||
HmacKey hmacKey = storageFixture.getInstance().createHmacKey(serviceAccount); | ||
HmacKeyMetadata actual = | ||
storageFixture.getInstance().getHmacKey(hmacKey.getMetadata().getAccessId()); | ||
assertThat(actual).isEqualTo(hmacKey.getMetadata()); | ||
} | ||
|
||
@Test | ||
public void listHmacKeys() { | ||
ImmutableList<HmacKey> keys = | ||
IntStream.rangeClosed(1, 4) | ||
.mapToObj(i -> ServiceAccount.of(String.format("x-%[email protected]", i))) | ||
.map( | ||
sa -> | ||
storageFixture | ||
.getInstance() | ||
.createHmacKey(sa, CreateHmacKeyOption.projectId("proj"))) | ||
.collect(ImmutableList.toImmutableList()); | ||
|
||
ImmutableList<HmacKeyMetadata> expected = | ||
keys.stream().map(HmacKey::getMetadata).collect(ImmutableList.toImmutableList()); | ||
|
||
Page<HmacKeyMetadata> page = | ||
storageFixture.getInstance().listHmacKeys(ListHmacKeysOption.projectId("proj")); | ||
|
||
ImmutableList<HmacKeyMetadata> actual = | ||
StreamSupport.stream(page.iterateAll().spliterator(), false) | ||
.collect(ImmutableList.toImmutableList()); | ||
|
||
assertThat(actual).isEqualTo(expected); | ||
} | ||
|
||
@Test | ||
public void updateHmacKey() { | ||
ServiceAccount serviceAccount = ServiceAccount.of("[email protected]"); | ||
HmacKey hmacKey = storageFixture.getInstance().createHmacKey(serviceAccount); | ||
HmacKeyMetadata updated = | ||
storageFixture | ||
.getInstance() | ||
.updateHmacKeyState(hmacKey.getMetadata(), HmacKeyState.INACTIVE); | ||
assertThat(updated.getServiceAccount()).isEqualTo(serviceAccount); | ||
assertThat(updated.getState()).isEqualTo(HmacKeyState.INACTIVE); | ||
} | ||
|
||
@Test | ||
public void deleteHmacKey() { | ||
ServiceAccount serviceAccount = ServiceAccount.of("[email protected]"); | ||
HmacKey hmacKey = storageFixture.getInstance().createHmacKey(serviceAccount); | ||
storageFixture.getInstance().updateHmacKeyState(hmacKey.getMetadata(), HmacKeyState.INACTIVE); | ||
storageFixture.getInstance().deleteHmacKey(hmacKey.getMetadata()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters