Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: workforce audience #741

Merged
merged 2 commits into from Sep 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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