pomerium/pkg/policy/criteria/authenticated_user_test.go
Caleb Doxsey efffe57bf0
ppl: pass contextual information through policy (#2612)
* ppl: pass contextual information through policy

* maybe fix nginx

* fix nginx

* pr comments

* go mod tidy
2021-09-20 16:02:26 -06:00

39 lines
921 B
Go

package criteria
import (
"testing"
"github.com/stretchr/testify/require"
"github.com/pomerium/pomerium/pkg/grpc/session"
)
func TestAuthenticatedUser(t *testing.T) {
t.Run("no session", func(t *testing.T) {
res, err := evaluate(t, `
allow:
and:
- authenticated_user: 1
`, []dataBrokerRecord{}, Input{Session: InputSession{ID: "SESSION_ID"}})
require.NoError(t, err)
require.Equal(t, A{false, A{ReasonUserUnauthenticated}}, res["allow"])
require.Equal(t, A{false, A{}}, res["deny"])
})
t.Run("by domain", func(t *testing.T) {
res, err := evaluate(t, `
allow:
and:
- authenticated_user: 1
`,
[]dataBrokerRecord{
&session.Session{
Id: "SESSION_ID",
UserId: "USER_ID",
},
},
Input{Session: InputSession{ID: "SESSION_ID"}})
require.NoError(t, err)
require.Equal(t, A{true, A{ReasonUserOK}}, res["allow"])
require.Equal(t, A{false, A{}}, res["deny"])
})
}