Skip to content

Commit

Permalink
JENKINS-73941 - Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Antonio Muniz <[email protected]>
  • Loading branch information
jgarciacloudbees and amuniz authored Oct 24, 2024
1 parent af7eee1 commit fec6912
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ private PendingClasspathEntry getPendingClasspathEntry(@NonNull String hash) {
}

/* for test */ void addPendingClasspathEntry(PendingClasspathEntry pcp) {
if(!forceSandboxForCurrentUser()) {
if (!forceSandboxForCurrentUser()) {
pendingClasspathEntries.add(pcp);
}
}
Expand Down Expand Up @@ -657,7 +657,7 @@ public synchronized String configuring(@NonNull String script, @NonNull Language
if (key != null) {
pendingScripts.removeIf(pendingScript -> key.equals(pendingScript.getContext().getKey()));
}
if(!forceSandboxForCurrentUser()) {
if (!forceSandboxForCurrentUser()) {
pendingScripts.add(new PendingScript(script, language, context));
}
}
Expand Down Expand Up @@ -822,8 +822,8 @@ public synchronized FormValidation checking(@NonNull String script, @NonNull Lan
}

if (!Jenkins.get().hasPermission(Jenkins.ADMINISTER)) {
return FormValidation.warningWithMarkup(forceSandboxForCurrentUser()?
Messages.ScriptApproval_ForceSandBoxMessage():
return FormValidation.warningWithMarkup(forceSandboxForCurrentUser() ?
Messages.ScriptApproval_ForceSandBoxMessage() :
Messages.ScriptApproval_PipelineMessage());
} else {
if ((ALLOW_ADMIN_APPROVAL_ENABLED && (willBeApproved || ADMIN_AUTO_APPROVAL_ENABLED)) || !Jenkins.get().isUseSecurity()) {
Expand Down Expand Up @@ -1003,7 +1003,7 @@ public boolean isForceSandbox() {
}

//ForceSandbox restrictions does not apply to ADMINISTER users.
public boolean forceSandboxForCurrentUser() {
public boolean isForceSandboxForCurrentUser() {
return forceSandbox && !Jenkins.get().hasPermission(Jenkins.ADMINISTER);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ public class ScriptApprovalNote extends ConsoleNote<Object> {

public static void print(TaskListener listener, RejectedAccessException x) {
try {
String text = ScriptApproval.get().isForceSandbox()?
Messages.ScriptApprovalNoteForceSandBox_message():Messages.ScriptApprovalNote_message();
String text = ScriptApproval.get().isForceSandbox() ?
Messages.ScriptApprovalNoteForceSandBox_message() : Messages.ScriptApprovalNote_message();
listener.getLogger().println(x.getMessage() + ". " + new ScriptApprovalNote(text.length()).encode() + text);
} catch (IOException x2) {
LOGGER.log(Level.WARNING, null, x2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public final class UnapprovedUsageException extends SecurityException {
private final String hash;

UnapprovedUsageException(String hash) {
super(ScriptApproval.get().isForceSandbox()?Messages.UnapprovedUsage_ForceSandBox():Messages.UnapprovedUsage_NonApproved());
super(ScriptApproval.get().isForceSandbox() ? Messages.UnapprovedUsage_ForceSandBox() : Messages.UnapprovedUsage_NonApproved());
this.hash = hash;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!-- Just ti satisfy GlobalConfiguration.getGlobalConfigPage() -->
<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:l="/lib/layout" xmlns:f="/lib/form">
<f:section title="${%System Sandbox enablement}">
<f:section title="${%Sandbox Configuration}">
<f:entry field="forceSandbox" title="${%Force the use of the sandbox globally in the system}">
<f:checkbox/>
</f:entry>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div>
<p>Controls whether the "Use Groovy Sandbox" is shown in the system to users without Overall/Administer permission.</p>
<p>This can be used to simplify the UX in highly secured environments where all pipelines and other logics are
<p>This can be used to simplify the UX in highly secured environments where all pipelines and any other groovy execution are
required to run in the sandbox (ie. running arbitrary code is never approved)</p>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -246,14 +246,14 @@ public void forceSandboxTests() throws Exception {
assertTrue(ScriptApproval.get().getPendingSignatures().isEmpty());
}

//Insert new Pending ClassPatch - As the user is not admin and ForceSandbox is enabled, nothing should be added
//Insert new Pending Classpath - As the user is not admin and ForceSandbox is enabled, nothing should be added
{
ClasspathEntry cpe = new ClasspathEntry("https://www.jenkins.io");
ScriptApproval.get().configuring(cpe, ac);
ScriptApproval.get().addPendingClasspathEntry(
new ScriptApproval.PendingClasspathEntry("hash", new URL("https://www.jenkins.io"), ac));
assertThrows(UnapprovedClasspathException.class, () -> ScriptApproval.get().using(cpe));
//As we are forcing sandbox, none of the previous operations are able to crete new pending ClasspathEntries
// As we are forcing sandbox, none of the previous operations are able to create new pending ClasspathEntries
assertTrue(ScriptApproval.get().getPendingClasspathEntries().isEmpty());
}
}
Expand Down

0 comments on commit fec6912

Please sign in to comment.