@@ -29,6 +29,12 @@ it_is := true`,
2929 token : `package token
3030import rego.v1
3131p := true
32+ ` ,
33+ main : `package system.main
34+ import rego.v1
35+
36+ main.has_input if input
37+ main.different_input if input.foo == "bar"
3238` ,
3339 } ;
3440 const authzPolicy = `package system.authz
@@ -39,6 +45,7 @@ allow if input.method == "PUT"
3945allow if input.path[0] == "health"
4046allow if input.path[2] == "test"
4147allow if input.path[2] == "has"
48+ allow if count(input.path) == 1 # default policy
4249allow if {
4350 input.path[2] = "token"
4451 input.identity = "opensesame"
@@ -56,6 +63,7 @@ allow if {
5663 "--log-level=debug" ,
5764 "--authentication=token" ,
5865 "--authorization=basic" ,
66+ "--set=default_decision=system/main/main" ,
5967 "/authz.rego" ,
6068 ] )
6169 . withExposedPorts ( 8181 )
@@ -92,6 +100,18 @@ allow if {
92100 assert . strictEqual ( res , true ) ;
93101 } ) ;
94102
103+ it ( "default can be called without types, without input" , async ( ) => {
104+ const res = await new OPAClient ( serverURL ) . evaluateDefault ( ) ;
105+ assert . deepStrictEqual ( res , { has_input : true } ) ;
106+ } ) ;
107+
108+ it ( "default can be called with input" , async ( ) => {
109+ const res = await new OPAClient ( serverURL ) . evaluateDefault ( {
110+ foo : "bar" ,
111+ } ) ;
112+ assert . deepStrictEqual ( res , { has_input : true , different_input : true } ) ;
113+ } ) ;
114+
95115 it ( "supports rules with slashes" , async ( ) => {
96116 const res = await new OPAClient ( serverURL ) . evaluate (
97117 "has/weird%2fpackage/but/it_is" ,
0 commit comments