-
Notifications
You must be signed in to change notification settings - Fork 63
/
Copy pathtest_sign_cryptography.py
29 lines (22 loc) · 1020 Bytes
/
test_sign_cryptography.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
from mock import patch
import os
import unittest
from adb_shell.auth.keygen import keygen
from adb_shell.auth.sign_cryptography import CryptographySigner
from .keygen_stub import open_priv_pub
class TestCryptographySigner(unittest.TestCase):
def setUp(self):
with patch('adb_shell.auth.sign_cryptography.open', open_priv_pub), patch('adb_shell.auth.keygen.open', open_priv_pub):
keygen('tests/adbkey')
self.signer = CryptographySigner('tests/adbkey')
def test_sign(self):
"""Test that the ``Sign`` method does not raise an exception."""
with self.assertRaises(ValueError):
self.signer.Sign(b'notadb')
self.assertTrue(True)
def test_get_public_key(self):
"""Test that the ``GetPublicKey`` method works correctly."""
with patch('{}.open'.format(__name__), open_priv_pub):
with open('tests/adbkey.pub', 'rb') as f:
pub = f.read()
self.assertEqual(pub, self.signer.GetPublicKey())