~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/per_repository/test_signatures.py

  • Committer: Patch Queue Manager
  • Date: 2011-10-10 17:21:12 UTC
  • mfrom: (6205.2.1 move-signature-tests)
  • Revision ID: pqm@pqm.ubuntu.com-20111010172112-zj6ufki2aonpr4ut
(jelmer) Move some signature-related tests from bzrlib.tests.per_branch to
 bzrlib.tests.per_repository. (Jelmer Vernooij)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2005-2011 Canonical Ltd
 
2
#
 
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.
 
7
#
 
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.
 
12
#
 
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
 
16
 
 
17
"""Tests for repository revision signatures."""
 
18
 
 
19
from bzrlib import (
 
20
    errors,
 
21
    gpg,
 
22
    tests,
 
23
    urlutils,
 
24
    )
 
25
 
 
26
from bzrlib.testament import Testament
 
27
from bzrlib.tests import per_repository
 
28
 
 
29
class TestSignatures(per_repository.TestCaseWithRepository):
 
30
 
 
31
# TODO 20051003 RBC:
 
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.
 
35
 
 
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'))
 
50
 
 
51
    def test_store_signature(self):
 
52
        wt = self.make_branch_and_tree('.')
 
53
        branch = wt.branch
 
54
        branch.lock_write()
 
55
        try:
 
56
            branch.repository.start_write_group()
 
57
            try:
 
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"
 
64
                    "revisions")
 
65
            except:
 
66
                branch.repository.abort_write_group()
 
67
                raise
 
68
            else:
 
69
                branch.repository.commit_write_group()
 
70
        finally:
 
71
            branch.unlock()
 
72
        # A signature without a revision should not be accessible.
 
73
        self.assertRaises(errors.NoSuchRevision,
 
74
                          branch.repository.has_signature_for_revision_id,
 
75
                          'A')
 
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'))
 
80
 
 
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
 
85
        repo.lock_write()
 
86
        repo.start_write_group()
 
87
        repo.sign_revision('A', gpg.LoopbackGPGStrategy(None))
 
88
        repo.commit_write_group()
 
89
        repo.unlock()
 
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'))