Skip to content

Commit

Permalink
Merge pull request #225 from amuniz/JENKINS-66514
Browse files Browse the repository at this point in the history
[JENKINS-66514] BaseStandardCredentials ID validation error
  • Loading branch information
Wadeck authored Sep 9, 2021
2 parents 72db2db + a18c003 commit bbb8f97
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 bbb8f97

Please sign in to comment.