Skip to content

Commit b4943eb

Browse files
Vlatombegounthar
authored andcommitted
[JENKINS-75321] Clarify the message displayed when loading the content of build history widget
(cherry picked from commit 5d65d11)
1 parent a0f566f commit b4943eb

7 files changed

Lines changed: 25 additions & 24 deletions

File tree

cli/src/main/java/hudson/cli/CLI.java

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -318,31 +318,20 @@ public static int _main(String[] _args) throws Exception {
318318
throw new AssertionError();
319319
}
320320

321-
private static File validateAndSanitizePath(String userInput) {
322-
// Define a base directory for validation
323-
String baseDir = "/safe/base/directory";
324-
Path basePath = Paths.get(baseDir).toAbsolutePath().normalize();
325-
Path userPath = Paths.get(userInput).toAbsolutePath().normalize();
326-
327-
// Check if the user path is within the base directory
328-
if (!userPath.startsWith(basePath)) {
329-
throw new IllegalArgumentException("Invalid file path");
330-
}
331-
332-
// Sanitize the path (e.g., remove dangerous characters)
333-
String sanitizedPath = userPath.toString().replaceAll("[^a-zA-Z0-9./_-]", "");
334-
return new File(sanitizedPath);
335-
}
336-
337-
@SuppressFBWarnings("PATH_TRAVERSAL_IN")
321+
@SuppressFBWarnings(value = "PATH_TRAVERSAL_IN", justification = "User provided value for running the program.")
338322
private static String readAuthFromFile(String auth) throws IOException {
339-
Path path = validateAndSanitizePath(auth.substring(1)).toPath();
323+
Path path;
324+
try {
325+
path = Paths.get(auth.substring(1));
326+
} catch (InvalidPathException e) {
327+
throw new IOException(e);
328+
}
340329
return Files.readString(path, Charset.defaultCharset());
341330
}
342331

343-
@SuppressFBWarnings("PATH_TRAVERSAL_IN")
332+
@SuppressFBWarnings(value = "PATH_TRAVERSAL_IN", justification = "User provided value for running the program.")
344333
private static File getFileFromArguments(List<String> args) {
345-
return validateAndSanitizePath(args.get(1));
334+
return new File(args.get(1));
346335
}
347336

348337
private static int webSocketConnection(String url, List<String> args, CLIConnectionFactory factory) throws Exception {
@@ -354,17 +343,20 @@ public void onOpen(Session session, EndpointConfig config) {}
354343

355344
class Authenticator extends ClientEndpointConfig.Configurator {
356345
HandshakeResponse hr;
346+
357347
@Override
358348
public void beforeRequest(Map<String, List<String>> headers) {
359349
if (factory.authorization != null) {
360350
headers.put("Authorization", List.of(factory.authorization));
361351
}
362352
}
353+
363354
@Override
364355
public void afterResponse(HandshakeResponse hr) {
365356
this.hr = hr;
366357
}
367358
}
359+
368360
var authenticator = new Authenticator();
369361

370362
ClientManager client = ClientManager.createClient(JdkClientContainer.class.getName()); // ~ ContainerProvider.getWebSocketContainer()

core/src/main/java/hudson/DescriptorExtensionList.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
import edu.umd.cs.findbugs.annotations.CheckForNull;
2828
import edu.umd.cs.findbugs.annotations.NonNull;
29+
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
2930
import hudson.model.Describable;
3031
import hudson.model.Descriptor;
3132
import hudson.model.Descriptor.FormException;
@@ -274,6 +275,7 @@ protected Descriptor adapt(ExtensionComponent<Descriptor> item) {
274275
/**
275276
* Exposed just for the test harness. Clear legacy instances.
276277
*/
278+
@SuppressFBWarnings(value = "HSM_HIDING_METHOD", justification = "TODO needs triage")
277279
public static void clearLegacyInstances() {
278280
legacyDescriptors.clear();
279281
}

core/src/main/java/hudson/console/ModelHyperlinkNote.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package hudson.console;
22

33
import edu.umd.cs.findbugs.annotations.NonNull;
4+
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
45
import hudson.Extension;
56
import hudson.model.Computer;
67
import hudson.model.Item;
@@ -66,6 +67,7 @@ public static String encodeTo(Label label) {
6667
return encodeTo("/" + label.getUrl(), label.getName());
6768
}
6869

70+
@SuppressFBWarnings(value = "HSM_HIDING_METHOD", justification = "TODO needs triage")
6971
public static String encodeTo(String url, String text) {
7072
return HyperlinkNote.encodeTo(url, text, ModelHyperlinkNote::new);
7173
}

core/src/main/java/hudson/model/AutoCompletionCandidates.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ public static <T extends Item> AutoCompletionCandidates ofJobNames(final Class<T
109109
* The nearby contextual {@link ItemGroup} to resolve relative job names from.
110110
* @since 1.553
111111
*/
112-
@SuppressFBWarnings(value = "SBSC_USE_STRINGBUFFER_CONCATENATION", justification = "no big deal")
113112
public static <T extends Item> AutoCompletionCandidates ofJobNames(final Class<T> type, final String value, ItemGroup container) {
114113
final AutoCompletionCandidates candidates = new AutoCompletionCandidates();
115114
class Visitor extends ItemVisitor {

core/src/main/java/hudson/model/FileParameterValue.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ public org.apache.commons.fileupload.FileItem getFile() {
164164
@Override
165165
public BuildWrapper createBuildWrapper(AbstractBuild<?, ?> build) {
166166
return new BuildWrapper() {
167-
@SuppressFBWarnings(value = {"FILE_UPLOAD_FILENAME", "NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE"}, justification = "TODO needs triage")
167+
@SuppressFBWarnings(value = "NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE", justification = "TODO needs triage")
168168
@Override
169169
public Environment setUp(AbstractBuild build, Launcher launcher, BuildListener listener) throws IOException, InterruptedException {
170170
if (location != null && !location.isEmpty() && file.getName() != null && !file.getName().isEmpty()) {

core/src/main/resources/hudson/widgets/HistoryWidget/index.jelly

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,10 @@ THE SOFTWARE.
4949
clazz="${page.runs.isEmpty() and page.queueItems.isEmpty() ? 'jenkins-hidden' : ''}"/>
5050

5151
<div class="app-builds-container">
52-
<div id="no-builds" class="app-builds-container__placeholder">
52+
<div id="loading-builds" class="app-builds-container__placeholder">
53+
<l:spinner text="${%Loading builds...}"/>
54+
</div>
55+
<div id="no-builds" style="display:none" class="app-builds-container__placeholder">
5356
${%No builds}
5457
</div>
5558

src/main/js/pages/project/builds-card.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const ajaxUrl = buildHistoryPage.getAttribute("page-ajax");
99
const card = document.querySelector("#jenkins-builds");
1010
const contents = card.querySelector("#jenkins-build-history");
1111
const container = card.querySelector(".app-builds-container");
12+
const loadingBuilds = card.querySelector("#loading-builds");
1213
const noBuilds = card.querySelector("#no-builds");
1314

1415
// Pagination controls
@@ -58,6 +59,7 @@ function load(options = {}) {
5859
if (responseText.trim() === "") {
5960
contents.innerHTML = "";
6061
noBuilds.style.display = "block";
62+
loadingBuilds.style.display = "none";
6163
updateCardControls({
6264
pageHasUp: false,
6365
pageHasDown: false,
@@ -69,7 +71,7 @@ function load(options = {}) {
6971

7072
// Show the refreshed builds list
7173
contents.innerHTML = responseText;
72-
noBuilds.style.display = "none";
74+
loadingBuilds.style.display = "none";
7375
behaviorShim.applySubtree(contents);
7476

7577
// Show the card controls
@@ -146,6 +148,7 @@ document.addEventListener("DOMContentLoaded", function () {
146148
debouncedLoad();
147149
});
148150

151+
container.classList.add("app-builds-container--loading");
149152
load();
150153

151154
window.addEventListener("focus", function () {

0 commit comments

Comments
 (0)