summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormo khan <mo@mokhan.ca>2025-07-11 14:37:14 -0600
committermo khan <mo@mokhan.ca>2025-07-11 14:37:14 -0600
commita8d2fb21c72dddf4589cca45594fbcd6bed3f273 (patch)
tree3c364b005edafc23bba05a7ce107ba4863c5cc53
parent67e0ccd1ad69d97b5f36b6f038feac5b8f7861ef (diff)
test: add test for remote check service client
-rw-r--r--pkg/authz/remote_check_service_test.go48
1 files changed, 48 insertions, 0 deletions
diff --git a/pkg/authz/remote_check_service_test.go b/pkg/authz/remote_check_service_test.go
index d06dab0..338625f 100644
--- a/pkg/authz/remote_check_service_test.go
+++ b/pkg/authz/remote_check_service_test.go
@@ -1,10 +1,17 @@
package authz
import (
+ "context"
+ "net"
"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"
+ "google.golang.org/grpc/codes"
+ "google.golang.org/grpc/credentials/insecure"
+ "google.golang.org/grpc/test/bufconn"
)
func TestRemoteCheckService(t *testing.T) {
@@ -17,5 +24,46 @@ func TestRemoteCheckService(t *testing.T) {
require.Nil(t, result)
require.Error(t, err)
})
+
+ t.Run("when a client is configured", func(t *testing.T) {
+ socket := bufconn.Listen(1024 * 1024)
+ srv := grpc.NewServer()
+ auth.RegisterAuthorizationServer(srv, NewLocalCheckService())
+
+ defer srv.GracefulStop()
+ go func() {
+ require.NoError(t, srv.Serve(socket))
+ }()
+
+ connection, err := grpc.DialContext(
+ t.Context(),
+ "bufnet",
+ grpc.WithContextDialer(func(context.Context, string) (net.Conn, error) {
+ return socket.Dial()
+ }),
+ grpc.WithTransportCredentials(insecure.NewCredentials()),
+ )
+ require.NoError(t, err)
+ defer connection.Close()
+
+ t.Run("returns a response from the client", func(t *testing.T) {
+ client := auth.NewAuthorizationClient(connection)
+ svc := NewRemoteCheckService(client)
+
+ response, err := svc.Check(t.Context(), &auth.CheckRequest{
+ Attributes: &auth.AttributeContext{
+ Request: &auth.AttributeContext_Request{
+ Http: &auth.AttributeContext_HttpRequest{
+ Method: "GET",
+ Path: "/",
+ },
+ },
+ },
+ })
+
+ require.NoError(t, err)
+ assert.Equal(t, int32(codes.OK), response.Status.Code)
+ })
+ })
})
}