pomerium/pkg/policy/criteria/http_method_test.go
Caleb Doxsey bbed421cd8
config: remove source, remove deadcode, fix linting issues (#4118)
* remove source, remove deadcode, fix linting issues

* use github action for lint

* fix missing envoy
2023-04-21 17:25:11 -06:00

33 lines
806 B
Go

package criteria
import (
"net/http"
"testing"
"github.com/stretchr/testify/require"
)
func TestHTTPMethod(t *testing.T) {
t.Run("ok", func(t *testing.T) {
res, err := evaluate(t, `
allow:
and:
- http_method:
is: GET
`, []dataBrokerRecord{}, Input{HTTP: InputHTTP{Method: http.MethodGet}})
require.NoError(t, err)
require.Equal(t, A{true, A{ReasonHTTPMethodOK}, 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_method:
is: GET
`, []dataBrokerRecord{}, Input{HTTP: InputHTTP{Method: "POST"}})
require.NoError(t, err)
require.Equal(t, A{false, A{ReasonHTTPMethodUnauthorized}, M{}}, res["allow"])
require.Equal(t, A{false, A{}}, res["deny"])
})
}