def test_get_valid_token_password(self): print(">>> test_get_valid_token_password") new_user = get_user_model() resp = requests.post(self.public_url + '/api/user'.format(), json=new_user) self.assertEqual(201, resp.status_code) token = get_token_template() resp = requests.post(self.public_url + '/api/token'.format(), json=token) self.assertEqual(200, resp.status_code)
def test_post_authorize_route(self): print(">>> test_post_authorize_route") new_user = get_user_model() resp = requests.post(self.public_url + '/api/user'.format(), json=new_user) print(" >> create_user") self.assertEqual(201, resp.status_code) form = get_form_template(new_user) print(" >> connect_user_oauth") resp = requests.post(self.public_url + '/api/auth/authorize', data=form) self.assertEqual(200, resp.status_code) it = resp.url.find("https://oauth-redirect.googleusercontent.com/") self.assertNotEqual(-1, it)
def test_valid_refresh_token(self): print(">>> test_valid_refresh_token") new_user = get_user_model() resp = requests.post(self.public_url + '/api/user'.format(), json=new_user) print(" >> create_user") refresh_token = resp.json()['extra']['refresh_token'] self.assertEqual(201, resp.status_code) token = get_token_template() token['grant_type'] = "refresh_token" token['refresh_token'] = refresh_token resp = requests.post(self.public_url + '/api/token'.format(), json=token) self.assertEqual(200, resp.status_code)
def test_get_valid_authorization_code(self): print(">>> test_get_valid_authorization_code") new_user = get_user_model() resp = requests.post(self.public_url + '/api/user'.format(), json=new_user) self.assertEqual(201, resp.status_code) code = resp.json()['extra']['access_token'] token = get_token_template() token["grant_type"] = "authorization_code" token["password"] = "******" token["code"] = code token["redirect_uri"] = "" resp = requests.post(self.public_url + '/api/token'.format(), json=token) self.assertEqual(200, resp.status_code)
def test_invalid_post_authorize_route(self): print(">>> test_invalid_post_authorize_route") new_user = get_user_model() resp = requests.post(self.public_url + '/api/user'.format(), json=new_user) print(" >> create_user") self.assertEqual(201, resp.status_code) for bad in ['state', 'client_id', 'response_type', 'redirect_uri', 'username', 'password']: form = get_form_template(new_user) form[bad] = "bad" print(" >> invalid_" + bad + "_user_oauth") resp = requests.post(self.public_url + '/api/auth/authorize', data=form) if resp.status_code == 200: it = resp.text.find("<title>S'inscrire</title>") self.assertNotEqual(it, -1) else: self.assertNotEqual(200, resp.status_code)
def test_get_invalid_refresh_token(self): print(">>> test_get_invalid_refresh_token") new_user = get_user_model() resp = requests.post(self.public_url + '/api/user'.format(), json=new_user) print(" >> create_user") self.assertEqual(201, resp.status_code) print(" >> test_invalid_refresh_token") token = get_token_template() token["grant_type"] = "refresh_token" token['refresh_token'] = "bad" resp = requests.post(self.public_url + '/api/token'.format(), json=token) find = resp.content.decode().title().casefold().find("<Title>Exception: Refresh token not found.".casefold()) self.assertNotEqual(-1, find) print(" >> test_invalid_client_id") token = get_token_template() token['client_id'] = "bad" resp = requests.post(self.public_url + '/api/token'.format(), json=token) find = resp.content.decode().title().casefold().find("<Title>Exception: Invalid application : app_id.".casefold()) self.assertNotEqual(-1, find)
def test_get_invalid_token_password(self): print(">>> test_get_invalid_token_password") new_user = get_user_model() resp = requests.post(self.public_url + '/api/user'.format(), json=new_user) print(" >> create_user") self.assertEqual(201, resp.status_code) for invalid in ['password', 'username']: print(" >> test_invalid_", invalid) token = get_token_template() token[invalid] = "bad" resp = requests.post(self.public_url + '/api/token'.format(), json=token) find = resp.content.decode().title().casefold().find("<Title>Exception: Invalid Username Or Password".casefold()) self.assertNotEqual(-1, find) print(" >> test_invalid_client_id") token = get_token_template() token['client_id'] = "bad" resp = requests.post(self.public_url + '/api/token'.format(), json=token) find = resp.content.decode().title().casefold().find("<Title>Exception: Invalid application : app_id.".casefold()) self.assertNotEqual(-1, find)
def test_get_invalid_authorization_code(self): print(">>> test_get_invalid_authorization_code") new_user = get_user_model() resp = requests.post(self.public_url + '/api/user'.format(), json=new_user) print(" >> create_user") self.assertEqual(201, resp.status_code) print(" >> test_invalid_authorization_code") token = get_token_template() token['grant_type'] = "authorization_code" token['code'] = "bad" token['redirect_uri'] = "" resp = requests.post(self.public_url + '/api/token'.format(), json=token) find = resp.content.decode().title().casefold().find("<Title>Exception: Missing valid code".casefold()) self.assertNotEqual(-1, find) print(" >> test_invalid_client_id") token = get_token_template() token['client_id'] = "bad" resp = requests.post(self.public_url + '/api/token'.format(), json=token) find = resp.content.decode().title().casefold().find("<Title>Exception: Invalid application : app_id.".casefold()) self.assertNotEqual(-1, find)