Enhance tests for saml2 signing exception logging

There was no test that verified that the log message was generated
correctly when there was an exception from the xmlsec1 binary. The
test shows that the log message isn't generated correctly but
instead causes a TypeError to be raised.

The test__sign_assertion_fileutils_exc test is also enhanced to
verify that the error is logged correctly.

Change-Id: I5b7c22d27bad241339fdacae8b61973d45d55d30
Partial-Bug: 1484735
This commit is contained in:
Brant Knudson 2015-08-13 18:30:28 -05:00
parent 0ca655f9c2
commit e16aa8e5e5
1 changed files with 29 additions and 2 deletions

View File

@ -16,6 +16,7 @@ import subprocess
from testtools import matchers
import uuid
import fixtures
from lxml import etree
import mock
from oslo_config import cfg
@ -3437,12 +3438,38 @@ class SAMLGenerationTests(FederationTests):
create_class_mock.assert_called_with(saml.Assertion, 'fakeoutput')
@mock.patch('oslo_utils.fileutils.write_to_tempfile')
def test__sign_assertion_fileutils_exc(self, write_to_tempfile_mock):
write_to_tempfile_mock.side_effect = Exception('fake')
@mock.patch('subprocess.check_output')
def test__sign_assertion_exc(self, check_output_mock,
write_to_tempfile_mock):
# If the command fails the command output is logged.
write_to_tempfile_mock.return_value = 'tmp_path'
sample_returncode = 1
sample_output = self.getUniqueString()
check_output_mock.side_effect = subprocess.CalledProcessError(
returncode=sample_returncode, cmd=CONF.saml.xmlsec1_binary,
output=sample_output)
# FIXME(blk-u): This should raise exception.SAMLSigningError instead,
# but fails with TypeError due to concatenating string to Message, see
# bug 1484735.
self.assertRaises(TypeError,
keystone_idp._sign_assertion,
self.signed_assertion)
@mock.patch('oslo_utils.fileutils.write_to_tempfile')
def test__sign_assertion_fileutils_exc(self, write_to_tempfile_mock):
exception_msg = 'fake'
write_to_tempfile_mock.side_effect = Exception(exception_msg)
logger_fixture = self.useFixture(fixtures.LoggerFixture())
self.assertRaises(exception.SAMLSigningError,
keystone_idp._sign_assertion,
self.signed_assertion)
expected_log = (
'Error when signing assertion, reason: %s\n' % exception_msg)
self.assertEqual(expected_log, logger_fixture.output)
class IdPMetadataGenerationTests(FederationTests):