sbsm 1.5.6 → 1.5.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b2938a44d2cbad70bde08139096f8578c00cb635
4
- data.tar.gz: ffef6523d8bcdae0ea1d9b1b553c704c1da2de66
3
+ metadata.gz: d5121512c837227a27ac5adae0dc1f1264a20829
4
+ data.tar.gz: 9088b0ec0826c8013ef29ac9e17befea18de4d4d
5
5
  SHA512:
6
- metadata.gz: 22b3f3a5ef861c0737eb309f77820f722ca88076913c9b99ee9c409db66832f57c9d656b50aa5c0716d24b73de9fcfa8994052692523ff22d475fea1d6ef4c30
7
- data.tar.gz: 3e7225581937bf52e25000c34525e58565d9d85c1514b610508784f607de82abdd065d933fb56ff92cdd4b27cb86310c3da712ecad9f300fb422976c16244381
6
+ metadata.gz: eda614acaf8ca9a2c2fb2678f613868dd7be9364db124182e6992bfb9d514b51f035eedb832147920d98f203740d7759775486147dd93d7062b1c9471a603b33
7
+ data.tar.gz: 492ff66f7b38b7f78eb66328056102706f0094b524724e515b84d6ddafdffa781b64d32e9eadb473eda03a852af055dc4151d78f59151ab95e1d18369627bc06
@@ -1,3 +1,7 @@
1
+ === 1.5.7 / 8.08.2017
2
+
3
+ * Return nice 404 error for non existing files
4
+
1
5
  === 1.5.6 / 12.07.2017
2
6
 
3
7
  * Handle several IPs in X_FORWARDED_FOR
@@ -127,15 +127,17 @@ module SBSM
127
127
  res = session.process_rack(rack_request: request)
128
128
  thru = session.get_passthru
129
129
  if thru.size > 0
130
- file_name = thru.first.untaint
131
- response.set_header('Content-Type', MimeMagic.by_extension(File.extname(file_name)).type)
132
- response.headers['Content-Disposition'] = "#{thru.last}; filename=#{File.basename(file_name)}"
133
- response.headers['Content-Length'] = File.size(file_name).to_s
134
130
  begin
131
+ file_name = thru.first.untaint
132
+ raise Errno::ENOENT unless File.exist?(file_name)
133
+ response.set_header('Content-Type', MimeMagic.by_extension(File.extname(file_name)).type)
134
+ response.headers['Content-Disposition'] = "#{thru.last}; filename=#{File.basename(file_name)}"
135
+ response.headers['Content-Length'] = File.size(file_name).to_s
135
136
  response.write(File.open(file_name, File::RDONLY){|file| file.read})
136
137
  rescue Errno::ENOENT, IOError => err
137
- SBSM.error("#{err.message} #{thru.first}")
138
- return [404, {}, []]
138
+ error_msg = "#{file_name} Not found\n"
139
+ SBSM.error("#{err.message} #{thru.first} => #{error_msg}")
140
+ return [404, {'Content-Type' => 'text/html', 'Content-Length' => error_msg.size.to_s}, [error_msg]]
139
141
  end
140
142
  else
141
143
  response.write res unless request.request_method.eql?('HEAD')
@@ -1,3 +1,3 @@
1
1
  module SBSM
2
- VERSION = '1.5.6'
2
+ VERSION = '1.5.7'
3
3
  end
@@ -7,6 +7,7 @@ ENV['RACK_ENV'] = 'test'
7
7
  ENV['REQUEST_METHOD'] = 'GET'
8
8
 
9
9
  require 'minitest/autorun'
10
+ require 'flexmock/minitest'
10
11
  require 'rack/test'
11
12
  require 'sbsm/app'
12
13
  require 'sbsm/session'
@@ -55,6 +56,25 @@ class AppVariantTest < Minitest::Test
55
56
  assert last_response.body.empty?
56
57
  assert last_response.headers.keys.index('Content-Type')
57
58
  end
59
+ def test_request_file
60
+ session_id_mock = '1234'
61
+ invalid_path = '/path/to/non/existing/file'
62
+
63
+ @app = flexmock('file_app', @app)
64
+ env = { 'HTTP_COOKIE' => "_session_id=#{session_id_mock}" }
65
+ session_store = SBSM::SessionStore.new(app: @app)
66
+ session_mock= flexmock('session', session_store[session_id_mock.to_s])
67
+ session_mock.should_receive(:get_passthru).and_return([invalid_path])
68
+ @app.should_receive(:session_store).and_return(session_store)
69
+
70
+ result = get invalid_path, {}, env
71
+
72
+ assert_equal(false, last_response.ok?)
73
+ assert_equal(404, last_response.status)
74
+ assert (last_response.body.to_s.index(invalid_path))
75
+ assert last_response.headers.keys.index('Content-Type')
76
+ assert_equal('text/html', last_response.headers['Content-Type'])
77
+ end
58
78
  end
59
79
 
60
80
  class AppTestSimple < Minitest::Test
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sbsm
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.6
4
+ version: 1.5.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Masaomi Hatakeyama, Zeno R.R. Davatz
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-07-12 00:00:00.000000000 Z
11
+ date: 2017-08-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack