Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
systemsmanagement:Uyuni:Master:CentOS6-Uyuni-Client-Tools
salt
suppress-missing-fields-typeerror-exception-by-...
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File suppress-missing-fields-typeerror-exception-by-m2cry.patch of Package salt
From 382598141ca558f5b937740a99d3c1ea547ac4c2 Mon Sep 17 00:00:00 2001 From: Aljosha Friemann <a.friemann@automate.wtf> Date: Sat, 5 Aug 2017 03:53:48 +0200 Subject: [PATCH] Suppress missing fields TypeError exception by m2crypto Add logging to the subject parsing Add unit test for x509 module on function _parse_subject Lintfix: unused import Fix unit test on Python3 --- salt/modules/x509.py | 5 +-- tests/unit/modules/test_x509.py | 67 +++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+), 3 deletions(-) create mode 100644 tests/unit/modules/test_x509.py diff --git a/salt/modules/x509.py b/salt/modules/x509.py index b63188dd7d..3d5e32d8b5 100644 --- a/salt/modules/x509.py +++ b/salt/modules/x509.py @@ -335,9 +335,8 @@ def _parse_subject(subject): if val: ret[nid_name] = val nids.append(nid_num) - except TypeError as e: - if e.args and e.args[0] == 'No string argument provided': - pass + except TypeError as err: + log.trace("Missing attribute '%s'. Error: %s", nid_name, err) return ret diff --git a/tests/unit/modules/test_x509.py b/tests/unit/modules/test_x509.py new file mode 100644 index 0000000000..edafe4ff44 --- /dev/null +++ b/tests/unit/modules/test_x509.py @@ -0,0 +1,67 @@ +# -*- coding: utf-8 -*- +# +# Author: Bo Maryniuk <bo@suse.de> +# +# Copyright 2018 SUSE LLC +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Import Salt Testing Libs +from __future__ import absolute_import, print_function, unicode_literals + +try: + import pytest +except ImportError as import_error: + pytest = None + +from tests.support.mixins import LoaderModuleMockMixin +from tests.support.unit import TestCase, skipIf +from tests.support.mock import ( + patch, + MagicMock, + NO_MOCK, + NO_MOCK_REASON +) + +from salt.modules import x509 + + +@skipIf(NO_MOCK, NO_MOCK_REASON) +@skipIf(not bool(pytest), False) +class X509TestCase(TestCase, LoaderModuleMockMixin): + + def setup_loader_modules(self): + return {x509: {}} + + @patch('salt.modules.x509.log', MagicMock()) + def test_private_func__parse_subject(self): + ''' + Test private function _parse_subject(subject) it handles a missing fields + :return: + ''' + class FakeSubject(object): + ''' + Class for faking x509'th subject. + ''' + def __init__(self): + self.nid = {'Darth Vader': 1} + + def __getattr__(self, item): + if item != 'nid': + raise TypeError('A star wars satellite accidentally blew up the WAN.') + + subj = FakeSubject() + x509._parse_subject(subj) + x509.log.trace.assert_called_once() + assert x509.log.trace.call_args[0][0] == "Missing attribute '%s'. Error: %s" + assert x509.log.trace.call_args[0][1] == list(subj.nid.keys())[0] + assert isinstance(x509.log.trace.call_args[0][2], TypeError) -- 2.17.1
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor