rack-logs 0.0.2 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +1 -1
- data/.travis.yml +9 -6
- data/lib/rack/logs.rb +4 -0
- data/lib/rack/logs/backport.rb +7 -0
- data/lib/rack/logs/config.rb +2 -1
- data/lib/rack/logs/version.rb +1 -1
- data/lib/rack/logs/viewer.rb +46 -7
- data/rack-logs.gemspec +17 -5
- data/spec/integration/accessing_an_individual_log_spec.rb +34 -0
- data/spec/integration/running_rack_logs_via_rack_spec.rb +4 -9
- data/spec/spec_helper.rb +10 -0
- data/spec/support/fixtures/log/large_log.doge +14999 -0
- data/spec/support/fixtures/log/my_log.doge +6 -0
- data/spec/support/fixtures/log/my_log_file.log +1 -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/other_log_file.log +1 -0
- data/spec/support/fixtures/tmp/secret_file.txt +1 -0
- data/spec/unit/rack/logs/config_spec.rb +10 -0
- data/spec/unit/rack/logs/viewer_spec.rb +66 -20
- metadata +28 -26
@@ -0,0 +1 @@
|
|
1
|
+
LOG ENTRY 1234
|
@@ -0,0 +1 @@
|
|
1
|
+
Nothing to see here
|
@@ -0,0 +1 @@
|
|
1
|
+
LOG ENTRY 5678
|
@@ -0,0 +1 @@
|
|
1
|
+
S3kr1t!
|
@@ -22,4 +22,14 @@ describe 'Rack::Logs::Config' do
|
|
22
22
|
expect(config.pattern).to eq '*.doge'
|
23
23
|
end
|
24
24
|
end
|
25
|
+
|
26
|
+
describe '#lines' do
|
27
|
+
it 'defaults to 200' do
|
28
|
+
expect(config.lines).to eq 200
|
29
|
+
end
|
30
|
+
it 'is configurable' do
|
31
|
+
config.lines = 300
|
32
|
+
expect(config.lines).to eq 300
|
33
|
+
end
|
34
|
+
end
|
25
35
|
end
|
@@ -1,8 +1,11 @@
|
|
1
|
-
require '
|
1
|
+
require 'timeout'
|
2
2
|
require 'rack/logs/viewer'
|
3
3
|
|
4
4
|
describe 'Rack::Logs::Viewer' do
|
5
|
-
let(:config)
|
5
|
+
let(:config) do
|
6
|
+
instance_double "Rack::Logs::Config", lines: 5, pattern: '*.doge',
|
7
|
+
log_dir: support_path('fixtures/log')
|
8
|
+
end
|
6
9
|
|
7
10
|
describe '#initialize' do
|
8
11
|
it 'takes a configuration' do
|
@@ -12,30 +15,73 @@ describe 'Rack::Logs::Viewer' do
|
|
12
15
|
|
13
16
|
describe '#call env' do
|
14
17
|
let(:viewer) { Rack::Logs::Viewer.new config }
|
15
|
-
let(:
|
18
|
+
let(:contents) { response[2].inject("") { |contents, fragment| contents + fragment } }
|
16
19
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
20
|
+
around do |example|
|
21
|
+
begin
|
22
|
+
Timeout::timeout(0.01) { example.run }
|
23
|
+
rescue Timeout::Error
|
24
|
+
fail "Performance regression, even large files should be under .01s"
|
25
|
+
end
|
22
26
|
end
|
23
|
-
|
24
|
-
|
27
|
+
|
28
|
+
shared_examples_for "a rack logs response" do
|
29
|
+
integer_const =
|
30
|
+
if ENV["RUBY_VERSION"].to_f >= 2.4
|
31
|
+
Integer
|
32
|
+
else
|
33
|
+
Fixnum
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'returns a rack response' do
|
37
|
+
expect(response[0]).to be_a integer_const
|
38
|
+
expect(response[1]).to be_a Hash
|
39
|
+
expect(response[1].keys).to include 'Content-Type'
|
40
|
+
expect(response[2].respond_to? :each).to be true
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'limits itself to the last n lines' do
|
44
|
+
expect(contents).to_not match "Ignored"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
context "for all files" do
|
49
|
+
let(:response) { viewer.call({}) }
|
50
|
+
|
51
|
+
it_should_behave_like "a rack logs response"
|
52
|
+
|
53
|
+
it 'returns the contents of all the logs' do
|
54
|
+
expect(contents).to match "log/my_log\.doge\n\n"
|
55
|
+
expect(contents).to match "Much log, such information"
|
56
|
+
expect(contents).to match "log/other_log\.doge\n\n"
|
57
|
+
expect(contents).to match "Other log, such information"
|
58
|
+
end
|
25
59
|
end
|
26
60
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
61
|
+
context "for a file" do
|
62
|
+
let(:response) { viewer.call({ 'PATH_INFO' => '/my_log.doge' }) }
|
63
|
+
|
64
|
+
it_should_behave_like "a rack logs response"
|
65
|
+
|
66
|
+
it 'returns the contents the specific log' do
|
67
|
+
expect(contents).to match "log/my_log\.doge\n\n"
|
68
|
+
expect(contents).to match "Much log, such information"
|
69
|
+
end
|
70
|
+
it 'ignores other contents' do
|
71
|
+
expect(contents).to_not match "log/other_log\.doge\n\n"
|
72
|
+
expect(contents).to_not match "Other log, such information"
|
73
|
+
end
|
32
74
|
end
|
33
|
-
|
34
|
-
|
35
|
-
response
|
36
|
-
|
75
|
+
|
76
|
+
context "for a forbidden file" do
|
77
|
+
let(:response) { viewer.call({ 'PATH_INFO' => '/../tmp/secret_file.txt' }) }
|
78
|
+
|
79
|
+
it 'returns a 404 rack response' do
|
80
|
+
expect(response[0]).to eq 404
|
81
|
+
expect(response[1]).to be_a Hash
|
82
|
+
expect(response[1].keys).to include 'Content-Type'
|
83
|
+
expect(response[2]).to eq ['No Such File']
|
37
84
|
end
|
38
|
-
expect(contents).to eq "## tmp/my_log.doge\n\nMuch log, such information"
|
39
85
|
end
|
40
86
|
end
|
41
87
|
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.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jon Rowe
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-07-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|
@@ -16,44 +16,30 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 2.2.3
|
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: 2.2.3
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 13.0.0
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: 13.0.0
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
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
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: rake
|
42
|
+
name: bundler
|
57
43
|
requirement: !ruby/object:Gem::Requirement
|
58
44
|
requirements:
|
59
45
|
- - ">="
|
@@ -86,14 +72,14 @@ dependencies:
|
|
86
72
|
requirements:
|
87
73
|
- - "~>"
|
88
74
|
- !ruby/object:Gem::Version
|
89
|
-
version: 3.
|
75
|
+
version: 3.9.0
|
90
76
|
type: :development
|
91
77
|
prerelease: false
|
92
78
|
version_requirements: !ruby/object:Gem::Requirement
|
93
79
|
requirements:
|
94
80
|
- - "~>"
|
95
81
|
- !ruby/object:Gem::Version
|
96
|
-
version: 3.
|
82
|
+
version: 3.9.0
|
97
83
|
description: Simple rack based log viewer
|
98
84
|
email:
|
99
85
|
- hello@jonrowe.co.uk
|
@@ -110,12 +96,21 @@ files:
|
|
110
96
|
- Rakefile
|
111
97
|
- lib/rack-logs.rb
|
112
98
|
- lib/rack/logs.rb
|
99
|
+
- lib/rack/logs/backport.rb
|
113
100
|
- lib/rack/logs/config.rb
|
114
101
|
- lib/rack/logs/version.rb
|
115
102
|
- lib/rack/logs/viewer.rb
|
116
103
|
- rack-logs.gemspec
|
104
|
+
- spec/integration/accessing_an_individual_log_spec.rb
|
117
105
|
- spec/integration/running_rack_logs_via_rack_spec.rb
|
118
106
|
- spec/spec_helper.rb
|
107
|
+
- spec/support/fixtures/log/large_log.doge
|
108
|
+
- spec/support/fixtures/log/my_log.doge
|
109
|
+
- spec/support/fixtures/log/my_log_file.log
|
110
|
+
- spec/support/fixtures/log/not_log.txt
|
111
|
+
- spec/support/fixtures/log/other_log.doge
|
112
|
+
- spec/support/fixtures/other_log_file.log
|
113
|
+
- spec/support/fixtures/tmp/secret_file.txt
|
119
114
|
- spec/unit/rack/logs/config_spec.rb
|
120
115
|
- spec/unit/rack/logs/viewer_spec.rb
|
121
116
|
- spec/unit/rack/logs_spec.rb
|
@@ -139,14 +134,21 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
139
134
|
- !ruby/object:Gem::Version
|
140
135
|
version: '0'
|
141
136
|
requirements: []
|
142
|
-
|
143
|
-
rubygems_version: 2.2.0
|
137
|
+
rubygems_version: 3.1.3
|
144
138
|
signing_key:
|
145
139
|
specification_version: 4
|
146
140
|
summary: Simple rack based log viewer
|
147
141
|
test_files:
|
142
|
+
- spec/integration/accessing_an_individual_log_spec.rb
|
148
143
|
- spec/integration/running_rack_logs_via_rack_spec.rb
|
149
144
|
- spec/spec_helper.rb
|
145
|
+
- spec/support/fixtures/log/large_log.doge
|
146
|
+
- spec/support/fixtures/log/my_log.doge
|
147
|
+
- spec/support/fixtures/log/my_log_file.log
|
148
|
+
- spec/support/fixtures/log/not_log.txt
|
149
|
+
- spec/support/fixtures/log/other_log.doge
|
150
|
+
- spec/support/fixtures/other_log_file.log
|
151
|
+
- spec/support/fixtures/tmp/secret_file.txt
|
150
152
|
- spec/unit/rack/logs/config_spec.rb
|
151
153
|
- spec/unit/rack/logs/viewer_spec.rb
|
152
154
|
- spec/unit/rack/logs_spec.rb
|