Ejemplo n.º 1
0
def get_yubikey(stream=sys.stderr):
    """ Sets up YubiKey communication """
    _log('Connecting to the YubiKey...', stream)
    dev = open_device()
    yubikey = YubiKey(dev.driver)
    _log('Connected', stream)
    return yubikey
Ejemplo n.º 2
0
    def _open_oath(self):
        if self._reader_filter:
            dev = self._get_dev_from_reader()
            if dev:
                return OathContextManager(dev)
            else:
                raise ValueError('no_device_custom_reader')

        return OathContextManager(
            open_device(TRANSPORT.CCID, serial=self._current_serial))
Ejemplo n.º 3
0
def _multiply_test_classes_by_devices(
    transports_and_serials,
    create_test_classes,
    create_test_class_context,
):
    '''
    Instantiate device-specific versions of test classes for each combination
    of the given transports and the available devices.

    Each test class returned by create_test_classes is instantiated for each
    combination of transport and device.

    :param transports_and_serials: a sequence of (ykman.util.TRANSPORT,
            ykman.device.YubiKey) pairs, for each of which to instantiate each
            test.
    :param create_test_classes: the additional_tests function that was
            decorated with @device_test_suite or @cli_test_suite.
    :param create_test_class_context: a function which, given a
            ykman.device.Yubikey and a ykman.util.TRANSPORT, returns a
            specialized open_device or ykman_cli function for that device and
            transport.
    :returns: an iterable of instantiated tests and a dict with original test
            class names mapped to sets of test method names that were
            instantiated.
    '''

    tests = []
    covered_test_names = {}

    for (transport, serial) in transports_and_serials:
        with open_device(transports=transport, serial=serial) as dev:
            for test_class in _create_test_classes_for_device(
                    transport, dev, create_test_classes,
                    create_test_class_context):
                orig_name = test_class._original_test_name
                test_names = _get_test_method_names(test_class)
                covered_test_names[orig_name] = (covered_test_names.get(
                    orig_name, set()).union(test_names))
                for test_method_name in test_names:
                    tests.append(test_class(test_method_name))

    return tests, covered_test_names
Ejemplo n.º 4
0
def _yk_piv_ctrl():
    yk = open_device(transports=TRANSPORT.CCID)
    yield PivController(yk.driver)
    yk.close()
Ejemplo n.º 5
0
def _yk():
    yk = open_device(transports=TRANSPORT.CCID)
    yield yk
    yk.close()
Ejemplo n.º 6
0
 def _open_otp(self):
     return OtpContextManager(
         open_device(TRANSPORT.OTP, serial=self._current_serial))