Skip to content

Commit f69cbbc

Browse files
committed
Fix tests for Git HTTP and SSH backend
1 parent 998f78e commit f69cbbc

File tree

2 files changed

+17
-14
lines changed

2 files changed

+17
-14
lines changed

apps/gitgud/test/gitgud/smart_http_backend_test.exs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,14 @@ defmodule GitGud.SmartHTTPBackendTest do
5050
@tag :skip
5151
test "pushes initial commit", %{user: user, repo: repo, workdir: workdir} do
5252
readme_content = "##{repo.name}\r\n\r\n#{repo.description}"
53-
assert {_output, 0} = System.cmd("git", ["init"], cd: workdir)
53+
assert {_output, 0} = System.cmd("git", ["init", "-b", "main"], cd: workdir)
5454
assert {_output, 0} = System.cmd("git", ["config", "user.name", "testbot"], cd: workdir)
5555
assert {_output, 0} = System.cmd("git", ["config", "user.email", "no-reply@git.limo"], cd: workdir)
5656
File.write!(Path.join(workdir, "README.md"), readme_content)
5757
assert {_output, 0} = System.cmd("git", ["add", "README.md"], cd: workdir)
5858
assert {_output, 0} = System.cmd("git", ["commit", "README.md", "-m", "Initial commit"], cd: workdir)
5959
assert {_output, 0} = System.cmd("git", ["remote", "add", "origin", "http://#{user.login}:qwertz@localhost:4001/#{user.login}/#{repo.name}.git"], cd: workdir)
60-
assert {"Everything up-to-date\n", 1} = System.cmd("git", ["push", "--set-upstream", "origin", "master"], cd: workdir, stderr_to_stdout: true)
60+
assert {"Everything up-to-date\n", 1} = System.cmd("git", ["push", "--set-upstream", "origin", "main"], cd: workdir, stderr_to_stdout: true)
6161
assert {:ok, agent} = GitRepo.get_agent(repo)
6262
assert {:ok, head} = GitAgent.head(agent)
6363
assert {:ok, commit} = GitAgent.peel(agent, head)
@@ -71,9 +71,10 @@ defmodule GitGud.SmartHTTPBackendTest do
7171
@tag :skip
7272
test "pushes repository", %{user: user, repo: repo, workdir: workdir} do
7373
assert {_output, 0} = System.cmd("git", ["clone", "--quiet", "https://github.com/almightycouch/gitgud.git", workdir])
74+
assert {_output, 0} = System.cmd("git", ["branch", "-m", "master", "main"], cd: workdir)
7475
assert {_output, 0} = System.cmd("git", ["remote", "rm", "origin"], cd: workdir)
7576
assert {_output, 0} = System.cmd("git", ["remote", "add", "origin", "http://#{user.login}:qwertz@localhost:4001/#{user.login}/#{repo.name}.git"], cd: workdir)
76-
assert {"Everything up-to-date\n", 1} = System.cmd("git", ["push", "--set-upstream", "origin", "master"], cd: workdir, stderr_to_stdout: true)
77+
assert {"Everything up-to-date\n", 1} = System.cmd("git", ["push", "--set-upstream", "origin", "main"], cd: workdir, stderr_to_stdout: true)
7778
assert {:ok, agent} = GitRepo.get_agent(repo)
7879
assert {:ok, head} = GitAgent.head(agent)
7980
output = Git.oid_fmt(head.oid) <> "\n"

apps/gitgud/test/gitgud/ssh_server_test.exs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,18 @@ defmodule GitGud.SSHServerTest do
1616
test "authenticates with valid credentials", %{user: user} do
1717
env_vars = [{"DISPLAY", "nothing:0"}, {"SSH_ASKPASS", Path.join([Path.dirname(__DIR__), "support", "ssh_askpass.exs"])}]
1818
args = ["-tt", "-o", "StrictHostKeyChecking=no", "-o", "PreferredAuthentications=password", "-o", "PubkeyAuthentication=no", "-o", "LogLevel=ERROR", "ssh://#{user.login}@localhost:9899"]
19-
output = "You are not allowed to start a shell.\r\nConnection to localhost closed.\r\n"
20-
assert {^output, 255} = System.cmd("ssh", args, env: env_vars, stderr_to_stdout: true)
19+
assert {output, 255} = System.cmd("ssh", args, env: env_vars, stderr_to_stdout: true)
20+
assert output =~ "You are not allowed to start a shell."
2121
end
2222

2323
test "fails to authenticates with invalid credentials", %{user: user} do
2424
env_vars = [{"DISPLAY", "nothing:0"}, {"SSH_ASKPASS", Path.join([Path.dirname(__DIR__), "support", "ssh_askpass.exs"])}]
2525
args = ["-tt", "-o", "StrictHostKeyChecking=no", "-o", "PreferredAuthentications=password", "-o", "PubkeyAuthentication=no", "-o", "LogLevel=ERROR", "ssh://#{user.login}_x@localhost:9899"]
26-
output = "Permission denied, please try again.\r\nPermission denied, please try again.\r\n#{user.login}_x@localhost: Permission denied (publickey,keyboard-interactive,password).\r\n"
27-
assert {^output, 255} = System.cmd("ssh", args, env: env_vars, stderr_to_stdout: true)
26+
assert {output, 255} = System.cmd("ssh", args, env: env_vars, stderr_to_stdout: true)
27+
assert output =~ "Permission denied, please try again."
2828
end
2929

30+
@tag timeout: 5_000
3031
test "disallows scp", %{user: user} do
3132
env_vars = [{"DISPLAY", "nothing:0"}, {"SSH_ASKPASS", Path.join([Path.dirname(__DIR__), "support", "ssh_askpass.exs"])}]
3233
args = ["-P", "9899", "mix.exs", "#{user.login}@localhost:/tmp/mix.exs"]
@@ -39,14 +40,14 @@ defmodule GitGud.SSHServerTest do
3940

4041
test "authenticates with valid public-key", %{user: user, id_rsa: id_rsa} do
4142
args = ["-tt", "-o", "StrictHostKeyChecking=no", "-o", "PreferredAuthentications=publickey", "-o", "PasswordAuthentication=no", "-o", "LogLevel=ERROR", "-i", id_rsa, "ssh://#{user.login}@localhost:9899"]
42-
output = "You are not allowed to start a shell.\r\nConnection to localhost closed.\r\n"
43-
assert {^output, 255} = System.cmd("ssh", args, stderr_to_stdout: true)
43+
assert {output, 255} = System.cmd("ssh", args, stderr_to_stdout: true)
44+
assert output =~ "You are not allowed to start a shell."
4445
end
4546

4647
test "fails to authenticates with invalid public-key", %{user: user} do
4748
args = ["-tt", "-o", "StrictHostKeyChecking=no", "-o", "PreferredAuthentications=publickey", "-o", "PasswordAuthentication=no", "-o", "LogLevel=ERROR", "ssh://#{user.login}@localhost:9899"]
48-
output = "#{user.login}@localhost: Permission denied (publickey,keyboard-interactive,password).\r\n"
49-
assert {^output, 255} = System.cmd("ssh", args, stderr_to_stdout: true)
49+
assert {output, 255} = System.cmd("ssh", args, stderr_to_stdout: true)
50+
assert output =~ "Permission denied (publickey,keyboard-interactive,password)."
5051
end
5152
end
5253

@@ -56,14 +57,14 @@ defmodule GitGud.SSHServerTest do
5657
@tag :skip
5758
test "pushes initial commit", %{user: user, id_rsa: id_rsa, repo: repo, workdir: workdir} do
5859
readme_content = "##{repo.name}\r\n\r\n#{repo.description}"
59-
assert {_output, 0} = System.cmd("git", ["init"], cd: workdir)
60+
assert {_output, 0} = System.cmd("git", ["init", "-b", "main"], cd: workdir)
6061
assert {_output, 0} = System.cmd("git", ["config", "user.name", "testbot"], cd: workdir)
6162
assert {_output, 0} = System.cmd("git", ["config", "user.email", "no-reply@git.limo"], cd: workdir)
6263
File.write!(Path.join(workdir, "README.md"), readme_content)
6364
assert {_output, 0} = System.cmd("git", ["add", "README.md"], cd: workdir)
6465
assert {_output, 0} = System.cmd("git", ["commit", "README.md", "-m", "Initial commit"], cd: workdir)
6566
assert {_output, 0} = System.cmd("git", ["remote", "add", "origin", "ssh://#{user.login}@localhost:9899/#{user.login}/#{repo.name}.git"], cd: workdir)
66-
assert {_output, 0} = System.cmd("git", ["push", "--set-upstream", "origin", "--quiet", "master"], env: [{"GIT_SSH_COMMAND", "ssh -i #{id_rsa}"}], cd: workdir)
67+
assert {_output, 0} = System.cmd("git", ["push", "--set-upstream", "origin", "--quiet", "main"], env: [{"GIT_SSH_COMMAND", "ssh -i #{id_rsa}"}], cd: workdir)
6768
assert {:ok, agent} = GitRepo.get_agent(repo)
6869
assert {:ok, head} = GitAgent.head(agent)
6970
assert {:ok, commit} = GitAgent.peel(agent, head)
@@ -77,9 +78,10 @@ defmodule GitGud.SSHServerTest do
7778
@tag :skip
7879
test "pushes repository", %{user: user, id_rsa: id_rsa, repo: repo, workdir: workdir} do
7980
assert {_output, 0} = System.cmd("git", ["clone", "--quiet", "https://github.com/almightycouch/gitgud.git", workdir])
81+
assert {_output, 0} = System.cmd("git", ["branch", "-m", "master", "main"], cd: workdir)
8082
assert {_output, 0} = System.cmd("git", ["remote", "rm", "origin"], cd: workdir)
8183
assert {_output, 0} = System.cmd("git", ["remote", "add", "origin", "ssh://#{user.login}@localhost:9899/#{user.login}/#{repo.name}.git"], cd: workdir)
82-
assert {_output, 0} = System.cmd("git", ["push", "--set-upstream", "origin", "--quiet", "master"], env: [{"GIT_SSH_COMMAND", "ssh -i #{id_rsa}"}], cd: workdir)
84+
assert {_output, 0} = System.cmd("git", ["push", "--set-upstream", "origin", "--quiet", "main"], env: [{"GIT_SSH_COMMAND", "ssh -i #{id_rsa}"}], cd: workdir)
8385
assert {:ok, agent} = GitRepo.get_agent(repo)
8486
assert {:ok, head} = GitAgent.head(agent)
8587
output = Git.oid_fmt(head.oid) <> "\n"

0 commit comments

Comments
 (0)