'Any unexpected exception raised by the credential factory\'s C{decode}
method results in a 500 response code and causes the exception to be
logged.'

def test_unexpectedDecodeError(self):

    class UnexpectedException(Exception, ):
        pass
    class BadFactory(object, ):
        scheme = 'bad'
        def getChallenge(self, client):
            return {}
        def decode(self, response, request):
            raise UnexpectedException()
    self.credentialFactories.append(BadFactory())
    request = self.makeRequest([self.childName])
    request.requestHeaders.addRawHeader('authorization', 'Bad    abc')
    child = getChildForRequest(self.wrapper, request)
    request.render(child)
    self.assertEqual(request.responseCode, 500)
    self.assertEqual(len(self.flushLoggedErrors(UnexpectedException)), 1)
