@@ -69,6 +69,56 @@ async def _solve_admin_challenge(self, encrypted_b64: str):
6969
7070 async def load_feedback_page (self ) -> None :
7171 self .validate ()
72+
73+ message_data = generate_admin_message ()
74+ message_text = message_data ["message" ]
75+ message_year = message_data ["year" ]
76+
77+ self .logger .info (f"Posting time traveller message from { message_year } : { message_text [:50 ]} ..." )
78+
79+ response = await self .client .post (
80+ "/login" ,
81+ headers = {"Accept" : "application/json" },
82+ data = {
83+ "username" : self .admin_username ,
84+ "password" : self .admin_password
85+ }
86+ )
87+
88+ if response .status_code not in [200 , 201 , 302 ]:
89+ raise MumbleException ("Failed to login as admin" )
90+
91+ response = await self .client .get ("/admin-challenge" )
92+ if response .status_code != 200 :
93+ raise MumbleException ("Failed to get admin challenge" )
94+
95+ match = re .search (r'<pre[^>]*>(.*?)</pre>' , response .text , re .DOTALL )
96+ if not match :
97+ raise MumbleException ("Could not find encrypted challenge on page" )
98+
99+ encrypted_b64 = match .group (1 ).strip ()
100+
101+ decrypted_text = await self ._solve_admin_challenge (encrypted_b64 )
102+
103+ response = await self .client .post (
104+ "/admin-challenge" ,
105+ headers = {"Accept" : "application/json" },
106+ data = {"decrypted_challenge" : decrypted_text }
107+ )
108+
109+ if response .status_code not in [200 , 201 , 302 ]:
110+ raise MumbleException (f"Failed to submit admin challenge solution: { response .text } , { response .status_code } " )
111+
112+ cookies = []
113+ for ck in self .client .cookies .jar :
114+ cookies .append ({
115+ 'name' : ck .name ,
116+ 'value' : ck .value ,
117+ 'domain' : ck .domain ,
118+ 'path' : ck .path ,
119+ 'httpOnly' : ck .secure ,
120+ 'secure' : ck .secure
121+ })
72122
73123 async with async_playwright () as p :
74124 browser = await p .chromium .launch (
@@ -77,30 +127,13 @@ async def load_feedback_page(self) -> None:
77127 )
78128
79129 try :
80- page = await browser .new_page ()
130+ context = await browser .new_context ()
131+ await context .add_cookies (cookies )
132+
133+ page = await context .new_page ()
81134
82135 page .set_default_timeout (10000 )
83136
84- await page .goto (f"{ self .service_url } /" )
85-
86- await page .fill ('#login-username' , self .admin_username )
87- await page .fill ('#login-password' , self .admin_password )
88-
89- await page .click ('#login-form button[type="submit"]' )
90-
91- await page .wait_for_url (f"{ self .service_url } /admin-challenge" )
92-
93- challenge_form = page .locator ('#admin-challenge-form' )
94- if await challenge_form .count () == 0 :
95- return
96- encrypted_b64 = (await page .inner_text ('pre' )).strip ()
97-
98- decrypted_text = await self ._solve_admin_challenge (encrypted_b64 )
99-
100- await page .fill ('#decrypted_challenge' , decrypted_text )
101- await page .click ('#admin-challenge-form button[type="submit"]' )
102- await page .wait_for_url (f"{ self .service_url } /problems" , timeout = 10_000 )
103-
104137 await page .goto (f"{ self .service_url } /admin/feedback" )
105138
106139 await page .wait_for_url (f"{ self .service_url } /admin/feedback" , timeout = 2000 )
0 commit comments