Skip to content

Commit

Permalink
feature: enable http Proxy (#146)
Browse files Browse the repository at this point in the history
  • Loading branch information
sparsick authored Aug 27, 2024
1 parent 5c1fea3 commit fee8d30
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ public class GitHttpServerContainer extends GenericContainer<GitHttpServerContai
private final static DockerImageName DEFAULT_DOCKER_IMAGE_NAME = DockerImageName.parse("rockstorm/git-server");

private final BasicAuthenticationCredentials basicAuthenticationCredentials;
private HttpProxySetting httpProxySetting;
private boolean httpProxyEnabled = false;


/**
Expand Down Expand Up @@ -135,4 +137,20 @@ public BasicAuthenticationCredentials getBasicAuthCredentials() {
return basicAuthenticationCredentials;
}

public boolean hasHttpProxy() {
return this.httpProxyEnabled;
}

public GitHttpServerContainer withHttpProxySetting(HttpProxySetting httpProxySetting) {
withEnv("HTTP_PROXY", httpProxySetting.getHttpProxy());
withEnv("http_proxy", httpProxySetting.getHttpProxy());

withEnv("HTTPS_PROXY", httpProxySetting.getHttpsProxy());
withEnv("https_proxy", httpProxySetting.getHttpsProxy());

withEnv("NO_PROXY", httpProxySetting.getNoProxy());
withEnv("no_proxy", httpProxySetting.getNoProxy());
this.httpProxyEnabled = true;
return this;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.github.sparsick.testcontainers.gitserver.http;

import java.util.Objects;

public class HttpProxySetting {

private String httpProxy;
private String httpsProxy;
private String noProxy;

public HttpProxySetting(String httpProxy, String httpsProxy, String noProxy) {
this.httpProxy = httpProxy;
this.httpsProxy = httpsProxy;
this.noProxy = noProxy;
}

public String getHttpProxy() {
return httpProxy;
}

public String getHttpsProxy() {
return httpsProxy;
}

public String getNoProxy() {
return noProxy;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.api.errors.TransportException;
import org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.CleanupMode;
import org.junit.jupiter.api.io.TempDir;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.EnumSource;
import org.testcontainers.utility.DockerImageName;

import java.io.File;
import java.io.IOException;
Expand All @@ -20,6 +22,8 @@

public class GitHttpServerContainerTest {

private static final DockerImageName LATEST_GIT_SERVER_VERSION = GitServerVersions.V2_45.getDockerImageName();

@TempDir(cleanup = CleanupMode.NEVER)
private File tempDir;

Expand Down Expand Up @@ -71,6 +75,16 @@ void cloneWithAuthentication(GitServerVersions gitServerVersions) throws GitAPIE
assertGitPull(git, credentialsProvider);
}

@Test
void enableHttpProxySetting() throws GitAPIException, IOException {
GitHttpServerContainer containerUnderTest = new GitHttpServerContainer(LATEST_GIT_SERVER_VERSION).withHttpProxySetting(new HttpProxySetting("http://proxy.example.com", "https://proxy.example.com", ""));
containerUnderTest.start();

assertThat(containerUnderTest.hasHttpProxy()).isTrue();


}

private void assertGitPull(Git git, UsernamePasswordCredentialsProvider credentialsProvider) throws IOException, GitAPIException {
new File(tempDir, "test.txt").createNewFile();
git.add().addFilepattern(".").call();
Expand Down

0 comments on commit fee8d30

Please sign in to comment.