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(app-check): fix activate parameters and return, and app-check import advice #6056

Merged
merged 5 commits into from
Feb 7, 2022
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions packages/app-check/e2e/appcheck.e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,29 @@ describe('appCheck()', function () {
});
});
describe('activate())', function () {
it('should activate with default provider and default token refresh', async function () {
it('should activate with default provider and defined token refresh', function () {
firebase
.appCheck()
.activate('ignored', false)
.then(value => expect(value).toBe(undefined))
.catch(e => new Error('app-check activate failed? ' + e));
});

it('should error if activate gets no parameters', async function () {
try {
firebase.appCheck().activate();
return Promise.reject(new Error('should have thrown an error'));
} catch (e) {
e.message.should.containEql('siteKeyOrProvider must be a string value');
}
});

it('should not error if activate called with no token refresh value', async function () {
try {
await firebase.appCheck().activate('ignored', false);
firebase.appCheck().activate('ignored');
return Promise.resolve(true);
} catch (e) {
return Promise.reject(e);
return Promise.reject(new Error('should not have thrown an error - ' + e));
}
});
});
Expand Down
5 changes: 4 additions & 1 deletion packages/app-check/ios/RNFBAppCheck/RNFBAppCheckModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ - (dispatch_queue_t)methodQueue {
RCT_EXPORT_METHOD(activate
: (FIRApp *)firebaseApp
: (nonnull NSString *)siteKeyOrProvider
: (BOOL)isTokenAutoRefreshEnabled) {
: (BOOL)isTokenAutoRefreshEnabled
: (RCTPromiseResolveBlock)resolve rejecter
: (RCTPromiseRejectBlock)reject) {
// From SDK docs:
// NOTE: Make sure to call this method before FirebaseApp.configure().
// If this method is called after configuring Firebase, the changes will not take effect.
Expand All @@ -49,6 +51,7 @@ - (dispatch_queue_t)methodQueue {

FIRAppCheck *appCheck = [FIRAppCheck appCheckWithApp:firebaseApp];
appCheck.isTokenAutoRefreshEnabled = isTokenAutoRefreshEnabled;
resolve([NSNull null]);
}

RCT_EXPORT_METHOD(setTokenAutoRefreshEnabled
Expand Down
21 changes: 20 additions & 1 deletion packages/app-check/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*
*/

import { isIOS } from '@react-native-firebase/app/lib/common';
import { isBoolean, isIOS, isString } from '@react-native-firebase/app/lib/common';
import {
createModuleNamespace,
FirebaseModule,
Expand All @@ -32,6 +32,25 @@ const nativeModuleName = 'RNFBAppCheckModule';

class FirebaseAppCheckModule extends FirebaseModule {
activate(siteKeyOrProvider, isTokenAutoRefreshEnabled) {
if (!isString(siteKeyOrProvider)) {
throw new Error('siteKeyOrProvider must be a string value to match firebase-js-sdk API');
}

// If the caller did not specify token refresh, attempt to use app-check specific setting:
if (!isBoolean(isTokenAutoRefreshEnabled)) {
isTokenAutoRefreshEnabled = this.firebaseJson.app_check_token_auto_refresh;
}

// If that was not defined, attempt to use app-wide data collection setting per docs:
if (!isBoolean(isTokenAutoRefreshEnabled)) {
isTokenAutoRefreshEnabled = this.firebaseJson.app_data_collection_default_enabled;
}

// If that also was not defined, the default is documented as true.
if (!isBoolean(isTokenAutoRefreshEnabled)) {
isTokenAutoRefreshEnabled = true;
}

return this.native.activate(siteKeyOrProvider, isTokenAutoRefreshEnabled);
}

Expand Down
14 changes: 12 additions & 2 deletions packages/app/lib/internal/registry/namespace.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,11 +194,16 @@ function firebaseRootModuleProxy(firebaseNamespace, moduleNamespace) {
return getOrCreateModuleForRoot(moduleNamespace);
}

moduleWithDashes = moduleNamespace
.split(/(?=[A-Z])/)
.join('-')
.toLowerCase();

throw new Error(
[
`You attempted to use 'firebase.${moduleNamespace}' but this module could not be found.`,
'',
`Ensure you have installed and imported the '@react-native-firebase/${moduleNamespace}' package.`,
`Ensure you have installed and imported the '@react-native-firebase/${moduleWithDashes}' package.`,
].join('\r\n'),
);
}
Expand All @@ -215,11 +220,16 @@ export function firebaseAppModuleProxy(app, moduleNamespace) {
return getOrCreateModuleForApp(app, moduleNamespace);
}

moduleWithDashes = moduleNamespace
.split(/(?=[A-Z])/)
.join('-')
.toLowerCase();

throw new Error(
[
`You attempted to use "firebase.app('${app.name}').${moduleNamespace}" but this module could not be found.`,
'',
`Ensure you have installed and imported the '@react-native-firebase/${moduleNamespace}' package.`,
`Ensure you have installed and imported the '@react-native-firebase/${moduleWithDashes}' package.`,
].join('\r\n'),
);
}
Expand Down
68 changes: 34 additions & 34 deletions tests/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -856,70 +856,70 @@ PODS:
- React-jsi (= 0.67.1)
- React-logger (= 0.67.1)
- React-perflogger (= 0.67.1)
- RNFBAnalytics (14.2.3):
- RNFBAnalytics (14.3.0):
- Firebase/Analytics (= 8.11.0)
- React-Core
- RNFBApp
- RNFBApp (14.2.3):
- RNFBApp (14.3.0):
- Firebase/CoreOnly (= 8.11.0)
- React-Core
- RNFBAppCheck (14.2.3):
- RNFBAppCheck (14.3.0):
- Firebase/AppCheck (= 8.11.0)
- React-Core
- RNFBApp
- RNFBAppDistribution (14.2.3):
- RNFBAppDistribution (14.3.0):
- Firebase/AppDistribution (= 8.11.0)
- React-Core
- RNFBApp
- RNFBAuth (14.2.3):
- RNFBAuth (14.3.0):
- Firebase/Auth (= 8.11.0)
- React-Core
- RNFBApp
- RNFBCrashlytics (14.2.3):
- RNFBCrashlytics (14.3.0):
- Firebase/Crashlytics (= 8.11.0)
- React-Core
- RNFBApp
- RNFBDatabase (14.2.3):
- RNFBDatabase (14.3.0):
- Firebase/Database (= 8.11.0)
- React-Core
- RNFBApp
- RNFBDynamicLinks (14.2.3):
- RNFBDynamicLinks (14.3.0):
- Firebase/DynamicLinks (= 8.11.0)
- GoogleUtilities/AppDelegateSwizzler
- React-Core
- RNFBApp
- RNFBFirestore (14.2.3):
- RNFBFirestore (14.3.0):
- Firebase/Firestore (= 8.11.0)
- React-Core
- RNFBApp
- RNFBFunctions (14.2.3):
- RNFBFunctions (14.3.0):
- Firebase/Functions (= 8.11.0)
- React-Core
- RNFBApp
- RNFBInAppMessaging (14.2.3):
- RNFBInAppMessaging (14.3.0):
- Firebase/InAppMessaging (= 8.11.0)
- React-Core
- RNFBApp
- RNFBInstallations (14.2.3):
- RNFBInstallations (14.3.0):
- Firebase/Installations (= 8.11.0)
- React-Core
- RNFBApp
- RNFBMessaging (14.2.3):
- RNFBMessaging (14.3.0):
- Firebase/Messaging (= 8.11.0)
- React-Core
- RNFBApp
- RNFBML (14.2.3):
- RNFBML (14.3.0):
- React-Core
- RNFBApp
- RNFBPerf (14.2.3):
- RNFBPerf (14.3.0):
- Firebase/Performance (= 8.11.0)
- React-Core
- RNFBApp
- RNFBRemoteConfig (14.2.3):
- RNFBRemoteConfig (14.3.0):
- Firebase/RemoteConfig (= 8.11.0)
- React-Core
- RNFBApp
- RNFBStorage (14.2.3):
- RNFBStorage (14.3.0):
- Firebase/Storage (= 8.11.0)
- React-Core
- RNFBApp
Expand Down Expand Up @@ -1171,23 +1171,23 @@ SPEC CHECKSUMS:
React-RCTVibration: 19c012d1202df46bafbe49268a346f6b3edadfdd
React-runtimeexecutor: 2c92a8bddd1a3e72c7513d1e74235c2d9c84875c
ReactCommon: 2e816fad39f65f2a94a5999d5be463a6b620dcf6
RNFBAnalytics: 2dbe78d2c4213ad68922b2a59148943a24d464ac
RNFBApp: 0d0ffe0e3aacdf9fcad35f90b79bd8a3d3a99844
RNFBAppCheck: 11d0acf2c2b9e35bd99138cb33114558243a5d99
RNFBAppDistribution: ffa5a3fef8fbf4af53bf4f8a3eba0bb0695277dc
RNFBAuth: e156e2afa8695023b7507f76080527bdd3e38cb7
RNFBCrashlytics: 67e789bf7ffd7cd9accb7251b37d8f487d6beb74
RNFBDatabase: e111844746ee0a2f1fafe27667bdd916a6a53230
RNFBDynamicLinks: e9390d129dd2ff70ef357e7a5c7fe4f0ba0126df
RNFBFirestore: 1ba382d55702376493cf6b7f7c5f9d9389fd9a3a
RNFBFunctions: ef3a2037edb6470aa17a8f6515d9c926c47f0d49
RNFBInAppMessaging: f4fd6640ea94ab61c46f6a73d0d328fbaabfb305
RNFBInstallations: 9bd21ecd5c824bb5aa27d69cc0386c35d995b715
RNFBMessaging: 2a9dffb32f76274f86123644c62902e9ddc2a9ec
RNFBML: e2aced306ebca244d057b0d20cc9ad9ad7bdd125
RNFBPerf: 7b1140d7f288442f8a3bf899ba084fb8f7717ed4
RNFBRemoteConfig: 72f802427a422d236b367dcf3326566957045da5
RNFBStorage: 7fb11f8bb05fdfcd814e880c3da42a3f294e8226
RNFBAnalytics: 5e84004d8e64bd58bd185a324610fb433a103ca0
RNFBApp: 16bdf8b75b84631513da3d5f5e2520a436ec9b29
RNFBAppCheck: 5432a5aec00de2807aba195702a23d8c8eb12386
RNFBAppDistribution: 83d1260fc4cf2da900ebd9b3928d164bec21974f
RNFBAuth: 7eb50d60c82b4a59018b0c7a1d4afdd1250eff74
RNFBCrashlytics: eb4ea7e8ac4c9d9c6fb179370b3ac1bbc53ab69b
RNFBDatabase: 225f0ac57d2aedfec3221d8751b49670bc779b16
RNFBDynamicLinks: fa716828611f31e5da251225b1f22bb5667c0796
RNFBFirestore: 431b62b5751a8131d099cf2d094e16facaea455f
RNFBFunctions: 6edd867deda52f7e43cc5a3d69b2720aa6ce7e05
RNFBInAppMessaging: bb8766d9e57cce1d2e1ae0d3928a46a62c42bfc0
RNFBInstallations: 13accf200f3fc0fc5d2fb48ff12075e99858c84f
RNFBMessaging: ee73f1b9d0ea6781f32251401fc884549fd0bc44
RNFBML: a5e96c7912a7a7ac5200a590de350446484bf9e0
RNFBPerf: 50ae527679d837a6b0d4eed466935a99ec8b5bbb
RNFBRemoteConfig: e2a73b279da8b6f794977c7c3aeb6963a23f4e25
RNFBStorage: 2725730a381b228385959286894d469b861b5be3
Yoga: 5cbf25add73edb290e1067017690f7ebf56c5468

PODFILE CHECKSUM: a4854589561b42da6b3b0726136a46ac6aef3ebd
Expand Down
92 changes: 92 additions & 0 deletions tests/patches/react-native+0.67.1.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
diff --git a/node_modules/react-native/scripts/find-node.sh b/node_modules/react-native/scripts/find-node.sh
index 84e930a..b386939 100755
--- a/node_modules/react-native/scripts/find-node.sh
+++ b/node_modules/react-native/scripts/find-node.sh
@@ -8,45 +8,45 @@ set -e

# remove global prefix if it's already set
# the running shell process will choose a node binary and a global package directory breaks version managers
-unset PREFIX
-
-# Support Homebrew on M1
-HOMEBREW_M1_BIN=/opt/homebrew/bin
-if [[ -d $HOMEBREW_M1_BIN && ! $PATH =~ $HOMEBREW_M1_BIN ]]; then
- export PATH="$HOMEBREW_M1_BIN:$PATH"
-fi
-
-# Define NVM_DIR and source the nvm.sh setup script
-[ -z "$NVM_DIR" ] && export NVM_DIR="$HOME/.nvm"
-
-if [[ -s "$HOME/.nvm/nvm.sh" ]]; then
- # shellcheck source=/dev/null
- . "$HOME/.nvm/nvm.sh"
-elif [[ -x "$(command -v brew)" && -s "$(brew --prefix nvm)/nvm.sh" ]]; then
- # shellcheck source=/dev/null
- . "$(brew --prefix nvm)/nvm.sh"
-fi
-
-# Set up the nodenv node version manager if present
-if [[ -x "$HOME/.nodenv/bin/nodenv" ]]; then
- eval "$("$HOME/.nodenv/bin/nodenv" init -)"
-elif [[ -x "$(command -v brew)" && -x "$(brew --prefix nodenv)/bin/nodenv" ]]; then
- eval "$("$(brew --prefix nodenv)/bin/nodenv" init -)"
-fi
-
-# Set up the ndenv of anyenv if preset
-if [[ ! -x node && -d ${HOME}/.anyenv/bin ]]; then
- export PATH=${HOME}/.anyenv/bin:${PATH}
- if [[ "$(anyenv envs | grep -c ndenv )" -eq 1 ]]; then
- eval "$(anyenv init -)"
- fi
-fi
-
-# Set up asdf-vm if present
-if [[ -f "$HOME/.asdf/asdf.sh" ]]; then
- # shellcheck source=/dev/null
- . "$HOME/.asdf/asdf.sh"
-elif [[ -x "$(command -v brew)" && -f "$(brew --prefix asdf)/asdf.sh" ]]; then
- # shellcheck source=/dev/null
- . "$(brew --prefix asdf)/asdf.sh"
-fi
+# unset PREFIX
+
+# # Support Homebrew on M1
+# HOMEBREW_M1_BIN=/opt/homebrew/bin
+# if [[ -d $HOMEBREW_M1_BIN && ! $PATH =~ $HOMEBREW_M1_BIN ]]; then
+# export PATH="$HOMEBREW_M1_BIN:$PATH"
+# fi
+
+# # Define NVM_DIR and source the nvm.sh setup script
+# [ -z "$NVM_DIR" ] && export NVM_DIR="$HOME/.nvm"
+
+# if [[ -s "$HOME/.nvm/nvm.sh" ]]; then
+# # shellcheck source=/dev/null
+# . "$HOME/.nvm/nvm.sh"
+# elif [[ -x "$(command -v brew)" && -s "$(brew --prefix nvm)/nvm.sh" ]]; then
+# # shellcheck source=/dev/null
+# . "$(brew --prefix nvm)/nvm.sh"
+# fi
+
+# # Set up the nodenv node version manager if present
+# if [[ -x "$HOME/.nodenv/bin/nodenv" ]]; then
+# eval "$("$HOME/.nodenv/bin/nodenv" init -)"
+# elif [[ -x "$(command -v brew)" && -x "$(brew --prefix nodenv)/bin/nodenv" ]]; then
+# eval "$("$(brew --prefix nodenv)/bin/nodenv" init -)"
+# fi
+
+# # Set up the ndenv of anyenv if preset
+# if [[ ! -x node && -d ${HOME}/.anyenv/bin ]]; then
+# export PATH=${HOME}/.anyenv/bin:${PATH}
+# if [[ "$(anyenv envs | grep -c ndenv )" -eq 1 ]]; then
+# eval "$(anyenv init -)"
+# fi
+# fi
+
+# # Set up asdf-vm if present
+# if [[ -f "$HOME/.asdf/asdf.sh" ]]; then
+# # shellcheck source=/dev/null
+# . "$HOME/.asdf/asdf.sh"
+# elif [[ -x "$(command -v brew)" && -f "$(brew --prefix asdf)/asdf.sh" ]]; then
+# # shellcheck source=/dev/null
+# . "$(brew --prefix asdf)/asdf.sh"
+# fi