diff options
-rw-r--r-- | worktree_commit_test.go | 140 |
1 files changed, 85 insertions, 55 deletions
diff --git a/worktree_commit_test.go b/worktree_commit_test.go index 823a886..004926f 100644 --- a/worktree_commit_test.go +++ b/worktree_commit_test.go @@ -7,6 +7,7 @@ import ( "golang.org/x/crypto/openpgp" "golang.org/x/crypto/openpgp/armor" + "golang.org/x/crypto/openpgp/errors" "gopkg.in/src-d/go-git.v4/plumbing" "gopkg.in/src-d/go-git.v4/plumbing/object" "gopkg.in/src-d/go-git.v4/plumbing/storer" @@ -154,7 +155,7 @@ func (s *WorktreeSuite) TestCommitSign(c *C) { _, err = w.Add("foo") c.Assert(err, IsNil) - key := commitSignKey(c) + key := commitSignKey(c, true) hash, err := w.Commit("foo\n", &CommitOptions{Author: defaultSignature(), SignKey: key}) c.Assert(err, IsNil) @@ -175,6 +176,26 @@ func (s *WorktreeSuite) TestCommitSign(c *C) { c.Assert(actual.PrimaryKey, DeepEquals, key.PrimaryKey) } +func (s *WorktreeSuite) TestCommitSignBadKey(c *C) { + fs := memfs.New() + storage := memory.NewStorage() + + r, err := Init(storage, fs) + c.Assert(err, IsNil) + + w, err := r.Worktree() + c.Assert(err, IsNil) + + util.WriteFile(fs, "foo", []byte("foo"), 0644) + + _, err = w.Add("foo") + c.Assert(err, IsNil) + + key := commitSignKey(c, false) + _, err = w.Commit("foo\n", &CommitOptions{Author: defaultSignature(), SignKey: key}) + c.Assert(err, Equals, errors.InvalidArgumentError("signing key is encrypted")) +} + func assertStorageStatus( c *C, r *Repository, treesCount, blobCount, commitCount int, head plumbing.Hash, @@ -214,7 +235,7 @@ func defaultSignature() *object.Signature { } } -func commitSignKey(c *C) *openpgp.Entity { +func commitSignKey(c *C, decrypt bool) *openpgp.Entity { s := strings.NewReader(armoredKeyRing) es, err := openpgp.ReadArmoredKeyRing(s) c.Assert(err, IsNil) @@ -224,63 +245,72 @@ func commitSignKey(c *C) *openpgp.Entity { _, ok := es[0].Identities["foo bar <foo@foo.foo>"] c.Assert(ok, Equals, true) - return es[0] + key := es[0] + if decrypt { + err = key.PrivateKey.Decrypt([]byte(keyPassphrase)) + c.Assert(err, IsNil) + } + + return key } const armoredKeyRing = ` -----BEGIN PGP PRIVATE KEY BLOCK----- -lQcYBFt1xEwBEACcJKn7ZVm465OXXDM3gvIMft4GKD82VmzujjAT1XQQf3srIrNR -lgFZiSE3fYFvc7SbqIXRVn1Fg9N95XSF6S5C8PwRwtpEPBfKOwGSuFWdlL68vRXX -yDs0u9Ih3TYOtnJ9qBJ/QUt6dOZd/CC88qaEEn0tvNU1A2uujjWuJCbcnfjZisM8 -8fF2vTkgN7eSojhK07WFGwbuYxJmkfZ1zyvaeeSH61WCE29vXKObZtc0dqA/AOW4 -x08hFyzAdLSqSdMURHpMjHGO1/0xtnZXaf346IJDwOyJKoIEVuSLppIKB8uUCuMZ -ux+cYXfwBkzTKD7SmQO5Q0lU13QRz+aLCOjWij5PR5KqqYpLgS2iiEE12gxx7uuj -a5pHjRdCrMNlvn8fFwgRjhciZWftHy3cda0wMLEchezYBK4xF2bWqfO8jIrsXHxr -m9/9T7t7f9wIJN4fFNVQDeNOsONMv63eZKudAfkElIBwfnBDGHLD14uID9KVnPUY -EJ/pm1lptDd5nBsR1sfaLIj05vM29yByk/jE7HCvqlHi/6H4igCjhGm7+9ypHmPO -iviXKNCJpllCPNMaJRaOYcTYfX9PMMNIrp6txuzNwFNj5bwoyaegaa6R2/9hm7Pu -ljXd6Clck2XNEX6Uig3ZBM+LrAn4fn5IEH7XfXGlK0SNvjZMRk6kgpiInwARAQAB -AA/7B02YRk10PrfOBY/m2VtnjfnHY9RVytb5/+uNLPlz3iI/J0JXhaLw68q64f/5 -NEjeJYyHBKH5ZkjQUIpswqc6r2ja8V25nJshOAL1FgWQTLhlmuBO5xdAk2GPQc1d -7gw8iKaeztwO0rPfmesuSfXYDWh+Qqc/rIBhvfnqz2i+5JOVOxZs2nQszg7OzMaJ -y/L2JjZiLBhRYNFMluIiRRE1aXQkohdnmgV4H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