Files
archived-teslamate/test/teslamate/auth_test.exs
Adrian Kumpf 0d6e288c70 Encrypt API tokens (#2360)
Store API tokens encrypted in the database.

During the database migration a randomly generated key will be used encrypt the tokens if no ENCRYPTION_KEY environment variable was provided.

If the application is started without the presence of an ENCRYPTION_KEY (or if the key failed to decrypt the existing tokens), the UI will display a warning with further instructions.
2022-02-18 17:03:13 +01:00

41 lines
1.2 KiB
Elixir

defmodule TeslaMate.AuthTest do
use TeslaMate.DataCase
alias TeslaMate.Auth
setup do
start_supervised!(TeslaMate.Vault)
:ok
end
describe "tokens" do
@valid_attrs %{refresh_token: "some refresh token", token: "some access token"}
@update_attrs %{
refresh_token: "some updated refresh token",
token: "some updated access token"
}
@invalid_attrs %{refresh_token: nil, token: nil}
test "save/1 with valid data creates or updats the tokens" do
assert Auth.get_tokens() == nil
assert :ok = Auth.save(@valid_attrs)
assert tokens = Auth.get_tokens()
assert tokens.refresh == "some refresh token"
assert tokens.access == "some access token"
assert :ok = Auth.save(@update_attrs)
assert tokens = Auth.get_tokens()
assert tokens.refresh == "some updated refresh token"
assert tokens.access == "some updated access token"
end
test "save/1 with invalid data returns error changeset" do
assert {:error, %Ecto.Changeset{} = changeset} = Auth.save(@invalid_attrs)
assert %{refresh: ["can't be blank"], access: ["can't be blank"]} ==
errors_on(changeset)
end
end
end