diff options
author | Ib Lundgren <ib.lundgren@gmail.com> | 2013-06-20 15:07:22 +0100 |
---|---|---|
committer | Ib Lundgren <ib.lundgren@gmail.com> | 2013-06-20 15:07:22 +0100 |
commit | 6d762fce70fcd4edc70358c4b7ef72591cc7518a (patch) | |
tree | e89a3913a30dc0c259f6da9919117fcc2c697b46 /tests | |
parent | a8fbacf462e0b93388a848ba4b59b9d4bec5a9a2 (diff) | |
download | oauthlib-6d762fce70fcd4edc70358c4b7ef72591cc7518a.tar.gz |
Add initial refresh token grant tests. Fix #182.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/oauth2/rfc6749/test_grant_types.py | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/tests/oauth2/rfc6749/test_grant_types.py b/tests/oauth2/rfc6749/test_grant_types.py index c8bd501..932680b 100644 --- a/tests/oauth2/rfc6749/test_grant_types.py +++ b/tests/oauth2/rfc6749/test_grant_types.py @@ -14,6 +14,7 @@ from oauthlib.oauth2.rfc6749.grant_types import AuthorizationCodeGrant from oauthlib.oauth2.rfc6749.grant_types import ImplicitGrant from oauthlib.oauth2.rfc6749.grant_types import ResourceOwnerPasswordCredentialsGrant from oauthlib.oauth2.rfc6749.grant_types import ClientCredentialsGrant +from oauthlib.oauth2.rfc6749.grant_types import RefreshTokenGrant from oauthlib.oauth2.rfc6749.tokens import BearerToken @@ -190,3 +191,45 @@ class ClientCredentialsGrantTest(TestCase): def test_validate_token_response(self): # wrong grant type, scope pass + + +class RefreshTokenGrantTest(TestCase): + + def setUp(self): + mock_client = mock.MagicMock() + mock_client.user.return_value = 'mocked user' + self.request = Request('http://a.b/path') + self.request.grant_type = 'refresh_token' + self.request.refresh_token = 'lsdkfhj230' + self.request.client = mock_client + self.request.scopes = ('mocked', 'scopes') + self.mock_validator = mock.MagicMock() + self.auth = RefreshTokenGrant( + request_validator=self.mock_validator) + + def test_create_token_response(self): + bearer = BearerToken(self.mock_validator) + uri, headers, body, status_code = self.auth.create_token_response( + self.request, bearer) + token = json.loads(body) + self.assertIn('access_token', token) + self.assertIn('token_type', token) + self.assertIn('expires_in', token) + + def test_invalid_token(self): + self.mock_validator.validate_refresh_token.return_value = False + bearer = BearerToken(self.mock_validator) + uri, headers, body, status_code = self.auth.create_token_response( + self.request, bearer) + token = json.loads(body) + self.assertEqual(token['error'], 'invalid_grant') + self.assertEqual(status_code, 400) + + def test_invalid_client(self): + self.mock_validator.authenticate_client.return_value = False + bearer = BearerToken(self.mock_validator) + uri, headers, body, status_code = self.auth.create_token_response( + self.request, bearer) + token = json.loads(body) + self.assertEqual(token['error'], 'invalid_client') + self.assertEqual(status_code, 401) |