Search in sources :

Example 6 with GitCredentialsProviderFactory

use of org.springframework.cloud.config.server.support.GitCredentialsProviderFactory in project spring-cloud-config by spring-cloud.

the class JGitEnvironmentRepositoryTests method gitCredentialsProviderFactoryCreatesUsernamePasswordProvider.

@Test
public void gitCredentialsProviderFactoryCreatesUsernamePasswordProvider() throws Exception {
    GitCredentialsProviderFactory credentialsFactory = new GitCredentialsProviderFactory();
    Git mockGit = mock(Git.class);
    MockCloneCommand mockCloneCommand = new MockCloneCommand(mockGit);
    final String username = "someuser";
    final String password = "mypassword";
    JGitEnvironmentRepository envRepository = new JGitEnvironmentRepository(this.environment, new JGitEnvironmentProperties());
    envRepository.setGitFactory(new MockGitFactory(mockGit, mockCloneCommand));
    envRepository.setUri("git+ssh://git@somegitserver/somegitrepo");
    envRepository.setBasedir(new File("./mybasedir"));
    envRepository.setGitCredentialsProvider(credentialsFactory.createFor(envRepository.getUri(), username, password, null));
    envRepository.setCloneOnStart(true);
    envRepository.afterPropertiesSet();
    assertTrue(mockCloneCommand.getCredentialsProvider() instanceof UsernamePasswordCredentialsProvider);
    CredentialsProvider provider = mockCloneCommand.getCredentialsProvider();
    CredentialItem.Username usernameCredential = new CredentialItem.Username();
    CredentialItem.Password passwordCredential = new CredentialItem.Password();
    assertTrue(provider.supports(usernameCredential));
    assertTrue(provider.supports(passwordCredential));
    provider.get(new URIish(), usernameCredential);
    assertEquals(usernameCredential.getValue(), username);
    provider.get(new URIish(), passwordCredential);
    assertEquals(String.valueOf(passwordCredential.getValue()), password);
}
Also used : URIish(org.eclipse.jgit.transport.URIish) UsernamePasswordCredentialsProvider(org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider) CredentialItem(org.eclipse.jgit.transport.CredentialItem) Matchers.anyString(org.mockito.Matchers.anyString) CredentialsProvider(org.eclipse.jgit.transport.CredentialsProvider) UsernamePasswordCredentialsProvider(org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider) PassphraseCredentialsProvider(org.springframework.cloud.config.server.support.PassphraseCredentialsProvider) Git(org.eclipse.jgit.api.Git) GitCredentialsProviderFactory(org.springframework.cloud.config.server.support.GitCredentialsProviderFactory) File(java.io.File) Test(org.junit.Test)

Aggregations

GitCredentialsProviderFactory (org.springframework.cloud.config.server.support.GitCredentialsProviderFactory)6 Test (org.junit.Test)4 Git (org.eclipse.jgit.api.Git)3 CredentialItem (org.eclipse.jgit.transport.CredentialItem)3 URIish (org.eclipse.jgit.transport.URIish)3 Matchers.anyString (org.mockito.Matchers.anyString)3 File (java.io.File)2 CredentialsProvider (org.eclipse.jgit.transport.CredentialsProvider)2 UsernamePasswordCredentialsProvider (org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider)2 PassphraseCredentialsProvider (org.springframework.cloud.config.server.support.PassphraseCredentialsProvider)2 UnsupportedCredentialItem (org.eclipse.jgit.errors.UnsupportedCredentialItem)1 Before (org.junit.Before)1 AwsCodeCommitCredentialProvider (org.springframework.cloud.config.server.support.AwsCodeCommitCredentialProvider)1