@@ -79,10 +79,12 @@ def test_check_ld_so_configuration(monkeypatch, included_configs_glob_dict, othe
79
79
[
80
80
(['include ld.so.conf.d/*.conf\n ' ],
81
81
['/etc/ld.so.conf.d/*.conf' ], []),
82
- (['include ld.so.conf.d/*.conf\n ' , '\n ' , '/custom/path.lib\n ' ],
82
+ (['include ld.so.conf.d/*.conf\n ' , '\n ' , '/custom/path.lib\n ' , '#comment' ],
83
83
['/etc/ld.so.conf.d/*.conf' ], ['/custom/path.lib' ]),
84
84
(['include ld.so.conf.d/*.conf\n ' , 'include /custom/path.conf\n ' ],
85
85
['/etc/ld.so.conf.d/*.conf' , '/custom/path.conf' ], []),
86
+ (['include ld.so.conf.d/*.conf\n ' , '#include /custom/path.conf\n ' , '#/custom/path.conf\n ' ],
87
+ ['/etc/ld.so.conf.d/*.conf' ], []),
86
88
([' \n ' ],
87
89
[], [])
88
90
])
@@ -99,27 +101,75 @@ def mocked_read_file(path):
99
101
assert _other_lines == other_lines
100
102
101
103
102
- @pytest .mark .parametrize (('config_path' , 'run_result ' , 'package_exists ' , 'is_custom ' ),
104
+ @pytest .mark .parametrize (('config_path' , 'package_name ' , 'run_result ' , 'is_modified ' ),
103
105
[
104
- ('/etc/ld.so.conf.d/dyninst-x86_64.conf' , 'dyninst' , True , False ),
105
- ('/etc/ld.so.conf.d/somelib.conf' , CalledProcessError , False , True ),
106
- ('/etc/custom/custom.conf' , 'custom' , False , True )
106
+ ('/etc/ld.so.conf.d/dyninst-x86_64.conf' , 'dyninst' ,
107
+ '.......T. c /etc/ld.so.conf.d/dyninst-x86_64.conf' , False ),
108
+ ('/etc/ld.so.conf.d/dyninst-x86_64.conf' , 'dyninst' ,
109
+ 'S.5....T. c /etc/ld.so.conf.d/dyninst-x86_64.conf' , True ),
110
+ ('/etc/ld.so.conf.d/kernel-3.10.0-1160.el7.x86_64.conf' , 'kernel' ,
111
+ '' , False )
107
112
])
108
- def test_is_included_ld_so_config_custom (monkeypatch , config_path , run_result , package_exists , is_custom ):
113
+ def test_is_modified (monkeypatch , config_path , package_name , run_result , is_modified ):
114
+ def mocked_run (command ):
115
+ assert package_name in command
116
+ if run_result :
117
+ raise CalledProcessError ("message" , command , {'stdout' : run_result })
118
+ return ''
119
+
120
+ monkeypatch .setattr (checkldsoconfiguration , 'run' , mocked_run )
121
+
122
+ _is_modified = checkldsoconfiguration ._is_modified (config_path , package_name )
123
+ assert _is_modified == is_modified
124
+
125
+
126
+ @pytest .mark .parametrize (('config_path' ,
127
+ 'config_contents' , 'run_result' ,
128
+ 'is_installed_rh_signed_package' , 'is_modified' , 'has_effective_lines' ),
129
+ [
130
+ ('/etc/ld.so.conf.d/dyninst-x86_64.conf' ,
131
+ ['/usr/lib64/dyninst\n ' ], 'dyninst' ,
132
+ True , False , True ), # RH sighend package without modification - Not custom
133
+ ('/etc/ld.so.conf.d/dyninst-x86_64.conf' ,
134
+ ['/usr/lib64/my_dyninst\n ' ], 'dyninst' ,
135
+ True , True , True ), # Was modified by user - Custom
136
+ ('/etc/custom/custom.conf' ,
137
+ ['/usr/lib64/custom' ], 'custom' ,
138
+ False , None , True ), # Third-party package - Custom
139
+ ('/etc/custom/custom.conf' ,
140
+ ['#/usr/lib64/custom\n ' ], 'custom' ,
141
+ False , None , False ), # Third-party package without effective lines - Not custom
142
+ ('/etc/ld.so.conf.d/somelib.conf' ,
143
+ ['/usr/lib64/somelib\n ' ], CalledProcessError ,
144
+ None , None , True ), # User created configuration file - Custom
145
+ ('/etc/ld.so.conf.d/somelib.conf' ,
146
+ ['#/usr/lib64/somelib\n ' ], CalledProcessError ,
147
+ None , None , False ) # User created configuration file without effective lines - Not custom
148
+ ])
149
+ def test_is_included_ld_so_config_custom (monkeypatch , config_path , config_contents , run_result ,
150
+ is_installed_rh_signed_package , is_modified , has_effective_lines ):
109
151
def mocked_run (command ):
110
152
assert config_path in command
111
153
if run_result and not isinstance (run_result , str ):
112
- raise CalledProcessError ("message" , [ " command" ] , "result" )
154
+ raise CalledProcessError ("message" , command , "result" )
113
155
return {'stdout' : run_result }
114
156
115
157
def mocked_has_package (model , package_name ):
116
158
assert model is InstalledRedHatSignedRPM
117
159
assert package_name == run_result
118
- return package_exists
160
+ return is_installed_rh_signed_package
161
+
162
+ def mocked_read_file (path ):
163
+ assert path == config_path
164
+ return config_contents
119
165
120
166
monkeypatch .setattr (checkldsoconfiguration , 'run' , mocked_run )
121
167
monkeypatch .setattr (checkldsoconfiguration , 'has_package' , mocked_has_package )
168
+ monkeypatch .setattr (checkldsoconfiguration , '_read_file' , mocked_read_file )
169
+ monkeypatch .setattr (checkldsoconfiguration , '_is_modified' , lambda * _ : is_modified )
122
170
monkeypatch .setattr (os .path , 'isfile' , lambda _ : True )
123
171
124
172
result = checkldsoconfiguration ._is_included_ld_so_config_custom (config_path )
173
+ is_custom = not isinstance (run_result , str ) or not is_installed_rh_signed_package or is_modified
174
+ is_custom &= has_effective_lines
125
175
assert result == is_custom
0 commit comments