carrierwave-virus_free 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +23 -0
- data/.rspec +3 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +22 -0
- data/README.md +45 -0
- data/Rakefile +2 -0
- data/carrierwave-virus_free.gemspec +27 -0
- data/lib/carrierwave/virus_free.rb +13 -0
- data/lib/carrierwave/virus_free/version.rb +5 -0
- data/spec/spec_helper.rb +113 -0
- data/spec/support/data.rb +11 -0
- data/spec/support/mock.rb +29 -0
- data/spec/virus_free_validator_spec.rb +15 -0
- metadata +131 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 875a0c92e74effca97e9747d72c33e006324a85b
|
4
|
+
data.tar.gz: 47bfa4f426c438406367d0baf50068dca0266e23
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 033960c5d0f7dc3f38d81e5367602313cea78b3ce69dc83c99f7e118acd9b13cf5160f355a574304696f4a533b541f4928223f085614effb1e76997511547111
|
7
|
+
data.tar.gz: ac15569bde8a4b07aa45edd3fa8d46e2dcf7e7130bd9b3b57fe1959a0a508a52b774c79d36440a2649e8f517305d3b89fc59975ab75d6d8681aa21f78be8fb77
|
data/.gitignore
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
23
|
+
spec/data/
|
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 John Schroeder
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
# Carrierwave::VirusFreeValidator
|
2
|
+
|
3
|
+
Validate carrierwave uploads are virus free with clamav.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'carrierwave-virus_free_validator'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install carrierwave-virus_free_validator
|
18
|
+
|
19
|
+
## ClamScan Dependency
|
20
|
+
|
21
|
+
This gem requires the _clam_scan_ gem which requires that you have ClamAV installed. You may also need to configure it according to your needs - pointing it to the right location to clamscan/clamdscan on your system, setting it to delete infected files, etc. See the _clam_scan_ gem documentation for more details.
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
ClamScan.configure do |config|
|
27
|
+
# see clam_scan documentation for details
|
28
|
+
end
|
29
|
+
|
30
|
+
class MyModel < ActiveRecord::Base
|
31
|
+
mount_uploader :file, MyUploader
|
32
|
+
|
33
|
+
validates :file, virus_free: true
|
34
|
+
end
|
35
|
+
```
|
36
|
+
|
37
|
+
It's that easy.
|
38
|
+
|
39
|
+
## Contributing
|
40
|
+
|
41
|
+
1. Fork it ( https://github.com/[my-github-username]/carrierwave-virus_free_validator/fork )
|
42
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
43
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
44
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
45
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'carrierwave/virus_free/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "carrierwave-virus_free"
|
8
|
+
spec.version = Carrierwave::VirusFree::VERSION
|
9
|
+
spec.authors = ["John Schroeder"]
|
10
|
+
spec.email = ["jschroeder@multiadsolutions.com"]
|
11
|
+
spec.summary = %q{Validate carrierwave uploads are virus free with clamav.}
|
12
|
+
spec.description = %q{Validate carrierwave uploads are virus free with clamav.}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "activemodel"
|
22
|
+
spec.add_dependency "carrierwave"
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
25
|
+
spec.add_development_dependency "rake"
|
26
|
+
spec.add_development_dependency "rspec"
|
27
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module CarrierWave
|
2
|
+
module VirusFree
|
3
|
+
class VirusFreeValidator < ActiveModel::EachValidator
|
4
|
+
def validate_each (record, attribute, value)
|
5
|
+
if value.present? && !ClamScan::Client.scan(location: value.url).safe?
|
6
|
+
record.errors.add(attribute, 'That file can not be accepted')
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
ActiveModel::Validations.include CarrierWave::VirusFree
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
|
+
# The generated `.rspec` file contains `--require spec_helper` which will cause this
|
4
|
+
# file to always be loaded, without a need to explicitly require it in any files.
|
5
|
+
#
|
6
|
+
# Given that it is always loaded, you are encouraged to keep this file as
|
7
|
+
# light-weight as possible. Requiring heavyweight dependencies from this file
|
8
|
+
# will add to the boot time of your test suite on EVERY test run, even for an
|
9
|
+
# individual file that may not need all of that loaded. Instead, make a
|
10
|
+
# separate helper file that requires this one and then use it only in the specs
|
11
|
+
# that actually need it.
|
12
|
+
#
|
13
|
+
# The `.rspec` file also contains a few flags that are not defaults but that
|
14
|
+
# users commonly want.
|
15
|
+
#
|
16
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
17
|
+
|
18
|
+
# end initial stuff
|
19
|
+
|
20
|
+
require 'active_model'
|
21
|
+
require 'carrierwave/virus_free'
|
22
|
+
require 'clam_scan'
|
23
|
+
|
24
|
+
Dir[File.expand_path(File.join('..', 'support', '**', '*.rb'), __FILE__)].each { |f| require f }
|
25
|
+
|
26
|
+
RSpec.configure do |config|
|
27
|
+
# The settings below are suggested to provide a good initial experience
|
28
|
+
# with RSpec, but feel free to customize to your heart's content.
|
29
|
+
# These two settings work together to allow you to limit a spec run
|
30
|
+
# to individual examples or groups you care about by tagging them with
|
31
|
+
# `:focus` metadata. When nothing is tagged with `:focus`, all examples
|
32
|
+
# get run.
|
33
|
+
config.filter_run :focus
|
34
|
+
config.run_all_when_everything_filtered = true
|
35
|
+
|
36
|
+
# Many RSpec users commonly either run the entire suite or an individual
|
37
|
+
# file, and it's useful to allow more verbose output when running an
|
38
|
+
# individual spec file.
|
39
|
+
if config.files_to_run.one?
|
40
|
+
# Use the documentation formatter for detailed output,
|
41
|
+
# unless a formatter has already been configured
|
42
|
+
# (e.g. via a command-line flag).
|
43
|
+
config.default_formatter = 'doc'
|
44
|
+
end
|
45
|
+
|
46
|
+
# Print the 10 slowest examples and example groups at the
|
47
|
+
# end of the spec run, to help surface which specs are running
|
48
|
+
# particularly slow.
|
49
|
+
config.profile_examples = 10
|
50
|
+
|
51
|
+
# Run specs in random order to surface order dependencies. If you find an
|
52
|
+
# order dependency and want to debug it, you can fix the order by providing
|
53
|
+
# the seed, which is printed after each run.
|
54
|
+
# --seed 1234
|
55
|
+
config.order = :random
|
56
|
+
|
57
|
+
# Seed global randomization in this process using the `--seed` CLI option.
|
58
|
+
# Setting this allows you to use `--seed` to deterministically reproduce
|
59
|
+
# test failures related to randomization by passing the same `--seed` value
|
60
|
+
# as the one that triggered the failure.
|
61
|
+
Kernel.srand config.seed
|
62
|
+
|
63
|
+
# rspec-expectations config goes here. You can use an alternate
|
64
|
+
# assertion/expectation library such as wrong or the stdlib/minitest
|
65
|
+
# assertions if you prefer.
|
66
|
+
config.expect_with :rspec do |expectations|
|
67
|
+
# Enable only the newer, non-monkey-patching expect syntax.
|
68
|
+
# For more details, see:
|
69
|
+
# - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
|
70
|
+
expectations.syntax = :expect
|
71
|
+
end
|
72
|
+
|
73
|
+
# rspec-mocks config goes here. You can use an alternate test double
|
74
|
+
# library (such as bogus or mocha) by changing the `mock_with` option here.
|
75
|
+
config.mock_with :rspec do |mocks|
|
76
|
+
# Enable only the newer, non-monkey-patching expect syntax.
|
77
|
+
# For more details, see:
|
78
|
+
# - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
|
79
|
+
mocks.syntax = :expect
|
80
|
+
|
81
|
+
# Prevents you from mocking or stubbing a method that does not exist on
|
82
|
+
# a real object. This is generally recommended.
|
83
|
+
mocks.verify_partial_doubles = true
|
84
|
+
end
|
85
|
+
|
86
|
+
# end default stuff
|
87
|
+
|
88
|
+
config.before(:suite) do
|
89
|
+
# make data dir if it doesn't exist
|
90
|
+
unless File.directory? data_path
|
91
|
+
require 'fileutils'
|
92
|
+
FileUtils.mkdir_p data_path
|
93
|
+
end
|
94
|
+
|
95
|
+
# get eicar sample file if we don't have it
|
96
|
+
unless File.exist? eicar_path
|
97
|
+
require 'net/http'
|
98
|
+
Net::HTTP.start('www.eicar.org') do |http|
|
99
|
+
resp = http.get('/download/eicar.com')
|
100
|
+
File.open(eicar_path, 'wb') do |file|
|
101
|
+
file.write(resp.body)
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
# make a safe file if we don't have it
|
107
|
+
unless File.exist? safe_path
|
108
|
+
File.open(safe_path, 'w') do |file|
|
109
|
+
file.write 'bar'
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# okay... this isn't exactly great
|
2
|
+
# but after spending too much time looking for the perfect way to test this, it's good enough for now
|
3
|
+
# something better is welcome
|
4
|
+
|
5
|
+
class MyModel
|
6
|
+
include ActiveModel::Validations
|
7
|
+
|
8
|
+
attr_accessor :file
|
9
|
+
validates :file, :virus_free => true
|
10
|
+
|
11
|
+
def initialize (present, virus)
|
12
|
+
@file = MyFile.new(present, virus)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
class MyFile
|
17
|
+
def initialize (present, virus)
|
18
|
+
@present = present
|
19
|
+
@virus = virus
|
20
|
+
end
|
21
|
+
|
22
|
+
def present?
|
23
|
+
@present
|
24
|
+
end
|
25
|
+
|
26
|
+
def url
|
27
|
+
@virus ? eicar_path : safe_path
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe CarrierWave::VirusFree do
|
4
|
+
it 'is not valid when a virus is uploaded' do
|
5
|
+
expect(MyModel.new(true, true).valid?).to be_falsey
|
6
|
+
end
|
7
|
+
|
8
|
+
it 'is valid when something not infected is uploaded' do
|
9
|
+
expect(MyModel.new(true, false).valid?).to be_truthy
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'is valid when nothing is uploaded' do
|
13
|
+
expect(MyModel.new(false, false).valid?).to be_truthy
|
14
|
+
end
|
15
|
+
end
|
metadata
ADDED
@@ -0,0 +1,131 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: carrierwave-virus_free
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- John Schroeder
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-09-30 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activemodel
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: carrierwave
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.6'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.6'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: Validate carrierwave uploads are virus free with clamav.
|
84
|
+
email:
|
85
|
+
- jschroeder@multiadsolutions.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- ".rspec"
|
92
|
+
- Gemfile
|
93
|
+
- LICENSE.txt
|
94
|
+
- README.md
|
95
|
+
- Rakefile
|
96
|
+
- carrierwave-virus_free.gemspec
|
97
|
+
- lib/carrierwave/virus_free.rb
|
98
|
+
- lib/carrierwave/virus_free/version.rb
|
99
|
+
- spec/spec_helper.rb
|
100
|
+
- spec/support/data.rb
|
101
|
+
- spec/support/mock.rb
|
102
|
+
- spec/virus_free_validator_spec.rb
|
103
|
+
homepage: ''
|
104
|
+
licenses:
|
105
|
+
- MIT
|
106
|
+
metadata: {}
|
107
|
+
post_install_message:
|
108
|
+
rdoc_options: []
|
109
|
+
require_paths:
|
110
|
+
- lib
|
111
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
112
|
+
requirements:
|
113
|
+
- - ">="
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: '0'
|
116
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
117
|
+
requirements:
|
118
|
+
- - ">="
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: '0'
|
121
|
+
requirements: []
|
122
|
+
rubyforge_project:
|
123
|
+
rubygems_version: 2.2.2
|
124
|
+
signing_key:
|
125
|
+
specification_version: 4
|
126
|
+
summary: Validate carrierwave uploads are virus free with clamav.
|
127
|
+
test_files:
|
128
|
+
- spec/spec_helper.rb
|
129
|
+
- spec/support/data.rb
|
130
|
+
- spec/support/mock.rb
|
131
|
+
- spec/virus_free_validator_spec.rb
|