Skip to content

Commit

Permalink
Merge pull request #62 from TheManWhoLikesToCode/51-p2-file-mangement…
Browse files Browse the repository at this point in the history
…-test-coverage-increase

51 p2 file management test coverage increase
  • Loading branch information
TheManWhoLikesToCode authored Jan 24, 2024
2 parents 6a0ae6b + 748aec3 commit c5e0bc4
Show file tree
Hide file tree
Showing 21 changed files with 718 additions and 205 deletions.
1 change: 1 addition & 0 deletions .github/workflows/BDD-Tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ jobs:
env:
TEST_USERNAME: ${{ secrets.TEST_USERNAME }}
TEST_PASSWORD: ${{ secrets.TEST_PASSWORD }}
ENVIRONMENT: dev
run: |
cd backend
behave
23 changes: 13 additions & 10 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
backend/client_secrets.json
backend/.env
backend/credentials.json
backend/support/.DS_Store

client_secrets.json
mycreds.txt
backend/.env

frontend/.env
frontend/.DS_Store

*.pyc
*.DS_Store
backend/support/.DS_Store

credentials.json
backend/credentials.json

.DS_Store
frontend/.DS_Store
backend/support/.DS_Store
frontend/.DS_Store
frontend/.DS_Store
.DS_Store
frontend/.DS_Store
*.env

*.env

.vscode
11 changes: 7 additions & 4 deletions backend/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import logging
import os
import threading
import time

from dotenv import load_dotenv
from flask import Flask, abort, after_this_request, jsonify, make_response, request, send_from_directory
Expand Down Expand Up @@ -71,7 +70,11 @@ def index():
@app.route('/login', methods=['POST'])
@cross_origin(supports_credentials=True)
def login():
data = request.json
try:
data = request.get_json()
except Exception as e:
return jsonify({'error': 'Invalid JSON format'}), 400

username = data.get('username')
password = data.get('password')

Expand All @@ -89,7 +92,7 @@ def login():
bb_session_manager.put_bb_session(username, bb_session)

resp = make_response(
jsonify({'message': 'Logged in successfully'}))
jsonify({'message': 'Logged in successfully'}), 200)
resp.set_cookie('user_session', bb_session.session_id,
max_age=3600, secure=True, httponly=True)
return resp
Expand All @@ -107,7 +110,7 @@ def logout():
user_session = request.cookies.get('user_session')
if user_session:
# Remove the session from BlackboardSessionManager
bb_session_manager.delete_bb_session(user_session)
bb_session_manager.delete_bb_session_by_id(user_session)

# Clear the user's session cookie
resp = make_response(jsonify({'message': 'Logged out successfully'}))
Expand Down
13 changes: 12 additions & 1 deletion backend/blackboard_session_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,18 @@ def delete_bb_session(self, username):
with self.lock:
session_id = self.user_session_map.pop(username, None)
if session_id:
return self.bb_sessions.pop(session_id, None)
del self.bb_sessions[session_id]
return True
return False

def delete_bb_session_by_id(self, session_id):
with self.lock:
for user, sid in self.user_session_map.items():
if sid == session_id:
del self.user_session_map[user]
del self.bb_sessions[session_id]
return True
return False

def clean_up_inactive_sessions(self, inactivity_threshold_seconds=3600):
with self.lock:
Expand Down
51 changes: 51 additions & 0 deletions backend/features/app_login.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
Feature: Backend Flask App - Login
In order to protect directory
As a system
I want users to have to login

Scenario: Successful Login
Given the app is running
When I pass valid credentials to the login endpoint
Then the response of "200" and "Logged in successfully" should be returned
And cookies should be set

Scenario: Unsuccessful Login - Incorrect username and password
Given the app is running
When I pass an incorrect username and password to the login endpoint
Then the response of "401" and "The username you entered cannot be identified." should be returned

Scenario: Unsuccessful Login - Incorrect password
Given the app is running
When I pass an incorrect password to the login endpoint
Then the response of "401" and "The password you entered was incorrect." should be returned

Scenario: Unsuccessful Login - Incorrect username
Given the app is running
When I pass an incorrect username to the login endpoint
Then the response of "401" and "The username you entered cannot be identified." should be returned

Scenario: Unsuccessful Login - Missing password
Given the app is running
When I pass only a username to the login endpoint
Then the response of "400" and "Missing username or password" should be returned

Scenario: Unsuccessful Login - Missing username
Given the app is running
When I pass only a password to the login endpoint
Then the response of "400" and "Missing username or password" should be returned

Scenario: Unsuccessful Login - Missing username and password
Given the app is running
When I pass no credentials to the login endpoint
Then the response of "400" and "Missing username or password" should be returned

Scenario: Unsuccessful Login - Invalid JSON Format in Request
Given the app is running
When I pass data in an invalid JSON format to the login endpoint
Then the response of "400" and "Invalid JSON format" should be returned

Scenario: Already Logged In
Given the app is running
And the user is already logged in
When I pass valid credentials to the login endpoint
Then the response of "200" and "Already logged in" should be returned
16 changes: 16 additions & 0 deletions backend/features/bb_session_enable_instructors_and_time.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Feature: Blackboard Session - Enable Insturctors and Time
In order to correctly name courses
As a system
I want to enable instructors and course season

Scenario: Enable instructors when logged in
Given I have valid credentials
And I am logged in
When I enable instructors
Then the enable instructors response should be "Instructors enabled"

Scenario: Enable instructors when not logged in
Given I have invalid username and password
And I am not logged in
When I enable instructors
Then the enable instructors response should be "Not logged in."
16 changes: 16 additions & 0 deletions backend/features/bb_session_get_courses.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Feature: Blackboard Session - Get Courses
In order to archive courses for the user
As a system
I want to get courses

Scenario: Get courses when logged in
Given I have valid credentials
And I am logged in
When I get courses
Then the get courses response should be "Courses retrieved"

Scenario: Get courses when not logged in
Given I have invalid username and password
And I am not logged in
When I get courses
Then the get courses response should be "Not logged in."
16 changes: 16 additions & 0 deletions backend/features/bb_session_get_download_tasks.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Feature: Blackboard Session - Get Download Tasks
In order to return the courses to the user
As a system
I want to get the download tasks

Scenario: Get download tasks when logged in
Given I have valid credentials
And I am logged in
When I get download tasks
Then the get download tasks response should be "Download tasks retrieved"

Scenario: Get download tasks when not logged in
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."
20 changes: 20 additions & 0 deletions backend/features/bb_session_login.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Feature: Blackboard Session - Login
In order to access Blackboard
As a system
I want to login

Scenario: Valid credentials login
Given I have valid credentials
When I login
Then the response should be "Login successful."

Scenario: Invalid both username and password
Given I have invalid username and password
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."
15 changes: 15 additions & 0 deletions backend/features/bb_session_manager_creating_sessions.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Feature: Blackboard Sesssion Manager - Creating a new session for a user
In order to use blackboard
As a user
I want to create a new session

Scenario: Creating a new blackboard session for a user
Given a blackboard session manager
When I request a session for user "Alice"
Then a new session should be created for "Alice"

Scenario: Storing a blackboard session for a user
Given a blackboard session manager
And a blackboard session for user "Charlie"
When I store the session for user "Charlie"
Then the session for "Charlie" should be stored in the manager
27 changes: 27 additions & 0 deletions backend/features/bb_session_manager_deleting_sessions.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
Feature: Blackboard Session Manager - Deleting Sessions
In order to correctly delete user data
As a system
I want to delete blackboard sessions

Scenario: Deleting a blackboard session for a user
Given a blackboard session manager
And an existing session for user "Eve"
When I delete the session for user "Eve"
Then the session for "Eve" should be removed

Scenario: Cleaning up inactive sessions
Given a blackboard session manager
And inactive sessions older than 3600 seconds
When I clean up inactive sessions
Then all sessions older than 3600 seconds should be removed

Scenario: Attempting to delete a session for a non-existent user
Given a blackboard session manager
When I delete the session for user "NonExistentUser"
Then no session should be removed

Scenario: Cleaning up with no inactive sessions
Given a blackboard session manager
And no inactive sessions
When I clean up inactive sessions
Then no session should be removed
10 changes: 10 additions & 0 deletions backend/features/bb_session_manager_modifying_sessions.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Feature: Blackboard session management - Modifying users sessions
In order to modify users sessions to keep them alive
As a blackboard administrator
I want to be able to modify users sessions

Scenario: Updating the last activity time of a session
Given a blackboard session manager
And an existing session for user "George"
When I update the last activity time for "George"'s session
Then the last activity time for "George"'s session should be updated
38 changes: 38 additions & 0 deletions backend/features/bb_session_manager_retrieving_sessions.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
Feature: Blackboard Session Manager: Retrieving a session
In order to keep track of users
As a system
I want to be able to retrieve a blackboard session for a user

Scenario: Retrieving an existing blackboard session for a user
Given a blackboard session manager
And an existing session for user "Bob"
When I request a session for user "Bob"
Then the existing session for "Bob" should be returned

Scenario: Retrieving a blackboard session by username
Given a blackboard session manager
And an existing session for user "David"
When I retrieve a session by username "David"
Then the session for "David" should be returned

Scenario: Retrieving a blackboard session by session ID
Given a blackboard session manager
And an existing session with ID "session123"
When I retrieve a session by session ID "session123"
Then the session with ID "session123" should be returned

Scenario: Attempting to retrieve a session for a non-existent user
Given a blackboard session manager
When I retrieve a session by username "NonExistentUser"
Then no session should be returned

Scenario: Attempting to retrieve a session with a non-existent session ID
Given a blackboard session manager
When I retrieve a session by session ID "nonExistentSession123"
Then no session should be returned

Scenario: Multiple users sharing the same session ID
Given a blackboard session manager
And an existing session with ID "sharedSession123" for users "Harry" and "Irene"
When I retrieve a session by session ID "sharedSession123"
Then the same session should be returned for both "Harry" and "Irene"
53 changes: 0 additions & 53 deletions backend/features/blackboard_session.feature

This file was deleted.

7 changes: 7 additions & 0 deletions backend/features/environment.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from app import app

def before_all(context):
context.client = app.test_client()

def after_scenario(context, scenario):
context.client.post('/logout')
Loading

0 comments on commit c5e0bc4

Please sign in to comment.