test_server 0.4.1 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +6 -3
- data/Gemfile +13 -5
- data/README.md +16 -0
- data/Rakefile +17 -3
- data/app/assets/javascripts/test_server/file_uploader.js.coffee +3 -0
- data/app/assets/stylesheets/application.scss +31 -0
- data/app/assets/stylesheets/test_server/file_uploader.css.scss +3 -0
- data/app/controllers/test_server/file_uploader_controller.rb +42 -0
- data/app/helpers/test_server/file_uploader_helper.rb +2 -0
- data/app/models/test_server/file_upload.rb +41 -0
- data/app/views/layouts/application.html.haml +10 -0
- data/app/views/test_server/dashboard/show.html.haml +1 -0
- data/app/views/test_server/file_uploader/_form.html.haml +27 -0
- data/app/views/test_server/file_uploader/_overview.html.haml +1 -0
- data/app/views/test_server/file_uploader/index.html.haml +1 -0
- data/app/views/test_server/file_uploader/result.html.haml +40 -0
- data/app/views/test_server/file_uploader/upload.html.haml +1 -0
- data/config/routes.rb +8 -2
- data/lib/test_server/checksum.rb +21 -0
- data/lib/test_server/checksum_calculator.rb +27 -0
- data/lib/test_server/command_runner.rb +58 -0
- data/lib/test_server/exceptions.rb +3 -0
- data/lib/test_server/file_size.rb +14 -0
- data/lib/test_server/filetype_detector.rb +21 -0
- data/lib/test_server/locales/en.yml +28 -1
- data/lib/test_server/main.rb +6 -1
- data/lib/test_server/md5_calculator.rb +17 -0
- data/lib/test_server/permitted_params.rb +25 -7
- data/lib/test_server/sha256_calculator.rb +17 -0
- data/lib/test_server/uploaded_file.rb +58 -0
- data/lib/test_server/version.rb +1 -1
- data/lib/test_server/virus_detector.rb +43 -0
- data/lib/test_server.rb +15 -0
- data/public/assets/{manifest-7c069da388f8a976fadfaab958b9feb7.json → manifest-1a3c45fcd482cca628c8cdc72631eb98.json} +0 -0
- data/spec/controllers/test_server/file_uploader_controller_spec.rb +26 -0
- data/spec/encoder_spec.rb +3 -3
- data/spec/features/fetch_data_via_javascript_spec.rb +18 -18
- data/spec/filetype_detector_spec.rb +31 -0
- data/spec/fixtures/file_uploader/file.bin +0 -0
- data/spec/permitted_params_spec.rb +1 -1
- data/spec/sha256_calculator_spec.rb +36 -0
- data/spec/spec_helper.rb +2 -0
- data/spec/support/commands.rb +15 -0
- data/spec/support/debugging.rb +6 -1
- data/spec/support/eicar.rb +15 -0
- data/spec/support/fixtures.rb +16 -0
- data/spec/support/rails.rb +2 -0
- data/spec/uploaded_file_spec.rb +167 -0
- data/spec/views/errors/not_found.html.haml_spec.rb +1 -1
- data/spec/views/test_server/file_uploader/index.html.haml_spec.rb +32 -0
- data/spec/views/test_server/file_uploader/result.html.haml_spec.rb +58 -0
- data/spec/views/test_server/file_uploader/upload.html.haml_spec.rb +12 -0
- data/spec/views/test_server/reflector/client_ip_address.html.haml_spec.rb +1 -1
- data/spec/virus_detector_spec.rb +45 -0
- data/test_server.gemspec +2 -3
- metadata +48 -19
File without changes
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe TestServer::FileUploaderController do
|
4
|
+
|
5
|
+
describe "GET 'show'" do
|
6
|
+
it "returns http success" do
|
7
|
+
post 'result'
|
8
|
+
response.should be_success
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "GET 'index'" do
|
13
|
+
it "returns http success" do
|
14
|
+
get 'index'
|
15
|
+
response.should be_success
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "GET 'upload'" do
|
20
|
+
it "returns http success" do
|
21
|
+
get 'upload'
|
22
|
+
response.should be_success
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
data/spec/encoder_spec.rb
CHANGED
@@ -20,7 +20,7 @@ describe Encoder do
|
|
20
20
|
|
21
21
|
context '#name?' do
|
22
22
|
it 'checks name' do
|
23
|
-
expect(MyEncoder.new.name?(MyEncoder.new.name)).to
|
23
|
+
expect(MyEncoder.new.name?(MyEncoder.new.name)).to be_truthy
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
@@ -34,7 +34,7 @@ describe Encoder do
|
|
34
34
|
it 'compares instances for hash' do
|
35
35
|
e1 = MyEncoder.new
|
36
36
|
e2 = MyEncoder.new
|
37
|
-
expect(e1.eql? e2).to
|
37
|
+
expect(e1.eql? e2).to be_truthy
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
@@ -42,7 +42,7 @@ describe Encoder do
|
|
42
42
|
it 'understands equality' do
|
43
43
|
e1 = MyEncoder.new
|
44
44
|
e2 = MyEncoder.new
|
45
|
-
expect(e1 == e2).to
|
45
|
+
expect(e1 == e2).to be_truthy
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
@@ -54,25 +54,25 @@ describe 'Fetch data via javascript', :js do
|
|
54
54
|
expect(page).to have_content(url)
|
55
55
|
end
|
56
56
|
|
57
|
-
it 'supports opening a new page based on given values' do
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
57
|
+
#it 'supports opening a new page based on given values' do
|
58
|
+
# url = '/generator/xhr'
|
59
|
+
# visit '/generator/xhr'
|
60
|
+
|
61
|
+
# within '#form' do
|
62
|
+
# fill_in 'url', :with => url
|
63
|
+
# fill_in 'count', :with => 1
|
64
|
+
# fill_in 'timeout', :with => 100
|
65
|
+
# find('#repeat').trigger('click')
|
66
|
+
# end
|
67
67
|
|
68
|
-
|
68
|
+
# click_link('clone')
|
69
69
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
end
|
70
|
+
# within_window '' do
|
71
|
+
# expect(find('#url').value).to eq url
|
72
|
+
# expect(find('#count').value).to eq '1'
|
73
|
+
# expect(find('#timeout').value).to eq '100'
|
74
|
+
# expect(find('#repeat').checked?).to be true
|
75
|
+
# end
|
76
|
+
#end
|
77
77
|
end
|
78
78
|
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe FiletypeDetector do
|
5
|
+
context '#use' do
|
6
|
+
it 'adds filetype if it\'s known' do
|
7
|
+
test_file = create_file('file.html', '<html></html>')
|
8
|
+
|
9
|
+
file = double 'file'
|
10
|
+
expect(file).to receive(:path).and_return(test_file)
|
11
|
+
expect(file).to receive(:filetype=).with('HTML document, ASCII text, with no line terminators')
|
12
|
+
|
13
|
+
detector = FiletypeDetector.new
|
14
|
+
detector.use file
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'adds error message if an error occured during filetype detection' do
|
19
|
+
test_file = SecureRandom.hex
|
20
|
+
|
21
|
+
file = double 'file'
|
22
|
+
expect(file).to receive(:path).and_return(test_file)
|
23
|
+
allow(file).to receive(:name).and_return(File.basename(test_file))
|
24
|
+
expect(file).to receive(:filetype=).with("cannot open `#{test_file}' (No such file or directory)")
|
25
|
+
|
26
|
+
detector = FiletypeDetector.new
|
27
|
+
detector.use file
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
Binary file
|
@@ -58,7 +58,7 @@ describe PermittedParams do
|
|
58
58
|
permitted_params = PermittedParams.new(params)
|
59
59
|
|
60
60
|
params = permitted_params.known_params_for_controller("string", "plain")
|
61
|
-
expect(params).to eq [:base64, :base64_strict, :count, :expires, :gzip]
|
61
|
+
expect(params).to eq [:base64, :base64_strict, :count, :expires, :gzip, :wait]
|
62
62
|
end
|
63
63
|
end
|
64
64
|
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe Sha256Calculator do
|
5
|
+
|
6
|
+
context '#use' do
|
7
|
+
it 'adds check sum to file' do
|
8
|
+
test_file = create_file('file.html', 'data')
|
9
|
+
checksum = Digest::SHA256.hexdigest 'data'
|
10
|
+
|
11
|
+
file = double 'file'
|
12
|
+
expect(file).to receive(:path).and_return(test_file)
|
13
|
+
expect(file).to receive(:checksum=) do |arg|
|
14
|
+
expect(arg.algorithm).to eq(:sha256)
|
15
|
+
expect(arg.value).to eq(checksum)
|
16
|
+
end
|
17
|
+
|
18
|
+
detector = Sha256Calculator.new
|
19
|
+
detector.use file
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'adds error message to file' do
|
23
|
+
test_file = SecureRandom.hex
|
24
|
+
|
25
|
+
file = double 'file'
|
26
|
+
allow(file).to receive(:path).and_return(test_file)
|
27
|
+
allow(file).to receive(:name).and_return(File.basename(test_file))
|
28
|
+
expect(file).to receive(:checksum=) do |arg|
|
29
|
+
expect(arg.value).to eq("An error occured while determine checksum for \"#{test_file}\".")
|
30
|
+
end
|
31
|
+
|
32
|
+
detector = Sha256Calculator.new
|
33
|
+
detector.use file
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -16,6 +16,8 @@ require 'test_server'
|
|
16
16
|
|
17
17
|
# Loading support files
|
18
18
|
Dir.glob(::File.expand_path('../support/*.rb', __FILE__)).each { |f| require_relative f }
|
19
|
+
# Loading shared examples
|
20
|
+
Dir.glob(::File.expand_path('../shared_examples/**/*.rb', __FILE__)).each { |f| require_relative f }
|
19
21
|
|
20
22
|
include TestServer
|
21
23
|
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'fedux_org/stdlib/command/which'
|
3
|
+
|
4
|
+
module TestServer
|
5
|
+
module SpecHelper
|
6
|
+
module Commands
|
7
|
+
include ::FeduxOrg::Stdlib::Command::Which
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
RSpec.configure do |c|
|
13
|
+
c.include TestServer::SpecHelper::Commands
|
14
|
+
end
|
15
|
+
|
data/spec/support/debugging.rb
CHANGED
@@ -0,0 +1,15 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module TestServer
|
3
|
+
module SpecHelper
|
4
|
+
module Eicar
|
5
|
+
def eicar_test_string
|
6
|
+
%w{X 5 O ! P % @ A P [ 4 \\ P Z X 5 4 ( P ^ ) 7 C C ) 7 \} $ E I C A R - S T A N D A R D - A N T I V I R U S - T E S T - F I L E ! $ H + H * }.join
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
RSpec.configure do |c|
|
13
|
+
c.include TestServer::SpecHelper::Eicar
|
14
|
+
end
|
15
|
+
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module TestServer
|
4
|
+
module SpecHelper
|
5
|
+
module Fixtures
|
6
|
+
def fixture_file(name)
|
7
|
+
File.new(File.expand_path("../../fixtures/#{name}", __FILE__))
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
RSpec.configure do |c|
|
14
|
+
c.include TestServer::SpecHelper::Fixtures
|
15
|
+
end
|
16
|
+
|
data/spec/support/rails.rb
CHANGED
@@ -0,0 +1,167 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe UploadedFile do
|
5
|
+
context '#initialize' do
|
6
|
+
it 'requires an uploaded file' do
|
7
|
+
uploaded_file = double('ActionDispatch::Http::UploadedFile')
|
8
|
+
allow(uploaded_file).to receive(:tempfile)
|
9
|
+
|
10
|
+
UploadedFile.new(uploaded_file)
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'handles empty string' do
|
14
|
+
expect {
|
15
|
+
UploadedFile.new('')
|
16
|
+
}.not_to raise_error
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
context '#path' do
|
21
|
+
it 'returns path for uploaded file' do
|
22
|
+
uploaded_file = double('ActionDispatch::Http::UploadedFile')
|
23
|
+
allow(uploaded_file).to receive(:tempfile)
|
24
|
+
allow(uploaded_file).to receive(:path).and_return('/tmp/filename.png')
|
25
|
+
|
26
|
+
file = UploadedFile.new(uploaded_file)
|
27
|
+
expect(file.path).to eq('/tmp/filename.png')
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
context '#name' do
|
32
|
+
it 'returns basename for uploaded file' do
|
33
|
+
uploaded_file = double('ActionDispatch::Http::UploadedFile')
|
34
|
+
allow(uploaded_file).to receive(:tempfile)
|
35
|
+
allow(uploaded_file).to receive(:original_filename).and_return('filename.png')
|
36
|
+
|
37
|
+
file = UploadedFile.new(uploaded_file)
|
38
|
+
expect(file.name).to eq('filename.png')
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
context '#contains_virus?' do
|
43
|
+
it 'is false if does not contain virus' do
|
44
|
+
uploaded_file = double('ActionDispatch::Http::UploadedFile')
|
45
|
+
allow(uploaded_file).to receive(:tempfile)
|
46
|
+
|
47
|
+
file = UploadedFile.new(uploaded_file)
|
48
|
+
expect(file.contains_virus?).to be_falsey
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
context '#virus_id' do
|
53
|
+
it 'sets a virus id' do
|
54
|
+
uploaded_file = double('ActionDispatch::Http::UploadedFile')
|
55
|
+
allow(uploaded_file).to receive(:tempfile)
|
56
|
+
|
57
|
+
file = UploadedFile.new(uploaded_file)
|
58
|
+
|
59
|
+
expect {
|
60
|
+
file.virus_id = 'EICAR'
|
61
|
+
}.not_to raise_error
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'returns a virus id' do
|
65
|
+
uploaded_file = double('ActionDispatch::Http::UploadedFile')
|
66
|
+
allow(uploaded_file).to receive(:tempfile)
|
67
|
+
|
68
|
+
file = UploadedFile.new(uploaded_file)
|
69
|
+
file.virus_id = 'EICAR'
|
70
|
+
|
71
|
+
expect(file.virus_id).to eq 'EICAR'
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
context '#has_filetype?' do
|
76
|
+
it 'is false if has no filetype' do
|
77
|
+
uploaded_file = double('ActionDispatch::Http::UploadedFile')
|
78
|
+
allow(uploaded_file).to receive(:tempfile)
|
79
|
+
|
80
|
+
file = UploadedFile.new(uploaded_file)
|
81
|
+
expect(file.has_filetype?).to be_falsey
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
context '#filetype' do
|
86
|
+
it 'sets a filetype' do
|
87
|
+
uploaded_file = double('ActionDispatch::Http::UploadedFile')
|
88
|
+
allow(uploaded_file).to receive(:tempfile)
|
89
|
+
|
90
|
+
file = UploadedFile.new(uploaded_file)
|
91
|
+
|
92
|
+
expect {
|
93
|
+
file.filetype = 'Text'
|
94
|
+
}.not_to raise_error
|
95
|
+
end
|
96
|
+
|
97
|
+
it 'returns a filetype' do
|
98
|
+
uploaded_file = double('ActionDispatch::Http::UploadedFile')
|
99
|
+
allow(uploaded_file).to receive(:tempfile)
|
100
|
+
|
101
|
+
file = UploadedFile.new(uploaded_file)
|
102
|
+
file.filetype = 'Text'
|
103
|
+
|
104
|
+
expect(file.filetype).to eq 'Text'
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
context '#checksum=' do
|
109
|
+
it 'sets the checksum for file' do
|
110
|
+
uploaded_file = double('ActionDispatch::Http::UploadedFile')
|
111
|
+
allow(uploaded_file).to receive(:tempfile)
|
112
|
+
|
113
|
+
file = UploadedFile.new(uploaded_file)
|
114
|
+
|
115
|
+
expect {
|
116
|
+
file.checksum = Digest::SHA256.hexdigest 'message'
|
117
|
+
}.not_to raise_error
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
context '#checksum' do
|
122
|
+
it 'returns checksum hash for content' do
|
123
|
+
uploaded_file = double('ActionDispatch::Http::UploadedFile')
|
124
|
+
allow(uploaded_file).to receive(:tempfile)
|
125
|
+
|
126
|
+
checksum = Digest::SHA256.hexdigest 'message'
|
127
|
+
|
128
|
+
file = UploadedFile.new(uploaded_file)
|
129
|
+
file.checksum = checksum
|
130
|
+
|
131
|
+
expect(file.checksum.first).to eq(checksum)
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
context '#has_checksum' do
|
136
|
+
it 'is false if has no checksum' do
|
137
|
+
uploaded_file = double('ActionDispatch::Http::UploadedFile')
|
138
|
+
allow(uploaded_file).to receive(:tempfile)
|
139
|
+
|
140
|
+
file = UploadedFile.new(uploaded_file)
|
141
|
+
expect(file.has_checksum?).to be_falsey
|
142
|
+
end
|
143
|
+
|
144
|
+
it 'is true if has a checksum' do
|
145
|
+
uploaded_file = double('ActionDispatch::Http::UploadedFile')
|
146
|
+
allow(uploaded_file).to receive(:tempfile)
|
147
|
+
|
148
|
+
file = UploadedFile.new(uploaded_file)
|
149
|
+
file.checksum = Digest::SHA256.hexdigest 'message'
|
150
|
+
expect(file.has_checksum?).to be_truthy
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
context '#size' do
|
155
|
+
it 'returns the file size' do
|
156
|
+
uploaded_file = double('ActionDispatch::Http::UploadedFile')
|
157
|
+
allow(uploaded_file).to receive(:tempfile)
|
158
|
+
allow(uploaded_file).to receive(:size).and_return 4294967296
|
159
|
+
|
160
|
+
file = UploadedFile.new(uploaded_file)
|
161
|
+
expect(file.size[:b].value).to eq('4294967296')
|
162
|
+
expect(file.size[:kib].value).to eq('4194304.00')
|
163
|
+
expect(file.size[:mib].value).to eq('4096.00')
|
164
|
+
expect(file.size[:gib].value).to eq('4.00')
|
165
|
+
end
|
166
|
+
end
|
167
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe "file_uploader/index.html.haml" do
|
5
|
+
before :each do
|
6
|
+
config = Class.new do
|
7
|
+
include FeduxOrg::Stdlib::Filesystem
|
8
|
+
|
9
|
+
def root_directory
|
10
|
+
::File.expand_path('../../../', __FILE__)
|
11
|
+
end
|
12
|
+
|
13
|
+
def log_level
|
14
|
+
:unknown
|
15
|
+
end
|
16
|
+
|
17
|
+
def access_log
|
18
|
+
File.join(working_directory, 'access.log')
|
19
|
+
end
|
20
|
+
end.new
|
21
|
+
|
22
|
+
TestServer.config = config
|
23
|
+
end
|
24
|
+
|
25
|
+
context 'Upload files' do
|
26
|
+
it 'lists links to all other test functions' do
|
27
|
+
visit '/file_uploader/'
|
28
|
+
|
29
|
+
expect(page).to have_content 'Upload file'
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|