Ejemplo n.º 1
0
    def test_secret(self):
        not_valid = (None, "", 151 * "*")
        with self.assertRaises(ValidationError):
            for s in not_valid:
                Validator.secret(s)

        self.assertIsNone(Validator.secret(30 * "*"))
Ejemplo n.º 2
0
    def test_tries(self):
        not_valid = (-1, 0, 2, 11)
        with self.assertRaises(ValidationError):
            for t in not_valid:
                Validator.tries(t)

        for t in range(3, 11):
            self.assertIsNone(Validator.tries(t))
Ejemplo n.º 3
0
    def test_days(self):
        not_valid = (-1, 0, 8, 10)
        with self.assertRaises(ValidationError):
            for d in not_valid:
                Validator.days(d)

        for d in range(1, 8):
            self.assertIsNone(Validator.days(d))
Ejemplo n.º 4
0
    def test_haveibeenpwned(self, mock_pwned):
        with self.assertRaises(ValidationError):
            mock_pwned.return_value = 123
            Validator.haveibeenpwned("Hello123")

            mock_pwned.side_effect = Exception
            Validator.haveibeenpwned("Hello123j0e32hf")

        mock_pwned.return_value = False
        self.assertIsNone(Validator.haveibeenpwned("cjHeW9ihf9u43f9u4b3"))
Ejemplo n.º 5
0
    def test_secret(self):
        # We need the app context as we need to access the app config
        app = create_app(env="testing")
        app_context = app.app_context()
        app_context.push()

        not_valid = (None, "", 251 * "*")
        for s in not_valid:
            with self.assertRaises(ValidationError):
                Validator.secret(s)

        self.assertIsNone(Validator.secret(30 * "*"))
Ejemplo n.º 6
0
    def test_strength(self):
        not_valid = (
            "weak",
            "Weak",
            "Weak1",
            "weak_but_long",
            "weak_but_long_1",
            "Weak_but_long",
        )
        with self.assertRaises(ValidationError):
            for word in not_valid:
                Validator.strength(word)

        self.assertIsNone(Validator.strength("UPPERlower9211"))
Ejemplo n.º 7
0
 def haveibeenpwned_checker(self, data, **kwargs):
     """Check the passphrase against haveibeenpwned if set to true."""
     if data.get("haveibeenpwned"):
         Validator.haveibeenpwned(data["passphrase"])
Ejemplo n.º 8
0
 def test_slug(self):
     not_valid = (None, "")
     with self.assertRaises(ValidationError):
         for s in not_valid:
             Validator.slug(s)
Ejemplo n.º 9
0
 def test_passphrase(self):
     not_valid = (None, "")
     with self.assertRaises(ValidationError):
         for s in not_valid:
             Validator.passphrase(s)
Ejemplo n.º 10
0
 def test_tries(self):
     not_valid = (0, -1, 15)
     for tries in not_valid:
         with self.assertRaises(ValidationError):
             Validator.tries(tries)
Ejemplo n.º 11
0
 def test_expire(self):
     not_valid = ("80d", "3.5m", "1y", "0", "i do not exist", 23)
     for expire in not_valid:
         with self.assertRaises(ValidationError):
             Validator.expire(expire)