~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/blackbox/test_sign_my_commits.py

  • Committer: Tarmac
  • Author(s): Vincent Ladeuil
  • Date: 2017-01-30 14:42:05 UTC
  • mfrom: (6620.1.1 trunk)
  • Revision ID: tarmac-20170130144205-r8fh2xpmiuxyozpv
Merge  2.7 into trunk including fix for bug #1657238 [r=vila]

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005 Canonical Ltd
 
1
# Copyright (C) 2006, 2007, 2009-2013, 2016 Canonical Ltd
2
2
# -*- coding: utf-8 -*-
3
3
#
4
4
# This program is free software; you can redistribute it and/or modify
21
21
    gpg,
22
22
    tests,
23
23
    )
 
24
from bzrlib.tests.matchers import ContainsNoVfsCalls
24
25
 
25
26
 
26
27
class SignMyCommits(tests.TestCaseWithTransport):
107
108
        out = self.run_bzr('sign-my-commits --dry-run')[0]
108
109
 
109
110
        outlines = out.splitlines()
110
 
        self.assertEquals(5, len(outlines))
111
 
        self.assertEquals('Signed 4 revisions', outlines[-1])
 
111
        self.assertEqual(5, len(outlines))
 
112
        self.assertEqual('Signed 4 revisions.', outlines[-1])
112
113
        self.assertUnsigned(repo, 'A')
113
114
        self.assertUnsigned(repo, 'B')
114
115
        self.assertUnsigned(repo, 'C')
115
116
        self.assertUnsigned(repo, 'D')
116
117
        self.assertUnsigned(repo, 'E')
117
118
 
118
 
    def test_verify_commits(self):
119
 
        wt = self.setup_tree()
120
 
        self.monkey_patch_gpg()
121
 
        self.run_bzr('sign-my-commits')
122
 
        out = self.run_bzr('verify-signatures', retcode=1)
123
 
        self.assertEquals(('4 commits with valid signatures\n'
124
 
                           '0 commits with unknown keys\n'
125
 
                           '0 commits not valid\n'
126
 
                           '1 commit not signed\n', ''), out)
127
 
 
128
 
    def test_verify_commits_acceptable_key(self):
129
 
        wt = self.setup_tree()
130
 
        self.monkey_patch_gpg()
131
 
        self.run_bzr('sign-my-commits')
132
 
        out = self.run_bzr(['verify-signatures', '--acceptable-keys=foo,bar'],
133
 
                            retcode=1)
134
 
        self.assertEquals(('4 commits with valid signatures\n'
135
 
                           '0 commits with unknown keys\n'
136
 
                           '0 commits not valid\n'
137
 
                           '1 commit not signed\n', ''), out)
 
119
 
 
120
class TestSmartServerSignMyCommits(tests.TestCaseWithTransport):
 
121
 
 
122
    def monkey_patch_gpg(self):
 
123
        """Monkey patch the gpg signing strategy to be a loopback.
 
124
 
 
125
        This also registers the cleanup, so that we will revert to
 
126
        the original gpg strategy when done.
 
127
        """
 
128
        # monkey patch gpg signing mechanism
 
129
        self.overrideAttr(gpg, 'GPGStrategy', gpg.LoopbackGPGStrategy)
 
130
 
 
131
    def test_sign_single_commit(self):
 
132
        self.setup_smart_server_with_call_log()
 
133
        t = self.make_branch_and_tree('branch')
 
134
        self.build_tree_contents([('branch/foo', 'thecontents')])
 
135
        t.add("foo")
 
136
        t.commit("message")
 
137
        self.reset_smart_call_log()
 
138
        self.monkey_patch_gpg()
 
139
        out, err = self.run_bzr(['sign-my-commits', self.get_url('branch')])
 
140
        # This figure represent the amount of work to perform this use case. It
 
141
        # is entirely ok to reduce this number if a test fails due to rpc_count
 
142
        # being too low. If rpc_count increases, more network roundtrips have
 
143
        # become necessary for this use case. Please do not adjust this number
 
144
        # upwards without agreement from bzr's network support maintainers.
 
145
        self.assertLength(15, self.hpss_calls)
 
146
        self.assertLength(1, self.hpss_connections)
 
147
        self.assertThat(self.hpss_calls, ContainsNoVfsCalls)