[JENKINS-70895] skip isSecureContext check in automated tests (#7784)

https://issues.jenkins.io/browse/JENKINS-70895 reports that
`isSecureContext` is not recognized by HTMLUnit in its JavaScript
handling.  That breaks tests for some plugins that use HTMLUnit to test
configuration round trips.

https://github.com/jenkinsci/jenkins/pull/7665 introduced this change
to notify users running over HTTP connections (insecure) that the copy
button does not work over insecure connections.

https://issues.jenkins.io/browse/JENKINS-21052 was the original motivation
for that informational message to the user.

James Nord tested this change in the automated test that was failing
with Jenkins 2.397 and confirmed that the test passes with this change.

I tested interactively over HTTP and confirmed that the copy button on
the inbound agent page still reports that copy is not supported over an
insecure session.

I tested interactively over HTTPS and confirmed that the copy button on
the inbound agent page still correctly copies the expected content.

I spent several unsuccessful hours trying to create an automated test
to show the failure.  I think we should include this fix without an
automated test because the automated tests in the plugin that James
maintains will detect the issue.
This commit is contained in:
Mark Waite authored and GitHub committed 2023-04-01 13:55:22 -06:00
1 parent 2e9c67c4c6
commit 50cc038a29
1 file changed
+3 -1
@@ -4,7 +4,9 @@ Behaviour.specify(
0,
function (copyButton) {
copyButton.addEventListener("click", () => {
if (isSecureContext) {
// HTMLUnit 2.70.0 does not recognize isSecureContext
// https://issues.jenkins.io/browse/JENKINS-70895
if (!window.isRunAsTest && isSecureContext) {
// Make an invisible textarea element containing the text
const fakeInput = document.createElement("textarea");
fakeInput.value = copyButton.getAttribute("text");