-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2ef158d
commit 9bef1bc
Showing
13 changed files
with
81 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
class AuditLog < ApplicationRecord | ||
validates :request_id, :action, :result, :subject, presence: true | ||
|
||
if Config[:db_encryption] | ||
encrypts :request_id, :action, :result, :error, :subject, :cert_common_name, :kv_path | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
class CreateAuditLogs < ActiveRecord::Migration[7.2] | ||
def change | ||
create_table :audit_logs do |t| | ||
t.string :request_id, null: false | ||
t.string :action, null: false | ||
t.string :result, null: false | ||
t.string :error, null: true | ||
t.string :subject, null: false | ||
t.string :cert_common_name, null: true | ||
t.string :kv_path, null: true | ||
t.timestamps | ||
end | ||
add_index :audit_logs, [ :subject, :created_at ] | ||
end | ||
end |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,13 +5,7 @@ def setup | |
@domain = domains(:owner_match) | ||
@identity = Identity.new(subject: @domain.users.first) | ||
@cr = Requests::CertIssueRequest.new(common_name: @domain.fqdn) | ||
@log = Tempfile.new("log-test") | ||
Config[:audit_log_file] = @log.path | ||
end | ||
|
||
def teardown | ||
@log.close | ||
@log.unlink | ||
Thread.current[:request_id] = "request_id" | ||
end | ||
|
||
test ".call will be logged as success" do | ||
|
@@ -23,7 +17,9 @@ def call | |
end) | ||
rslt = SuccessAction.call(identity: @identity, request: @cr) | ||
assert rslt.success? | ||
assert_match %Q("action":"SuccessAction","result":"success","subject":"[email protected]","cert_common_name":"example.com"), @log.readlines.last | ||
log = AuditLog.last | ||
expected = { "action"=>"SuccessAction", "result"=>"success", "subject"=>"[email protected]", "cert_common_name"=>"example.com" } | ||
assert expected <= log.attributes | ||
end | ||
|
||
test ".call will be logged as failure" do | ||
|
@@ -36,6 +32,8 @@ def call | |
end) | ||
rslt = FailAction.call(identity: @identity, request: @cr) | ||
assert_not rslt.success? | ||
assert_match %Q("action":"FailAction","result":"failure","subject":"[email protected]","cert_common_name":"example.com"), @log.readlines.last | ||
log = AuditLog.last | ||
expected = { "action"=>"FailAction", "result"=>"failure", "subject"=>"[email protected]", "cert_common_name"=>"example.com" } | ||
assert expected <= log.attributes | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ class AuthenticateIdentityTest < ActiveSupport::TestCase | |
def setup | ||
@interactor = AuthenticateIdentity | ||
@identity = Identity.new(subject: "[email protected]", groups: [ "admin_group" ]) | ||
Thread.current[:request_id] = "request_id" | ||
end | ||
|
||
test ".call success" do | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
require "test_helper" | ||
|
||
class AuditLogTest < ActiveSupport::TestCase | ||
def setup | ||
@attributes = { | ||
request_id: "uuid1", | ||
action: "string1", | ||
result: "string2", | ||
subject: "string3", | ||
cert_common_name: "string4" | ||
} | ||
@audit_log = AuditLog.new(@attributes) | ||
end | ||
|
||
test "#new should set attributes from attributes argument" do | ||
@attributes.each do |key, value| | ||
assert_equal value, @audit_log.send(key), "Attribute #{key} was not set correctly" | ||
end | ||
end | ||
|
||
test "#valid? should be valid with valid attributes" do | ||
assert @audit_log.valid? | ||
end | ||
|
||
test "#valid? should require an result" do | ||
@audit_log.result = nil | ||
assert_not @audit_log.valid? | ||
assert_includes @audit_log.errors[:result], "can't be blank" | ||
end | ||
end |