From 3386f648b4ad4ea4118eba3a708e094dbb9ab732 Mon Sep 17 00:00:00 2001 From: Vincent Latombe Date: Tue, 3 Dec 2024 15:30:33 +0100 Subject: [PATCH] Avoid using a temporary file to store screenshot after a test failure Temporary files are created with 600, differing from defined umask. For the screenshot file that is later attached as diagnostic, this can cause permission issues in some environments. --- .../test/acceptance/junit/DiagnosticRule.java | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/jenkinsci/test/acceptance/junit/DiagnosticRule.java b/src/main/java/org/jenkinsci/test/acceptance/junit/DiagnosticRule.java index abdca9329..1a933205c 100644 --- a/src/main/java/org/jenkinsci/test/acceptance/junit/DiagnosticRule.java +++ b/src/main/java/org/jenkinsci/test/acceptance/junit/DiagnosticRule.java @@ -1,10 +1,9 @@ package org.jenkinsci.test.acceptance.junit; import jakarta.inject.Inject; -import java.io.File; import java.io.IOException; +import java.nio.file.Files; import java.util.logging.Logger; -import org.apache.commons.io.FileUtils; import org.jenkinsci.test.acceptance.controller.JenkinsController; import org.jenkinsci.test.acceptance.po.CapybaraPortingLayerImpl; import org.junit.rules.TestWatcher; @@ -44,10 +43,9 @@ protected void failed(Throwable t, Description description) { private void takeScreenshot() { try { - File file = diagnostics.touch("screenshot.png"); - File screenshot = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE); - FileUtils.copyFile(screenshot, file); - + Files.write( + diagnostics.touch("screenshot.png").toPath(), + ((TakesScreenshot) driver).getScreenshotAs(OutputType.BYTES)); } catch (IOException e) { logger.warning("An error occurred when taking screenshot"); throw new Error(e);