Initial commit
[ta/config-manager.git] / cmframework / test / cmlogger_test.py
1 # Copyright 2019 Nokia
2
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 #     http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15 import mock
16 from cmframework.utils.cmlogger import CMMaskFormatter
17
18
19 class Test(object):
20
21     def test_masking_case1(self):
22         record = r'\"compute-3\": {\"hwmgmt\": {\"password\": \"secret\"'
23         formatter = mock.MagicMock()
24         formatter.format.return_value = record
25         maskformatter = CMMaskFormatter(formatter, ['password', 'admin_pass'])
26         log = maskformatter.format(record)
27         assert log == r'\"compute-3\": {\"hwmgmt\": {\"password\": \"*** password ***\"'
28
29     def test_masking_case2(self):
30         record = r'"compute-3": {"hwmgmt": {"password": "secret"'
31         formatter = mock.MagicMock()
32         formatter.format.return_value = record
33         maskformatter = CMMaskFormatter(formatter, ['password', 'admin_pass'])
34         log = maskformatter.format(record)
35         assert log == r'"compute-3": {"hwmgmt": {"password": "*** password ***"'
36
37     def test_masking_case3(self):
38         record = r'\\"compute-3\\": {\\"hwmgmt\\": {\\"password\\": \\"secret\\"'
39         formatter = mock.MagicMock()
40         formatter.format.return_value = record
41         maskformatter = CMMaskFormatter(formatter, ['password', 'admin_pass'])
42         log = maskformatter.format(record)
43         assert log == r'\\"compute-3\\": {\\"hwmgmt\\": {\\"password\\": \\"*** password ***\\"'