-
Notifications
You must be signed in to change notification settings - Fork 192
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
Figure out how to make logging in work for func tests #277
Comments
@miketaylr How the test suite is supposed to work? I have seen
But does that mean the tests are done on the real instance of webcompat.com or on the local test instance. I don't see anything related to SetUp and TearDown for the functional tests where we could for example start the instance of the local server, create necessary issues for the test, and login information. |
Hmmm searching… |
Here's how I run tests:
I've exported $TESTUSER and $TESTPW in my .bash_profile. Right now we don't have any kind of setUp/tearDown stuff--but that would be a nice place to put the login routine. There's some of that going on in https://github.com/mozilla/fxa-content-server/blob/master/tests/functional/complete_sign_up.js, for example. Here's where |
As part of this, I was working on removing |
Here's that commit: a1e7892 on the referer branch. Everything works when I test it manually, but I'm hesitant to merge it in because it 4 tests are failing. Unsure if that's due to these changes (which could be OK, if the tests were written to the old behavior) or to the recent banning of all our bots cough cough |
a1e7892 doesn't solve all the problems though--we're still using |
I wondered if Selenium was struggling with reading/setting our session cookies. I still don't know, but something is weird. Make sure you from selenium import webdriver
driver = webdriver.Firefox()
driver.get("http://localhost:5000/issues/100")
elem = driver.find_element_by_css_selector(".nav__section--right .nav__link")
elem.click() This will navigate to Issue 100 and click the login link. You should now be at GitHub, so you can type in your user credentials. Expected: redirected back to Issue 100 If you try this from a regular web browser, new session, private window, whatever--it redirects back to the right place. 💣 |
OK. I think the root of the issue is I wonder if we can disable this for the session cookie only for testing. It might be a good approach. It could mean ditching Intern to more easily manipulate this from python. Or we could could pass an argument to run.py to let it know it's in testing mode. Possibly something to do in the meantime, as a quick fix. |
Some explorations
|
Related to this work, #279 It doesn't solve everything though. |
@miketaylr I was wondering why do we need to login or even make request to github. What we want is to test the functionality. Is it possible/hard to mock up and then not rely on network requests for testing? |
Logging in is something we want to make sure we don't break. We also want to make sure that certain features stay behind a login. Or that not-logged in people can do the same thing with our proxy request stuff, etc. So I don't think there's any way to test the appliction well without dealing with logins.
It should be possible to mock logging in, but probably a little complicated to mock OAuth2 token exchange. http://stackoverflow.com/questions/18827985/mocking-oauth-providers-while-testing looks interesting. |
Adding also Flask Testing Client. Let me clarify what I meant. I agree that testing logging is important, but it doesn't mean we have to actually log on github. Logging is done through an exchange, a negotiation in between two entities. What we want to be sure is that our application reacts well to the supposed message it receives (be a redirection URL, be a cookie, etc, choose your message). By mocking up the response, I meant define the supposed returned response so we are not dependent of online interactions (isolated tests environment), so our side of the application succeeds and fails well. OAuth2 seems indeed a bit more complex. I searched a couple of days ago about OAuth testing + intern and failed to find anything really interesting. All of that with a tongue-in-cheek, because I have no idea (yet) how to setup this. |
Issue #277 - Upgrade Intern to 2.1.1
I've spent a few hours messing with this again and it's time to give up for now. Observations: In test/functional/libs/index.js, when the first test logs in it succeeds. The second time fails. This my local server. From /issues/22 and when not logged in, I click "Login". Inside of the
Now, when I run the same thing from Intern:
The user_id was correctly set in the session from the But for whatever reason, the session (cookie) is lost between GET requests ( I need to do more digging on the Selenium/Intern side of things--rewriting the way we handle sessions on the server side doesn't (appear) to make a difference. |
💟
😍 Silly mistake which stole most of my day. Thanks @vladikoff. |
Supercalifragilisticexpialidocious! |
BIG THXXXXXXXXXXXXXXXXXXX to @vladikoff
And here's the why: https://github.com/webcompat/webcompat.com/blob/master/config.py.example#L66 If we start at 127.0.0.1 and login, Github will redirect us back to localhost. Because that's what we've told it to do. So the origin changed and presumably we don't have access to the session cookie at that point. 🙈 🙉 🙊 |
This is fixed, forgot to close. |
Right now there's a problem preventing us from testing any of the non-homepage logged-in functionality, i.e., #270, #271, #272.
For whatever reason, Selenium/Intern isn't able to read the session cookie, where we store the
next_url
key which tells the browser where to go after going through the auth routine.See https://github.com/webcompat/webcompat.com/blob/master/webcompat/views.py#L74
and https://github.com/webcompat/webcompat.com/blob/master/webcompat/views.py#L95.
So no matter what, you'll end up back at the homepage. Manually redirecting in the test won't help--it can't read the session to know that you're logged in.
@vladikoff suggested we try to return the cookie value to tests like in https://github.com/mozilla/fxa-content-server/blob/master/tests/functional/lib/helpers.js#L20. Worth exploring.
The other option would be to ditch the
next_url
param and storingnext_url
in the session entirely and pick another approach. We could store the URI of where the login request came from (inflask.g
maybe?)The text was updated successfully, but these errors were encountered: