Skip to content

Commit

Permalink
Merge pull request #2292 from alphagov/increase-size-of-event-logs-tr…
Browse files Browse the repository at this point in the history
…ailing-message

Change trailing_message column from varchar(255) to text
  • Loading branch information
chrisroos authored Aug 2, 2023
2 parents 51b134a + 4fece10 commit cb17900
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class ChangeEventLogsTrailingMessageColumn < ActiveRecord::Migration[7.0]
def up
change_column :event_logs, :trailing_message, :text
end

def down
change_column :event_logs, :trailing_message, :string
end
end
2 changes: 1 addition & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
t.datetime "created_at", precision: nil, null: false
t.integer "initiator_id"
t.integer "application_id"
t.string "trailing_message"
t.text "trailing_message"
t.integer "event_id"
t.decimal "ip_address", precision: 38
t.integer "user_agent_id"
Expand Down
17 changes: 17 additions & 0 deletions test/services/user_update_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,23 @@ class UserUpdateTest < ActionView::TestCase
assert_equal parsed_ip_address, add_event.ip_address_string
end

should "log the addition of a large number of permissions" do
current_user = create(:superadmin_user)
ip_address = "1.2.3.4"

affected_user = create(:user)
permissions = (0..100).map { |i| "permission-#{i}" }
app = create(:application, name: "App", with_supported_permissions: permissions)

params = { supported_permission_ids: app.supported_permissions.map(&:id) }
UserUpdate.new(affected_user, params, current_user, ip_address).call

add_event = EventLog.where(event_id: EventLog::PERMISSIONS_ADDED.id).last
logged_permissions = add_event.trailing_message.sub(/^\(/, "").sub(/\)$/, "").gsub(/ /, "").split(",")

assert Set.new(permissions).subset?(Set.new(logged_permissions))
end

should "record when 2SV exemption has been removed" do
current_user = create(:superadmin_user)
ip_address = "1.2.3.4"
Expand Down

0 comments on commit cb17900

Please sign in to comment.