aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing/object/commit_test.go
diff options
context:
space:
mode:
authorJavi Fontan <jfontan@gmail.com>2018-07-18 11:14:49 +0200
committerJavi Fontan <jfontan@gmail.com>2018-07-18 11:14:49 +0200
commit8df413fe09e6cb2069a76b6df6715d0e610c8458 (patch)
treef59b42322cf4e4d7cdfe2054c34bdb5d16aecb8f /plumbing/object/commit_test.go
parent9f00789688d26191a987fdec8bc2678362ec4453 (diff)
downloadgo-git-8df413fe09e6cb2069a76b6df6715d0e610c8458.tar.gz
plumbing/object: fix pgp signature encoder/decoder
The way of reading pgp signatures was searching for pgp begin line in the header. This caused problems when this string appeared and was not part of the signature. For example if it appears in the message as an example or is part of the author name the decoder starts treating it as a signature. In this state the code was not able to notice then the header ended so it entered in an infinite loop searching for pgp end string. Now it uses the same method as original git. Searches for gpgsig section in header and starts getting all lines until the next part. In encoder the string used to add signatures was incorrect. It is now changed to the proper "gpgsig" string instead of "pgpsig". Signed-off-by: Javi Fontan <jfontan@gmail.com>
Diffstat (limited to 'plumbing/object/commit_test.go')
-rw-r--r--plumbing/object/commit_test.go32
1 files changed, 32 insertions, 0 deletions
diff --git a/plumbing/object/commit_test.go b/plumbing/object/commit_test.go
index 996d481..b5dfbe3 100644
--- a/plumbing/object/commit_test.go
+++ b/plumbing/object/commit_test.go
@@ -324,6 +324,38 @@ RUysgqjcpT8+iQM1PblGfHR4XAhuOqN5Fx06PSaFZhqvWFezJ28/CLyX5q+oIVk=
err = decoded.Decode(encoded)
c.Assert(err, IsNil)
c.Assert(decoded.PGPSignature, Equals, pgpsignature)
+
+ // signature in author name
+
+ commit.PGPSignature = ""
+ commit.Author.Name = beginpgp
+ encoded = &plumbing.MemoryObject{}
+ decoded = &Commit{}
+
+ err = commit.Encode(encoded)
+ c.Assert(err, IsNil)
+
+ err = decoded.Decode(encoded)
+ c.Assert(err, IsNil)
+ c.Assert(decoded.PGPSignature, Equals, "")
+ c.Assert(decoded.Author.Name, Equals, beginpgp)
+
+ // broken signature
+
+ commit.PGPSignature = beginpgp + "\n" +
+ "some\n" +
+ "trash\n" +
+ endpgp +
+ "text\n"
+ encoded = &plumbing.MemoryObject{}
+ decoded = &Commit{}
+
+ err = commit.Encode(encoded)
+ c.Assert(err, IsNil)
+
+ err = decoded.Decode(encoded)
+ c.Assert(err, IsNil)
+ c.Assert(decoded.PGPSignature, Equals, commit.PGPSignature)
}
func (s *SuiteCommit) TestStat(c *C) {