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

chore: Implement gRPC and HttpJson showcase tests for IAM #1789

Merged
merged 30 commits into from
Jul 7, 2023

Conversation

lqiu96
Copy link
Contributor

@lqiu96 lqiu96 commented Jun 20, 2023

Thank you for opening a Pull Request! For general contributing guidelines, please refer to contributing guide

Before submitting your PR, there are a few things you can do to make sure it goes smoothly:

  • Make sure to open an issue as a bug/issue before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea
  • Ensure the tests and linter pass
  • Code coverage does not decrease (if any source code was changed)
  • Appropriate docs were updated (if necessary)

Part of #1439 ☕️

These showcase tests were modeled after gapic-generator-go's IAM showcase tests.

@product-auto-label product-auto-label bot added the size: xl Pull request size is extra large. label Jun 20, 2023
Comment on lines +232 to +236
<dependency>
<groupId>com.google.api.grpc</groupId>
<artifactId>grpc-google-iam-v1</artifactId>
<scope>test</scope>
</dependency>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added since there are compilation issues for MockIAMPolicy and MockIAMPolicyImpl

@lqiu96 lqiu96 mentioned this pull request Jun 20, 2023
27 tasks
@lqiu96
Copy link
Contributor Author

lqiu96 commented Jun 22, 2023

HttpJson's getIamPolicy test is failing. Issue is tracked: googleapis/gapic-showcase#1338 which should resolve this issue.

@lqiu96 lqiu96 marked this pull request as ready for review July 5, 2023 21:47
@lqiu96 lqiu96 requested a review from a team as a code owner July 5, 2023 21:47
@lqiu96 lqiu96 added the owlbot:run Add this label to trigger the Owlbot post processor. label Jul 5, 2023
@snippet-bot
Copy link

snippet-bot bot commented Jul 5, 2023

Here is the summary of changes.

You are about to add 36 region tags.

This comment is generated by snippet-bot.
If you find problems with this result, please file an issue at:
https://github.com/googleapis/repo-automation-bots/issues.
To update this comment, add snippet-bot:force-run label or use the checkbox below:

  • Refresh this comment

@gcf-owl-bot gcf-owl-bot bot removed the owlbot:run Add this label to trigger the Owlbot post processor. label Jul 5, 2023
@@ -19,7 +19,8 @@ proto_library_with_info(
"@com_google_gapic_showcase//schema/google/showcase/v1beta1:showcase_proto",
# "//showcase/gapic-showcase-extended/proto:showcase_proto_extended",
"@com_google_googleapis//google/cloud:common_resources_proto",
"@com_google_googleapis//google/cloud/location:location_proto"
"@com_google_googleapis//google/cloud/location:location_proto",
"@com_google_googleapis//google/iam/v1:iam_policy_proto"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So adding this iam_policy_proto implicitly enables IAM feature? Is this how we are suppose to enable IAM?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe having this in the bazel rule enables it: https://github.com/googleapis/gapic-showcase/blob/b146f892d98ea0d733c45a2315941e8e6ab69c90/schema/google/showcase/v1beta1/showcase_v1beta1.yaml#L29

But this was to generate the Java related Mixin code.

showcase/pom.xml Show resolved Hide resolved

@Before
public void setupTests() {
resourceName = "users/" + UUID.randomUUID().toString().substring(0, 8);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the resource name is in this format? I see that it is a wild card resource based on the definition in googleapis, I guess it is randomly chosen?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was using the IdentityClient to call the IAM RPCs which uses the User resource. I just gave it user/{random_user_id}.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Discussed offline that this could be any format.

public void testGrpc_setIamPolicy_missingResource() {
SetIamPolicyRequest setIamPolicyRequest = SetIamPolicyRequest.newBuilder().build();
assertThrows(
InvalidArgumentException.class, () -> grpcClient.setIamPolicy(setIamPolicyRequest));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is this exception being thrown? Is it in our client libraries? I see that we are adding a lot of error scenarios in this IT, a general comment is that we only want to test the exception if it's being thrown in the IAM code before it reaches backend, or if there is any specific response exception mapping logic in IAM code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is being thrown in the backend: https://github.com/googleapis/gapic-showcase/blob/b146f892d98ea0d733c45a2315941e8e6ab69c90/server/services/iam_policy_service.go#L27-L29

There is only a few validation checks that the backend iam server does.

@sonarcloud
Copy link

sonarcloud bot commented Jul 7, 2023

[gapic-generator-java-root] SonarCloud Quality Gate failed.    Quality Gate failed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 12 Code Smells

39.6% 39.6% Coverage
49.3% 49.3% Duplication

idea Catch issues before they fail your Quality Gate with our IDE extension sonarlint SonarLint

@sonarcloud
Copy link

sonarcloud bot commented Jul 7, 2023

[java_showcase_integration_tests] SonarCloud Quality Gate failed.    Quality Gate failed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

34.6% 34.6% Coverage
49.3% 49.3% Duplication

idea Catch issues before they fail your Quality Gate with our IDE extension sonarlint SonarLint

@sonarcloud
Copy link

sonarcloud bot commented Jul 7, 2023

[java_showcase_unit_tests] SonarCloud Quality Gate failed.    Quality Gate failed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

39.6% 39.6% Coverage
49.3% 49.3% Duplication

idea Catch issues before they fail your Quality Gate with our IDE extension sonarlint SonarLint

@lqiu96 lqiu96 merged commit b1d3fe0 into main Jul 7, 2023
@lqiu96 lqiu96 deleted the main-showcase_iam_tests branch July 7, 2023 20:55
lqiu96 added a commit that referenced this pull request Jul 12, 2023
* chore: Add framework for iam showcase tests

* chore: Generate clients with IAM stubs

* chore: Add IAM showcase tests

* chore: Add samples

* chore: Exclude httpjson tests

* chore: Use @before to create the resource

* chore: Use constant for policy

* chore: Log resource name

* chore: Test use setPolicyRequest's resourceName

* chore: run mvn clean before showcase tests

* chore: Attempt again with cache deleted

* chore: Add logging for test

* chore: Sleep for 1s

* chore: Use resource from setPolicyRequest

* chore: Ignore failing HttpJson test for now

* chore: Un-ignore test

* chore: Fix lint issues

* chore: Test with rooms/ prefix

* chore: Use Identity client for Users

* chore: Create user resource to assign policy to

* chore: Use user's name as resource id

* chore: Change resource name before each test

* chore: Add iam-grpc in pom

* chore: Resolve sonar issues

* chore: Add comment for testIamPolicy

* chore: Address PR comments
lqiu96 added a commit that referenced this pull request Jul 17, 2023
* fix: Use bindings for resolving multi pattern resources

* chore: Fix lint issues

* chore: Add unit tests for the behavior

* chore: Add comments for the tests

* chore: Remove unused comment

* feat: support GDC-H Credentials  (#1642)

* chore: initial additions to handle GDC-H API audience

* chore: add unit tests for GDC-H

* chore: cleanup of logic

* chore: decompose tests into separate methods

* chore: fix clirr diff check

* chore: fmt:format

* chore: add support in `ClientSettings`

* chore: add showcase IT for GDCH credentials

* chore: comments

* chore: improve tests

* chore: add partial IT for testing context credential

* chore: recreate GdchCredentials with audience using convenience method

* chore: more readable api audience logic

* chore: no wildcard imports

* chore: javadoc for public methods

* chore: gdch test to use default null initialization

* chore: tear down for gdch IT

* chore: `assertThrows` for gdch ITs

* chore: mvn fmt:format

* test: remove context test

* docs: explain that audience will be overriden if set through client/stub settings

* test: test audience setting should modify initial credentials

* chore: clirr check

* chore: ignore gdch changes

* chore: format

* chore: default to endpoint if audience not provided

* test: refresh gdch creds to confirm audience works

* chore: fmt

* chore: fmt

* chore: better test names in ClientContextTest

* chore: better test names for showcase tests

* chore: simplify refresh verification logic

* chore: include outcome in gdch it test names

* chore: expand comments in GDCH ITs

* test: intercept mock transport to verify audience

* chore: fmt

* chore: move auth test-jar to shared dependencies

* chore: cleanup

* chore: use inferred version for auth library

* deps: update google-auth-java-library to 1.19.0

* choreL fmt ITGdch.java

* chore: import auth test-jar using common version variable

* chore: remove auth test-jar import from first-party-dependencies

* chore: add license headers to new files

* chore: revert google-auth-version to be obtained from main branch

* chore: correct showcase parent pom indentation

* chore: remove resource declaration for native test build

* fix: [gapic-generator-java] handle response and metadata type ambiguity in LRO parsing (#1726)

* chore: Bump grpc-java version to 1.55.3 (#1829)

* chore: Bump gapic-showcase version to 0.28.2 (#1830)

* build(deps): Bump guava version to 32.1.1-jre (#1832)

* chore: Bump guava version to 32.1.1-jre

* chore: Add guava to gradle template

* chore: Add j2obc-annotations to shared-dependencies (#1834)

* ci: fix showcase-clirr check on release PRs (#1835)

Install sdk-platform-java before performing final clirr check, so version changes are available in the local repository

* chore(main): release 2.23.0 (#1806)

Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com>

* chore(main): release 2.23.1-SNAPSHOT (#1836)

Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com>

* chore: Implement gRPC and HttpJson showcase tests for IAM (#1789)

* chore: Add framework for iam showcase tests

* chore: Generate clients with IAM stubs

* chore: Add IAM showcase tests

* chore: Add samples

* chore: Exclude httpjson tests

* chore: Use @before to create the resource

* chore: Use constant for policy

* chore: Log resource name

* chore: Test use setPolicyRequest's resourceName

* chore: run mvn clean before showcase tests

* chore: Attempt again with cache deleted

* chore: Add logging for test

* chore: Sleep for 1s

* chore: Use resource from setPolicyRequest

* chore: Ignore failing HttpJson test for now

* chore: Un-ignore test

* chore: Fix lint issues

* chore: Test with rooms/ prefix

* chore: Use Identity client for Users

* chore: Create user resource to assign policy to

* chore: Use user's name as resource id

* chore: Change resource name before each test

* chore: Add iam-grpc in pom

* chore: Resolve sonar issues

* chore: Add comment for testIamPolicy

* chore: Address PR comments

* ci: showcase native check (#1833)

* ci: showcase native check

* fix: add explicit java version

* fix: adjust syntax

* fix: add resource-config entry for ITGdch

* fix: copy file to temp folder so it can be accessed by path

* chore: formatting

* fix: prevent shutdown warnings with client.awaitTermination

* ci: fix build file location for downstream test

* chore: use static imports for Truth assertions

* chore: Resolve merge conflicts

* chore: Use bindings for any matching resource patterns

* chore: Fix lint issues

* chore: Remove unused code

* chore: Fix lint issues

* chore: Add test for resourceName matching bindings

* chore: Fix lint issues

---------

Co-authored-by: Diego Alonso Marquez Palacios <diegomarquezp@google.com>
Co-authored-by: Emily Wang <emmwang@google.com>
Co-authored-by: Burke Davison <40617934+burkedavison@users.noreply.github.com>
Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size: xl Pull request size is extra large.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants