@@ -239,6 +239,46 @@ def test_client_auth_redirect(server):
239239 assert len (server .calls ) == 2
240240
241241
242+ def test_client_auth_redirect_web_login (server ):
243+ """Ensure web login session token is used when redirect is required.
244+ Regression test: https://github.com/palazzem/econnect-python/issues/158
245+ """
246+ redirect = """
247+ {
248+ "SessionId": "00000000-0000-0000-0000-000000000000",
249+ "Domain": "domain",
250+ "Redirect": true,
251+ "RedirectTo": "https://redirect.example.com"
252+ }
253+ """
254+ login = """
255+ {
256+ "SessionId": "99999999-9999-9999-9999-999999999999",
257+ "Username": "test",
258+ "Domain": "domain",
259+ "Language": "en",
260+ "IsActivated": true,
261+ "IsConnected": true,
262+ "IsLoggedIn": false,
263+ "IsLoginInProgress": false,
264+ "CanElevate": true,
265+ "AccountId": 100,
266+ "IsManaged": false,
267+ "Redirect": false,
268+ "IsElevation": false
269+ }
270+ """
271+ server .add (responses .GET , "https://connect.elmospa.com/api/login" , body = redirect , status = 200 )
272+ server .add (responses .GET , "https://redirect.example.com/api/login" , body = login , status = 200 )
273+ server .add (responses .POST , "https://webservice.elmospa.com/domain" , body = r .STATUS_PAGE , status = 200 )
274+ client = ElmoClient (base_url = ELMO_E_CONNECT , domain = "domain" )
275+ # Test
276+ assert client .auth ("test" , "test" )
277+ assert len (server .calls ) == 3
278+ assert client ._router ._base_url == "https://redirect.example.com"
279+ assert client ._session_id == "f8h23b4e-7a9f-4d3f-9b08-2769263ee33c"
280+
281+
242282def test_client_auth_infinite_redirect (server ):
243283 """Should prevent infinite redirects in the auth() call."""
244284 redirect = """
@@ -349,16 +389,16 @@ def test_client_poll(server):
349389
350390
351391def test_client_auth_econnect_web_login (server ):
352- """Web login should be used when accessing with e-Connect.
392+ """Ensure API and Web login are executed when using e-Connect cloud API .
353393 Regression test: https://github.com/palazzem/econnect-python/issues/158
354394 """
395+ server .add (responses .GET , "https://connect.elmospa.com/api/login" , body = r .LOGIN , status = 200 )
355396 server .add (responses .POST , "https://webservice.elmospa.com/domain" , body = r .STATUS_PAGE , status = 200 )
356- server .add (responses .GET , f"{ ELMO_E_CONNECT } /api/login" , body = r .LOGIN , status = 200 )
357397 client = ElmoClient (base_url = ELMO_E_CONNECT , domain = "domain" )
358398 # Test
359399 client .auth ("test" , "test" )
360- request_body = dict (item .split ("=" ) for item in server .calls [0 ].request .body .split ("&" ))
361400 assert len (server .calls ) == 2
401+ request_body = dict (item .split ("=" ) for item in server .calls [1 ].request .body .split ("&" ))
362402 assert client ._session_id == "f8h23b4e-7a9f-4d3f-9b08-2769263ee33c"
363403 assert request_body == {
364404 "IsDisableAccountCreation" : "True" ,
@@ -373,28 +413,14 @@ def test_client_auth_econnect_web_login_metronet(server):
373413 """Web login should NOT be used when accessing with Metronet.
374414 Regression test: https://github.com/palazzem/econnect-python/issues/158
375415 """
376- server .add (responses .GET , f" { IESS_METRONET } /api/login" , body = r .LOGIN , status = 200 )
416+ server .add (responses .GET , "https://metronet.iessonline.com /api/login" , body = r .LOGIN , status = 200 )
377417 client = ElmoClient (base_url = IESS_METRONET , domain = "domain" )
378418 # Test
379419 client .auth ("test" , "test" )
380420 assert client ._session_id == "00000000-0000-0000-0000-000000000000"
381421 assert len (server .calls ) == 1
382422
383423
384- def test_client_auth_econnect_web_login_forbidden (server ):
385- """Should raise an exception if credentials are not valid in the web login form."""
386- server .add (
387- responses .POST , "https://webservice.elmospa.com/domain" , body = "Username or Password is invalid" , status = 403
388- )
389- client = ElmoClient (base_url = ELMO_E_CONNECT , domain = "domain" )
390- # Test
391- with pytest .raises (CredentialError ):
392- client .auth ("test" , "test" )
393- assert client ._session_id is None
394- assert client ._panel is None
395- assert len (server .calls ) == 1
396-
397-
398424def test_client_poll_with_changes (server ):
399425 """Should return a dict with updated states."""
400426 html = """
0 commit comments