Skip to content

Commit 1afb1d6

Browse files
authored
Switch to using HTMLUnit-compatible JS (#1846)
Co-authored-by: Daniel Beck <[email protected]>
1 parent 3c44138 commit 1afb1d6

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

src/main/resources/com/dabsquared/gitlabjenkins/GitLabPushTrigger/adjunct.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
Behaviour.specify("BUTTON.gitlab_plugin-generate", "gitlab_plugin-generate", 0, function (e) {
22
e.onclick = function (evt) {
3-
document.getElementById('gitlab_plugin_secretToken').value = [...Array(32)].map(() => Math.floor(Math.random() * 16).toString(16)).join('');
3+
const array = new Uint32Array(4);
4+
self.crypto.getRandomValues(array);
5+
document.getElementById('gitlab_plugin_secretToken').value = Array.from(array).map(e => e.toString(16)).join("");
46
evt.preventDefault();
57
};
68
});
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.dabsquared.gitlabjenkins.util;
2+
3+
import com.dabsquared.gitlabjenkins.GitLabPushTrigger;
4+
import hudson.model.FreeStyleProject;
5+
import java.io.IOException;
6+
import org.junit.jupiter.api.Test;
7+
import org.jvnet.hudson.test.JenkinsRule;
8+
import org.jvnet.hudson.test.junit.jupiter.WithJenkins;
9+
import org.xml.sax.SAXException;
10+
11+
/**
12+
* JS in HTMLUnit isn't great, so ensure our JS doesn't cause it to fall over.
13+
*/
14+
@WithJenkins
15+
public class JavaScriptTest {
16+
@Test
17+
void testJavaScriptExecution(JenkinsRule j) throws IOException, SAXException {
18+
final FreeStyleProject fs = j.createFreeStyleProject();
19+
final GitLabPushTrigger trigger = new GitLabPushTrigger();
20+
fs.addTrigger(trigger);
21+
fs.save();
22+
try (JenkinsRule.WebClient wc = j.createWebClient()) {
23+
wc.getPage(fs, "configure");
24+
}
25+
}
26+
}

0 commit comments

Comments
 (0)