Build a new path policy struct, ased on the new path trie struct. It is designed to be able to store policies for paths. A Check method can then be used to look up the policy for a given path based on the defined policies.
50 lines
995 B
Go
50 lines
995 B
Go
package disk
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestPathPolicyCheck(t *testing.T) {
|
|
assert := assert.New(t)
|
|
|
|
entires := map[string]PathPolicy{
|
|
"/": {Exact: true},
|
|
"/boot": {Exact: true},
|
|
"/boot/efi": {Exact: true},
|
|
"/var": {},
|
|
"/var/empty": {Deny: true},
|
|
"/srv": {},
|
|
"/home": {},
|
|
}
|
|
|
|
policies := NewPathPolicies(entires)
|
|
assert.NotNil(policies)
|
|
|
|
tests := map[string]bool{
|
|
"/": true,
|
|
"/custom": false,
|
|
"/boot": true,
|
|
"/boot/grub2": false,
|
|
"/boot/efi": true,
|
|
"/boot/efi/redora": false,
|
|
"/srv": true,
|
|
"/srv/www": true,
|
|
"/srv/www/data": true,
|
|
"/var": true,
|
|
"/var/log": true,
|
|
"/var/empty": false,
|
|
"/var/empty/dir": false,
|
|
}
|
|
|
|
for k, v := range tests {
|
|
err := policies.Check(k)
|
|
if v {
|
|
assert.NoError(err)
|
|
} else {
|
|
assert.Errorf(err, "unexpected error for path '%s'", k)
|
|
|
|
}
|
|
}
|
|
}
|