Skip to content

Commit

Permalink
fix: workforce audience (#741)
Browse files Browse the repository at this point in the history
* fix: workforce audience

* fix: format
  • Loading branch information
lsirac committed Sep 21, 2021
1 parent 5f3fed7 commit a08cacc
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 24 deletions.
Expand Up @@ -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();
Expand Down
Expand Up @@ -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());
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
}
Expand Down
Expand Up @@ -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(
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit a08cacc

Please sign in to comment.