Fix regression issue with serializing reported events

This commit is contained in:
adfoster-r7 2021-09-03 12:59:32 +01:00
parent 31e0e73e56
commit 4b818000fc
No known key found for this signature in database
GPG Key ID: 3BD4FA3818818F04
2 changed files with 10 additions and 2 deletions

View File

@ -168,10 +168,13 @@ class DataStore < Hash
return str
end
# Override Hash's to_h method so we can include the original case of each key
# (failing to do this breaks a number of places in framework and pro that use
# serialized datastores)
def to_h
datastore_hash = {}
self.keys.each do |k|
datastore_hash[k.to_s] = self[k]
datastore_hash[k.to_s] = self[k].to_s
end
datastore_hash
end

View File

@ -23,8 +23,13 @@ RSpec::Matchers.define :have_datastore_values do |expected|
ssh_keys = %w[RHOSTS RPORT USERNAME PASSWORD]
required_keys = http_keys + smb_keys + mysql_keys + postgres_keys + ssh_keys
datastores.map do |datastore|
# Workaround: Manually convert the datastore to a hash ourselves as `datastore.to_h` coerces all datatypes into strings
# which prevents this test suite from validating types correctly. i.e. The tests need to ensure that RPORT is correctly
# set as an integer class etc.
datastore_hash = datastore.keys.each_with_object({}) { |key, hash| hash[key] = datastore[key] }
# Slice the datastore options that we care about, ignoring other values that just add noise such as VERBOSE/WORKSPACE/etc.
datastore.to_h.slice(*required_keys)
datastore_hash.slice(*required_keys)
end
end
end