pomerium/pkg/policy/criteria/http_path_test.go
Caleb Doxsey 2d04106e6d
ppl: add support for http_path and http_method (#2813)
* ppl: add support for http_path and http_method

* fix import ordering
2021-12-10 07:28:51 -07:00

32 lines
782 B
Go

package criteria
import (
"testing"
"github.com/stretchr/testify/require"
)
func TestHTTPPath(t *testing.T) {
t.Run("ok", func(t *testing.T) {
res, err := evaluate(t, `
allow:
and:
- http_path:
is: /test
`, []dataBrokerRecord{}, Input{HTTP: InputHTTP{Path: "/test"}})
require.NoError(t, err)
require.Equal(t, A{true, A{ReasonHTTPPathOK}, M{}}, res["allow"])
require.Equal(t, A{false, A{}}, res["deny"])
})
t.Run("unauthorized", func(t *testing.T) {
res, err := evaluate(t, `
allow:
and:
- http_path:
is: /test
`, []dataBrokerRecord{}, Input{HTTP: InputHTTP{Path: "/not-test"}})
require.NoError(t, err)
require.Equal(t, A{false, A{ReasonHTTPPathUnauthorized}, M{}}, res["allow"])
require.Equal(t, A{false, A{}}, res["deny"])
})
}