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);
}
Aggregations