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

detoxURLBlacklistRegex in launchArgs not working (always nil) #1861

Closed
2 tasks done
michaelgmcd opened this issue Jan 16, 2020 · 34 comments
Closed
2 tasks done

detoxURLBlacklistRegex in launchArgs not working (always nil) #1861

michaelgmcd opened this issue Jan 16, 2020 · 34 comments

Comments

@michaelgmcd
Copy link
Contributor

michaelgmcd commented Jan 16, 2020

  • I have tested this issue on the latest Detox release and it still reproduces

Description

No matter what value I set detoxURLBlacklistRegex to in launchArgs when launching the app, it is always nil when picked up in the native code.

If I replace [options arrayForKey:@"detoxURLBlacklistRegex"];with @[@".*"]; my tests run as expected. I've tried setting the values to all of the following:

  • The example: '\\("http://192.168.1.253:19001/onchange","https://e.crashlytics.com/spi/v2/events"\\)'
  • '\\(".*"\\)'
  • '\\(.*\\)'
  • ['.*']

Reproduction

  1. Update detox/ios/Detox/DetoxManager.m to print out "blacklistRegex"
  2. Run detox tests using detoxURLBlacklistRegex in launchApp (as mentioned in the docs)

Expected behavior

The value should be set to what is passed in detoxURLBlacklistRegex

Environment (please complete the following information):

  • Detox: 15.1.2
  • React Native: 0.61.5
  • Node: 12.14.1
  • Device: iPhone 8 (tried on multiple)
  • Xcode: 11.3.1
  • iOS: 13.3
  • macOS: 10.14.5

Logs

If you are experiencing a timeout in your test

Omitting the log for brevity. It shows a lot of App State -> busy Waiting for network requests to finish: ... logs while launching

@LeoNatan
Copy link
Contributor

Can you please print NSProcessInfo.processInfo.arguments and post it here? Thanks

@LeoNatan
Copy link
Contributor

I wonder if the syntax of what is passed is perhaps not correctly understood by the system, and thus not parsed correctly as an array, which then returns nil, as you've seen.

@michaelgmcd
Copy link
Contributor Author

michaelgmcd commented Jan 17, 2020

I wasn't able to easily print NSProcessInfo.processInfo.arguments from the native side, but I sent it back through the websocket:

[
  "/<omitted>/Library/Developer/CoreSimulator/Devices/DCEDB0BC-2805-4FF4-8F0B-AAA68F2777EC/data/Containers/Bundle/Application/B4169AF8-137C-4697-B781-ABC8341F6D81/<omitted>.app/Lifion",
  "--args",
  "-detoxServer",
  "ws://localhost:50704",
  "-detoxSessionId",
  "1206b777-0544-6187-ff96-b6291745ab7c",
  "-detoxPrintBusyIdleResources",
  "YES",
  "-detoxURLBlacklistRegex",
  "\\(.*codepush.azurewebsites.*,.*clients3.google.*,.*googleapis.*,.*app-measurement.*,.*crashlytics.*\\)"
]

Relevant logs:

detox[82393] TRACE: [ArtifactsManager.js/LIFECYCLE] artifactsManager.onBeforeLaunchApp({
  bundleId: 'com.<omitted>',
  deviceId: 'DCEDB0BC-2805-4FF4-8F0B-AAA68F2777EC',
  launchArgs: {
    detoxServer: 'ws://localhost:50704',
    detoxSessionId: '1206b777-0544-6187-ff96-b6291745ab7c',
    detoxPrintBusyIdleResources: 'YES',
    detoxURLBlacklistRegex: '\\(".*codepush.azurewebsites.*",".*clients3.google.*",".*googleapis.*",".*app-measurement.*",".*crashlytics.*"\\)'
  }
})
detox[82393] DEBUG: [exec.js/EXEC_CMD, #5] SIMCTL_CHILD_DYLD_INSERT_LIBRARIES="/<omitted>/Library/Detox/ios/6482a19f2e78285efde7a67b977225fd53e12142/Detox.framework/Detox" /usr/bin/xcrun simctl launch DCEDB0BC-2805-4FF4-8F0B-AAA68F2777EC com.<omitted> --args -detoxServer "ws://localhost:50704" -detoxSessionId "1206b777-0544-6187-ff96-b6291745ab7c" -detoxPrintBusyIdleResources "YES" -detoxURLBlacklistRegex "\(".*codepush.azurewebsites.*",".*clients3.google.*",".*googleapis.*",".*app-measurement.*",".*crashlytics.*"\)"
detox[82393] DEBUG: [exec.js/EXEC_TRY, #5] Launching com.<omitted>...
detox[82393] TRACE: [exec.js/EXEC_SUCCESS, #5] com.<omitted>: 82430

detox[82393] DEBUG: [exec.js/EXEC_CMD, #6] /usr/bin/xcrun simctl get_app_container DCEDB0BC-2805-4FF4-8F0B-AAA68F2777EC com.<omitted>
detox[82393] TRACE: [exec.js/EXEC_SUCCESS, #6] /<omitted>/Library/Developer/CoreSimulator/Devices/DCEDB0BC-2805-4FF4-8F0B-AAA68F2777EC/data/Containers/Bundle/Application/B4169AF8-137C-4697-B781-ABC8341F6D81/<omitted>.app

detox[82393] INFO:  [AppleSimUtils.js] com.<omitted> launched. To watch simulator logs, run:
        /usr/bin/xcrun simctl spawn DCEDB0BC-2805-4FF4-8F0B-AAA68F2777EC log stream --level debug --style compact --predicate 'processImagePath beginsWith "/<omitted>/Library/Developer/CoreSimulator/Devices/DCEDB0BC-2805-4FF4-8F0B-AAA68F2777EC/data/Containers/Bundle/Application/B4169AF8-137C-4697-B781-ABC8341F6D81/<omitted>.app"'
detox[82430] TRACE: [ArtifactsManager.js/LIFECYCLE] artifactsManager.onLaunchApp({
  bundleId: 'com.<omitted>',
  deviceId: 'DCEDB0BC-2805-4FF4-8F0B-AAA68F2777EC',
  launchArgs: {
    detoxServer: 'ws://localhost:50704',
    detoxSessionId: '1206b777-0544-6187-ff96-b6291745ab7c',
    detoxPrintBusyIdleResources: 'YES',
    detoxURLBlacklistRegex: '\\(".*codepush.azurewebsites.*",".*clients3.google.*",".*googleapis.*",".*app-measurement.*",".*crashlytics.*"\\)'
  },
  pid: 82430
})

@LeoNatan
Copy link
Contributor

Ah, I think the syntax is incorrect. It needs to be an array of strings. You are missing the " for each string. Try with that.

@michaelgmcd
Copy link
Contributor Author

You can see in several places in the second log (example below) that I am passing strings. They're being stripped out somewhere:

detox[82393] TRACE: [ArtifactsManager.js/LIFECYCLE] artifactsManager.onBeforeLaunchApp({
  bundleId: 'com.<omitted>',
  deviceId: 'DCEDB0BC-2805-4FF4-8F0B-AAA68F2777EC',
  launchArgs: {
    detoxServer: 'ws://localhost:50704',
    detoxSessionId: '1206b777-0544-6187-ff96-b6291745ab7c',
    detoxPrintBusyIdleResources: 'YES',
    detoxURLBlacklistRegex: '\\(".*codepush.azurewebsites.*",".*clients3.google.*",".*googleapis.*",".*app-measurement.*",".*crashlytics.*"\\)'
  }
})

@LeoNatan
Copy link
Contributor

Not good!

@LeoNatan
Copy link
Contributor

@d4vidi @rotemmiz This likely broke after the rewrite of arguments. It means this feature is broken.

@michaelgmcd
Copy link
Contributor Author

Mind linking to the "rewrite of arguments"? I'd love to dive a little deeper into this.

@d4vidi
Copy link
Collaborator

d4vidi commented Jan 18, 2020

Yikes, are we lacking e2e coverage there? @michaelgmcd have you happened to have tried this out on Android?

@rotemmiz
Copy link
Member

A quick note here, setURLBlacklist is a passthrough operation into EarlGrey, it only accepts regex expressions (i.e. https\:\/\/www.google.com.* instead of https://www.google.com.
Try your expressions in a regex matching site (like regex 101) and see if it works.

@LeoNatan
Copy link
Contributor

@rotemmiz The issue is the lack of quotes, because they are stripped. NSUserDefaults then fails to parse the array of strings as such.

@michaelgmcd
Copy link
Contributor Author

@d4vidi I have not tried this on Android. Is it even supported there?

@rotemmiz I tried a lot of different options, including ".*". Will to give any other example a shot.

@michaelgmcd
Copy link
Contributor Author

Hey @LeoNatan, following up here. What are the next steps? I'd love some advice on how to debug this a little better. The "Debugging in XCode" doc doesn't seem to apply here because we're launching the app a different way.

@LeoNatan
Copy link
Contributor

I am not familiar with the JS side of things. If you’d like to help us debug, please follow the launch arguments from the user-facing launch API to where it is actually sent. Somewhere there is a bug that causes incorrect stripping of quotes and possibly other characters. Thanks

@michaelgmcd
Copy link
Contributor Author

I dug a little bit into this and everything up until the native code seems ok. Below (from AppleSimUtils.js) is the only place that manipulates and uses the launch args:

...
  _joinLaunchArgs(launchArgs) {
    return _.map(launchArgs, (v, k) => `-${k} "${v}"`)
      .join(' ')
      .trim();
  }

  async _launchMagically(frameworkPath, udid, bundleId, launchArgs, languageAndLocale) {
    const args = this._joinLaunchArgs(launchArgs);

    const statusLogs = {
      trying: `Launching ${bundleId}...`,
    };

    let dylibs = `${frameworkPath}/Detox`;
    if (process.env.SIMCTL_CHILD_DYLD_INSERT_LIBRARIES) {
      dylibs = `${process.env.SIMCTL_CHILD_DYLD_INSERT_LIBRARIES}:${dylibs}`;
    }

    let launchBin =
      `SIMCTL_CHILD_DYLD_INSERT_LIBRARIES="${dylibs}" ` +
      `/usr/bin/xcrun simctl launch ${udid} ${bundleId} --args ${args}`;

    if (!!languageAndLocale && !!languageAndLocale.language) {
      launchBin += ` -AppleLanguages "(${languageAndLocale.language})"`;
    }

    if (!!languageAndLocale && !!languageAndLocale.locale) {
      launchBin += ` -AppleLocale ${languageAndLocale.locale}`;
    }

    const result = await exec.execWithRetriesAndLogs(launchBin, undefined, statusLogs, 1);

    return result;
  }
...

The arguments to simctl launch seem correct:

/usr/bin/xcrun simctl launch <omitted> --args -detoxServer "ws://localhost:65313" -detoxSessionId "d6f3d4e7-7a91-7cd6-0423-b679f5cea8eb" -detoxPrintBusyIdleResources "YES" -detoxURLBlacklistRegex "\(".*codepush.azurewebsites.*",".*clients3.google.*",".*googleapis.*",".*app-measurement.*",".*crashlytics.*"\)"

@michaelgmcd
Copy link
Contributor Author

I've tried escaping the " in the launchArgs I pass as well, but still no luck:

'\\(\\".*codepush.azurewebsites.*\\",\\".*clients3.google.*\\",\\".*googleapis.*\\",\\".*app-measurement.*\\",\\".*crashlytics.*\\"\\)'

@renanmav
Copy link

renanmav commented Feb 3, 2020

Any news on this?

@Durisvk
Copy link

Durisvk commented Feb 3, 2020

@LeoNatan

This likely broke after the rewrite of arguments. It means this feature is broken.

Is there a specific version of Detox we can use in the meantime until this gets sorted out?

@LeoNatan
Copy link
Contributor

LeoNatan commented Feb 3, 2020

I'm sorry, I'm not sure which version introduced this issue. It was a while back. Contributions are welcome.

@Durisvk
Copy link

Durisvk commented Feb 3, 2020

@michaelgmcd when you escape those " characters,
what is the output you get back from your NSProcessInfo.processInfo.arguments sent through websockets?

is there an easy way to set the logging through websockets up?

@socksrust
Copy link

Hey @LeoNatan @renanmav @Durisvk

if using detox on v14.0.0

and using:

await device.setURLBlacklist(['.*googleapis.*']);

works for me

@Durisvk
Copy link

Durisvk commented Feb 4, 2020

@jaburx I'm missing in the docs, when is the right time to call await device.setURLBlacklist(['.*googleapis.*']);

is it before detox.init? after detox.init?

the problem is I'm using detox for Expo ejected app and it gets stuck on init and on setURLBlacklist as well

@LeoNatan
Copy link
Contributor

LeoNatan commented Feb 4, 2020

Sending the param as launch argument and using setURLBlacklist are two different things. The bug is in the former, while the latter passes the data over the web socket.

@socksrust
Copy link

Its after init

@socksrust
Copy link

Hey Leo, we know that, but u guys were asking for a way to run it.

@LeoNatan
Copy link
Contributor

LeoNatan commented Feb 4, 2020

But the suggestion doesn't work here, because if an app makes requests on launch, Detox will be stuck waiting for them, unable to reach idle state, so it can process the setURLBlacklist() call.

@Minishlink
Copy link

Hello, I dug into this issue and couldn't find where it was altered. I played with NSUserDefaults and launch args in XCode, and in fact there's no problem with detox.

You can use this function to generate the correct value of detoxURLBlacklistRegex from a list of domains:

const getDetoxURLBlacklistRegexFromDomains = domains =>
  '(' + domains.map(domain => `\\".*${domain}.*\\"`).join(',') + ')';

This generates the following CLI arg, with your example @michaelgmcd :

-detoxURLBlacklistRegex "(\".*codepush.azurewebsites.*\",\".*clients3.google.*\",\".*googleapis.*\",\".*app-measurement.*\",\".*crashlytics.*\")"

Happy to do a PR to add a more friendly API if need be.

@michaelgmcd
Copy link
Contributor Author

@Minishlink, it works! Weird that I tried a very similar function that didn't. I think a friendlier API would make sense. Maybe just accept an array of url regex strings?

@mckenzit
Copy link

Is there any solution that doesn’t involve diving into the workings of Detox, and just using the
await detox.init(config, { launchApp: false, detoxURLBlacklistRegex: ""});


If there is (having kept a close eye on this bug) I would be very grateful to know what regex I would need to blacklist pub-nub domains. I.e. ps1.pndsn.com, ps2.pndsn.com, ps3.pndsn.com, ps22.pndsn.com etc etc



I know it would seem straightforward, but nothing seems to work.
Thanks

@Minishlink
Copy link

@mckenzit Have you seen my comment?

You would then have to do :

const detoxURLBlacklistRegex = getDetoxURLBlacklistRegexFromDomains(['pndsn.com']);
await detox.init(config, { launchApp: false, detoxURLBlacklistRegex });

@stale
Copy link

stale bot commented Mar 22, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
If you believe the issue is still relevant, please test on the latest Detox and report back.

Thank you for your contributions!

For more information on bots in this reporsitory, read this discussion.

@stale stale bot added the 🏚 stale label Mar 22, 2020
@d4vidi
Copy link
Collaborator

d4vidi commented Mar 22, 2020

What's the status here, then? Should we pin or close?

@stale stale bot removed the 🏚 stale label Mar 22, 2020
@stale
Copy link

stale bot commented Apr 23, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
If you believe the issue is still relevant, please test on the latest Detox and report back.

Thank you for your contributions!

For more information on bots in this reporsitory, read this discussion.

@stale stale bot added the 🏚 stale label Apr 23, 2020
@stale
Copy link

stale bot commented Apr 30, 2020

The issue has been closed for inactivity.

@stale stale bot closed this as completed Apr 30, 2020
@lock lock bot locked as resolved and limited conversation to collaborators May 5, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

9 participants