Skip to content

Commit

Permalink
Merge pull request #61 from TheManWhoLikesToCode/53-p2-incorrect-hand…
Browse files Browse the repository at this point in the history
…ling-of-logged-in-users

Added logged in catch
  • Loading branch information
TheManWhoLikesToCode authored Jan 22, 2024
2 parents 40d67a4 + d69f45e commit 6a0ae6b
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
2 changes: 2 additions & 0 deletions backend/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
12 changes: 10 additions & 2 deletions backend/blackboard_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand Down
8 changes: 7 additions & 1 deletion backend/features/blackboard_session.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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."
3 changes: 3 additions & 0 deletions backend/features/steps/blackboard_session_steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 6a0ae6b

Please sign in to comment.