def test_32_allowed_serial_numbers(self):
        self.assertTrue(check_serial_valid("TOTP12345"))
        # Blank is not allowed
        self.assertRaises(Exception, check_serial_valid, "TOTP 12345")

        # Minus and underscore is allowed
        self.assertTrue(check_serial_valid("spass-123"))
        self.assertTrue(check_serial_valid("spass_123"))
        # Slash and backslash is not allowed
        self.assertRaises(Exception, check_serial_valid, "spass/123")
        self.assertRaises(Exception, check_serial_valid, "spass\\123")

        # an empty serial is not allowed
        self.assertRaises(Exception, check_serial_valid, "")
Exemple #2
0
    def user_or_serial_wrapper(*args, **kwds):
        # If there is no user and serial keyword parameter and if
        # there is no normal argument, we do not have enough information
        serial = kwds.get("serial")
        user = kwds.get("user")
        # We have no serial! The serial would be the first arg
        if (serial is None and (len(args) == 0 or args[0] is None)
                and (user is None or (user is not None and user.is_empty()))):
            # We either have an empty User object or None
            raise ParameterError(ParameterError.USER_OR_SERIAL)

        if serial:
            check_serial_valid(serial)

        f_result = func(*args, **kwds)
        return f_result