1
# Copyright (C) 2005 by 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
"""Black-box tests for bzr re-sign.
25
from bzrlib.bzrdir import BzrDir
26
from bzrlib.testament import Testament
27
from bzrlib.tests import TestCaseInTempDir
30
class ReSign(TestCaseInTempDir):
32
def monkey_patch_gpg(self):
33
"""Monkey patch the gpg signing strategy to be a loopback.
35
This also registers the cleanup, so that we will revert to
36
the original gpg strategy when done.
38
self._oldstrategy = bzrlib.gpg.GPGStrategy
40
# monkey patch gpg signing mechanism
41
bzrlib.gpg.GPGStrategy = bzrlib.gpg.LoopbackGPGStrategy
43
self.addCleanup(self._fix_gpg_strategy)
45
def _fix_gpg_strategy(self):
46
bzrlib.gpg.GPGStrategy = self._oldstrategy
49
wt = BzrDir.create_standalone_workingtree('.')
50
wt.commit("base A", allow_pointless=True, rev_id='A')
51
wt.commit("base B", allow_pointless=True, rev_id='B')
52
wt.commit("base C", allow_pointless=True, rev_id='C')
56
def assertEqualSignature(self, repo, revision_id):
57
"""Assert a signature is stored correctly in repository."""
59
Testament.from_revision(repo, revision_id).as_short_text(),
60
repo.get_signature_text(revision_id))
62
def test_resign(self):
63
#Test re signing of data.
64
wt = self.setup_tree()
65
repo = wt.branch.repository
67
self.monkey_patch_gpg()
68
self.run_bzr('re-sign', '-r', 'revid:A')
70
self.assertEqualSignature(repo, 'A')
72
self.run_bzr('re-sign', 'B')
73
self.assertEqualSignature(repo, 'B')
75
def test_resign_range(self):
76
wt = self.setup_tree()
77
repo = wt.branch.repository
79
self.monkey_patch_gpg()
80
self.run_bzr('re-sign', '-r', '1..')
81
self.assertEqualSignature(repo, 'A')
82
self.assertEqualSignature(repo, 'B')
83
self.assertEqualSignature(repo, 'C')
85
def test_resign_multiple(self):
86
wt = self.setup_tree()
87
repo = wt.branch.repository
89
self.monkey_patch_gpg()
90
self.run_bzr('re-sign', 'A', 'B', 'C')
91
self.assertEqualSignature(repo, 'A')
92
self.assertEqualSignature(repo, 'B')
93
self.assertEqualSignature(repo, 'C')