2424
2525package hudson .bugs ;
2626
27- import static org .junit .Assert .assertFalse ;
28- import static org .junit .Assert .assertTrue ;
27+ import static org .junit .jupiter . api . Assertions .assertFalse ;
28+ import static org .junit .jupiter . api . Assertions .assertTrue ;
2929
3030import hudson .model .Slave ;
3131import hudson .model .User ;
3434import java .net .HttpURLConnection ;
3535import java .net .URL ;
3636import java .util .Locale ;
37+ import jenkins .model .Jenkins ;
3738import jenkins .security .s2m .AdminWhitelistRule ;
3839import org .dom4j .Document ;
3940import org .dom4j .Element ;
4041import org .dom4j .io .DOMReader ;
4142import org .htmlunit .Page ;
4243import org .htmlunit .html .HtmlPage ;
4344import org .htmlunit .xml .XmlPage ;
44- import org .junit .Rule ;
45- import org .junit .Test ;
45+ import org .junit .jupiter .api .BeforeEach ;
46+ import org .junit .jupiter .api .Test ;
47+ import org .junit .jupiter .api .extension .RegisterExtension ;
4648import org .jvnet .hudson .test .Email ;
47- import org .jvnet .hudson .test .InboundAgentRule ;
4849import org .jvnet .hudson .test .JenkinsRule ;
49- import org .jvnet .hudson .test .recipes .PresetData ;
50- import org .jvnet .hudson .test .recipes .PresetData .DataSet ;
50+ import org .jvnet .hudson .test .MockAuthorizationStrategy ;
51+ import org .jvnet .hudson .test .junit .jupiter .InboundAgentExtension ;
52+ import org .jvnet .hudson .test .junit .jupiter .WithJenkins ;
5153
5254/**
5355 * Makes sure that the jars that web start needs are readable, even when the anonymous user doesn't have any read access.
5456 *
5557 * @author Kohsuke Kawaguchi
5658 */
57- public class JnlpAccessWithSecuredHudsonTest {
59+ @ WithJenkins
60+ class JnlpAccessWithSecuredHudsonTest {
5861
59- @ Rule
60- public JenkinsRule r = new JenkinsRule ();
62+ @ RegisterExtension
63+ private final InboundAgentExtension inboundAgents = new InboundAgentExtension ();
6164
62- @ Rule
63- public InboundAgentRule inboundAgents = new InboundAgentRule ();
65+ private JenkinsRule r ;
66+
67+ @ BeforeEach
68+ void setUp (JenkinsRule rule ) {
69+ r = rule ;
70+ }
6471
65- @ PresetData (DataSet .NO_ANONYMOUS_READACCESS )
6672 @ Email ("http://markmail.org/message/on4wkjdaldwi2atx" )
6773 @ Test
68- public void anonymousCanAlwaysLoadJARs () throws Exception {
69- inboundAgents .createAgent (r , InboundAgentRule .Options .newBuilder ().name ("test" ).skipStart ().build ());
74+ void anonymousCanAlwaysLoadJARs () throws Exception {
75+ JenkinsRule .DummySecurityRealm realm = r .createDummySecurityRealm ();
76+ r .jenkins .setSecurityRealm (realm );
77+ r .jenkins .setAuthorizationStrategy (new MockAuthorizationStrategy ()
78+ .grant (Jenkins .ADMINISTER ).everywhere ().toAuthenticated ());
79+
80+ inboundAgents .createAgent (r , InboundAgentExtension .Options .newBuilder ().name ("test" ).skipStart ().build ());
7081 JenkinsRule .WebClient wc = r .createWebClient ();
7182 HtmlPage p = wc .withBasicApiToken (User .getById ("alice" , true )).goTo ("computer/test/" );
7283
@@ -87,21 +98,30 @@ public void anonymousCanAlwaysLoadJARs() throws Exception {
8798 }
8899 }
89100
90- @ PresetData (DataSet .ANONYMOUS_READONLY )
91101 @ Test
92- public void anonymousCannotGetSecrets () throws Exception {
93- inboundAgents .createAgent (r , InboundAgentRule .Options .newBuilder ().name ("test" ).skipStart ().build ());
102+ void anonymousCannotGetSecrets () throws Exception {
103+ JenkinsRule .DummySecurityRealm realm = r .createDummySecurityRealm ();
104+ r .jenkins .setSecurityRealm (realm );
105+ r .jenkins .setAuthorizationStrategy (new MockAuthorizationStrategy ()
106+ .grant (Jenkins .READ ).everywhere ().toEveryone ()
107+ .grant (Jenkins .ADMINISTER ).everywhere ().toAuthenticated ());
108+
109+ inboundAgents .createAgent (r , InboundAgentExtension .Options .newBuilder ().name ("test" ).skipStart ().build ());
94110 r .createWebClient ().assertFails ("computer/test/jenkins-agent.jnlp" , HttpURLConnection .HTTP_FORBIDDEN );
95111 }
96112
97- @ PresetData (DataSet .NO_ANONYMOUS_READACCESS )
98113 @ Test
99- public void serviceUsingDirectSecret () throws Exception {
100- Slave slave = inboundAgents .createAgent (r , InboundAgentRule .Options .newBuilder ().name ("test" ).secret ().build ());
114+ void serviceUsingDirectSecret () throws Exception {
115+ JenkinsRule .DummySecurityRealm realm = r .createDummySecurityRealm ();
116+ r .jenkins .setSecurityRealm (realm );
117+ r .jenkins .setAuthorizationStrategy (new MockAuthorizationStrategy ()
118+ .grant (Jenkins .ADMINISTER ).everywhere ().toAuthenticated ());
119+
120+ Slave slave = inboundAgents .createAgent (r , InboundAgentExtension .Options .newBuilder ().name ("test" ).build ());
101121 try {
102122 r .createWebClient ().goTo ("computer/test/jenkins-agent.jnlp?encrypt=true" , "application/octet-stream" );
103123 Channel channel = slave .getComputer ().getChannel ();
104- assertFalse ("SECURITY-206" , channel .isRemoteClassLoadingAllowed ());
124+ assertFalse (channel .isRemoteClassLoadingAllowed (), "SECURITY-206" );
105125 r .jenkins .getExtensionList (AdminWhitelistRule .class ).get (AdminWhitelistRule .class ).setMasterKillSwitch (false );
106126 final File f = new File (r .jenkins .getRootDir (), "config.xml" );
107127 assertTrue (f .exists ());
0 commit comments