@@ -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 \n Connection 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 \n Permission 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 \n Connection 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