use of com.cloudbees.plugins.credentials.common.UsernamePasswordCredentials in project gitea-plugin by jenkinsci.
the class GiteaAuthSourceTest method given__userPassCredential__when__convert__then__tokenAuth.
@Test
public void given__userPassCredential__when__convert__then__tokenAuth() throws Exception {
// we use a mock to ensure that java.lang.reflect.Proxy implementations of the credential interface work
UsernamePasswordCredentials credential = Mockito.mock(UsernamePasswordCredentials.class);
Mockito.when(credential.getUsername()).thenReturn("bob");
Mockito.when(credential.getPassword()).thenReturn(Secret.fromString("secret"));
GiteaAuth auth = AuthenticationTokens.convert(GiteaAuth.class, credential);
assertThat(auth, instanceOf(GiteaAuthUser.class));
assertThat(((GiteaAuthUser) auth).getUsername(), is("bob"));
assertThat(((GiteaAuthUser) auth).getPassword(), is("secret"));
}
use of com.cloudbees.plugins.credentials.common.UsernamePasswordCredentials in project configuration-as-code-plugin by jenkinsci.
the class SystemCredentialsTest method configure_system_credentials.
@Test
@ConfiguredWithCode("SystemCredentialsTest.yml")
public void configure_system_credentials() throws Exception {
Jenkins jenkins = Jenkins.getInstance();
List<UsernamePasswordCredentials> ups = CredentialsProvider.lookupCredentials(UsernamePasswordCredentials.class, jenkins, ACL.SYSTEM, Collections.emptyList());
assertThat(ups, hasSize(1));
assertThat(ups.get(0).getPassword().getPlainText(), equalTo("1234"));
List<CertificateCredentials> certs = CredentialsProvider.lookupCredentials(CertificateCredentials.class, jenkins, ACL.SYSTEM, Collections.emptyList());
assertThat(certs, hasSize(1));
assertThat(certs.get(0).getPassword().getPlainText(), equalTo("ABCD"));
List<BasicSSHUserPrivateKey> sshPrivateKeys = CredentialsProvider.lookupCredentials(BasicSSHUserPrivateKey.class, jenkins, ACL.SYSTEM, Collections.emptyList());
assertThat(sshPrivateKeys, hasSize(2));
assertThat(sshPrivateKeys.get(0).getPassphrase().getPlainText(), equalTo("ABCD"));
}
Aggregations