diff --git a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/AetherFactories.java b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/AetherFactories.java index 8b53b89aa2..32b8ef009f 100644 --- a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/AetherFactories.java +++ b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/AetherFactories.java @@ -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); } diff --git a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/AetherStubDownloader.java b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/AetherStubDownloader.java index 843f921900..1aa8a0aa4c 100644 --- a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/AetherStubDownloader.java +++ b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/AetherStubDownloader.java @@ -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, diff --git a/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/AetherStubDownloaderSpec.groovy b/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/AetherStubDownloaderSpec.groovy index 5b7ea6b86f..a2db5101da 100644 --- a/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/AetherStubDownloaderSpec.groovy +++ b/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/AetherStubDownloaderSpec.groovy @@ -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(