@@ -37,6 +37,16 @@ class PolicyEngineTest : Assert() {
3737 println (allowed)
3838 }
3939
40+ @Test
41+ fun testIsActionAllowedFalse () {
42+ val claims = Claims (mapOf (" sub" to " userid" , " roles" to listOf (" admin" ), " exp" to Date (),
43+ " features" to listOf (" maintenance" )))
44+ val environment = Environment (emptyMap())
45+ val resource = " em2m:ident:account:1234"
46+ val isActionAllowed = policyEngine.isActionAllowed(" ident:DeleteAccount" , PolicyContext (claims, environment, resource))
47+ assertFalse(isActionAllowed)
48+ }
49+
4050 @Test
4151 @Ignore
4252 fun testAllowIfFeature () {
@@ -85,9 +95,23 @@ class PolicyEngineTest : Assert() {
8595 }
8696
8797 @Test
88- @Ignore
8998 fun testDeny () {
90- error(" Not implemented" )
99+ val claims = Claims (mapOf (" sub" to " 1234" , " roles" to listOf (" sales" ), " exp" to Date ()))
100+ val environment = Environment (emptyMap())
101+ val resource = " em2m:ident:account:1234"
102+ val context = PolicyContext (claims, environment, resource)
103+ val allowed = policyEngine.isActionAllowed(" ident:ChangeMyPassword" , context)
104+ assertFalse(allowed)
105+ }
106+
107+ @Test
108+ fun testAllowedActionsFiltering () {
109+ val claims = Claims (mapOf (" sub" to " 1234" , " roles" to listOf (" sales" ), " exp" to Date ()))
110+ val environment = Environment (emptyMap())
111+ val resource = " em2m:ident:account:1234"
112+ val context = PolicyContext (claims, environment, resource)
113+ val allowedActions = policyEngine.findAllowedActions(context)
114+ assertFalse(" ident:ChangeMyPassword" in allowedActions)
91115 }
92116
93117 class ReportTypeKey : KeyHandlerSupport () {
@@ -111,4 +135,4 @@ class PolicyEngineTest : Assert() {
111135 }
112136 }
113137
114- }
138+ }
0 commit comments