Skip to content

Commit

Permalink
[JENKINS-66514] BaseStandardCredentials ID validation error
Browse files Browse the repository at this point in the history
See details in JENKINS-66514

The fix is to remove the unnecesary explicit `checkUrl` so the legacy
validation method is nt used. The check URL will be calculated
automatically and the "new" (years old) mechanism kicks in.

The test is checking that the validation error shows up when needed (and
only when needed).
  • Loading branch information
amuniz committed Sep 1, 2021
1 parent 72db2db commit a18c003
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
<f:textbox name="_.id"
value="${instance != null ? instance.id : null}"
readonly="${instance != null ? 'readonly' : null}"
checkUrl="${instance != null ? null : descriptor.getCheckUrl('id')}"
/>
</f:entry>
<f:entry title="${%Description}" field="description">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import com.cloudbees.plugins.credentials.CredentialsStore;
import com.cloudbees.plugins.credentials.common.IdCredentials;
import com.cloudbees.plugins.credentials.domains.Domain;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import hudson.model.ModelObject;
import hudson.model.User;
import hudson.security.ACL;
Expand All @@ -41,11 +42,15 @@
import org.junit.Test;
import org.jvnet.hudson.test.JenkinsRule;
import org.jvnet.hudson.test.MockFolder;
import org.xml.sax.SAXException;

import static hudson.util.FormValidation.Kind.ERROR;
import static hudson.util.FormValidation.Kind.OK;
import static hudson.util.FormValidation.Kind.WARNING;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.core.StringContains.containsString;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;

public class BaseStandardCredentialsTest {
Expand Down Expand Up @@ -138,6 +143,17 @@ public void run() {

// TODO could test the case that alice has Item.READ but not CredentialsProvider.VIEW on a folder, and mocks a web request passing that folder as context
}

@Test
public void noIDValidationMessageOnCredentialsUpdate() throws IOException, SAXException {
// create credentials with ID test
CredentialsStore store = lookupStore(r.jenkins);
addCreds(store, CredentialsScope.GLOBAL, "test");
// check there is no validation message about a duplicated ID when updating
JenkinsRule.WebClient webClient = r.createWebClient();
HtmlPage htmlPage = webClient.goTo("credentials/store/system/domain/_/credential/test/update");
assertThat(htmlPage.asText(), not(containsString("This ID is already in use")));
}

private static CredentialsStore lookupStore(ModelObject object) {
Iterator<CredentialsStore> stores = CredentialsProvider.lookupStores(object).iterator();
Expand Down

0 comments on commit a18c003

Please sign in to comment.