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

Use NoCredentialsProvider when firestore emulator enabled. #555

Merged
merged 5 commits into from
Aug 9, 2021

Conversation

garywg04
Copy link
Contributor

Fix GH-501

Copy link
Member

@meltsufin meltsufin left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution. It looks pretty good. Just a couple of small comments.

ApplicationContextRunner contextRunner = new ApplicationContextRunner()
.withPropertyValues(
"spring.cloud.gcp.firestore.projectId=test-project",
"spring.cloud.gcp.firestore.emulator.enabled=true",
Copy link
Member

Choose a reason for hiding this comment

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

How about also a test where the property is not set?

Copy link
Member

@meltsufin meltsufin left a comment

Choose a reason for hiding this comment

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

Just one more thing on verifying the credentials provider in the tests.

"spring.cloud.gcp.firestore.host-port=localhost:8080"
).run(context -> {
CredentialsProvider defaultCredentialsProvider = context.getBean(CredentialsProvider.class);
assertThat(defaultCredentialsProvider).isNotInstanceOf(NoCredentialsProvider.class);
Copy link
Member

Choose a reason for hiding this comment

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

I feel like we're missing the assertion on the actual Firestore credentials provider which this PR is all about.
I think you'll need to add a package-private getter for the credentialsProvider in GcpFirestoreAutoConfiguration.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right, added assertion on the new commit to make sure the GcpFirestoreAutoConfiguration did change to NoCredentialsProvider when emulator enabled.

Copy link
Contributor

@elefeint elefeint left a comment

Choose a reason for hiding this comment

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

Looks very good, just a testing request.

(non-actionable) I checked additional-spring-configuration-metadata.json, and we already had spring.cloud.gcp.firestore.emulator.enabled documented there, so no changes will be needed to the metadata.

Comment on lines 79 to 80
CredentialsProvider defaultCredentialsProvider = context.getBean(CredentialsProvider.class);
assertThat(defaultCredentialsProvider).isNotInstanceOf(DefaultCredentialsProvider.class);
Copy link
Contributor

Choose a reason for hiding this comment

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

Two minor testing things:

  1. It would be good to validate that the mocked CredentialsProvider is returned. One way to do that is to use .withBean(() -> /* handle to mock */ ) instead of the current .withUserConfiguration(GcpFirestoreEmulatorAutoConfigurationTests.TestConfiguration.class).
  2. Could you also test firestoreAutoConfiguration.getCredentialsProvider() here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@elefeint thanks for the review! pushed new commit, would you mind have a look and let me know what you think ?

…reAutoConfiguration.getCredentialsProvider() return the mocked bean.
@sonarcloud
Copy link

sonarcloud bot commented Aug 5, 2021

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

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

100.0% 100.0% Coverage
0.0% 0.0% Duplication

Copy link
Contributor

@elefeint elefeint left a comment

Choose a reason for hiding this comment

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

Thank you!

@dzou
Copy link
Contributor

dzou commented Aug 9, 2021

@meltsufin -- Could you take another look again when you get a chance?

@meltsufin meltsufin merged commit ebef98a into GoogleCloudPlatform:main Aug 9, 2021
kateryna216 added a commit to kateryna216/spring-cloud-gcp that referenced this pull request Oct 20, 2022
prash-mi pushed a commit that referenced this pull request Jun 20, 2023
Bumps [spring-test](https://github.com/spring-projects/spring-framework) from 5.3.20 to 5.3.21.
- [Release notes](https://github.com/spring-projects/spring-framework/releases)
- [Commits](spring-projects/spring-framework@v5.3.20...v5.3.21)

---
updated-dependencies:
- dependency-name: org.springframework:spring-test
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use Emulator Credentials when using Firestore Emulator
4 participants