def test_init(self):
        with patch.object(os, 'urandom',
                          return_value=(b'\xab' * 8)) as mock_method:
            hid_device = TestHIDDevice()
            hid_device.response = HIDDeviceTest.build_response(
                b'\xff' * 4, b'\x86',
                b'\xab' * 8 + b'\x01\x02\x03\x04' + b'\x01\x02\x03\x04\x05')

            dev = hid_transport.HIDDevice('/dev/null')
            dev.handle = hid_device
            dev.init()
            self.assertEqual(dev.capabilities, 0x05)
    def test_init_invalid_nonce(self):
        with patch.object(os, 'urandom',
                          return_value=(b'\xab' * 8)) as mock_method:
            hid_device = TestHIDDevice()
            hid_device.response = HIDDeviceTest.build_response(
                b'\xff' * 4, b'\x86',
                b'\x00' * 8 + b'\x01\x02\x03\x04' + b'\x01\x02\x03\x04\x05')

            dev = hid_transport.HIDDevice('/dev/null')
            dev.handle = hid_device
            with self.assertRaises(exc.DeviceError) as context:
                dev.init()
                self.assertTrue(
                    'Wrong INIT response from device' in context.exception)
 def test_ctap2_enabled(self):
     dev = hid_transport.HIDDevice('/dev/null')
     dev.capabilities = 0x01
     self.assertFalse(dev.ctap2_enabled())
     dev.capabilities = 0x04
     self.assertTrue(dev.ctap2_enabled())