Skip to content

Commit

Permalink
Merge branch 'master' into transportRestart
Browse files Browse the repository at this point in the history
  • Loading branch information
arvindbr8 committed Dec 29, 2022
2 parents cb0717e + 12b8fb5 commit 5dbeec7
Show file tree
Hide file tree
Showing 2 changed files with 260 additions and 152 deletions.
152 changes: 0 additions & 152 deletions test/end2end_test.go
Expand Up @@ -6754,158 +6754,6 @@ func (s) TestRPCWaitsForResolver(t *testing.T) {
}
}

func (s) TestHTTPHeaderFrameErrorHandlingHTTPMode(t *testing.T) {
// Non-gRPC content-type fallback path.
for httpCode := range transport.HTTPStatusConvTab {
if err := doHTTPHeaderTest(t, transport.HTTPStatusConvTab[int(httpCode)], []string{
":status", fmt.Sprintf("%d", httpCode),
"content-type", "text/html", // non-gRPC content type to switch to HTTP mode.
"grpc-status", "1", // Make up a gRPC status error
"grpc-status-details-bin", "???", // Make up a gRPC field parsing error
}); err != nil {
t.Error(err)
}
}

// Missing content-type fallback path.
for httpCode := range transport.HTTPStatusConvTab {
if err := doHTTPHeaderTest(t, transport.HTTPStatusConvTab[int(httpCode)], []string{
":status", fmt.Sprintf("%d", httpCode),
// Omitting content type to switch to HTTP mode.
"grpc-status", "1", // Make up a gRPC status error
"grpc-status-details-bin", "???", // Make up a gRPC field parsing error
}); err != nil {
t.Error(err)
}
}

// Malformed HTTP status when fallback.
if err := doHTTPHeaderTest(t, codes.Internal, []string{
":status", "abc",
// Omitting content type to switch to HTTP mode.
"grpc-status", "1", // Make up a gRPC status error
"grpc-status-details-bin", "???", // Make up a gRPC field parsing error
}); err != nil {
t.Error(err)
}
}

// Testing erroneous ResponseHeader or Trailers-only (delivered in the first HEADERS frame).
func (s) TestHTTPHeaderFrameErrorHandlingInitialHeader(t *testing.T) {
for _, test := range []struct {
header []string
errCode codes.Code
}{
{
// missing gRPC status.
header: []string{
":status", "403",
"content-type", "application/grpc",
},
errCode: codes.PermissionDenied,
},
{
// malformed grpc-status.
header: []string{
":status", "502",
"content-type", "application/grpc",
"grpc-status", "abc",
},
errCode: codes.Internal,
},
{
// Malformed grpc-tags-bin field.
header: []string{
":status", "502",
"content-type", "application/grpc",
"grpc-status", "0",
"grpc-tags-bin", "???",
},
errCode: codes.Unavailable,
},
{
// gRPC status error.
header: []string{
":status", "502",
"content-type", "application/grpc",
"grpc-status", "3",
},
errCode: codes.Unavailable,
},
} {
if err := doHTTPHeaderTest(t, test.errCode, test.header); err != nil {
t.Error(err)
}
}
}

// Testing non-Trailers-only Trailers (delivered in second HEADERS frame)
func (s) TestHTTPHeaderFrameErrorHandlingNormalTrailer(t *testing.T) {
tests := []struct {
name string
responseHeader []string
trailer []string
errCode codes.Code
}{
{
name: "trailer missing grpc-status",
responseHeader: []string{
":status", "200",
"content-type", "application/grpc",
},
trailer: []string{
// trailer missing grpc-status
":status", "502",
},
errCode: codes.Unavailable,
},
{
name: "malformed grpc-status-details-bin field with status 404",
responseHeader: []string{
":status", "404",
"content-type", "application/grpc",
},
trailer: []string{
// malformed grpc-status-details-bin field
"grpc-status", "0",
"grpc-status-details-bin", "????",
},
errCode: codes.Unimplemented,
},
{
name: "malformed grpc-status-details-bin field with status 200",
responseHeader: []string{
":status", "200",
"content-type", "application/grpc",
},
trailer: []string{
// malformed grpc-status-details-bin field
"grpc-status", "0",
"grpc-status-details-bin", "????",
},
errCode: codes.Internal,
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
if err := doHTTPHeaderTest(t, test.errCode, test.responseHeader, test.trailer); err != nil {
t.Error(err)
}
})

}
}

func (s) TestHTTPHeaderFrameErrorHandlingMoreThanTwoHeaders(t *testing.T) {
header := []string{
":status", "200",
"content-type", "application/grpc",
}
if err := doHTTPHeaderTest(t, codes.Internal, header, header, header); err != nil {
t.Fatal(err)
}
}

type httpServerResponse struct {
headers [][]string
payload []byte
Expand Down

0 comments on commit 5dbeec7

Please sign in to comment.