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

Erroring if gRPC parameters contains headers key #3350

Merged
merged 2 commits into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions js/modules/k6/grpc/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -446,9 +446,6 @@ func (c *Client) parseInvokeParams(paramsVal goja.Value) (*invokeParams, error)
params := paramsVal.ToObject(rt)
for _, k := range params.Keys() {
switch k {
case "headers":
c.vu.State().Logger.Warn("The headers property is deprecated, replace it with the metadata property, please.")
fallthrough
case "metadata":
md, err := newMetadata(params.Get(k))
if err != nil {
Expand All @@ -467,6 +464,8 @@ func (c *Client) parseInvokeParams(paramsVal goja.Value) (*invokeParams, error)
if err != nil {
return result, fmt.Errorf("invalid timeout value: %w", err)
}
case "headers":
return result, errors.New("you should use metadata param instead of headers")
olegbespalov marked this conversation as resolved.
Show resolved Hide resolved
default:
return result, fmt.Errorf("unknown param: %q", k)
}
Expand Down
38 changes: 0 additions & 38 deletions js/modules/k6/grpc/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"github.com/golang/protobuf/ptypes/wrappers"
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/metadata"
Expand Down Expand Up @@ -1129,43 +1128,6 @@ func TestDebugStat(t *testing.T) {
}
}

func TestClientInvokeHeadersDeprecated(t *testing.T) {
t.Parallel()

ts := newTestState(t)
reflection.Register(ts.httpBin.ServerGRPC)

ts.httpBin.GRPCStub.EmptyCallFunc = func(_ context.Context, _ *grpc_testing.Empty) (*grpc_testing.Empty, error) {
return &grpc_testing.Empty{}, nil
}

initString := codeBlock{
code: `var client = new grpc.Client();`,
}
vuString := codeBlock{
code: `
client.connect("GRPCBIN_ADDR", {reflect:true});
var resp = client.invoke("grpc.testing.TestService/EmptyCall", {}, { headers: { "X-Load-Tester": "k6" } })
if (resp.status !== grpc.StatusOK) {
throw new Error("failed to send a request")
}
`,
}

val, err := ts.Run(initString.code)
assertResponse(t, initString, err, val, ts)

ts.ToVUContext()

val, err = ts.Run(vuString.code)
assertResponse(t, vuString, err, val, ts)

entries := ts.loggerHook.Drain()

require.Len(t, entries, 1)
require.Contains(t, entries[0].Message, "headers property is deprecated")
}

func TestClientLoadProto(t *testing.T) {
t.Parallel()

Expand Down