tcell_agent 1.1.12 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/bin/tcell_agent +26 -14
- data/lib/tcell_agent.rb +16 -10
- data/lib/tcell_agent/agent.rb +78 -97
- data/lib/tcell_agent/agent/route_manager.rb +0 -16
- data/lib/tcell_agent/agent/static_agent.rb +9 -30
- data/lib/tcell_agent/authlogic.rb +3 -6
- data/lib/tcell_agent/config/unknown_options.rb +4 -8
- data/lib/tcell_agent/configuration.rb +38 -119
- data/lib/tcell_agent/devise.rb +25 -27
- data/lib/tcell_agent/hooks/login_fraud.rb +30 -33
- data/lib/tcell_agent/instrument_servers.rb +25 -0
- data/lib/tcell_agent/instrumentation.rb +12 -10
- data/lib/tcell_agent/instrumentation/cmdi.rb +19 -15
- data/lib/tcell_agent/instrumentation/lfi.rb +73 -0
- data/lib/tcell_agent/instrumentation/monkey_patches/file.rb +25 -0
- data/lib/tcell_agent/instrumentation/monkey_patches/io.rb +123 -0
- data/lib/tcell_agent/instrumentation/monkey_patches/kernel.rb +159 -0
- data/lib/tcell_agent/logger.rb +50 -114
- data/lib/tcell_agent/patches.rb +6 -7
- data/lib/tcell_agent/policies/appfirewall_policy.rb +26 -0
- data/lib/tcell_agent/policies/command_injection_policy.rb +28 -0
- data/lib/tcell_agent/policies/dataloss_policy.rb +44 -44
- data/lib/tcell_agent/policies/headers_policy.rb +25 -0
- data/lib/tcell_agent/policies/http_redirect_policy.rb +13 -79
- data/lib/tcell_agent/policies/js_agent_policy.rb +27 -0
- data/lib/tcell_agent/policies/local_file_access.rb +28 -0
- data/lib/tcell_agent/policies/login_policy.rb +43 -0
- data/lib/tcell_agent/policies/patches_policy.rb +27 -0
- data/lib/tcell_agent/policies/policies_manager.rb +68 -0
- data/lib/tcell_agent/policies/policy_polling.rb +58 -0
- data/lib/tcell_agent/policies/policy_types.rb +14 -0
- data/lib/tcell_agent/policies/system_enablements.rb +27 -0
- data/lib/tcell_agent/rails/auth/authlogic.rb +43 -68
- data/lib/tcell_agent/rails/auth/devise.rb +20 -23
- data/lib/tcell_agent/rails/auth/doorkeeper.rb +63 -74
- data/lib/tcell_agent/rails/csrf_exception.rb +2 -2
- data/lib/tcell_agent/rails/dlp.rb +25 -15
- data/lib/tcell_agent/rails/dlp_handler.rb +1 -2
- data/lib/tcell_agent/rails/js_agent_insert.rb +12 -13
- data/lib/tcell_agent/rails/middleware/body_filter_middleware.rb +4 -25
- data/lib/tcell_agent/rails/middleware/context_middleware.rb +2 -12
- data/lib/tcell_agent/rails/middleware/global_middleware.rb +0 -1
- data/lib/tcell_agent/rails/middleware/headers_middleware.rb +14 -34
- data/lib/tcell_agent/rails/on_start.rb +32 -31
- data/lib/tcell_agent/rails/routes.rb +7 -6
- data/lib/tcell_agent/rails/routes/grape.rb +1 -3
- data/lib/tcell_agent/rails/routes/route_id.rb +3 -1
- data/lib/tcell_agent/rails/settings_reporter.rb +23 -36
- data/lib/tcell_agent/rails/start_agent_after_initializers.rb +12 -0
- data/lib/tcell_agent/rails/tcell_body_proxy.rb +6 -4
- data/lib/tcell_agent/rust/agent_config.rb +49 -0
- data/lib/tcell_agent/rust/{libtcellagent-alpine-1.3.2.so → libtcellagent-4.14.0.dylib} +0 -0
- data/lib/tcell_agent/rust/libtcellagent-4.14.0.so +0 -0
- data/lib/tcell_agent/rust/{libtcellagent-1.3.2.so → libtcellagent-alpine-4.14.0.so} +0 -0
- data/lib/tcell_agent/rust/models.rb +0 -55
- data/lib/tcell_agent/rust/native_agent.rb +531 -0
- data/lib/tcell_agent/rust/native_agent_response.rb +42 -0
- data/lib/tcell_agent/rust/native_library.rb +68 -0
- data/lib/tcell_agent/rust/tcellagent-4.14.0.dll +0 -0
- data/lib/tcell_agent/sensor_events/agent_setting_event.rb +12 -0
- data/lib/tcell_agent/sensor_events/{app_config.rb → app_config_setting_event.rb} +0 -6
- data/lib/tcell_agent/sensor_events/dlp.rb +2 -6
- data/lib/tcell_agent/sensor_events/sensor.rb +0 -62
- data/lib/tcell_agent/sensor_events/server_agent.rb +13 -18
- data/lib/tcell_agent/sensor_events/util/sanitizer_utilities.rb +0 -108
- data/lib/tcell_agent/sensor_events/util/utils.rb +0 -2
- data/lib/tcell_agent/servers/passenger.rb +1 -28
- data/lib/tcell_agent/servers/puma.rb +3 -21
- data/lib/tcell_agent/servers/rails_server.rb +1 -1
- data/lib/tcell_agent/servers/thin.rb +2 -2
- data/lib/tcell_agent/servers/unicorn.rb +19 -80
- data/lib/tcell_agent/servers/webrick.rb +1 -1
- data/lib/tcell_agent/settings_reporter.rb +24 -24
- data/lib/tcell_agent/sinatra.rb +14 -16
- data/lib/tcell_agent/tcell_context.rb +40 -14
- data/lib/tcell_agent/utils/headers.rb +14 -0
- data/lib/tcell_agent/version.rb +1 -1
- data/spec/lib/tcell_agent/cmdi_spec.rb +0 -585
- data/spec/lib/tcell_agent/config/unknown_options_spec.rb +0 -18
- data/spec/lib/tcell_agent/configuration_spec.rb +4 -140
- data/spec/lib/tcell_agent/hooks/login_fraud_spec.rb +46 -173
- data/spec/lib/tcell_agent/instrumentation/cmdi/io_cmdi_spec.rb +504 -0
- data/spec/lib/tcell_agent/instrumentation/cmdi/kernel_cmdi_spec.rb +435 -0
- data/spec/lib/tcell_agent/instrumentation/lfi/file_lfi_spec.rb +326 -0
- data/spec/lib/tcell_agent/instrumentation/lfi/io_lfi_spec.rb +556 -0
- data/spec/lib/tcell_agent/instrumentation/lfi/kernel_lfi_spec.rb +249 -0
- data/spec/lib/tcell_agent/instrumentation/lfi_spec.rb +105 -0
- data/spec/lib/tcell_agent/patches_spec.rb +25 -43
- data/spec/lib/tcell_agent/policies/appfirewall_policy_spec.rb +183 -0
- data/spec/lib/tcell_agent/policies/clickjacking_policy_spec.rb +57 -0
- data/spec/lib/tcell_agent/policies/command_injection_policy_spec.rb +84 -773
- data/spec/lib/tcell_agent/policies/content_security_policy_spec.rb +161 -0
- data/spec/lib/tcell_agent/policies/dataloss_policy_spec.rb +9 -9
- data/spec/lib/tcell_agent/policies/http_redirect_policy_spec.rb +243 -198
- data/spec/lib/tcell_agent/policies/js_agent_policy_spec.rb +75 -0
- data/spec/lib/tcell_agent/policies/login_policy_spec.rb +165 -33
- data/spec/lib/tcell_agent/policies/patches_policy_spec.rb +84 -277
- data/spec/lib/tcell_agent/policies/policies_manager_spec.rb +104 -0
- data/spec/lib/tcell_agent/policies/policy_polling_spec.rb +6 -0
- data/spec/lib/tcell_agent/policies/secure_headers_policy_spec.rb +56 -0
- data/spec/lib/tcell_agent/rails/csrf_exception_spec.rb +9 -18
- data/spec/lib/tcell_agent/rails/js_agent_insert_spec.rb +13 -30
- data/spec/lib/tcell_agent/rails/logger_spec.rb +27 -7
- data/spec/lib/tcell_agent/rails/middleware/tcell_body_proxy_spec.rb +17 -12
- data/spec/lib/tcell_agent/rails/routes/routes_spec.rb +14 -14
- data/spec/lib/tcell_agent/sensor_events/util/sanitizer_utilities_spec.rb +0 -35
- data/spec/lib/tcell_agent/settings_reporter_spec.rb +127 -153
- data/spec/spec_helper.rb +1 -1
- data/spec/support/builders.rb +104 -0
- data/spec/support/force_logger_mocking.rb +38 -0
- data/spec/support/resources/lfi_sample_file.txt +2 -0
- data/spec/support/static_agent_overrides.rb +0 -15
- metadata +63 -74
- data/lib/tcell_agent/agent/event_processor.rb +0 -326
- data/lib/tcell_agent/agent/fork_pipe_manager.rb +0 -113
- data/lib/tcell_agent/agent/policy_manager.rb +0 -219
- data/lib/tcell_agent/agent/policy_types.rb +0 -30
- data/lib/tcell_agent/api.rb +0 -91
- data/lib/tcell_agent/appsensor/injections_reporter.rb +0 -24
- data/lib/tcell_agent/config/child_process_events.rb +0 -8
- data/lib/tcell_agent/instrumentation/cmdi/backtick.rb +0 -10
- data/lib/tcell_agent/instrumentation/cmdi/exec.rb +0 -14
- data/lib/tcell_agent/instrumentation/cmdi/popen.rb +0 -28
- data/lib/tcell_agent/instrumentation/cmdi/spawn.rb +0 -11
- data/lib/tcell_agent/instrumentation/cmdi/system.rb +0 -11
- data/lib/tcell_agent/policies/http_tx_policy.rb +0 -60
- data/lib/tcell_agent/policies/login_fraud_policy.rb +0 -45
- data/lib/tcell_agent/policies/rust_policies.rb +0 -110
- data/lib/tcell_agent/rails.rb +0 -40
- data/lib/tcell_agent/rust/libtcellagent-1.3.2.dylib +0 -0
- data/lib/tcell_agent/rust/tcellagent-1.3.2.dll +0 -0
- data/lib/tcell_agent/rust/whisperer.rb +0 -308
- data/lib/tcell_agent/sensor_events/appsensor_event.rb +0 -52
- data/lib/tcell_agent/sensor_events/appsensor_meta_event.rb +0 -45
- data/lib/tcell_agent/sensor_events/command_injection.rb +0 -75
- data/lib/tcell_agent/sensor_events/honeytokens.rb +0 -16
- data/lib/tcell_agent/sensor_events/login_fraud.rb +0 -60
- data/lib/tcell_agent/sensor_events/metrics.rb +0 -123
- data/lib/tcell_agent/sensor_events/patches.rb +0 -21
- data/lib/tcell_agent/start_background_thread.rb +0 -55
- data/lib/tcell_agent/system_info.rb +0 -11
- data/lib/tcell_agent/utils/io.rb +0 -38
- data/lib/tcell_agent/utils/passwords.rb +0 -28
- data/lib/tcell_agent/utils/queue_with_timeout.rb +0 -142
- data/spec/lib/tcell_agent/agent/fork_pipe_manager_spec.rb +0 -100
- data/spec/lib/tcell_agent/agent/policy_manager_spec.rb +0 -535
- data/spec/lib/tcell_agent/agent/static_agent_spec.rb +0 -133
- data/spec/lib/tcell_agent/api/api_spec.rb +0 -39
- data/spec/lib/tcell_agent/appsensor/injections_reporter_spec.rb +0 -187
- data/spec/lib/tcell_agent/instrumentation_spec.rb +0 -225
- data/spec/lib/tcell_agent/policies/appsensor_policy_spec.rb +0 -517
- data/spec/lib/tcell_agent/policies/http_tx_policy_spec.rb +0 -22
- data/spec/lib/tcell_agent/rails/middleware/appsensor_middleware_spec.rb +0 -293
- data/spec/lib/tcell_agent/rails/middleware/dlp_middleware_spec.rb +0 -198
- data/spec/lib/tcell_agent/rails/middleware/global_middleware_spec.rb +0 -180
- data/spec/lib/tcell_agent/rails/middleware/redirect_middleware_spec.rb +0 -116
- data/spec/lib/tcell_agent/rust/models_spec.rb +0 -120
- data/spec/lib/tcell_agent/rust/whisperer_spec.rb +0 -704
- data/spec/lib/tcell_agent/sensor_events/appsensor_meta_event_spec.rb +0 -45
- data/spec/lib/tcell_agent/sensor_events/sessions_metric_spec.rb +0 -272
- data/spec/lib/tcell_agent/utils/bounded_queue_spec.rb +0 -52
- data/spec/lib/tcell_agent/utils/passwords_spec.rb +0 -143
@@ -1,45 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
module TCellAgent
|
4
|
-
module SensorEvents
|
5
|
-
describe AppSensorMetaEvent do
|
6
|
-
describe '#post_process' do
|
7
|
-
before(:each) do
|
8
|
-
@meta_data = TCellAgent::MetaData.new(
|
9
|
-
'get',
|
10
|
-
'remote_address',
|
11
|
-
'route_id',
|
12
|
-
'session_id',
|
13
|
-
'user_id',
|
14
|
-
'transaction_id',
|
15
|
-
'http://test.com'
|
16
|
-
)
|
17
|
-
@appsensor_meta_event = AppSensorMetaEvent.new(@meta_data)
|
18
|
-
end
|
19
|
-
|
20
|
-
context 'empty rust policies' do
|
21
|
-
it 'should not process anything' do
|
22
|
-
expect(TCellAgent).to receive(:policy).with(
|
23
|
-
TCellAgent::PolicyTypes::RUST
|
24
|
-
).and_return(nil)
|
25
|
-
|
26
|
-
@appsensor_meta_event.post_process
|
27
|
-
end
|
28
|
-
end
|
29
|
-
context 'rust policies available' do
|
30
|
-
it 'should call rust policies for processing' do
|
31
|
-
rust_policies = double('rust_policies')
|
32
|
-
expect(TCellAgent).to receive(:policy).with(
|
33
|
-
TCellAgent::PolicyTypes::RUST
|
34
|
-
).and_return(rust_policies)
|
35
|
-
expect(rust_policies).to receive(:check_appfirewall_injections).with(
|
36
|
-
@appsensor_meta_event.meta_data
|
37
|
-
)
|
38
|
-
|
39
|
-
@appsensor_meta_event.post_process
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
@@ -1,272 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
module TCellAgent
|
4
|
-
module SensorEvents
|
5
|
-
describe SessionsMetric do
|
6
|
-
describe '#initialize' do
|
7
|
-
context 'empty sessions info' do
|
8
|
-
it 'should have the event type set' do
|
9
|
-
sessions_metric = SessionsMetric.new
|
10
|
-
expect(sessions_metric).to eq({ 'event_type' => 'metrics', 'sessions' => {} })
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
describe '#add_session_info' do
|
16
|
-
context 'empty sessions info' do
|
17
|
-
context 'adding session info' do
|
18
|
-
it 'should have the session info' do
|
19
|
-
sessions_metric = SessionsMetric.new
|
20
|
-
sessions_metric.add_session_info('hmac_session_id', 'user_id', '127.0.0.1', 'user_agent')
|
21
|
-
|
22
|
-
expect(sessions_metric.sessions?).to eq(true)
|
23
|
-
expect(sessions_metric).to eq(
|
24
|
-
{
|
25
|
-
'event_type' => 'metrics',
|
26
|
-
'sessions' => {
|
27
|
-
'hmac_session_id' => [
|
28
|
-
{
|
29
|
-
'uid' => 'user_id',
|
30
|
-
'track' => [
|
31
|
-
['user_agent', ['127.0.0.1']]
|
32
|
-
]
|
33
|
-
}
|
34
|
-
]
|
35
|
-
}
|
36
|
-
}
|
37
|
-
)
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
context 'adding a really long user agent' do
|
42
|
-
it 'should truncate the agent' do
|
43
|
-
long_user_agent = 'user_agent_user_agent_user_agent_user_agent_user_agent_user_agent_user_agent_'
|
44
|
-
long_user_agent += 'user_agent_user_agent_user_agent_user_agent_user_agent_user_agent_user_agent'
|
45
|
-
long_user_agent += 'user_agent_user_agent_user_agent_user_agent_user_agent_user_agent_user_agent'
|
46
|
-
long_user_agent += 'user_agent_user_agent_user_agent_user_agent_user_agent_user_agent_user_agent'
|
47
|
-
sessions_metric = SessionsMetric.new
|
48
|
-
sessions_metric.add_session_info('hmac_session_id', 'user_id', '127.0.0.1', long_user_agent)
|
49
|
-
|
50
|
-
expect(sessions_metric).to eq(
|
51
|
-
{
|
52
|
-
'event_type' => 'metrics',
|
53
|
-
'sessions' => {
|
54
|
-
'hmac_session_id' => [
|
55
|
-
{
|
56
|
-
'uid' => 'user_id',
|
57
|
-
'track' => [
|
58
|
-
['user_agent_user_agent_user_agent_user_agent_user_agent_user_agent_user_agent_user_agent_user_agent_user_agent_user_agent_user_agent_user_agent_user_agentuser_agent_user_agent_user_agent_user_agent_user_agent_user_agent_user_agentuser_agent_user_agent_user_', ['127.0.0.1']]
|
59
|
-
]
|
60
|
-
}
|
61
|
-
]
|
62
|
-
}
|
63
|
-
}
|
64
|
-
)
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
context 'with an existing session info' do
|
70
|
-
context 'adding the same info' do
|
71
|
-
it 'should not do anything' do
|
72
|
-
sessions_metric = SessionsMetric.new
|
73
|
-
sessions_metric.add_session_info('hmac_session_id', 'user_id', '127.0.0.1', 'user_agent')
|
74
|
-
sessions_metric.add_session_info('hmac_session_id', 'user_id', '127.0.0.1', 'user_agent')
|
75
|
-
|
76
|
-
expect(sessions_metric).to eq(
|
77
|
-
{
|
78
|
-
'event_type' => 'metrics',
|
79
|
-
'sessions' => {
|
80
|
-
'hmac_session_id' => [
|
81
|
-
{
|
82
|
-
'uid' => 'user_id',
|
83
|
-
'track' => [
|
84
|
-
['user_agent', ['127.0.0.1']]
|
85
|
-
]
|
86
|
-
}
|
87
|
-
]
|
88
|
-
}
|
89
|
-
}
|
90
|
-
)
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
context 'adding a new session' do
|
95
|
-
it 'should add the new info' do
|
96
|
-
sessions_metric = SessionsMetric.new
|
97
|
-
sessions_metric.add_session_info('hmac_session_id', 'user_id', '127.0.0.1', 'user_agent')
|
98
|
-
|
99
|
-
sessions_metric.add_session_info('hmac_session_id_dos', 'user_id_dos', '127.0.0.1_dos', 'user_agent_dos')
|
100
|
-
expect(sessions_metric).to eq(
|
101
|
-
{
|
102
|
-
'event_type' => 'metrics',
|
103
|
-
'sessions' => {
|
104
|
-
'hmac_session_id' => [
|
105
|
-
{
|
106
|
-
'uid' => 'user_id',
|
107
|
-
'track' => [
|
108
|
-
['user_agent', ['127.0.0.1']]
|
109
|
-
]
|
110
|
-
}
|
111
|
-
],
|
112
|
-
'hmac_session_id_dos' => [
|
113
|
-
{
|
114
|
-
'uid' => 'user_id_dos',
|
115
|
-
'track' => [
|
116
|
-
['user_agent_dos', ['127.0.0.1_dos']]
|
117
|
-
]
|
118
|
-
}
|
119
|
-
]
|
120
|
-
}
|
121
|
-
}
|
122
|
-
)
|
123
|
-
end
|
124
|
-
|
125
|
-
context 'with the same user_id' do
|
126
|
-
it 'should add the new info' do
|
127
|
-
sessions_metric = SessionsMetric.new
|
128
|
-
sessions_metric.add_session_info('hmac_session_id', 'user_id', '127.0.0.1', 'user_agent')
|
129
|
-
|
130
|
-
sessions_metric.add_session_info('hmac_session_id_dos', 'user_id', '127.0.0.1', 'user_agent')
|
131
|
-
expect(sessions_metric).to eq(
|
132
|
-
{
|
133
|
-
'event_type' => 'metrics',
|
134
|
-
'sessions' => {
|
135
|
-
'hmac_session_id' => [
|
136
|
-
{
|
137
|
-
'uid' => 'user_id',
|
138
|
-
'track' => [
|
139
|
-
['user_agent', ['127.0.0.1']]
|
140
|
-
]
|
141
|
-
}
|
142
|
-
],
|
143
|
-
'hmac_session_id_dos' => [
|
144
|
-
{
|
145
|
-
'uid' => 'user_id',
|
146
|
-
'track' => [
|
147
|
-
['user_agent', ['127.0.0.1']]
|
148
|
-
]
|
149
|
-
}
|
150
|
-
]
|
151
|
-
}
|
152
|
-
}
|
153
|
-
)
|
154
|
-
end
|
155
|
-
end
|
156
|
-
end
|
157
|
-
|
158
|
-
context 'adding new info for the existing session' do
|
159
|
-
context 'adding a new user_id' do
|
160
|
-
it 'should append the ip address to the existing info' do
|
161
|
-
sessions_metric = SessionsMetric.new
|
162
|
-
sessions_metric.add_session_info('hmac_session_id', 'user_id', '127.0.0.1', 'user_agent')
|
163
|
-
sessions_metric.add_session_info('hmac_session_id', 'user_id_dos', '127.0.0.1', 'user_agent')
|
164
|
-
|
165
|
-
expect(sessions_metric).to eq(
|
166
|
-
{
|
167
|
-
'event_type' => 'metrics',
|
168
|
-
'sessions' => {
|
169
|
-
'hmac_session_id' => [
|
170
|
-
{
|
171
|
-
'uid' => 'user_id',
|
172
|
-
'track' => [
|
173
|
-
['user_agent', ['127.0.0.1']]
|
174
|
-
]
|
175
|
-
},
|
176
|
-
{
|
177
|
-
'uid' => 'user_id_dos',
|
178
|
-
'track' => [
|
179
|
-
['user_agent', ['127.0.0.1']]
|
180
|
-
]
|
181
|
-
}
|
182
|
-
]
|
183
|
-
}
|
184
|
-
}
|
185
|
-
)
|
186
|
-
end
|
187
|
-
end
|
188
|
-
|
189
|
-
context 'adding a new ip address' do
|
190
|
-
it 'should append the ip address to the existing info' do
|
191
|
-
sessions_metric = SessionsMetric.new
|
192
|
-
sessions_metric.add_session_info('hmac_session_id', 'user_id', '127.0.0.1', 'user_agent')
|
193
|
-
sessions_metric.add_session_info('hmac_session_id', 'user_id', '127.0.0.1_dos', 'user_agent')
|
194
|
-
|
195
|
-
expect(sessions_metric).to eq(
|
196
|
-
{
|
197
|
-
'event_type' => 'metrics',
|
198
|
-
'sessions' => {
|
199
|
-
'hmac_session_id' => [
|
200
|
-
{
|
201
|
-
'uid' => 'user_id',
|
202
|
-
'track' => [
|
203
|
-
['user_agent', ['127.0.0.1', '127.0.0.1_dos']]
|
204
|
-
]
|
205
|
-
}
|
206
|
-
]
|
207
|
-
}
|
208
|
-
}
|
209
|
-
)
|
210
|
-
end
|
211
|
-
end
|
212
|
-
|
213
|
-
context 'adding a new user agent' do
|
214
|
-
it 'should add the new user agent' do
|
215
|
-
sessions_metric = SessionsMetric.new
|
216
|
-
sessions_metric.add_session_info('hmac_session_id', 'user_id', '127.0.0.1', 'user_agent')
|
217
|
-
sessions_metric.add_session_info('hmac_session_id', 'user_id', '127.0.0.1', 'user_agent_dos')
|
218
|
-
|
219
|
-
expect(sessions_metric).to eq(
|
220
|
-
{
|
221
|
-
'event_type' => 'metrics',
|
222
|
-
'sessions' => {
|
223
|
-
'hmac_session_id' => [
|
224
|
-
{
|
225
|
-
'uid' => 'user_id',
|
226
|
-
'track' => [
|
227
|
-
['user_agent', ['127.0.0.1']],
|
228
|
-
['user_agent_dos', ['127.0.0.1']]
|
229
|
-
]
|
230
|
-
}
|
231
|
-
]
|
232
|
-
}
|
233
|
-
}
|
234
|
-
)
|
235
|
-
end
|
236
|
-
end
|
237
|
-
end
|
238
|
-
end
|
239
|
-
|
240
|
-
context 'adding 200 sessions' do
|
241
|
-
it 'should update its state to flush' do
|
242
|
-
sessions_metric = SessionsMetric.new
|
243
|
-
expect(sessions_metric.flush).to eq(false)
|
244
|
-
|
245
|
-
200.times do |x|
|
246
|
-
sessions_metric.add_session_info('hmac_session_id', 'user_id', "127.0.0.1_#{x}", 'user_agent')
|
247
|
-
end
|
248
|
-
|
249
|
-
expect(sessions_metric.flush).to eq(true)
|
250
|
-
end
|
251
|
-
end
|
252
|
-
|
253
|
-
context 'adding 251 sessions' do
|
254
|
-
it 'should drop session after 250' do
|
255
|
-
logger = double('logger')
|
256
|
-
sessions_metric = SessionsMetric.new
|
257
|
-
|
258
|
-
expect(sessions_metric.flush).to eq(false)
|
259
|
-
expect(TCellAgent).to receive(:logger).and_return(logger)
|
260
|
-
expect(logger).to receive(:warn).with('Sessions Metric is full. Information dropped')
|
261
|
-
|
262
|
-
250.times do |x|
|
263
|
-
sessions_metric.add_session_info('hmac_session_id', 'user_id', "127.0.0.1_#{x}", 'user_agent')
|
264
|
-
end
|
265
|
-
|
266
|
-
expect(sessions_metric.flush).to eq(true)
|
267
|
-
end
|
268
|
-
end
|
269
|
-
end
|
270
|
-
end
|
271
|
-
end
|
272
|
-
end
|
@@ -1,52 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe TCellAgent::BoundedQueue do
|
4
|
-
describe '#full?' do
|
5
|
-
it 'should be true when the queue is full' do
|
6
|
-
queue = TCellAgent::BoundedQueue.new(1)
|
7
|
-
queue.push('one')
|
8
|
-
expect(queue.full?).to eq(true)
|
9
|
-
end
|
10
|
-
|
11
|
-
it 'should return false when the queue is not full' do
|
12
|
-
queue = TCellAgent::BoundedQueue.new(1)
|
13
|
-
expect(queue.full?).to eq(false)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
describe '#push' do
|
18
|
-
context 'pushing to a queue with space available' do
|
19
|
-
it 'should push the item' do
|
20
|
-
queue = TCellAgent::BoundedQueue.new(1)
|
21
|
-
queue.push('one')
|
22
|
-
|
23
|
-
expect(queue.size).to eq(1)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
context 'pushing to a full queue' do
|
28
|
-
it 'should not be possible to push anymore items' do
|
29
|
-
queue = TCellAgent::BoundedQueue.new(1)
|
30
|
-
queue.push('one')
|
31
|
-
|
32
|
-
expect(queue.size).to eq(1)
|
33
|
-
expect(queue.full?).to eq(true)
|
34
|
-
|
35
|
-
expect do
|
36
|
-
queue.push('two', 0.1)
|
37
|
-
end.to raise_error(RuntimeError)
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
describe '#pop' do
|
43
|
-
context 'popping from an empty queue' do
|
44
|
-
it 'should return nil when there are no items' do
|
45
|
-
queue = TCellAgent::BoundedQueue.new(1)
|
46
|
-
expect(queue.size).to eq(0)
|
47
|
-
|
48
|
-
expect(queue.pop(0.1)).to eq(nil)
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
@@ -1,143 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
module TCellAgent
|
4
|
-
module Utils
|
5
|
-
describe '.fingerprint_password' do
|
6
|
-
context 'with nil password' do
|
7
|
-
it 'should return nil' do
|
8
|
-
configuration = double('configuration',
|
9
|
-
:app_id => 'app_id',
|
10
|
-
:password_hmac_key => 'password_hmac_key')
|
11
|
-
|
12
|
-
expect(TCellAgent).to receive(:configuration).and_return(
|
13
|
-
configuration
|
14
|
-
)
|
15
|
-
expect(TCellAgent).to receive(:configuration).and_return(
|
16
|
-
configuration
|
17
|
-
)
|
18
|
-
|
19
|
-
expect(Passwords.fingerprint_password(nil, nil)).to be_nil
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
context "with '' password" do
|
24
|
-
it 'should return nil' do
|
25
|
-
configuration = double('configuration',
|
26
|
-
:app_id => 'app_id',
|
27
|
-
:password_hmac_key => 'password_hmac_key')
|
28
|
-
|
29
|
-
expect(TCellAgent).to receive(:configuration).and_return(
|
30
|
-
configuration
|
31
|
-
)
|
32
|
-
expect(TCellAgent).to receive(:configuration).and_return(
|
33
|
-
configuration
|
34
|
-
)
|
35
|
-
|
36
|
-
expect(Passwords.fingerprint_password('', nil)).to be_nil
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
context "with ' ' password" do
|
41
|
-
it 'should return nil' do
|
42
|
-
configuration = double('configuration',
|
43
|
-
:app_id => 'app_id',
|
44
|
-
:password_hmac_key => 'password_hmac_key')
|
45
|
-
|
46
|
-
expect(TCellAgent).to receive(:configuration).and_return(
|
47
|
-
configuration
|
48
|
-
)
|
49
|
-
expect(TCellAgent).to receive(:configuration).and_return(
|
50
|
-
configuration
|
51
|
-
)
|
52
|
-
|
53
|
-
expect(Passwords.fingerprint_password(' ', nil)).to be_nil
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
context 'with nil password_hmac_key' do
|
58
|
-
it 'should return nil' do
|
59
|
-
configuration = double('configuration',
|
60
|
-
:app_id => 'app_id',
|
61
|
-
:password_hmac_key => nil)
|
62
|
-
|
63
|
-
expect(TCellAgent).to receive(:configuration).and_return(
|
64
|
-
configuration
|
65
|
-
)
|
66
|
-
expect(TCellAgent).to receive(:configuration).and_return(
|
67
|
-
configuration
|
68
|
-
)
|
69
|
-
|
70
|
-
expect(Passwords.fingerprint_password('admin123', nil)).to be_nil
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
context "with '' password_hmac_key" do
|
75
|
-
it 'should return nil' do
|
76
|
-
configuration = double('configuration',
|
77
|
-
:app_id => 'app_id',
|
78
|
-
:password_hmac_key => '')
|
79
|
-
|
80
|
-
expect(TCellAgent).to receive(:configuration).and_return(
|
81
|
-
configuration
|
82
|
-
)
|
83
|
-
expect(TCellAgent).to receive(:configuration).and_return(
|
84
|
-
configuration
|
85
|
-
)
|
86
|
-
|
87
|
-
expect(Passwords.fingerprint_password('admin123', nil)).to be_nil
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
context "with ' ' password_hmac_key" do
|
92
|
-
it 'should return nil' do
|
93
|
-
configuration = double('configuration',
|
94
|
-
:app_id => 'app_id',
|
95
|
-
:password_hmac_key => ' ')
|
96
|
-
|
97
|
-
expect(TCellAgent).to receive(:configuration).and_return(
|
98
|
-
configuration
|
99
|
-
)
|
100
|
-
expect(TCellAgent).to receive(:configuration).and_return(
|
101
|
-
configuration
|
102
|
-
)
|
103
|
-
|
104
|
-
expect(Passwords.fingerprint_password('admin123', nil)).to be_nil
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
context 'with no user_id' do
|
109
|
-
it 'should return digest' do
|
110
|
-
configuration = double('configuration',
|
111
|
-
:app_id => 'TestAppId-AppId',
|
112
|
-
:password_hmac_key => 'password_hmac_key')
|
113
|
-
|
114
|
-
expect(TCellAgent).to receive(:configuration).and_return(
|
115
|
-
configuration
|
116
|
-
)
|
117
|
-
expect(TCellAgent).to receive(:configuration).and_return(
|
118
|
-
configuration
|
119
|
-
)
|
120
|
-
|
121
|
-
expect(Passwords.fingerprint_password('admin123', nil)).to eq('83ff14db')
|
122
|
-
end
|
123
|
-
end
|
124
|
-
|
125
|
-
context 'with user_id present' do
|
126
|
-
it 'should return digest' do
|
127
|
-
configuration = double('configuration',
|
128
|
-
:app_id => 'TestAppId-AppId',
|
129
|
-
:password_hmac_key => 'password_hmac_key')
|
130
|
-
|
131
|
-
expect(TCellAgent).to receive(:configuration).and_return(
|
132
|
-
configuration
|
133
|
-
)
|
134
|
-
expect(TCellAgent).to receive(:configuration).and_return(
|
135
|
-
configuration
|
136
|
-
)
|
137
|
-
|
138
|
-
expect(Passwords.fingerprint_password('admin123', 'user_id')).to eq('11a88b27')
|
139
|
-
end
|
140
|
-
end
|
141
|
-
end
|
142
|
-
end
|
143
|
-
end
|