Skip to content

Commit 4404525

Browse files
committed
Merge branch 'ignore-httperror-for-one-testcase' into dev
2 parents 6613fd0 + 6463b47 commit 4404525

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed

msal/mex.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,25 @@
3333
from xml.etree import cElementTree as ET
3434
except ImportError:
3535
from xml.etree import ElementTree as ET
36+
import logging
3637

3738

39+
logger = logging.getLogger(__name__)
40+
3841
def _xpath_of_root(route_to_leaf):
3942
# Construct an xpath suitable to find a root node which has a specified leaf
4043
return '/'.join(route_to_leaf + ['..'] * (len(route_to_leaf)-1))
4144

4245

4346
def send_request(mex_endpoint, http_client, **kwargs):
44-
mex_document = http_client.get(mex_endpoint, **kwargs).text
45-
return Mex(mex_document).get_wstrust_username_password_endpoint()
47+
mex_resp = http_client.get(mex_endpoint, **kwargs)
48+
mex_resp.raise_for_status()
49+
try:
50+
return Mex(mex_resp.text).get_wstrust_username_password_endpoint()
51+
except ET.ParseError:
52+
logger.exception(
53+
"Malformed MEX document: %s, %s", mex_resp.status_code, mex_resp.text)
54+
raise
4655

4756

4857
class Mex(object):

tests/http_client.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,6 @@ def __init__(self, requests_resp=None, status_code=None, text=None):
2626
self._raw_resp = requests_resp
2727

2828
def raise_for_status(self):
29-
if self._raw_resp:
29+
if self._raw_resp is not None: # Turns out `if requests.response` won't work
30+
# cause it would be True when 200<=status<400
3031
self._raw_resp.raise_for_status()

tests/test_e2e.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -516,9 +516,14 @@ def test_adfs2_fed_user(self):
516516
self._test_username_password(**config)
517517

518518
def test_adfs2019_fed_user(self):
519-
config = self.get_lab_user(usertype="federated", federationProvider="ADFSv2019")
520-
config["password"] = self.get_lab_user_secret(config["lab_name"])
521-
self._test_username_password(**config)
519+
try:
520+
config = self.get_lab_user(usertype="federated", federationProvider="ADFSv2019")
521+
config["password"] = self.get_lab_user_secret(config["lab_name"])
522+
self._test_username_password(**config)
523+
except requests.exceptions.HTTPError:
524+
if os.getenv("TRAVIS"):
525+
self.skipTest("MEX endpoint in our test environment tends to fail")
526+
raise
522527

523528
def test_ropc_adfs2019_onprem(self):
524529
# Configuration is derived from https://github.com/AzureAD/microsoft-authentication-library-for-dotnet/blob/4.7.0/tests/Microsoft.Identity.Test.Common/TestConstants.cs#L250-L259

0 commit comments

Comments
 (0)