29
29
import java .io .File ;
30
30
import java .net .MalformedURLException ;
31
31
import java .net .URL ;
32
+ import java .nio .file .Files ;
33
+ import java .nio .file .Path ;
32
34
35
+ import jenkins .model .Jenkins ;
36
+ import org .htmlunit .html .HtmlPage ;
33
37
import org .junit .Rule ;
34
38
import org .junit .Test ;
35
39
import org .junit .rules .TemporaryFolder ;
36
40
41
+ import static org .hamcrest .Matchers .containsString ;
42
+ import static org .hamcrest .Matchers .emptyString ;
37
43
import static org .junit .Assert .*;
38
- import org .jvnet .hudson .test .Issue ;
44
+
45
+ import org .jvnet .hudson .test .*;
39
46
40
47
public class ClasspathEntryTest {
41
48
@ Rule public TemporaryFolder rule = new TemporaryFolder ();
42
-
49
+ @ Rule public JenkinsRule jr = new JenkinsRule ();
50
+
51
+ @ Issue ("SECURITY-3447" )
52
+ @ Test
53
+ public void testDoCheckPath () throws Exception {
54
+ jr .jenkins .setSecurityRealm (jr .createDummySecurityRealm ());
55
+ jr .jenkins .setAuthorizationStrategy (new MockAuthorizationStrategy ().
56
+ grant (Jenkins .ADMINISTER ).everywhere ().to ("admin" )
57
+ .grant (Jenkins .READ ).everywhere ().to ("dev" ));
58
+ Path path = Files .createTempDirectory ("temp dir" );
59
+ try (JenkinsRule .WebClient webClient = jr .createWebClient ()) {
60
+ webClient .login ("admin" );
61
+ final HtmlPage adminPage = webClient .goTo ("descriptor/org.jenkinsci.plugins.scriptsecurity.scripts.ClasspathEntry/checkPath?value=" + path .toUri ());
62
+ final String adminContent = adminPage .asXml ();
63
+ assertThat (adminContent , containsString ("Class directories are not allowed as classpath entries." ));
64
+ }
65
+ try (JenkinsRule .WebClient devWebClient = jr .createWebClient ()) {
66
+ devWebClient .login ("dev" );
67
+ final HtmlPage devPage = devWebClient .goTo ("descriptor/org.jenkinsci.plugins.scriptsecurity.scripts.ClasspathEntry/checkPath?value=" + path .toUri ());
68
+ final String devContent = devPage .asNormalizedText ();
69
+ assertThat (devContent , emptyString ());
70
+ }
71
+ Files .deleteIfExists (path );
72
+
73
+ }
74
+
75
+ @ WithoutJenkins
43
76
@ Test public void pathURLConversion () throws Exception {
44
77
if (!Functions .isWindows ()) {
45
78
assertRoundTrip ("/tmp/x.jar" , "file:/tmp/x.jar" );
@@ -54,6 +87,7 @@ private static void assertRoundTrip(String path, String url) throws Exception {
54
87
assertEquals (url , ClasspathEntry .pathToURL (path ).toString ());
55
88
}
56
89
90
+ @ WithoutJenkins
57
91
@ Test public void classDirDetected () throws Exception {
58
92
final File tmpDir = rule .newFolder ();
59
93
assertTrue ("Existing directory must be detected" , ClasspathEntry .isClassDirectoryURL (tmpDir .toURI ().toURL ()));
@@ -67,6 +101,7 @@ private static void assertRoundTrip(String path, String url) throws Exception {
67
101
assertFalse ("Generic URLs ending in / are not considered class directories" , ClasspathEntry .isClassDirectoryURL (new URL ("http://example.com/file" )));
68
102
}
69
103
104
+ @ WithoutJenkins
70
105
@ Issue ("JENKINS-37599" )
71
106
@ Test public void pathToURL () throws Exception {
72
107
ClasspathEntry ignore = new ClasspathEntry ("http://nowhere.net/" );
0 commit comments