From 2f4487c184ed8d6903861ed2e2bfc7ffd4cdd431 Mon Sep 17 00:00:00 2001 From: Joseph Schorr Date: Tue, 14 Feb 2017 13:51:58 -0500 Subject: [PATCH] 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. --- test/test_oauth_login.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/test/test_oauth_login.py b/test/test_oauth_login.py index 9590a39aa..ce5dfcd5f 100644 --- a/test/test_oauth_login.py +++ b/test/test_oauth_login.py @@ -1,6 +1,7 @@ import json as py_json import time import unittest +import urlparse import jwt @@ -59,7 +60,8 @@ class OAuthLoginTestCase(EndpointTestCase): def test_google_oauth(self): @urlmatch(netloc=r'accounts.google.com', path='/o/oauth2/token') 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'} return py_json.dumps(content) else: @@ -81,7 +83,8 @@ class OAuthLoginTestCase(EndpointTestCase): def test_github_oauth(self): @urlmatch(netloc=r'github.com', path='/login/oauth/access_token') 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'} return py_json.dumps(content) else: