2052.3.2
by John Arbash Meinel
Change Copyright .. by Canonical to Copyright ... Canonical |
1 |
# Copyright (C) 2005 Canonical Ltd
|
1185.78.6
by John Arbash Meinel
Adding sign-my-commits as a builtin, along with some simple tests. |
2 |
# -*- coding: utf-8 -*-
|
1887.1.1
by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines, |
3 |
#
|
1185.78.6
by John Arbash Meinel
Adding sign-my-commits as a builtin, along with some simple tests. |
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.
|
|
1887.1.1
by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines, |
8 |
#
|
1185.78.6
by John Arbash Meinel
Adding sign-my-commits as a builtin, along with some simple tests. |
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.
|
|
1887.1.1
by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines, |
13 |
#
|
1185.78.6
by John Arbash Meinel
Adding sign-my-commits as a builtin, along with some simple tests. |
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
|
|
4183.7.1
by Sabin Iacob
update FSF mailing address |
16 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
1185.78.6
by John Arbash Meinel
Adding sign-my-commits as a builtin, along with some simple tests. |
17 |
|
1185.79.3
by John Arbash Meinel
cleanups from Robert |
18 |
"""Black-box tests for bzr sign-my-commits."""
|
1185.78.6
by John Arbash Meinel
Adding sign-my-commits as a builtin, along with some simple tests. |
19 |
|
4985.1.5
by Vincent Ladeuil
Deploying the new overrideAttr facility further reduces the complexity |
20 |
from bzrlib import ( |
21 |
gpg, |
|
22 |
tests, |
|
23 |
)
|
|
6352.2.3
by Jelmer Vernooij
s/NoVfsCalls/ContainsNoVfsCalls/. |
24 |
from bzrlib.tests.matchers import ContainsNoVfsCalls |
1185.78.6
by John Arbash Meinel
Adding sign-my-commits as a builtin, along with some simple tests. |
25 |
|
26 |
||
4985.1.5
by Vincent Ladeuil
Deploying the new overrideAttr facility further reduces the complexity |
27 |
class SignMyCommits(tests.TestCaseWithTransport): |
1185.78.6
by John Arbash Meinel
Adding sign-my-commits as a builtin, along with some simple tests. |
28 |
|
29 |
def monkey_patch_gpg(self): |
|
30 |
"""Monkey patch the gpg signing strategy to be a loopback.
|
|
31 |
||
32 |
This also registers the cleanup, so that we will revert to
|
|
33 |
the original gpg strategy when done.
|
|
34 |
"""
|
|
35 |
# monkey patch gpg signing mechanism
|
|
4985.1.5
by Vincent Ladeuil
Deploying the new overrideAttr facility further reduces the complexity |
36 |
self.overrideAttr(gpg, 'GPGStrategy', gpg.LoopbackGPGStrategy) |
1185.78.6
by John Arbash Meinel
Adding sign-my-commits as a builtin, along with some simple tests. |
37 |
|
1185.79.3
by John Arbash Meinel
cleanups from Robert |
38 |
def setup_tree(self, location='.'): |
39 |
wt = self.make_branch_and_tree(location) |
|
1185.78.6
by John Arbash Meinel
Adding sign-my-commits as a builtin, along with some simple tests. |
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>') |
|
5972.3.23
by Jelmer Vernooij
Fix handling of ghosts in sign_my_commits. |
45 |
wt.add_parent_tree_id("aghost") |
46 |
wt.commit("base E", allow_pointless=True, rev_id='E') |
|
1185.78.6
by John Arbash Meinel
Adding sign-my-commits as a builtin, along with some simple tests. |
47 |
return wt |
48 |
||
1563.2.31
by Robert Collins
Convert Knit repositories to use knits. |
49 |
def assertUnsigned(self, repo, revision_id): |
50 |
"""Assert that revision_id is not signed in repo."""
|
|
51 |
self.assertFalse(repo.has_signature_for_revision_id(revision_id)) |
|
52 |
||
53 |
def assertSigned(self, repo, revision_id): |
|
54 |
"""Assert that revision_id is signed in repo."""
|
|
55 |
self.assertTrue(repo.has_signature_for_revision_id(revision_id)) |
|
56 |
||
1185.78.6
by John Arbash Meinel
Adding sign-my-commits as a builtin, along with some simple tests. |
57 |
def test_sign_my_commits(self): |
58 |
#Test re signing of data.
|
|
59 |
wt = self.setup_tree() |
|
60 |
repo = wt.branch.repository |
|
61 |
||
62 |
self.monkey_patch_gpg() |
|
63 |
||
1563.2.31
by Robert Collins
Convert Knit repositories to use knits. |
64 |
self.assertUnsigned(repo, 'A') |
65 |
self.assertUnsigned(repo, 'B') |
|
66 |
self.assertUnsigned(repo, 'C') |
|
67 |
self.assertUnsigned(repo, 'D') |
|
1185.78.6
by John Arbash Meinel
Adding sign-my-commits as a builtin, along with some simple tests. |
68 |
|
69 |
self.run_bzr('sign-my-commits') |
|
70 |
||
1563.2.31
by Robert Collins
Convert Knit repositories to use knits. |
71 |
self.assertSigned(repo, 'A') |
72 |
self.assertSigned(repo, 'B') |
|
73 |
self.assertSigned(repo, 'C') |
|
74 |
self.assertUnsigned(repo, 'D') |
|
3943.8.1
by Marius Kruger
remove all trailing whitespace from bzr source |
75 |
|
1185.78.6
by John Arbash Meinel
Adding sign-my-commits as a builtin, along with some simple tests. |
76 |
def test_sign_my_commits_location(self): |
1185.79.3
by John Arbash Meinel
cleanups from Robert |
77 |
wt = self.setup_tree('other') |
1185.78.6
by John Arbash Meinel
Adding sign-my-commits as a builtin, along with some simple tests. |
78 |
repo = wt.branch.repository |
79 |
||
80 |
self.monkey_patch_gpg() |
|
81 |
||
2552.2.3
by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests. |
82 |
self.run_bzr('sign-my-commits other') |
1185.78.6
by John Arbash Meinel
Adding sign-my-commits as a builtin, along with some simple tests. |
83 |
|
1563.2.31
by Robert Collins
Convert Knit repositories to use knits. |
84 |
self.assertSigned(repo, 'A') |
85 |
self.assertSigned(repo, 'B') |
|
86 |
self.assertSigned(repo, 'C') |
|
87 |
self.assertUnsigned(repo, 'D') |
|
1185.78.6
by John Arbash Meinel
Adding sign-my-commits as a builtin, along with some simple tests. |
88 |
|
89 |
def test_sign_diff_committer(self): |
|
90 |
wt = self.setup_tree() |
|
91 |
repo = wt.branch.repository |
|
92 |
||
93 |
self.monkey_patch_gpg() |
|
94 |
||
2552.2.3
by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests. |
95 |
self.run_bzr(['sign-my-commits', '.', 'Alternate <alt@foo.com>']) |
1185.78.6
by John Arbash Meinel
Adding sign-my-commits as a builtin, along with some simple tests. |
96 |
|
1563.2.31
by Robert Collins
Convert Knit repositories to use knits. |
97 |
self.assertUnsigned(repo, 'A') |
98 |
self.assertUnsigned(repo, 'B') |
|
99 |
self.assertUnsigned(repo, 'C') |
|
100 |
self.assertSigned(repo, 'D') |
|
1185.78.6
by John Arbash Meinel
Adding sign-my-commits as a builtin, along with some simple tests. |
101 |
|
102 |
def test_sign_dry_run(self): |
|
103 |
wt = self.setup_tree() |
|
104 |
repo = wt.branch.repository |
|
105 |
||
106 |
self.monkey_patch_gpg() |
|
107 |
||
2552.2.3
by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests. |
108 |
out = self.run_bzr('sign-my-commits --dry-run')[0] |
1185.78.6
by John Arbash Meinel
Adding sign-my-commits as a builtin, along with some simple tests. |
109 |
|
5972.3.6
by Jelmer Vernooij
Fix sign_my_commits test. |
110 |
outlines = out.splitlines() |
5972.3.23
by Jelmer Vernooij
Fix handling of ghosts in sign_my_commits. |
111 |
self.assertEquals(5, len(outlines)) |
112 |
self.assertEquals('Signed 4 revisions', outlines[-1]) |
|
1563.2.31
by Robert Collins
Convert Knit repositories to use knits. |
113 |
self.assertUnsigned(repo, 'A') |
114 |
self.assertUnsigned(repo, 'B') |
|
115 |
self.assertUnsigned(repo, 'C') |
|
116 |
self.assertUnsigned(repo, 'D') |
|
5972.3.23
by Jelmer Vernooij
Fix handling of ghosts in sign_my_commits. |
117 |
self.assertUnsigned(repo, 'E') |
5971.1.9
by Jonathan Riddell
add some tests |
118 |
|
119 |
def test_verify_commits(self): |
|
120 |
wt = self.setup_tree() |
|
121 |
self.monkey_patch_gpg() |
|
122 |
self.run_bzr('sign-my-commits') |
|
5971.1.68
by Jonathan Riddell
rename command in tests |
123 |
out = self.run_bzr('verify-signatures', retcode=1) |
5971.1.63
by Jonathan Riddell
use self.outf.write() rather than note() |
124 |
self.assertEquals(('4 commits with valid signatures\n' |
6043.2.11
by Jonathan Riddell
fix test_verify_commits |
125 |
'0 commits with key now expired\n' |
5971.1.63
by Jonathan Riddell
use self.outf.write() rather than note() |
126 |
'0 commits with unknown keys\n' |
127 |
'0 commits not valid\n' |
|
128 |
'1 commit not signed\n', ''), out) |
|
5971.1.14
by Jonathan Riddell
add test for set_acceptable_keys, accept non-trusted keys if specified as acceptable, import dummy key in tests so it works outside my machine |
129 |
|
130 |
def test_verify_commits_acceptable_key(self): |
|
131 |
wt = self.setup_tree() |
|
132 |
self.monkey_patch_gpg() |
|
133 |
self.run_bzr('sign-my-commits') |
|
5971.1.68
by Jonathan Riddell
rename command in tests |
134 |
out = self.run_bzr(['verify-signatures', '--acceptable-keys=foo,bar'], |
135 |
retcode=1) |
|
5971.1.63
by Jonathan Riddell
use self.outf.write() rather than note() |
136 |
self.assertEquals(('4 commits with valid signatures\n' |
6043.2.10
by Jonathan Riddell
fix test test_verify_commits_acceptable_key |
137 |
'0 commits with key now expired\n' |
5971.1.63
by Jonathan Riddell
use self.outf.write() rather than note() |
138 |
'0 commits with unknown keys\n' |
139 |
'0 commits not valid\n' |
|
140 |
'1 commit not signed\n', ''), out) |
|
6283.1.7
by Jelmer Vernooij
Add hpss call count for 'bzr sign-my-commits'. |
141 |
|
142 |
||
143 |
class TestSmartServerSignMyCommits(tests.TestCaseWithTransport): |
|
144 |
||
145 |
def monkey_patch_gpg(self): |
|
146 |
"""Monkey patch the gpg signing strategy to be a loopback.
|
|
147 |
||
148 |
This also registers the cleanup, so that we will revert to
|
|
149 |
the original gpg strategy when done.
|
|
150 |
"""
|
|
151 |
# monkey patch gpg signing mechanism
|
|
152 |
self.overrideAttr(gpg, 'GPGStrategy', gpg.LoopbackGPGStrategy) |
|
153 |
||
154 |
def test_sign_single_commit(self): |
|
155 |
self.setup_smart_server_with_call_log() |
|
156 |
t = self.make_branch_and_tree('branch') |
|
157 |
self.build_tree_contents([('branch/foo', 'thecontents')]) |
|
158 |
t.add("foo") |
|
159 |
t.commit("message") |
|
160 |
self.reset_smart_call_log() |
|
161 |
self.monkey_patch_gpg() |
|
162 |
out, err = self.run_bzr(['sign-my-commits', self.get_url('branch')]) |
|
163 |
# This figure represent the amount of work to perform this use case. It
|
|
164 |
# is entirely ok to reduce this number if a test fails due to rpc_count
|
|
165 |
# being too low. If rpc_count increases, more network roundtrips have
|
|
166 |
# become necessary for this use case. Please do not adjust this number
|
|
167 |
# upwards without agreement from bzr's network support maintainers.
|
|
6282.6.42
by Jelmer Vernooij
merge hpss-get-checkout-format. |
168 |
self.assertLength(15, self.hpss_calls) |
169 |
self.assertThat(self.hpss_calls, ContainsNoVfsCalls) |
|
6283.1.10
by Jelmer Vernooij
Add hpss call count test for 'bzr verify-signatures'. |
170 |
|
171 |
def test_verify_commits(self): |
|
172 |
self.setup_smart_server_with_call_log() |
|
173 |
t = self.make_branch_and_tree('branch') |
|
174 |
self.build_tree_contents([('branch/foo', 'thecontents')]) |
|
175 |
t.add("foo") |
|
176 |
t.commit("message") |
|
177 |
self.monkey_patch_gpg() |
|
178 |
out, err = self.run_bzr(['sign-my-commits', self.get_url('branch')]) |
|
179 |
self.reset_smart_call_log() |
|
180 |
self.run_bzr('sign-my-commits') |
|
181 |
out = self.run_bzr(['verify-signatures', self.get_url('branch')]) |
|
6311.1.1
by Jelmer Vernooij
Add in boilerplate about changing number, cope with spurious test failures. |
182 |
# This figure represent the amount of work to perform this use case. It
|
183 |
# is entirely ok to reduce this number if a test fails due to rpc_count
|
|
184 |
# being too low. If rpc_count increases, more network roundtrips have
|
|
185 |
# become necessary for this use case. Please do not adjust this number
|
|
186 |
# upwards without agreement from bzr's network support maintainers.
|
|
6282.6.11
by Jelmer Vernooij
Adjust some call counts. |
187 |
self.assertLength(10, self.hpss_calls) |
6282.6.42
by Jelmer Vernooij
merge hpss-get-checkout-format. |
188 |
self.assertThat(self.hpss_calls, ContainsNoVfsCalls) |