11from requests import Session
22from bs4 import BeautifulSoup , Tag
33import re
4+ from typing import Any
45
56import config
67import totp
8+ from helpers import send_request
79
810
911def login_with_drexel_connect (session : Session ) -> Session :
10- response = session .get (config .drexel_connect_base_url )
12+ response = send_request (session , config .drexel_connect_base_url , method = "GET" )
13+ assert response .status_code == 200 , "Failed to get Drexel Connect login page"
1114 soup = BeautifulSoup (response .text , "html.parser" )
1215
1316 csrf_token = extract_csrf_token (soup )
@@ -21,26 +24,44 @@ def login_with_drexel_connect(session: Session) -> Session:
2124 }
2225
2326 # this should send the credentials and send the MFA request
24- response = session .post (
25- config .drexel_connect_base_url + form_action_path , data = login_payload
27+ response = send_request (
28+ session ,
29+ config .drexel_connect_base_url + form_action_path ,
30+ data = login_payload ,
31+ method = "POST" ,
2632 )
33+ assert (
34+ response .status_code == 200
35+ ), "Failed to send request to Drexel Connect with username and password"
2736
2837 soup = BeautifulSoup (response .text , "html.parser" )
2938 data = parse_initial_mfa_page (soup )
3039
31- response = session .post (
32- config .drexel_connect_base_url + data ["url" ], data = data ["form-data" ]
40+ response = send_request (
41+ session ,
42+ config .drexel_connect_base_url + data ["url" ],
43+ data = data ["form-data" ],
44+ method = "POST" ,
3345 )
46+ assert (
47+ response .status_code == 200
48+ ), "Failed to request MFA code page from Drexel Connect"
3449 json_response = response .json ()
3550
3651 data = {
3752 json_response ["csrfN" ]: json_response ["csrfV" ],
3853 "_eventId" : json_response ["actValue" ],
3954 }
4055
41- response = session .post (
42- config .drexel_connect_base_url + json_response ["flowExURL" ], data = data
56+ response = send_request (
57+ session ,
58+ config .drexel_connect_base_url + json_response ["flowExURL" ],
59+ data = data ,
60+ method = "POST" ,
4361 )
62+ assert (
63+ response .status_code == 200
64+ ), "Failed to receive MFA code page from Drexel Connect"
4465 soup = BeautifulSoup (response .text , "html.parser" )
4566
4667 parsed_data = parse_final_mfa_page (soup )
@@ -53,9 +74,15 @@ def login_with_drexel_connect(session: Session) -> Session:
5374 "j_mfaToken" : totp_code ,
5475 }
5576
56- response = session .post (
57- config .drexel_connect_base_url + parsed_data ["url" ], data = data
77+ response = send_request (
78+ session ,
79+ config .drexel_connect_base_url + parsed_data ["url" ],
80+ data = data ,
81+ method = "POST" ,
5882 )
83+ assert (
84+ response .status_code == 200
85+ ), "Failed to send MFA code to Drexel Connect (final step)"
5986
6087 return session
6188
@@ -98,7 +125,7 @@ def extract_form_action_path(soup: BeautifulSoup) -> str:
98125 return form_action_path
99126
100127
101- def parse_initial_mfa_page (soup : BeautifulSoup ) -> dict [str , str ]:
128+ def parse_initial_mfa_page (soup : BeautifulSoup ) -> dict [str , Any ]:
102129 data = {}
103130
104131 # get the first script tag that isn't empty
0 commit comments