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
7 # http://www.apache.org/licenses/LICENSE-2.0
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.
16 from cmframework.utils.cmlogger import CMMaskFormatter
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 ***\"'
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 ***"'
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 ***\\"'