Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
public class GitServerContainer extends GenericContainer<GitServerContainer> {

private static final String GIT_PASSWORD_KEY = "GIT_PASSWORD";
private static DockerImageName DEFAULT_DOCKER_IMAGE_NAME = DockerImageName.parse("rockstorm/git-server");
private static final DockerImageName DEFAULT_DOCKER_IMAGE_NAME = DockerImageName.parse("rockstorm/git-server");
private String gitRepoName = "testRepo";
private String pathToExistingRepo;
private SshIdentity sshClientIdentity;
Expand Down Expand Up @@ -153,6 +153,7 @@ private void configureGitRepository() {
execInContainer("git", "init", "--bare", gitRepoPath);
execInContainer("chown", "-R", "git:git", "/srv");
}
execInContainer("git", "symbolic-ref", "HEAD", "refs/heads/main");
} catch (IOException | InterruptedException e) {
throw new RuntimeException("Configure Git repository failed",e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import java.util.List;
import java.util.Map;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;

import static org.assertj.core.api.Assertions.assertThatNoException;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
Expand Down Expand Up @@ -126,7 +125,6 @@ void copyExistingGitRepo(@TempDir File sampleRepo) throws GitAPIException, IOExc
Git.cloneRepository()
.setURI(gitRepoURI.toString())
.setDirectory(tempDir)
.setBranch("main")
.setTransportConfigCallback(GitServerContainerTest::configureWithPasswordAndNoHostKeyChecking)
.call()
);
Expand All @@ -149,7 +147,6 @@ void copyExistingGitRepoWithCustomRepoName(@TempDir File sampleRepo) throws IOEx
Git.cloneRepository()
.setURI(gitRepoURI.toString())
.setDirectory(tempDir)
.setBranch("main")
.setTransportConfigCallback(GitServerContainerTest::configureWithPasswordAndNoHostKeyChecking)
.call()
);
Expand All @@ -170,7 +167,6 @@ void setupGitRepo(GitServerVersions gitServer) {
Git.cloneRepository()
.setURI(gitRepoURI.toString())
.setDirectory(tempDir)
.setBranch("main")
.setTransportConfigCallback(GitServerContainerTest::configureWithPasswordAndNoHostKeyChecking)
.call()
);
Expand All @@ -189,7 +185,6 @@ void pubKeyAuth(GitServerVersions gitServer) {
Git.cloneRepository()
.setURI(gitRepoURI.toString())
.setDirectory(tempDir)
.setBranch("main")
.setTransportConfigCallback(configureWithSshIdentityAndNoHostVerification(containerUnderTest.getSshClientIdentity()))
.call()
);
Expand All @@ -210,12 +205,30 @@ void strictHostKeyVerifivation(GitServerVersions gitServer) {
Git.cloneRepository()
.setURI(gitRepoURI.toString())
.setDirectory(tempDir)
.setBranch("main")
.setTransportConfigCallback(configureWithSshIdentityAndHostKey(containerUnderTest.getSshClientIdentity(), containerUnderTest.getHostKey()))
.call()
);
}

@ParameterizedTest
@EnumSource(GitServerVersions.class)
void defaultBranch(GitServerVersions gitServer) throws GitAPIException, IOException {
var containerUnderTest = new GitServerContainer(gitServer.getDockerImageName());

containerUnderTest.start();

URI gitRepoURI = containerUnderTest.getGitRepoURIAsSSH();

Git repo = Git.cloneRepository()
.setURI(gitRepoURI.toString())
.setDirectory(tempDir)
.setTransportConfigCallback(GitServerContainerTest::configureWithPasswordAndNoHostKeyChecking)
.call();

String currentBranch = repo.getRepository().getBranch();
assertThat(currentBranch).isEqualTo("main");
}

@NotNull
private TransportConfigCallback configureWithSshIdentityAndHostKey(SshIdentity sshIdentity, SshHostKey hostKey) {
return transport -> {
Expand Down