예제 #1
0
파일: auth_test.py 프로젝트: hypothesis/h
    def test_it_raises_error_when_token_is_empty(self, pyramid_request):
        pyramid_request.auth_token = ""

        with pytest.raises(OAuthTokenError) as exc:
            views.debug_token(pyramid_request)

        assert exc.value.type == "missing_token"
        assert "Bearer token is missing" in str(exc.value)
예제 #2
0
파일: auth_test.py 프로젝트: hypothesis/h
    def test_it_raises_error_when_token_is_invalid(
        self, pyramid_request, token_service
    ):
        pyramid_request.auth_token = "the-token"
        token_service.validate.return_value = None

        with pytest.raises(OAuthTokenError) as exc:
            views.debug_token(pyramid_request)

        assert exc.value.type == "missing_token"
        assert "Bearer token does not exist or is expired" in str(exc.value)
예제 #3
0
파일: auth_test.py 프로젝트: hypothesis/h
    def test_returns_debug_data_for_developer_token(
        self, pyramid_request, token_service, developer_token
    ):
        pyramid_request.auth_token = developer_token.value
        token_service.fetch.return_value = developer_token

        result = views.debug_token(pyramid_request)

        assert result == {
            "userid": developer_token.userid,
            "issued_at": utc_iso8601(developer_token.created),
            "expires_at": None,
            "expired": False,
        }
예제 #4
0
파일: auth_test.py 프로젝트: hypothesis/h
    def test_returns_debug_data_for_oauth_token(
        self, pyramid_request, token_service, oauth_token
    ):
        pyramid_request.auth_token = oauth_token.value
        token_service.fetch.return_value = oauth_token

        result = views.debug_token(pyramid_request)

        assert result == {
            "userid": oauth_token.userid,
            "client": {
                "id": oauth_token.authclient.id,
                "name": oauth_token.authclient.name,
            },
            "issued_at": utc_iso8601(oauth_token.created),
            "expires_at": utc_iso8601(oauth_token.expires),
            "expired": oauth_token.expired,
        }
예제 #5
0
파일: auth_test.py 프로젝트: kaydoh/h
    def test_it(self, pyramid_request, auth_token_service, oauth_token):
        result = views.debug_token(pyramid_request)

        auth_token_service.get_bearer_token.assert_called_once_with(
            pyramid_request)
        token_string = auth_token_service.get_bearer_token.return_value
        auth_token_service.validate.assert_called_once_with(token_string)
        auth_token_service.fetch.assert_called_once_with(token_string)

        assert result == {
            "client": {
                "id": oauth_token.authclient.id,
                "name": oauth_token.authclient.name,
            },
            "expired": oauth_token.expired,
            "expires_at": "2001-11-30T17:45:50.000000+00:00",
            "issued_at": "2000-10-16T15:51:59.000000+00:00",
            "userid": oauth_token.userid,
        }
예제 #6
0
    def test_it_validates_token(self, pyramid_request, token_service):
        pyramid_request.auth_token = "the-access-token"

        views.debug_token(pyramid_request)

        token_service.validate.assert_called_once_with("the-access-token")
예제 #7
0
파일: auth_test.py 프로젝트: kaydoh/h
    def test_it_with_invalid_token_string(self, pyramid_request,
                                          auth_token_service):
        auth_token_service.validate.return_value = None

        with pytest.raises(OAuthTokenError):
            views.debug_token(pyramid_request)
예제 #8
0
파일: auth_test.py 프로젝트: kaydoh/h
    def test_it_without_token_string(self, pyramid_request,
                                     auth_token_service):
        auth_token_service.get_bearer_token.return_value = None

        with pytest.raises(OAuthTokenError):
            views.debug_token(pyramid_request)
예제 #9
0
파일: auth_test.py 프로젝트: kaydoh/h
    def test_it_without_auth_client(self, pyramid_request, oauth_token):
        oauth_token.authclient = None

        result = views.debug_token(pyramid_request)

        assert "client" not in result
예제 #10
0
파일: auth_test.py 프로젝트: hypothesis/h
    def test_it_validates_token(self, pyramid_request, token_service):
        pyramid_request.auth_token = "the-access-token"

        views.debug_token(pyramid_request)

        token_service.validate.assert_called_once_with("the-access-token")