def test_standup_start_invalidID(register): auth_logout(register[0]['token']) auth_logout(register[1]['token']) login_return = auth_login("*****@*****.**", "myunsw") login_return2 = auth_login("*****@*****.**", "mygmail") channel = channels_create(login_return['token'], "Test Channel 0", True) u_id = login_return['u_id'] token = login_return['token'] with pytest.raises(ValueError): standup_start(token, 1000, 10), "Channel (based on ID) does not exist"
def standup_sendsuccess(register): auth_logout(register[0]['token']) auth_logout(register[1]['token']) login_return = auth_login("*****@*****.**", "myunsw") login_return2 = auth_login("*****@*****.**", "mygmail") channel = channels_create(login_return['token'], "Test Channel 0", True) u_id = login_return['u_id'] token = login_return['token'] standup_start(token, channel['channel_id'], 20) assert standup_send(token, channel['channel_id'], 'success') == {}
def standup_active_success(register): auth_logout(register[0]['token']) auth_logout(register[1]['token']) login_return = auth_login("*****@*****.**", "myunsw") login_return2 = auth_login("*****@*****.**", "mygmail") channel = channels_create(login_return['token'], "Test Channel 0", True) u_id = login_return['u_id'] token = login_return['token'] assert standup_active(token, channel['channel_id']) == { is_active: False, time_finish: None }
def standup_send_notmember(register): auth_logout(register[0]['token']) auth_logout(register[1]['token']) login_return = auth_login("*****@*****.**", "myunsw") login_return2 = auth_login("*****@*****.**", "mygmail") channel = channels_create(login_return['token'], "Test Channel 0", True) u_id = login_return['u_id'] token = login_return['token'] token1 = login_return2['token'] standup_start(token, 1, 20) with pytest.raises(ValueError): standup_send(token1, 1, 'notmember'), "not a member of the channel"
def standup_send_unactive(register): auth_logout(register[0]['token']) auth_logout(register[1]['token']) login_return = auth_login("*****@*****.**", "myunsw") login_return2 = auth_login("*****@*****.**", "mygmail") channel = channels_create(login_return['token'], "Test Channel 0", True) u_id = login_return['u_id'] token = login_return['token'] with pytest.raises(ValueError): standup_send( token, 1, 'unactive' ), "An active standup is not currently running in this channel"
def standup_sendLongmsg(register): auth_logout(register[0]['token']) auth_logout(register[1]['token']) login_return = auth_login("*****@*****.**", "myunsw") login_return2 = auth_login("*****@*****.**", "mygmail") channel = channels_create(login_return['token'], "Test Channel 0", True) u_id = login_return['u_id'] token = login_return['token'] message = "a" * 1001 standup_start(token, channel['channel_id'], 20) with pytest.raises(ValueError): standup_send(token, channel['channel_id'], message), "Message is more than 1000"
def handle_auth_login(): """ HTTP Route: /auth/login HTTP Method: POST Params: (email, password) Returns JSON: { token, user_id, username, profile_img_url } """ request_data = request.get_json() email = request_data["email"] password = request_data['password'] printColour(" ➤ Logged in: {}".format(email), colour="blue") return jsonify(auth_login(email, password))
def callback(): # The provider gives US a unique authorisation code after we redirect to them # and after the user consents. Get authorization code Google sent back: code = request.args.get("code") # Find out what URL to hit to get tokens that allow you to ask for # things on behalf of a user google_provider_cfg = get_google_provider_configuration() token_endpoint = google_provider_cfg["token_endpoint"] # Prepare and send a request to get tokens request_url = request.url[:4] + "s" + request.url[4:] token_url, headers, body = client.prepare_token_request( token_endpoint, authorization_response=request_url, redirect_url="https://techsuite.dev/api/google/login/callback", code=code) token_response = requests.post( token_url, headers=headers, data=body, auth=(GOOGLE_CLIENT_ID, GOOGLE_CLIENT_SECRET), ) # Parse the tokens! client.parse_request_body_response(json.dumps(token_response.json())) """ Now that you have the necessary tools to get the user’s profile information, you need to ask Google for it. Luckily, OIDC defines a user information endpoint, and its URL for a given provider is standardized in the provider configuration. You can get the location by checking the userinfo_endpoint field in the provider configuration document. """ # Now that you have tokens (yay) let's find and hit the URL # from Google that gives you the user's profile information, # including their Google profile image and email userinfo_endpoint = google_provider_cfg["userinfo_endpoint"] uri, headers, body = client.add_token(userinfo_endpoint) userinfo_response = requests.get(uri, headers=headers, data=body) # You want to make sure their email is verified. # The user authenticated with Google, authorized your # app, and now you've verified their email through Google! if userinfo_response.json().get("email_verified"): unique_id = userinfo_response.json()["sub"] users_email = userinfo_response.json()["email"] picture = userinfo_response.json()["picture"] users_name = userinfo_response.json()["given_name"] else: return "User email not available or not verified by Google.", 400 # Register the user, or log them in # Workaround for Google auth: the callback in the Flask server redirects back # to the homepage and embeds the token and id in the URL like this: # /home/user_id/token # The token and ID are extracted and removed out of the URL and saved to the # client's cookies try: resp_data = auth_signup(users_email, "asdfasdf", users_name) if picture: users_profile_upload_photo(resp_data["token"], resp_data["user_id"], picture) printColour(" ➤ Google auth callback: Signed up: {}, {}".format( users_name, users_email), colour="blue") return redirect("https://techsuite.dev/home/{}/{}".format( resp_data["user_id"], resp_data["token"])) except: resp_data = auth_login(users_email, "asdfasdf") printColour(" ➤ Google auth callback: Logged in: {}, {}".format( users_name, users_email)) return redirect("https://techsuite.dev/home/{}/{}".format( resp_data["user_id"], resp_data["token"]))