tcell_agent 2.0.0 → 2.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (112) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +2 -2
  3. data/bin/tcell_agent +41 -150
  4. data/lib/tcell_agent/agent.rb +87 -52
  5. data/lib/tcell_agent/config_initializer.rb +63 -0
  6. data/lib/tcell_agent/configuration.rb +72 -267
  7. data/lib/tcell_agent/hooks/login_fraud.rb +1 -1
  8. data/lib/tcell_agent/instrument_servers.rb +14 -18
  9. data/lib/tcell_agent/instrumentation/cmdi.rb +47 -15
  10. data/lib/tcell_agent/instrumentation/lfi.rb +72 -15
  11. data/lib/tcell_agent/instrumentation/monkey_patches/ruby_2/file.rb +21 -0
  12. data/lib/tcell_agent/instrumentation/monkey_patches/ruby_2/io.rb +75 -0
  13. data/lib/tcell_agent/instrumentation/monkey_patches/ruby_2/kernel.rb +80 -0
  14. data/lib/tcell_agent/instrumentation/monkey_patches/ruby_3/file.rb +21 -0
  15. data/lib/tcell_agent/instrumentation/monkey_patches/ruby_3/io.rb +75 -0
  16. data/lib/tcell_agent/instrumentation/monkey_patches/ruby_3/kernel.rb +80 -0
  17. data/lib/tcell_agent/instrumentation.rb +14 -6
  18. data/lib/tcell_agent/logger.rb +3 -4
  19. data/lib/tcell_agent/policies/command_injection_policy.rb +1 -1
  20. data/lib/tcell_agent/policies/dataloss_policy.rb +15 -8
  21. data/lib/tcell_agent/policies/headers_policy.rb +2 -2
  22. data/lib/tcell_agent/policies/patches_policy.rb +8 -4
  23. data/lib/tcell_agent/policies/policies_manager.rb +1 -0
  24. data/lib/tcell_agent/policies/policy_polling.rb +4 -3
  25. data/lib/tcell_agent/rails/auth/authlogic.rb +49 -44
  26. data/lib/tcell_agent/rails/auth/authlogic_helper.rb +20 -0
  27. data/lib/tcell_agent/rails/auth/devise.rb +103 -102
  28. data/lib/tcell_agent/rails/auth/devise_helper.rb +29 -0
  29. data/lib/tcell_agent/rails/auth/doorkeeper.rb +54 -57
  30. data/lib/tcell_agent/{userinfo.rb → rails/auth/userinfo.rb} +0 -0
  31. data/lib/tcell_agent/rails/better_ip.rb +7 -19
  32. data/lib/tcell_agent/rails/csrf_exception.rb +0 -8
  33. data/lib/tcell_agent/rails/dlp/process_request.rb +5 -0
  34. data/lib/tcell_agent/rails/dlp.rb +58 -56
  35. data/lib/tcell_agent/rails/dlp_handler.rb +9 -10
  36. data/lib/tcell_agent/rails/js_agent_insert.rb +2 -3
  37. data/lib/tcell_agent/rails/middleware/context_middleware.rb +2 -1
  38. data/lib/tcell_agent/rails/middleware/global_middleware.rb +3 -4
  39. data/lib/tcell_agent/rails/middleware/headers_middleware.rb +1 -0
  40. data/lib/tcell_agent/rails/{on_start.rb → railties/tcell_agent_railties.rb} +9 -16
  41. data/lib/tcell_agent/rails/railties/tcell_agent_unicorn_railties.rb +8 -0
  42. data/lib/tcell_agent/rails/routes/grape.rb +5 -12
  43. data/lib/tcell_agent/rails/routes.rb +6 -9
  44. data/lib/tcell_agent/rails/settings_reporter.rb +3 -6
  45. data/lib/tcell_agent/rails/tcell_body_proxy.rb +4 -7
  46. data/lib/tcell_agent/routes/table.rb +3 -0
  47. data/lib/tcell_agent/rust/agent_config.rb +62 -33
  48. data/lib/tcell_agent/rust/{libtcellagent-4.14.0.so → libtcellagent-alpine.so} +0 -0
  49. data/lib/tcell_agent/rust/{libtcellagent-4.14.0.dylib → libtcellagent-x64.dll} +0 -0
  50. data/lib/tcell_agent/rust/{libtcellagent-alpine-4.14.0.so → libtcellagent.dylib} +0 -0
  51. data/lib/tcell_agent/rust/libtcellagent.so +0 -0
  52. data/lib/tcell_agent/rust/models.rb +9 -0
  53. data/lib/tcell_agent/rust/native_agent.rb +61 -51
  54. data/lib/tcell_agent/rust/native_library.rb +8 -10
  55. data/lib/tcell_agent/sensor_events/server_agent.rb +3 -100
  56. data/lib/tcell_agent/sensor_events/util/sanitizer_utilities.rb +1 -0
  57. data/lib/tcell_agent/servers/puma.rb +30 -13
  58. data/lib/tcell_agent/servers/rack_puma_handler.rb +33 -0
  59. data/lib/tcell_agent/servers/rails_server.rb +4 -4
  60. data/lib/tcell_agent/servers/unicorn.rb +1 -1
  61. data/lib/tcell_agent/servers/webrick.rb +12 -3
  62. data/lib/tcell_agent/settings_reporter.rb +0 -93
  63. data/lib/tcell_agent/sinatra.rb +1 -0
  64. data/lib/tcell_agent/tcell_context.rb +16 -7
  65. data/lib/tcell_agent/utils/headers.rb +0 -1
  66. data/lib/tcell_agent/utils/strings.rb +2 -2
  67. data/lib/tcell_agent/version.rb +1 -1
  68. data/lib/tcell_agent.rb +8 -16
  69. data/spec/cruby_spec_helper.rb +26 -0
  70. data/spec/lib/tcell_agent/configuration_spec.rb +62 -212
  71. data/spec/lib/tcell_agent/instrument_servers_spec.rb +95 -0
  72. data/spec/lib/tcell_agent/instrumentation/cmdi/io_cmdi_spec.rb +2 -2
  73. data/spec/lib/tcell_agent/{cmdi_spec.rb → instrumentation/cmdi_spec.rb} +50 -0
  74. data/spec/lib/tcell_agent/instrumentation/lfi/file_lfi_spec.rb +211 -272
  75. data/spec/lib/tcell_agent/instrumentation/lfi/io_lfi_spec.rb +213 -223
  76. data/spec/lib/tcell_agent/instrumentation/lfi/kernel_lfi_spec.rb +95 -61
  77. data/spec/lib/tcell_agent/instrumentation/lfi_spec.rb +120 -2
  78. data/spec/lib/tcell_agent/patches_spec.rb +2 -1
  79. data/spec/lib/tcell_agent/policies/clickjacking_policy_spec.rb +1 -2
  80. data/spec/lib/tcell_agent/policies/content_security_policy_spec.rb +5 -6
  81. data/spec/lib/tcell_agent/policies/patches_policy_spec.rb +21 -2
  82. data/spec/lib/tcell_agent/policies/policies_manager_spec.rb +1 -1
  83. data/spec/lib/tcell_agent/policies/secure_headers_policy_spec.rb +13 -8
  84. data/spec/lib/tcell_agent/rails/better_ip_spec.rb +9 -11
  85. data/spec/lib/tcell_agent/rails/csrf_exception_spec.rb +6 -6
  86. data/spec/lib/tcell_agent/rails/dlp_spec.rb +1 -0
  87. data/spec/lib/tcell_agent/rails/js_agent_insert_spec.rb +10 -2
  88. data/spec/lib/tcell_agent/rails/middleware/tcell_body_proxy_spec.rb +2 -1
  89. data/spec/lib/tcell_agent/rails/routes/route_id_spec.rb +4 -4
  90. data/spec/lib/tcell_agent/rust/agent_config_spec.rb +27 -0
  91. data/spec/lib/tcell_agent/settings_reporter_spec.rb +2 -89
  92. data/spec/lib/tcell_agent/tcell_context_spec.rb +6 -5
  93. data/spec/spec_helper.rb +9 -1
  94. data/spec/support/builders.rb +8 -7
  95. data/spec/support/server_mocks/passenger_mock.rb +7 -0
  96. data/spec/support/server_mocks/puma_mock.rb +21 -0
  97. data/spec/support/server_mocks/rails_mock.rb +7 -0
  98. data/spec/support/server_mocks/thin_mock.rb +7 -0
  99. data/spec/support/server_mocks/unicorn_mock.rb +11 -0
  100. data/spec/support/shared_spec.rb +29 -0
  101. data/tcell_agent.gemspec +14 -14
  102. metadata +46 -29
  103. data/Rakefile +0 -18
  104. data/lib/tcell_agent/authlogic.rb +0 -23
  105. data/lib/tcell_agent/config/unknown_options.rb +0 -119
  106. data/lib/tcell_agent/devise.rb +0 -33
  107. data/lib/tcell_agent/instrumentation/monkey_patches/file.rb +0 -25
  108. data/lib/tcell_agent/instrumentation/monkey_patches/io.rb +0 -123
  109. data/lib/tcell_agent/instrumentation/monkey_patches/kernel.rb +0 -159
  110. data/lib/tcell_agent/rails/start_agent_after_initializers.rb +0 -12
  111. data/lib/tcell_agent/rust/tcellagent-4.14.0.dll +0 -0
  112. data/spec/lib/tcell_agent/config/unknown_options_spec.rb +0 -195
@@ -4,37 +4,34 @@ module TCellAgent
4
4
  module Utils
5
5
  describe '.better_ip' do
6
6
  context 'with reverse_proxy off' do
7
- it 'should return the normal ip' do
7
+ it 'returns null' do
8
8
  configuration = double('configuration')
9
9
  request = double('request', :ip => '127.0.0.0')
10
10
 
11
11
  expect(TCellAgent).to receive(:configuration).and_return(configuration)
12
12
  expect(configuration).to receive(:reverse_proxy).and_return(false)
13
- expect(Rails.better_ip(request)).to eq('127.0.0.0')
13
+ expect(Rails.reverse_proxy_header(request)).to eq(nil)
14
14
  end
15
15
  end
16
16
 
17
17
  context 'with reverse_proxy on' do
18
18
  context 'with empty reverse_proxy_ip_address_header' do
19
- it 'should return normal ip' do
19
+ it 'returns null' do
20
20
  configuration = double('configuration')
21
21
  request = double('request', :ip => '127.0.0.0')
22
- env = double('env')
23
22
 
24
23
  expect(TCellAgent).to receive(:configuration).and_return(configuration)
25
24
  expect(configuration).to receive(:reverse_proxy).and_return(true)
26
25
  expect(TCellAgent).to receive(:configuration).and_return(configuration)
27
26
  expect(configuration).to receive(:reverse_proxy_ip_address_header).and_return('')
28
- expect(request).to receive(:env).and_return(env)
29
- expect(env).to receive(:[]).with('HTTP_X_FORWARDED_FOR').and_return('')
30
- expect(Rails.better_ip(request)).to eq('127.0.0.0')
27
+ expect(Rails.reverse_proxy_header(request)).to eq(nil)
31
28
  end
32
29
  end
33
30
 
34
31
  context "with reverse_proxy_ip_address_header that doesn't exist" do
35
- it 'should return normal ip' do
32
+ it 'returns null' do
36
33
  configuration = double('configuration')
37
- request = double('request', :ip => '127.0.0.0')
34
+ request = double('request', :ip => '127.0.0.0', :env => {})
38
35
  env = double('env')
39
36
 
40
37
  expect(TCellAgent).to receive(:configuration).and_return(configuration)
@@ -45,7 +42,7 @@ module TCellAgent
45
42
  )
46
43
  expect(request).to receive(:env).and_return(env)
47
44
  expect(env).to receive(:[]).with('HTTP_WEIRD_HTTP_PROXY_HEADER').and_return(nil)
48
- expect(Rails.better_ip(request)).to eq('127.0.0.0')
45
+ expect(Rails.reverse_proxy_header(request)).to eq(nil)
49
46
  end
50
47
  end
51
48
 
@@ -57,13 +54,14 @@ module TCellAgent
57
54
 
58
55
  expect(TCellAgent).to receive(:configuration).and_return(configuration)
59
56
  expect(configuration).to receive(:reverse_proxy).and_return(true)
57
+
60
58
  expect(TCellAgent).to receive(:configuration).and_return(configuration)
61
59
  expect(configuration).to receive(:reverse_proxy_ip_address_header).and_return(
62
60
  'X-Real-IP'
63
61
  )
64
62
  expect(request).to receive(:env).and_return(env)
65
63
  expect(env).to receive(:[]).with('HTTP_X_REAL_IP').and_return('192.168.99.100')
66
- expect(Rails.better_ip(request)).to eq('192.168.99.100')
64
+ expect(Rails.reverse_proxy_header(request)).to eq('192.168.99.100')
67
65
  end
68
66
  end
69
67
  end
@@ -1,13 +1,13 @@
1
1
  require 'spec_helper'
2
2
 
3
- module TCellAgent
4
- describe 'CsrfExceptionReporter' do
5
- class WrapperClass
6
- include TCellAgent::CsrfExceptionReporter
3
+ class WrapperClass
4
+ include TCellAgent::CsrfExceptionReporter
7
5
 
8
- def request; end
9
- end
6
+ def request; end
7
+ end
10
8
 
9
+ module TCellAgent
10
+ describe 'CsrfExceptionReporter' do
11
11
  before(:all) do
12
12
  @csrf_class = WrapperClass.new
13
13
  end
@@ -4,6 +4,7 @@ module TCellAgent
4
4
  module DLP
5
5
  class SomeColumn
6
6
  attr_accessor :name
7
+
7
8
  def initialize(name = nil)
8
9
  @name = name
9
10
  end
@@ -127,10 +127,10 @@ module TCellAgent
127
127
  end
128
128
 
129
129
  context 'with a <HEAD> tag' do
130
- it 'should not append script after <HEAD> tag' do
130
+ it 'should append script after <HEAD> tag' do
131
131
  response = JSAgent.handle_js_agent_insert('SCRIPT', 'i am the <HEAD> response')
132
132
 
133
- expect(response).to eq('i am the <HEAD> response')
133
+ expect(response).to eq('i am the <HEAD>SCRIPT response')
134
134
  end
135
135
  end
136
136
 
@@ -142,6 +142,14 @@ module TCellAgent
142
142
  end
143
143
  end
144
144
 
145
+ context 'with a <HEAD\n> tag' do
146
+ it 'should append script after <HEAD\n> tag' do
147
+ response = JSAgent.handle_js_agent_insert('SCRIPT', "i am the <HEAD\n> response")
148
+
149
+ expect(response).to eq("i am the <HEAD\n>SCRIPT response")
150
+ end
151
+ end
152
+
145
153
  context 'with invalid parameters' do
146
154
  context 'with nil response' do
147
155
  it 'should return the unmodified response' do
@@ -13,7 +13,8 @@ module TCellAgent
13
13
  'session_id',
14
14
  'user_id',
15
15
  'transaction_id',
16
- 'http://test.com/'
16
+ 'http://test.com/',
17
+ '0.0.0.0'
17
18
  )
18
19
  end
19
20
 
@@ -3,7 +3,7 @@ require 'spec_helper'
3
3
  module TCellAgent
4
4
  module Instrumentation
5
5
  describe RouteId do
6
- TCELL_CONTEXT_KEY = TCellAgent::Instrumentation::TCELL_ID
6
+ tcell_context_key = TCellAgent::Instrumentation::TCELL_ID
7
7
 
8
8
  describe '.update_context' do
9
9
  context 'with nil route' do
@@ -11,7 +11,7 @@ module TCellAgent
11
11
  tcell_context = TCellData.new
12
12
  tcell_context.route_id = nil
13
13
 
14
- RouteId.update_context({ TCELL_CONTEXT_KEY => tcell_context }, {}, nil)
14
+ RouteId.update_context({ tcell_context_key => tcell_context }, {}, nil)
15
15
 
16
16
  expect(tcell_context.route_id).to eq(nil)
17
17
  expect(tcell_context.grape_mount_endpoint).to eq(nil)
@@ -41,7 +41,7 @@ module TCellAgent
41
41
 
42
42
  expect(TCellAgent::Instrumentation).to receive(:grape_route?).with(route).and_return(false)
43
43
 
44
- RouteId.update_context({ TCELL_CONTEXT_KEY => tcell_context }, { :id => 1 }, route)
44
+ RouteId.update_context({ tcell_context_key => tcell_context }, { :id => 1 }, route)
45
45
 
46
46
  expect(tcell_context.route_id).to eq(
47
47
  TCellAgent::SensorEvents::Util.calculate_route_id('GET', '/some/regular/path')
@@ -64,7 +64,7 @@ module TCellAgent
64
64
 
65
65
  expect(TCellAgent::Instrumentation).to receive(:grape_route?).with(route).and_return(true)
66
66
 
67
- RouteId.update_context({ TCELL_CONTEXT_KEY => tcell_context }, { :id => 1 }, route)
67
+ RouteId.update_context({ tcell_context_key => tcell_context }, { :id => 1 }, route)
68
68
 
69
69
  expect(tcell_context.route_id).to eq(nil)
70
70
  expect(tcell_context.grape_mount_endpoint).to eq('/grape_api')
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+
3
+ module TCellAgent
4
+ module Rust
5
+ describe AgentConfig do
6
+ context 'with initializers set' do
7
+ before do
8
+ TCellAgent.configure do |config|
9
+ config.app_id = 'initializer_app_id_set'
10
+ config.api_key = 'initializer_api_key_set'
11
+ config.enabled_instrumentations = { 'authlogic' => false, :devise => false, 'doorkeeper' => false }
12
+ config.hmac_key = config.app_id
13
+ end
14
+ end
15
+ it 'should return the correct values' do
16
+ config = AgentConfig.new(TCellAgent.initializer_configuration)
17
+
18
+ expect(config['agent_type']).to eq 'Ruby'
19
+ expect(config['overrides']['disabled_instrumentation']).to contain_exactly('authlogic', 'devise', 'doorkeeper')
20
+ expect(config['overrides']['applications'][0][:api_key]).to eq 'initializer_api_key_set'
21
+ expect(config['overrides']['applications'][0][:app_id]).to eq 'initializer_app_id_set'
22
+ expect(config['overrides']['applications'][0][:api_key]).to eq 'initializer_api_key_set'
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -14,7 +14,6 @@ module TCellAgent
14
14
  :reverse_proxy => true,
15
15
  :reverse_proxy_ip_address_header => nil,
16
16
  :log_filename => 'log-filename',
17
- :config_filename => 'config-filename',
18
17
  :agent_log_dir => 'agent-log-dir',
19
18
  :agent_home_dir => 'agent-home-dir',
20
19
  :agent_home_owner => nil,
@@ -28,26 +27,12 @@ module TCellAgent
28
27
  ).at_least(:once)
29
28
  expect(TCellAgent).to receive(:logger).and_return(logger).at_least(:once)
30
29
  expect(Thread).to receive(:new).and_yield
31
- expect(logger).to receive(:debug).with('TCellAgent::SensorEvents::ServerAgentDetailsSensorEvent', 'User unknown')
32
- expect(logger).to receive(:debug).with('TCellAgent::SensorEvents::ServerAgentDetailsSensorEvent', 'Group unknown')
33
- expect(TCellAgent).to receive(:send_event).with(
34
- {
35
- 'event_type' => 'server_agent_details',
36
- 'user' => 'unknown',
37
- 'group' => 'unknown'
38
- }
39
- )
30
+
40
31
  expect(logger).to receive(:debug).with(anything, anything).at_least(:once)
41
32
  expect(TCellAgent).to receive(:send_event).with(
42
33
  hash_including('event_type' => 'server_agent_packages')
43
- ) # packages event
44
- expect(TCellAgent).to receive(:send_event).with(
45
- {
46
- 'event_type' => 'server_agent_details',
47
- 'language' => 'Ruby',
48
- 'language_version' => RUBY_VERSION
49
- }
50
34
  )
35
+
51
36
  expect(TCellAgent).to receive(:send_event).with(
52
37
  {
53
38
  'event_type' => 'app_config_setting',
@@ -57,78 +42,6 @@ module TCellAgent
57
42
  'value' => 'true'
58
43
  }
59
44
  )
60
- expect(TCellAgent).to receive(:send_event).with(
61
- {
62
- 'event_type' => 'app_config_setting',
63
- 'package' => 'tcell',
64
- 'section' => 'config',
65
- 'name' => 'allow_payloads',
66
- 'value' => 'true'
67
- }
68
- )
69
- expect(TCellAgent).to receive(:send_event).with(
70
- {
71
- 'event_type' => 'app_config_setting',
72
- 'package' => 'tcell',
73
- 'section' => 'config',
74
- 'name' => 'reverse_proxy',
75
- 'value' => 'true'
76
- }
77
- )
78
- expect(TCellAgent).to receive(:send_event).with(
79
- {
80
- 'event_type' => 'app_config_setting',
81
- 'package' => 'tcell',
82
- 'section' => 'config',
83
- 'name' => 'config_filename',
84
- 'value' => 'config-filename'
85
- }
86
- )
87
- expect(TCellAgent).to receive(:send_event).with(
88
- {
89
- 'event_type' => 'app_config_setting',
90
- 'package' => 'tcell',
91
- 'section' => 'config',
92
- 'name' => 'logging_directory',
93
- 'value' => 'agent-log-dir'
94
- }
95
- )
96
- expect(TCellAgent).to receive(:send_event).with(
97
- {
98
- 'event_type' => 'app_config_setting',
99
- 'package' => 'tcell',
100
- 'section' => 'config',
101
- 'name' => 'agent_home_directory',
102
- 'value' => 'agent-home-dir'
103
- }
104
- )
105
- expect(TCellAgent).to receive(:send_event).with(
106
- {
107
- 'event_type' => 'app_config_setting',
108
- 'package' => 'tcell',
109
- 'section' => 'config',
110
- 'name' => 'logging_enabled',
111
- 'value' => 'true'
112
- }
113
- )
114
- expect(TCellAgent).to receive(:send_event).with(
115
- {
116
- 'event_type' => 'app_config_setting',
117
- 'package' => 'tcell',
118
- 'section' => 'config',
119
- 'name' => 'logging_level',
120
- 'value' => 'INFO'
121
- }
122
- )
123
- expect(TCellAgent).to receive(:send_event).with(
124
- {
125
- 'event_type' => 'app_config_setting',
126
- 'package' => 'tcell',
127
- 'section' => 'config',
128
- 'name' => 'reverse_proxy_ip_address_header',
129
- 'value' => ''
130
- }
131
- )
132
45
 
133
46
  TCellAgent.report_settings
134
47
  end
@@ -4,9 +4,9 @@ module TCellAgent
4
4
  describe MetaData do
5
5
  describe '#set_headers_dict' do
6
6
  it 'should set all headers that start with http and skip cookies' do
7
- method = remote_address = route_id = session_id = user_id = transaction_id = location = nil
7
+ method = remote_address = route_id = session_id = user_id = transaction_id = location = reverse_proxy_header_value = nil
8
8
 
9
- meta = MetaData.new(method, remote_address, route_id, session_id, user_id, transaction_id, location)
9
+ meta = MetaData.new(method, remote_address, route_id, session_id, user_id, transaction_id, location, reverse_proxy_header_value)
10
10
  meta.headers_dict = {
11
11
  'rack.version' => [1, 2],
12
12
  'REQUEST_METHOD' => 'POST',
@@ -24,9 +24,9 @@ module TCellAgent
24
24
  end
25
25
 
26
26
  it 'should set all headers that start with http and include content_length and content_type' do
27
- method = remote_address = route_id = session_id = user_id = transaction_id = location = nil
27
+ method = remote_address = route_id = session_id = user_id = transaction_id = location = reverse_proxy_header_value = nil
28
28
 
29
- meta = MetaData.new(method, remote_address, route_id, session_id, user_id, transaction_id, location)
29
+ meta = MetaData.new(method, remote_address, route_id, session_id, user_id, transaction_id, location, reverse_proxy_header_value)
30
30
  meta.headers_dict = {
31
31
  'REQUEST_METHOD' => 'POST',
32
32
  'HTTP_VERSION' => 'HTTP/1.1',
@@ -71,7 +71,8 @@ module TCellAgent
71
71
  'session_id',
72
72
  'user_id',
73
73
  'transaction_id',
74
- 'http://test.com'
74
+ 'http://test.com',
75
+ '0.0.0.0'
75
76
  )
76
77
  end
77
78
 
data/spec/spec_helper.rb CHANGED
@@ -12,11 +12,19 @@ end
12
12
  ENV['TCELL_AGENT_SERVER'] = 'mock'
13
13
  require File.join(File.dirname(__FILE__), '..', 'lib', 'tcell_agent')
14
14
 
15
- Dir[File.join(File.dirname(__FILE__), 'support', '**', '*.rb')].each { |f| require f }
15
+ Dir[File.join(File.dirname(__FILE__), 'support', '**', '*.rb')].sort.each { |f| require f }
16
16
 
17
17
  def get_test_resource_path(name)
18
18
  File.join(File.dirname(__FILE__), 'support', 'resources', name)
19
19
  end
20
20
 
21
+ NEW_FILE_NAME ||= "/tmp/#{SecureRandom.uuid}".freeze
22
+
21
23
  require 'tcell_agent/agent'
22
24
  require 'tcell_agent/rails/routes'
25
+
26
+ TCellAgent.configuration.enabled = true
27
+ TCellAgent.configuration.instrument = true
28
+ TCellAgent.configuration.enable_intercept_requests = true
29
+ TCellAgent.configuration.disabled_instrumentation = []
30
+ TCellAgent.thread_agent.instrument_built_ins
@@ -1,12 +1,11 @@
1
1
  require 'spec_helper'
2
+ require 'tcell_agent/config_initializer'
3
+
2
4
  module TCellAgent
3
5
  module Tests
4
6
  class ConfigurationBuilder
5
7
  def initialize
6
- @configuration = TCellAgent::Configuration.new
7
- @configuration.config_filename = 'tcell_agent.config'
8
- @configuration.demomode = false
9
- @configuration.enable_event_manager = false
8
+ @configuration = TCellAgent::ConfigInitializer.new
10
9
  @configuration.fetch_policies_from_tcell = false
11
10
  @configuration.max_csp_header_bytes = nil
12
11
  @configuration.app_id = 'TestAppId-AppId'
@@ -18,11 +17,12 @@ module TCellAgent
18
17
  @configuration.allow_payloads = true
19
18
  @configuration.js_agent_api_base_url = @configuration.tcell_api_url
20
19
  @configuration.js_agent_url = 'https://jsagent.tcell.io/tcellagent.min.js'
21
- @configuration.cache_folder = nil
22
20
  @configuration.agent_log_dir = 'tcell/logs'
23
- @configuration.logging_options = { 'enabled' => false }
21
+ @configuration.logging_options = { :enabled => false }
24
22
  @configuration.host_identifier = 'python-test-suite'
25
23
  @configuration.reverse_proxy_ip_address_header = 'X-Forwarded-For'
24
+ @configuration.enable_intercept_requests = true
25
+ @configuration.enabled = true
26
26
  end
27
27
 
28
28
  def update_attribute(attribute, setting)
@@ -73,7 +73,8 @@ module TCellAgent
73
73
  'session-id',
74
74
  'user-id',
75
75
  SecureRandom.uuid,
76
- 'http://domain.com/some/path?hide-my-value=sensitive'
76
+ 'http://domain.com/some/path?hide-my-value=sensitive',
77
+ '0.0.0.0'
77
78
  )
78
79
 
79
80
  @meta_data.path = '/some/path'
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PhusionPassenger
4
+ module LoaderSharedHelpers
5
+ def before_handling_requests; end
6
+ end
7
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Puma
4
+ class Server
5
+ def run; end
6
+ end
7
+
8
+ class Config
9
+ def self.options
10
+ {}
11
+ end
12
+ end
13
+
14
+ def self.cli_config
15
+ Config
16
+ end
17
+
18
+ module Const
19
+ PUMA_VERSION = '5.1.0'
20
+ end
21
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rails
4
+ module Server
5
+ def build_app; end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Thin
4
+ module Server
5
+ def start; end
6
+ end
7
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Unicorn
4
+ class HttpServer
5
+ START_CTX = {}.freeze
6
+
7
+ def init_worker_process; end
8
+
9
+ def load_config!; end
10
+ end
11
+ end
@@ -0,0 +1,29 @@
1
+ def test_ruby2_ruby3_keywords(cls, func, args, options, res, min_ruby = '2.0.0')
2
+ ruby_version = Gem::Version.new(RUBY_VERSION)
3
+
4
+ context 'using ruby2_3 helper function' do
5
+ after(:each) do
6
+ expect(@result).to eq res unless res.nil?
7
+ end
8
+
9
+ if ruby_version >= Gem::Version.new(min_ruby) && \
10
+ ruby_version < Gem::Version.new('3.0.0')
11
+ # This spec tests the following format:
12
+ # File.new('/dev/null', 'w', 0o644, { :binmode => true })
13
+ it 'behaves correctly in ruby < 2.7' do
14
+ args_cp = Array.new(args)
15
+ args_cp << options
16
+
17
+ @result = cls.send(func, *args_cp)
18
+ end
19
+ end
20
+
21
+ if ruby_version >= Gem::Version.new(min_ruby)
22
+ # This spec tests the following format:
23
+ # File.new('/dev/null', 'w', 0o644, :binmode => true )
24
+ it 'behaves correctly in ruby >= 3.0' do
25
+ @result = cls.send(func, *args, **options)
26
+ end
27
+ end
28
+ end
29
+ end
data/tcell_agent.gemspec CHANGED
@@ -6,23 +6,23 @@ require 'tcell_agent/version'
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = 'tcell_agent'
8
8
  spec.version = TCellAgent::VERSION
9
- spec.authors = %w[Rafael]
10
- spec.email = ['rafael@tcell.io']
11
- spec.summary = 'tCell.io Agent for Rails'
12
- spec.description = 'This agent allows users to use the tCell.io service with their Rails app.'
13
- spec.homepage = 'https://www.tcell.io'
14
- spec.license = 'Copyright (c) 2017 tCell.io (see LICENSE file)'
9
+ spec.authors = 'Rapid7, Inc.'
10
+ spec.summary = 'tCell Agent for Rails'
11
+ spec.description = 'This agent allows users to use the tCell service with their Rails app.'
12
+ spec.homepage = 'https://www.rapid7.com/tcell'
13
+ spec.license = 'Copyright (c) 2020 Rapid7, Inc. (see LICENSE file)'
15
14
 
16
15
  spec.files = Dir[
17
- 'Rakefile',
16
+ 'README.md',
17
+ 'LICENSE',
18
+ 'tcell_agent.gemspec',
19
+ 'spec/**/*',
18
20
  'lib/tcell_agent.rb',
19
- '{lib/tcell_agent,spec}/**/*',
20
- 'lib/tcell_agent/rust/libtcellagent-*.so',
21
- 'lib/tcell_agent/rust/libtcellagent-*.dylib',
22
- 'lib/tcell_agent/rust/tcellagent-*.dll',
23
- 'README*',
24
- 'LICENSE*',
25
- 'tcell_agent.gemspec'
21
+ 'lib/tcell_agent/**/*rb',
22
+ 'lib/tcell_agent/rust/libtcellagent.dylib',
23
+ 'lib/tcell_agent/rust/libtcellagent.so',
24
+ 'lib/tcell_agent/rust/libtcellagent-alpine.so',
25
+ 'lib/tcell_agent/rust/libtcellagent-x64.dll',
26
26
  ]
27
27
  spec.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
28
28
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})