package org.jenkinsci.plugins.p4.credentials; import com.cloudbees.plugins.credentials.CredentialsNameProvider; import com.cloudbees.plugins.credentials.CredentialsProvider; import com.cloudbees.plugins.credentials.CredentialsScope; import com.cloudbees.plugins.credentials.SystemCredentialsProvider; import com.cloudbees.plugins.credentials.domains.DomainRequirement; import hudson.security.ACL; import jenkins.model.Jenkins; import org.acegisecurity.Authentication; import org.jenkinsci.plugins.p4.client.AuthorisationConfig; import org.jenkinsci.plugins.p4.client.AuthorisationType; import org.junit.Rule; import org.junit.Test; import org.jvnet.hudson.test.JenkinsRule; import java.io.IOException; import java.util.List; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; public class PerforceCredentialsTest { @Rule public JenkinsRule jenkins = new JenkinsRule(); @Test public void testAddStandardCredentials() throws IOException { P4BaseCredentials credential = new P4PasswordImpl( CredentialsScope.SYSTEM, "id", "desc:passwd", "localhost:1666", null, "user", "0", "0", "pass"); assertTrue(lookupCredentials().isEmpty()); SystemCredentialsProvider.getInstance().getCredentials() .add(credential); assertFalse(lookupCredentials().isEmpty()); assertTrue(new SystemCredentialsProvider().getCredentials().isEmpty()); SystemCredentialsProvider.getInstance().save(); assertFalse(new SystemCredentialsProvider().getCredentials().isEmpty()); assertEquals("desc:passwd", credential.getDescription()); assertEquals("id", credential.getId()); List<P4BaseCredentials> list = lookupCredentials(); assertEquals("localhost:1666", list.get(0).getP4port()); assertEquals("user", list.get(0).getUsername()); assertFalse(list.get(0).isSsl()); String name = CredentialsNameProvider.name(credential); assertEquals("user/****** (desc:passwd)", name); } @Test public void testAddPasswordCredentials() throws IOException { P4PasswordImpl credential = new P4PasswordImpl(CredentialsScope.SYSTEM, "id", "description", "localhost:1666", null, "user", "0", "0", "pass"); assertTrue(lookupCredentials().isEmpty()); SystemCredentialsProvider.getInstance().getCredentials() .add(credential); assertFalse(lookupCredentials().isEmpty()); assertTrue(new SystemCredentialsProvider().getCredentials().isEmpty()); SystemCredentialsProvider.getInstance().save(); assertFalse(new SystemCredentialsProvider().getCredentials().isEmpty()); assertEquals("pass", credential.getPassword().getPlainText()); assertFalse(credential.isSsl()); AuthorisationConfig auth = new AuthorisationConfig(credential); assertEquals(AuthorisationType.PASSWORD, auth.getType()); assertEquals("user", auth.getUsername()); assertEquals("pass", auth.getPassword()); assertEquals("user@no-client", auth.toString()); // point less auth.setClient("client"); assertEquals("client", auth.getClient()); assertEquals("user@client", auth.toString()); } @Test public void testAddSslCredentials() throws IOException { TrustImpl ssl = new TrustImpl("12345ABCD"); P4PasswordImpl credential = new P4PasswordImpl(CredentialsScope.SYSTEM, "id", "description", "localhost:1666", ssl, "user", "0", "0", "pass"); assertTrue(lookupCredentials().isEmpty()); SystemCredentialsProvider.getInstance().getCredentials() .add(credential); assertFalse(lookupCredentials().isEmpty()); assertTrue(new SystemCredentialsProvider().getCredentials().isEmpty()); SystemCredentialsProvider.getInstance().save(); assertFalse(new SystemCredentialsProvider().getCredentials().isEmpty()); assertTrue(credential.isSsl()); assertEquals("12345ABCD", credential.getTrust()); } @Test public void testAddTicketCredentials() throws IOException { TicketModeImpl ticket = new TicketModeImpl("ticketValueSet", "12345", null); P4TicketImpl credential = new P4TicketImpl(CredentialsScope.SYSTEM, "id", "desc:ticket", "localhost:1666", null, "user", "0", "0", ticket); assertTrue(lookupCredentials().isEmpty()); SystemCredentialsProvider.getInstance().getCredentials() .add(credential); assertFalse(lookupCredentials().isEmpty()); assertTrue(new SystemCredentialsProvider().getCredentials().isEmpty()); SystemCredentialsProvider.getInstance().save(); assertFalse(new SystemCredentialsProvider().getCredentials().isEmpty()); assertEquals("12345", credential.getTicketValue()); AuthorisationConfig auth = new AuthorisationConfig(credential); assertEquals(AuthorisationType.TICKET, auth.getType()); assertEquals("12345", auth.getTicketValue()); String name = CredentialsNameProvider.name(credential); assertEquals("user (desc:ticket)", name); } @Test public void testAddTicketPathCredentials() throws IOException { TicketModeImpl ticket = new TicketModeImpl("ticketPathSet", null, "~/.p4ticket"); P4TicketImpl credential = new P4TicketImpl(CredentialsScope.SYSTEM, "id", "description", "localhost:1666", null, "user", "0", "0", ticket); assertTrue(lookupCredentials().isEmpty()); SystemCredentialsProvider.getInstance().getCredentials() .add(credential); assertFalse(lookupCredentials().isEmpty()); assertTrue(new SystemCredentialsProvider().getCredentials().isEmpty()); SystemCredentialsProvider.getInstance().save(); assertFalse(new SystemCredentialsProvider().getCredentials().isEmpty()); assertEquals("~/.p4ticket", credential.getTicketPath()); AuthorisationConfig auth = new AuthorisationConfig(credential); assertEquals(AuthorisationType.TICKETPATH, auth.getType()); assertEquals("~/.p4ticket", auth.getTicketPath()); } private List<P4BaseCredentials> lookupCredentials() { Class<P4BaseCredentials> type = P4BaseCredentials.class; Jenkins scope = Jenkins.getInstance(); Authentication acl = ACL.SYSTEM; DomainRequirement domain = new DomainRequirement(); return CredentialsProvider.lookupCredentials(type, scope, acl, domain); } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#2 | 23685 | Paul Allen | Copy main -> dev | ||
#1 | 20641 | Paul Allen | Copy main -> dev (jenkinsci/p4-plugin) | ||
//guest/perforce_software/p4jenkins/main/src/test/java/org/jenkinsci/plugins/p4/credentials/PerforceCredentialsTest.java | |||||
#6 | 20598 | Paul Allen |
P4Credentials Interfaces for Mixins. Updated test cases to match changes from CredentialsNameProvider. @stephenc |
||
#5 | 16502 | Paul Allen |
Advanced Credentials option for RPC_SOCKET_SO_TIMEOUT_NICK JENKINS-31196 |
||
#4 | 15656 | Paul Allen |
Updated credentials to extend BaseStandardCredentials. Allows users to set the ID at creation. JENKINS-29702 |
||
#3 | 15293 | Paul Allen |
Add retry attempts to Perforce Tasks. If a task fails due to an exception then the task will retry based on the value specified in the connection Credential. |
||
#2 | 11132 | Paul Allen |
Fix Credential name for Template plugin Added `@NameWith` annotation to allow the implementation to override the reported Credential name. JENKINS-25682 |
||
#1 | 9690 | Paul Allen |
[Branching using p4-jenkins] Release 1.0.1 |
||
//guest/paul_allen/dev/p4-jenkins/p4-client/src/test/java/org/jenkinsci/plugins/p4/credentials/PerforceCredentialsTest.java | |||||
#1 | 9672 | Paul Allen | Refactor name from 'p4_client' to 'p4'. | ||
//guest/paul_allen/dev/p4-jenkins/p4-client/src/test/java/org/jenkinsci/plugins/p4_client/credentials/PerforceCredentialsTest.java | |||||
#4 | 8902 | Paul Allen |
Updated test cases: Pushed Workspace 'charset' to abstract Workspace class. Minor bugfixes in Workspace AutoCompletionCandidates method. |
||
#3 | 8898 | Paul Allen | Removed Deprecated 'HudsonTestCase' for Jenkins @Rule | ||
#2 | 8888 | Paul Allen |
Extended test coverage for Workspace and Credentials. - Removed ununsed methods. |
||
#1 | 8761 | Paul Allen | Basic unit tests for PerforceScm configuration and Credentials. |