Skip to content

Commit

Permalink
Fix moving file to local permanent folder
Browse files Browse the repository at this point in the history
Fix virus scanner spec
  • Loading branch information
sammo1235 committed Oct 2, 2024
1 parent 252f9b1 commit 1ebe9a6
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/jobs/file_scan_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def perform(key, class_name, record_id, attribute_name)
begin
file_to_scan = get_file_to_scan(file)
scan_result = VirusScanner.scan_file(file_to_scan)
status = scan_result[:malware] ? :infected : :clean
status = scan_result[:malware] ? 'infected' : 'clean'

Check failure on line 13 in app/jobs/file_scan_job.rb

View workflow job for this annotation

GitHub Actions / lint

Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

Check failure on line 13 in app/jobs/file_scan_job.rb

View workflow job for this annotation

GitHub Actions / lint

Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
record.send(:"on_scan_#{attribute_name}", status: status)
rescue VirusScanner::AuthenticationError => e
handle_authentication_error(record, attribute_name, e)
Expand Down
2 changes: 1 addition & 1 deletion app/models/concerns/scan_files.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def move_to_permanent_s3_bucket(file)

def move_to_permanent_local_folder(attribute_name)
file = send(attribute_name)
if file.present?
if file.respond_to?(:path)
new_path = file.path.sub('/tmp/', '/permanent/')
Rails.logger.debug "Moving file from #{file.path} to #{new_path}"
FileUtils.mkdir_p(File.dirname(new_path))
Expand Down
1 change: 1 addition & 0 deletions spec/lib/virus_scanner_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
allow(temp_file).to receive(:write)
allow(temp_file).to receive(:rewind)
allow(File).to receive(:open).with(file_path, "rb").and_yield(StringIO.new(file_content))
allow(IO).to receive(:copy_stream)
allow(Net::HTTP).to receive(:start).and_yield(http)
allow(http).to receive(:request).and_return(http_response)
allow_any_instance_of(Net::HTTP::Post).to receive(:body_stream=)
Expand Down

0 comments on commit 1ebe9a6

Please sign in to comment.