~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

(jelmer) Support verifying signatures on remote repositories. (Jelmer
 Vernooij)

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
 
29
29
class TestSignatures(per_repository.TestCaseWithRepository):
30
30
 
 
31
    def setUp(self):
 
32
        super(TestSignatures, self).setUp()
 
33
        if not self.repository_format.supports_revision_signatures:
 
34
            raise tests.TestNotApplicable(
 
35
                "repository does not support signing revisions")
 
36
 
31
37
# TODO 20051003 RBC:
32
38
# compare the gpg-to-sign info for a commit with a ghost and
33
39
#     an identical tree without a ghost
34
40
# fetch missing should rewrite the TOC of weaves to list newly available parents.
35
41
 
36
 
    def setUp(self):
37
 
        super(TestSignatures, self).setUp()
38
 
        if not self.repository_format.supports_revision_signatures:
39
 
            raise tests.TestNotApplicable(
40
 
                "repository does not support signing revisions")
41
 
 
42
42
    def test_sign_existing_revision(self):
43
43
        wt = self.make_branch_and_tree('.')
44
44
        wt.commit("base", allow_pointless=True, rev_id='A')
100
100
        self.assertEqual(repo.get_signature_text('A'),
101
101
                         d2.open_repository().get_signature_text('A'))
102
102
 
 
103
    def test_verify_revision_signature_not_signed(self):
 
104
        wt = self.make_branch_and_tree('.')
 
105
        wt.commit("base", allow_pointless=True, rev_id='A')
 
106
        strategy = gpg.LoopbackGPGStrategy(None)
 
107
        self.assertEquals(
 
108
            (gpg.SIGNATURE_NOT_SIGNED, None),
 
109
            wt.branch.repository.verify_revision_signature('A', strategy))
 
110
 
 
111
    def test_verify_revision_signature(self):
 
112
        wt = self.make_branch_and_tree('.')
 
113
        wt.commit("base", allow_pointless=True, rev_id='A')
 
114
        strategy = gpg.LoopbackGPGStrategy(None)
 
115
        repo = wt.branch.repository
 
116
        self.addCleanup(repo.lock_write().unlock)
 
117
        repo.start_write_group()
 
118
        repo.sign_revision('A', strategy)
 
119
        repo.commit_write_group()
 
120
        self.assertEqual('-----BEGIN PSEUDO-SIGNED CONTENT-----\n' +
 
121
                         Testament.from_revision(repo,
 
122
                         'A').as_short_text() +
 
123
                         '-----END PSEUDO-SIGNED CONTENT-----\n',
 
124
                         repo.get_signature_text('A'))
 
125
        self.assertEquals(
 
126
            (gpg.SIGNATURE_VALID, None, ),
 
127
            repo.verify_revision_signature('A', strategy))
 
128
 
103
129
 
104
130
class TestUnsupportedSignatures(per_repository.TestCaseWithRepository):
105
131