Skip to content

Commit

Permalink
awslabs#35 Adding in tests to cover bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
ericdbarry committed Jul 27, 2019
1 parent a216e70 commit 9e1855b
Showing 1 changed file with 67 additions and 0 deletions.
67 changes: 67 additions & 0 deletions tests/unit/test_saml.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,73 @@ def tests_uses_default_form_values(self, generic_auth, generic_config,
}
)

def test_input_missing_name_attribute(self, generic_auth,
generic_config,
mock_requests_session):
saml_form = (
'<html>'
'<form action="/path/login/">'
'<input debug="true"/>'
'<input name="spam" value="eggs"/>'
'<input name="username"/>'
'<input name="password"/>'
'</form>'
'</html>'
)
mock_requests_session.get.return_value = mock.Mock(
spec=requests.Response, status_code=200, text=saml_form
)
mock_requests_session.post.return_value = mock.Mock(
spec=requests.Response, status_code=200, text=(
'<form><input name="SAMLResponse" '
'value="fakeassertion"/></form>'
)
)
saml_assertion = generic_auth.retrieve_saml_assertion(generic_config)
assert saml_assertion == 'fakeassertion'

mock_requests_session.post.assert_called_with(
"https://example.com/path/login/", verify=True,
data={
'username': 'monty',
'password': 'mypassword',
'spam': 'eggs'
}
)

def test_boolean_presence_attribute(self, generic_auth,
generic_config,
mock_requests_session):
saml_form = (
'<html>'
'<form action="/path/login/">'
'<input boolean-attr name="spam" value="eggs"/>'
'<input name="username"/>'
'<input name="password"/>'
'</form>'
'</html>'
)
mock_requests_session.get.return_value = mock.Mock(
spec=requests.Response, status_code=200, text=saml_form
)
mock_requests_session.post.return_value = mock.Mock(
spec=requests.Response, status_code=200, text=(
'<form><input name="SAMLResponse" '
'value="fakeassertion"/></form>'
)
)
saml_assertion = generic_auth.retrieve_saml_assertion(generic_config)
assert saml_assertion == 'fakeassertion'

mock_requests_session.post.assert_called_with(
"https://example.com/path/login/", verify=True,
data={
'username': 'monty',
'password': 'mypassword',
'spam': 'eggs'
}
)

def test_error_getting_form(self, generic_auth, mock_requests_session,
generic_config):
mock_requests_session.get.return_value = mock.Mock(
Expand Down

0 comments on commit 9e1855b

Please sign in to comment.