party_foul 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +3 -0
- data/lib/generators/party_foul/install_generator.rb +5 -12
- data/lib/generators/party_foul/templates/party_foul.rb +8 -5
- data/lib/party_foul.rb +2 -1
- data/lib/party_foul/exception_handler.rb +18 -2
- data/lib/party_foul/version.rb +1 -1
- data/test/generator_test.rb +1 -2
- data/test/party_foul/exception_handler_test.rb +35 -7
- data/test/test_helper.rb +1 -1
- data/test/tmp/config/initializers/party_foul.rb +8 -5
- metadata +3 -3
data/README.md
CHANGED
@@ -69,6 +69,9 @@ PartyFoul.configure do |config|
|
|
69
69
|
# The constants here *must* be represented as strings
|
70
70
|
config.ignored_exceptions = ['ActiveRecord::RecordNotFound', 'ActionController::RoutingError']
|
71
71
|
|
72
|
+
# The names of the HTTP headers to not report
|
73
|
+
config.filtered_http_headers = ['Cookie']
|
74
|
+
|
72
75
|
# The OAuth token for the account that will be opening the issues on Github
|
73
76
|
config.oauth_token = 'abcdefgh1234567890'
|
74
77
|
|
@@ -7,22 +7,15 @@ module PartyFoul
|
|
7
7
|
source_root File.expand_path('../templates', __FILE__)
|
8
8
|
|
9
9
|
def create_initializer_file
|
10
|
-
|
11
|
-
password
|
12
|
-
|
13
|
-
end
|
14
|
-
|
15
|
-
say ''
|
16
|
-
|
17
|
-
@owner = ask_with_default 'Repository owner:', username
|
10
|
+
login = ask 'Github login:'
|
11
|
+
password = STDIN.noecho { ask 'Github password:' }
|
12
|
+
@owner = ask_with_default "\nRepository owner:", login
|
18
13
|
@repo = ask 'Repository name:'
|
19
14
|
@endpoint = ask_with_default 'Endpoint:', 'https://api.github.com'
|
20
15
|
|
21
|
-
github = Github.new :login => username, :password => password, :endpoint => @endpoint
|
22
|
-
|
23
16
|
begin
|
24
|
-
github.
|
25
|
-
@oauth_token = github.
|
17
|
+
github = Github.new :login => login, :password => password, :endpoint => @endpoint
|
18
|
+
@oauth_token = github.oauth.create('scopes' => ['repo']).token
|
26
19
|
template 'party_foul.rb', 'config/initializers/party_foul.rb'
|
27
20
|
rescue Github::Error::Unauthorized
|
28
21
|
say 'There was an error retrieving your Github OAuth token'
|
@@ -1,18 +1,21 @@
|
|
1
1
|
PartyFoul.configure do |config|
|
2
2
|
# the collection of exceptions to be ignored by PartyFoul
|
3
3
|
# The constants here *must* be represented as strings
|
4
|
-
config.ignored_exceptions
|
4
|
+
config.ignored_exceptions = ['ActiveRecord::RecordNotFound', 'ActionController::RoutingError']
|
5
|
+
|
6
|
+
# The names of the HTTP headers to not report
|
7
|
+
config.filtered_http_headers = ['Cookie']
|
5
8
|
|
6
9
|
# The OAuth token for the account that will be opening the issues on Github
|
7
|
-
config.oauth_token
|
10
|
+
config.oauth_token = '<%= @oauth_token %>'
|
8
11
|
|
9
12
|
# The API endpoint for Github. Unless you are hosting a private
|
10
13
|
# instance of Enterprise Github you do not need to include this
|
11
|
-
config.endpoint
|
14
|
+
config.endpoint = '<%= @endpoint %>'
|
12
15
|
|
13
16
|
# The organization or user that owns the target repository
|
14
|
-
config.owner
|
17
|
+
config.owner = '<%= @owner %>'
|
15
18
|
|
16
19
|
# The repository for this application
|
17
|
-
config.repo
|
20
|
+
config.repo = '<%= @repo %>'
|
18
21
|
end
|
data/lib/party_foul.rb
CHANGED
@@ -2,7 +2,7 @@ require 'github_api'
|
|
2
2
|
|
3
3
|
module PartyFoul
|
4
4
|
class << self
|
5
|
-
attr_accessor :github, :oauth_token, :endpoint, :owner, :repo, :ignored_exceptions, :adapter, :issue_template, :comment_template
|
5
|
+
attr_accessor :github, :oauth_token, :endpoint, :owner, :repo, :ignored_exceptions, :adapter, :issue_template, :comment_template, :filtered_http_headers
|
6
6
|
end
|
7
7
|
|
8
8
|
def self.issue_template
|
@@ -27,6 +27,7 @@ Fingerprint: `:fingerprint`
|
|
27
27
|
<tr><th>Occurred at</th><td>:occurred_at</td></tr>
|
28
28
|
<tr><th>Params</th><td>:params</td></tr>
|
29
29
|
<tr><th>IP Address</th><td>:ip_address</td></tr>
|
30
|
+
<tr><th>Session</th><td>:session</td></tr>
|
30
31
|
<tr><th>HTTP Headers</th><td>:http_headers</td></tr>
|
31
32
|
</table>
|
32
33
|
TEMPLATE
|
@@ -94,10 +94,19 @@ class PartyFoul::ExceptionHandler
|
|
94
94
|
|
95
95
|
def compile_template(template)
|
96
96
|
template.gsub(/:\w+/) do |method|
|
97
|
-
self.send(method.split(':').last)
|
97
|
+
value = self.send(method.split(':').last)
|
98
|
+
if value.kind_of?(Hash)
|
99
|
+
hash_as_table(value)
|
100
|
+
else
|
101
|
+
value
|
102
|
+
end
|
98
103
|
end
|
99
104
|
end
|
100
105
|
|
106
|
+
def hash_as_table(value)
|
107
|
+
"<table>#{value.map {|key, value| "<tr><th>#{key}</th><td>#{value}</td></tr>"}.join}</table>"
|
108
|
+
end
|
109
|
+
|
101
110
|
def occurred_at
|
102
111
|
Time.now.strftime('%B %d, %Y %H:%M:%S %z')
|
103
112
|
end
|
@@ -106,8 +115,15 @@ class PartyFoul::ExceptionHandler
|
|
106
115
|
env['REMOTE_ADDR']
|
107
116
|
end
|
108
117
|
|
118
|
+
def session
|
119
|
+
env['rack.session']
|
120
|
+
end
|
121
|
+
|
109
122
|
def http_headers
|
110
|
-
|
123
|
+
env.keys.select { |key| key =~ /^HTTP_(\w+)/ && !(PartyFoul.filtered_http_headers || []).include?($1.split('_').map(&:capitalize).join('-')) }.sort.inject({}) do |hash, key|
|
124
|
+
hash[key.split('HTTP_').last.split('_').map(&:capitalize).join('-')] = env[key]
|
125
|
+
hash
|
126
|
+
end
|
111
127
|
end
|
112
128
|
|
113
129
|
private
|
data/lib/party_foul/version.rb
CHANGED
data/test/generator_test.rb
CHANGED
@@ -8,10 +8,9 @@ class PartyFoul::GeneratorTest < Rails::Generators::TestCase
|
|
8
8
|
test 'it copies the initializer' do
|
9
9
|
oauth = mock('Oauth')
|
10
10
|
oauth.stubs(:create)
|
11
|
-
oauth.expects(:create).with('scopes' => ['repo'])
|
11
|
+
oauth.expects(:create).with('scopes' => ['repo']).returns(Hashie::Mash.new(token: 'test_token'))
|
12
12
|
github = mock('Github')
|
13
13
|
github.stubs(:oauth).returns(oauth)
|
14
|
-
github.stubs(:oauth_token).returns('test_token')
|
15
14
|
Github.stubs(:new).with(:login => 'test_login', :password => 'test_password', :endpoint => 'test_endpoint').returns(github)
|
16
15
|
$stdin.stubs(:gets).returns('test_login').then.returns('test_password').then.returns('').then.returns('test_repo').then.returns("test_endpoint").then.returns('')
|
17
16
|
run_generator
|
@@ -4,7 +4,11 @@ require 'action_dispatch/http/parameter_filter'
|
|
4
4
|
|
5
5
|
describe 'Party Foul Exception Handler' do
|
6
6
|
before do
|
7
|
-
Time.stubs(:now).returns(Time.
|
7
|
+
Time.stubs(:now).returns(Time.new(1970, 1, 1, 0, 0, 0, '-05:00'))
|
8
|
+
end
|
9
|
+
|
10
|
+
after do
|
11
|
+
clean_up_party
|
8
12
|
end
|
9
13
|
|
10
14
|
describe '#body' do
|
@@ -21,7 +25,7 @@ describe 'Party Foul Exception Handler' do
|
|
21
25
|
<table>
|
22
26
|
<tr><th>Exception</th><td>Test Exception</td></tr>
|
23
27
|
<tr><th>Count</th><td>1</td></tr>
|
24
|
-
<tr><th>Last Occurance</th><td>
|
28
|
+
<tr><th>Last Occurance</th><td>January 01, 1970 00:00:00 -0500</td></tr>
|
25
29
|
</table>
|
26
30
|
|
27
31
|
## Stack Trace
|
@@ -60,7 +64,7 @@ Fingerprint: `abcdefg1234567890`
|
|
60
64
|
<table>
|
61
65
|
<tr><th>Exception</th><td>Test Exception</td></tr>
|
62
66
|
<tr><th>Count</th><td>1</td></tr>
|
63
|
-
<tr><th>Last Occurance</th><td>
|
67
|
+
<tr><th>Last Occurance</th><td>January 01, 1970 00:00:00 -0500</td></tr>
|
64
68
|
</table>
|
65
69
|
|
66
70
|
## Stack Trace
|
@@ -102,7 +106,8 @@ Fingerprint: `abcdefg1234567890`
|
|
102
106
|
'HTTP_USER_AGENT' => 'test_user_agent',
|
103
107
|
'REMOTE_ADDR' => '127.0.0.1',
|
104
108
|
'HTTP_HOST' => 'localhost:3000',
|
105
|
-
'QUERY_STRING' => { :controller => 'landing', :action => 'index' }
|
109
|
+
'QUERY_STRING' => { :controller => 'landing', :action => 'index' },
|
110
|
+
'rack.session' => { :id => 1 }
|
106
111
|
}
|
107
112
|
@handler = PartyFoul::ExceptionHandler.new(nil, env)
|
108
113
|
end
|
@@ -110,10 +115,11 @@ Fingerprint: `abcdefg1234567890`
|
|
110
115
|
it 'renders a new comment' do
|
111
116
|
expected_comment = <<-COMMENT
|
112
117
|
<table>
|
113
|
-
<tr><th>Occurred at</th><td>
|
114
|
-
<tr><th>Params</th><td>
|
118
|
+
<tr><th>Occurred at</th><td>January 01, 1970 00:00:00 -0500</td></tr>
|
119
|
+
<tr><th>Params</th><td><table><tr><th>controller</th><td>landing</td></tr><tr><th>action</th><td>index</td></tr></table></td></tr>
|
115
120
|
<tr><th>IP Address</th><td>127.0.0.1</td></tr>
|
116
|
-
<tr><th>
|
121
|
+
<tr><th>Session</th><td><table><tr><th>id</th><td>1</td></tr></table></td></tr>
|
122
|
+
<tr><th>HTTP Headers</th><td><table><tr><th>Host</th><td>localhost:3000</td></tr><tr><th>User-Agent</th><td>test_user_agent</td></tr></table></td></tr>
|
117
123
|
</table>
|
118
124
|
COMMENT
|
119
125
|
|
@@ -130,4 +136,26 @@ COMMENT
|
|
130
136
|
@handler.compile_template(template).must_equal '<span>123</span><div>abc</div>'
|
131
137
|
end
|
132
138
|
end
|
139
|
+
|
140
|
+
describe '#http_headers' do
|
141
|
+
before do
|
142
|
+
PartyFoul.filtered_http_headers = ['Cookie']
|
143
|
+
env = {
|
144
|
+
'HTTP_USER_AGENT' => 'test_user_agent',
|
145
|
+
'HTTP_COOKIE' => 'test_cookie',
|
146
|
+
}
|
147
|
+
@handler = PartyFoul::ExceptionHandler.new(nil, env)
|
148
|
+
end
|
149
|
+
|
150
|
+
it 'ignored Cookie' do
|
151
|
+
@handler.http_headers.must_equal('User-Agent' => 'test_user_agent')
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
describe '#hash_as_table' do
|
156
|
+
it 'renders as an HTML table' do
|
157
|
+
expected = '<table><tr><th>Value 1</th><td>A</td></tr><tr><th>Value B</th><td>2</td></tr></table>'
|
158
|
+
PartyFoul::ExceptionHandler.new(nil, nil).hash_as_table('Value 1' => 'A', 'Value B' => 2).must_equal expected
|
159
|
+
end
|
160
|
+
end
|
133
161
|
end
|
data/test/test_helper.rb
CHANGED
@@ -21,7 +21,7 @@ module MiniTest::Expectations
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def clean_up_party
|
24
|
-
%w{github oauth_token endpoint owner repo ignored_exceptions}.each do |attr|
|
24
|
+
%w{github oauth_token endpoint owner repo ignored_exceptions adapter issue_template comment_template filtered_http_headers}.each do |attr|
|
25
25
|
PartyFoul.send("#{attr}=", nil)
|
26
26
|
end
|
27
27
|
end
|
@@ -1,18 +1,21 @@
|
|
1
1
|
PartyFoul.configure do |config|
|
2
2
|
# the collection of exceptions to be ignored by PartyFoul
|
3
3
|
# The constants here *must* be represented as strings
|
4
|
-
config.ignored_exceptions
|
4
|
+
config.ignored_exceptions = ['ActiveRecord::RecordNotFound', 'ActionController::RoutingError']
|
5
|
+
|
6
|
+
# The names of the HTTP headers to not report
|
7
|
+
config.filtered_http_headers = ['Cookie']
|
5
8
|
|
6
9
|
# The OAuth token for the account that will be opening the issues on Github
|
7
|
-
config.oauth_token
|
10
|
+
config.oauth_token = 'test_token'
|
8
11
|
|
9
12
|
# The API endpoint for Github. Unless you are hosting a private
|
10
13
|
# instance of Enterprise Github you do not need to include this
|
11
|
-
config.endpoint
|
14
|
+
config.endpoint = 'test_endpoint'
|
12
15
|
|
13
16
|
# The organization or user that owns the target repository
|
14
|
-
config.owner
|
17
|
+
config.owner = 'test_login'
|
15
18
|
|
16
19
|
# The repository for this application
|
17
|
-
config.repo
|
20
|
+
config.repo = 'test_repo'
|
18
21
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: party_foul
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -193,7 +193,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
193
193
|
version: '0'
|
194
194
|
segments:
|
195
195
|
- 0
|
196
|
-
hash:
|
196
|
+
hash: 3070115477891214928
|
197
197
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
198
198
|
none: false
|
199
199
|
requirements:
|
@@ -202,7 +202,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
202
202
|
version: '0'
|
203
203
|
segments:
|
204
204
|
- 0
|
205
|
-
hash:
|
205
|
+
hash: 3070115477891214928
|
206
206
|
requirements: []
|
207
207
|
rubyforge_project:
|
208
208
|
rubygems_version: 1.8.23
|