1
1
package com.github.pgutkowski.kgraphql.access
2
2
3
- import com.github.pgutkowski.kgraphql.context
4
- import com.github.pgutkowski.kgraphql.defaultSchema
5
- import com.github.pgutkowski.kgraphql.deserialize
6
- import com.github.pgutkowski.kgraphql.expect
7
- import com.github.pgutkowski.kgraphql.extract
3
+ import com.github.pgutkowski.kgraphql.*
8
4
import org.hamcrest.CoreMatchers.equalTo
9
5
import org.hamcrest.MatcherAssert.assertThat
10
6
import org.junit.Test
@@ -24,10 +20,16 @@ class AccessRulesTest {
24
20
}
25
21
26
22
type<Player >{
23
+ val accessRuleBlock = { player: Player , _: Context ->
24
+ if (player.name != " BONNER" ) IllegalAccessException (" ILLEGAL ACCESS" ) else null
25
+ }
26
+
27
27
property(Player ::id){
28
- accessRule { player, _ ->
29
- if (player.name != " BONNER" ) IllegalAccessException (" ILLEGAL ACCESS" ) else null
30
- }
28
+ accessRule(accessRuleBlock)
29
+ }
30
+ property<String >(" item" ) {
31
+ accessRule(accessRuleBlock)
32
+ resolver { " item" }
31
33
}
32
34
}
33
35
}
@@ -44,13 +46,28 @@ class AccessRulesTest {
44
46
45
47
@Test
46
48
fun `reject when not matching` (){
47
- expect<IllegalAccessException > {
49
+ expect<IllegalAccessException >( " " ) {
48
50
deserialize (
49
51
schema.execute(" { black_mamba {id} }" , context { + " LAKERS" })
50
52
).extract<String >(" data/black_mamba/id" )
51
53
}
52
54
}
53
55
56
+ @Test
57
+ fun `allow property resolver access rule` () {
58
+ assertThat(
59
+ deserialize(schema.execute(" {white_mamba {item}}" )).extract<String >(" data/white_mamba/item" ),
60
+ equalTo(" item" )
61
+ )
62
+ }
63
+
64
+ @Test
65
+ fun `reject property resolver access rule` () {
66
+ expect<IllegalAccessException >(" ILLEGAL ACCESS" ) {
67
+ schema.execute(" {black_mamba {item}}" , context { + " LAKERS" })
68
+ }
69
+ }
70
+
54
71
// TODO: MORE TESTS
55
72
56
73
}
0 commit comments