File: test_sign_pycryptodome.py

package info (click to toggle)
python-adb-shell 0.4.4-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 792 kB
  • sloc: python: 3,861; makefile: 191; sh: 124
file content (32 lines) | stat: -rw-r--r-- 1,050 bytes parent folder | download
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
30
31
32
import os
import unittest

try:
    from unittest.mock import patch
except ImportError:
    from mock import patch

from adb_shell.auth.keygen import keygen
from adb_shell.auth.sign_pycryptodome import PycryptodomeAuthSigner

from .keygen_stub import open_priv_pub


class TestPycryptodomeAuthSigner(unittest.TestCase):
    def setUp(self):
        with patch('adb_shell.auth.sign_pycryptodome.open', open_priv_pub), patch('adb_shell.auth.keygen.open', open_priv_pub):
            keygen('tests/adbkey')
            self.signer = PycryptodomeAuthSigner('tests/adbkey')

    def test_sign(self):
        """Test that the ``Sign`` method does not raise an exception."""
        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())