Skip to content
This repository has been archived by the owner on Jun 30, 2021. It is now read-only.

Commit

Permalink
Add key controller log tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mederic committed Dec 7, 2018
1 parent 434eac3 commit 50904a2
Showing 1 changed file with 103 additions and 0 deletions.
Expand Up @@ -66,6 +66,32 @@ defmodule AdminAPI.V1.AdminAuth.KeyControllerTest do
# so we can only check that it is a string with some length.
assert String.length(response["data"]["secret_key"]) > 0
end

test "generates an activity log" do
timestamp = DateTime.utc_now()
response = admin_user_request("/access_key.create")

assert response["success"] == true
key = get_last_inserted(Key)
account = Account.get_master_account()

logs = get_all_activity_logs_since(timestamp)
assert Enum.count(logs) == 1

logs
|> Enum.at(0)
|> assert_activity_log(
action: "insert",
originator: get_test_admin(),
target: key,
changes: %{
"account_uuid" => account.uuid,
"access_key" => key.access_key,
"secret_key_hash" => key.secret_key_hash
},
encrypted_changes: %{}
)
end
end

describe "/access_key.update" do
Expand Down Expand Up @@ -122,6 +148,33 @@ defmodule AdminAPI.V1.AdminAuth.KeyControllerTest do
updated = Key.get(key.id)
assert updated.secret_key_hash == key.secret_key_hash
end

test "generates an activity log" do
key = insert(:key)
timestamp = DateTime.utc_now()
response =
admin_user_request("/access_key.update", %{
id: key.id,
expired: true
})

assert response["success"] == true

logs = get_all_activity_logs_since(timestamp)
assert Enum.count(logs) == 1

logs
|> Enum.at(0)
|> assert_activity_log(
action: "update",
originator: get_test_admin(),
target: key,
changes: %{
"enabled" => false
},
encrypted_changes: %{}
)
end
end

describe "/access_key.enable_or_disable" do
Expand Down Expand Up @@ -175,6 +228,33 @@ defmodule AdminAPI.V1.AdminAuth.KeyControllerTest do
assert response["data"]["id"] == key.id
assert response["data"]["enabled"] == true
end

test "generates an activity log" do
key = insert(:key)
timestamp = DateTime.utc_now()
response =
admin_user_request("/access_key.enable_or_disable", %{
id: key.id,
enabled: false
})

assert response["success"] == true

logs = get_all_activity_logs_since(timestamp)
assert Enum.count(logs) == 1

logs
|> Enum.at(0)
|> assert_activity_log(
action: "update",
originator: get_test_admin(),
target: key,
changes: %{
"enabled" => false
},
encrypted_changes: %{}
)
end
end

describe "/access_key.delete" do
Expand Down Expand Up @@ -227,5 +307,28 @@ defmodule AdminAPI.V1.AdminAuth.KeyControllerTest do
}
}
end

test "generates an activity log" do
key = insert(:key)

timestamp = DateTime.utc_now()
response = admin_user_request("/access_key.delete", %{id: key.id})

assert response["success"] == true

key = Repo.get_by(Key, %{id: key.id})
logs = get_all_activity_logs_since(timestamp)
assert Enum.count(logs) == 1

logs
|> Enum.at(0)
|> assert_activity_log(
action: "update",
originator: get_test_admin(),
target: key,
changes: %{"deleted_at" => NaiveDateTime.to_iso8601(key.deleted_at)},
encrypted_changes: %{}
)
end
end
end

0 comments on commit 50904a2

Please sign in to comment.