1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
package authz
import (
"testing"
auth "github.com/envoyproxy/go-control-plane/envoy/service/auth/v3"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"google.golang.org/grpc/codes"
)
func TestCompositeCheckService(t *testing.T) {
t.Run("without any services", func(t *testing.T) {
svc := NewCheckService([]auth.AuthorizationServer{})
response, err := svc.Check(t.Context(), &auth.CheckRequest{})
require.Error(t, err)
require.Nil(t, response)
})
t.Run("with a single service", func(t *testing.T) {
svc := NewCheckService([]auth.AuthorizationServer{
NewLocalCheckService(),
})
response, err := svc.Check(t.Context(), &auth.CheckRequest{})
require.NoError(t, err)
assert.Equal(t, int32(codes.PermissionDenied), response.Status.Code)
})
t.Run("with a multiple services", func(t *testing.T) {
svc := NewCheckService([]auth.AuthorizationServer{
NewRemoteCheckService(nil),
NewLocalCheckService(),
})
response, err := svc.Check(t.Context(), &auth.CheckRequest{})
require.NoError(t, err)
assert.Equal(t, int32(codes.PermissionDenied), response.Status.Code)
})
t.Run("with a multiple failing services", func(t *testing.T) {
svc := NewCheckService([]auth.AuthorizationServer{
NewRemoteCheckService(nil),
NewRemoteCheckService(nil),
})
response, err := svc.Check(t.Context(), &auth.CheckRequest{})
require.Error(t, err)
require.Nil(t, response)
})
}
|