1
1
package com .cloudbees .jenkins .support ;
2
2
3
+ import static org .hamcrest .MatcherAssert .assertThat ;
4
+ import static org .hamcrest .Matchers .empty ;
3
5
import static org .junit .Assert .fail ;
4
6
5
7
import com .cloudbees .jenkins .support .api .Component ;
21
23
import com .cloudbees .jenkins .support .impl .UpdateCenter ;
22
24
import hudson .EnvVars ;
23
25
import hudson .ExtensionList ;
26
+ import hudson .Functions ;
24
27
import hudson .model .FreeStyleBuild ;
25
28
import hudson .model .FreeStyleProject ;
26
29
import hudson .model .User ;
27
30
import hudson .model .labels .LabelAtom ;
28
31
import hudson .model .queue .QueueTaskFuture ;
32
+ import hudson .security .ACL ;
29
33
import java .io .BufferedInputStream ;
30
34
import java .io .ByteArrayOutputStream ;
31
35
import java .io .File ;
@@ -88,25 +92,31 @@ public void checkFilterTest() throws Exception {
88
92
// Generate the filtered words
89
93
checker .generateFilteredWords ();
90
94
91
- // Check the components are filtered correctly
92
- assertComponent (
93
- Arrays .asList (
94
- AboutJenkins .class ,
95
- AboutUser .class ,
96
- AgentsConfigFile .class ,
97
- BuildQueue .class ,
98
- ConfigFileComponent .class ,
99
- DumpExportTable .class ,
100
- EnvironmentVariables .class ,
101
- JVMProcessSystemMetricsContents .Agents .class ,
102
- JVMProcessSystemMetricsContents .Master .class ,
103
- SystemConfiguration .class ,
104
- NetworkInterfaces .class ,
105
- NodeMonitors .class ,
106
- UpdateCenter .class ,
107
- SystemProperties .class ,
108
- ThreadDumps .class ),
109
- checker );
95
+ j .jenkins .setSecurityRealm (j .createDummySecurityRealm ());
96
+ try (var ignored = ACL .as (User .getById ("admin" , true ))) {
97
+ // Check the components are filtered correctly
98
+ assertComponent (
99
+ Arrays .asList (
100
+ AboutJenkins .class ,
101
+ AboutUser .class ,
102
+ AgentsConfigFile .class ,
103
+ BuildQueue .class ,
104
+ ConfigFileComponent .class ,
105
+ DumpExportTable .class ,
106
+ EnvironmentVariables .class ,
107
+ JVMProcessSystemMetricsContents .Agents .class ,
108
+ JVMProcessSystemMetricsContents .Master .class ,
109
+ SystemConfiguration .class ,
110
+ NetworkInterfaces .class ,
111
+ NodeMonitors .class ,
112
+ UpdateCenter .class ,
113
+ SystemProperties .class ,
114
+ ThreadDumps .class ),
115
+ checker );
116
+ }
117
+ if (!Functions .isWindows ()) { // some entries for procfs skipped on Windows
118
+ assertThat (checker .unchecked .stream ().map (f -> f .filePattern ).toList (), empty ());
119
+ }
110
120
111
121
// Cancel the job running
112
122
build .cancel (true );
@@ -219,24 +229,25 @@ private static String getFirstEnvVar() {
219
229
220
230
private static class FileChecker {
221
231
private Set <FileToCheck > fileSet = new HashSet <>();
232
+ private Set <FileToCheck > unchecked = new HashSet <>();
222
233
private Set <String > words = new HashSet <>();
223
234
224
235
private FileChecker (Jenkins jenkins ) throws UnknownHostException {
225
236
fileSet .add (of ("manifest.md" , "about" , false ));
226
237
fileSet .add (of ("about.md" , "b" , false ));
227
- fileSet .add (of ("items.md" , "jobs" , false ));
238
+ // fileSet.add(of("items.md", "jobs", false));
228
239
// checksum.md5 is not generated in tests
229
240
230
241
// AboutJenkins -> nodes.md
231
242
// The agent node name should be filtered
232
243
fileSet .add (of ("nodes.md" , AGENT_NAME , true ));
233
244
// AboutUser
234
- fileSet .add (of ("user.md" , "anonymous " , true ));
245
+ fileSet .add (of ("user.md" , "admin " , true ));
235
246
236
- fileSet .add (of ("node-monitors.md" , AGENT_NAME , true ));
247
+ // fileSet.add(of("node-monitors.md", AGENT_NAME, true));
237
248
238
- fileSet .add (of ("admin-monitors.md" , "diagnostics" , false ));
239
- fileSet .add (of ("admin-monitors.md" , "Family" , false ));
249
+ // fileSet.add(of("admin-monitors.md", "diagnostics", false));
250
+ // fileSet.add(of("admin-monitors.md", "Family", false));
240
251
241
252
fileSet .add (of ("nodes/slave/*/config.xml" , AGENT_NAME , true ));
242
253
@@ -293,23 +304,23 @@ private FileChecker(Jenkins jenkins) throws UnknownHostException {
293
304
// system-uptime.txt
294
305
// net/rpc/nfs.txt
295
306
// net/rpc/nfsd.txt
296
- fileSet .add (of ("nodes/master/proc/swaps.txt" , "cpu" , false ));
297
- fileSet .add (of ("nodes/slave/*/proc/swaps.txt" , "cpu" , false ));
307
+ // fileSet.add(of("nodes/master/proc/swaps.txt", "cpu", false));
308
+ // fileSet.add(of("nodes/slave/*/proc/swaps.txt", "cpu", false));
298
309
299
- fileSet .add (of ("nodes/master/proc/cpuinfo.txt" , "cpu" , false ));
300
- fileSet .add (of ("nodes/slave/*/proc/cpuinfo.txt" , "cpu" , false ));
310
+ // fileSet.add(of("nodes/master/proc/cpuinfo.txt", "cpu", false));
311
+ // fileSet.add(of("nodes/slave/*/proc/cpuinfo.txt", "cpu", false));
301
312
302
- fileSet .add (of ("nodes/master/proc/mounts.txt" , "cpu" , false ));
303
- fileSet .add (of ("nodes/slave/*/proc/mounts.txt" , "cpu" , false ));
313
+ // fileSet.add(of("nodes/master/proc/mounts.txt", "cpu", false));
314
+ // fileSet.add(of("nodes/slave/*/proc/mounts.txt", "cpu", false));
304
315
305
- fileSet .add (of ("nodes/master/proc/system-uptime.txt" , "cpu" , false ));
306
- fileSet .add (of ("nodes/slave/*/proc/system-uptime.txt" , "cpu" , false ));
316
+ // fileSet.add(of("nodes/master/proc/system-uptime.txt", "cpu", false));
317
+ // fileSet.add(of("nodes/slave/*/proc/system-uptime.txt", "cpu", false));
307
318
308
- fileSet .add (of ("nodes/master/proc/net/rpc/nfs.txt" , "cpu" , false ));
309
- fileSet .add (of ("nodes/slave/*/proc/net/rpc/nfs.txt" , "cpu" , false ));
319
+ // fileSet.add(of("nodes/master/proc/net/rpc/nfs.txt", "cpu", false));
320
+ // fileSet.add(of("nodes/slave/*/proc/net/rpc/nfs.txt", "cpu", false));
310
321
311
- fileSet .add (of ("nodes/master/proc/net/rpc/nfsd.txt" , "cpu" , false ));
312
- fileSet .add (of ("nodes/slave/*/proc/net/rpc/nfsd.txt" , "cpu" , false ));
322
+ // fileSet.add(of("nodes/master/proc/net/rpc/nfsd.txt", "cpu", false));
323
+ // fileSet.add(of("nodes/slave/*/proc/net/rpc/nfsd.txt", "cpu", false));
313
324
314
325
// NetworkInterfaces --> nodes/master/networkInterface.md, nodes/slave/*/networkInterface.md
315
326
String anIP = getInetAddress ();
@@ -333,6 +344,7 @@ private FileChecker(Jenkins jenkins) throws UnknownHostException {
333
344
// ThreadDumps --> nodes/slave/*/thread-dump.txt, nodes/master/thread-dump.txt
334
345
fileSet .add (of ("nodes/master/thread-dump.txt" , "runnable" , true ));
335
346
fileSet .add (of ("nodes/slave/*/thread-dump.txt" , "runnable" , true ));
347
+ unchecked .addAll (fileSet );
336
348
}
337
349
338
350
private String getUpdateCenterURL (Jenkins jenkins ) {
@@ -393,6 +405,7 @@ private void check(String file, String content) {
393
405
for (FileToCheck value : fileSet ) {
394
406
// If there is a filePattern to check that matches this entry of the bundle, we check
395
407
if (value .match (file )) {
408
+ unchecked .remove (value );
396
409
if (content == null ) {
397
410
fail (String .format ("Error checking the file %s because its content was null" , file ));
398
411
} else {
0 commit comments