Search in sources :

Example 1 with GiteaAuth

use of org.jenkinsci.plugin.gitea.client.api.GiteaAuth 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 GiteaAuth

use of org.jenkinsci.plugin.gitea.client.api.GiteaAuth in project gitea-plugin by jenkinsci.

the class GiteaAuthSourceTest method given__tokenCredential__when__convert__then__tokenAuth.

@Test
public void given__tokenCredential__when__convert__then__tokenAuth() throws Exception {
    // we use a mock to ensure that java.lang.reflect.Proxy implementations of the credential interface work
    PersonalAccessToken credential = Mockito.mock(PersonalAccessToken.class);
    Mockito.when(credential.getToken()).thenReturn(Secret.fromString("b5bc10f13665362bd61de931c731e3c74187acc4"));
    GiteaAuth auth = AuthenticationTokens.convert(GiteaAuth.class, credential);
    assertThat(auth, instanceOf(GiteaAuthToken.class));
    assertThat(((GiteaAuthToken) auth).getToken(), is("b5bc10f13665362bd61de931c731e3c74187acc4"));
}
Also used : GiteaAuthToken(org.jenkinsci.plugin.gitea.client.api.GiteaAuthToken) PersonalAccessToken(org.jenkinsci.plugin.gitea.credentials.PersonalAccessToken) GiteaAuth(org.jenkinsci.plugin.gitea.client.api.GiteaAuth) Test(org.junit.Test)

Aggregations

GiteaAuth (org.jenkinsci.plugin.gitea.client.api.GiteaAuth)2 Test (org.junit.Test)2 UsernamePasswordCredentials (com.cloudbees.plugins.credentials.common.UsernamePasswordCredentials)1 GiteaAuthToken (org.jenkinsci.plugin.gitea.client.api.GiteaAuthToken)1 GiteaAuthUser (org.jenkinsci.plugin.gitea.client.api.GiteaAuthUser)1 PersonalAccessToken (org.jenkinsci.plugin.gitea.credentials.PersonalAccessToken)1