scout 5.3.5 → 5.4.4.alpha

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. data/.gitignore +6 -0
  2. data/CHANGELOG +0 -12
  3. data/Gemfile +4 -0
  4. data/README +8 -0
  5. data/Rakefile +6 -108
  6. data/bin/scout +1 -0
  7. data/lib/scout.rb +5 -4
  8. data/lib/scout/command.rb +11 -12
  9. data/lib/scout/command/install.rb +1 -1
  10. data/lib/scout/command/run.rb +13 -1
  11. data/lib/scout/command/sign.rb +2 -8
  12. data/lib/scout/command/stream.rb +50 -0
  13. data/lib/scout/command/test.rb +1 -1
  14. data/lib/scout/daemon_spawn.rb +215 -0
  15. data/lib/scout/plugin.rb +20 -1
  16. data/lib/scout/server.rb +16 -111
  17. data/lib/scout/server_base.rb +100 -0
  18. data/lib/scout/streamer.rb +162 -0
  19. data/lib/scout/streamer_control.rb +43 -0
  20. data/lib/scout/version.rb +3 -0
  21. data/scout.gemspec +27 -0
  22. data/test/plugins/disk_usage.rb +86 -0
  23. data/test/scout_test.rb +598 -0
  24. data/vendor/pusher-gem/Gemfile +2 -0
  25. data/vendor/pusher-gem/LICENSE +20 -0
  26. data/vendor/pusher-gem/README.md +80 -0
  27. data/vendor/pusher-gem/Rakefile +11 -0
  28. data/vendor/pusher-gem/examples/async_message.rb +28 -0
  29. data/vendor/pusher-gem/lib/pusher.rb +107 -0
  30. data/vendor/pusher-gem/lib/pusher/channel.rb +154 -0
  31. data/vendor/pusher-gem/lib/pusher/request.rb +107 -0
  32. data/vendor/pusher-gem/pusher.gemspec +28 -0
  33. data/vendor/pusher-gem/spec/channel_spec.rb +274 -0
  34. data/vendor/pusher-gem/spec/pusher_spec.rb +87 -0
  35. data/vendor/pusher-gem/spec/spec_helper.rb +13 -0
  36. data/vendor/ruby-hmac/History.txt +15 -0
  37. data/vendor/ruby-hmac/Manifest.txt +11 -0
  38. data/vendor/ruby-hmac/README.md +41 -0
  39. data/vendor/ruby-hmac/Rakefile +23 -0
  40. data/vendor/ruby-hmac/lib/hmac-md5.rb +11 -0
  41. data/vendor/ruby-hmac/lib/hmac-rmd160.rb +11 -0
  42. data/vendor/ruby-hmac/lib/hmac-sha1.rb +11 -0
  43. data/vendor/ruby-hmac/lib/hmac-sha2.rb +25 -0
  44. data/vendor/ruby-hmac/lib/hmac.rb +118 -0
  45. data/vendor/ruby-hmac/lib/ruby_hmac.rb +2 -0
  46. data/vendor/ruby-hmac/ruby-hmac.gemspec +33 -0
  47. data/vendor/ruby-hmac/test/test_hmac.rb +89 -0
  48. data/vendor/signature/.document +5 -0
  49. data/vendor/signature/.gitignore +21 -0
  50. data/vendor/signature/Gemfile +3 -0
  51. data/vendor/signature/Gemfile.lock +29 -0
  52. data/vendor/signature/LICENSE +20 -0
  53. data/vendor/signature/README.md +55 -0
  54. data/vendor/signature/Rakefile +2 -0
  55. data/vendor/signature/VERSION +1 -0
  56. data/vendor/signature/lib/signature.rb +142 -0
  57. data/vendor/signature/lib/signature/version.rb +3 -0
  58. data/vendor/signature/signature.gemspec +22 -0
  59. data/vendor/signature/spec/signature_spec.rb +176 -0
  60. data/vendor/signature/spec/spec_helper.rb +10 -0
  61. data/vendor/util/lib/core_extensions.rb +60 -0
  62. metadata +120 -84
  63. data/AUTHORS +0 -4
  64. data/COPYING +0 -340
  65. data/INSTALL +0 -18
  66. data/TODO +0 -6
@@ -0,0 +1,28 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = "pusher"
6
+ s.version = "0.8.4"
7
+ s.platform = Gem::Platform::RUBY
8
+ s.authors = ["Pusher"]
9
+ s.email = ["support@pusher.com"]
10
+ s.homepage = "http://github.com/pusher/pusher-gem"
11
+ s.summary = %q{Pusher API client}
12
+ s.description = %q{Wrapper for pusher.com REST api}
13
+
14
+ s.add_dependency "multi_json", "~> 1.0"
15
+ s.add_dependency "crack", "~> 0.1.0"
16
+ s.add_dependency "ruby-hmac", "~> 0.4.0"
17
+ s.add_dependency 'signature', "~> 0.1.2"
18
+
19
+ s.add_development_dependency "rspec", "~> 2.0"
20
+ s.add_development_dependency "webmock"
21
+ s.add_development_dependency "em-http-request", "~> 1.0.0"
22
+ s.add_development_dependency "rake"
23
+
24
+ s.files = `git ls-files`.split("\n")
25
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
26
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
27
+ s.require_paths = ["lib"]
28
+ end
@@ -0,0 +1,274 @@
1
+ require 'spec_helper'
2
+
3
+ describe Pusher::Channel do
4
+ before do
5
+ Pusher.app_id = '20'
6
+ Pusher.key = '12345678900000001'
7
+ Pusher.secret = '12345678900000001'
8
+ Pusher.host = 'api.pusherapp.com'
9
+ Pusher.port = 80
10
+ Pusher.encrypted = false
11
+
12
+ WebMock.reset!
13
+ WebMock.disable_net_connect!
14
+
15
+ @pusher_url_regexp = %r{/apps/20/channels/test_channel/events}
16
+ end
17
+
18
+ after do
19
+ Pusher.app_id = nil
20
+ Pusher.key = nil
21
+ Pusher.secret = nil
22
+ end
23
+
24
+ describe 'trigger!' do
25
+ before :each do
26
+ WebMock.stub_request(:post, @pusher_url_regexp).
27
+ to_return(:status => 202)
28
+ @channel = Pusher['test_channel']
29
+ end
30
+
31
+ it 'should configure HTTP library to talk to pusher API' do
32
+ @channel.trigger!('new_event', 'Some data')
33
+ WebMock.should have_requested(:post, %r{http://api.pusherapp.com})
34
+ end
35
+
36
+ it "should POST to https api if ssl enabled" do
37
+ Pusher.encrypted = true
38
+ Pusher::Channel.new(Pusher.url, 'test_channel').trigger('new_event', 'Some data')
39
+ WebMock.should have_requested(:post, %r{https://api.pusherapp.com})
40
+ end
41
+
42
+ it 'should POST hashes by encoding as JSON in the request body' do
43
+ @channel.trigger!('new_event', {
44
+ :name => 'Pusher',
45
+ :last_name => 'App'
46
+ })
47
+ WebMock.should have_requested(:post, %r{/apps/20/channels/test_channel/events}).with do |req|
48
+ query_hash = req.uri.query_values
49
+ query_hash["name"].should == 'new_event'
50
+ query_hash["auth_key"].should == Pusher.key
51
+ query_hash["auth_timestamp"].should_not be_nil
52
+
53
+ parsed = MultiJson.decode(req.body)
54
+ parsed.should == {
55
+ "name" => 'Pusher',
56
+ "last_name" => 'App'
57
+ }
58
+
59
+ req.headers['Content-Type'].should == 'application/json'
60
+ end
61
+ end
62
+
63
+ it "should POST string data unmodified in request body" do
64
+ string = "foo\nbar\""
65
+ @channel.trigger!('new_event', string)
66
+ WebMock.should have_requested(:post, %r{/apps/20/channels/test_channel/events}).with do |req|
67
+ req.body.should == "foo\nbar\""
68
+ end
69
+ end
70
+
71
+ it "should catch all Net::HTTP exceptions and raise a Pusher::HTTPError, exposing the original error if required" do
72
+ WebMock.stub_request(
73
+ :post, %r{/apps/20/channels/test_channel/events}
74
+ ).to_raise(Timeout::Error)
75
+
76
+ error_raised = nil
77
+ begin
78
+ Pusher['test_channel'].trigger!('new_event', 'Some data')
79
+ rescue => e
80
+ error_raised = e
81
+ end
82
+ error_raised.class.should == Pusher::HTTPError
83
+ error_raised.message.should == 'Exception from WebMock (Timeout::Error)'
84
+ error_raised.original_error.class.should == Timeout::Error
85
+ end
86
+
87
+ it "should raise AuthenticationError if pusher returns 401" do
88
+ WebMock.stub_request(
89
+ :post,
90
+ %r{/apps/20/channels/test_channel/events}
91
+ ).to_return(:status => 401)
92
+ lambda {
93
+ Pusher['test_channel'].trigger!('new_event', 'Some data')
94
+ }.should raise_error(Pusher::AuthenticationError)
95
+ end
96
+
97
+ it "should raise Pusher::Error if pusher returns 404" do
98
+ WebMock.stub_request(
99
+ :post, %r{/apps/20/channels/test_channel/events}
100
+ ).to_return(:status => 404)
101
+ lambda {
102
+ Pusher['test_channel'].trigger!('new_event', 'Some data')
103
+ }.should raise_error(Pusher::Error, 'Resource not found: app_id is probably invalid')
104
+ end
105
+
106
+ it "should raise Pusher::Error if pusher returns 500" do
107
+ WebMock.stub_request(
108
+ :post, %r{/apps/20/channels/test_channel/events}
109
+ ).to_return(:status => 500, :body => "some error")
110
+ lambda {
111
+ Pusher['test_channel'].trigger!('new_event', 'Some data')
112
+ }.should raise_error(Pusher::Error, 'Unknown error (status code 500): some error')
113
+ end
114
+ end
115
+
116
+ describe 'trigger' do
117
+ it "should log failure if error raised in Net::HTTP call" do
118
+ stub_request(:post, @pusher_url_regexp).to_raise(Net::HTTPBadResponse)
119
+ Pusher.logger.should_receive(:error).with("Exception from WebMock (Net::HTTPBadResponse) (Pusher::HTTPError)")
120
+ Pusher.logger.should_receive(:debug) #backtrace
121
+ Pusher::Channel.new(Pusher.url, 'test_channel').trigger('new_event', 'Some data')
122
+ end
123
+
124
+ it "should log failure if Pusher returns an error response" do
125
+ stub_request(:post, @pusher_url_regexp).to_return(:status => 401)
126
+ # @http.should_receive(:post).and_raise(Net::HTTPBadResponse)
127
+ Pusher.logger.should_receive(:error).with(" (Pusher::AuthenticationError)")
128
+ Pusher.logger.should_receive(:debug) #backtrace
129
+ Pusher::Channel.new(Pusher.url, 'test_channel').trigger('new_event', 'Some data')
130
+ end
131
+ end
132
+
133
+ describe "trigger_async" do
134
+ it "should by default POST to http api" do
135
+ EM.run {
136
+ stub_request(:post, @pusher_url_regexp).to_return(:status => 202)
137
+ channel = Pusher::Channel.new(Pusher.url, 'test_channel')
138
+ channel.trigger_async('new_event', 'Some data').callback {
139
+ WebMock.should have_requested(:post, %r{http://api.pusherapp.com})
140
+ EM.stop
141
+ }
142
+ }
143
+ end
144
+
145
+ it "should POST to https api if ssl enabled" do
146
+ Pusher.encrypted = true
147
+ EM.run {
148
+ stub_request(:post, @pusher_url_regexp).to_return(:status => 202)
149
+ channel = Pusher::Channel.new(Pusher.url, 'test_channel')
150
+ channel.trigger_async('new_event', 'Some data').callback {
151
+ WebMock.should have_requested(:post, %r{https://api.pusherapp.com})
152
+ EM.stop
153
+ }
154
+ }
155
+ end
156
+
157
+ it "should return a deferrable which succeeds in success case" do
158
+ stub_request(:post, @pusher_url_regexp).to_return(:status => 202)
159
+
160
+ EM.run {
161
+ d = Pusher['test_channel'].trigger_async('new_event', 'Some data')
162
+ d.callback {
163
+ WebMock.should have_requested(:post, @pusher_url_regexp)
164
+ EM.stop
165
+ }
166
+ d.errback {
167
+ fail
168
+ EM.stop
169
+ }
170
+ }
171
+ end
172
+
173
+ it "should return a deferrable which fails (with exception) in fail case" do
174
+ stub_request(:post, @pusher_url_regexp).to_return(:status => 401)
175
+
176
+ EM.run {
177
+ d = Pusher['test_channel'].trigger_async('new_event', 'Some data')
178
+ d.callback {
179
+ fail
180
+ }
181
+ d.errback { |error|
182
+ WebMock.should have_requested(:post, @pusher_url_regexp)
183
+ error.should be_kind_of(Pusher::AuthenticationError)
184
+ EM.stop
185
+ }
186
+ }
187
+ end
188
+ end
189
+
190
+ describe "stats" do
191
+ before :each do
192
+ @api_path = %r{/apps/20/channels/presence-test_channel/stats}
193
+ end
194
+
195
+ it "should call the user_count api" do
196
+ WebMock.stub_request(:get, @api_path).to_return({
197
+ :status => 200,
198
+ :body => JSON.generate(:user_count => 1)
199
+ })
200
+ @channel = Pusher['presence-test_channel']
201
+
202
+ @channel.stats.should == {
203
+ :user_count => 1
204
+ }
205
+ end
206
+ end
207
+
208
+ describe "socket_auth" do
209
+ before :each do
210
+ @channel = Pusher['test_channel']
211
+ end
212
+
213
+ it "should return an authentication string given a socket id" do
214
+ auth = @channel.socket_auth('socketid')
215
+
216
+ auth.should == '12345678900000001:827076f551e22451357939e4c7bb1200de29f921d5bf80b40d71668f9cd61c40'
217
+ end
218
+
219
+ it "should raise error if authentication is invalid" do
220
+ [nil, ''].each do |invalid|
221
+ lambda {
222
+ @channel.socket_auth(invalid)
223
+ }.should raise_error
224
+ end
225
+ end
226
+
227
+ describe 'with extra string argument' do
228
+
229
+ it 'should be a string or nil' do
230
+ lambda {
231
+ @channel.socket_auth('socketid', 'boom')
232
+ }.should_not raise_error
233
+
234
+ lambda {
235
+ @channel.socket_auth('socketid', 123)
236
+ }.should raise_error
237
+
238
+ lambda {
239
+ @channel.socket_auth('socketid', nil)
240
+ }.should_not raise_error
241
+
242
+ lambda {
243
+ @channel.socket_auth('socketid', {})
244
+ }.should raise_error
245
+ end
246
+
247
+ it "should return an authentication string given a socket id and custom args" do
248
+ auth = @channel.socket_auth('socketid', 'foobar')
249
+
250
+ auth.should == "12345678900000001:#{HMAC::SHA256.hexdigest(Pusher.secret, "socketid:test_channel:foobar")}"
251
+ end
252
+
253
+ end
254
+ end
255
+
256
+ describe '#authenticate' do
257
+
258
+ before :each do
259
+ @channel = Pusher['test_channel']
260
+ @custom_data = {:uid => 123, :info => {:name => 'Foo'}}
261
+ end
262
+
263
+ it 'should return a hash with signature including custom data and data as json string' do
264
+ MultiJson.stub!(:encode).with(@custom_data).and_return 'a json string'
265
+
266
+ response = @channel.authenticate('socketid', @custom_data)
267
+
268
+ response.should == {
269
+ :auth => "12345678900000001:#{HMAC::SHA256.hexdigest(Pusher.secret, "socketid:test_channel:a json string")}",
270
+ :channel_data => 'a json string'
271
+ }
272
+ end
273
+ end
274
+ end
@@ -0,0 +1,87 @@
1
+ require 'spec_helper'
2
+
3
+ require 'em-http'
4
+
5
+ describe Pusher do
6
+ describe 'configuration' do
7
+ it 'should be preconfigured for api host' do
8
+ Pusher.host.should == 'api.pusherapp.com'
9
+ end
10
+
11
+ it 'should be preconfigured for port 80' do
12
+ Pusher.port.should == 80
13
+ end
14
+
15
+ it 'should use standard logger if no other logger if defined' do
16
+ Pusher.logger.debug('foo')
17
+ Pusher.logger.should be_kind_of(Logger)
18
+ end
19
+
20
+ it "can be configured to use any logger" do
21
+ logger = mock("ALogger")
22
+ logger.should_receive(:debug).with('foo')
23
+ Pusher.logger = logger
24
+ Pusher.logger.debug('foo')
25
+ Pusher.logger = nil
26
+ end
27
+ end
28
+
29
+ describe "configuration using url" do
30
+ after do
31
+ Pusher.app_id = nil
32
+ Pusher.key = nil
33
+ Pusher.secret = nil
34
+ Pusher.host = 'api.pusherapp.com'
35
+ Pusher.port = 80
36
+ end
37
+
38
+ it "should be possible to configure everything by setting the url" do
39
+ Pusher.url = "http://somekey:somesecret@api.staging.pusherapp.com:8080/apps/87"
40
+
41
+ Pusher.host.should == 'api.staging.pusherapp.com'
42
+ Pusher.port.should == 8080
43
+ Pusher.key.should == 'somekey'
44
+ Pusher.secret.should == 'somesecret'
45
+ Pusher.app_id.should == '87'
46
+ end
47
+ end
48
+
49
+ describe 'when configured' do
50
+ before do
51
+ Pusher.app_id = '20'
52
+ Pusher.key = '12345678900000001'
53
+ Pusher.secret = '12345678900000001'
54
+ end
55
+
56
+ after do
57
+ Pusher.app_id = nil
58
+ Pusher.key = nil
59
+ Pusher.secret = nil
60
+ end
61
+
62
+ describe '.[]' do
63
+ before do
64
+ @channel = Pusher['test_channel']
65
+ end
66
+
67
+ it 'should return a channel' do
68
+ @channel.should be_kind_of(Pusher::Channel)
69
+ end
70
+
71
+ it "should reuse the same channel objects" do
72
+ channel1, channel2 = Pusher['test_channel'], Pusher['test_channel']
73
+
74
+ channel1.object_id.should == channel2.object_id
75
+ end
76
+
77
+ %w{app_id key secret}.each do |config|
78
+ it "should raise exception if #{config} not configured" do
79
+ Pusher.send("#{config}=", nil)
80
+ lambda {
81
+ Pusher['test_channel']
82
+ }.should raise_error(Pusher::ConfigurationError)
83
+ end
84
+ end
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,13 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'although not required, it is recommended that you use bundler when running the tests'
5
+ end
6
+
7
+ require 'rspec'
8
+ require 'rspec/autorun'
9
+ require 'em-http' # As of webmock 1.4.0, em-http must be loaded first
10
+ require 'webmock/rspec'
11
+
12
+ require 'pusher'
13
+ require 'eventmachine'
@@ -0,0 +1,15 @@
1
+ == 0.4.0 / 2010-01-19
2
+
3
+ * Ruby 1.9 compatibility [Tim Kersey]
4
+ * Minitest integration [Tim Kersey]
5
+ * Updated to Hoe 2.5.0 [Geoffrey Grosenbach]
6
+
7
+ == 0.3.2 / 2008-08-20
8
+
9
+ * Removed spurious constants that cause warnings on load [Blaine Cook]
10
+ * Move hoe to build dependency if build deps are supported [Blaine Cook]
11
+
12
+ == 0.3.1 / 2007-08-13
13
+
14
+ * Converted to gem by Geoffrey Grosenbach
15
+ * Tests converted to Test::Unit
@@ -0,0 +1,11 @@
1
+ History.txt
2
+ Manifest.txt
3
+ README.txt
4
+ Rakefile
5
+ lib/hmac-md5.rb
6
+ lib/hmac-rmd160.rb
7
+ lib/hmac-sha1.rb
8
+ lib/hmac-sha2.rb
9
+ lib/hmac.rb
10
+ lib/ruby_hmac.rb
11
+ test/test_hmac.rb
@@ -0,0 +1,41 @@
1
+ = ruby-hmac
2
+
3
+ * http://ruby-hmac.rubyforge.org
4
+
5
+ == IMPORTANT: USE OpenSSL INSTEAD!
6
+
7
+ The HMAC functionality included with OpenSSL is available from Ruby and is much faster. It's recommended that you use OpenSSL instead of this library.
8
+
9
+ See the blog post on [OpenSSL vs. Ruby HMAC Benchmarks](http://blog.nathanielbibler.com/post/63031273/openssl-hmac-vs-ruby-hmac-benchmarks).
10
+
11
+ == DESCRIPTION:
12
+
13
+ This module provides common interface to HMAC functionality. HMAC is a kind of "Message Authentication Code" (MAC) algorithm whose standard is documented in RFC2104. Namely, a MAC provides a way to check the integrity of information transmitted over or stored in an unreliable medium, based on a secret key.
14
+
15
+ Originally written by Daiki Ueno. Converted to a RubyGem by Geoffrey Grosenbach
16
+
17
+ == LICENSE:
18
+
19
+ (The MIT License)
20
+
21
+ Copyright (c) 2007 Daiki Ueno
22
+
23
+ Permission is hereby granted, free of charge, to any person obtaining
24
+ a copy of this software and associated documentation files (the
25
+ 'Software'), to deal in the Software without restriction, including
26
+ without limitation the rights to use, copy, modify, merge, publish,
27
+ distribute, sublicense, and/or sell copies of the Software, and to
28
+ permit persons to whom the Software is furnished to do so, subject to
29
+ the following conditions:
30
+
31
+ The above copyright notice and this permission notice shall be
32
+ included in all copies or substantial portions of the Software.
33
+
34
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
35
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
36
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
37
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
38
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
39
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
40
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
41
+