tcell_agent 2.3.0 → 2.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (83) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +2 -2
  3. data/bin/tcell_agent +6 -11
  4. data/lib/tcell_agent/agent.rb +18 -13
  5. data/lib/tcell_agent/config_initializer.rb +0 -4
  6. data/lib/tcell_agent/configuration.rb +4 -4
  7. data/lib/tcell_agent/hooks/login_fraud.rb +1 -1
  8. data/lib/tcell_agent/instrumentation.rb +14 -6
  9. data/lib/tcell_agent/instrumentation/cmdi.rb +32 -0
  10. data/lib/tcell_agent/instrumentation/lfi.rb +55 -9
  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/logger.rb +2 -2
  18. data/lib/tcell_agent/policies/dataloss_policy.rb +15 -8
  19. data/lib/tcell_agent/policies/headers_policy.rb +2 -2
  20. data/lib/tcell_agent/policies/patches_policy.rb +8 -4
  21. data/lib/tcell_agent/policies/policies_manager.rb +1 -0
  22. data/lib/tcell_agent/policies/policy_polling.rb +4 -3
  23. data/lib/tcell_agent/rails/auth/doorkeeper.rb +1 -0
  24. data/lib/tcell_agent/rails/better_ip.rb +7 -19
  25. data/lib/tcell_agent/rails/dlp.rb +48 -48
  26. data/lib/tcell_agent/rails/dlp/process_request.rb +5 -0
  27. data/lib/tcell_agent/rails/dlp_handler.rb +9 -10
  28. data/lib/tcell_agent/rails/js_agent_insert.rb +2 -3
  29. data/lib/tcell_agent/rails/middleware/context_middleware.rb +2 -1
  30. data/lib/tcell_agent/rails/middleware/global_middleware.rb +1 -5
  31. data/lib/tcell_agent/rails/middleware/headers_middleware.rb +1 -0
  32. data/lib/tcell_agent/rails/routes/grape.rb +2 -1
  33. data/lib/tcell_agent/rails/settings_reporter.rb +0 -8
  34. data/lib/tcell_agent/rails/tcell_body_proxy.rb +4 -6
  35. data/lib/tcell_agent/routes/table.rb +3 -0
  36. data/lib/tcell_agent/rust/agent_config.rb +9 -0
  37. data/lib/tcell_agent/rust/{libtcellagent-alpine-6.2.1.so → libtcellagent-alpine.so} +0 -0
  38. data/lib/tcell_agent/rust/{tcellagent-6.2.1.dll → libtcellagent-x64.dll} +0 -0
  39. data/lib/tcell_agent/rust/{libtcellagent-6.2.1.dylib → libtcellagent.dylib} +0 -0
  40. data/lib/tcell_agent/rust/{libtcellagent-6.2.1.so → libtcellagent.so} +0 -0
  41. data/lib/tcell_agent/rust/native_agent.rb +48 -58
  42. data/lib/tcell_agent/rust/native_library.rb +7 -10
  43. data/lib/tcell_agent/sensor_events/server_agent.rb +3 -100
  44. data/lib/tcell_agent/sensor_events/util/sanitizer_utilities.rb +1 -0
  45. data/lib/tcell_agent/servers/puma.rb +25 -8
  46. data/lib/tcell_agent/servers/rack_puma_handler.rb +13 -3
  47. data/lib/tcell_agent/servers/webrick.rb +13 -3
  48. data/lib/tcell_agent/settings_reporter.rb +0 -14
  49. data/lib/tcell_agent/sinatra.rb +1 -0
  50. data/lib/tcell_agent/tcell_context.rb +15 -6
  51. data/lib/tcell_agent/utils/headers.rb +0 -1
  52. data/lib/tcell_agent/utils/strings.rb +2 -2
  53. data/lib/tcell_agent/version.rb +1 -1
  54. data/spec/cruby_spec_helper.rb +26 -0
  55. data/spec/lib/tcell_agent/instrumentation/cmdi/io_cmdi_spec.rb +2 -2
  56. data/spec/lib/tcell_agent/instrumentation/lfi/file_lfi_spec.rb +211 -272
  57. data/spec/lib/tcell_agent/instrumentation/lfi/io_lfi_spec.rb +207 -223
  58. data/spec/lib/tcell_agent/instrumentation/lfi/kernel_lfi_spec.rb +89 -70
  59. data/spec/lib/tcell_agent/instrumentation/lfi_spec.rb +73 -0
  60. data/spec/lib/tcell_agent/patches_spec.rb +2 -1
  61. data/spec/lib/tcell_agent/policies/clickjacking_policy_spec.rb +1 -2
  62. data/spec/lib/tcell_agent/policies/content_security_policy_spec.rb +5 -6
  63. data/spec/lib/tcell_agent/policies/patches_policy_spec.rb +21 -2
  64. data/spec/lib/tcell_agent/policies/policies_manager_spec.rb +1 -1
  65. data/spec/lib/tcell_agent/policies/secure_headers_policy_spec.rb +14 -8
  66. data/spec/lib/tcell_agent/rails/better_ip_spec.rb +9 -11
  67. data/spec/lib/tcell_agent/rails/csrf_exception_spec.rb +6 -6
  68. data/spec/lib/tcell_agent/rails/dlp_spec.rb +1 -0
  69. data/spec/lib/tcell_agent/rails/js_agent_insert_spec.rb +10 -2
  70. data/spec/lib/tcell_agent/rails/middleware/tcell_body_proxy_spec.rb +2 -1
  71. data/spec/lib/tcell_agent/rails/routes/route_id_spec.rb +4 -4
  72. data/spec/lib/tcell_agent/settings_reporter_spec.rb +2 -16
  73. data/spec/lib/tcell_agent/tcell_context_spec.rb +6 -5
  74. data/spec/spec_helper.rb +3 -1
  75. data/spec/support/builders.rb +2 -1
  76. data/spec/support/server_mocks/puma_mock.rb +4 -0
  77. data/spec/support/shared_spec.rb +29 -0
  78. data/tcell_agent.gemspec +14 -14
  79. metadata +23 -19
  80. data/Rakefile +0 -18
  81. data/lib/tcell_agent/instrumentation/monkey_patches/file.rb +0 -25
  82. data/lib/tcell_agent/instrumentation/monkey_patches/io.rb +0 -131
  83. data/lib/tcell_agent/instrumentation/monkey_patches/kernel.rb +0 -102
@@ -262,10 +262,10 @@ describe IO do
262
262
  IO.popen(@env, %w[echo test], 'w+', :unsetenv_others => true)
263
263
 
264
264
  expect(TCellAgent::Cmdi).to receive(:block_command?).with('echo test')
265
- IO.popen([@env, 'echo', 'test', :unsetenv_others => true], 'w+')
265
+ IO.popen([@env, 'echo', 'test', { :unsetenv_others => true }], 'w+')
266
266
 
267
267
  expect(TCellAgent::Cmdi).to receive(:block_command?).with('echo test')
268
- IO.popen(@env, [@env, 'echo', 'test', :unsetenv_others => true], 'w+', :err => %i[child out])
268
+ IO.popen(@env, [@env, 'echo', 'test', { :unsetenv_others => true }], 'w+', :err => %i[child out])
269
269
  end
270
270
  end
271
271
  end
@@ -1,3 +1,6 @@
1
+ # rubocop:disable Style/HashSyntax
2
+ # rubocop:disable Lint/UselessAssignment
3
+
1
4
  require 'spec_helper'
2
5
  require 'securerandom'
3
6
 
@@ -12,7 +15,7 @@ describe 'File' do
12
15
  )
13
16
  @filename = get_test_resource_path('lfi_sample_file.txt')
14
17
  @file_contents = "This is line one.\nThis is line two.\n"
15
- @new_file_name = '/tmp/' + SecureRandom.uuid
18
+ @new_file_name = NEW_FILE_NAME
16
19
  end
17
20
 
18
21
  describe '.new' do
@@ -29,298 +32,234 @@ describe 'File' do
29
32
  end.to raise_error(Errno::ENOENT)
30
33
  end
31
34
  end
32
- context 'with a non-existent file' do
33
- context 'with a directory not blocked for read/write' do
34
- before(:each) do
35
- expect(TCellAgent).to receive(:policy).with(
36
- TCellAgent::PolicyTypes::LFI
37
- ).and_return(@local_files_policy)
38
- expect(@local_files_policy).to receive(:block_file_access?).and_return(false)
39
- end
40
- context 'with a filename and mode r' do
41
- it 'should raise an ERRNO::ENOENT error' do
42
- expect do
43
- File.new(@new_file_name, 'r')
44
- end.to raise_error(Errno::ENOENT)
45
- end
46
- end
47
- context 'with a filename and mode w' do
48
- it 'should create the file' do
49
- File.new(@new_file_name, 'w')
50
35
 
51
- expect(File.exist?(@new_file_name)).to be_truthy
52
- File.delete(@new_file_name)
53
- end
54
- end
55
- context 'with a filename and write mode and file permissions 644' do
56
- it 'should create the file with the correct permissions' do
57
- File.new(@new_file_name, 'w', 0o644)
58
-
59
- expect(File.exist?(@new_file_name)).to be_truthy
60
- expect(File.stat(@new_file_name).mode.to_s(8)[3..5]).to eq('644')
61
- File.delete(@new_file_name)
62
- end
63
- end
64
- context 'with a filename and write mode and file permissions 755' do
65
- it 'should create the file with the correct permissions' do
66
- File.new(@new_file_name, 'w', 0o755)
67
-
68
- expect(File.exist?(@new_file_name)).to be_truthy
69
- expect(File.stat(@new_file_name).mode.to_s(8)[3..5]).to eq('755')
70
- File.delete(@new_file_name)
71
- end
72
- end
73
- context 'with a filename and write mode and file permissions 777' do
74
- it 'should create the file with permissions 755' do
75
- File.new(@new_file_name, 'w', 0o777)
76
-
77
- expect(File.exist?(@new_file_name)).to be_truthy
78
- expect(File.stat(@new_file_name).mode.to_s(8)[3..5]).to eq('755')
79
- File.delete(@new_file_name)
80
- end
81
- end
36
+ context 'with a file not blocked for read/write' do
37
+ before(:each) do
38
+ expect(TCellAgent).to receive(:policy).with(
39
+ TCellAgent::PolicyTypes::LFI
40
+ ).and_return(@local_files_policy)
41
+ expect(@local_files_policy).to receive(:block_file_access?).and_return(false)
82
42
  end
83
- context 'with a filename blocked for read/write' do
84
- before(:each) do
85
- expect(TCellAgent).to receive(:policy).with(
86
- TCellAgent::PolicyTypes::LFI
87
- ).and_return(@local_files_policy)
88
- expect(@local_files_policy).to receive(:block_file_access?).and_return(true)
89
- end
90
- context 'with a filename and write mode' do
91
- it 'should raise an IOError' do
92
- expect do
93
- File.new(@new_file_name, 'w')
94
- end.to raise_error(IOError)
95
- end
96
- end
97
- context 'with a filename and write mode and file permissions 644' do
98
- it 'should raise an IOError' do
99
- expect do
100
- File.new(@new_file_name, 'w', 644)
101
- end.to raise_error(IOError)
102
- end
43
+
44
+ after(:each) do |example|
45
+ end
46
+
47
+ it 'raises an ERRNO::ENOENT error', :file_created => false do
48
+ expect do
49
+ File.new(@new_file_name, 'r')
50
+ end.to raise_error(Errno::ENOENT)
51
+ end
52
+
53
+ it 'creates the file when passed mode w' do
54
+ File.new(@new_file_name, 'w')
55
+
56
+ expect(File.exist?(@new_file_name)).to be_truthy
57
+ File.delete(@new_file_name) if File.exist?(@new_file_name)
58
+ end
59
+
60
+ it 'creates the file with the correct permissions' do
61
+ File.new(@new_file_name, 'w', 0o644)
62
+
63
+ expect(File.stat(@new_file_name).mode.to_s(8)[3..5]).to eq('644')
64
+ expect(File.exist?(@new_file_name)).to be_truthy
65
+ File.delete(@new_file_name) if File.exist?(@new_file_name)
66
+ end
67
+
68
+ it 'creates the file with the correct permissions' do
69
+ File.new(@new_file_name, 'w', 0o755)
70
+
71
+ expect(File.stat(@new_file_name).mode.to_s(8)[3..5]).to eq('755')
72
+ expect(File.exist?(@new_file_name)).to be_truthy
73
+ File.delete(@new_file_name) if File.exist?(@new_file_name)
74
+ end
75
+
76
+ it 'reads the file' do
77
+ result = File.new(@filename).read
78
+ expect(result).to eq @file_contents
79
+ end
80
+
81
+ it 'reads the file when passed a mode' do
82
+ result = File.new(@filename, 'r').read
83
+ expect(result).to eq @file_contents
84
+ end
85
+
86
+ it 'writes to the file' do
87
+ file = File.new('/dev/null', 'w')
88
+ expect(file.write('dummy message')).to eq 13
89
+ end
90
+
91
+ it 'appends to the file' do
92
+ file = File.new('/dev/null', 'a')
93
+ expect(file.write('dummy message')).to eq 13
94
+ end
95
+
96
+ context 'using mode, permission, binmode opt' do
97
+ after :each do
98
+ expect(@result.binmode?).to be_truthy
99
+ expect(File.stat(@new_file_name).mode.to_s(8)[3..5]).to eq('755')
100
+
101
+ File.delete(@new_file_name)
103
102
  end
103
+
104
+ test_ruby2_ruby3_keywords(File,
105
+ 'new',
106
+ [NEW_FILE_NAME, 'w', 0o755],
107
+ { binmode: true },
108
+ nil)
104
109
  end
105
110
  end
106
- context 'with an existing file' do
107
- context 'with a file not blocked for read/write' do
108
- before(:each) do
109
- expect(TCellAgent).to receive(:policy).with(
110
- TCellAgent::PolicyTypes::LFI
111
- ).and_return(@local_files_policy)
112
- expect(@local_files_policy).to receive(:block_file_access?).and_return(false)
113
- end
114
- context 'with a filename' do
115
- it 'should still be able to read the file' do
116
- result = File.new(@filename).read
117
- expect(result).to eq @file_contents
118
- end
119
- end
120
- context 'with a filename and mode r' do
121
- it 'should still be able to read the file' do
122
- result = File.new(@filename, 'r').read
123
- expect(result).to eq @file_contents
124
- end
125
- end
126
- context 'with a filenname and mode w' do
127
- it 'should still be able to write to a file' do
128
- file = File.new('/dev/null', 'w')
129
- expect(file.write('dummy message')).to eq 13
130
- end
131
- end
132
- context 'with a filenname and mode a' do
133
- it 'should still be able to write to a file' do
134
- file = File.new('/dev/null', 'a')
135
- expect(file.write('dummy message')).to eq 13
136
- end
137
- end
111
+
112
+ context 'with a file blocked for read/write' do
113
+ before(:each) do
114
+ expect(TCellAgent).to receive(:policy).with(
115
+ TCellAgent::PolicyTypes::LFI
116
+ ).and_return(@local_files_policy)
117
+ expect(@local_files_policy).to receive(:block_file_access?).and_return(true)
138
118
  end
139
- context 'with a file blocked for read/write' do
140
- before(:each) do
141
- expect(TCellAgent).to receive(:policy).with(
142
- TCellAgent::PolicyTypes::LFI
143
- ).and_return(@local_files_policy)
144
- expect(@local_files_policy).to receive(:block_file_access?).and_return(true)
145
- end
146
- context 'with a filename' do
147
- it 'should not be able to read the file' do
148
- expect do
149
- File.new(@filename)
150
- end.to raise_error(IOError)
151
- end
152
- end
153
- context 'with a filename and mode r' do
154
- it 'should not be able to read the file' do
155
- expect do
156
- File.new(@filename, 'r')
157
- end.to raise_error(IOError)
158
- end
159
- end
160
- context 'with a filename and mode w' do
161
- it 'should not be able to write to the file' do
162
- expect do
163
- File.new('/dev/null', 'w')
164
- end.to raise_error(IOError)
165
- end
166
- end
119
+
120
+ it 'raises an IOError' do
121
+ expect do
122
+ File.new(@new_file_name, 'w')
123
+ end.to raise_error(IOError)
124
+ end
125
+
126
+ it 'raises an IOError' do
127
+ expect do
128
+ File.new(@new_file_name, 'w', 644)
129
+ end.to raise_error(IOError)
130
+ end
131
+
132
+ it 'raises an IOError' do
133
+ expect do
134
+ File.new(@filename)
135
+ end.to raise_error(IOError)
136
+ end
137
+
138
+ it 'raises an IOError' do
139
+ expect do
140
+ File.new(@filename, 'r')
141
+ end.to raise_error(IOError)
142
+ end
143
+ it 'raises an IOError' do
144
+ expect do
145
+ File.new('/dev/null', 'w')
146
+ end.to raise_error(IOError)
167
147
  end
168
148
  end
169
149
  end
170
150
 
171
151
  describe '.open' do
172
- context 'empty path' do
173
- it 'should raise an error' do
174
- expect do
175
- File.open
176
- end.to raise_error(ArgumentError)
177
- expect do
178
- File.open(nil)
179
- end.to raise_error(TypeError)
152
+ context 'with a file not blocked for read/write' do
153
+ before(:each) do
154
+ expect(TCellAgent).to receive(:policy).with(
155
+ TCellAgent::PolicyTypes::LFI
156
+ ).and_return(@local_files_policy)
157
+ expect(@local_files_policy).to receive(:block_file_access?).and_return(false)
158
+ end
159
+
160
+ it 'raises an ERRNO::ENOENT error', :file_created => false do
180
161
  expect do
181
- File.open('')
162
+ File.open(@new_file_name, 'r')
182
163
  end.to raise_error(Errno::ENOENT)
183
164
  end
184
- end
185
- context 'with a non-existent file' do
186
- before(:all) do
187
- @new_file_name = '/tmp/' + SecureRandom.uuid
188
- end
189
- context 'with a directory not blocked for read/write' do
190
- before(:each) do
191
- expect(TCellAgent).to receive(:policy).with(
192
- TCellAgent::PolicyTypes::LFI
193
- ).and_return(@local_files_policy)
194
- expect(@local_files_policy).to receive(:block_file_access?).and_return(false)
195
- end
196
- context 'with a filename and mode r' do
197
- it 'should raise an ERRNO::ENOENT error' do
198
- expect do
199
- File.open(@new_file_name, 'r')
200
- end.to raise_error(Errno::ENOENT)
201
- end
202
- end
203
- context 'with a filename and mode w' do
204
- it 'should create the file' do
205
- File.open(@new_file_name, 'w')
206
165
 
207
- expect(File.exist?(@new_file_name)).to be_truthy
208
- File.delete(@new_file_name)
209
- end
210
- end
211
- context 'with a filename and write mode and file permissions 644' do
212
- it 'should create the file with the correct permissions' do
213
- File.open(@new_file_name, 'w', 0o644)
214
-
215
- expect(File.exist?(@new_file_name)).to be_truthy
216
- expect(File.stat(@new_file_name).mode.to_s(8)[3..5]).to eq('644')
217
- File.delete(@new_file_name)
218
- end
219
- end
220
- context 'with a filename and write mode and file permissions 755' do
221
- it 'should create the file with the correct permissions' do
222
- File.open(@new_file_name, 'w', 0o755)
223
-
224
- expect(File.exist?(@new_file_name)).to be_truthy
225
- expect(File.stat(@new_file_name).mode.to_s(8)[3..5]).to eq('755')
226
- File.delete(@new_file_name)
227
- end
228
- end
229
- context 'with a filename and write mode and file permissions 777' do
230
- it 'should create the file with permissions 755' do
231
- File.open(@new_file_name, 'w', 0o777)
232
-
233
- expect(File.exist?(@new_file_name)).to be_truthy
234
- expect(File.stat(@new_file_name).mode.to_s(8)[3..5]).to eq('755')
235
- File.delete(@new_file_name)
236
- end
237
- end
166
+ it 'creates the file when passed mode w' do
167
+ File.open(@new_file_name, 'w')
168
+
169
+ expect(File.exist?(@new_file_name)).to be_truthy
170
+ File.delete(@new_file_name) if File.exist?(@new_file_name)
238
171
  end
239
- context 'with a filename blocked for read/write' do
240
- before(:each) do
241
- expect(TCellAgent).to receive(:policy).with(
242
- TCellAgent::PolicyTypes::LFI
243
- ).and_return(@local_files_policy)
244
- expect(@local_files_policy).to receive(:block_file_access?).and_return(true)
245
- end
246
- context 'with a filename and write mode' do
247
- it 'should raise an IOError' do
248
- expect do
249
- File.open(@new_file_name, 'w')
250
- end.to raise_error(IOError)
251
- end
252
- end
253
- context 'with a filename and write mode and file permissions 644' do
254
- it 'should raise an IOError' do
255
- expect do
256
- File.open(@new_file_name, 'w', 644)
257
- end.to raise_error(IOError)
258
- end
172
+
173
+ it 'creates the file with the correct permissions' do
174
+ File.open(@new_file_name, 'w', 0o644)
175
+
176
+ expect(File.stat(@new_file_name).mode.to_s(8)[3..5]).to eq('644')
177
+ expect(File.exist?(@new_file_name)).to be_truthy
178
+ File.delete(@new_file_name) if File.exist?(@new_file_name)
179
+ end
180
+
181
+ it 'creates the file with the correct permissions' do
182
+ File.open(@new_file_name, 'w', 0o755)
183
+
184
+ expect(File.stat(@new_file_name).mode.to_s(8)[3..5]).to eq('755')
185
+ expect(File.exist?(@new_file_name)).to be_truthy
186
+ File.delete(@new_file_name) if File.exist?(@new_file_name)
187
+ end
188
+
189
+ it 'reads the file' do
190
+ result = File.open(@filename).read
191
+ expect(result).to eq @file_contents
192
+ end
193
+
194
+ it 'reads the file when passed a mode' do
195
+ result = File.open(@filename, 'r').read
196
+ expect(result).to eq @file_contents
197
+ end
198
+
199
+ it 'writes to the file' do
200
+ file = File.open('/dev/null', 'w')
201
+ expect(file.write('dummy message')).to eq 13
202
+ end
203
+
204
+ it 'appends to the file' do
205
+ file = File.open('/dev/null', 'a')
206
+ expect(file.write('dummy message')).to eq 13
207
+ end
208
+
209
+ context 'using mode, permission, binmode opt' do
210
+ after :each do
211
+ expect(@result.binmode?).to be_truthy
212
+ expect(File.stat(@new_file_name).mode.to_s(8)[3..5]).to eq('755')
259
213
  end
214
+
215
+ test_ruby2_ruby3_keywords(File,
216
+ 'open',
217
+ [NEW_FILE_NAME, 'w', 0o755],
218
+ { binmode: true },
219
+ nil)
260
220
  end
261
221
  end
262
- context 'with an existing file' do
263
- context 'with a file not blocked for read/write' do
264
- before(:each) do
265
- expect(TCellAgent).to receive(:policy).with(
266
- TCellAgent::PolicyTypes::LFI
267
- ).and_return(@local_files_policy)
268
- expect(@local_files_policy).to receive(:block_file_access?).and_return(false)
269
- end
270
- context 'with a filename' do
271
- it 'should still be able to read the file' do
272
- result = File.open(@filename).read
273
- expect(result).to eq @file_contents
274
- end
275
- end
276
- context 'with a filename and mode r' do
277
- it 'should still be able to read the file' do
278
- result = File.open(@filename, 'r').read
279
- expect(result).to eq @file_contents
280
- end
281
- end
282
- context 'with a filenname and mode w' do
283
- it 'should still be able to write to a file' do
284
- file = File.open('/dev/null', 'w')
285
- expect(file.write('dummy message')).to eq 13
286
- end
287
- end
288
- context 'with a filenname and mode a' do
289
- it 'should still be able to write to a file' do
290
- file = File.open('/dev/null', 'a')
291
- expect(file.write('dummy message')).to eq 13
292
- end
293
- end
222
+
223
+ context 'with a file blocked for read/write' do
224
+ before(:each) do
225
+ expect(TCellAgent).to receive(:policy).with(
226
+ TCellAgent::PolicyTypes::LFI
227
+ ).and_return(@local_files_policy)
228
+ expect(@local_files_policy).to receive(:block_file_access?).and_return(true)
294
229
  end
295
- context 'with a file blocked for read/write' do
296
- before(:each) do
297
- expect(TCellAgent).to receive(:policy).with(
298
- TCellAgent::PolicyTypes::LFI
299
- ).and_return(@local_files_policy)
300
- expect(@local_files_policy).to receive(:block_file_access?).and_return(true)
301
- end
302
- context 'with a filename' do
303
- it 'should not be able to read the file' do
304
- expect do
305
- File.open(@filename)
306
- end.to raise_error(IOError)
307
- end
308
- end
309
- context 'with a filename and mode r' do
310
- it 'should not be able to read the file' do
311
- expect do
312
- File.open(@filename, 'r')
313
- end.to raise_error(IOError)
314
- end
315
- end
316
- context 'with a filename and mode w' do
317
- it 'should not be able to write to the file' do
318
- expect do
319
- File.open('/dev/null', 'w')
320
- end.to raise_error(IOError)
321
- end
322
- end
230
+
231
+ it 'raises an IOError' do
232
+ expect do
233
+ File.open(@new_file_name, 'w')
234
+ end.to raise_error(IOError)
235
+ end
236
+
237
+ it 'raises an IOError' do
238
+ expect do
239
+ File.open(@new_file_name, 'w', 644)
240
+ end.to raise_error(IOError)
241
+ end
242
+
243
+ it 'raises an IOError' do
244
+ expect do
245
+ File.open(@filename)
246
+ end.to raise_error(IOError)
247
+ end
248
+
249
+ it 'raises an IOError' do
250
+ expect do
251
+ File.open(@filename, 'r')
252
+ end.to raise_error(IOError)
253
+ end
254
+
255
+ it 'raises an IOError' do
256
+ expect do
257
+ File.open('/dev/null', 'w')
258
+ end.to raise_error(IOError)
323
259
  end
324
260
  end
325
261
  end
326
262
  end
263
+
264
+ # # rubocop:enable Style/HashSyntax
265
+ # # rubocop:enable Lint/UselessAssignment