/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
    )
24
25
26
class TestVerifySignatures(tests.TestCaseWithTransport):
27
28
    def monkey_patch_gpg(self):
29
        """Monkey patch the gpg signing strategy to be a loopback.
30
31
        This also registers the cleanup, so that we will revert to
32
        the original gpg strategy when done.
33
        """
34
        # monkey patch gpg signing mechanism
35
        self.overrideAttr(gpg, 'GPGStrategy', gpg.LoopbackGPGStrategy)
36
37
    def setup_tree(self, location='.'):
38
        wt = self.make_branch_and_tree(location)
6855.4.1 by Jelmer Vernooij
Yet more bees.
39
        wt.commit("base A", allow_pointless=True, rev_id=b'A')
40
        wt.commit("base B", allow_pointless=True, rev_id=b'B')
41
        wt.commit("base C", allow_pointless=True, rev_id=b'C')
42
        wt.commit("base D", allow_pointless=True, rev_id=b'D',
7143.15.2 by Jelmer Vernooij
Run autopep8.
43
                  committer='Alternate <alt@foo.com>')
6973.10.4 by Jelmer Vernooij
Update python3.passing.
44
        wt.add_parent_tree_id(b"aghost")
6855.4.1 by Jelmer Vernooij
Yet more bees.
45
        wt.commit("base E", allow_pointless=True, rev_id=b'E')
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.
46
        return wt
47
48
    def test_verify_signatures(self):
49
        wt = self.setup_tree()
50
        self.monkey_patch_gpg()
51
        self.run_bzr('sign-my-commits')
52
        out = self.run_bzr('verify-signatures', retcode=1)
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
53
        self.assertEqual(('4 commits with valid signatures\n'
7143.15.2 by Jelmer Vernooij
Run autopep8.
54
                          '0 commits with key now expired\n'
55
                          '0 commits with unknown keys\n'
56
                          '0 commits not valid\n'
57
                          '1 commit not signed\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.
58
59
    def test_verify_signatures_acceptable_key(self):
60
        wt = self.setup_tree()
61
        self.monkey_patch_gpg()
62
        self.run_bzr('sign-my-commits')
63
        out = self.run_bzr(['verify-signatures', '--acceptable-keys=foo,bar'],
7143.15.2 by Jelmer Vernooij
Run autopep8.
64
                           retcode=1)
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
65
        self.assertEqual(('4 commits with valid signatures\n'
7143.15.2 by Jelmer Vernooij
Run autopep8.
66
                          '0 commits with key now expired\n'
67
                          '0 commits with unknown keys\n'
68
                          '0 commits not valid\n'
69
                          '1 commit not signed\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.
70
71
    def test_verify_signatures_verbose(self):
72
        wt = self.setup_tree()
73
        self.monkey_patch_gpg()
74
        self.run_bzr('sign-my-commits')
75
        out = self.run_bzr('verify-signatures --verbose', retcode=1)
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
76
        self.assertEqual(
77
            ('4 commits with valid signatures\n'
78
             '  None signed 4 commits\n'
79
             '0 commits with key now expired\n'
80
             '0 commits with unknown keys\n'
81
             '0 commits not valid\n'
82
             '1 commit not signed\n'
83
             '  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.
84
85
    def test_verify_signatures_verbose_all_valid(self):
86
        wt = self.setup_tree()
87
        self.monkey_patch_gpg()
88
        self.run_bzr('sign-my-commits')
89
        self.run_bzr(['sign-my-commits', '.', 'Alternate <alt@foo.com>'])
90
        out = self.run_bzr('verify-signatures --verbose')
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
91
        self.assertEqual(('All commits signed with verifiable keys\n'
92
                          '  None signed 5 commits\n', ''), out)