Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: handle invalid condition tuple error #1420

Merged
merged 1 commit into from
Mar 4, 2024

Conversation

adriantam
Copy link
Member

@adriantam adriantam commented Mar 4, 2024

Description

Fix HandleTupleValidateError so that it handles invalid condition tuple error bugs.

References

Close #1419

Testing

  1. Add with the following model
model
  schema 1.1

type user

type group
  relations
    define member: [user]
    define can_access: [user with less_than_hundred]
    
condition less_than_hundred(x: int) {
  x < 100
}

Send GET with

{
    "tuple_key": {
        "user": "user:test",
        "relation": "can_access",
        "object": "group:8"
    },
    "contextual_tuples": {
        "tuple_keys": [
            {
                "user": "user:test",
                "relation": "can_access",
                "object": "group:8",
                "condition": {
                    "name": "less_than_hundred",
                    "context": {
                        "x": "b"
                    }
                }
            }
        ]
    }
}

and see 400 Bad Request error with body

{
    "code": "validation_error",
    "message": "Invalid tuple 'group:8#can_access@user:test (condition name:\"less_than_hundred\"  context:{fields:{key:\"x\"  value:{string_value:\"b\"}}})'. Reason: parameter type error on condition 'less_than_hundred' - failed to convert context parameter 'x': expected a int64 value, but found invalid string value 'b'"
}
  1. With the following body
model
  schema 1.1

type user

type group
  relations
    define member: [user with restricted_to_ip]

type application
  relations
    define allowed: [group#member]

condition restricted_to_ip(allowed_ip_address: ipaddress, current_ip_address: ipaddress) {
  current_ip_address == allowed_ip_address
}

Check with body

{
    "tuple_key": {
        "user": "user:some_user",
        "relation": "allowed",
        "object": "application:test_application"
    },
    "contextual_tuples": {
        "tuple_keys": [
            {
                "user": "user:some_user",
                "relation": "member",
                "object": "group:premium"
            }
        ]
    }
}

produces 400 error with error message

{
    "code": "validation_error",
    "message": "Invalid tuple 'group:premium#member@user:some_user (condition <nil>)'. Reason: condition is missing"
}

Review Checklist

  • I have clicked on "allow edits by maintainers".
  • I have added documentation for new/changed functionality in this PR or in a PR to openfga.dev [Provide a link to any relevant PRs in the references section above]
  • The correct base branch is being used, if not main
  • I have added tests to validate that the change in functionality is working as expected

@adriantam adriantam requested a review from a team as a code owner March 4, 2024 20:49
@adriantam adriantam merged commit b8252ce into main Mar 4, 2024
9 of 11 checks passed
@adriantam adriantam deleted the fix/invalid_conditional_tuple_error branch March 4, 2024 21:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

HandleTupleValidateError throw 500 errors when condition is invalid
4 participants