Ejemplo n.º 1
0
def get_mocked_session(patch):
    """
    Create a fake session by mocking
    the backend.transceive function
    """
    mocked_backend = get_backend()
    mocked_backend.transceive = MagicMock(get_backend().transceive)
    mocked_backend.transceive.side_effect = [
        b'\x83\x00\x11\x00\x05MV1\xc9\x18o\x802%\xed\x8a2$\xf2\xcf',
        b'\x84\x00\x00'
    ]
    hsm = YubiHsm(backend=mocked_backend)

    auth_key_id = 1
    key_enc = b'\t\x0bG\xdb\xedYVT\x90\x1d\xee\x1c\xc6U\xe4 '
    key_mac = b'Y/\xd4\x83\xf7Y\xe2\x99\t\xa0LE\x05\xd2\xce\n'
    return hsm.create_session(auth_key_id, key_enc, key_mac)
Ejemplo n.º 2
0
    def test_get_device_info_mock_transceive(self):
        """
        Test get_device_info function by mocking the transceive function
        """

        backend = get_backend()
        backend.transceive = MagicMock(backend.transceive,
                                       return_value=_TRANSCEIVE_DEVICE_INFO)

        hsm = YubiHsm(backend)

        info = hsm.get_device_info()
        hsm._backend.transceive.assert_called_once_with(b'\x06\x00\x00')

        self.assertEqual(info.version, (2, 0, 0))
        self.assertEqual(info.serial, 7550140)
        self.assertEqual(info.log_size, 62)
        self.assertEqual(info.log_used, 4)
        self.assertEqual(len(info.supported_algorithms), 47)