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

test(messaging): cloud function sendFCM feature for messaging testing #8143

Merged
merged 4 commits into from
Nov 16, 2024

Conversation

mikehardy
Copy link
Collaborator

Description

I have a large backlog of issues on Notifee, plus a couple issues in react-native-firebase that are related to messaging problems with FCM handling

I can'd diagnose those easily unless I can easily trigger an FCM to a specific device

This PR adds a new cloud function for testing that will take a TokenMessage (basically a regular FCM but with a device token in it) and just reflect that Message right back to the token, with an optional delay

As mentioned in the commit, it will only work if you have the correct google-services files and use the correct package names and even then on iOS it will only work if you have the Xcode developer profile installed for the com.invertase.testing bundle. So I'm not sure how it could be abused, even if you somehow knew some devices "react-native-firebase-testing" project-specific device token

Related issues

Too many to list, but all related to incorrect handling of FCM in various app states on various platforms

Here's one:

Release Summary

All conventional commits, but also none of them will trigger release, they're all build or test

Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
    • Yes
  • My change supports the following platforms;
    • Android
    • iOS
  • My change includes tests;
    • e2e tests added or updated in packages/\*\*/e2e
    • jest tests added or updated in packages/\*\*/__tests__
  • I have updated TypeScript types that are affected by my change.
  • This is a breaking change;
    • Yes
    • No

Test Plan

deploy function cd .github/workflows/scripts/functions && yarn deploy

Execution of function:

 const fcmRequest = await fetch(
      'https://us-central1-react-native-firebase-testing.cloudfunctions.net/sendFCM',
      {
        method: 'POST',
        headers: {
          'Content-Type': 'application/json',
        },
        body: JSON.stringify({
          data: {
            delay: 5000,
            message: {
              // TODO all the mesage stuff here
              token: await firebase.messaging().getToken(),
              notification: {
                title: 'hello world title',
                body: 'hello world body',
              },
            }
          },
        }),
        redirect: 'follow',
      },
    );
    const { result } = await fcmRequest.json();
    console.log('got sendFCM result: ' + JSON.stringify(result, null, 2));
  };

watch react-native console logs

got sendFCM result: {
"messageId": "projects/react-native-firebase-testing/messages/0:1731783390638267%6b3c7cd26b3c7cd2"
}

watch firebase function logs:

https://console.cloud.google.com/logs/query;query=%2528resource.type%3D%22cloud_function%22%20resource.labels.region%3D%22us-central1%22%2529%20OR%20%2528resource.type%3D%22cloud_run_revision%22%20resource.labels.service_name%3D%2528%22sendfcm%22%2529%20resource.labels.location%3D%22us-central1%22%2529;cursorTimestamp=2024-11-16T18:47:18.873543Z;duration=PT1H?authuser=0&project=react-native-firebase-testing&hl=en&inv=1&invt=AbhpwQ

image

Think react-native-firebase is great? Please consider supporting the project with any of the below:

Copy link

vercel bot commented Nov 16, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
react-native-firebase ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 16, 2024 7:30pm

@mikehardy
Copy link
Collaborator Author

There is no way to test functions without actually deploying them, so this is already actually deployed

Given that, I'm going to merge it so that source tree state matches deployed state of the cloud functions but I'll be clear: very happy to make any follow-on PRs related to review on this one if something looks off...

- requires a TokenMessage, and just sends the Message to the device
  addressed by the token in the message
- optionally can have a delay so you can put a test app in background
  or kill it or similar after calling the API

For security purposes:
- Tested this with an incorrect google-services.json / plist and the function
  call simply fails
- Tested this with an incorrect package name and the function all also simply fails
- Tested it with a correct package name and you can send on android, but on iOS there
  is still a lot of Apple developer account / app work to do, so that fails.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant