/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
1
# Copyright (C) 2013, 2016 Canonical Ltd
6583.4.4 by Reagan Sanders
Split the existing test cases for verify-signatures away from those for sign-my-commits and added test cases covering the --verbose option.
2
# -*- coding: utf-8 -*-
3
#
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.
8
#
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.
13
#
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
6622.1.29 by Jelmer Vernooij
Fix some more tests.
18
"""Black-box tests for brz verify-signatures."""
6583.4.4 by Reagan Sanders
Split the existing test cases for verify-signatures away from those for sign-my-commits and added test cases covering the --verbose option.
19
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
20
from breezy import (
6583.4.4 by Reagan Sanders
Split the existing test cases for verify-signatures away from those for sign-my-commits and added test cases covering the --verbose option.
21
    gpg,
22
    tests,
23
    )
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
24
from breezy.tests.matchers import ContainsNoVfsCalls
6583.4.4 by Reagan Sanders
Split the existing test cases for verify-signatures away from those for sign-my-commits and added test cases covering the --verbose option.
25
26
27
class TestVerifySignatures(tests.TestCaseWithTransport):
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
36
        self.overrideAttr(gpg, 'GPGStrategy', gpg.LoopbackGPGStrategy)
37
38
    def setup_tree(self, location='.'):
39
        wt = self.make_branch_and_tree(location)
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>')
45
        wt.add_parent_tree_id("aghost")
46
        wt.commit("base E", allow_pointless=True, rev_id='E')
47
        return wt
48
49
    def test_verify_signatures(self):
50
        wt = self.setup_tree()
51
        self.monkey_patch_gpg()
52
        self.run_bzr('sign-my-commits')
53
        out = self.run_bzr('verify-signatures', retcode=1)
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
54
        self.assertEqual(('4 commits with valid signatures\n'
6583.4.4 by Reagan Sanders
Split the existing test cases for verify-signatures away from those for sign-my-commits and added test cases covering the --verbose option.
55
                           '0 commits with key now expired\n'
56
                           '0 commits with unknown keys\n'
57
                           '0 commits not valid\n'
58
                           '1 commit not signed\n', ''), out)
59
60
    def test_verify_signatures_acceptable_key(self):
61
        wt = self.setup_tree()
62
        self.monkey_patch_gpg()
63
        self.run_bzr('sign-my-commits')
64
        out = self.run_bzr(['verify-signatures', '--acceptable-keys=foo,bar'],
65
                            retcode=1)
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
66
        self.assertEqual(('4 commits with valid signatures\n'
6583.4.4 by Reagan Sanders
Split the existing test cases for verify-signatures away from those for sign-my-commits and added test cases covering the --verbose option.
67
                           '0 commits with key now expired\n'
68
                           '0 commits with unknown keys\n'
69
                           '0 commits not valid\n'
70
                           '1 commit not signed\n', ''), out)
71
72
    def test_verify_signatures_verbose(self):
73
        wt = self.setup_tree()
74
        self.monkey_patch_gpg()
75
        self.run_bzr('sign-my-commits')
76
        out = self.run_bzr('verify-signatures --verbose', retcode=1)
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
77
        self.assertEqual(
78
            ('4 commits with valid signatures\n'
79
             '  None signed 4 commits\n'
80
             '0 commits with key now expired\n'
81
             '0 commits with unknown keys\n'
82
             '0 commits not valid\n'
83
             '1 commit not signed\n'
84
             '  1 commit by author Alternate <alt@foo.com>\n', ''), out)
6583.4.4 by Reagan Sanders
Split the existing test cases for verify-signatures away from those for sign-my-commits and added test cases covering the --verbose option.
85
86
    def test_verify_signatures_verbose_all_valid(self):
87
        wt = self.setup_tree()
88
        self.monkey_patch_gpg()
89
        self.run_bzr('sign-my-commits')
90
        self.run_bzr(['sign-my-commits', '.', 'Alternate <alt@foo.com>'])
91
        out = self.run_bzr('verify-signatures --verbose')
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
92
        self.assertEqual(('All commits signed with verifiable keys\n'
93
                          '  None signed 5 commits\n', ''), out)
6583.4.4 by Reagan Sanders
Split the existing test cases for verify-signatures away from those for sign-my-commits and added test cases covering the --verbose option.
94
95
96
class TestSmartServerVerifySignatures(tests.TestCaseWithTransport):
97
98
    def monkey_patch_gpg(self):
99
        """Monkey patch the gpg signing strategy to be a loopback.
100
101
        This also registers the cleanup, so that we will revert to
102
        the original gpg strategy when done.
103
        """
104
        # monkey patch gpg signing mechanism
105
        self.overrideAttr(gpg, 'GPGStrategy', gpg.LoopbackGPGStrategy)
106
107
    def test_verify_signatures(self):
108
        self.setup_smart_server_with_call_log()
109
        t = self.make_branch_and_tree('branch')
110
        self.build_tree_contents([('branch/foo', 'thecontents')])
111
        t.add("foo")
112
        t.commit("message")
113
        self.monkey_patch_gpg()
114
        out, err = self.run_bzr(['sign-my-commits', self.get_url('branch')])
115
        self.reset_smart_call_log()
116
        self.run_bzr('sign-my-commits')
117
        out = self.run_bzr(['verify-signatures', self.get_url('branch')])
118
        # This figure represent the amount of work to perform this use case. It
119
        # is entirely ok to reduce this number if a test fails due to rpc_count
120
        # being too low. If rpc_count increases, more network roundtrips have
121
        # become necessary for this use case. Please do not adjust this number
122
        # upwards without agreement from bzr's network support maintainers.
123
        self.assertLength(10, self.hpss_calls)
124
        self.assertLength(1, self.hpss_connections)
125
        self.assertThat(self.hpss_calls, ContainsNoVfsCalls)