Пример #1
0
 def test_one_time_password_with_empty_spaces(self):
     password = Authenticator(
         "\ta\bt\tc\td \te\tf\tg\th").one_time_password()
     self.assertIsNotNone(password)
     password = Authenticator(
         "\ra\rb\rc\rd \re\rf\rg\rh").one_time_password()
     self.assertIsNotNone(password)
Пример #2
0
 def test_one_time_password(self):
     password = self._authenticator.one_time_password()
     self.assertIsNotNone(password)
     self.assertIsNotNone(Authenticator("abcd xyzw a").one_time_password())
     self.assertIsNotNone(Authenticator("abcd xyzw ab").one_time_password())
     self.assertIsNotNone(
         Authenticator("abcd xyzw abcd").one_time_password())
Пример #3
0
    def test_wrong_initiation(self):
        with self.assertRaises(Exception) as context:
            Authenticator(123456)

        self.assertTrue(
            "You must set a str variable as secret!" in str(context.exception))

        with self.assertRaises(Exception) as context:
            Authenticator("abcd")

        self.assertTrue("You must set a secret of minimum 8 characters!" in
                        str(context.exception))

        with self.assertRaises(Exception) as context:
            Authenticator("ĀƯŤĤËŊŦĩÇÁƮŏƦ")

        self.assertTrue("You must set an ascii str variable as secret!" in str(
            context.exception))

        with self.assertRaises(Exception) as context:
            Authenticator(lambda: None)

        self.assertTrue(
            "You must set a str variable as secret!" in str(context.exception))

        with self.assertRaises(Exception) as context:
            Authenticator(123456.789)

        self.assertTrue(
            "You must set a str variable as secret!" in str(context.exception))

        with self.assertRaises(Exception) as context:
            Authenticator([])

        self.assertTrue(
            "You must set a str variable as secret!" in str(context.exception))

        with self.assertRaises(Exception) as context:
            Authenticator(set())

        self.assertTrue(
            "You must set a str variable as secret!" in str(context.exception))

        with self.assertRaises(Exception) as context:
            Authenticator(tuple())

        self.assertTrue(
            "You must set a str variable as secret!" in str(context.exception))

        with self.assertRaises(Exception) as context:
            Authenticator("abcd efg0")

        self.assertTrue("All characters in the secret must be alphabetic!" in
                        str(context.exception))
Пример #4
0
    parser.add_argument('--secret', type=str, help='secret string for user')
    parser.add_argument(
        '--time',
        type=int,
        help='optional delay to generate another new token (default 30 seconds)'
    )
    args = parser.parse_args()

    if len(sys.argv) < 2:
        print('Specify a secret key to use')
        sys.exit(1)

    # Optional bash tab completion support
    try:
        import argcomplete
        argcomplete.autocomplete(parser)
    except ImportError:
        pass

    secret = sys.argv[2]
    authenticator = Authenticator(secret)

    sleep_time = 30
    if len(sys.argv) > 4:
        sleep_time = float(sys.argv[4])

    scheduler = sched.scheduler(time.time, time.sleep)
    scheduler.enter(0, 0, create_one_time_password,
                    (scheduler, authenticator, sleep_time))
    scheduler.run()
 def setUp(self):
     self._authenticator = Authenticator('abcd xyzw abcd xyzw abcd xyzw abcd xyzw')