diff --git a/src/test/java/com/cloudbees/plugins/credentials/CredentialsSelectHelperTest.java b/src/test/java/com/cloudbees/plugins/credentials/CredentialsSelectHelperTest.java
index 4bd099da7..b15802773 100644
--- a/src/test/java/com/cloudbees/plugins/credentials/CredentialsSelectHelperTest.java
+++ b/src/test/java/com/cloudbees/plugins/credentials/CredentialsSelectHelperTest.java
@@ -5,11 +5,14 @@
import static org.hamcrest.Matchers.is;
import static org.junit.jupiter.api.Assertions.assertTrue;
+import com.cloudbees.plugins.credentials.common.CertificateCredentials;
+import com.cloudbees.plugins.credentials.common.StandardCertificateCredentials;
import com.cloudbees.plugins.credentials.common.UsernamePasswordCredentials;
import com.cloudbees.plugins.credentials.impl.CertificateCredentialsImpl;
import com.cloudbees.plugins.credentials.impl.CertificateCredentialsImplTest;
import hudson.model.UnprotectedRootAction;
+import hudson.security.ACL;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.List;
@@ -20,6 +23,7 @@
import org.htmlunit.html.DomNode;
import org.htmlunit.html.DomNodeList;
import org.htmlunit.html.HtmlButton;
+import org.htmlunit.html.HtmlDivision;
import org.htmlunit.html.HtmlElementUtil;
import org.htmlunit.html.HtmlForm;
import org.htmlunit.html.HtmlFormUtil;
@@ -61,14 +65,17 @@ void doAddCredentialsFromPopupWorksAsExpected() throws Exception {
HtmlPage htmlPage = wc.goTo("credentials-selection");
HtmlButton addCredentialsButton = htmlPage.querySelector(".credentials-add-menu");
- // The 'click' event doesn't fire a 'mouseenter' event causing the menu not to show, so let's fire one
- addCredentialsButton.fireEvent("mouseenter");
addCredentialsButton.click();
HtmlButton jenkinsCredentialsOption = htmlPage.querySelector(".jenkins-dropdown__item");
- jenkinsCredentialsOption.click();
+ HtmlElementUtil.click(jenkinsCredentialsOption);
+
+ HtmlRadioButtonInput item = htmlPage.querySelector(".jenkins-choice-list__item input");
+ HtmlElementUtil.click(item);
+
+ HtmlButton formSubmitButton = htmlPage.querySelector("#cr-dialog-next");
+ HtmlElementUtil.click(formSubmitButton);
- wc.waitForBackgroundJavaScript(4000);
HtmlForm form = htmlPage.querySelector("#credentials-dialog-form");
HtmlInput username = form.querySelector("input[name='_.username']");
@@ -78,12 +85,11 @@ void doAddCredentialsFromPopupWorksAsExpected() throws Exception {
HtmlInput id = form.querySelector("input[name='_.id']");
id.setValue("test");
- HtmlButton formSubmitButton = htmlPage.querySelector(".jenkins-button[data-id='ok']");
- formSubmitButton.fireEvent("click");
- wc.waitForBackgroundJavaScript(5000);
+ formSubmitButton = htmlPage.querySelector("#cr-dialog-submit");
+ HtmlElementUtil.click(formSubmitButton);
// check if credentials were added
- List
creds = CredentialsProvider.lookupCredentials(UsernamePasswordCredentials.class);
+ List creds = CredentialsProvider.lookupCredentialsInItem(UsernamePasswordCredentials.class, null, ACL.SYSTEM2);
assertThat(creds, Matchers.hasSize(1));
UsernamePasswordCredentials cred = creds.get(0);
assertThat(cred.getUsername(), is("bob"));
@@ -98,12 +104,19 @@ void doAddCredentialsFromPopupForPEMCertificateKeystore() throws Exception {
try (JenkinsRule.WebClient wc = j.createWebClient()) {
HtmlPage htmlPage = wc.goTo("credentials-selection");
HtmlForm form = selectPEMCertificateKeyStore(htmlPage, wc);
+ HtmlInput id = form.querySelector("input[name='_.id']");
+ id.setValue("test");
form.getTextAreaByName("_.certChain").setTextContent(pemCert);
form.getTextAreaByName("_.privateKey").setTextContent(pemKey);
form.getInputsByName("_.password").forEach(input -> input.setValue(VALID_PASSWORD));
- Page submit = HtmlFormUtil.submit(form);
- JSONObject responseJson = JSONObject.fromObject(submit.getWebResponse().getContentAsString());
- assertThat(responseJson.getString("notificationType"), is("SUCCESS"));
+
+ HtmlButton formSubmitButton = htmlPage.querySelector("#cr-dialog-submit");
+ HtmlElementUtil.click(formSubmitButton);
+
+ List creds = CredentialsProvider.lookupCredentialsInItem(StandardCertificateCredentials.class, null, ACL.SYSTEM2);
+ assertThat(creds, Matchers.hasSize(1));
+ StandardCertificateCredentials cred = creds.get(0);
+ assertThat(cred.getId(), is("test"));
}
}
@@ -113,10 +126,13 @@ void doAddCredentialsFromPopupForPEMCertificateKeystore_missingKeyStore() throws
try (JenkinsRule.WebClient wc = j.createWebClient()) {
HtmlPage htmlPage = wc.goTo("credentials-selection");
- HtmlForm form = selectPEMCertificateKeyStore(htmlPage, wc);
- Page submit = HtmlFormUtil.submit(form);
- JSONObject responseJson = JSONObject.fromObject(submit.getWebResponse().getContentAsString());
- assertThat(responseJson.getString("notificationType"), is("ERROR"));
+ selectPEMCertificateKeyStore(htmlPage, wc);
+
+ HtmlButton formSubmitButton = htmlPage.querySelector("#cr-dialog-submit");
+ HtmlElementUtil.click(formSubmitButton);
+
+ List creds = CredentialsProvider.lookupCredentialsInItem(StandardCertificateCredentials.class, null, ACL.SYSTEM2);
+ assertThat(creds, Matchers.hasSize(0));
}
}
@@ -130,9 +146,12 @@ void doAddCredentialsFromPopupForInvalidPEMCertificateKeystore_missingCert() thr
form.getTextAreaByName("_.certChain").setTextContent(null);
form.getTextAreaByName("_.privateKey").setTextContent(pemKey);
form.getInputsByName("_.password").forEach(input -> input.setValue(VALID_PASSWORD));
- Page submit = HtmlFormUtil.submit(form);
- JSONObject responseJson = JSONObject.fromObject(submit.getWebResponse().getContentAsString());
- assertThat(responseJson.getString("notificationType"), is("ERROR"));
+
+ HtmlButton formSubmitButton = htmlPage.querySelector("#cr-dialog-submit");
+ HtmlElementUtil.click(formSubmitButton);
+
+ List creds = CredentialsProvider.lookupCredentialsInItem(StandardCertificateCredentials.class, null, ACL.SYSTEM2);
+ assertThat(creds, Matchers.hasSize(0));
}
}
@@ -145,9 +164,12 @@ void doAddCredentialsFromPopupForInvalidPEMCertificateKeystore_missingPassword()
HtmlForm form = selectPEMCertificateKeyStore(htmlPage, wc);
form.getTextAreaByName("_.certChain").setTextContent(pemCert);
form.getTextAreaByName("_.privateKey").setTextContent(pemKey);
- Page submit = HtmlFormUtil.submit(form);
- JSONObject responseJson = JSONObject.fromObject(submit.getWebResponse().getContentAsString());
- assertThat(responseJson.getString("notificationType"), is("ERROR"));
+
+ HtmlButton formSubmitButton = htmlPage.querySelector("#cr-dialog-submit");
+ HtmlElementUtil.click(formSubmitButton);
+
+ List creds = CredentialsProvider.lookupCredentialsInItem(StandardCertificateCredentials.class, null, ACL.SYSTEM2);
+ assertThat(creds, Matchers.hasSize(0));
}
}
@@ -161,44 +183,54 @@ void doAddCredentialsFromPopupForInvalidPEMCertificateKeystore_invalidPassword()
form.getTextAreaByName("_.certChain").setTextContent(pemCert);
form.getTextAreaByName("_.privateKey").setTextContent(pemKey);
form.getInputsByName("_.password").forEach(input -> input.setValue(INVALID_PASSWORD));
- Page submit = HtmlFormUtil.submit(form);
- JSONObject responseJson = JSONObject.fromObject(submit.getWebResponse().getContentAsString());
- assertThat(responseJson.getString("notificationType"), is("ERROR"));
+
+ HtmlButton formSubmitButton = htmlPage.querySelector("#cr-dialog-submit");
+ HtmlElementUtil.click(formSubmitButton);
+
+ List creds = CredentialsProvider.lookupCredentialsInItem(StandardCertificateCredentials.class, null, ACL.SYSTEM2);
+ assertThat(creds, Matchers.hasSize(0));
}
}
private HtmlForm selectPEMCertificateKeyStore(HtmlPage htmlPage, JenkinsRule.WebClient wc) throws IOException {
HtmlButton addCredentialsButton = htmlPage.querySelector(".credentials-add-menu");
- addCredentialsButton.fireEvent("mouseenter");
addCredentialsButton.click();
HtmlButton jenkinsCredentialsOption = htmlPage.querySelector(".jenkins-dropdown__item");
- jenkinsCredentialsOption.click();
+ HtmlElementUtil.click(jenkinsCredentialsOption);
- wc.waitForBackgroundJavaScript(4000);
- HtmlForm form = htmlPage.querySelector("#credentials-dialog-form");
+ HtmlForm form = htmlPage.getFormByName("dialog");
String certificateDisplayName = j.jenkins.getDescriptor(CertificateCredentialsImpl.class).getDisplayName();
String KeyStoreSourceDisplayName = j.jenkins.getDescriptor(
CertificateCredentialsImpl.PEMEntryKeyStoreSource.class).getDisplayName();
- DomNodeList allOptions = htmlPage.getDocumentElement().querySelectorAll(
- "select.dropdownList option");
+
+ DomNodeList allOptions = form.querySelectorAll(".jenkins-choice-list__item");
+
boolean optionFound = selectOption(allOptions, certificateDisplayName);
assertTrue(optionFound, "The Certificate option was not found in the credentials type select");
+
+ HtmlButton formSubmitButton = htmlPage.querySelector("#cr-dialog-next");
+ HtmlElementUtil.click(formSubmitButton);
+
List inputs = htmlPage.getDocumentElement().getByXPath(
"//input[contains(@name, 'keyStoreSource') and following-sibling::label[contains(.,'"
+ KeyStoreSourceDisplayName + "')]]");
assertThat("query should return only a singular input", inputs, hasSize(1));
HtmlElementUtil.click(inputs.get(0));
wc.waitForBackgroundJavaScript(4000);
+ form = htmlPage.getFormByName("newCredentials");
+
return form;
}
private static boolean selectOption(DomNodeList allOptions, String optionName) {
return allOptions.stream().anyMatch(domNode -> {
- if (domNode instanceof HtmlOption option) {
- if (option.getVisibleText().equals(optionName)) {
+ if (domNode instanceof HtmlDivision option) {
+ if (option.getVisibleText().contains(optionName)) {
try {
- HtmlElementUtil.click(option);
+ HtmlRadioButtonInput item = domNode.querySelector(".jenkins-choice-list__item input");
+ HtmlElementUtil.click(item);
+
} catch (IOException e) {
throw new RuntimeException(e);
}
diff --git a/src/test/java/com/cloudbees/plugins/credentials/CredentialsStoreActionTest.java b/src/test/java/com/cloudbees/plugins/credentials/CredentialsStoreActionTest.java
index ada6c8a27..f270971ca 100644
--- a/src/test/java/com/cloudbees/plugins/credentials/CredentialsStoreActionTest.java
+++ b/src/test/java/com/cloudbees/plugins/credentials/CredentialsStoreActionTest.java
@@ -64,11 +64,10 @@ void smokes() throws Exception {
+ ""
+ "<_>"
+ ""
- + "Credentials that should be available irrespective of domain specification to requirements "
- + "matching."
+ + "Credentials that should be available everywhere."
+ ""
- + "Global credentials (unrestricted)"
- + "System ยป Global credentials (unrestricted)"
+ + "Global"
+ + "System ยป Global"
+ "system/_"
+ "true"
+ "_"
@@ -90,11 +89,10 @@ void smokes() throws Exception {
+ ""
+ "<_>"
+ ""
- + "Credentials that should be available irrespective of domain specification to requirements "
- + "matching."
+ + "Credentials that should be available everywhere."
+ ""
- + "Global credentials (unrestricted)"
- + "System ยป Global credentials (unrestricted)"
+ + "Global"
+ + "System ยป Global"
+ "system/_"
+ "true"
+ "_"
diff --git a/src/test/java/com/cloudbees/plugins/credentials/ViewCredentialsActionTest.java b/src/test/java/com/cloudbees/plugins/credentials/ViewCredentialsActionTest.java
index 4e7e6c45f..214645145 100644
--- a/src/test/java/com/cloudbees/plugins/credentials/ViewCredentialsActionTest.java
+++ b/src/test/java/com/cloudbees/plugins/credentials/ViewCredentialsActionTest.java
@@ -54,11 +54,10 @@ void smokes(JenkinsRule j) throws Exception {
+ ""
+ "<_>"
+ ""
- + "Credentials that should be available irrespective of domain specification to requirements "
- + "matching."
+ + "Credentials that should be available everywhere."
+ ""
- + "Global credentials (unrestricted)"
- + "System ยป Global credentials (unrestricted)"
+ + "Global"
+ + "System ยป Global"
+ "system/_"
+ "true"
+ "_"
@@ -84,11 +83,10 @@ void smokes(JenkinsRule j) throws Exception {
+ ""
+ "<_>"
+ ""
- + "Credentials that should be available irrespective of domain specification to requirements "
- + "matching."
+ + "Credentials that should be available everywhere."
+ ""
- + "Global credentials (unrestricted)"
- + "System ยป Global credentials (unrestricted)"
+ + "Global"
+ + "System ยป Global"
+ "system/_"
+ "true"
+ "_"
diff --git a/src/test/java/com/cloudbees/plugins/credentials/impl/CertificateCredentialsImplTest.java b/src/test/java/com/cloudbees/plugins/credentials/impl/CertificateCredentialsImplTest.java
index 658fa3711..141245293 100644
--- a/src/test/java/com/cloudbees/plugins/credentials/impl/CertificateCredentialsImplTest.java
+++ b/src/test/java/com/cloudbees/plugins/credentials/impl/CertificateCredentialsImplTest.java
@@ -37,6 +37,8 @@
import org.htmlunit.html.DomNode;
import org.htmlunit.html.DomNodeList;
import org.htmlunit.html.HtmlButton;
+import org.htmlunit.html.HtmlDivision;
+import org.htmlunit.html.HtmlElement;
import org.htmlunit.html.HtmlElementUtil;
import org.htmlunit.html.HtmlFileInput;
import org.htmlunit.html.HtmlForm;
@@ -206,26 +208,25 @@ void fullSubmitOfUploadedKeystore() throws Exception {
String KeyStoreSourceDisplayName = r.jenkins.getDescriptor(CertificateCredentialsImpl.UploadedKeyStoreSource.class).getDisplayName();
JenkinsRule.WebClient wc = r.createWebClient();
- HtmlPage htmlPage = wc.goTo("credentials/store/system/domain/_/newCredentials");
- HtmlForm newCredentialsForm = htmlPage.getFormByName("newCredentials");
+ HtmlPage htmlPage = wc.goTo("credentials/store/system/domain/_/");
- DomNodeList allOptions = htmlPage.getDocumentElement().querySelectorAll("select.dropdownList option");
- boolean optionFound = allOptions.stream().anyMatch(domNode -> {
- if (domNode instanceof HtmlOption option) {
- if (option.getVisibleText().equals(certificateDisplayName)) {
- try {
- HtmlElementUtil.click(option);
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- return true;
- }
- }
+ HtmlButton button = (HtmlButton) htmlPage
+ .getDocumentElement()
+ .getElementsByAttribute("button", "data-type", "credentials-add-store-item").get(0);
+ HtmlElementUtil.click(button);
+
+ HtmlForm form = htmlPage.getFormByName("dialog");
+
+ DomNodeList allOptions = form.querySelectorAll(".jenkins-choice-list__item");
+ boolean optionFound = selectOption(allOptions, certificateDisplayName);
- return false;
- });
assertTrue(optionFound, "The Certificate option was not found in the credentials type select");
+ HtmlButton formSubmitButton = htmlPage.querySelector("#cr-dialog-next");
+ HtmlElementUtil.click(formSubmitButton);
+
+ HtmlForm newCredentialsForm = htmlPage.getFormByName("newCredentials");
+
List inputs = htmlPage.getDocumentElement().
getByXPath("//input[contains(@name, 'keyStoreSource') and following-sibling::label[contains(.,'"+KeyStoreSourceDisplayName+"')]]");
assertThat("query should return only a singular input", inputs, hasSize(1));
@@ -241,7 +242,8 @@ void fullSubmitOfUploadedKeystore() throws Exception {
List certificateCredentials = CredentialsProvider.lookupCredentialsInItemGroup(CertificateCredentials.class, null, ACL.SYSTEM2);
assertThat(certificateCredentials, hasSize(0));
- r.submit(newCredentialsForm);
+ formSubmitButton = htmlPage.querySelector("#cr-dialog-submit");
+ HtmlElementUtil.click(formSubmitButton);
certificateCredentials = CredentialsProvider.lookupCredentialsInItemGroup(CertificateCredentials.class, null, ACL.SYSTEM2);
assertThat(certificateCredentials, hasSize(1));
@@ -258,36 +260,34 @@ void fullSubmitOfUploadedPEM() throws Exception {
String KeyStoreSourceDisplayName = r.jenkins.getDescriptor(CertificateCredentialsImpl.PEMEntryKeyStoreSource.class).getDisplayName();
JenkinsRule.WebClient wc = r.createWebClient();
- HtmlPage htmlPage = wc.goTo("credentials/store/system/domain/_/newCredentials");
- HtmlForm newCredentialsForm = htmlPage.getFormByName("newCredentials");
+ HtmlPage htmlPage = wc.goTo("credentials/store/system/domain/_/");
- DomNodeList allOptions = htmlPage.getDocumentElement().querySelectorAll("select.dropdownList option");
- boolean optionFound = allOptions.stream().anyMatch(domNode -> {
- if (domNode instanceof HtmlOption option) {
- if (option.getVisibleText().equals(certificateDisplayName)) {
- try {
- HtmlElementUtil.click(option);
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- return true;
- }
- }
+ HtmlButton button = (HtmlButton) htmlPage
+ .getDocumentElement()
+ .getElementsByAttribute("button", "data-type", "credentials-add-store-item").get(0);
+ HtmlElementUtil.click(button);
- return false;
- });
+ HtmlForm form = htmlPage.getFormByName("dialog");
+
+ DomNodeList allOptions = form.querySelectorAll(".jenkins-choice-list__item");
+ boolean optionFound = selectOption(allOptions, certificateDisplayName);
assertTrue(optionFound, "The Certificate option was not found in the credentials type select");
+ HtmlButton formSubmitButton = htmlPage.querySelector("#cr-dialog-next");
+ HtmlElementUtil.click(formSubmitButton);
+
+ HtmlForm newCredentialsForm = htmlPage.getFormByName("newCredentials");
+
List inputs = htmlPage.getDocumentElement().
getByXPath("//input[contains(@name, 'keyStoreSource') and following-sibling::label[contains(.,'"+KeyStoreSourceDisplayName+"')]]");
assertThat("query should return only a singular input", inputs, hasSize(1));
HtmlElementUtil.click(inputs.get(0));
// enable entry of the secret (HACK just click all the Add buttons)
- List buttonsByName = htmlPage.getDocumentElement().getByXPath("//button[contains(.,'Add')]");
+ DomNodeList buttonsByName = newCredentialsForm.querySelectorAll(".secret-update-btn");
assertThat("I need 2 buttons", buttonsByName, hasSize(2));
- for (HtmlButton b : buttonsByName) {
- HtmlElementUtil.click(b);
+ for (DomNode b : buttonsByName) {
+ HtmlElementUtil.click((HtmlElement) b);
}
newCredentialsForm.getTextAreaByName("_.certChain").setTextContent(pemCert);
@@ -310,6 +310,24 @@ void fullSubmitOfUploadedPEM() throws Exception {
assertEquals(EXPECTED_DISPLAY_NAME_PEM, displayName);
}
+ private static boolean selectOption(DomNodeList allOptions, String optionDisplayName) {
+ return allOptions.stream().anyMatch(domNode -> {
+ if (domNode instanceof HtmlDivision option) {
+ if (option.getVisibleText().contains(optionDisplayName)) {
+ try {
+ HtmlRadioButtonInput item = domNode.querySelector(".jenkins-choice-list__item input");
+ HtmlElementUtil.click(item);
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ return true;
+ }
+ }
+
+ return false;
+ });
+ }
+
private String getValidP12_base64() throws Exception {
return Base64.getEncoder().encodeToString(Files.readAllBytes(p12.toPath()));
}