@@ -239,6 +239,46 @@ def test_client_auth_redirect(server):
239
239
assert len (server .calls ) == 2
240
240
241
241
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
+
242
282
def test_client_auth_infinite_redirect (server ):
243
283
"""Should prevent infinite redirects in the auth() call."""
244
284
redirect = """
@@ -349,16 +389,16 @@ def test_client_poll(server):
349
389
350
390
351
391
def 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 .
353
393
Regression test: https://github.com/palazzem/econnect-python/issues/158
354
394
"""
395
+ server .add (responses .GET , "https://connect.elmospa.com/api/login" , body = r .LOGIN , status = 200 )
355
396
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 )
357
397
client = ElmoClient (base_url = ELMO_E_CONNECT , domain = "domain" )
358
398
# Test
359
399
client .auth ("test" , "test" )
360
- request_body = dict (item .split ("=" ) for item in server .calls [0 ].request .body .split ("&" ))
361
400
assert len (server .calls ) == 2
401
+ request_body = dict (item .split ("=" ) for item in server .calls [1 ].request .body .split ("&" ))
362
402
assert client ._session_id == "f8h23b4e-7a9f-4d3f-9b08-2769263ee33c"
363
403
assert request_body == {
364
404
"IsDisableAccountCreation" : "True" ,
@@ -373,28 +413,14 @@ def test_client_auth_econnect_web_login_metronet(server):
373
413
"""Web login should NOT be used when accessing with Metronet.
374
414
Regression test: https://github.com/palazzem/econnect-python/issues/158
375
415
"""
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 )
377
417
client = ElmoClient (base_url = IESS_METRONET , domain = "domain" )
378
418
# Test
379
419
client .auth ("test" , "test" )
380
420
assert client ._session_id == "00000000-0000-0000-0000-000000000000"
381
421
assert len (server .calls ) == 1
382
422
383
423
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
-
398
424
def test_client_poll_with_changes (server ):
399
425
"""Should return a dict with updated states."""
400
426
html = """
0 commit comments