1
# Copyright (C) 2005-2011 Canonical Ltd
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
"""Tests for repository revision signatures."""
26
from bzrlib.testament import Testament
27
from bzrlib.tests import per_repository
29
class TestSignatures(per_repository.TestCaseWithRepository):
32
# compare the gpg-to-sign info for a commit with a ghost and
33
# an identical tree without a ghost
34
# fetch missing should rewrite the TOC of weaves to list newly available parents.
36
def test_sign_existing_revision(self):
37
wt = self.make_branch_and_tree('.')
38
wt.commit("base", allow_pointless=True, rev_id='A')
39
strategy = gpg.LoopbackGPGStrategy(None)
40
repo = wt.branch.repository
41
self.addCleanup(repo.lock_write().unlock)
42
repo.start_write_group()
43
repo.sign_revision('A', strategy)
44
repo.commit_write_group()
45
self.assertEqual('-----BEGIN PSEUDO-SIGNED CONTENT-----\n' +
46
Testament.from_revision(repo,
47
'A').as_short_text() +
48
'-----END PSEUDO-SIGNED CONTENT-----\n',
49
repo.get_signature_text('A'))
51
def test_store_signature(self):
52
wt = self.make_branch_and_tree('.')
56
branch.repository.start_write_group()
58
branch.repository.store_revision_signature(
59
gpg.LoopbackGPGStrategy(None), 'FOO', 'A')
60
except errors.NoSuchRevision:
61
branch.repository.abort_write_group()
62
raise tests.TestNotApplicable(
63
"repository does not support signing non-present"
66
branch.repository.abort_write_group()
69
branch.repository.commit_write_group()
72
# A signature without a revision should not be accessible.
73
self.assertRaises(errors.NoSuchRevision,
74
branch.repository.has_signature_for_revision_id,
76
wt.commit("base", allow_pointless=True, rev_id='A')
77
self.assertEqual('-----BEGIN PSEUDO-SIGNED CONTENT-----\n'
78
'FOO-----END PSEUDO-SIGNED CONTENT-----\n',
79
branch.repository.get_signature_text('A'))
81
def test_clone_preserves_signatures(self):
82
wt = self.make_branch_and_tree('source')
83
wt.commit('A', allow_pointless=True, rev_id='A')
84
repo = wt.branch.repository
86
repo.start_write_group()
87
repo.sign_revision('A', gpg.LoopbackGPGStrategy(None))
88
repo.commit_write_group()
90
#FIXME: clone should work to urls,
91
# wt.clone should work to disks.
92
self.build_tree(['target/'])
93
d2 = repo.bzrdir.clone(urlutils.local_path_to_url('target'))
94
self.assertEqual(repo.get_signature_text('A'),
95
d2.open_repository().get_signature_text('A'))