Skip to content

Commit

Permalink
Modfied e2e tests to work with new FIREBASE_APP_CHECK_DEBUG_TOKEN
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabriel Lesperance committed Jan 25, 2022
1 parent ddecc6f commit 6173ad2
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 69 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"tests:packager:jet-reset-cache": "cd tests && cross-env REACT_DEBUGGER=\"echo nope\" node_modules/.bin/react-native start --reset-cache --no-interactive",
"tests:emulator:start": "cd ./.github/workflows/scripts && ./start-firebase-emulator.sh --no-daemon",
"tests:emulator:start-ci": "cd ./.github/workflows/scripts && ./start-firebase-emulator.sh",
"tests:android:build": "cd tests && yarn detox build --configuration android.emu.debug",
"tests:android:build": "cd tests && FIREBASE_APP_CHECK_DEBUG_TOKEN=\"698956B2-187B-49C6-9E25-C3F3530EEBAF\" yarn detox build --configuration android.emu.debug",
"tests:android:build-release": "cd tests && yarn detox build --configuration android.emu.release",
"tests:android:test": "cd tests && yarn detox test --configuration android.emu.debug",
"tests:android:test:debug": "cd tests && yarn detox test --configuration android.emu.debug --inspect",
Expand Down
19 changes: 1 addition & 18 deletions packages/app-check/e2e/appcheck.e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ describe('appCheck()', function () {
});
describe('getToken())', function () {
it('token fetch attempt should work', async function () {
await firebase.appCheck().activate('ignored', false);
// Our tests configure a debug provider with shared secret so we should get a valid token
const { token } = await firebase.appCheck().getToken();
token.should.not.equal('');
Expand Down Expand Up @@ -71,23 +72,5 @@ describe('appCheck()', function () {
return Promise.reject(e);
}
});
// Dynamic providers are not possible on iOS, so the debug provider is always working
it('token fetch attempt should work but fail attestation', async function () {
if (device.getPlatform() === 'android') {
try {
// Activating on Android clobbers the shared secret in the debug provider shared secret, should fail now
await firebase.appCheck().getToken(true);
return Promise.reject(
'Should have thrown after resetting shared secret on debug provider',
);
} catch (e) {
e.message.should.containEql('[appCheck/token-error]');
e.message.should.containEql('App attestation failed');
return Promise.resolve();
}
} else {
this.skip();
}
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -28,40 +28,8 @@ public class DetoxTest {

@Test
public void runDetoxTests() {

try {
// 1) Detox makes it extremely difficult to pass unencoded arguments directly to the instrumentation runner on Android:
// https://github.com/wix/Detox/issues/2933
//
// 2) AppCheck will only let you set a debug AppCheck token in CI via their test helpers via instrumentation runner args
// https://firebase.google.com/docs/app-check/android/debug-provider#ci
//
// Here we avoid the Detox argument-passing / AppCheck argument-reading difficulty by directly putting the String in.
//
// This is unwanted in nearly all scenarios as it leaks an AppCheck token, but the react-native-firebase test
// project does not have AppCheck set to enforcing, so this is okay for this project.
//
// This has a great potential for leaking your token in a real app that wants to enforce and rely on AppCheck.
Class<?> testHelperClass = DebugAppCheckTestHelper.class;
Method[] methods = testHelperClass.getDeclaredMethods();
for (int i = 0; i < methods.length; i++) {
if (methods[i].getName().equals("fromString")) {
Method testHelperMethod = methods[i];
testHelperMethod.setAccessible(true);
DebugAppCheckTestHelper debugAppCheckTestHelper =
(DebugAppCheckTestHelper)testHelperMethod.invoke(null, "698956B2-187B-49C6-9E25-C3F3530EEBAF");
debugAppCheckTestHelper.withDebugProvider(() -> {

// This is the standard Detox androidTest implementation:
Detox.runTests(mActivityRule);

dumpCoverageData();
});
}
}
} catch (Exception e) {
throw new RuntimeException("Unable to force AppCheck debug token: ", e);
}
Detox.runTests(mActivityRule);
dumpCoverageData();
}

// If you send '-e coverage' as part of the instrumentation command line, it should dump coverage as the Instrumentation finishes.
Expand Down
32 changes: 16 additions & 16 deletions tests/e2e/.mocharc.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,22 @@ module.exports = {
recursive: true,
require: 'node_modules/jet/platform/node',
spec: [
'../packages/app/e2e/**/*.e2e.js',
// '../packages/app/e2e/**/*.e2e.js',
'../packages/app-check/e2e/**/*.e2e.js',
'../packages/app-distribution/e2e/**/*.e2e.js',
'../packages/analytics/e2e/**/*.e2e.js',
'../packages/auth/e2e/**/*.e2e.js',
'../packages/crashlytics/e2e/**/*.e2e.js',
'../packages/database/e2e/**/*.e2e.js',
'../packages/dynamic-links/e2e/**/*.e2e.js',
'../packages/firestore/e2e/**/*.e2e.js',
'../packages/functions/e2e/**/*.e2e.js',
'../packages/perf/e2e/**/*.e2e.js',
'../packages/messaging/e2e/**/*.e2e.js',
'../packages/ml/e2e/**/*.e2e.js',
'../packages/in-app-messaging/e2e/**/*.e2e.js',
'../packages/installations/e2e/**/*.e2e.js',
'../packages/remote-config/e2e/**/*.e2e.js',
'../packages/storage/e2e/**/*.e2e.js',
// '../packages/app-distribution/e2e/**/*.e2e.js',
// '../packages/analytics/e2e/**/*.e2e.js',
// '../packages/auth/e2e/**/*.e2e.js',
// '../packages/crashlytics/e2e/**/*.e2e.js',
// '../packages/database/e2e/**/*.e2e.js',
// '../packages/dynamic-links/e2e/**/*.e2e.js',
// '../packages/firestore/e2e/**/*.e2e.js',
// '../packages/functions/e2e/**/*.e2e.js',
// '../packages/perf/e2e/**/*.e2e.js',
// '../packages/messaging/e2e/**/*.e2e.js',
// '../packages/ml/e2e/**/*.e2e.js',
// '../packages/in-app-messaging/e2e/**/*.e2e.js',
// '../packages/installations/e2e/**/*.e2e.js',
// '../packages/remote-config/e2e/**/*.e2e.js',
// '../packages/storage/e2e/**/*.e2e.js',
],
};

0 comments on commit 6173ad2

Please sign in to comment.