Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure directories are writable when generating reports from read-only sources #6358

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ public FileVisitResult preVisitDirectory(Path file, BasicFileAttributes attrs)
"{}, found non empty folder with following content {}, will be ignored",
file, newDir, ex.getMessage(), newDir.toFile().listFiles());
}
if (!newDir.toFile().canWrite()) {
newDir.toFile().setWritable(true);
}
return FileVisitResult.CONTINUE;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.apache.jmeter.report.dashboard

import com.fasterxml.jackson.databind.ObjectMapper
import org.apache.commons.io.FileUtils
import org.apache.jmeter.junit.JMeterTestCase
import org.apache.jmeter.util.JMeterUtils
import org.junit.jupiter.api.Assertions.assertEquals
Expand All @@ -26,7 +27,10 @@ import org.junit.jupiter.api.assertThrows
import org.junit.jupiter.api.io.TempDir
import org.junit.jupiter.api.parallel.Isolated
import java.io.File
import java.nio.file.Files
import java.nio.file.Path
import java.nio.file.Paths
import kotlin.io.path.absolutePathString

@Isolated("modifies shared properties")
class ReportGeneratorTest : JMeterTestCase() {
Expand All @@ -43,6 +47,29 @@ class ReportGeneratorTest : JMeterTestCase() {
fun combine(vararg paths: String) =
Paths.get(JMeterUtils.getJMeterBinDir(), *paths).toString()

@Test
fun `check that report generation succeeds from read-only templates`() {
val roTemplate = Files.createTempDirectory("report-template-ro")
FileUtils.copyDirectoryToDirectory(Path.of(combine("report-template")).toFile(), roTemplate.toFile())
Files.walk(roTemplate).forEach { p -> p.toFile().setReadOnly() }
JMeterUtils.setProperty("jmeter.reportgenerator.exporter.html.property.template_dir", roTemplate.absolutePathString())
val roReport = Files.createTempDirectory("report-from-ro-template")

val mapper = ObjectMapper()
val expected = ReportGenerator::class.java.getResource("/org/apache/jmeter/gui/report/HTMLReportExpect.json")
val expectedRoot = mapper.readTree(expected)

JMeterUtils.setProperty("jmeter.reportgenerator.outputdir", roReport.absolutePathString())
val reportGenerator = ReportGenerator(
combine("testfiles", "HTMLReportTestFile.csv"), null
)
reportGenerator.generate()
val statistics = File(roReport.toFile(), "statistics.json")
val actualRoot = mapper.readTree(statistics)

assertEquals(expectedRoot, actualRoot, "test report json file")
}

@Test
fun `check that report generation succeeds and statistics json are generated`() {
val mapper = ObjectMapper()
Expand Down
1 change: 1 addition & 0 deletions xdocs/changes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ Summary
<ul>
<li><pr>6220</pr> Require Java 17 or later for running JMeter</li>
<li><pr>6274</pr> Change references to old MySQL driver to new class <code>com.mysql.cj.jdbc.Driver</code></li>
<li><issue>6357</issue> Ensure writable directories when copying template files while report generation.</li>
</ul>

<!-- =================== Thanks =================== -->
Expand Down
Loading