Skip to content

Commit

Permalink
Add tests for the POST binding using OneLogin_Saml2_Auth.login_post.
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Schrijver committed Jan 14, 2021
1 parent 6929c40 commit 5537390
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions tests/src/OneLogin/saml2_tests/auth_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,37 @@ def testLoginWithRelayState(self):
self.assertIn('RelayState', parsed_query)
self.assertIn(relay_state, parsed_query['RelayState'])

def testLoginPost(self):
settings_info = self.loadSettingsJSON()
request_data = self.get_request()
auth = OneLogin_Saml2_Auth(self.get_request(), old_settings=settings_info)

url, parameters = auth.login_post()
self.assertEqual(url, 'http://idp.example.com/SSOService.php')
# self.assertEqual(parameters['RelayState'], relay_state)
saml_request = b64decode(parameters['SAMLRequest'])
self.assertTrue(saml_request.startswith(b'<samlp:AuthnRequest'))

hostname = OneLogin_Saml2_Utils.get_self_host(request_data)
self.assertEqual(parameters['RelayState'], 'http://%s/index.html' % hostname)

self.assertIn(b'<ds:SignatureMethod Algorithm="http://www.w3.org/2001/04/xmldsig-more#rsa-sha256"/>', saml_request)
self.assertIn(b'<ds:DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"/>', saml_request)

def testLoginPostWithRelayState(self):
settings_info = self.loadSettingsJSON()
auth = OneLogin_Saml2_Auth(self.get_request(), old_settings=settings_info)
relay_state = 'http://sp.example.com'

url, parameters = auth.login_post(relay_state)
self.assertEqual(url, 'http://idp.example.com/SSOService.php')
self.assertEqual(parameters['RelayState'], relay_state)
saml_request = b64decode(parameters['SAMLRequest'])
self.assertTrue(saml_request.startswith(b'<samlp:AuthnRequest'))

self.assertIn(b'<ds:SignatureMethod Algorithm="http://www.w3.org/2001/04/xmldsig-more#rsa-sha256"/>', saml_request)
self.assertIn(b'<ds:DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"/>', saml_request)

def testLoginSigned(self):
"""
Tests the login method of the OneLogin_Saml2_Auth class
Expand Down

0 comments on commit 5537390

Please sign in to comment.