|
| 1 | +package jenkins.plugins.http_request; |
| 2 | + |
| 3 | +import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; |
| 4 | +import static com.github.tomakehurst.wiremock.client.WireMock.get; |
| 5 | +import static com.github.tomakehurst.wiremock.client.WireMock.urlMatching; |
| 6 | + |
| 7 | +import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition; |
| 8 | +import org.jenkinsci.plugins.workflow.job.WorkflowJob; |
| 9 | +import org.junit.jupiter.api.BeforeEach; |
| 10 | +import org.junit.jupiter.api.Test; |
| 11 | +import org.junit.jupiter.api.extension.RegisterExtension; |
| 12 | +import org.jvnet.hudson.test.Issue; |
| 13 | +import org.jvnet.hudson.test.JenkinsRule; |
| 14 | +import org.jvnet.hudson.test.junit.jupiter.WithJenkins; |
| 15 | + |
| 16 | +import com.github.tomakehurst.wiremock.junit5.WireMockExtension; |
| 17 | + |
| 18 | +@WithJenkins |
| 19 | +class HttpRequestPluginTest { |
| 20 | + |
| 21 | + @RegisterExtension |
| 22 | + private static final WireMockExtension WIRE_MOCK_EXTENSION = WireMockExtension.newInstance().build(); |
| 23 | + |
| 24 | + private JenkinsRule r; |
| 25 | + |
| 26 | + @BeforeEach |
| 27 | + void beforeEach(JenkinsRule rule) { |
| 28 | + r = rule; |
| 29 | + } |
| 30 | + |
| 31 | + @Test |
| 32 | + @Issue("JENKINS-76353") |
| 33 | + void test() throws Exception { |
| 34 | + String payload = "Some Random String"; |
| 35 | + |
| 36 | + WIRE_MOCK_EXTENSION.stubFor(get(urlMatching("/JENKINS-76353")) |
| 37 | + .willReturn(aResponse() |
| 38 | + .withStatus(200) |
| 39 | + .withStatusMessage("OK") |
| 40 | + .withHeader("date", "Fri, 23 Jan 2026 15:30:38 GMT") |
| 41 | + .withHeader("vary", "Accept-Encoding") |
| 42 | + .withHeader("content-disposition", "attachment; filename=\"file.txt\"; size=" + payload.length()) |
| 43 | + .withHeader("etag", "\"a21bcba577f439d703fbe1561f77213bedf7a019616fae65d9a76d2b3687773b\"") |
| 44 | + .withHeader("content-encoding", "none") |
| 45 | + .withHeader("content-type", "application/octet-stream") |
| 46 | + .withHeader("cache-control", "no-store, no-cache") |
| 47 | + .withHeader("pragma", "no-cache") |
| 48 | + .withHeader("content-length", String.valueOf(payload.length())) |
| 49 | + .withHeader("strict-transport-security", "max-age=31536000;includeSubDomains") |
| 50 | + .withBody(payload) |
| 51 | + )); |
| 52 | + |
| 53 | + WorkflowJob project = r.createProject(WorkflowJob.class); |
| 54 | + project.setDefinition(new CpsFlowDefinition( |
| 55 | + """ |
| 56 | + httpRequest( |
| 57 | + url: "%s/JENKINS-76353" |
| 58 | + ) |
| 59 | + """.formatted(WIRE_MOCK_EXTENSION.baseUrl()), |
| 60 | + true)); |
| 61 | + r.assertBuildStatusSuccess(project.scheduleBuild2(0)); |
| 62 | + } |
| 63 | +} |
0 commit comments