Skip to content
Permalink
Browse files
fix: workforce audience (#741)
* fix: workforce audience

* fix: format
  • Loading branch information
lsirac committed Sep 21, 2021
1 parent 5f3fed7 commit a08cacc7990b9058c8f1af3f9d8d816119562cc4
@@ -282,8 +282,7 @@ private String getSubjectTokenFromMetadataServer() throws IOException {
*/
public boolean isWorkforcePoolConfiguration() {
Pattern workforceAudiencePattern =
Pattern.compile(
"^//iam.googleapis.com/projects/.+/locations/.+/workforcePools/.+/providers/.+$");
Pattern.compile("^//iam.googleapis.com/locations/.+/workforcePools/.+/providers/.+$");
return workforcePoolUserProject != null
&& !workforcePoolUserProject.isEmpty()
&& workforceAudiencePattern.matcher(getAudience()).matches();
@@ -175,7 +175,7 @@ public void fromJson_identityPoolCredentialsWorkforce() {

assertTrue(credential instanceof IdentityPoolCredentials);
assertEquals(
"//iam.googleapis.com/projects/123/locations/global/workforcePools/pool/providers/provider",
"//iam.googleapis.com/locations/global/workforcePools/pool/providers/provider",
credential.getAudience());
assertEquals("subjectTokenType", credential.getSubjectTokenType());
assertEquals(STS_URL, credential.getTokenUrl());
@@ -236,17 +236,17 @@ public void fromJson_nullTransport_throws() {
}

@Test
public void fromJson_invalidWorkloadAudiences_throws() {
public void fromJson_invalidWorkforceAudiences_throws() {
List<String> invalidAudiences =
Arrays.asList(
"//iam.googleapis.com/projects/x23/locations/global/workloadIdentityPools/pool/providers/provider",
"//iam.googleapis.com/projects/y16/locations/global/workforcepools/pool/providers/provider",
"//iam.googleapis.com/projects/z6/locations/global/workforcePools/providers/provider",
"//iam.googleapis.com/projects/aa4/locations/global/workforcePools/providers",
"//iam.googleapis.com/projects/b5/locations/global/workforcePools/",
"//iam.googleapis.com/projects/6c/locations//workforcePools/providers",
"//iam.googleapis.com/projects/df7/notlocations/global/workforcePools/providers",
"//iam.googleapis.com/projects/e6/locations/global/workforce/providers");
"//iam.googleapis.com/locations/global/workloadIdentityPools/pool/providers/provider",
"//iam.googleapis.com/locations/global/workforcepools/pool/providers/provider",
"//iam.googleapis.com/locations/global/workforcePools/providers/provider",
"//iam.googleapis.com/locations/global/workforcePools/providers",
"//iam.googleapis.com/locations/global/workforcePools/",
"//iam.googleapis.com/locations//workforcePools/providers",
"//iam.googleapis.com/notlocations/global/workforcePools/providers",
"//iam.googleapis.com/locations/global/workforce/providers");

for (String audience : invalidAudiences) {
try {
@@ -543,8 +543,7 @@ private GenericJson buildJsonIdentityPoolCredential() {
private GenericJson buildJsonIdentityPoolWorkforceCredential() {
GenericJson json = buildJsonIdentityPoolCredential();
json.put(
"audience",
"//iam.googleapis.com/projects/123/locations/global/workforcePools/pool/providers/provider");
"audience", "//iam.googleapis.com/locations/global/workforcePools/pool/providers/provider");
json.put("workforce_pool_user_project", "userProject");
return json;
}
@@ -338,7 +338,7 @@ public void refreshAccessToken_internalOptionsSet() throws IOException {
IdentityPoolCredentials.newBuilder(FILE_SOURCED_CREDENTIAL)
.setWorkforcePoolUserProject("userProject")
.setAudience(
"//iam.googleapis.com/projects/123/locations/global/workforcePools/pool/providers/provider")
"//iam.googleapis.com/locations/global/workforcePools/pool/providers/provider")
.setTokenUrl(transportFactory.transport.getStsUrl())
.setHttpTransportFactory(transportFactory)
.setCredentialSource(
@@ -490,13 +490,13 @@ public void builder_invalidWorkforceAudiences_throws() {
Arrays.asList(
"",
"//iam.googleapis.com/projects/x23/locations/global/workloadIdentityPools/pool/providers/provider",
"//iam.googleapis.com/projects/y16/locations/global/workforcepools/pool/providers/provider",
"//iam.googleapis.com/projects/z6/locations/global/workforcePools/providers/provider",
"//iam.googleapis.com/projects/aa4/locations/global/workforcePools/providers",
"//iam.googleapis.com/projects/b5/locations/global/workforcePools/",
"//iam.googleapis.com/projects/6c/locations//workforcePools/providers",
"//iam.googleapis.com/projects/df7/notlocations/global/workforcePools/providers",
"//iam.googleapis.com/projects/e6/locations/global/workforce/providers");
"//iam.googleapis.com/locations/global/workforcepools/pool/providers/provider",
"//iam.googleapis.com/locations/global/workforcePools/providers/provider",
"//iam.googleapis.com/locations/global/workforcePools/providers",
"//iam.googleapis.com/locations/global/workforcePools/",
"//iam.googleapis.com/locations//workforcePools/providers",
"//iam.googleapis.com/notlocations/global/workforcePools/providers",
"//iam.googleapis.com/locations/global/workforce/providers");

for (String audience : invalidAudiences) {
try {
@@ -525,8 +525,7 @@ public void builder_emptyWorkforceUserProjectWithWorkforceAudience_throws() {
IdentityPoolCredentials.newBuilder()
.setWorkforcePoolUserProject("")
.setHttpTransportFactory(OAuth2Utils.HTTP_TRANSPORT_FACTORY)
.setAudience(
"//iam.googleapis.com/projects/123/locations/global/workforcePools/providers/provider")
.setAudience("//iam.googleapis.com/locations/global/workforcePools/providers/provider")
.setSubjectTokenType("subjectTokenType")
.setTokenUrl(STS_URL)
.setTokenInfoUrl("tokenInfoUrl")

0 comments on commit a08cacc

Please sign in to comment.