Skip to content

Commit

Permalink
Tests tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
queil committed Jun 13, 2022
1 parent 8de3562 commit bdf12c3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,18 @@ public class Claims

public class AuthorizationTestData : IEnumerable<object[]>
{
private readonly string SchemaCode = @"
type Query {
private readonly string SchemaCode = $@"
type Query {{
default: String @authorize
age: String @authorize(policy: ""graphql/authz/has_age_defined"")
age: String @authorize(policy: ""{Policies.HasDefinedAge}"")
roles: String @authorize(roles: [""a""])
roles_ab: String @authorize(roles: [""a"" ""b""])
piped: String
@authorize(policy: ""a"")
@authorize(policy: ""b"")
afterResolver: String
@authorize(policy: ""a"" apply: AFTER_RESOLVER)
}
}}
";

private readonly FieldMiddleware _schemaMiddleware = next => context =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ namespace HotChocolate.AspNetCore.Authorization;

public static class Policies
{
public const string HasDefinedAge = "graphql/authz/has_age_defined";
public const string HasDefinedAge = "graphql/authz/has_age_defined/allow";
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,16 @@ package graphql.authz.has_age_defined

import input.request

default allow = false
default allow = { "allow" : false }

valid_jwt = token {
valid_jwt = [is_valid, claims] {
token := replace(request.headers["Authorization"], "Bearer ", "")
startswith(token, "eyJhbG") # a toy validation
claims := io.jwt.decode(token)[1]
is_valid := startswith(token, "eyJhbG") # a toy validation
is_valid
}

claims = cl {
cl := io.jwt.decode(valid_jwt)[1]
valid_jwt
}

allow {
valid_jwt
allow = {"allow": is_valid, "claims": claims } {
[is_valid, claims] := valid_jwt
claims.birthdate
}

0 comments on commit bdf12c3

Please sign in to comment.