Fix flaky OAuth tests under tor
The `> 0` check fails if the code was found first in the query string, which can occasionally happen under tox due to the `PYTHONHASHSEED` var changing. We simply change to use a proper parse and check to avoid this issue entirely.
This commit is contained in:
parent
2b189694a8
commit
2f4487c184
1 changed files with 5 additions and 2 deletions
|
@ -1,6 +1,7 @@
|
||||||
import json as py_json
|
import json as py_json
|
||||||
import time
|
import time
|
||||||
import unittest
|
import unittest
|
||||||
|
import urlparse
|
||||||
|
|
||||||
import jwt
|
import jwt
|
||||||
|
|
||||||
|
@ -59,7 +60,8 @@ class OAuthLoginTestCase(EndpointTestCase):
|
||||||
def test_google_oauth(self):
|
def test_google_oauth(self):
|
||||||
@urlmatch(netloc=r'accounts.google.com', path='/o/oauth2/token')
|
@urlmatch(netloc=r'accounts.google.com', path='/o/oauth2/token')
|
||||||
def account_handler(_, request):
|
def account_handler(_, request):
|
||||||
if request.body.find("code=somecode") > 0:
|
parsed = dict(urlparse.parse_qsl(request.body))
|
||||||
|
if parsed['code'] == 'somecode':
|
||||||
content = {'access_token': 'someaccesstoken'}
|
content = {'access_token': 'someaccesstoken'}
|
||||||
return py_json.dumps(content)
|
return py_json.dumps(content)
|
||||||
else:
|
else:
|
||||||
|
@ -81,7 +83,8 @@ class OAuthLoginTestCase(EndpointTestCase):
|
||||||
def test_github_oauth(self):
|
def test_github_oauth(self):
|
||||||
@urlmatch(netloc=r'github.com', path='/login/oauth/access_token')
|
@urlmatch(netloc=r'github.com', path='/login/oauth/access_token')
|
||||||
def account_handler(url, _):
|
def account_handler(url, _):
|
||||||
if url.query.find("code=somecode") > 0:
|
parsed = dict(urlparse.parse_qsl(url.query))
|
||||||
|
if parsed['code'] == 'somecode':
|
||||||
content = {'access_token': 'someaccesstoken'}
|
content = {'access_token': 'someaccesstoken'}
|
||||||
return py_json.dumps(content)
|
return py_json.dumps(content)
|
||||||
else:
|
else:
|
||||||
|
|
Reference in a new issue