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

Get FCM Root Url from Environment variable #912

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

yashjain12yj
Copy link

@yashjain12yj yashjain12yj commented Feb 13, 2024

Summary

Added functionality to override FCM root URL via Env Variable so that before constructing the FirebaseApp object we can set the Fcm root url in the environment variable. This will help in changing the base URL to localhost while writing FTs(Functional Tests)/Integration Tests.

Global Variable: GOOGLE_FCM_HOST

Open Issue: #802

How setting the base url to localhost help with your functional tests?
While writing functional tests/Integration tests, we do mock all the external services and create mock servers which behaves the same as external service. So here in case of sending push notifications, we are using Firebase admin SDK and to write tests for this use-case, we would need to mock the FCM server with a mock server created in tests.

For example
image

Here, Suppose we are writing tests for Service 1. It exposes a GET API to get some data. The data contains multiple attributes few attributes from DB, a few from the cache, and a few from Service 2(HTTP API).

While setting up the tests we will create a DB, cache server, and a mock HTTP server. Once the server is up, we want Service 1 to point to these servers instead of actual hosts. Since the DB, cache, and mock HTTP server are running in the same machine on different ports. We would want to set the Host to localhost with respective ports.

Now in the case of Firebase admin SDK, the host is hardcoded in the library. Hence, we are not able to override the Host to localhost.

@yashjain12yj
Copy link
Author

yashjain12yj commented Feb 13, 2024

@kroikie @lahirumaramba Could you please review the PR?

Looks like others are also looking for the same feature. Please take a look on comment in this PR

@ajax-semenov-y
Copy link

@kroikie @lahirumaramba, these changes will increase the testability of applications that use firebase-admin-java. My team is also currently blocked. I will be grateful for accepting this contribution from @yashjain12yj.

Copy link

@aditya-gupta-swiggy aditya-gupta-swiggy 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 raising this PR @yashjain12yj ! this is much needed for our use case as well, grateful for your contribution. can we merge this @kroikie @lahirumaramba ?

@ajax-semenov-y
Copy link

@kroikie @lahirumaramba any updates on this?

@mygreen
Copy link

mygreen commented Apr 20, 2024

Excellent PR !

Furthermore, It would be better if it is possible to change the value of IID_HOST defined in InstanceIdClientImpl.

InstanceIdClientImpl is used when subscribing to a pre-work topic that sends push notifications to the topic.
ex) FirebaseMessaging.getInstance().subscribeToTopic(List.of("token"), "topic", );

@rashineema
Copy link

rashineema commented Jun 6, 2024

This change will significantly improve the testability of the application. By using the admin SDK, we avoid the need to implement the HTTP v1 client and manage FCM-specific errors ourselves.

@kroikie @lahirumaramba, could you please review and merge this? It will be beneficial for everyone.

Thanks @yashjain12yj for the contribution.

@martinboue
Copy link

Thanks for the contribution. Any update on this PR? This is also something we need for testing purposes.

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.

None yet

6 participants