Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import com.google.cloud.storage.StorageException;
import com.google.cloud.storage.StorageOptions;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.Date;
import java.util.HashSet;
Expand Down Expand Up @@ -177,6 +178,12 @@ private AccessConfig subscopedCredsForOperations(
Optional.of(REFRESH_ENDPOINT));
}

private JsonNode readResource(ObjectMapper mapper, String name) throws IOException {
try (InputStream in = GcpCredentialsStorageIntegrationTest.class.getResourceAsStream(name)) {
return mapper.readTree(in);
}
}

@Test
public void testGenerateAccessBoundary() throws IOException {
CredentialAccessBoundary credentialAccessBoundary =
Expand All @@ -185,10 +192,7 @@ public void testGenerateAccessBoundary() throws IOException {
assertThat(credentialAccessBoundary).isNotNull();
ObjectMapper mapper = new ObjectMapper();
JsonNode parsedRules = mapper.convertValue(credentialAccessBoundary, JsonNode.class);
JsonNode refRules =
mapper.readTree(
GcpCredentialsStorageIntegrationTest.class.getResource(
"gcp-testGenerateAccessBoundary.json"));
JsonNode refRules = readResource(mapper, "gcp-testGenerateAccessBoundary.json");
assertThat(parsedRules)
.usingRecursiveComparison(
RecursiveComparisonConfiguration.builder()
Expand All @@ -211,9 +215,7 @@ public void testGenerateAccessBoundaryWithMultipleBuckets() throws IOException {
ObjectMapper mapper = new ObjectMapper();
JsonNode parsedRules = mapper.convertValue(credentialAccessBoundary, JsonNode.class);
JsonNode refRules =
mapper.readTree(
GcpCredentialsStorageIntegrationTest.class.getResource(
"gcp-testGenerateAccessBoundaryWithMultipleBuckets.json"));
readResource(mapper, "gcp-testGenerateAccessBoundaryWithMultipleBuckets.json");
assertThat(parsedRules)
.usingRecursiveComparison(
RecursiveComparisonConfiguration.builder()
Expand All @@ -232,10 +234,7 @@ public void testGenerateAccessBoundaryWithoutList() throws IOException {
assertThat(credentialAccessBoundary).isNotNull();
ObjectMapper mapper = new ObjectMapper();
JsonNode parsedRules = mapper.convertValue(credentialAccessBoundary, JsonNode.class);
JsonNode refRules =
mapper.readTree(
GcpCredentialsStorageIntegrationTest.class.getResource(
"gcp-testGenerateAccessBoundaryWithoutList.json"));
JsonNode refRules = readResource(mapper, "gcp-testGenerateAccessBoundaryWithoutList.json");
assertThat(parsedRules)
.usingRecursiveComparison(
RecursiveComparisonConfiguration.builder()
Expand All @@ -254,10 +253,7 @@ public void testGenerateAccessBoundaryWithoutWrites() throws IOException {
assertThat(credentialAccessBoundary).isNotNull();
ObjectMapper mapper = new ObjectMapper();
JsonNode parsedRules = mapper.convertValue(credentialAccessBoundary, JsonNode.class);
JsonNode refRules =
mapper.readTree(
GcpCredentialsStorageIntegrationTest.class.getResource(
"gcp-testGenerateAccessBoundaryWithoutWrites.json"));
JsonNode refRules = readResource(mapper, "gcp-testGenerateAccessBoundaryWithoutWrites.json");
assertThat(parsedRules)
.usingRecursiveComparison(
RecursiveComparisonConfiguration.builder()
Expand Down