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

metadata: fix validation issues #6001

Merged
merged 8 commits into from Feb 28, 2023
Merged

metadata: fix validation issues #6001

merged 8 commits into from Feb 28, 2023

Conversation

ktalg
Copy link
Contributor

@ktalg ktalg commented Feb 1, 2023

fix: #5913

RELEASE NOTES:

  • metadata: fix validation logic and properly validate metadata appended via AppendToOutgoingContext.

@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Feb 1, 2023

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: ktalg / name: KT (e614562)

Copy link
Member

@dfawley dfawley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the fixes! Comments inline.

stream.go Outdated Show resolved Hide resolved
test/metadata_test.go Outdated Show resolved Hide resolved
test/metadata_test.go Outdated Show resolved Hide resolved
Copy link
Member

@dfawley dfawley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the updates! Just a few small comments otherwise LGTM.

internal/metadata/metadata.go Outdated Show resolved Hide resolved
internal/metadata/metadata_test.go Outdated Show resolved Hide resolved
stream.go Outdated Show resolved Hide resolved
test/metadata_test.go Outdated Show resolved Hide resolved
@ktalg
Copy link
Contributor Author

ktalg commented Feb 10, 2023

Thanks for your review! done.

Copy link
Member

@dfawley dfawley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Just a couple minor nits.

test/metadata_test.go Outdated Show resolved Hide resolved
stream.go Outdated Show resolved Hide resolved
@dfawley dfawley assigned zasweq and unassigned dfawley Feb 14, 2023
@dfawley
Copy link
Member

dfawley commented Feb 14, 2023

@zasweq can you take a second pass please?

Copy link
Contributor

@zasweq zasweq left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution. Sorry for the late review.

@@ -118,3 +101,31 @@ func hasNotPrintable(msg string) bool {
}
return false
}

// ValidatePair validate single pair in metadata
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: I know these comments are similar to ones on master here and throughout the PR, but can you please reword to have proper grammar (capitalization and periods). Also, some of these comments are not explaining why/reasoning a block of code is happening, simply stating exactly the operations taking place within the code block. Please reword to proper grammar/explaining why/delete those which you find appropriate.

if _, err := stream.Recv(); status.Code(err) != status.Code(test.recv) || !strings.Contains(err.Error(), test.recv.Error()) {
t.Errorf("stream.Recv() = _, get err :%v, want err :%v", err, test.recv)
}
t.Run("streaming "+test.name, func(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional nit (not important for linter or correctness): I prefer spaces in between operators i.e. "streaming " + test.name). Here and elsewhere

t.Errorf("call ss.Client stream Send(nil) will success but got err :%v", err)
}
if _, err := stream.Recv(); status.Code(err) != status.Code(test.recv) || !strings.Contains(err.Error(), test.recv.Error()) {
t.Errorf("stream.Recv() = _, get err :%v, want err :%v", err, test.recv)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

*got err

defer cancel()
stream, err := ss.Client.FullDuplexCall(ctx)
if err != nil {
t.Errorf("call ss.Client.FullDuplexCall(context.Background()) will success but got err :%v", err)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know you didn't write this, but this grammar is strange, and is incorrect (it's not being called with context.Background(), it's being called with context with a timeout). Please reword (see other examples in codebase). Perhaps something like "ss.Client.FullDuplexCall(ctx) want err: %v, got err : %v", nil, err). Here and elsewhere.

return
}
if err := stream.Send(&testpb.StreamingOutputCallRequest{}); err != nil {
t.Errorf("call ss.Client stream Send(nil) will success but got err :%v", err)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here (see comment above). This isn't sending nil, but an allocated testpb.StreamingOutputCallRequest.

md := metadata.Join(test.md, metadata.Pairs(test.appendMD...))

if err := stream.SetHeader(md); !reflect.DeepEqual(test.want, err) {
return fmt.Errorf("call stream.SendHeader(md) validate metadata which is %v got err :%v, want err :%v", md, err, test.want)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As below, please reword.

Copy link
Contributor

@zasweq zasweq left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@zasweq zasweq merged commit dba41ef into grpc:master Feb 28, 2023
1 check passed
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 28, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Metadata validation problem
4 participants