Files
rickyandClaude Opus 5.5 9a20c91f5e Owners can invite mechanics again; who adds aircraft is an admin setting
- Admin → Settings → Who can add aircraft: administrators only (the
  default) or everyone. Adding an aircraft or importing a .sam.zip makes
  you its Owner, so this decides who can become one.
- A signing invitation from an Owner of the aircraft (or an
  administrator) lets the outside mechanic create an account for the
  invited address again, with a password or by signing in with SSO;
  checked when it's used. Others' signing invitations still need an
  existing account, and say so.
- Docs: who makes accounts, the new setting.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 19:09:49 -05:00

100 lines
5.1 KiB
Ruby

require "test_helper"
# Requests no form sends, found by fuzzing: each used to be a server error.
class MalformedInputTest < ActionDispatch::IntegrationTest
setup do
@owner = create_user("owner@example.com")
@a = create_aircraft(owner: @owner)
sign_in @owner
end
test "a page in a format it doesn't have is 'not acceptable', not an error" do
%w[pdf json csv zip xml].each do |ext|
get "/aircraft/#{@a.id}/report.#{ext}"
assert_response :not_acceptable, ext
end
end
test "parts can't be made into a loop, and an existing loop doesn't break the pages" do
engine = @a.components.create!(component_type: ComponentType.create!(name: "Engine"), manufacturer: "L", model: "O-320", date_in_service: Date.current)
mag = @a.components.create!(component_type: ComponentType.create!(name: "Magneto"), manufacturer: "S", model: "4370", date_in_service: Date.current, parent_component: engine)
patch aircraft_component_path(@a, engine), params: { component: { parent_component_id: mag.id } }
assert_response :unprocessable_entity
assert_nil engine.reload.parent_component_id
engine.update_column(:parent_component_id, mag.id) # as if made before the check existed
assert_equal [ mag.id ], engine.reload.ancestor_ids
assert_equal [ mag.id ], engine.descendant_ids
get new_aircraft_logbook_entry_path(@a)
assert_response :success
end
test "a link to a record that doesn't exist is a validation error" do
part = @a.components.create!(component_type: ComponentType.create!(name: "Alternator"), manufacturer: "P", model: "ALX", date_in_service: Date.current)
patch aircraft_component_path(@a, part), params: { component: { parent_component_id: 999_999 } }
assert_response :unprocessable_entity
end
test "a blank required checkbox or number takes its default" do
post aircraft_notes_path(@a), params: { aircraft_note: { text: "Blank public", public: "" } }
assert_equal false, @a.notes.last.public
end
test "text where a file belongs, or a tampered upload reference, is turned away politely" do
Setting.update_integers("anyone_adds_aircraft" => 1) # anyone may add aircraft here
post import_aircraft_oil_analyses_path(@a), params: { report: "not a file" }
assert_redirected_to new_aircraft_oil_analysis_path(@a)
post aircraft_imports_path, params: { archive: "not a file" }
assert_redirected_to new_aircraft_import_path
post aircraft_logbook_imports_path(@a), params: { pages: [ "not a file" ] }
assert_redirected_to new_aircraft_logbook_import_path(@a)
post aircraft_squawks_path(@a), params: { squawk: { issue_reported: "Leak", attachments: [ "eyJfcmFpbHMiOnt9fQ==--forged" ] } }
assert_response :redirect
assert_equal "Something in that form couldn't be saved. Check what you entered and try again.", flash[:alert]
end
test "a null byte is refused up front" do
post aircraft_notes_path(@a), params: { aircraft_note: { text: "a\u0000b" } }
assert_response :bad_request
assert_equal 0, @a.notes.count
end
test "a number too big to store is turned away politely" do
admin = create_user("admin@example.com", admin: true)
sign_in admin
template = LogbookTemplate.create!(name: "T", log_type: "AC", entry_type: "MAINTENANCE", text: "x")
patch admin_logbook_template_path(template), params: { logbook_template: { position: "9" * 40 } }
assert_response :redirect
assert_match "couldn't be saved", flash[:alert]
end
test "a rejected photo shows the form's error, not a server error" do
patch aircraft_path(@a), params: { aircraft: { picture: Rack::Test::UploadedFile.new(StringIO.new("<html>not a photo</html>"), "text/html", original_filename: "photo.html") } }
assert_response :unprocessable_entity
patch aircraft_path(@a), params: { aircraft: { picture: Rack::Test::UploadedFile.new(StringIO.new(""), "image/jpeg", original_filename: "empty.jpg") } }
assert_response :unprocessable_entity
end
test "photos measured without dimensions (uploaded before image processing) still get thumbnails" do
jpeg = Vips::Image.black(400, 300).jpegsave_buffer
@a.picture.attach(io: StringIO.new(jpeg), filename: "old.jpg", content_type: "image/jpeg")
@a.picture.blob.update!(metadata: { identified: true, analyzed: true }) # as older uploads were recorded
get aircraft_path(@a)
assert_select "img[src*='/representations/']"
squawk = @a.squawks.create!(issue_reported: "Leak", reported_by: @owner)
squawk.attachments.attach(io: StringIO.new(jpeg), filename: "PXL_1.jpg", content_type: "image/jpeg")
squawk.attachments.first.blob.update!(metadata: { identified: true, analyzed: true })
get aircraft_squawks_path(@a)
assert_select "a[data-gallery-target=item] img[src*='/representations/']"
end
test "if resizing a photo fails anyway, the original is sent instead of an error" do
@a.picture.attach(io: StringIO.new("GIF89a not really"), filename: "broken.gif", content_type: "image/gif")
get url_for(@a.picture.variant(:thumb))
assert_response :redirect
assert_match %r{/rails/active_storage/blobs/redirect/}, response.location
end
end