scout_apm 6.3.2 → 6.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/semgrep.yml +41 -0
- data/.github/workflows/test.yml +2 -0
- data/CHANGELOG.markdown +14 -0
- data/data/cacert.pem +2088 -3060
- data/lib/scout_apm/config.rb +49 -1
- data/lib/scout_apm/reporter.rb +2 -1
- data/lib/scout_apm/serializers/payload_serializer_to_json.rb +20 -36
- data/lib/scout_apm/utils/sql_sanitizer.rb +14 -13
- data/lib/scout_apm/version.rb +1 -1
- data/test/unit/config_test.rb +104 -0
- data/test/unit/reporter_test.rb +24 -0
- data/test/unit/serializers/payload_serializer_test.rb +26 -0
- data/test/unit/sql_sanitizer_test.rb +53 -0
- metadata +3 -1
data/lib/scout_apm/config.rb
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
require 'yaml'
|
|
2
2
|
require 'erb'
|
|
3
|
+
require 'openssl'
|
|
3
4
|
|
|
4
5
|
require 'scout_apm/environment'
|
|
5
6
|
|
|
@@ -353,6 +354,19 @@ module ScoutApm
|
|
|
353
354
|
"Resolved Setting Values:\n" +
|
|
354
355
|
all_settings.map{|hsh| "#{hsh[:source]} - #{hsh[:key]}: #{hsh[:value]}"}.join("\n")
|
|
355
356
|
)
|
|
357
|
+
logger.debug(ssl_trust_store_message)
|
|
358
|
+
end
|
|
359
|
+
|
|
360
|
+
def ssl_trust_store_message
|
|
361
|
+
cert_file = value('ssl_cert_file')
|
|
362
|
+
if cert_file.nil?
|
|
363
|
+
"HTTPS reporting verifies against OpenSSL's default trust store " \
|
|
364
|
+
"(#{OpenSSL::X509::DEFAULT_CERT_FILE}, #{OpenSSL::X509::DEFAULT_CERT_DIR})"
|
|
365
|
+
elsif cert_file == ConfigDefaults::BUNDLED_SSL_CERT_FILE
|
|
366
|
+
"HTTPS reporting verifies against the bundled CA file #{cert_file}"
|
|
367
|
+
else
|
|
368
|
+
"HTTPS reporting verifies against ssl_cert_file #{cert_file}"
|
|
369
|
+
end
|
|
356
370
|
end
|
|
357
371
|
|
|
358
372
|
def logger
|
|
@@ -360,6 +374,40 @@ module ScoutApm
|
|
|
360
374
|
end
|
|
361
375
|
|
|
362
376
|
class ConfigDefaults
|
|
377
|
+
# Mozilla's CA bundle as published by curl (https://curl.se/docs/caextract.html).
|
|
378
|
+
# To refresh it, download https://curl.se/ca/cacert.pem, check it against
|
|
379
|
+
# https://curl.se/ca/cacert.pem.sha256, and replace data/cacert.pem unmodified.
|
|
380
|
+
BUNDLED_SSL_CERT_FILE = File.join(File.dirname(__FILE__), *%w[.. .. data cacert.pem])
|
|
381
|
+
|
|
382
|
+
def self.default_ssl_cert_file(cert_file=OpenSSL::X509::DEFAULT_CERT_FILE,
|
|
383
|
+
cert_dir=OpenSSL::X509::DEFAULT_CERT_DIR,
|
|
384
|
+
env=ENV)
|
|
385
|
+
# SSL_CERT_FILE and SSL_CERT_DIR replace OpenSSL's default store, often
|
|
386
|
+
# with a bundle meant only for internal services. The bundled file has
|
|
387
|
+
# always taken precedence over them, so keep it when either is set.
|
|
388
|
+
# SCOUT_SSL_CERT_FILE still selects any other file explicitly.
|
|
389
|
+
return BUNDLED_SSL_CERT_FILE if env.key?(OpenSSL::X509::DEFAULT_CERT_FILE_ENV) ||
|
|
390
|
+
env.key?(OpenSSL::X509::DEFAULT_CERT_DIR_ENV)
|
|
391
|
+
|
|
392
|
+
# nil leaves Net::HTTP on OpenSSL's default trust store.
|
|
393
|
+
return nil if (File.file?(cert_file) && File.readable?(cert_file)) ||
|
|
394
|
+
hashed_cert_dir?(cert_dir)
|
|
395
|
+
|
|
396
|
+
BUNDLED_SSL_CERT_FILE
|
|
397
|
+
end
|
|
398
|
+
|
|
399
|
+
# OpenSSL only finds CAs in a directory through hash links such as
|
|
400
|
+
# "5ad8a5d6.0". A directory without any, like the empty /etc/ssl/certs
|
|
401
|
+
# left by installing openssl without ca-certificates, has nothing to trust.
|
|
402
|
+
# Names are matched as binary because this runs at require time, and a
|
|
403
|
+
# name that is invalid in the locale's encoding would raise ArgumentError.
|
|
404
|
+
def self.hashed_cert_dir?(cert_dir)
|
|
405
|
+
File.directory?(cert_dir) &&
|
|
406
|
+
Dir.entries(cert_dir).any? { |name| name.b =~ /\A\h{8}\.\d+\z/n }
|
|
407
|
+
rescue SystemCallError
|
|
408
|
+
false
|
|
409
|
+
end
|
|
410
|
+
|
|
363
411
|
DEFAULTS = {
|
|
364
412
|
'compress_payload' => true,
|
|
365
413
|
'detailed_middleware' => false,
|
|
@@ -400,7 +448,7 @@ module ScoutApm
|
|
|
400
448
|
'use_prepend' => false,
|
|
401
449
|
'alias_method_instruments' => [],
|
|
402
450
|
'prepend_instruments' => [],
|
|
403
|
-
'ssl_cert_file' =>
|
|
451
|
+
'ssl_cert_file' => default_ssl_cert_file,
|
|
404
452
|
'errors_enabled' => false,
|
|
405
453
|
'errors_ignored_exceptions' => %w(ActiveRecord::RecordNotFound ActionController::RoutingError),
|
|
406
454
|
'errors_filtered_params' => %w(password s3-key),
|
data/lib/scout_apm/reporter.rb
CHANGED
|
@@ -126,7 +126,8 @@ module ScoutApm
|
|
|
126
126
|
proxy_uri.password).new(url.host, url.port)
|
|
127
127
|
if url.is_a?(URI::HTTPS)
|
|
128
128
|
http.use_ssl = true
|
|
129
|
-
|
|
129
|
+
cert_file = config.value("ssl_cert_file")
|
|
130
|
+
http.ca_file = cert_file unless cert_file.nil?
|
|
130
131
|
http.verify_mode = VERIFY_MODE
|
|
131
132
|
end
|
|
132
133
|
http
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
require 'json'
|
|
2
|
+
|
|
1
3
|
module ScoutApm
|
|
2
4
|
module Serializers
|
|
3
5
|
module PayloadSerializerToJson
|
|
@@ -39,50 +41,32 @@ module ScoutApm
|
|
|
39
41
|
end
|
|
40
42
|
|
|
41
43
|
def jsonify_hash(hash)
|
|
42
|
-
|
|
43
|
-
hash.each do |key, value|
|
|
44
|
-
formatted_key = format_by_type(key)
|
|
45
|
-
formatted_value = format_by_type(value)
|
|
46
|
-
str_parts << "#{formatted_key}:#{formatted_value}"
|
|
47
|
-
end
|
|
48
|
-
"{#{str_parts.join(",")}}"
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
ESCAPE_MAPPINGS = {
|
|
52
|
-
# Stackoverflow answer on gsub matches and backslashes
|
|
53
|
-
# https://stackoverflow.com/a/4149087/2705125
|
|
54
|
-
'\\' => '\\\\\\\\',
|
|
55
|
-
"\b" => '\\b',
|
|
56
|
-
"\t" => '\\t',
|
|
57
|
-
"\n" => '\\n',
|
|
58
|
-
"\f" => '\\f',
|
|
59
|
-
"\r" => '\\r',
|
|
60
|
-
'"' => '\\"',
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
def escape(string)
|
|
64
|
-
ESCAPE_MAPPINGS.inject(string.to_s) {|s, (bad, good)|
|
|
65
|
-
s.gsub(bad, good)
|
|
66
|
-
}
|
|
44
|
+
JSON.generate(json_ready(hash), :allow_nan => true, :max_nesting => false)
|
|
67
45
|
end
|
|
68
46
|
|
|
69
|
-
def
|
|
70
|
-
case
|
|
47
|
+
def json_ready(value)
|
|
48
|
+
case value
|
|
71
49
|
when Hash
|
|
72
|
-
|
|
50
|
+
value.each_with_object({}) { |(key, item), ready| ready[json_ready(key)] = json_ready(item) }
|
|
73
51
|
when Array
|
|
74
|
-
|
|
75
|
-
|
|
52
|
+
value.map { |item| json_ready(item) }
|
|
53
|
+
when Integer, Float, nil
|
|
54
|
+
value
|
|
76
55
|
when Numeric
|
|
77
|
-
|
|
56
|
+
value.to_f
|
|
78
57
|
when Time
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
else # strings and everything
|
|
83
|
-
%Q["#{escape(formatee)}"]
|
|
58
|
+
value.iso8601
|
|
59
|
+
else
|
|
60
|
+
valid_utf8(value.to_s)
|
|
84
61
|
end
|
|
85
62
|
end
|
|
63
|
+
|
|
64
|
+
def valid_utf8(string)
|
|
65
|
+
return string if string.valid_encoding? && string.encoding != Encoding::BINARY
|
|
66
|
+
|
|
67
|
+
string = string.dup.force_encoding(Encoding::UTF_8)
|
|
68
|
+
string.valid_encoding? ? string : string.scrub
|
|
69
|
+
end
|
|
86
70
|
end
|
|
87
71
|
end
|
|
88
72
|
end
|
|
@@ -11,6 +11,10 @@ module ScoutApm
|
|
|
11
11
|
MULTIPLE_QUESTIONS = /\?(,\?)+/.freeze
|
|
12
12
|
|
|
13
13
|
PSQL_VAR_INTERPOLATION = %r|\[\[.*\]\]\s*\z|.freeze
|
|
14
|
+
# A line holding only a bind list, optionally followed by /* */ comments.
|
|
15
|
+
# The list body can't run past a "/*", and a comment body stops at its
|
|
16
|
+
# first "*/", so each line is matched in linear time.
|
|
17
|
+
PSQL_VAR_INTERPOLATION_LINES = %r{^[ \t]*\[\[(?:[^/\n]|/(?!\*))*\]\](?=(?:[ \t]*/\*(?:[^*\n]|\*(?!/))*\*/)*[ \t\r]*$)}.freeze
|
|
14
18
|
PSQL_REMOVE_STRINGS = /'(?:[^']|'')*'/.freeze
|
|
15
19
|
PSQL_REMOVE_JSON_STRINGS = /:"(?:[^"]|"")*"/.freeze
|
|
16
20
|
PSQL_REMOVE_INTEGERS = /(?<!LIMIT )\b\d+\b/.freeze
|
|
@@ -44,7 +48,6 @@ module ScoutApm
|
|
|
44
48
|
def initialize(sql)
|
|
45
49
|
@raw_sql = sql
|
|
46
50
|
@database_engine = ScoutApm::Agent.instance.context.environment.database_engine
|
|
47
|
-
@sanitized = false # only sanitize once.
|
|
48
51
|
end
|
|
49
52
|
|
|
50
53
|
def sql
|
|
@@ -52,17 +55,12 @@ module ScoutApm
|
|
|
52
55
|
end
|
|
53
56
|
|
|
54
57
|
def to_s
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
when :postgres then to_s_postgres
|
|
62
|
-
when :mysql then to_s_mysql
|
|
63
|
-
when :sqlite then to_s_sqlite
|
|
64
|
-
when :sqlserver then to_s_sqlserver
|
|
65
|
-
end
|
|
58
|
+
@to_s ||= case database_engine
|
|
59
|
+
when :postgres then to_s_postgres
|
|
60
|
+
when :mysql then to_s_mysql
|
|
61
|
+
when :sqlite then to_s_sqlite
|
|
62
|
+
when :sqlserver then to_s_sqlserver
|
|
63
|
+
end
|
|
66
64
|
end
|
|
67
65
|
|
|
68
66
|
private
|
|
@@ -77,7 +75,10 @@ module ScoutApm
|
|
|
77
75
|
|
|
78
76
|
def to_s_postgres
|
|
79
77
|
sql.gsub!(PSQL_PLACEHOLDER, '?')
|
|
80
|
-
sql.
|
|
78
|
+
if sql.include?('[[')
|
|
79
|
+
sql.gsub!(PSQL_VAR_INTERPOLATION, '')
|
|
80
|
+
sql.gsub!(PSQL_VAR_INTERPOLATION_LINES, '')
|
|
81
|
+
end
|
|
81
82
|
# sql.gsub!(PSQL_REMOVE_STRINGS, '?')
|
|
82
83
|
sql.gsub!(PSQL_AFTER_WHERE) {|c| c.gsub(PSQL_REMOVE_STRINGS, '?')}
|
|
83
84
|
sql.gsub!(PSQL_AFTER_FROM_AS) {|c| c.gsub(PSQL_REMOVE_JSON_STRINGS, ':"?"')}
|
data/lib/scout_apm/version.rb
CHANGED
data/test/unit/config_test.rb
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
require 'test_helper'
|
|
2
2
|
|
|
3
3
|
require 'scout_apm/config'
|
|
4
|
+
require 'tmpdir'
|
|
4
5
|
|
|
5
6
|
class ConfigTest < Minitest::Test
|
|
6
7
|
def setup
|
|
@@ -21,6 +22,109 @@ class ConfigTest < Minitest::Test
|
|
|
21
22
|
assert_equal 'testval', conf.value('config_test_key')
|
|
22
23
|
end
|
|
23
24
|
|
|
25
|
+
def test_ssl_cert_file_defaults_to_os_store_when_cert_file_exists
|
|
26
|
+
Dir.mktmpdir do |dir|
|
|
27
|
+
cert_file = File.join(dir, 'cert.pem')
|
|
28
|
+
File.write(cert_file, 'certificate')
|
|
29
|
+
|
|
30
|
+
assert_nil ScoutApm::Config::ConfigDefaults.default_ssl_cert_file(cert_file, File.join(dir, 'missing'), {})
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def test_ssl_cert_file_defaults_to_os_store_when_only_cert_dir_has_hashed_certs
|
|
35
|
+
Dir.mktmpdir do |dir|
|
|
36
|
+
File.write(File.join(dir, '5ad8a5d6.0'), 'certificate')
|
|
37
|
+
|
|
38
|
+
assert_nil ScoutApm::Config::ConfigDefaults.default_ssl_cert_file(File.join(dir, 'missing'), dir, {})
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def test_ssl_cert_file_falls_back_to_bundled_file_when_cert_dir_is_empty
|
|
43
|
+
Dir.mktmpdir do |dir|
|
|
44
|
+
defaults = ScoutApm::Config::ConfigDefaults
|
|
45
|
+
assert_equal defaults::BUNDLED_SSL_CERT_FILE,
|
|
46
|
+
defaults.default_ssl_cert_file(File.join(dir, 'missing'), dir, {})
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def test_ssl_cert_file_falls_back_to_bundled_file_when_cert_dir_has_no_hashed_certs
|
|
51
|
+
Dir.mktmpdir do |dir|
|
|
52
|
+
File.write(File.join(dir, 'README'), 'not a certificate')
|
|
53
|
+
|
|
54
|
+
defaults = ScoutApm::Config::ConfigDefaults
|
|
55
|
+
assert_equal defaults::BUNDLED_SSL_CERT_FILE,
|
|
56
|
+
defaults.default_ssl_cert_file(File.join(dir, 'missing'), dir, {})
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def test_ssl_cert_file_ignores_cert_dir_names_invalid_in_the_locale_encoding
|
|
61
|
+
# An existing directory that needs no cleanup: Dir.mktmpdir's cleanup calls
|
|
62
|
+
# Dir.entries too, which the stub would intercept.
|
|
63
|
+
dir = File.dirname(__FILE__)
|
|
64
|
+
invalid_name = "\xFFcert".dup.force_encoding('UTF-8')
|
|
65
|
+
Dir.stubs(:entries).with(dir).returns(['.', '..', invalid_name, '5ad8a5d6.0'])
|
|
66
|
+
|
|
67
|
+
assert_nil ScoutApm::Config::ConfigDefaults.default_ssl_cert_file(File.join(dir, 'missing'), dir, {})
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def test_bundled_ssl_cert_file_loads_into_a_cert_store
|
|
71
|
+
bundled = ScoutApm::Config::ConfigDefaults::BUNDLED_SSL_CERT_FILE
|
|
72
|
+
OpenSSL::X509::Store.new.add_file(bundled)
|
|
73
|
+
|
|
74
|
+
assert_operator File.binread(bundled).scan('-----BEGIN CERTIFICATE-----').size, :>, 100
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def test_ssl_cert_file_falls_back_to_bundled_file_without_os_store
|
|
78
|
+
Dir.mktmpdir do |dir|
|
|
79
|
+
defaults = ScoutApm::Config::ConfigDefaults
|
|
80
|
+
assert_equal defaults::BUNDLED_SSL_CERT_FILE,
|
|
81
|
+
defaults.default_ssl_cert_file(File.join(dir, 'missing.pem'), File.join(dir, 'missing-certs'), {})
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
def test_ssl_cert_file_keeps_bundled_file_when_ssl_cert_file_env_is_set
|
|
86
|
+
Dir.mktmpdir do |dir|
|
|
87
|
+
cert_file = File.join(dir, 'cert.pem')
|
|
88
|
+
File.write(cert_file, 'certificate')
|
|
89
|
+
|
|
90
|
+
defaults = ScoutApm::Config::ConfigDefaults
|
|
91
|
+
assert_equal defaults::BUNDLED_SSL_CERT_FILE,
|
|
92
|
+
defaults.default_ssl_cert_file(cert_file, dir, 'SSL_CERT_FILE' => '/etc/internal-ca.pem')
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def test_ssl_cert_file_keeps_bundled_file_when_ssl_cert_dir_env_is_set
|
|
97
|
+
Dir.mktmpdir do |dir|
|
|
98
|
+
File.write(File.join(dir, '5ad8a5d6.0'), 'certificate')
|
|
99
|
+
|
|
100
|
+
defaults = ScoutApm::Config::ConfigDefaults
|
|
101
|
+
assert_equal defaults::BUNDLED_SSL_CERT_FILE,
|
|
102
|
+
defaults.default_ssl_cert_file(File.join(dir, 'missing'), dir, 'SSL_CERT_DIR' => '/etc/internal-certs')
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
def test_ssl_trust_store_message_for_os_store
|
|
107
|
+
conf = make_fake_config('ssl_cert_file' => nil)
|
|
108
|
+
assert_match(/OpenSSL's default trust store/, conf.ssl_trust_store_message)
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
def test_ssl_trust_store_message_for_bundled_file
|
|
112
|
+
conf = make_fake_config('ssl_cert_file' => ScoutApm::Config::ConfigDefaults::BUNDLED_SSL_CERT_FILE)
|
|
113
|
+
assert_match(/bundled CA file/, conf.ssl_trust_store_message)
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
def test_ssl_trust_store_message_for_explicit_file
|
|
117
|
+
conf = make_fake_config('ssl_cert_file' => '/tmp/custom-ca.pem')
|
|
118
|
+
assert_equal 'HTTPS reporting verifies against ssl_cert_file /tmp/custom-ca.pem', conf.ssl_trust_store_message
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
def test_explicit_ssl_cert_file_overrides_default
|
|
122
|
+
ENV['SCOUT_SSL_CERT_FILE'] = '/tmp/custom-ca.pem'
|
|
123
|
+
assert_equal '/tmp/custom-ca.pem', ScoutApm::Config.without_file(@context).value('ssl_cert_file')
|
|
124
|
+
ensure
|
|
125
|
+
ENV.delete('SCOUT_SSL_CERT_FILE')
|
|
126
|
+
end
|
|
127
|
+
|
|
24
128
|
def test_loading_a_file
|
|
25
129
|
set_rack_env('production')
|
|
26
130
|
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
class ReporterTest < Minitest::Test
|
|
4
|
+
FakeContext = Struct.new(:config)
|
|
5
|
+
|
|
6
|
+
def test_http_does_not_set_ca_file_when_default_is_nil
|
|
7
|
+
config = FakeConfigOverlay.new('ssl_cert_file' => nil)
|
|
8
|
+
reporter = ScoutApm::Reporter.new(FakeContext.new(config), :checkin)
|
|
9
|
+
Net::HTTP.any_instance.expects(:ca_file=).never
|
|
10
|
+
|
|
11
|
+
http = reporter.send(:http, URI.parse('https://example.com'))
|
|
12
|
+
|
|
13
|
+
assert http.use_ssl?
|
|
14
|
+
assert_equal ScoutApm::Reporter::VERIFY_MODE, http.verify_mode
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def test_http_uses_explicit_ca_file
|
|
18
|
+
config = FakeConfigOverlay.new('ssl_cert_file' => '/tmp/custom-ca.pem')
|
|
19
|
+
reporter = ScoutApm::Reporter.new(FakeContext.new(config), :checkin)
|
|
20
|
+
Net::HTTP.any_instance.expects(:ca_file=).with('/tmp/custom-ca.pem')
|
|
21
|
+
|
|
22
|
+
reporter.send(:http, URI.parse('https://example.com'))
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -144,4 +144,30 @@ class PayloadSerializerTest < Minitest::Test
|
|
|
144
144
|
result = ScoutApm::Serializers::PayloadSerializerToJson.jsonify_hash(json)
|
|
145
145
|
assert_equal json, JSON.parse(result)
|
|
146
146
|
end
|
|
147
|
+
|
|
148
|
+
def test_encodes_non_string_values
|
|
149
|
+
hash = {
|
|
150
|
+
:time => Time.utc(2026, 10, 29, 10, 0, 1),
|
|
151
|
+
:literals => [nil, true, false, :symbol],
|
|
152
|
+
:numbers => [1, 0.5, Rational(1, 4)],
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
result = JSON.parse(ScoutApm::Serializers::PayloadSerializerToJson.jsonify_hash(hash))
|
|
156
|
+
|
|
157
|
+
assert_equal({ "time" => "2026-10-29T10:00:01Z", "literals" => [nil, "true", "false", "symbol"], "numbers" => [1, 0.5, 0.25] }, result)
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
def test_keeps_non_finite_floats
|
|
161
|
+
result = ScoutApm::Serializers::PayloadSerializerToJson.jsonify_hash({ "nan" => Float::NAN, "inf" => Float::INFINITY })
|
|
162
|
+
|
|
163
|
+
assert_equal '{"nan":NaN,"inf":Infinity}', result
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
def test_replaces_invalid_utf8_bytes
|
|
167
|
+
hash = { "utf8" => "bad \xFF byte".dup.force_encoding("UTF-8"), "binary" => "caf\xC3\xA9 \xFF".b }
|
|
168
|
+
|
|
169
|
+
result = ScoutApm::Serializers::PayloadSerializerToJson.jsonify_hash(hash)
|
|
170
|
+
|
|
171
|
+
assert_equal({ "utf8" => "bad \uFFFD byte", "binary" => "caf\u00E9 \uFFFD" }, JSON.parse(result))
|
|
172
|
+
end
|
|
147
173
|
end
|
|
@@ -25,6 +25,50 @@ module ScoutApm
|
|
|
25
25
|
assert_equal %q|SELECT "users".* FROM "users" WHERE "users"."name" = ?|, ss.to_s
|
|
26
26
|
end
|
|
27
27
|
|
|
28
|
+
def test_postgres_where_multiline_binds
|
|
29
|
+
sql = %Q|SELECT "users".* FROM "users" WHERE "users"."name" = $1 AND "users"."id" = $2\n [["name", "chris"]]\n [["id", 1]]|
|
|
30
|
+
ss = SqlSanitizer.new(sql).tap{ |it| it.database_engine = :postgres }
|
|
31
|
+
assert_equal %q|SELECT "users".* FROM "users" WHERE "users"."name" = ? AND "users"."id" = ?|, ss.to_s
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def test_postgres_where_multiline_binds_crlf
|
|
35
|
+
sql = %Q|SELECT "users".* FROM "users" WHERE "users"."name" = $1 AND "users"."id" = $2\r\n [["name", "chris"]]\r\n [["id", 1]]|
|
|
36
|
+
ss = SqlSanitizer.new(sql).tap{ |it| it.database_engine = :postgres }
|
|
37
|
+
assert_equal %q|SELECT "users".* FROM "users" WHERE "users"."name" = ? AND "users"."id" = ?|, ss.to_s
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def test_postgres_multiline_binds_before_comment
|
|
41
|
+
sql = %Q|SELECT "users".* FROM "users" WHERE "users"."name" = $1\n [["name", "chris"]]\n /*application:Blog*/|
|
|
42
|
+
ss = SqlSanitizer.new(sql).tap{ |it| it.database_engine = :postgres }
|
|
43
|
+
assert_equal %q|SELECT "users".* FROM "users" WHERE "users"."name" = ? /*application:Blog*/|, ss.to_s
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def test_postgres_multiline_binds_with_comment_on_same_line
|
|
47
|
+
sql = %Q|SELECT "users".* FROM "users" WHERE "users"."name" = $1 AND "users"."id" = $2\n [["id", 1]]\n [["name", "chris"]] /*application:Blog*/|
|
|
48
|
+
ss = SqlSanitizer.new(sql).tap{ |it| it.database_engine = :postgres }
|
|
49
|
+
assert_equal %q|SELECT "users".* FROM "users" WHERE "users"."name" = ? AND "users"."id" = ? /*application:Blog*/|, ss.to_s
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def test_postgres_keeps_array_literal_before_multiline_binds
|
|
53
|
+
sql = %Q|SELECT "users".* FROM "users" WHERE "users"."tags" = ARRAY[[1,2],[3,4]]\n [["id", 1]]|
|
|
54
|
+
ss = SqlSanitizer.new(sql).tap{ |it| it.database_engine = :postgres }
|
|
55
|
+
assert_equal %q|SELECT "users".* FROM "users" WHERE "users"."tags" = ARRAY[[?,?],[?,?]]|, ss.to_s
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
# Inputs that make an unanchored, repeated or unbounded version of the
|
|
59
|
+
# bind-list line pattern backtrack quadratically or worse.
|
|
60
|
+
def test_postgres_bind_list_line_pattern_is_linear
|
|
61
|
+
[
|
|
62
|
+
"SELECT 1 " + ("[[" * 7000),
|
|
63
|
+
("[[1]]\n" * 2700) + "x",
|
|
64
|
+
"[[" + ("]] /* x" * 2000),
|
|
65
|
+
].each do |sql|
|
|
66
|
+
assert_faster_than(0.03) do
|
|
67
|
+
sql.gsub(SqlSanitizer::PSQL_VAR_INTERPOLATION_LINES, '')
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
|
|
28
72
|
def test_postgres_strips_literals
|
|
29
73
|
# Strip strings
|
|
30
74
|
sql = %q|SELECT "users".* FROM "users" INNER JOIN "blogs" ON "blogs"."user_id" = "users"."id" WHERE (blogs.title = 'hello world')|
|
|
@@ -163,6 +207,15 @@ module ScoutApm
|
|
|
163
207
|
assert_equal %q|UPDATE "mytable" SET "myfield" = ?, "countofthings" = ? WHERE "user_id" = ?|, ss.to_s
|
|
164
208
|
end
|
|
165
209
|
|
|
210
|
+
def test_sanitizes_only_once
|
|
211
|
+
sql = %q|SELECT "users".* FROM "users" WHERE "users"."id" = 1|
|
|
212
|
+
ss = SqlSanitizer.new(sql).tap{ |it| it.database_engine = :postgres }
|
|
213
|
+
sanitized = ss.to_s
|
|
214
|
+
|
|
215
|
+
ss.expects(:to_s_postgres).never
|
|
216
|
+
assert_equal sanitized, ss.to_s
|
|
217
|
+
end
|
|
218
|
+
|
|
166
219
|
def test_postgres_multiline_sql
|
|
167
220
|
sql = %q|
|
|
168
221
|
SELECT "html_form_payloads".*
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: scout_apm
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 6.
|
|
4
|
+
version: 6.4.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Derek Haynes
|
|
@@ -216,6 +216,7 @@ extensions:
|
|
|
216
216
|
extra_rdoc_files: []
|
|
217
217
|
files:
|
|
218
218
|
- ".github/workflows/release.yml"
|
|
219
|
+
- ".github/workflows/semgrep.yml"
|
|
219
220
|
- ".github/workflows/test.yml"
|
|
220
221
|
- ".gitignore"
|
|
221
222
|
- ".rubocop.yml"
|
|
@@ -485,6 +486,7 @@ files:
|
|
|
485
486
|
- test/unit/remote/message_test.rb
|
|
486
487
|
- test/unit/remote/route_test.rb
|
|
487
488
|
- test/unit/remote/server_test.rb
|
|
489
|
+
- test/unit/reporter_test.rb
|
|
488
490
|
- test/unit/reporting_test.rb
|
|
489
491
|
- test/unit/request_histograms_test.rb
|
|
490
492
|
- test/unit/request_manager_test.rb
|