instana 1.11.8 → 1.193.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.editorconfig +10 -0
- data/Rakefile +26 -37
- data/gemfiles/libraries.gemfile +2 -0
- data/lib/instana/agent.rb +6 -0
- data/lib/instana/base.rb +2 -0
- data/lib/instana/config.rb +11 -0
- data/lib/instana/frameworks/cuba.rb +33 -0
- data/lib/instana/frameworks/instrumentation/abstract_mysql_adapter.rb +5 -7
- data/lib/instana/frameworks/instrumentation/action_controller.rb +11 -0
- data/lib/instana/frameworks/instrumentation/action_view.rb +6 -10
- data/lib/instana/frameworks/instrumentation/active_record.rb +4 -4
- data/lib/instana/frameworks/instrumentation/mysql2_adapter.rb +17 -15
- data/lib/instana/frameworks/instrumentation/mysql_adapter.rb +11 -7
- data/lib/instana/frameworks/instrumentation/postgresql_adapter.rb +33 -19
- data/lib/instana/frameworks/roda.rb +41 -0
- data/lib/instana/frameworks/sinatra.rb +17 -0
- data/lib/instana/instrumentation/dalli.rb +9 -14
- data/lib/instana/instrumentation/excon.rb +1 -1
- data/lib/instana/instrumentation/graphql.rb +77 -0
- data/lib/instana/instrumentation/grpc.rb +72 -62
- data/lib/instana/instrumentation/instrumented_request.rb +68 -0
- data/lib/instana/instrumentation/net-http.rb +44 -43
- data/lib/instana/instrumentation/rack.rb +17 -52
- data/lib/instana/instrumentation/redis.rb +15 -18
- data/lib/instana/instrumentation/resque.rb +17 -28
- data/lib/instana/instrumentation/rest-client.rb +3 -13
- data/lib/instana/secrets.rb +42 -0
- data/lib/instana/setup.rb +1 -0
- data/lib/instana/tracer.rb +6 -0
- data/lib/instana/tracing/span.rb +14 -10
- data/lib/instana/util.rb +15 -69
- data/lib/instana/version.rb +1 -1
- data/test/apps/cuba.rb +4 -0
- data/test/apps/roda.rb +3 -0
- data/test/apps/sinatra.rb +4 -0
- data/test/config_test.rb +1 -17
- data/test/frameworks/cuba_test.rb +14 -1
- data/test/frameworks/rack_test.rb +52 -19
- data/test/frameworks/rails/actioncontroller_test.rb +12 -0
- data/test/frameworks/rails/activerecord_test.rb +80 -28
- data/test/frameworks/roda_test.rb +14 -0
- data/test/frameworks/sinatra_test.rb +14 -0
- data/test/instrumentation/excon_test.rb +0 -2
- data/test/instrumentation/graphql_test.rb +116 -0
- data/test/instrumentation/instrumented_request_test.rb +84 -0
- data/test/instrumentation/redis_test.rb +10 -0
- data/test/secrets_test.rb +73 -0
- data/test/test_helper.rb +3 -9
- data/test/tracing/id_management_test.rb +4 -66
- metadata +16 -6
@@ -153,4 +153,16 @@ class ActionControllerTest < Minitest::Test
|
|
153
153
|
assert ac_span.key?(:stack)
|
154
154
|
assert 1, ac_span[:ec]
|
155
155
|
end
|
156
|
+
|
157
|
+
def test_path_template
|
158
|
+
clear_all!
|
159
|
+
|
160
|
+
Net::HTTP.get(URI.parse('http://localhost:3205/test/world'))
|
161
|
+
|
162
|
+
spans = ::Instana.processor.queued_spans
|
163
|
+
rack_span = find_first_span_by_name(spans, :rack)
|
164
|
+
|
165
|
+
assert_equal false, rack_span.key?(:error)
|
166
|
+
assert_equal '/test/world(.:format)', rack_span[:data][:http][:path_tpl]
|
167
|
+
end
|
156
168
|
end
|
@@ -2,7 +2,14 @@ require 'test_helper'
|
|
2
2
|
require 'active_record'
|
3
3
|
|
4
4
|
class ActiveRecordTest < Minitest::Test
|
5
|
+
|
6
|
+
def teardown
|
7
|
+
# Make sure defaults are back in place
|
8
|
+
::Instana.config[:sanitize_sql] = true
|
9
|
+
end
|
10
|
+
|
5
11
|
def test_config_defaults
|
12
|
+
assert ::Instana.config[:sanitize_sql] == true
|
6
13
|
assert ::Instana.config[:active_record].is_a?(Hash)
|
7
14
|
assert ::Instana.config[:active_record].key?(:enabled)
|
8
15
|
assert_equal true, ::Instana.config[:active_record][:enabled]
|
@@ -28,19 +35,14 @@ class ActiveRecordTest < Minitest::Test
|
|
28
35
|
assert span[:data][:activerecord].key?(:username)
|
29
36
|
end
|
30
37
|
|
31
|
-
|
32
|
-
found = false
|
33
38
|
if ::Rails::VERSION::MAJOR < 4
|
34
39
|
sql = "INSERT INTO \"blocks\" (\"color\", \"created_at\", \"name\", \"updated_at\") VALUES ($?, $?, $?, $?) RETURNING \"id\""
|
35
40
|
else
|
36
41
|
sql = "INSERT INTO \"blocks\" (\"name\", \"color\", \"created_at\", \"updated_at\") VALUES ($?, $?, $?, $?) RETURNING \"id\""
|
37
42
|
end
|
38
|
-
ar_spans
|
39
|
-
|
40
|
-
found = true
|
41
|
-
end
|
43
|
+
ar_span = find_first_span_by_qualifier(ar_spans) do |span|
|
44
|
+
span[:data][:activerecord][:sql] == sql
|
42
45
|
end
|
43
|
-
assert found
|
44
46
|
|
45
47
|
found = false
|
46
48
|
if ::Rails::VERSION::MAJOR >= 5
|
@@ -50,12 +52,9 @@ class ActiveRecordTest < Minitest::Test
|
|
50
52
|
else
|
51
53
|
sql = "SELECT \"blocks\".* FROM \"blocks\" WHERE \"blocks\".\"name\" = ? LIMIT ?"
|
52
54
|
end
|
53
|
-
ar_spans
|
54
|
-
|
55
|
-
found = true
|
56
|
-
end
|
55
|
+
ar_span = find_first_span_by_qualifier(ar_spans) do |span|
|
56
|
+
span[:data][:activerecord][:sql] == sql
|
57
57
|
end
|
58
|
-
assert found
|
59
58
|
|
60
59
|
found = false
|
61
60
|
if ::Rails::VERSION::MAJOR == 3
|
@@ -63,12 +62,73 @@ class ActiveRecordTest < Minitest::Test
|
|
63
62
|
else
|
64
63
|
sql = "DELETE FROM \"blocks\" WHERE \"blocks\".\"id\" = $?"
|
65
64
|
end
|
65
|
+
ar_span = find_first_span_by_qualifier(ar_spans) do |span|
|
66
|
+
span[:data][:activerecord][:sql] == sql
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_postgresql_without_sanitize
|
71
|
+
skip unless ::Instana::Test.postgresql?
|
72
|
+
|
73
|
+
# Shut SQL sanitization off
|
74
|
+
::Instana.config[:sanitize_sql] = false
|
75
|
+
# Pause so the thread can syncronize values
|
76
|
+
sleep 1
|
77
|
+
|
78
|
+
clear_all!
|
79
|
+
|
80
|
+
Net::HTTP.get(URI.parse('http://localhost:3205/test/db'))
|
81
|
+
|
82
|
+
spans = Instana.processor.queued_spans
|
83
|
+
assert_equal 6, spans.length
|
84
|
+
rack_span = find_first_span_by_name(spans, :rack)
|
85
|
+
|
86
|
+
ar_spans = find_spans_by_name(spans, :activerecord)
|
87
|
+
assert_equal 3, ar_spans.length
|
88
|
+
|
66
89
|
ar_spans.each do |span|
|
67
|
-
|
68
|
-
|
69
|
-
|
90
|
+
assert_equal "postgresql", span[:data][:activerecord][:adapter]
|
91
|
+
assert span[:data][:activerecord].key?(:host)
|
92
|
+
assert span[:data][:activerecord].key?(:username)
|
93
|
+
end
|
94
|
+
|
95
|
+
if ::Rails::VERSION::MAJOR < 4
|
96
|
+
sql = "INSERT INTO \"blocks\" (\"color\", \"created_at\", \"name\", \"updated_at\") VALUES ($1, $2, $3, $4) RETURNING \"id\""
|
97
|
+
else
|
98
|
+
sql = "INSERT INTO \"blocks\" (\"name\", \"color\", \"created_at\", \"updated_at\") VALUES ($1, $2, $3, $4) RETURNING \"id\""
|
70
99
|
end
|
71
|
-
|
100
|
+
ar_span = find_first_span_by_qualifier(ar_spans) do |span|
|
101
|
+
span[:data][:activerecord][:sql] == sql
|
102
|
+
end
|
103
|
+
assert ar_span[:data][:activerecord].key?(:binds)
|
104
|
+
assert ar_span[:data][:activerecord][:binds].is_a?(Array)
|
105
|
+
assert_equal 4, ar_span[:data][:activerecord][:binds].length
|
106
|
+
|
107
|
+
if ::Rails::VERSION::MAJOR >= 5
|
108
|
+
sql = "SELECT \"blocks\".* FROM \"blocks\" WHERE \"blocks\".\"name\" = $1 ORDER BY \"blocks\".\"id\" ASC LIMIT $2"
|
109
|
+
elsif ::Rails::VERSION::MAJOR == 4
|
110
|
+
sql = "SELECT \"blocks\".* FROM \"blocks\" WHERE \"blocks\".\"name\" = $? ORDER BY \"blocks\".\"id\" ASC LIMIT ?"
|
111
|
+
else
|
112
|
+
sql = "SELECT \"blocks\".* FROM \"blocks\" WHERE \"blocks\".\"name\" = ? LIMIT ?"
|
113
|
+
end
|
114
|
+
ar_span = find_first_span_by_qualifier(ar_spans) do |span|
|
115
|
+
span[:data][:activerecord][:sql] == sql
|
116
|
+
end
|
117
|
+
assert ar_span[:data][:activerecord].key?(:binds)
|
118
|
+
assert ar_span[:data][:activerecord][:binds].is_a?(Array)
|
119
|
+
assert_equal 2, ar_span[:data][:activerecord][:binds].length
|
120
|
+
|
121
|
+
if ::Rails::VERSION::MAJOR == 3
|
122
|
+
sql = "DELETE FROM \"blocks\" WHERE \"blocks\".\"id\" = 1"
|
123
|
+
else
|
124
|
+
sql = "DELETE FROM \"blocks\" WHERE \"blocks\".\"id\" = $1"
|
125
|
+
end
|
126
|
+
ar_span = find_first_span_by_qualifier(ar_spans) do |span|
|
127
|
+
span[:data][:activerecord][:sql] == sql
|
128
|
+
end
|
129
|
+
assert ar_span[:data][:activerecord].key?(:binds)
|
130
|
+
assert ar_span[:data][:activerecord][:binds].is_a?(Array)
|
131
|
+
assert_equal 1, ar_span[:data][:activerecord][:binds].length
|
72
132
|
end
|
73
133
|
|
74
134
|
def test_postgresql_lock_table
|
@@ -93,21 +153,13 @@ class ActiveRecordTest < Minitest::Test
|
|
93
153
|
assert_equal "postgres", ar_span[:data][:activerecord][:username]
|
94
154
|
end
|
95
155
|
|
96
|
-
|
97
|
-
|
98
|
-
if span[:data][:activerecord][:sql] == "LOCK blocks IN ACCESS EXCLUSIVE MODE"
|
99
|
-
found = true
|
100
|
-
end
|
156
|
+
ar_span = find_first_span_by_qualifier(ar_spans) do |span|
|
157
|
+
span[:data][:activerecord][:sql] == "LOCK blocks IN ACCESS EXCLUSIVE MODE"
|
101
158
|
end
|
102
|
-
assert found
|
103
159
|
|
104
|
-
|
105
|
-
|
106
|
-
if span[:data][:activerecord][:sql] == "SELECT ?"
|
107
|
-
found = true
|
108
|
-
end
|
160
|
+
ar_span = find_first_span_by_qualifier(ar_spans) do |span|
|
161
|
+
span[:data][:activerecord][:sql] == "SELECT ?"
|
109
162
|
end
|
110
|
-
assert found
|
111
163
|
end
|
112
164
|
|
113
165
|
def test_postgresql_raw_execute
|
@@ -40,5 +40,19 @@ if defined?(::Roda)
|
|
40
40
|
assert first_span[:data][:http].key?(:host)
|
41
41
|
assert_equal "example.org", first_span[:data][:http][:host]
|
42
42
|
end
|
43
|
+
|
44
|
+
def test_path_template
|
45
|
+
clear_all!
|
46
|
+
|
47
|
+
r = get '/greet/instana'
|
48
|
+
assert last_response.ok?
|
49
|
+
|
50
|
+
spans = ::Instana.processor.queued_spans
|
51
|
+
assert_equal 1, spans.count
|
52
|
+
|
53
|
+
first_span = spans.first
|
54
|
+
assert_equal :rack, first_span[:n]
|
55
|
+
assert_equal '/greet/{name}', first_span[:data][:http][:path_tpl]
|
56
|
+
end
|
43
57
|
end
|
44
58
|
end
|
@@ -48,5 +48,19 @@ if defined?(::Sinatra)
|
|
48
48
|
assert rack_span[:data][:http].key?(:host)
|
49
49
|
assert_equal "example.org", rack_span[:data][:http][:host]
|
50
50
|
end
|
51
|
+
|
52
|
+
def test_path_template
|
53
|
+
clear_all!
|
54
|
+
|
55
|
+
r = get '/greet/instana'
|
56
|
+
assert last_response.ok?
|
57
|
+
|
58
|
+
spans = ::Instana.processor.queued_spans
|
59
|
+
assert_equal 1, spans.count
|
60
|
+
|
61
|
+
first_span = spans.first
|
62
|
+
assert_equal :rack, first_span[:n]
|
63
|
+
assert_equal '/greet/:name', first_span[:data][:http][:path_tpl]
|
64
|
+
end
|
51
65
|
end
|
52
66
|
end
|
@@ -0,0 +1,116 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class GraphqlTest < Minitest::Test
|
4
|
+
class TaskType < GraphQL::Schema::Object
|
5
|
+
field :id, ID, null: false
|
6
|
+
field :action, String, null: false
|
7
|
+
end
|
8
|
+
|
9
|
+
class NewTaskType < GraphQL::Schema::Mutation
|
10
|
+
argument :action, String, required: true
|
11
|
+
field :task, TaskType, null: true
|
12
|
+
|
13
|
+
def resolve(action:)
|
14
|
+
{
|
15
|
+
task: OpenStruct.new(id: '0', action: action)
|
16
|
+
}
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
class QueryType < GraphQL::Schema::Object
|
21
|
+
field :tasks, TaskType.connection_type, null: false
|
22
|
+
|
23
|
+
def tasks()
|
24
|
+
[
|
25
|
+
OpenStruct.new(id: '0', action: 'Sample')
|
26
|
+
]
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
class MutationType < GraphQL::Schema::Object
|
31
|
+
field :create_task, mutation: NewTaskType
|
32
|
+
end
|
33
|
+
|
34
|
+
class Schema < GraphQL::Schema
|
35
|
+
query QueryType
|
36
|
+
mutation MutationType
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_it_works
|
40
|
+
assert defined?(GraphQL)
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_config_defaults
|
44
|
+
assert ::Instana.config[:graphql].is_a?(Hash)
|
45
|
+
assert ::Instana.config[:graphql].key?(:enabled)
|
46
|
+
assert_equal true, ::Instana.config[:graphql][:enabled]
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_query
|
50
|
+
clear_all!
|
51
|
+
|
52
|
+
query = "query Sample {
|
53
|
+
tasks(after: \"\", first: 10) {
|
54
|
+
nodes {
|
55
|
+
action
|
56
|
+
}
|
57
|
+
}
|
58
|
+
}"
|
59
|
+
|
60
|
+
expected_data = {
|
61
|
+
:operationName => "Sample",
|
62
|
+
:operationType => "query",
|
63
|
+
:arguments => { "tasks" => ["after", "first"] },
|
64
|
+
:fields => { "tasks" => ["nodes"], "nodes" => ["action"] }
|
65
|
+
}
|
66
|
+
expected_results = {
|
67
|
+
"data" => {
|
68
|
+
"tasks" => {
|
69
|
+
"nodes" => [{ "action" => "Sample" }]
|
70
|
+
}
|
71
|
+
}
|
72
|
+
}
|
73
|
+
|
74
|
+
results = Instana.tracer.start_or_continue_trace('graphql-test') { Schema.execute(query) }
|
75
|
+
query_span, root_span = *Instana.processor.queued_spans
|
76
|
+
|
77
|
+
assert_equal expected_results, results.to_h
|
78
|
+
assert_equal :sdk, root_span[:n]
|
79
|
+
assert_equal :'graphql.server', query_span[:n]
|
80
|
+
assert_equal expected_data, query_span[:data][:graphql]
|
81
|
+
end
|
82
|
+
|
83
|
+
def test_mutation
|
84
|
+
clear_all!
|
85
|
+
|
86
|
+
query = "mutation Sample {
|
87
|
+
createTask(action: \"Sample\") {
|
88
|
+
task {
|
89
|
+
action
|
90
|
+
}
|
91
|
+
}
|
92
|
+
}"
|
93
|
+
|
94
|
+
expected_data = {
|
95
|
+
:operationName => "Sample",
|
96
|
+
:operationType => "mutation",
|
97
|
+
:arguments => { "createTask" => ["action"] },
|
98
|
+
:fields => { "createTask" => ["task"], "task" => ["action"] }
|
99
|
+
}
|
100
|
+
expected_results = {
|
101
|
+
"data" => {
|
102
|
+
"createTask" => {
|
103
|
+
"task" => { "action" => "Sample" }
|
104
|
+
}
|
105
|
+
}
|
106
|
+
}
|
107
|
+
|
108
|
+
results = Instana.tracer.start_or_continue_trace('graphql-test') { Schema.execute(query) }
|
109
|
+
query_span, root_span = *Instana.processor.queued_spans
|
110
|
+
|
111
|
+
assert_equal expected_results, results.to_h
|
112
|
+
assert_equal :sdk, root_span[:n]
|
113
|
+
assert_equal :'graphql.server', query_span[:n]
|
114
|
+
assert_equal expected_data, query_span[:data][:graphql]
|
115
|
+
end
|
116
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class InstrumentedRequestTest < Minitest::Test
|
4
|
+
def test_skip_trace_with_header
|
5
|
+
req = Instana::InstrumentedRequest.new(
|
6
|
+
'HTTP_X_INSTANA_L' => '0;sample-data'
|
7
|
+
)
|
8
|
+
|
9
|
+
assert req.skip_trace?
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_skip_trace_without_header
|
13
|
+
req = Instana::InstrumentedRequest.new({})
|
14
|
+
|
15
|
+
refute req.skip_trace?
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_incomming_context
|
19
|
+
id = Instana::Util.generate_id
|
20
|
+
req = Instana::InstrumentedRequest.new(
|
21
|
+
'HTTP_X_INSTANA_L' => '1',
|
22
|
+
'HTTP_X_INSTANA_T' => id,
|
23
|
+
'HTTP_X_INSTANA_S' => id
|
24
|
+
)
|
25
|
+
|
26
|
+
expected = {
|
27
|
+
trace_id: id,
|
28
|
+
span_id: id,
|
29
|
+
level: '1'
|
30
|
+
}
|
31
|
+
|
32
|
+
assert_equal expected, req.incoming_context
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_request_tags
|
36
|
+
::Instana.agent.extra_headers = %w[X-Capture-This]
|
37
|
+
req = Instana::InstrumentedRequest.new(
|
38
|
+
'HTTP_HOST' => 'example.com',
|
39
|
+
'REQUEST_METHOD' => 'GET',
|
40
|
+
'HTTP_X_CAPTURE_THIS' => 'that',
|
41
|
+
'PATH_INFO' => '/'
|
42
|
+
)
|
43
|
+
|
44
|
+
expected = {
|
45
|
+
method: 'GET',
|
46
|
+
url: '/',
|
47
|
+
host: 'example.com',
|
48
|
+
header: {
|
49
|
+
"X-Capture-This": 'that'
|
50
|
+
}
|
51
|
+
}
|
52
|
+
|
53
|
+
assert_equal expected, req.request_tags
|
54
|
+
::Instana.agent.extra_headers = nil
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_correlation_data_valid
|
58
|
+
req = Instana::InstrumentedRequest.new(
|
59
|
+
'HTTP_X_INSTANA_L' => '1,correlationType=web ;correlationId=1234567890abcdef'
|
60
|
+
)
|
61
|
+
expected = {
|
62
|
+
type: 'web',
|
63
|
+
id: '1234567890abcdef'
|
64
|
+
}
|
65
|
+
|
66
|
+
assert_equal expected, req.correlation_data
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_correlation_data_invalid
|
70
|
+
req = Instana::InstrumentedRequest.new(
|
71
|
+
'HTTP_X_INSTANA_L' => '0;sample-data'
|
72
|
+
)
|
73
|
+
|
74
|
+
assert_equal({}, req.correlation_data)
|
75
|
+
end
|
76
|
+
|
77
|
+
def test_correlation_data_legacy
|
78
|
+
req = Instana::InstrumentedRequest.new(
|
79
|
+
'HTTP_X_INSTANA_L' => '1'
|
80
|
+
)
|
81
|
+
|
82
|
+
assert_equal({}, req.correlation_data)
|
83
|
+
end
|
84
|
+
end
|
@@ -20,6 +20,16 @@ class RedisTest < Minitest::Test
|
|
20
20
|
assert_redis_trace('SET')
|
21
21
|
end
|
22
22
|
|
23
|
+
def test_georadius
|
24
|
+
clear_all!
|
25
|
+
|
26
|
+
Instana.tracer.start_or_continue_trace(:redis_test) do
|
27
|
+
@redis_client.georadius('Sicily', '15', '37', '200', 'km', 'WITHCOORD', 'WITHDIST')
|
28
|
+
end
|
29
|
+
|
30
|
+
assert_redis_trace('GEORADIUS')
|
31
|
+
end
|
32
|
+
|
23
33
|
def test_normal_call_with_error
|
24
34
|
clear_all!
|
25
35
|
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class SecretsTest < Minitest::Test
|
4
|
+
def setup
|
5
|
+
@subject = Instana::Secrets.new
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_equals_ignore_case
|
9
|
+
sample_config = {
|
10
|
+
"matcher"=>"equals-ignore-case",
|
11
|
+
"list"=>["key"]
|
12
|
+
}
|
13
|
+
|
14
|
+
url = url_for(%w(key Str kEy KEY))
|
15
|
+
assert_redacted @subject.remove_from_query(url, sample_config), %w(key kEy KEY)
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_equals
|
19
|
+
sample_config = {
|
20
|
+
"matcher"=>"equals",
|
21
|
+
"list"=>["key", "kEy"]
|
22
|
+
}
|
23
|
+
|
24
|
+
url = url_for(%w(key Str kEy KEY))
|
25
|
+
assert_redacted @subject.remove_from_query(url, sample_config), %w(key kEy)
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_contains_ignore_case
|
29
|
+
sample_config = {
|
30
|
+
"matcher"=>"contains-ignore-case",
|
31
|
+
"list"=>["stan"]
|
32
|
+
}
|
33
|
+
|
34
|
+
url = url_for(%w(instantiate conTESTant sample))
|
35
|
+
assert_redacted @subject.remove_from_query(url, sample_config), %w(instantiate conTESTant)
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_contains
|
39
|
+
sample_config = {
|
40
|
+
"matcher"=>"contains",
|
41
|
+
"list"=>["stan"]
|
42
|
+
}
|
43
|
+
|
44
|
+
url = url_for(%w(instantiate conTESTant sample))
|
45
|
+
assert_redacted @subject.remove_from_query(url, sample_config), %w(instantiate)
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_regexp
|
50
|
+
sample_config = {
|
51
|
+
"matcher"=>"regex",
|
52
|
+
"list"=>["l{2}"]
|
53
|
+
}
|
54
|
+
|
55
|
+
url = url_for(%w(ball foot move))
|
56
|
+
assert_redacted @subject.remove_from_query(url, sample_config), %w(ball)
|
57
|
+
end
|
58
|
+
|
59
|
+
private
|
60
|
+
|
61
|
+
def url_for(keys)
|
62
|
+
url = URI('http://example.com')
|
63
|
+
url.query = URI.encode_www_form(keys.map { |k| [k, rand(1..100)]})
|
64
|
+
url.to_s
|
65
|
+
end
|
66
|
+
|
67
|
+
def assert_redacted(str, keys)
|
68
|
+
url = URI(str)
|
69
|
+
params = CGI.parse(url.query)
|
70
|
+
|
71
|
+
assert_equal keys, params.select { |_, v| v == %w(<redacted>) }.keys, 'to be redacted'
|
72
|
+
end
|
73
|
+
end
|