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

secrets: improve tests on malformed message #2377

Merged
merged 3 commits into from Jun 19, 2019

Conversation

shantuo
Copy link
Contributor

@shantuo shantuo commented Jun 18, 2019

Fixes #1692

@shantuo shantuo requested a review from zombiezen June 18, 2019 22:58
@googlebot googlebot added the cla: yes Google CLA has been signed! label Jun 18, 2019
},
{
name: "missing second byte",
malformed: append(encryptedMsg[:1], encryptedMsg[2:]...),
Copy link
Contributor

Choose a reason for hiding this comment

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

This removes the byte for the rest of the test, though. Each of these slices should operate on a copy of encryptedMsg. The most concise way I can think of to do the copy is by creating a small helper function above:

encryptedMsg, err := keeper.Encrypt(ctx, msg)
if err != nil {
	t.Fatal(err)
}
copyEncryptedMsg := func() []byte {
  return append([]byte(nil), encryptedMsg...)
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Copy link
Contributor Author

@shantuo shantuo left a comment

Choose a reason for hiding this comment

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

PTAL

},
{
name: "missing second byte",
malformed: append(encryptedMsg[:1], encryptedMsg[2:]...),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes Google CLA has been signed!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

secrets: verify that Decrypt does not permit using the wrong key
3 participants