Skip to content

Commit

Permalink
server: return UNIMPLEMENTED on receipt of malformed method name (#4464)
Browse files Browse the repository at this point in the history
  • Loading branch information
easwars committed May 25, 2021
1 parent c4ed636 commit 728364a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion server.go
Expand Up @@ -1590,7 +1590,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 @@ -6347,6 +6347,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

0 comments on commit 728364a

Please sign in to comment.