def test_comment_login_logout(self): user = ("test_" + generate_random()).lower() pwd = "pwd123" rv = self.login(user, pwd) self.assertEqual(200, rv.status_code) self.assertIn(b"No valid username found", rv.data) exec_createuser(user, pwd) rv = self.login(user, pwd) data = rv.get_json() self.assertIsInstance(data, dict) self.assertIn("sid", data) self.assertIn("code", data) self.assertIn("expire", data) self.assertEqual(data["code"], 0) with self.app.test_request_context(): self.app.preprocess_request() (signin, userinfo) = default_login_auth(data["sid"]) self.assertTrue(signin) self.assertIsInstance(userinfo, dict) self.assertEqual(user, userinfo["username"]) rv = self.client.get("/api/config") self.assertEqual(405, rv.status_code) rv = self.client.post("/api/config") self.assertEqual(403, rv.status_code) self.logout() rv = self.client.post("/api/config") self.assertEqual(404, rv.status_code)
def test_admin(self): user = "******" + generate_random() pwd = "pwd123" exec_createuser(user, pwd, is_admin=1) rv = self.login(user, pwd) self.assertIn(b"sid", rv.data) rv = self.client.post("/api/config", data=dict(hello='world')) self.assertEqual(200, rv.status_code) site = get_site_config() self.assertIn("hello", site) self.assertEqual(site["hello"], "world") hm = self.app.extensions["hookmanager"] self.client.post("/api/hook?Action=disable", data=dict(name='up2local')) self.assertEqual(2, len(hm.get_enabled_hooks)) self.client.post("/api/hook?Action=enable", data=dict(name='up2local')) self.assertEqual(3, len(hm.get_enabled_hooks))