Fixed broken tests

This commit is contained in:
Marcin Grzejszczak
2020-04-06 12:13:56 +02:00
parent 0a6d93a8d6
commit 3032069781
3 changed files with 29 additions and 7 deletions

View File

@@ -134,8 +134,15 @@ final class AetherFactories {
private static File userSettings() {
String user = fromSystemPropOrEnv(MAVEN_USER_SETTINGS_LOCATION);
if (user == null) {
return new File(new File(System.getProperty("user.home")).getAbsoluteFile(),
File file = new File(new File(System.getProperty("user.home")).getAbsoluteFile(),
File.separator + ".m2" + File.separator + "settings.xml");
if (log.isDebugEnabled()) {
log.debug("No custom maven user settings provided, will use [" + file + "]");
}
return file;
}
if (log.isDebugEnabled()) {
log.debug("Custom location provided for user settings [" + user + "]");
}
return new File(user);
}

View File

@@ -178,16 +178,22 @@ public class AetherStubDownloader implements StubDownloader {
if (StringUtils.hasText(stubRunnerOptions.serverId)) {
Server stubServer = this.settings.getServer(stubRunnerOptions.serverId);
if (stubServer != null) {
if (log.isDebugEnabled()) {
log.debug("Custom server id [" + stubServer.getId() + "] passed will resolve credentials");
}
SettingsDecryptionRequest settingsDecryptionRequest = new DefaultSettingsDecryptionRequest(
stubServer);
String stubServerPassword = new MavenSettings().createSettingsDecrypter()
.decrypt(settingsDecryptionRequest).getServer().getPassword();
return new AuthenticationBuilder().addUsername(stubServer.getUsername())
.addPassword(stubServerPassword).build();
return buildAuthentication(stubServerPassword, stubServer.getUsername());
}
}
return new AuthenticationBuilder().addUsername(stubRunnerOptions.username)
.addPassword(stubRunnerOptions.password).build();
return buildAuthentication(stubRunnerOptions.password, stubRunnerOptions.username);
}
Authentication buildAuthentication(String stubServerPassword, String username) {
return new AuthenticationBuilder().addUsername(username)
.addPassword(stubServerPassword).build();
}
private File unpackedJar(String resolvedVersion, String stubsGroup,

View File

@@ -18,6 +18,7 @@ package org.springframework.cloud.contract.stubrunner
import io.specto.hoverfly.junit.HoverflyRule
import org.eclipse.aether.RepositorySystemSession
import org.eclipse.aether.repository.Authentication
import org.junit.Rule
import org.junit.rules.TemporaryFolder
import spock.lang.Specification
@@ -110,10 +111,18 @@ class AetherStubDownloaderSpec extends Specification {
and:
StubRunnerOptions stubRunnerOptions = new StubRunnerOptionsBuilder()
.withStubsMode(StubRunnerProperties.StubsMode.REMOTE)
.withStubRepositoryRoot("file://" + folder.newFolder().absolutePath)
.withStubRepositoryRoot(AetherStubDownloaderSpec.getResource("/m2repo/repository").toString())
.withServerId("my-server")
.build()
AetherStubDownloader aetherStubDownloader = new AetherStubDownloader(stubRunnerOptions)
AetherStubDownloader aetherStubDownloader = new AetherStubDownloader(stubRunnerOptions) {
@Override
Authentication buildAuthentication(String stubServerPassword, String username) {
assert username == "admin"
// hashed {ha7QXbuAf9wH5uVeYJGWg+SC8fdkufPVfdtpTK8Yk3E=}
assert stubServerPassword == "mypassword"
return super.buildAuthentication(stubServerPassword, username)
}
}
when:
def jar = aetherStubDownloader.downloadAndUnpackStubJar(