vigilion-rails 2.0.0 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/jobs/vigilion_rails/application_job.rb +9 -0
- data/app/jobs/vigilion_rails/vigilion_scan_job.rb +10 -0
- data/lib/vigilion-rails/configuration.rb +1 -0
- data/lib/vigilion-rails/version.rb +1 -1
- data/lib/vigilion-rails.rb +8 -2
- data/spec/dummy/app/assets/config/manifest.js +3 -0
- data/spec/dummy/config/application.rb +0 -4
- data/spec/dummy/config/initializers/vigilion.rb +4 -0
- data/spec/jobs/vigilion_rails/vigilion_scan_job_spec.rb +26 -0
- data/spec/lib/integrations/local_integration_spec.rb +2 -2
- data/spec/lib/vigilion_rails_spec.rb +35 -1
- data/spec/vigilion_rails_helper.rb +2 -0
- metadata +62 -41
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e1f3ee39ebf2b55e3545ba4a2ea9c656e9b48d297e50250342a5a981d4d4aed3
|
4
|
+
data.tar.gz: 171c41bb2480b4a084051822bc0116a3e20af7d275e7a4c89c46f6c3eccb0f41
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dc908eb63faff594fa229f73c54ae067591715f4a494f5836666a9fd956f1c328fc5c247fb5a394d20e17d51afc17e3c2ab056b2dc320a1a66bbc9bbb4b79e5e
|
7
|
+
data.tar.gz: b0bd0272236fd4fed6be07ab447a1cee92422d6aa17ec6a7988f0b8e32ebf65685428b071aef49e28cce132b5b61781d351af0e653b3f4546b75ab1f1d5b1ffb
|
@@ -0,0 +1,9 @@
|
|
1
|
+
module VigilionRails
|
2
|
+
class ApplicationJob < ActiveJob::Base
|
3
|
+
# Automatically retry jobs that encountered a deadlock
|
4
|
+
# retry_on ActiveRecord::Deadlocked
|
5
|
+
|
6
|
+
# Most jobs are safe to ignore if the underlying records are no longer available
|
7
|
+
# discard_on ActiveJob::DeserializationError
|
8
|
+
end
|
9
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
module VigilionRails
|
2
|
+
class VigilionScanJob < ApplicationJob
|
3
|
+
queue_as :default
|
4
|
+
|
5
|
+
def perform(integration_class, class_name, id, key, column)
|
6
|
+
file = class_name.constantize.find(id)
|
7
|
+
integration_class.constantize.new.scan key, file, column.to_sym
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
data/lib/vigilion-rails.rb
CHANGED
@@ -4,6 +4,7 @@ require "vigilion-rails/integrations/local_integration"
|
|
4
4
|
require "vigilion-rails/configuration"
|
5
5
|
|
6
6
|
module VigilionRails
|
7
|
+
PENDING_STATUS = 'pending'
|
7
8
|
|
8
9
|
module ActiveRecord
|
9
10
|
def scan_file column, options={}
|
@@ -20,7 +21,12 @@ module VigilionRails
|
|
20
21
|
|
21
22
|
self.class.find(id).on_scan_#{column} status: Vigilion::Configuration.loopback_response
|
22
23
|
else
|
23
|
-
|
24
|
+
if Vigilion::Configuration.active_job
|
25
|
+
::VigilionRails::VigilionScanJob.set(wait: 60).perform_later(#{integration_class}.to_s, self.class.name, id, key, '#{column}')
|
26
|
+
else
|
27
|
+
#{integration_class}.new.scan key, self, :#{column}
|
28
|
+
end
|
29
|
+
self.class.find(id).send('on_scan_#{column}', status: PENDING_STATUS)
|
24
30
|
end
|
25
31
|
@#{column}_old_url = #{column}.url
|
26
32
|
return true
|
@@ -32,7 +38,7 @@ module VigilionRails
|
|
32
38
|
end
|
33
39
|
|
34
40
|
after_initialize :remember_#{column}_url
|
35
|
-
after_commit :check_scan_#{column}
|
41
|
+
after_commit :check_scan_#{column}, on: [:create, :update]
|
36
42
|
|
37
43
|
def remember_#{column}_url
|
38
44
|
@#{column}_old_url = #{column}.try(:url) unless new_record?
|
@@ -24,9 +24,5 @@ module Dummy
|
|
24
24
|
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
|
25
25
|
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
|
26
26
|
# config.i18n.default_locale = :de
|
27
|
-
|
28
|
-
# Do not swallow errors in after_commit/after_rollback callbacks.
|
29
|
-
config.active_record.raise_in_transactional_callbacks = true
|
30
27
|
end
|
31
28
|
end
|
32
|
-
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require "vigilion_rails_helper"
|
2
|
+
|
3
|
+
RSpec.describe VigilionRails::VigilionScanJob do
|
4
|
+
disable_loopback
|
5
|
+
it "matches with performed job" do
|
6
|
+
ActiveJob::Base.queue_adapter = :test
|
7
|
+
ActiveJob::Base.queue_adapter.perform_enqueued_jobs = true
|
8
|
+
document = CarrierwaveDocument.create
|
9
|
+
key = { model: document.class.name, column: 'attachment', id: document.id }
|
10
|
+
|
11
|
+
stub_request(:post, "https://api.vigilion.com/scans").
|
12
|
+
with(
|
13
|
+
body: "{\"scan\":{\"key\":{\"model\":\"CarrierwaveDocument\",\"column\":\"attachment\",\"id\":1},\"url\":null}}",
|
14
|
+
headers: {
|
15
|
+
'Accept'=>'*/*',
|
16
|
+
'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
|
17
|
+
'Content-Type'=>'application/json',
|
18
|
+
'User-Agent'=>'Vigilion 1.0.4 (x86_64-darwin19, Ruby 2.7.1)',
|
19
|
+
'X-Api-Key'=>'test'
|
20
|
+
}).
|
21
|
+
to_return(status: 200, body: "", headers: {})
|
22
|
+
|
23
|
+
VigilionRails::VigilionScanJob.perform_later("VigilionRails::UrlIntegration", document.class.name, document.id, key, 'attachment')
|
24
|
+
expect(VigilionRails::VigilionScanJob).to have_been_performed
|
25
|
+
end
|
26
|
+
end
|
@@ -5,9 +5,9 @@ describe VigilionRails::LocalIntegration do
|
|
5
5
|
|
6
6
|
describe "#scan" do
|
7
7
|
it "calls vigilion scanner" do
|
8
|
-
document = CarrierwaveDocument.
|
8
|
+
document = CarrierwaveDocument.create
|
9
9
|
expect(Vigilion).to receive(:scan_path)
|
10
10
|
document.scan_attachment!
|
11
11
|
end
|
12
12
|
end
|
13
|
-
end
|
13
|
+
end
|
@@ -1,6 +1,8 @@
|
|
1
1
|
require "vigilion_rails_helper"
|
2
2
|
|
3
3
|
describe VigilionRails do
|
4
|
+
include ActiveJob::TestHelper
|
5
|
+
|
4
6
|
describe "#clean?" do
|
5
7
|
context "without scan results" do
|
6
8
|
it "is not clean" do
|
@@ -32,7 +34,7 @@ describe VigilionRails do
|
|
32
34
|
disable_loopback
|
33
35
|
|
34
36
|
it "calls vigilion scanner" do
|
35
|
-
document = AgnosticDocument.
|
37
|
+
document = AgnosticDocument.create
|
36
38
|
expect(Vigilion).to receive(:scan_url)
|
37
39
|
document.scan_attachment!
|
38
40
|
end
|
@@ -119,4 +121,36 @@ describe VigilionRails do
|
|
119
121
|
end
|
120
122
|
end
|
121
123
|
end
|
124
|
+
|
125
|
+
describe "#active_job" do
|
126
|
+
before do
|
127
|
+
Vigilion::Configuration.loopback = false
|
128
|
+
Vigilion::Configuration.active_job = true
|
129
|
+
Vigilion::Configuration.integration = :url
|
130
|
+
end
|
131
|
+
|
132
|
+
it "enqueues a job" do
|
133
|
+
document = AgnosticDocument.create
|
134
|
+
expect {
|
135
|
+
document.scan_attachment!
|
136
|
+
}.to have_enqueued_job(::VigilionRails::VigilionScanJob)
|
137
|
+
end
|
138
|
+
|
139
|
+
it 'calls proper integration' do
|
140
|
+
document = AgnosticDocument.create
|
141
|
+
key = { model: document.class.name, column: 'attachment', id: document.id }.to_json
|
142
|
+
expect_any_instance_of(
|
143
|
+
::VigilionRails::UrlIntegration
|
144
|
+
).to receive(:scan).with(key, document, :attachment)
|
145
|
+
perform_enqueued_jobs do
|
146
|
+
document.scan_attachment!
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
it 'sets default status' do
|
151
|
+
document = AgnosticDocument.create
|
152
|
+
document.scan_attachment!
|
153
|
+
expect(document.reload.attachment_scan_results).to eq "pending"
|
154
|
+
end
|
155
|
+
end
|
122
156
|
end
|
@@ -4,8 +4,10 @@ require 'spec_helper'
|
|
4
4
|
require File.expand_path('../dummy/config/environment', __FILE__)
|
5
5
|
require 'rspec/rails'
|
6
6
|
require 'helper_methods'
|
7
|
+
require 'webmock/rspec'
|
7
8
|
|
8
9
|
ActiveRecord::Migration.maintain_test_schema!
|
10
|
+
ActiveJob::Base.queue_adapter = :test
|
9
11
|
|
10
12
|
RSpec.configure do |config|
|
11
13
|
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vigilion-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bit Zesty Ltd
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-05-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 6.0.3.7
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 6.0.3.7
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: vigilion
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -80,6 +80,20 @@ dependencies:
|
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: webmock
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
83
97
|
description: Rails engine for Vigilion Anti-Virus & Malware file scanning service.
|
84
98
|
email:
|
85
99
|
- help@vigilion.com
|
@@ -90,6 +104,8 @@ files:
|
|
90
104
|
- MIT-LICENSE
|
91
105
|
- Rakefile
|
92
106
|
- app/controllers/vigilion/vigilion_controller.rb
|
107
|
+
- app/jobs/vigilion_rails/application_job.rb
|
108
|
+
- app/jobs/vigilion_rails/vigilion_scan_job.rb
|
93
109
|
- config/routes.rb
|
94
110
|
- lib/generators/vigilion/install_generator.rb
|
95
111
|
- lib/generators/vigilion/scan/USAGE
|
@@ -104,6 +120,7 @@ files:
|
|
104
120
|
- lib/vigilion-rails/version.rb
|
105
121
|
- spec/dummy/README.rdoc
|
106
122
|
- spec/dummy/Rakefile
|
123
|
+
- spec/dummy/app/assets/config/manifest.js
|
107
124
|
- spec/dummy/app/assets/javascripts/application.js
|
108
125
|
- spec/dummy/app/assets/stylesheets/application.css
|
109
126
|
- spec/dummy/app/controllers/application_controller.rb
|
@@ -133,6 +150,7 @@ files:
|
|
133
150
|
- spec/dummy/config/initializers/inflections.rb
|
134
151
|
- spec/dummy/config/initializers/mime_types.rb
|
135
152
|
- spec/dummy/config/initializers/session_store.rb
|
153
|
+
- spec/dummy/config/initializers/vigilion.rb
|
136
154
|
- spec/dummy/config/initializers/wrap_parameters.rb
|
137
155
|
- spec/dummy/config/locales/en.yml
|
138
156
|
- spec/dummy/config/routes.rb
|
@@ -147,6 +165,7 @@ files:
|
|
147
165
|
- spec/dummy/public/500.html
|
148
166
|
- spec/dummy/public/favicon.ico
|
149
167
|
- spec/helper_methods.rb
|
168
|
+
- spec/jobs/vigilion_rails/vigilion_scan_job_spec.rb
|
150
169
|
- spec/lib/integrations/local_integration_spec.rb
|
151
170
|
- spec/lib/vigilion_rails_spec.rb
|
152
171
|
- spec/routing/vigilion_routing_spec.rb
|
@@ -171,59 +190,61 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
171
190
|
- !ruby/object:Gem::Version
|
172
191
|
version: '0'
|
173
192
|
requirements: []
|
174
|
-
|
175
|
-
rubygems_version: 2.7.6
|
193
|
+
rubygems_version: 3.0.3.1
|
176
194
|
signing_key:
|
177
195
|
specification_version: 4
|
178
196
|
summary: Rails engine for Vigilion Anti-Virus & Malware file scanning service.
|
179
197
|
test_files:
|
198
|
+
- spec/routing/vigilion_routing_spec.rb
|
199
|
+
- spec/helper_methods.rb
|
200
|
+
- spec/lib/vigilion_rails_spec.rb
|
201
|
+
- spec/lib/integrations/local_integration_spec.rb
|
180
202
|
- spec/vigilion_rails_helper.rb
|
181
|
-
- spec/
|
182
|
-
- spec/dummy/
|
183
|
-
- spec/dummy/app/models/carrierwave_document.rb
|
184
|
-
- spec/dummy/app/models/agnostic_document.rb
|
185
|
-
- spec/dummy/app/models/paperclip_document.rb
|
186
|
-
- spec/dummy/app/models/dragonfly_document.rb
|
187
|
-
- spec/dummy/app/controllers/application_controller.rb
|
188
|
-
- spec/dummy/app/views/layouts/application.html.erb
|
189
|
-
- spec/dummy/app/assets/javascripts/application.js
|
190
|
-
- spec/dummy/app/assets/stylesheets/application.css
|
191
|
-
- spec/dummy/app/helpers/application_helper.rb
|
192
|
-
- spec/dummy/bin/rake
|
203
|
+
- spec/dummy/Rakefile
|
204
|
+
- spec/dummy/README.rdoc
|
193
205
|
- spec/dummy/bin/setup
|
206
|
+
- spec/dummy/bin/rake
|
194
207
|
- spec/dummy/bin/bundle
|
195
208
|
- spec/dummy/bin/rails
|
196
|
-
- spec/dummy/config/secrets.yml
|
197
|
-
- spec/dummy/config/routes.rb
|
198
|
-
- spec/dummy/config/locales/en.yml
|
199
|
-
- spec/dummy/config/environments/production.rb
|
200
|
-
- spec/dummy/config/environments/development.rb
|
201
|
-
- spec/dummy/config/environments/test.rb
|
202
|
-
- spec/dummy/config/environment.rb
|
203
209
|
- spec/dummy/config/application.rb
|
204
|
-
- spec/dummy/config/database.yml
|
205
210
|
- spec/dummy/config/boot.rb
|
206
|
-
- spec/dummy/config/
|
211
|
+
- spec/dummy/config/secrets.yml
|
212
|
+
- spec/dummy/config/locales/en.yml
|
213
|
+
- spec/dummy/config/initializers/vigilion.rb
|
207
214
|
- spec/dummy/config/initializers/mime_types.rb
|
208
|
-
- spec/dummy/config/initializers/filter_parameter_logging.rb
|
209
|
-
- spec/dummy/config/initializers/session_store.rb
|
210
215
|
- spec/dummy/config/initializers/wrap_parameters.rb
|
216
|
+
- spec/dummy/config/initializers/inflections.rb
|
217
|
+
- spec/dummy/config/initializers/filter_parameter_logging.rb
|
211
218
|
- spec/dummy/config/initializers/assets.rb
|
219
|
+
- spec/dummy/config/initializers/backtrace_silencers.rb
|
220
|
+
- spec/dummy/config/initializers/session_store.rb
|
212
221
|
- spec/dummy/config/initializers/cookies_serializer.rb
|
213
|
-
- spec/dummy/config/
|
222
|
+
- spec/dummy/config/database.yml
|
223
|
+
- spec/dummy/config/routes.rb
|
224
|
+
- spec/dummy/config/environments/production.rb
|
225
|
+
- spec/dummy/config/environments/development.rb
|
226
|
+
- spec/dummy/config/environments/test.rb
|
227
|
+
- spec/dummy/config/environment.rb
|
228
|
+
- spec/dummy/app/views/layouts/application.html.erb
|
229
|
+
- spec/dummy/app/assets/javascripts/application.js
|
230
|
+
- spec/dummy/app/assets/config/manifest.js
|
231
|
+
- spec/dummy/app/assets/stylesheets/application.css
|
232
|
+
- spec/dummy/app/models/dragonfly_document.rb
|
233
|
+
- spec/dummy/app/models/carrierwave_document.rb
|
234
|
+
- spec/dummy/app/models/agnostic_document.rb
|
235
|
+
- spec/dummy/app/models/paperclip_document.rb
|
236
|
+
- spec/dummy/app/controllers/application_controller.rb
|
237
|
+
- spec/dummy/app/uploaders/attachment_uploader.rb
|
238
|
+
- spec/dummy/app/helpers/application_helper.rb
|
214
239
|
- spec/dummy/config.ru
|
215
|
-
- spec/dummy/Rakefile
|
216
|
-
- spec/dummy/public/favicon.ico
|
217
|
-
- spec/dummy/public/422.html
|
218
|
-
- spec/dummy/public/500.html
|
219
|
-
- spec/dummy/public/404.html
|
220
240
|
- spec/dummy/db/schema.rb
|
221
241
|
- spec/dummy/db/migrate/20150616144235_create_dragonfly_documents.rb
|
222
|
-
- spec/dummy/db/migrate/20150616144544_create_agnostic_documents.rb
|
223
242
|
- spec/dummy/db/migrate/20150616144227_create_paperclip_documents.rb
|
243
|
+
- spec/dummy/db/migrate/20150616144544_create_agnostic_documents.rb
|
224
244
|
- spec/dummy/db/migrate/20150616144220_create_carrierwave_documents.rb
|
225
|
-
- spec/dummy/
|
226
|
-
- spec/
|
227
|
-
- spec/
|
228
|
-
- spec/
|
229
|
-
- spec/
|
245
|
+
- spec/dummy/public/404.html
|
246
|
+
- spec/dummy/public/500.html
|
247
|
+
- spec/dummy/public/favicon.ico
|
248
|
+
- spec/dummy/public/422.html
|
249
|
+
- spec/spec_helper.rb
|
250
|
+
- spec/jobs/vigilion_rails/vigilion_scan_job_spec.rb
|