Ejemplo n.º 1
0
    def test_sub_claim_verification(self, app, _payload):
        @app.route("/<sub:username>/private-info")
        def private_info(username):
            return "Private information"

        _payload["sub"] = "coyote"

        with app.test_request_context("/elmer/private-info"):
            assert _is_authorized(_payload) is False

        _payload["sub"] = "elmer"

        with app.test_request_context("/elmer/private-info"):
            assert _is_authorized(_payload) is True
Ejemplo n.º 2
0
    def test_aud_claim_verification(self, app, payload, expected):
        @app.route("/<aud:orgname>/private-info")
        def private_info(orgname):
            return "Private information"

        with app.test_request_context("/acme/private-info"):
            assert _is_authorized(payload) is expected
Ejemplo n.º 3
0
    def test_routes_without_required_claim(self, app, _payload):

        # route without any view_args
        @app.route("/private-info")
        def list_private():
            return "Private information"

        # route with view_args
        @app.route("/private-info/<int:id>")
        def get_private(id):
            return "Private information"

        with app.test_request_context("/private-info"):
            assert _is_authorized(_payload) is True

        with app.test_request_context("/private-info/1"):
            assert _is_authorized(_payload) is True
Ejemplo n.º 4
0
    def test_http_method_to_action_mapping(self, app, action, method, expect):
        @app.route("/", methods=[method])
        def private_info():
            return ""

        payload = getpayload(scp={"cartoon": [action]})

        with app.test_request_context("/", method=method):
            assert _is_authorized(payload, "cartoon") is expect
Ejemplo n.º 5
0
    def test_scope_validation(self, app, scope, required, expected):
        @app.route("/")
        def private_info():
            return ""

        payload = getpayload(scp=scope)

        resource = required[0]
        action = required[1]

        with app.test_request_context("/"):
            assert _is_authorized(payload, resource, action) is expected
Ejemplo n.º 6
0
    def test_scope_validation_with_nested_resource(
        self, app, scope, required, expected
    ):

        app.auth._resources = {"puchase": None, "product": {"catalog": None}}

        @app.route("/")
        def private_info():
            return ""

        payload = getpayload(scp=scope)

        resource = required[0]
        action = required[1]

        with app.test_request_context("/"):
            assert _is_authorized(payload, resource, action) is expected