Skip to content

Commit

Permalink
Merge pull request #131 from darxriggs/improvements
Browse files Browse the repository at this point in the history
Small Code Improvements
  • Loading branch information
MarkEWaite authored Mar 26, 2023
2 parents 2d89646 + 1ce9306 commit 1324c2c
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public String getGlobalSecurityConfigPage() {
*/
public static List<AuthorizeProjectStrategyDescriptor> getDescriptorsForGlobalSecurityConfigPage() {
List<Descriptor<AuthorizeProjectStrategy>> all = AuthorizeProjectStrategy.all();
List<AuthorizeProjectStrategyDescriptor> r = new ArrayList<AuthorizeProjectStrategyDescriptor>(all.size());
List<AuthorizeProjectStrategyDescriptor> r = new ArrayList<>(all.size());
for (Descriptor<AuthorizeProjectStrategy> d: all) {
if (
d instanceof AuthorizeProjectStrategyDescriptor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ protected static SpecificUsersAuthorizationStrategy getCurrentStrategy(Job<?,?>
protected Object readResolve() throws ObjectStreamException {
SpecificUsersAuthorizationStrategy self = (SpecificUsersAuthorizationStrategy)super.readResolve();
if (self.noNeedReauthentication != null) {
self.setDontRestrictJobConfiguration(self.noNeedReauthentication.booleanValue());
self.setDontRestrictJobConfiguration(self.noNeedReauthentication);
}
return self;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,44 +22,43 @@
* THE SOFTWARE.
*/

package org.jenkinsci.plugins.authorizeproject;
package org.jenkinsci.plugins.authorizeproject

import jenkins.model.Jenkins;
import jenkins.model.Jenkins

st = namespace("jelly:stapler");
st = namespace("jelly:stapler")

def descriptor = Jenkins.instance.getDescriptorOrDie(AuthorizeProjectProperty.class);
def descriptor = Jenkins.instance.getDescriptorOrDie(AuthorizeProjectProperty.class)

def myselfName = descriptor.plugin.shortName;
def myselfName = descriptor.plugin.shortName

// help file for strategy itself.
def strategyRawHelpFile = descriptor.getHelpFile("strategyRaw");
def strategyRawHelpFile = descriptor.getHelpFile("strategyRaw")

if (strategyRawHelpFile != null) {
div(
class: "authorize-project-nested-help",
helpURL: String.format("%s%s", rootURL, strategyRawHelpFile),
myselfName: myselfName,
) {
text("Loading...");
text("Loading...")
}
}

dl() {
descriptor.strategyList.each() { d ->
def helpFile = d.getHelpFile();
dt(d.displayName);
def helpFile = d.getHelpFile()
dt(d.displayName)
if (helpFile != null) {
dd(
class: "authorize-project-nested-help",
helpURL: String.format("%s%s", rootURL, helpFile),
myselfName: myselfName,
) {
text("Loading...");
text("Loading...")
}
} else {
dd("No help available.");
dd("No help available.")
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,6 @@
import hudson.FilePath;
import hudson.Launcher;

/**
*
*/
public class ProjectQueueItemAuthenticatorTest {
@Rule
public JenkinsRule j = new AuthorizeProjectJenkinsRule(SpecificUsersAuthorizationStrategy.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@
import org.junit.Test;
import org.jvnet.hudson.test.JenkinsRule;

/**
*
*/
public class AnonymousAuthorizationStrategyTest {
@Rule
public JenkinsRule j = new AuthorizeProjectJenkinsRule();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,6 @@
import com.gargoylesoftware.htmlunit.xml.XmlPage;
import com.google.common.collect.Sets;

/**
*
*/
public class SpecificUsersAuthorizationStrategyTest {
@Rule
public JenkinsRule j = new AuthorizeProjectJenkinsRule(SpecificUsersAuthorizationStrategy.class);
Expand Down Expand Up @@ -346,8 +343,8 @@ public void testRestInterfaceSuccess() throws Exception {
srcProject.save();

WebClient wc = j.createWebClient();
wc.login("test1", "test1");
wc.login("test1");

// GET config.xml of srcProject (userid is set to test1)
String configXml = getConfigXml(wc.goToXml(String.format("%s/config.xml", srcProject.getUrl())));

Expand Down Expand Up @@ -400,8 +397,8 @@ public void testRestInterfaceFailure() throws Exception {
srcProject.save();

WebClient wc = j.createWebClient();
wc.login("test1", "test1");
wc.login("test1");

// GET config.xml of srcProject (userid is set to admin)
String configXml = getConfigXml(wc.goToXml(String.format("%s/config.xml", srcProject.getUrl())));

Expand Down Expand Up @@ -459,7 +456,7 @@ public void testCliSuccess() throws Exception {
srcProject.save();

WebClient wc = j.createWebClient();
wc.login("test1", "test1");
wc.login("test1");

// GET config.xml of srcProject (userid is set to test1)
String configXml = null;
Expand Down Expand Up @@ -527,8 +524,8 @@ public void testCliFailure() throws Exception {
srcProject.save();

WebClient wc = j.createWebClient();
wc.login("test1", "test1");
wc.login("test1");

// GET config.xml of srcProject (userid is set to admin)
String configXml = null;
{
Expand Down Expand Up @@ -942,8 +939,8 @@ public void testConfigureJobByTheUserIsAllowed() throws Exception {
p.save();

WebClient wc = j.createWebClient();
wc.login("test1", "test1");
wc.login("test1");

j.submit(wc.getPage(p, "configure").getFormByName("config"));
}

Expand All @@ -956,8 +953,8 @@ public void testConfigureJobByAnotherUserIsForbidden() throws Exception {
p.save();

WebClient wc = j.createWebClient();
wc.login("test2", "test2");
wc.login("test2");

try {
j.submit(wc.getPage(p, "configure").getFormByName("config"));
} catch (FailingHttpStatusCodeException e) {
Expand All @@ -976,8 +973,8 @@ public void testDontRestrictJobConfiguration() throws Exception {
p.save();

WebClient wc = j.createWebClient();
wc.login("test2", "test2");
wc.login("test2");

j.submit(wc.getPage(p, "configure").getFormByName("config"));
}

Expand All @@ -996,8 +993,8 @@ public void testConfigureJobBySystemAdminIsAllowed() throws Exception {
p.save();

WebClient wc = j.createWebClient();
wc.login("admin", "admin");
wc.login("admin");

j.submit(wc.getPage(p, "configure").getFormByName("config"));
}

Expand All @@ -1017,7 +1014,7 @@ public void testConfigureJobByJobAdminIsNotAllowed() throws Exception {
p.save();

WebClient wc = j.createWebClient();
wc.login("test2", "test2");
wc.login("test2");

try {
j.submit(wc.getPage(p, "configure").getFormByName("config"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,6 @@
import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail;

/**
*
*/
public class SystemAuthorizationStrategyTest {
@Rule
public JenkinsRule j = new AuthorizeProjectJenkinsRule(SystemAuthorizationStrategy.class);
Expand Down Expand Up @@ -171,7 +168,7 @@ public void testRestInterfaceSuccess() throws Exception {
srcProject.save();

WebClient wc = j.createWebClient();
wc.login("admin", "admin");
wc.login("admin");

// GET config.xml of srcProject
String configXml = getConfigXml(wc.goToXml(String.format("%s/config.xml", srcProject.getUrl())));
Expand Down Expand Up @@ -219,7 +216,7 @@ public void testRestInterfaceFailure() throws Exception {
srcProject.save();

WebClient wc = j.createWebClient();
wc.login("test1", "test1");
wc.login("test1");

// we want to verify that you cannot clone a job even if you can reconfigure a job that uses this strategy
j.getInstance().getDescriptorByType(SystemAuthorizationStrategy.DescriptorImpl.class)
Expand Down Expand Up @@ -276,7 +273,7 @@ public void testCliSuccess() throws Exception {
srcProject.save();

WebClient wc = j.createWebClient();
wc.login("admin", "admin");
wc.login("admin");

// GET config.xml of srcProject
String configXml = null;
Expand Down Expand Up @@ -340,7 +337,7 @@ public void testCliFailure() throws Exception {
srcProject.save();

WebClient wc = j.createWebClient();
wc.login("test1", "test1");
wc.login("test1");

// we want to verify that you cannot clone a job even if you can reconfigure a job that uses this strategy
j.getInstance().getDescriptorByType(SystemAuthorizationStrategy.DescriptorImpl.class).setPermitReconfiguration(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,6 @@
import org.jvnet.hudson.test.JenkinsRule.WebClient;
import org.jvnet.hudson.test.recipes.LocalData;

/**
*
*/
public class TriggeringUsersAuthorizationStrategyTest {
@Rule
public JenkinsRule j = new AuthorizeProjectJenkinsRule();
Expand Down Expand Up @@ -106,7 +103,7 @@ public void testAuthenticate() throws Exception {
// if triggered from a user, run in the privilege of that user.
{
assertNull(p.getLastBuild());
WebClient wc = j.createWebClient().login("test1", "test1");
WebClient wc = j.createWebClient().login("test1");
triggerBuildWithoutParameters(wc, p);
j.waitUntilNoActivity();
FreeStyleBuild b = p.getLastBuild();
Expand All @@ -120,7 +117,7 @@ public void testAuthenticate() throws Exception {
// test with another user.
{
assertNull(p.getLastBuild());
WebClient wc = j.createWebClient().login("test2", "test2");
WebClient wc = j.createWebClient().login("test2");
triggerBuildWithoutParameters(wc, p);
j.waitUntilNoActivity();
FreeStyleBuild b = p.getLastBuild();
Expand Down Expand Up @@ -148,7 +145,7 @@ public void testAuthenticateDownstream() throws Exception {
// if triggered from a user, its downstream runs in the privilege of that user.
{
assertNull(p.getLastBuild());
WebClient wc = j.createWebClient().login("test1", "test1");
WebClient wc = j.createWebClient().login("test1");
triggerBuildWithoutParameters(wc, upstream);
j.waitUntilNoActivity();
FreeStyleBuild b = p.getLastBuild();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@
import hudson.tasks.BuildStepDescriptor;
import hudson.tasks.Builder;

/**
*
*/
public class AuthorizationCheckBuilder extends Builder {

// "transient" is required for exclusion from serialization - see https://jenkins.io/redirect/class-filter/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@

import com.gargoylesoftware.htmlunit.WebResponse;

/**
*
*/
public class AuthorizeProjectJenkinsRule extends JenkinsRule {
private Set<Class<? extends Describable<?>>> enabledStrategiesByClass;
private Set<Class<? extends Describable<?>>> disabledStrategiesByClass;
Expand Down

0 comments on commit 1324c2c

Please sign in to comment.