Fix auth_exchange tests BOM-648

This commit is contained in:
Jeremy Bowman
2019-09-18 16:37:52 -04:00
parent 93142ebd2d
commit 83eb9e7f1a
2 changed files with 9 additions and 4 deletions

View File

@@ -50,7 +50,7 @@ class AccessTokenExchangeFormTest(AccessTokenExchangeTestMixin):
self.assertTrue(form.is_valid())
self.assertEqual(form.cleaned_data["user"], self.user)
self.assertEqual(form.cleaned_data["client"], self.oauth_client)
self.assertEqual(scope.to_names(form.cleaned_data["scope"]), expected_scopes)
self.assertEqual(set(scope.to_names(form.cleaned_data["scope"])), set(expected_scopes))
# This is necessary because cms does not implement third party auth

View File

@@ -63,11 +63,16 @@ class AccessTokenExchangeViewTest(AccessTokenExchangeTestMixin):
timedelta(seconds=int(content["expires_in"])),
provider.constants.EXPIRE_DELTA_PUBLIC
)
self.assertEqual(content["scope"], ' '.join(expected_scopes))
actual_scopes = content["scope"]
if actual_scopes:
actual_scopes = actual_scopes.split(' ')
else:
actual_scopes = []
self.assertEqual(set(actual_scopes), set(expected_scopes))
token = self.oauth2_adapter.get_access_token(token_string=content["access_token"])
self.assertEqual(token.user, self.user)
self.assertEqual(self.oauth2_adapter.get_client_for_token(token), self.oauth_client)
self.assertEqual(self.oauth2_adapter.get_token_scope_names(token), expected_scopes)
self.assertEqual(set(self.oauth2_adapter.get_token_scope_names(token)), set(expected_scopes))
def test_single_access_token(self):
def extract_token(response):
@@ -184,7 +189,7 @@ class TestLoginWithAccessTokenView(TestCase):
Calls the login_with_access_token endpoint and verifies the response given the expected values.
"""
url = reverse("login_with_access_token")
response = self.client.post(url, HTTP_AUTHORIZATION=b"Bearer {0}".format(access_token))
response = self.client.post(url, HTTP_AUTHORIZATION=u"Bearer {0}".format(access_token).encode('utf-8'))
self.assertEqual(response.status_code, expected_status_code)
if expected_cookie_name:
self.assertIn(expected_cookie_name, response.cookies)