Skip to content

Commit

Permalink
testing: delete internal copy of test service proto, and use canonica…
Browse files Browse the repository at this point in the history
…l one (grpc#6164)
  • Loading branch information
easwars authored Apr 6, 2023
1 parent 10401b9 commit bfb57b8
Show file tree
Hide file tree
Showing 68 changed files with 2,621 additions and 2,136 deletions.
72 changes: 37 additions & 35 deletions authz/grpc_authz_end2end_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,25 @@ import (
"google.golang.org/grpc/internal/grpctest"
"google.golang.org/grpc/metadata"
"google.golang.org/grpc/status"
pb "google.golang.org/grpc/test/grpc_testing"
"google.golang.org/grpc/testdata"

testgrpc "google.golang.org/grpc/interop/grpc_testing"
testpb "google.golang.org/grpc/interop/grpc_testing"
)

type testServer struct {
pb.UnimplementedTestServiceServer
testgrpc.UnimplementedTestServiceServer
}

func (s *testServer) UnaryCall(ctx context.Context, req *pb.SimpleRequest) (*pb.SimpleResponse, error) {
return &pb.SimpleResponse{}, nil
func (s *testServer) UnaryCall(ctx context.Context, req *testpb.SimpleRequest) (*testpb.SimpleResponse, error) {
return &testpb.SimpleResponse{}, nil
}

func (s *testServer) StreamingInputCall(stream pb.TestService_StreamingInputCallServer) error {
func (s *testServer) StreamingInputCall(stream testgrpc.TestService_StreamingInputCallServer) error {
for {
_, err := stream.Recv()
if err == io.EOF {
return stream.SendAndClose(&pb.StreamingInputCallResponse{})
return stream.SendAndClose(&testpb.StreamingInputCallResponse{})
}
if err != nil {
return err
Expand Down Expand Up @@ -315,7 +317,7 @@ func (s) TestStaticPolicyEnd2End(t *testing.T) {
grpc.ChainUnaryInterceptor(i.UnaryInterceptor),
grpc.ChainStreamInterceptor(i.StreamInterceptor))
defer s.Stop()
pb.RegisterTestServiceServer(s, &testServer{})
testgrpc.RegisterTestServiceServer(s, &testServer{})

lis, err := net.Listen("tcp", "localhost:0")
if err != nil {
Expand All @@ -329,14 +331,14 @@ func (s) TestStaticPolicyEnd2End(t *testing.T) {
t.Fatalf("grpc.Dial(%v) failed: %v", lis.Addr().String(), err)
}
defer clientConn.Close()
client := pb.NewTestServiceClient(clientConn)
client := testgrpc.NewTestServiceClient(clientConn)

ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
ctx = metadata.NewOutgoingContext(ctx, test.md)

// Verifying authorization decision for Unary RPC.
_, err = client.UnaryCall(ctx, &pb.SimpleRequest{})
_, err = client.UnaryCall(ctx, &testpb.SimpleRequest{})
if got := status.Convert(err); got.Code() != test.wantStatus.Code() || got.Message() != test.wantStatus.Message() {
t.Fatalf("[UnaryCall] error want:{%v} got:{%v}", test.wantStatus.Err(), got.Err())
}
Expand All @@ -346,8 +348,8 @@ func (s) TestStaticPolicyEnd2End(t *testing.T) {
if err != nil {
t.Fatalf("failed StreamingInputCall err: %v", err)
}
req := &pb.StreamingInputCallRequest{
Payload: &pb.Payload{
req := &testpb.StreamingInputCallRequest{
Payload: &testpb.Payload{
Body: []byte("hi"),
},
}
Expand Down Expand Up @@ -385,7 +387,7 @@ func (s) TestAllowsRPCRequestWithPrincipalsFieldOnTLSAuthenticatedConnection(t *
grpc.Creds(creds),
grpc.ChainUnaryInterceptor(i.UnaryInterceptor))
defer s.Stop()
pb.RegisterTestServiceServer(s, &testServer{})
testgrpc.RegisterTestServiceServer(s, &testServer{})

lis, err := net.Listen("tcp", "localhost:0")
if err != nil {
Expand All @@ -403,13 +405,13 @@ func (s) TestAllowsRPCRequestWithPrincipalsFieldOnTLSAuthenticatedConnection(t *
t.Fatalf("grpc.Dial(%v) failed: %v", lis.Addr().String(), err)
}
defer clientConn.Close()
client := pb.NewTestServiceClient(clientConn)
client := testgrpc.NewTestServiceClient(clientConn)

ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()

// Verifying authorization decision.
if _, err = client.UnaryCall(ctx, &pb.SimpleRequest{}); err != nil {
if _, err = client.UnaryCall(ctx, &testpb.SimpleRequest{}); err != nil {
t.Fatalf("client.UnaryCall(_, _) = %v; want nil", err)
}
}
Expand Down Expand Up @@ -450,7 +452,7 @@ func (s) TestAllowsRPCRequestWithPrincipalsFieldOnMTLSAuthenticatedConnection(t
grpc.Creds(creds),
grpc.ChainUnaryInterceptor(i.UnaryInterceptor))
defer s.Stop()
pb.RegisterTestServiceServer(s, &testServer{})
testgrpc.RegisterTestServiceServer(s, &testServer{})

lis, err := net.Listen("tcp", "localhost:0")
if err != nil {
Expand Down Expand Up @@ -481,13 +483,13 @@ func (s) TestAllowsRPCRequestWithPrincipalsFieldOnMTLSAuthenticatedConnection(t
t.Fatalf("grpc.Dial(%v) failed: %v", lis.Addr().String(), err)
}
defer clientConn.Close()
client := pb.NewTestServiceClient(clientConn)
client := testgrpc.NewTestServiceClient(clientConn)

ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()

// Verifying authorization decision.
if _, err = client.UnaryCall(ctx, &pb.SimpleRequest{}); err != nil {
if _, err = client.UnaryCall(ctx, &testpb.SimpleRequest{}); err != nil {
t.Fatalf("client.UnaryCall(_, _) = %v; want nil", err)
}
}
Expand All @@ -504,7 +506,7 @@ func (s) TestFileWatcherEnd2End(t *testing.T) {
grpc.ChainUnaryInterceptor(i.UnaryInterceptor),
grpc.ChainStreamInterceptor(i.StreamInterceptor))
defer s.Stop()
pb.RegisterTestServiceServer(s, &testServer{})
testgrpc.RegisterTestServiceServer(s, &testServer{})

lis, err := net.Listen("tcp", "localhost:0")
if err != nil {
Expand All @@ -519,14 +521,14 @@ func (s) TestFileWatcherEnd2End(t *testing.T) {
t.Fatalf("grpc.Dial(%v) failed: %v", lis.Addr().String(), err)
}
defer clientConn.Close()
client := pb.NewTestServiceClient(clientConn)
client := testgrpc.NewTestServiceClient(clientConn)

ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
ctx = metadata.NewOutgoingContext(ctx, test.md)

// Verifying authorization decision for Unary RPC.
_, err = client.UnaryCall(ctx, &pb.SimpleRequest{})
_, err = client.UnaryCall(ctx, &testpb.SimpleRequest{})
if got := status.Convert(err); got.Code() != test.wantStatus.Code() || got.Message() != test.wantStatus.Message() {
t.Fatalf("[UnaryCall] error want:{%v} got:{%v}", test.wantStatus.Err(), got.Err())
}
Expand All @@ -536,8 +538,8 @@ func (s) TestFileWatcherEnd2End(t *testing.T) {
if err != nil {
t.Fatalf("failed StreamingInputCall err: %v", err)
}
req := &pb.StreamingInputCallRequest{
Payload: &pb.Payload{
req := &testpb.StreamingInputCallRequest{
Payload: &testpb.Payload{
Body: []byte("hi"),
},
}
Expand All @@ -552,9 +554,9 @@ func (s) TestFileWatcherEnd2End(t *testing.T) {
}
}

func retryUntil(ctx context.Context, tsc pb.TestServiceClient, want *status.Status) (lastErr error) {
func retryUntil(ctx context.Context, tsc testgrpc.TestServiceClient, want *status.Status) (lastErr error) {
for ctx.Err() == nil {
_, lastErr = tsc.UnaryCall(ctx, &pb.SimpleRequest{})
_, lastErr = tsc.UnaryCall(ctx, &testpb.SimpleRequest{})
if s := status.Convert(lastErr); s.Code() == want.Code() && s.Message() == want.Message() {
return nil
}
Expand All @@ -573,7 +575,7 @@ func (s) TestFileWatcher_ValidPolicyRefresh(t *testing.T) {
s := grpc.NewServer(
grpc.ChainUnaryInterceptor(i.UnaryInterceptor))
defer s.Stop()
pb.RegisterTestServiceServer(s, &testServer{})
testgrpc.RegisterTestServiceServer(s, &testServer{})

lis, err := net.Listen("tcp", "localhost:0")
if err != nil {
Expand All @@ -588,13 +590,13 @@ func (s) TestFileWatcher_ValidPolicyRefresh(t *testing.T) {
t.Fatalf("grpc.Dial(%v) failed: %v", lis.Addr().String(), err)
}
defer clientConn.Close()
client := pb.NewTestServiceClient(clientConn)
client := testgrpc.NewTestServiceClient(clientConn)

ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()

// Verifying authorization decision.
_, err = client.UnaryCall(ctx, &pb.SimpleRequest{})
_, err = client.UnaryCall(ctx, &testpb.SimpleRequest{})
if got := status.Convert(err); got.Code() != valid1.wantStatus.Code() || got.Message() != valid1.wantStatus.Message() {
t.Fatalf("client.UnaryCall(_, _) = %v; want = %v", got.Err(), valid1.wantStatus.Err())
}
Expand All @@ -621,7 +623,7 @@ func (s) TestFileWatcher_InvalidPolicySkipReload(t *testing.T) {
s := grpc.NewServer(
grpc.ChainUnaryInterceptor(i.UnaryInterceptor))
defer s.Stop()
pb.RegisterTestServiceServer(s, &testServer{})
testgrpc.RegisterTestServiceServer(s, &testServer{})

lis, err := net.Listen("tcp", "localhost:0")
if err != nil {
Expand All @@ -636,13 +638,13 @@ func (s) TestFileWatcher_InvalidPolicySkipReload(t *testing.T) {
t.Fatalf("grpc.Dial(%v) failed: %v", lis.Addr().String(), err)
}
defer clientConn.Close()
client := pb.NewTestServiceClient(clientConn)
client := testgrpc.NewTestServiceClient(clientConn)

ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()

// Verifying authorization decision.
_, err = client.UnaryCall(ctx, &pb.SimpleRequest{})
_, err = client.UnaryCall(ctx, &testpb.SimpleRequest{})
if got := status.Convert(err); got.Code() != valid.wantStatus.Code() || got.Message() != valid.wantStatus.Message() {
t.Fatalf("client.UnaryCall(_, _) = %v; want = %v", got.Err(), valid.wantStatus.Err())
}
Expand All @@ -656,7 +658,7 @@ func (s) TestFileWatcher_InvalidPolicySkipReload(t *testing.T) {
time.Sleep(40 * time.Millisecond)

// Verifying authorization decision.
_, err = client.UnaryCall(ctx, &pb.SimpleRequest{})
_, err = client.UnaryCall(ctx, &testpb.SimpleRequest{})
if got := status.Convert(err); got.Code() != valid.wantStatus.Code() || got.Message() != valid.wantStatus.Message() {
t.Fatalf("client.UnaryCall(_, _) = %v; want = %v", got.Err(), valid.wantStatus.Err())
}
Expand All @@ -672,7 +674,7 @@ func (s) TestFileWatcher_RecoversFromReloadFailure(t *testing.T) {
s := grpc.NewServer(
grpc.ChainUnaryInterceptor(i.UnaryInterceptor))
defer s.Stop()
pb.RegisterTestServiceServer(s, &testServer{})
testgrpc.RegisterTestServiceServer(s, &testServer{})

lis, err := net.Listen("tcp", "localhost:0")
if err != nil {
Expand All @@ -687,13 +689,13 @@ func (s) TestFileWatcher_RecoversFromReloadFailure(t *testing.T) {
t.Fatalf("grpc.Dial(%v) failed: %v", lis.Addr().String(), err)
}
defer clientConn.Close()
client := pb.NewTestServiceClient(clientConn)
client := testgrpc.NewTestServiceClient(clientConn)

ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()

// Verifying authorization decision.
_, err = client.UnaryCall(ctx, &pb.SimpleRequest{})
_, err = client.UnaryCall(ctx, &testpb.SimpleRequest{})
if got := status.Convert(err); got.Code() != valid1.wantStatus.Code() || got.Message() != valid1.wantStatus.Message() {
t.Fatalf("client.UnaryCall(_, _) = %v; want = %v", got.Err(), valid1.wantStatus.Err())
}
Expand All @@ -707,7 +709,7 @@ func (s) TestFileWatcher_RecoversFromReloadFailure(t *testing.T) {
time.Sleep(120 * time.Millisecond)

// Verifying authorization decision.
_, err = client.UnaryCall(ctx, &pb.SimpleRequest{})
_, err = client.UnaryCall(ctx, &testpb.SimpleRequest{})
if got := status.Convert(err); got.Code() != valid1.wantStatus.Code() || got.Message() != valid1.wantStatus.Message() {
t.Fatalf("client.UnaryCall(_, _) = %v; want = %v", got.Err(), valid1.wantStatus.Err())
}
Expand Down
Loading

0 comments on commit bfb57b8

Please sign in to comment.