Ejemplo n.º 1
0
 def test_can_get_consent_request(self, request):
     c = Client(**self.data)
     c.get_consent_request(self.challenge)
     request.assert_called_with(
         'GET',
         'http://localhost:4445/oauth2/auth/requests/consent',
         params={'consent_challenge': self.challenge})
Ejemplo n.º 2
0
 def test_request_with_token_authentication(self, request):
     request.return_value.json.return_value = self.token_response
     c = Client(**self.data)
     c.request('GET', '/clients', token=True)
     auth = ('client', 'secret')
     request.assert_called_with(
         'GET', 'http://localhost:4444/clients', auth=auth)
Ejemplo n.º 3
0
 def test_can_get_consent_request(self, request):
     c = Client(**self.data)
     c.get_consent_request(self.challenge)
     request.assert_called_with(
         'GET',
         'http://localhost:4445/oauth2/auth/requests/consent/{}'
         .format(self.challenge))
Ejemplo n.º 4
0
 def test_can_revoke_token(self, request):
     c = Client(**self.data)
     c.revoke_token(self.token)
     data = {'token': 'super-token'}
     auth = ('client', 'secret')
     request.assert_called_with(
         'POST', 'http://localhost:4444/oauth2/revoke',
         data=data, auth=auth)
Ejemplo n.º 5
0
 def test_can_instrospect_token(self, request):
     request.return_value.json.return_value = self.token_response
     c = Client(**self.data)
     c.instrospect_token(self.token)
     data = {'token': 'super-token'}
     request.assert_called_with(
         'POST', 'http://localhost:4445/oauth2/introspect',
         data=data)
Ejemplo n.º 6
0
 def test_can_lists_all_consent_sessions_user(self, request):
     c = Client(**self.data)
     user = '******'
     c.lists_all_consent_sessions_user(user)
     request.assert_called_once_with(
         'GET',
         'http://localhost:4445/oauth2/auth/sessions/consent',
         params={'subject': user})
Ejemplo n.º 7
0
 def test_request_with_token_authentication(self, request):
     request.return_value.json.return_value = self.token_response
     c = Client(**self.data)
     c.request('GET', '/clients', token=True)
     headers = {'Authorization': 'bearer super-token'}
     request.assert_called_with('GET',
                                'http://localhost/clients',
                                headers=headers)
Ejemplo n.º 8
0
 def test_can_get_access_token(self, request):
     request.return_value.json.return_value = self.token_response
     c = Client(**self.data)
     token = c.get_access_token('devices')
     self.assertEqual(token.scope, 'devices')
     self.assertEqual(token.expires_in, 10)
     self.assertEqual(token.token, 'super-token')
     self.assertEqual(token.type, 'bearer')
Ejemplo n.º 9
0
 def test_request_with_basic_authentication(self, request):
     c = Client(**self.data)
     c.request(
         'POST', '/oauth2/token', token=False,
         auth=('client', 'secret'), json={'token': 'foobar'})
     request.assert_called_with(
         'POST', 'http://localhost:4445/oauth2/token',
         auth=('client', 'secret'), json={'token': 'foobar'})
Ejemplo n.º 10
0
 def test_can_revoke_consent_sessions_oAuth2_client(self, request):
     c = Client(**self.data)
     user = '******'
     client = c.client
     c.revokes_consent_sessions_oAuth2_client(user, c.client)
     request.assert_called_with(
         'DELETE',
         'http://localhost:4445/oauth2/auth/sessions/consent',
         params={'subject': user, 'client': client})
Ejemplo n.º 11
0
 def test_can_revoke_consent_sessions_oAuth2_client(self, request):
     c = Client(**self.data)
     user = '******'
     client = c.client
     c.revokes_consent_sessions_oAuth2_client(user, c.client)
     request.assert_called_with(
         'DELETE',
         'http://localhost:4445/oauth2/auth/sessions/consent/{}/{}'
         .format(user, client))
Ejemplo n.º 12
0
 def test_can_revokes_all_previous_consent_session_user(self, request):
     c = Client(**self.data)
     user = '******'
     c.revokes_all_previous_consent_session_user(user)
     request.assert_called_once_with(
         'DELETE',
         'http://localhost:4445/oauth2/auth/sessions/consent',
         params={'subject': user}
     )
Ejemplo n.º 13
0
 def test_can_get_cached_token(self, request):
     request.return_value.json.return_value = self.token_response
     c = Client(**self.data)
     c.get_access_token()
     c.get_access_token()
     request.assert_called_once_with(
         'POST',
         'http://localhost/oauth2/token',
         auth=(c.client, c.secret),
         data={'grant_type': 'client_credentials'})
Ejemplo n.º 14
0
 def test_can_instrospect_token(self, request):
     request.return_value.json.return_value = self.token_response
     c = Client(**self.data)
     c.instrospect_token(self.token)
     headers = {'Authorization': 'bearer super-token'}
     data = {'token': 'super-token'}
     request.assert_called_with('POST',
                                'http://localhost/oauth2/introspect',
                                data=data,
                                headers=headers)
Ejemplo n.º 15
0
 def test_can_accept_login_request(self, request):
     c = Client(**self.data)
     accept_config = {
         'remember_for': 0,
         'remember': False,
         'subject': c.client
     }
     c.accept_login_request(self.challenge, accept_config)
     request.assert_called_with(
         'PUT',
         'http://localhost:4445/oauth2/auth/requests/login/accept',
         params={'login_challenge': self.challenge},
         json=accept_config)
Ejemplo n.º 16
0
 def test_can_reject_consent_request(self, request):
     c = Client(**self.data)
     reject_config = {
         'error': 'test',
         'error_debug': 'test',
         'error_description': 'test',
         'error_hint': 'test',
         'status_code': 404
     }
     c.reject_consent_request(self.challenge, reject_config)
     request.assert_called_once_with(
         'PUT',
         'http://localhost:4445/oauth2/auth/requests/consent/reject',
         params={'consent_challenge': self.challenge},
         json=reject_config)
Ejemplo n.º 17
0
 def test_can_accept_consent_request(self, request):
     c = Client(**self.data)
     accept_config = {
         'remember_for': 0,
         'remember': False,
         'session': {
             'access_token': self.token.ext
         },
     }
     c.accept_consent_request(self.challenge, accept_config)
     request.assert_called_with(
         'PUT',
         'http://localhost:4445/oauth2/auth/requests/consent/accept',
         params={'consent_challenge': self.challenge},
         json=accept_config)
Ejemplo n.º 18
0
    def test_get_access_token_request_is_made_correctly(self, request):
        c = Client(**self.data)
        c.get_access_token()
        request.assert_called_with('POST',
                                   'http://localhost/oauth2/token',
                                   auth=(c.client, c.secret),
                                   data={'grant_type': 'client_credentials'})

        c.get_access_token('devices')
        request.assert_called_with('POST',
                                   'http://localhost/oauth2/token',
                                   auth=(c.client, c.secret),
                                   data={
                                       'grant_type': 'client_credentials',
                                       'scope': 'devices'
                                   })
Ejemplo n.º 19
0
 def test_can_create_client(self):
     c = Client(**self.data)
     self.assertEqual(c.host, 'http://localhost')
     self.assertEqual(c.client, 'client')
     self.assertEqual(c.secret, 'secret')
Ejemplo n.º 20
0
 def test_can_logs_user_out_deleting_session_cookie(self, request):
     c = Client(**self.data)
     c.logs_user_out_deleting_session_cookie()
     request.assert_called_once_with(
         'GET',
         'http://localhost:4445/oauth2/auth/sessions/login/revoke')
Ejemplo n.º 21
0
 def test_can_create_client(self):
     c = Client(**self.data)
     self.assertEqual(c.publichost, 'http://localhost:4444')
     self.assertEqual(c.adminhost, 'http://localhost:4445')
     self.assertEqual(c.client, 'client')
     self.assertEqual(c.secret, 'secret')