mirror of
https://github.com/pomerium/pomerium.git
synced 2025-06-24 13:38:17 +02:00
config: add support for embedded PPL policy (#2401)
This commit is contained in:
parent
c34118360d
commit
0620cfdc50
8 changed files with 152 additions and 9 deletions
|
@ -10,6 +10,8 @@ import (
|
|||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"gopkg.in/yaml.v3"
|
||||
|
||||
"github.com/pomerium/pomerium/pkg/policy/parser"
|
||||
)
|
||||
|
||||
func TestJWTClaimHeaders_UnmarshalJSON(t *testing.T) {
|
||||
|
@ -190,3 +192,39 @@ func TestWeightedStringSlice(t *testing.T) {
|
|||
assert.Equal(t, tc.Weights, weights, name)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDecodePPLPolicyHookFunc(t *testing.T) {
|
||||
var withPolicy struct {
|
||||
Policy *PPLPolicy `mapstructure:"policy"`
|
||||
}
|
||||
decoder, err := mapstructure.NewDecoder(&mapstructure.DecoderConfig{
|
||||
DecodeHook: decodePPLPolicyHookFunc(),
|
||||
Result: &withPolicy,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
err = decoder.Decode(map[string]interface{}{
|
||||
"policy": map[string]interface{}{
|
||||
"allow": map[string]interface{}{
|
||||
"or": []map[string]interface{}{
|
||||
{"email": map[string]interface{}{
|
||||
"is": "user1@example.com",
|
||||
}},
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, &PPLPolicy{
|
||||
Policy: &parser.Policy{
|
||||
Rules: []parser.Rule{{
|
||||
Action: parser.ActionAllow,
|
||||
Or: []parser.Criterion{{
|
||||
Name: "email", Data: parser.Object{
|
||||
"is": parser.String("user1@example.com"),
|
||||
},
|
||||
}},
|
||||
}},
|
||||
},
|
||||
}, withPolicy.Policy)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue