1
# Copyright (C) 2005 Canonical Ltd
2
# -*- coding: utf-8 -*-
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; either version 2 of the License, or
7
# (at your option) any later version.
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
# GNU General Public License for more details.
14
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
"""Black-box tests for bzr verify-signatures."""
24
from bzrlib.tests.matchers import ContainsNoVfsCalls
27
class TestVerifySignatures(tests.TestCaseWithTransport):
29
def monkey_patch_gpg(self):
30
"""Monkey patch the gpg signing strategy to be a loopback.
32
This also registers the cleanup, so that we will revert to
33
the original gpg strategy when done.
35
# monkey patch gpg signing mechanism
36
self.overrideAttr(gpg, 'GPGStrategy', gpg.LoopbackGPGStrategy)
38
def setup_tree(self, location='.'):
39
wt = self.make_branch_and_tree(location)
40
wt.commit("base A", allow_pointless=True, rev_id='A')
41
wt.commit("base B", allow_pointless=True, rev_id='B')
42
wt.commit("base C", allow_pointless=True, rev_id='C')
43
wt.commit("base D", allow_pointless=True, rev_id='D',
44
committer='Alternate <alt@foo.com>')
45
wt.add_parent_tree_id("aghost")
46
wt.commit("base E", allow_pointless=True, rev_id='E')
49
def test_verify_signatures(self):
50
wt = self.setup_tree()
51
self.monkey_patch_gpg()
52
self.run_bzr('sign-my-commits')
53
out = self.run_bzr('verify-signatures', retcode=1)
54
self.assertEquals(('4 commits with valid signatures\n'
55
'0 commits with key now expired\n'
56
'0 commits with unknown keys\n'
57
'0 commits not valid\n'
58
'1 commit not signed\n', ''), out)
60
def test_verify_signatures_acceptable_key(self):
61
wt = self.setup_tree()
62
self.monkey_patch_gpg()
63
self.run_bzr('sign-my-commits')
64
out = self.run_bzr(['verify-signatures', '--acceptable-keys=foo,bar'],
66
self.assertEquals(('4 commits with valid signatures\n'
67
'0 commits with key now expired\n'
68
'0 commits with unknown keys\n'
69
'0 commits not valid\n'
70
'1 commit not signed\n', ''), out)
72
def test_verify_signatures_verbose(self):
73
wt = self.setup_tree()
74
self.monkey_patch_gpg()
75
self.run_bzr('sign-my-commits')
76
out = self.run_bzr('verify-signatures --verbose', retcode=1)
77
self.assertEquals(('4 commits with valid signatures\n'
78
' None signed 4 commits\n'
79
'0 commits with key now expired\n'
80
'0 commits with unknown keys\n'
81
'0 commits not valid\n'
82
'1 commit not signed\n'
83
' 1 commit by author Alternate <alt@foo.com>\n', ''), out)
85
def test_verify_signatures_verbose_all_valid(self):
86
wt = self.setup_tree()
87
self.monkey_patch_gpg()
88
self.run_bzr('sign-my-commits')
89
self.run_bzr(['sign-my-commits', '.', 'Alternate <alt@foo.com>'])
90
out = self.run_bzr('verify-signatures --verbose')
91
self.assertEquals(('All commits signed with verifiable keys\n'
92
' None signed 5 commits\n', ''), out)
95
class TestSmartServerVerifySignatures(tests.TestCaseWithTransport):
97
def monkey_patch_gpg(self):
98
"""Monkey patch the gpg signing strategy to be a loopback.
100
This also registers the cleanup, so that we will revert to
101
the original gpg strategy when done.
103
# monkey patch gpg signing mechanism
104
self.overrideAttr(gpg, 'GPGStrategy', gpg.LoopbackGPGStrategy)
106
def test_verify_signatures(self):
107
self.setup_smart_server_with_call_log()
108
t = self.make_branch_and_tree('branch')
109
self.build_tree_contents([('branch/foo', 'thecontents')])
112
self.monkey_patch_gpg()
113
out, err = self.run_bzr(['sign-my-commits', self.get_url('branch')])
114
self.reset_smart_call_log()
115
self.run_bzr('sign-my-commits')
116
out = self.run_bzr(['verify-signatures', self.get_url('branch')])
117
# This figure represent the amount of work to perform this use case. It
118
# is entirely ok to reduce this number if a test fails due to rpc_count
119
# being too low. If rpc_count increases, more network roundtrips have
120
# become necessary for this use case. Please do not adjust this number
121
# upwards without agreement from bzr's network support maintainers.
122
self.assertLength(10, self.hpss_calls)
123
self.assertLength(1, self.hpss_connections)
124
self.assertThat(self.hpss_calls, ContainsNoVfsCalls)