Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

server: return UNIMPLEMENTED on receipt of malformed method name #4464

Merged
merged 1 commit into from May 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion server.go
Expand Up @@ -1588,7 +1588,7 @@ func (s *Server) handleStream(t transport.ServerTransport, stream *transport.Str
trInfo.tr.SetError()
}
errDesc := fmt.Sprintf("malformed method name: %q", stream.Method())
if err := t.WriteStatus(stream, status.New(codes.ResourceExhausted, errDesc)); err != nil {
if err := t.WriteStatus(stream, status.New(codes.Unimplemented, errDesc)); err != nil {
if trInfo != nil {
trInfo.tr.LazyLog(&fmtStringer{"%v", []interface{}{err}}, true)
trInfo.tr.SetError()
Expand Down
17 changes: 17 additions & 0 deletions test/end2end_test.go
Expand Up @@ -6292,6 +6292,23 @@ func testServiceConfigMaxMsgSizeTD(t *testing.T, e env) {
}
}

// TestMalformedStreamMethod starts a test server and sends an RPC with a
// malformed method name. The server should respond with an UNIMPLEMENTED status
// code in this case.
func (s) TestMalformedStreamMethod(t *testing.T) {
const testMethod = "a-method-name-without-any-slashes"
te := newTest(t, tcpClearRREnv)
te.startServer(nil)
defer te.tearDown()

ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
defer cancel()
err := te.clientConn().Invoke(ctx, testMethod, nil, nil)
if gotCode := status.Code(err); gotCode != codes.Unimplemented {
t.Fatalf("Invoke with method %q, got code %s, want %s", testMethod, gotCode, codes.Unimplemented)
}
}

func (s) TestMethodFromServerStream(t *testing.T) {
const testMethod = "/package.service/method"
e := tcpClearRREnv
Expand Down