Search in sources :

Example 1 with UsernamePasswordCredentials

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"));
}
Also used : GiteaAuthUser(org.jenkinsci.plugin.gitea.client.api.GiteaAuthUser) GiteaAuth(org.jenkinsci.plugin.gitea.client.api.GiteaAuth) UsernamePasswordCredentials(com.cloudbees.plugins.credentials.common.UsernamePasswordCredentials) Test(org.junit.Test)

Example 2 with UsernamePasswordCredentials

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"));
}
Also used : Jenkins(jenkins.model.Jenkins) CertificateCredentials(com.cloudbees.plugins.credentials.common.CertificateCredentials) BasicSSHUserPrivateKey(com.cloudbees.jenkins.plugins.sshcredentials.impl.BasicSSHUserPrivateKey) UsernamePasswordCredentials(com.cloudbees.plugins.credentials.common.UsernamePasswordCredentials) Test(org.junit.Test) ConfiguredWithCode(org.jenkinsci.plugins.casc.misc.ConfiguredWithCode)

Aggregations

UsernamePasswordCredentials (com.cloudbees.plugins.credentials.common.UsernamePasswordCredentials)2 Test (org.junit.Test)2 BasicSSHUserPrivateKey (com.cloudbees.jenkins.plugins.sshcredentials.impl.BasicSSHUserPrivateKey)1 CertificateCredentials (com.cloudbees.plugins.credentials.common.CertificateCredentials)1 Jenkins (jenkins.model.Jenkins)1 GiteaAuth (org.jenkinsci.plugin.gitea.client.api.GiteaAuth)1 GiteaAuthUser (org.jenkinsci.plugin.gitea.client.api.GiteaAuthUser)1 ConfiguredWithCode (org.jenkinsci.plugins.casc.misc.ConfiguredWithCode)1