43
43
if content is None:
45
45
gpg_signing_key=amy@example.com
46
gpg_signing_command=false'''
47
47
super(FakeConfig, self).__init__(content)
50
class TestCommandLine(tests.TestCase):
53
super(TestCommandLine, self).setUp()
54
self.my_gpg = gpg.GPGStrategy(FakeConfig())
56
def test_signing_command_line(self):
57
self.assertEqual(['false', '--clearsign', '-u', 'amy@example.com'],
58
self.my_gpg._command_line())
60
def test_signing_command_line_from_default(self):
61
# Using 'default' for gpg_signing_key will use the mail part of 'email'
62
my_gpg = gpg.GPGStrategy(FakeConfig('''
63
email=Amy <amy@example.com>
64
gpg_signing_key=default
65
gpg_signing_command=false'''))
66
self.assertEqual(['false', '--clearsign', '-u', 'amy@example.com'],
67
my_gpg._command_line())
69
def test_signing_command_line_from_email(self):
70
# Not setting gpg_signing_key will use the mail part of 'email'
71
my_gpg = gpg.GPGStrategy(FakeConfig('''
72
email=Amy <amy@example.com>
73
gpg_signing_command=false'''))
74
self.assertEqual(['false', '--clearsign', '-u', 'amy@example.com'],
75
my_gpg._command_line())
77
def test_checks_return_code(self):
78
# This test needs a unix like platform - one with 'false' to run.
79
# if you have one, please make this work :)
80
self.assertRaises(errors.SigningFailed, self.my_gpg.sign, 'content')
82
def assertProduces(self, content):
83
# This needs a 'cat' command or similar to work.
84
if sys.platform == 'win32':
85
# Windows doesn't come with cat, and we don't require it
86
# so lets try using python instead.
87
# But stupid windows and line-ending conversions.
88
# It is too much work to make sys.stdout be in binary mode.
89
# http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/65443
90
self.my_gpg._command_line = lambda:[sys.executable, '-c',
91
'import sys; sys.stdout.write(sys.stdin.read())']
92
new_content = content.replace('\n', '\r\n')
94
self.assertEqual(new_content, self.my_gpg.sign(content))
96
self.my_gpg._command_line = lambda:['cat', '-']
97
self.assertEqual(content, self.my_gpg.sign(content))
99
def test_returns_output(self):
100
content = "some content\nwith newlines\n"
101
self.assertProduces(content)
103
def test_clears_progress(self):
104
content = "some content\nwith newlines\n"
105
old_clear_term = ui.ui_factory.clear_term
106
clear_term_called = []
109
clear_term_called.append(True)
110
ui.ui_factory.clear_term = clear_term
112
self.assertProduces(content)
114
ui.ui_factory.clear_term = old_clear_term
115
self.assertEqual([True], clear_term_called)
117
def test_aborts_on_unicode(self):
118
"""You can't sign Unicode text; it must be encoded first."""
119
self.assertRaises(errors.BzrBadParameterUnicode,
120
self.assertProduces, u'foo')
123
50
class TestVerify(TestCase):
125
52
def import_keys(self):