def test_validate_token_log_ip(self):
        Validators._validate_admin_token('ADMIN-TOKEN', '1.2.3.4')

        Logger.c.execute("SELECT * FROM logs WHERE category = 'LOGIN_ADMIN'")
        row = Logger.c.fetchone()
        self.assertIn("new ip", row[3])
        self.assertIn("1.2.3.4", row[3])
 def test_sso_different_username(self):
     Config.jwt_secret = "lalla"
     payload = {"username": "******", "firstName": "koh"}
     token = jwt.encode(payload, Config.jwt_secret)
     self._insert_data()
     with self.assertRaises(Forbidden):
         Validators._get_user_from_sso(token, "token")
    def test_validate_invalid_token(self):
        with self.assertRaises(Forbidden) as ex:
            Validators._validate_admin_token('wrong token', '1.2.3.4')

        self.assertIn("Invalid admin token",
                      ex.exception.response.data.decode())

        Logger.c.execute("SELECT * FROM logs WHERE category = 'LOGIN_ADMIN'")
        row = Logger.c.fetchone()
        self.assertIn("login failed", row[3])
        self.assertIn("1.2.3.4", row[3])
 def test_sso_existing_user(self):
     Config.jwt_secret = "lalla"
     self._insert_data()
     payload = {"username": "******", "firstName": "koh"}
     token = jwt.encode(payload, Config.jwt_secret)
     user = Validators._get_user_from_sso(token, "token")
     self.assertEqual("token", user["token"])
 def test_sso_invalid_jwt(self):
     Config.jwt_secret = "lalla"
     self._insert_data()
     with self.assertRaises(Forbidden):
         Validators._get_user_from_sso("uhuhu", "token")
 def test_validate_token_no_token(self, read, extract):
     Database.del_meta("admin_token")
     Validators._validate_admin_token("ADMIN-TOKEN", '1.2.3.4')
     extract.assert_called_once_with("ADMIN-TOKEN")
     read.assert_called_once_with()
 def test_validate_token(self):
     Validators._validate_admin_token('ADMIN-TOKEN', '1.2.3.4')
Ejemplo n.º 8
0
 def test_validate_token(self):
     Validators._validate_admin_token("ADMIN-TOKEN", "1.2.3.4")