def verify_client(self, environ, areq, authn_method, client_id=""): """ :param environ: WSGI environ :param areq: The request :param authn_method: client authentication method :return: """ if not client_id: client_id = get_client_id(self.cdb, areq, environ["HTTP_AUTHORIZATION"]) try: method = self.client_authn_methods[authn_method] except KeyError: raise UnSupported() return method(self).verify(environ, client_id=client_id)
def verify_client(self, environ, areq, authn_method, client_id=""): """ Verify the client based on credentials. :param environ: WSGI environ :param areq: The request :param authn_method: client authentication method :return: """ if not client_id: client_id = get_client_id(self.cdb, areq, environ["HTTP_AUTHORIZATION"]) try: method = self.client_authn_methods[authn_method] except KeyError: raise UnSupported() return method(self).verify(environ, client_id=client_id)
def test_basic_authn_client_invalid(self): authn = "Basic " + b64encode(b"expired:drickyoughurt").decode() with pytest.raises(FailedAuthentication): get_client_id(self.cdb, AuthorizationRequest(), authn)
def test_basic_authn_client_ok(self): authn = "Basic " + b64encode(b"number5:drickyoughurt").decode() assert get_client_id(self.cdb, AuthorizationRequest(), authn)
def test_basic_authn_client_wrongpass(self): authn = "Basic " + b64encode(b"number5:wrongpassword").decode() with pytest.raises(FailedAuthentication): get_client_id(self.cdb, AuthorizationRequest(), authn)
def test_empty_authn_client_invalid(self): bib = {"client_id": "expired"} arq = AuthorizationRequest(**bib) with pytest.raises(FailedAuthentication): get_client_id(self.cdb, arq, None)
def test_wrong_authn(self): with pytest.raises(FailedAuthentication): get_client_id(self.cdb, AuthorizationRequest(), "mumbo jumbo")
def test_wrong_authn(self): with pytest.raises(FailedAuthentication): get_client_id(self.cdb, AuthorizationRequest(), 'mumbo jumbo')
def test_empty_authn_empty_request(self): with pytest.raises(FailedAuthentication): get_client_id(self.cdb, AuthorizationRequest(), None)
def test_bearer_authn_client_invalid(self): authn = 'Bearer expired_token' with pytest.raises(FailedAuthentication): get_client_id(self.cdb, AuthorizationRequest(), authn)
def test_bearer_authn_client_invalid(self): authn = "Bearer expired_token" with pytest.raises(FailedAuthentication): get_client_id(self.cdb, AuthorizationRequest(), authn)
def test_bearer_authn_client_ok(self): authn = 'Bearer secret_token' assert get_client_id(self.cdb, AuthorizationRequest(), authn) == 'token_client'
def test_bearer_authn_client_missing(self): authn = 'Bearer wrong_token' with pytest.raises(FailedAuthentication): get_client_id(self.cdb, AuthorizationRequest(), authn)
def test_basic_authn_client_invalid(self): authn = 'Basic ' + b64encode(b'expired:drickyoughurt').decode() with pytest.raises(FailedAuthentication): get_client_id(self.cdb, AuthorizationRequest(), authn)
def test_basic_authn_client_wrongpass(self): authn = 'Basic ' + b64encode(b'number5:wrongpassword').decode() with pytest.raises(FailedAuthentication): get_client_id(self.cdb, AuthorizationRequest(), authn)
def test_basic_authn_client_ok(self): authn = 'Basic ' + b64encode(b'number5:drickyoughurt').decode() assert get_client_id(self.cdb, AuthorizationRequest(), authn)
def test_bearer_authn_client_ok(self): authn = "Bearer secret_token" assert get_client_id(self.cdb, AuthorizationRequest(), authn) == "token_client"
def test_empty_authn_empty_request(self): with pytest.raises(FailedAuthentication): get_client_id(self.cdb, AuthorizationRequest(), None)
def test_bearer_authn_client_missing(self): authn = "Bearer wrong_token" with pytest.raises(FailedAuthentication): get_client_id(self.cdb, AuthorizationRequest(), authn)
def test_empty_authn_client_invalid(self): bib = {'client_id': 'expired'} arq = AuthorizationRequest(**bib) with pytest.raises(FailedAuthentication): get_client_id(self.cdb, arq, None)
def test_empty_authn_client_ok(self): bib = {"client_id": "number5"} arq = AuthorizationRequest(**bib) assert get_client_id(self.cdb, arq, None) == "number5"
def test_empty_authn_client_ok(self): bib = {'client_id': 'number5'} arq = AuthorizationRequest(**bib) assert get_client_id(self.cdb, arq, None) == 'number5'