From d69f45e6bc36675e7ab31b85b754357e56263de4 Mon Sep 17 00:00:00 2001 From: Jaydin_MacBook <74679492+TheManWhoLikesToCode@users.noreply.github.com> Date: Mon, 22 Jan 2024 13:13:25 -0500 Subject: [PATCH] Added logged in catch --- backend/app.py | 2 ++ backend/blackboard_session.py | 12 ++++++++++-- backend/features/blackboard_session.feature | 8 +++++++- backend/features/steps/blackboard_session_steps.py | 3 +++ 4 files changed, 22 insertions(+), 3 deletions(-) diff --git a/backend/app.py b/backend/app.py index 68030f4..bbbe9b1 100644 --- a/backend/app.py +++ b/backend/app.py @@ -93,6 +93,8 @@ def login(): resp.set_cookie('user_session', bb_session.session_id, max_age=3600, secure=True, httponly=True) return resp + elif response == 'Already logged in.': + return jsonify({'message': 'Already logged in'}), 200 else: return jsonify({'error': response}), 401 except Exception as e: diff --git a/backend/blackboard_session.py b/backend/blackboard_session.py index 147a608..eea82d2 100644 --- a/backend/blackboard_session.py +++ b/backend/blackboard_session.py @@ -146,6 +146,11 @@ def login(self): response -- The response of the login attempt. """ + + if self.is_logged_in == True: + self.set_response("Already logged in.") + return + try: initial_url = "https://blackboard.kettering.edu/" init_response = self._get_initial_url_response(initial_url) @@ -174,8 +179,11 @@ def login(self): # parse the response using Beautiful Soup with html parser soup = BeautifulSoup(login_send_response.content, "html.parser") - # Log the response of soup to be the response of the users payload - login_payload_response = soup.find(class_='alert alert-danger') + try: + # Log the response of soup to be the response of the users payload + login_payload_response = soup.find(class_='alert alert-danger') + except Exception as e: + logging.error(f"An error occurred while finding the payload response: {e}") # If the login_send_response url isn't the same as the login_send_response url if login_send_response.url != int_login_page_response.url and login_payload_response == None: diff --git a/backend/features/blackboard_session.feature b/backend/features/blackboard_session.feature index 1a0f37b..ae17f8b 100644 --- a/backend/features/blackboard_session.feature +++ b/backend/features/blackboard_session.feature @@ -10,6 +10,12 @@ Feature: Blackboard Session Management When I login Then the response should be "The username you entered cannot be identified." + Scenario: I attempt to login when already logged in + Given I have valid credentials + And I am logged in + When I login + Then the response should be "Already logged in." + Scenario: Enable instructors when logged in Given I have valid credentials And I am logged in @@ -44,4 +50,4 @@ Feature: Blackboard Session Management Given I have invalid username and password And I am not logged in When I get download tasks - Then the get download tasks response should be "Not logged in." + Then the get download tasks response should be "Not logged in." \ No newline at end of file diff --git a/backend/features/steps/blackboard_session_steps.py b/backend/features/steps/blackboard_session_steps.py index 5fd9a3d..545f325 100644 --- a/backend/features/steps/blackboard_session_steps.py +++ b/backend/features/steps/blackboard_session_steps.py @@ -35,6 +35,9 @@ def step_impl(context): def step_impl(context): assert context.response == "The username you entered cannot be identified." +@then('the response should be "Already logged in."') +def step_impl(context): + assert context.response == "Already logged in." @given('I am logged in') def step_impl(context):