rack-logs 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -1
- data/lib/rack/logs/version.rb +1 -1
- data/lib/rack/logs/viewer.rb +16 -5
- data/rack-logs.gemspec +0 -1
- data/spec/integration/accessing_an_individual_log_spec.rb +39 -0
- data/spec/integration/running_rack_logs_via_rack_spec.rb +2 -5
- data/spec/spec_helper.rb +10 -0
- data/spec/support/fixtures/log/my_log.doge +6 -0
- data/spec/support/fixtures/log/not_log.txt +1 -0
- data/spec/support/fixtures/log/other_log.doge +6 -0
- data/spec/support/fixtures/tmp/secret_file.txt +1 -0
- data/spec/unit/rack/logs/viewer_spec.rb +49 -26
- metadata +12 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 38f658a84c8b8956be836e3812a3a8362ee03f7d
|
4
|
+
data.tar.gz: c0e31cdcd0de005e773eb4aeaa00f6eb276f0e44
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7a952da98a94f7af5c0a2fd66483d60d0684e33d9c3bef6519c96eba97749afaa9b11b6824aa8fba194358f864d774db0b8dbcee261af6fc35afaf1374df47e9
|
7
|
+
data.tar.gz: 72b85e5be9e67ebd24e42b44726886236721816b46e7e0073992d1339ff9452b3fd5dacd8ddc1fff14b0656494c471b64adc7ac5f540ec7690778c6caba06afe
|
data/.gitignore
CHANGED
data/lib/rack/logs/version.rb
CHANGED
data/lib/rack/logs/viewer.rb
CHANGED
@@ -8,7 +8,12 @@ module Rack
|
|
8
8
|
attr_reader :config
|
9
9
|
|
10
10
|
def call env
|
11
|
-
|
11
|
+
contents = joined_logs(env.fetch('PATH_INFO','/'))
|
12
|
+
if contents.empty?
|
13
|
+
[404, headers, ['No Such File']]
|
14
|
+
else
|
15
|
+
[200, headers, contents]
|
16
|
+
end
|
12
17
|
end
|
13
18
|
|
14
19
|
private
|
@@ -27,6 +32,10 @@ module Rack
|
|
27
32
|
@lines = lines
|
28
33
|
end
|
29
34
|
|
35
|
+
def empty?
|
36
|
+
@filenames.empty?
|
37
|
+
end
|
38
|
+
|
30
39
|
def each &block
|
31
40
|
@filenames.each do |filename|
|
32
41
|
block.call "## #{filename}\n\n"
|
@@ -46,8 +55,8 @@ module Rack
|
|
46
55
|
end
|
47
56
|
end
|
48
57
|
|
49
|
-
def joined_logs
|
50
|
-
JoinedFiles.new files, @config.lines
|
58
|
+
def joined_logs path
|
59
|
+
JoinedFiles.new files(path), @config.lines
|
51
60
|
end
|
52
61
|
|
53
62
|
def logs
|
@@ -57,8 +66,10 @@ module Rack
|
|
57
66
|
end
|
58
67
|
end
|
59
68
|
|
60
|
-
def files
|
61
|
-
Dir[@config.log_dir+'/'+@config.pattern]
|
69
|
+
def files path
|
70
|
+
Dir[@config.log_dir+'/'+@config.pattern].select do |filename|
|
71
|
+
filename =~ Regexp.new( @config.log_dir + path )
|
72
|
+
end
|
62
73
|
end
|
63
74
|
|
64
75
|
end
|
data/rack-logs.gemspec
CHANGED
@@ -21,7 +21,6 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.add_runtime_dependency "rack", "~> 1.5.2"
|
22
22
|
|
23
23
|
spec.add_development_dependency "bundler", "~> 1.3"
|
24
|
-
spec.add_development_dependency "fakefs"
|
25
24
|
spec.add_development_dependency "rake"
|
26
25
|
spec.add_development_dependency "rack-test"
|
27
26
|
spec.add_development_dependency "rspec", "~> 3.0.0.beta1"
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'rack/test'
|
2
|
+
require 'rack/logs'
|
3
|
+
|
4
|
+
describe 'accessing an individual log', type: :integration do
|
5
|
+
include Rack::Test::Methods
|
6
|
+
|
7
|
+
let(:app) do
|
8
|
+
Rack::Builder.app do
|
9
|
+
logs = Rack::Logs.configure do |config|
|
10
|
+
config.log_dir = './tmp'
|
11
|
+
end
|
12
|
+
run logs
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
before do
|
17
|
+
File.open('./tmp/my_log_file.log','w') do |f|
|
18
|
+
f.write "LOG ENTRY 1234"
|
19
|
+
end
|
20
|
+
File.open('./tmp/other_file.log','w') do |f|
|
21
|
+
f.write "LOG ENTRY 5678"
|
22
|
+
end
|
23
|
+
get '/my_log_file.log'
|
24
|
+
end
|
25
|
+
|
26
|
+
example 'returns a 200 response code' do
|
27
|
+
expect(last_response).to be_ok
|
28
|
+
end
|
29
|
+
|
30
|
+
example 'accessing the log returns only the specific log contents' do
|
31
|
+
expect(last_response.body).to match 'LOG ENTRY 1234'
|
32
|
+
expect(last_response.body).to_not match 'LOG ENTRY 5678'
|
33
|
+
end
|
34
|
+
|
35
|
+
example 'cross path traversal is prevented' do
|
36
|
+
get "/../tmp/secret_file.txt"
|
37
|
+
expect(last_response.status).to be 404
|
38
|
+
end
|
39
|
+
end
|
@@ -9,11 +9,8 @@ describe 'running `Rack::Logs` via `Rack::Builder`', type: :integration do
|
|
9
9
|
|
10
10
|
before { get '/' }
|
11
11
|
|
12
|
-
example 'returns a
|
13
|
-
expect(last_response).to
|
14
|
-
end
|
15
|
-
example 'returns no logs because there are no files' do
|
16
|
-
expect(last_response.body).to eq ''
|
12
|
+
example 'returns a 404 response code because there are no files' do
|
13
|
+
expect(last_response.status).to eq 404
|
17
14
|
end
|
18
15
|
end
|
19
16
|
|
data/spec/spec_helper.rb
CHANGED
@@ -0,0 +1 @@
|
|
1
|
+
Nothing to see here
|
@@ -0,0 +1 @@
|
|
1
|
+
S3kr1t!
|
@@ -1,8 +1,10 @@
|
|
1
|
-
require 'fakefs/safe'
|
2
1
|
require 'rack/logs/viewer'
|
3
2
|
|
4
3
|
describe 'Rack::Logs::Viewer' do
|
5
|
-
let(:config)
|
4
|
+
let(:config) do
|
5
|
+
instance_double "Rack::Logs::Config", lines: 5, pattern: '*.doge',
|
6
|
+
log_dir: support_path('fixtures/log')
|
7
|
+
end
|
6
8
|
|
7
9
|
describe '#initialize' do
|
8
10
|
it 'takes a configuration' do
|
@@ -12,37 +14,58 @@ describe 'Rack::Logs::Viewer' do
|
|
12
14
|
|
13
15
|
describe '#call env' do
|
14
16
|
let(:viewer) { Rack::Logs::Viewer.new config }
|
15
|
-
let(:response) { viewer.call({}) }
|
16
17
|
let(:contents) { response[2].inject("") { |contents, fragment| contents + fragment } }
|
17
18
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
19
|
+
shared_examples_for "a rack logs response" do
|
20
|
+
it 'returns a rack response' do
|
21
|
+
expect(response[0]).to be_a Fixnum
|
22
|
+
expect(response[1]).to be_a Hash
|
23
|
+
expect(response[1].keys).to include 'Content-Type'
|
24
|
+
expect(response[2].respond_to? :each).to be true
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'limits itself to the last n lines' do
|
28
|
+
expect(contents).to_not match "Ignored"
|
28
29
|
end
|
29
|
-
end
|
30
|
-
after do
|
31
|
-
FakeFS.deactivate!
|
32
30
|
end
|
33
31
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
32
|
+
context "for all files" do
|
33
|
+
let(:response) { viewer.call({}) }
|
34
|
+
|
35
|
+
it_should_behave_like "a rack logs response"
|
36
|
+
|
37
|
+
it 'returns the contents of all the logs' do
|
38
|
+
expect(contents).to match "log/my_log\.doge\n\n"
|
39
|
+
expect(contents).to match "Much log, such information"
|
40
|
+
expect(contents).to match "log/other_log\.doge\n\n"
|
41
|
+
expect(contents).to match "Other log, such information"
|
42
|
+
end
|
39
43
|
end
|
40
|
-
|
41
|
-
|
42
|
-
|
44
|
+
|
45
|
+
context "for a file" do
|
46
|
+
let(:response) { viewer.call({ 'PATH_INFO' => '/my_log.doge' }) }
|
47
|
+
|
48
|
+
it_should_behave_like "a rack logs response"
|
49
|
+
|
50
|
+
it 'returns the contents the specific log' do
|
51
|
+
expect(contents).to match "log/my_log\.doge\n\n"
|
52
|
+
expect(contents).to match "Much log, such information"
|
53
|
+
end
|
54
|
+
it 'ignores other contents' do
|
55
|
+
expect(contents).to_not match "log/other_log\.doge\n\n"
|
56
|
+
expect(contents).to_not match "Other log, such information"
|
57
|
+
end
|
43
58
|
end
|
44
|
-
|
45
|
-
|
59
|
+
|
60
|
+
context "for a forbidden file" do
|
61
|
+
let(:response) { viewer.call({ 'PATH_INFO' => '/../tmp/secret_file.txt' }) }
|
62
|
+
|
63
|
+
it 'returns a 404 rack response' do
|
64
|
+
expect(response[0]).to eq 404
|
65
|
+
expect(response[1]).to be_a Hash
|
66
|
+
expect(response[1].keys).to include 'Content-Type'
|
67
|
+
expect(response[2]).to eq ['No Such File']
|
68
|
+
end
|
46
69
|
end
|
47
70
|
end
|
48
71
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-logs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jon Rowe
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-01-
|
11
|
+
date: 2014-01-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|
@@ -38,20 +38,6 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '1.3'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: fakefs
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - ">="
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '0'
|
48
|
-
type: :development
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - ">="
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '0'
|
55
41
|
- !ruby/object:Gem::Dependency
|
56
42
|
name: rake
|
57
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -114,8 +100,13 @@ files:
|
|
114
100
|
- lib/rack/logs/version.rb
|
115
101
|
- lib/rack/logs/viewer.rb
|
116
102
|
- rack-logs.gemspec
|
103
|
+
- spec/integration/accessing_an_individual_log_spec.rb
|
117
104
|
- spec/integration/running_rack_logs_via_rack_spec.rb
|
118
105
|
- spec/spec_helper.rb
|
106
|
+
- spec/support/fixtures/log/my_log.doge
|
107
|
+
- spec/support/fixtures/log/not_log.txt
|
108
|
+
- spec/support/fixtures/log/other_log.doge
|
109
|
+
- spec/support/fixtures/tmp/secret_file.txt
|
119
110
|
- spec/unit/rack/logs/config_spec.rb
|
120
111
|
- spec/unit/rack/logs/viewer_spec.rb
|
121
112
|
- spec/unit/rack/logs_spec.rb
|
@@ -145,8 +136,13 @@ signing_key:
|
|
145
136
|
specification_version: 4
|
146
137
|
summary: Simple rack based log viewer
|
147
138
|
test_files:
|
139
|
+
- spec/integration/accessing_an_individual_log_spec.rb
|
148
140
|
- spec/integration/running_rack_logs_via_rack_spec.rb
|
149
141
|
- spec/spec_helper.rb
|
142
|
+
- spec/support/fixtures/log/my_log.doge
|
143
|
+
- spec/support/fixtures/log/not_log.txt
|
144
|
+
- spec/support/fixtures/log/other_log.doge
|
145
|
+
- spec/support/fixtures/tmp/secret_file.txt
|
150
146
|
- spec/unit/rack/logs/config_spec.rb
|
151
147
|
- spec/unit/rack/logs/viewer_spec.rb
|
152
148
|
- spec/unit/rack/logs_spec.rb
|