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

Way to force showing the captcha input view? For testing #19

Closed
MaximusMcCann opened this issue Jan 22, 2018 · 11 comments · Fixed by #32
Closed

Way to force showing the captcha input view? For testing #19

MaximusMcCann opened this issue Jan 22, 2018 · 11 comments · Fixed by #32
Labels

Comments

@MaximusMcCann
Copy link

No description provided.

@fjcaetano
Copy link
Owner

There's no way to force it, mostly because it's using the Invisible ReCaptcha API. Even, if the embedded html were changed to use the explicit one, you'd need to use a different API key for the different methods.

Can I help you with your tests? Maybe what you're trying to do is already covered by our tests.

@MaximusMcCann
Copy link
Author

All good then. Just trying to clean up how some UI looks when the webview is presented. Had to keep refreshing a bunch, ha.

@augustorsouza
Copy link

augustorsouza commented Mar 8, 2018

Hello guys, I think there is a way to make it appear by forcing a user agent switch. In my tests it worked.

Based on these two links: https://stackoverflow.com/questions/43397678/is-it-possible-to-force-fail-a-recaptcha-v2-for-testing-purposes-i-e-pretend and https://stackoverflow.com/questions/478387/change-user-agent-in-uiwebview-iphone-sdk , I was able to put the following code in my function application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey : Any]? = nil) -> Bool of my App Delegate class:

UserDefaults.standard.register(defaults: ["UserAgent" : "Googlebot/2.1"])

Could you guys test too please and update me with the results?

@fjcaetano do you think we are able to put this as a feature into the ReCaptcha library? I can help with this if you want :)

Best regards

@fjcaetano
Copy link
Owner

Interesting. This does seem to work, but when would it be interesting to show the challenge to the user?

Would this work with a non-Invisible API key? If not, I don't think it would be an interesting addition, since it could cause confusion.

@fjcaetano fjcaetano reopened this Mar 8, 2018
@fjcaetano
Copy link
Owner

Interestingly enough, it didn't work for UI tests (which I think would be the most reasonable use for this), unless the defaults are set in the main application's AppDelegate as @augustorsouza said.

It'd be interesting to have this working in a setUp of a test case, for instance

@augustorsouza
Copy link

@fjcaetano some libraries, such as Analytics ones for exempla sometimes have a initialization in the app delegate with some configuration or extra information. Do you think this might be a way to proceed?

For example, some libs have a debug boolean flag in the initialization

@fjcaetano
Copy link
Owner

I'm still not sold on why would anyone want to explicitly show the challenge.

@MaximusMcCann you were the one who brought this up. Were you just trying to write tests for it? Doesn't the libraries tests cover what you were trying to do?

@augustorsouza
Copy link

I think the main reason is that sometimes it is hard to reproduce the behaviour some users of your app will see. When using the invisible API at my network I hardly get a recaptcha input view. With the workaround I described I am able to see the input view and check if there is something wrong in my UI for the user.

@fjcaetano
Copy link
Owner

Okay, I guess it makes sense to debug the webview position and layout.

Still, this is something that should only be available for development. What do you think of making a boolean public only in DEBUG that forces this? Something like:

class ReCaptcha {
...
#if DEBUG
    public var forceVisibleChallenge: Bool // Defaults to false
#endif
}

This may need to be set in the init, then it's another matter.

Luckily, WKWebView already has a customUserAgent prop, so it doesn't need to be set globally.

@fjcaetano
Copy link
Owner

@MaximusMcCann and @augustorsouza, please take a look at PR #32

@augustorsouza
Copy link

@fjcaetano the PR #32 looks great to me 👍 thank you very much for the improvement!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants