mirror of
https://github.com/rickbarrette/simple-aircraft-manager-rails.git
synced 2026-11-17 15:50:36 -05:00
Records integrity: history, nightly backup and check, records package
AC 120-78B chapter 3:
- Every change to logbook entries, sub-components, signatures, inspection
records, AD compliance, major records, W&B, components, squawks and
documents is kept as a RecordVersion (who, IP, when, field changes),
hash-chained per aircraft; versions can't be edited or deleted. Shown on
each logbook entry and in Activity -> Record history
- Nightly job: SQLite online-backup copy to storage/backups, verified
(integrity_check + record counts), pruned to the configured number; then
an integrity check of the history chains and every signature's seal and
fingerprint. Results on Admin -> About ("Back up and check now"); admins
are emailed on failure
- Software versions recorded (first/last seen) on Admin -> About
- Records package (Access & Sharing): logbook entries PDF with signatures,
signatures.csv, record-history.csv, self-contained status report HTML,
the .sam.zip, and a README, for the FAA/NTSB or a buyer
- Legacy (paper) records: documents can be marked as legacy records;
aircraft have an "electronic records since" date (status report, package)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
d719f663bc
commit
68a1719db2
53 files changed
+750
-12
No files matched your search
@@ -0,0 +1,59 @@
|
||||
require "test_helper"
|
||||
|
||||
# Backups copy the live database with SQLite's online backup API, which can't
|
||||
# run inside the transaction each test normally runs in: these tests commit
|
||||
# for real and clean up after themselves.
|
||||
class DatabaseBackupTest < ActionDispatch::IntegrationTest
|
||||
include ActionMailer::TestHelper
|
||||
self.use_transactional_tests = false
|
||||
|
||||
setup do
|
||||
@owner = create_user("owner@example.com")
|
||||
@a = create_aircraft(owner: @owner, tail_number: "N12345")
|
||||
@mech = create_user("mech@example.com").tap { _1.update!(name: "Sam Mechanic") }
|
||||
@ap = @mech.certificates.create!(kind: "AP", number: "7654321")
|
||||
end
|
||||
|
||||
teardown do
|
||||
FileUtils.rm_rf(DatabaseBackup::DIR)
|
||||
[ EntrySignature, LogbookEntry ].each { _1.delete_all }
|
||||
[ RecordVersion, IntegrityCheck, BackupRun, AircraftEvent, AircraftRole, UserCertificate, Aircraft, Session, Setting, User ].each(&:delete_all)
|
||||
end
|
||||
|
||||
def entry(**attrs)
|
||||
@a.logbook_entries.create!({ date: Date.new(2026, 10, 1), entry_type: "MAINTENANCE", text: "Changed oil", aircraft_hours_at_entry: 1000 }.merge(attrs))
|
||||
end
|
||||
|
||||
test "the nightly job backs up and verifies the database, prunes old copies, and emails admins on trouble" do
|
||||
admin = create_user("admin@example.com", admin: true)
|
||||
entry
|
||||
Setting.update_integers("backups_kept" => "2")
|
||||
dir = DatabaseBackup::DIR
|
||||
FileUtils.rm_rf(dir)
|
||||
3.times { |i| travel(i.minutes) { DatabaseBackup.run! } }
|
||||
run = BackupRun.latest
|
||||
assert run.ok, run.message
|
||||
assert_match "Verified: SQLite integrity check ok; 1 logbook entries", run.message
|
||||
assert_equal 2, Dir[dir.join("sam-*.sqlite3")].size
|
||||
db = SQLite3::Database.new(run.path, readonly: true)
|
||||
assert_equal 1, db.get_first_value("SELECT COUNT(*) FROM logbook_entries")
|
||||
db.close
|
||||
|
||||
assert_no_emails { RecordsIntegrityJob.perform_now }
|
||||
assert [ BackupRun.latest.ok, IntegrityCheck.latest.ok ].all?, [ BackupRun.latest.message, IntegrityCheck.latest.problems ].inspect
|
||||
LogbookEntry.update_all(text: "x") # no signatures, so this alone isn't a problem
|
||||
EntrySigner.new(entry(date: Date.new(2026, 10, 2)), user: @mech, certificate: @ap, auth_method: "password").sign!
|
||||
LogbookEntry.where(date: Date.new(2026, 10, 2)).update_all(text: "tampered")
|
||||
assert_emails 1 do
|
||||
RecordsIntegrityJob.perform_now
|
||||
end
|
||||
assert_equal [ admin.email_address ], ActionMailer::Base.deliveries.last.to
|
||||
|
||||
sign_in admin
|
||||
get admin_about_path
|
||||
assert_includes response.body, "Records integrity"
|
||||
assert_includes response.body, "changed after it was signed"
|
||||
post admin_check_records_path
|
||||
assert_redirected_to admin_about_path(anchor: "records")
|
||||
end
|
||||
end
|
||||
Reference in new issue
Block a user