summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorSimponic <loganhunt@simponic.xyz>2022-12-29 17:49:42 -0700
committerSimponic <loganhunt@simponic.xyz>2022-12-29 18:04:38 -0700
commit0aab3c2027d54fc1ba834ab73fd53328952b7a1b (patch)
tree4df45d7fc9df4668f5a6bd8d49895d12fafd7448 /test
parent1a2bdccf124de6207899f59538cc0ed2efc97b5a (diff)
downloadchessh-0aab3c2027d54fc1ba834ab73fd53328952b7a1b.tar.gz
chessh-0aab3c2027d54fc1ba834ab73fd53328952b7a1b.zip
Make tests pass, rename jail threshold
Diffstat (limited to 'test')
-rw-r--r--test/auth/password_test.exs3
-rw-r--r--test/auth/pubkey_test.exs3
-rw-r--r--test/ssh/ssh_auth_test-emacs-elixir-format.exs81
-rw-r--r--test/ssh/ssh_auth_test.exs28
4 files changed, 19 insertions, 96 deletions
diff --git a/test/auth/password_test.exs b/test/auth/password_test.exs
index 5e1b1d8..8c93ea9 100644
--- a/test/auth/password_test.exs
+++ b/test/auth/password_test.exs
@@ -5,7 +5,8 @@ defmodule Chessh.Auth.PasswordAuthenticatorTest do
@valid_user %{username: "logan", password: "password"}
setup_all do
- :ok = Ecto.Adapters.SQL.Sandbox.checkout(Chessh.Repo)
+ Ecto.Adapters.SQL.Sandbox.checkout(Repo)
+ Ecto.Adapters.SQL.Sandbox.mode(Repo, {:shared, self()})
{:ok, _user} = Repo.insert(Player.registration_changeset(%Player{}, @valid_user))
diff --git a/test/auth/pubkey_test.exs b/test/auth/pubkey_test.exs
index d8236e3..da2518b 100644
--- a/test/auth/pubkey_test.exs
+++ b/test/auth/pubkey_test.exs
@@ -9,7 +9,8 @@ defmodule Chessh.Auth.PublicKeyAuthenticatorTest do
}
setup_all do
- :ok = Ecto.Adapters.SQL.Sandbox.checkout(Chessh.Repo)
+ Ecto.Adapters.SQL.Sandbox.checkout(Repo)
+ Ecto.Adapters.SQL.Sandbox.mode(Repo, {:shared, self()})
{:ok, player} = Repo.insert(Player.registration_changeset(%Player{}, @valid_user))
diff --git a/test/ssh/ssh_auth_test-emacs-elixir-format.exs b/test/ssh/ssh_auth_test-emacs-elixir-format.exs
deleted file mode 100644
index cb07259..0000000
--- a/test/ssh/ssh_auth_test-emacs-elixir-format.exs
+++ /dev/null
@@ -1,81 +0,0 @@
-defmodule Chessh.SSH.AuthTest do
- use ExUnit.Case
- alias Chessh.{Player, Repo, Key}
-
- @localhost '127.0.0.1'
- @key_name "The Gamer Machine"
- @valid_user %{username: "logan", password: "password"}
- @client_test_keys_dir Path.join(Application.compile_env!(:chessh, :key_dir), "client_keys")
- @client_pub_key 'id_ed25519.pub'
-
- setup_all do
- case Ecto.Adapters.SQL.Sandbox.checkout(Repo) do
- :ok -> nil
- {:already, :owner} -> nil
- end
-
- Ecto.Adapters.SQL.Sandbox.mode(Repo, {:shared, self()})
-
- {:ok, player} = Repo.insert(Player.registration_changeset(%Player{}, @valid_user))
-
- {:ok, key_text} = File.read(Path.join(@client_test_keys_dir, @client_pub_key))
-
- {:ok, _key} =
- Repo.insert(
- Key.changeset(%Key{}, %{key: key_text, name: @key_name})
- |> Ecto.Changeset.put_assoc(:player, player)
- )
-
- :ok
- end
-
- test "Password attempts are rate limited" do
- assert :disconnect ==
- Enum.reduce(
- 1..Application.fetch_env!(:chessh, RateLimits, :jail_threshold),
- fn _, _ ->
- Chessh.SSH.Daemon.pwd_authenticate(
- @valid_user.username,
- 'wrong_password',
- @localhost
- ) do
- end
- )
- end
-
- test "INTEGRATION - Can ssh into daemon with password or public key" do
- {:ok, sup} = Task.Supervisor.start_link()
- test_pid = self()
-
- Task.Supervisor.start_child(sup, fn ->
- {:ok, _pid} =
- :ssh.connect(@localhost, Application.fetch_env!(:chessh, :port),
- user: String.to_charlist(@valid_user.username),
- password: String.to_charlist(@valid_user.password),
- auth_methods: 'password',
- silently_accept_hosts: true
- )
-
- send(test_pid, :connected_via_password)
- end)
-
- Task.Supervisor.start_child(sup, fn ->
- {:ok, _pid} =
- :ssh.connect(@localhost, Application.fetch_env!(:chessh, :port),
- user: String.to_charlist(@valid_user.username),
- auth_methods: 'publickey',
- silently_accept_hosts: true,
- user_dir: String.to_charlist(@client_test_keys_dir)
- )
-
- send(test_pid, :connected_via_public_key)
- end)
-
- assert_receive(:connected_via_password, 500)
- assert_receive(:connected_via_public_key, 500)
- end
-
- test "INTEGRATION - User cannot have more than specified concurrent sessions" do
- :ok
- end
-end
diff --git a/test/ssh/ssh_auth_test.exs b/test/ssh/ssh_auth_test.exs
index cb07259..27d5e4c 100644
--- a/test/ssh/ssh_auth_test.exs
+++ b/test/ssh/ssh_auth_test.exs
@@ -3,17 +3,14 @@ defmodule Chessh.SSH.AuthTest do
alias Chessh.{Player, Repo, Key}
@localhost '127.0.0.1'
+ @localhost_inet {{127, 0, 0, 1}, 1}
@key_name "The Gamer Machine"
@valid_user %{username: "logan", password: "password"}
@client_test_keys_dir Path.join(Application.compile_env!(:chessh, :key_dir), "client_keys")
@client_pub_key 'id_ed25519.pub'
setup_all do
- case Ecto.Adapters.SQL.Sandbox.checkout(Repo) do
- :ok -> nil
- {:already, :owner} -> nil
- end
-
+ Ecto.Adapters.SQL.Sandbox.checkout(Repo)
Ecto.Adapters.SQL.Sandbox.mode(Repo, {:shared, self()})
{:ok, player} = Repo.insert(Player.registration_changeset(%Player{}, @valid_user))
@@ -30,15 +27,19 @@ defmodule Chessh.SSH.AuthTest do
end
test "Password attempts are rate limited" do
+ jail_attempt_threshold =
+ Application.get_env(:chessh, RateLimits)
+ |> Keyword.get(:jail_attempt_threshold)
+
assert :disconnect ==
Enum.reduce(
- 1..Application.fetch_env!(:chessh, RateLimits, :jail_threshold),
+ 0..(jail_attempt_threshold + 1),
fn _, _ ->
Chessh.SSH.Daemon.pwd_authenticate(
- @valid_user.username,
- 'wrong_password',
- @localhost
- ) do
+ @valid_user.username,
+ "wrong_password",
+ @localhost_inet
+ )
end
)
end
@@ -75,7 +76,8 @@ defmodule Chessh.SSH.AuthTest do
assert_receive(:connected_via_public_key, 500)
end
- test "INTEGRATION - User cannot have more than specified concurrent sessions" do
- :ok
- end
+ # TODO
+ # test "INTEGRATION - User cannot have more than specified concurrent sessions" do
+ # :ok
+ # end
end