Skip to content

Commit 594b0e1

Browse files
dmaloney-r7dmaloney-r7
authored andcommitted
Merge pull request rapid7#3611 from shuckins-r7/bug/MSP-11021/import-reports-attr-fix
Date attrs set after creation in report import
2 parents dd55001 + 8fe9ec0 commit 594b0e1

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

lib/msf/core/db.rb

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2177,9 +2177,15 @@ def find_or_create_report(opts)
21772177
# @return [Integer] ID of created report
21782178
def report_report(opts)
21792179
return if not active
2180-
::ActiveRecord::Base.connection_pool.with_connection {
2180+
created = opts.delete(:created_at)
2181+
updated = opts.delete(:updated_at)
2182+
state = opts.delete(:state)
21812183

2184+
::ActiveRecord::Base.connection_pool.with_connection {
21822185
report = Report.new(opts)
2186+
report.created_at = created
2187+
report.updated_at = updated
2188+
21832189
unless report.valid?
21842190
errors = report.errors.full_messages.join('; ')
21852191
raise RuntimeError "Report to be imported is not valid: #{errors}"
@@ -2194,10 +2200,14 @@ def report_report(opts)
21942200
# Creates a ReportArtifact based on passed parameters.
21952201
# @param opts [Hash] of ReportArtifact attributes
21962202
def report_artifact(opts)
2203+
return if not active
2204+
21972205
artifacts_dir = Report::ARTIFACT_DIR
21982206
tmp_path = opts[:file_path]
21992207
artifact_name = File.basename tmp_path
22002208
new_path = File.join(artifacts_dir, artifact_name)
2209+
created = opts.delete(:created_at)
2210+
updated = opts.delete(:updated_at)
22012211

22022212
unless File.exists? tmp_path
22032213
raise DBImportError 'Report artifact file to be imported does not exist.'
@@ -2215,6 +2225,9 @@ def report_artifact(opts)
22152225
FileUtils.copy(tmp_path, new_path)
22162226
opts[:file_path] = new_path
22172227
artifact = ReportArtifact.new(opts)
2228+
artifact.created_at = created
2229+
artifact.updated_at = updated
2230+
22182231
unless artifact.valid?
22192232
errors = artifact.errors.full_messages.join('; ')
22202233
raise RuntimeError "Artifact to be imported is not valid: #{errors}"

0 commit comments

Comments
 (0)