|
24 | 24 | end |
25 | 25 |
|
26 | 26 | let(:test_file) { "tmp/a-file.txt" } |
| 27 | + let(:test_file_content) { "some content" } |
| 28 | + |
| 29 | + let(:mock_s3_client) do |
| 30 | + Aws::S3::Client.new(stub_responses: { |
| 31 | + get_object: { body: test_file_content }, |
| 32 | + }) |
| 33 | + end |
27 | 34 |
|
28 | 35 | after do |
29 | 36 | File.delete(test_file) if File.exist?(test_file) |
|
36 | 43 |
|
37 | 44 | allow(ReferenceNumberService).to receive(:generate).and_return(reference) |
38 | 45 |
|
39 | | - mock_s3_client = Aws::S3::Client.new(stub_responses: true) |
40 | 46 | allow(Aws::S3::Client).to receive(:new).and_return(mock_s3_client) |
41 | 47 | allow(mock_s3_client).to receive(:put_object) |
42 | 48 | allow(mock_s3_client).to receive(:get_object_tagging).and_return({ tag_set: [{ key: "GuardDutyMalwareScanStatus", value: scan_status }] }) |
43 | 49 |
|
44 | | - File.write(test_file, "some content") |
| 50 | + File.write(test_file, test_file_content) |
45 | 51 | end |
46 | 52 |
|
47 | 53 | context "when the file is successfully uploaded" do |
|
78 | 84 | end |
79 | 85 | end |
80 | 86 |
|
| 87 | + context "when the file unexpectedly contains binary" do |
| 88 | + # A PNG file which has been renamed to look like a TXT |
| 89 | + let(:test_file_content) { File.read("spec/fixtures/disguised_binary_file.txt") } |
| 90 | + let(:scan_status) { "NO_THREATS_FOUND" } |
| 91 | + |
| 92 | + scenario "As a form filler" do |
| 93 | + when_i_visit_the_form_start_page |
| 94 | + then_i_should_see_the_first_question |
| 95 | + then_i_see_the_file_upload_component |
| 96 | + when_i_upload_a_file |
| 97 | + and_i_click_on_continue |
| 98 | + then_i_see_the_review_file_page |
| 99 | + and_i_click_on_continue |
| 100 | + then_i_should_see_the_check_your_answers_page |
| 101 | + |
| 102 | + when_i_opt_out_of_email_confirmation |
| 103 | + and_i_submit_my_form |
| 104 | + then_my_form_should_be_submitted |
| 105 | + and_i_should_receive_a_reference_number |
| 106 | + and_an_email_submission_should_have_been_sent |
| 107 | + end |
| 108 | + end |
| 109 | + |
81 | 110 | def when_i_visit_the_form_start_page |
82 | 111 | visit form_path(mode: "form", form_id: 1, form_slug: "fill-in-this-form") |
83 | 112 | expect_page_to_have_no_axe_errors(page) |
|
0 commit comments