Skip to content

Commit 4628770

Browse files
committed
Add test
1 parent 6c2e700 commit 4628770

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

tests/test_wstrust.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
from xml.etree import ElementTree as ET
3232
import os
3333

34+
from msal.wstrust_request import _build_rst, escape_xml
3435
from msal.wstrust_response import *
3536

3637
from tests import unittest
@@ -96,3 +97,16 @@ def test_token_parsing_happy_path(self):
9697
self.assertEqual(result.get("type"), SAML_TOKEN_TYPE_V1)
9798
self.assertIn(b"<saml:Assertion", result.get("token", ""))
9899

100+
101+
class Test_WsTrustRequest(unittest.TestCase):
102+
103+
def test_escape_xml(self):
104+
self.assertEqual(escape_xml('<>&"\''), '&lt;&gt;&amp;&quot;&apos;')
105+
106+
def test_username_xml_injection_is_prevented(self):
107+
malicious = 'admin</wsse:Username><x>INJECTED'
108+
rst = _build_rst(malicious, 'pw', 'urn:x', 'https://x',
109+
'http://docs.oasis-open.org/ws-sx/ws-trust/200512/RST/Issue')
110+
self.assertEqual(rst.count('<wsse:Username>'), 1)
111+
self.assertNotIn('<x>INJECTED', rst)
112+

0 commit comments

Comments
 (0)