pusher-fake 1.12.0 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/pusher-fake +1 -3
- data/lib/pusher-fake.rb +3 -1
- data/lib/pusher-fake/channel.rb +4 -2
- data/lib/pusher-fake/channel/presence.rb +3 -3
- data/lib/pusher-fake/channel/private.rb +3 -1
- data/lib/pusher-fake/channel/public.rb +2 -0
- data/lib/pusher-fake/configuration.rb +4 -1
- data/lib/pusher-fake/connection.rb +10 -7
- data/lib/pusher-fake/server.rb +2 -0
- data/lib/pusher-fake/server/application.rb +4 -2
- data/lib/pusher-fake/support/base.rb +4 -2
- data/lib/pusher-fake/support/cucumber.rb +2 -0
- data/lib/pusher-fake/support/rspec.rb +2 -0
- data/lib/pusher-fake/webhook.rb +3 -1
- data/spec/features/api/channels_spec.rb +2 -0
- data/spec/features/api/users_spec.rb +2 -0
- data/spec/features/client/connect_spec.rb +2 -0
- data/spec/features/client/event_spec.rb +2 -0
- data/spec/features/client/presence_spec.rb +2 -0
- data/spec/features/client/subscribe_spec.rb +9 -5
- data/spec/features/server/event_spec.rb +2 -0
- data/spec/features/server/webhooks_spec.rb +2 -0
- data/spec/lib/pusher-fake/channel/presence_spec.rb +2 -0
- data/spec/lib/pusher-fake/channel/private_spec.rb +4 -2
- data/spec/lib/pusher-fake/channel/public_spec.rb +2 -0
- data/spec/lib/pusher-fake/channel_spec.rb +2 -0
- data/spec/lib/pusher-fake/configuration_spec.rb +9 -1
- data/spec/lib/pusher-fake/connection_spec.rb +4 -2
- data/spec/lib/pusher-fake/server/application_spec.rb +4 -2
- data/spec/lib/pusher-fake/server_spec.rb +2 -0
- data/spec/lib/pusher-fake/webhook_spec.rb +3 -1
- data/spec/lib/pusher_fake_spec.rb +2 -0
- data/spec/spec_helper.rb +3 -1
- data/spec/support/application.rb +3 -1
- data/spec/support/application/public/javascripts/vendor/polyfill.min.js +1 -0
- data/spec/support/application/public/javascripts/vendor/pusher-7.0.0.js +4565 -0
- data/spec/support/application/views/index.erb +2 -1
- data/spec/support/capybara.rb +4 -7
- data/spec/support/coveralls.rb +2 -0
- data/spec/support/helpers/connect.rb +2 -0
- data/spec/support/helpers/event.rb +2 -0
- data/spec/support/helpers/subscription.rb +2 -0
- data/spec/support/helpers/user.rb +2 -0
- data/spec/support/matchers/have_configuration_option.rb +2 -0
- data/spec/support/pusher_fake.rb +3 -1
- data/spec/support/webhooks.rb +17 -15
- metadata +104 -47
- data/lib/pusher-fake/cucumber.rb +0 -4
- data/spec/support/application/public/javascripts/vendor/pusher-4.2.2.js +0 -4183
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '09cf8cbf09383dbf9ca8829c07e67da46721965a6e226e76205a92329c55b8a1'
|
4
|
+
data.tar.gz: 0b3d172aa3c5f86c507eab2a3c71177287145ae5b819b323a26c500e2c8ef423
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 246b183a6b21546e1395cdec4e76b1b95953cb9b151901e84602be7a6ef3ef49ec00a6aea663f6ba9761c8479e5bb9799ddab3e1b629e37d449acb9c2d04c19f
|
7
|
+
data.tar.gz: 71df4af1d1a72e6ca55d1e19bdef165a04decbac64968955b2efac70b9b0c2a66e338f2c9770b857f29d86c503bb269b70c7cd779ada8911d53d3304ee406020
|
data/bin/pusher-fake
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
#
|
3
|
+
# frozen_string_literal: true
|
4
4
|
|
5
5
|
require "optparse"
|
6
6
|
require "pusher"
|
@@ -54,5 +54,3 @@ raise OptionParser::MissingArgument.new("--key") if Pusher.key.nil?
|
|
54
54
|
raise OptionParser::MissingArgument.new("--secret") if Pusher.secret.nil?
|
55
55
|
|
56
56
|
PusherFake::Server.start
|
57
|
-
|
58
|
-
# rubocop:enable Metrics/BlockLength, Metrics/LineLength
|
data/lib/pusher-fake.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "em-http-request"
|
2
4
|
require "em-websocket"
|
3
5
|
require "multi_json"
|
@@ -7,7 +9,7 @@ require "thin"
|
|
7
9
|
# A Pusher fake.
|
8
10
|
module PusherFake
|
9
11
|
# The current version string.
|
10
|
-
VERSION = "
|
12
|
+
VERSION = "3.0.0"
|
11
13
|
|
12
14
|
autoload :Channel, "pusher-fake/channel"
|
13
15
|
autoload :Configuration, "pusher-fake/configuration"
|
data/lib/pusher-fake/channel.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module PusherFake
|
2
4
|
# Channel creation and management.
|
3
5
|
module Channel
|
@@ -6,10 +8,10 @@ module PusherFake
|
|
6
8
|
autoload :Presence, "pusher-fake/channel/presence"
|
7
9
|
|
8
10
|
# Prefix for private channels.
|
9
|
-
PRIVATE_CHANNEL_PREFIX = "private-"
|
11
|
+
PRIVATE_CHANNEL_PREFIX = "private-"
|
10
12
|
|
11
13
|
# Prefix for presence channels.
|
12
|
-
PRESENCE_CHANNEL_PREFIX = "presence-"
|
14
|
+
PRESENCE_CHANNEL_PREFIX = "presence-"
|
13
15
|
|
14
16
|
class << self
|
15
17
|
# @return [Hash] Cache of existing channels.
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module PusherFake
|
2
4
|
module Channel
|
3
5
|
# A presence channel.
|
@@ -34,9 +36,7 @@ module PusherFake
|
|
34
36
|
#
|
35
37
|
# @return [Hash] Hash containing presence information.
|
36
38
|
def subscription_data
|
37
|
-
hash =
|
38
|
-
members.map { |_, member| [member[:user_id], member[:user_info]] }
|
39
|
-
]
|
39
|
+
hash = members.map { |_, member| [member[:user_id], member[:user_info]] }.to_h
|
40
40
|
|
41
41
|
{ presence: { hash: hash, count: members.size } }
|
42
42
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module PusherFake
|
2
4
|
module Channel
|
3
5
|
# A private channel.
|
@@ -38,7 +40,7 @@ module PusherFake
|
|
38
40
|
configuration = PusherFake.configuration
|
39
41
|
|
40
42
|
data = [id, name, data].compact.map(&:to_s).join(":")
|
41
|
-
digest = OpenSSL::Digest
|
43
|
+
digest = OpenSSL::Digest.new("SHA256")
|
42
44
|
signature = OpenSSL::HMAC.hexdigest(digest, configuration.secret, data)
|
43
45
|
|
44
46
|
"#{configuration.key}:#{signature}"
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module PusherFake
|
2
4
|
# Configuration class.
|
3
5
|
class Configuration
|
@@ -47,7 +49,7 @@ module PusherFake
|
|
47
49
|
def reset!
|
48
50
|
self.app_id = "PUSHER_APP_ID"
|
49
51
|
self.key = "PUSHER_API_KEY"
|
50
|
-
self.logger =
|
52
|
+
self.logger = $stdout.to_io
|
51
53
|
self.secret = "PUSHER_API_SECRET"
|
52
54
|
self.verbose = false
|
53
55
|
self.webhooks = []
|
@@ -65,6 +67,7 @@ module PusherFake
|
|
65
67
|
wsHost: socket_options[:host],
|
66
68
|
wsPort: socket_options[:port],
|
67
69
|
cluster: "us-east-1",
|
70
|
+
forceTLS: false,
|
68
71
|
disableStats: disable_stats
|
69
72
|
)
|
70
73
|
end
|
@@ -1,8 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module PusherFake
|
2
4
|
# A client connection.
|
3
5
|
class Connection
|
4
6
|
# Prefix for client events.
|
5
|
-
CLIENT_EVENT_PREFIX = "client-"
|
7
|
+
CLIENT_EVENT_PREFIX = "client-"
|
6
8
|
|
7
9
|
# @return [EventMachine::WebSocket::Connection] Socket for the connection.
|
8
10
|
attr_reader :socket
|
@@ -18,10 +20,10 @@ module PusherFake
|
|
18
20
|
#
|
19
21
|
# @return [Integer] The object ID of the socket.
|
20
22
|
def id
|
21
|
-
parts = socket.object_id.to_s.
|
22
|
-
parts = parts.each_slice(parts.length / 2).to_a
|
23
|
+
parts = socket.object_id.to_s.chars
|
24
|
+
parts = parts.each_slice((parts.length / 2.0).ceil).to_a
|
23
25
|
|
24
|
-
[parts.first.join
|
26
|
+
[parts.first.join, parts.last.join].join(".")
|
25
27
|
end
|
26
28
|
|
27
29
|
# Emit an event to the connection.
|
@@ -67,11 +69,12 @@ module PusherFake
|
|
67
69
|
end
|
68
70
|
|
69
71
|
def process_event(event, message)
|
70
|
-
|
72
|
+
case event
|
73
|
+
when "pusher:subscribe"
|
71
74
|
channel_for(message).add(self, message[:data])
|
72
|
-
|
75
|
+
when "pusher:unsubscribe"
|
73
76
|
channel_for(message).remove(self)
|
74
|
-
|
77
|
+
when "pusher:ping"
|
75
78
|
emit("pusher:pong")
|
76
79
|
end
|
77
80
|
end
|
data/lib/pusher-fake/server.rb
CHANGED
@@ -1,13 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module PusherFake
|
2
4
|
module Server
|
3
5
|
# The fake web application.
|
4
6
|
class Application
|
5
7
|
CHANNEL_FILTER_ERROR = "user_count may only be requested for presence " \
|
6
8
|
"channels - please supply filter_by_prefix " \
|
7
|
-
"begining with presence-"
|
9
|
+
"begining with presence-"
|
8
10
|
|
9
11
|
CHANNEL_USER_COUNT_ERROR = "Cannot retrieve the user count unless the " \
|
10
|
-
"channel is a presence channel"
|
12
|
+
"channel is a presence channel"
|
11
13
|
|
12
14
|
REQUEST_PATHS = {
|
13
15
|
%r{\A/apps/:id/batch_events\z} => :batch_events,
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
%w(app_id key secret).each do |setting|
|
2
4
|
next unless Pusher.public_send(setting).nil?
|
3
5
|
|
@@ -24,6 +26,6 @@ PusherFake.configuration.web_options.tap do |options|
|
|
24
26
|
end
|
25
27
|
|
26
28
|
# Start the fake socket and web servers.
|
27
|
-
|
28
|
-
at_exit {
|
29
|
+
Thread.new { PusherFake::Server.start }.tap do |thread|
|
30
|
+
at_exit { Thread.kill(thread) }
|
29
31
|
end
|
data/lib/pusher-fake/webhook.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module PusherFake
|
2
4
|
# Webhook triggering.
|
3
5
|
class Webhook
|
@@ -26,7 +28,7 @@ module PusherFake
|
|
26
28
|
end
|
27
29
|
|
28
30
|
def signature_for(payload)
|
29
|
-
digest = OpenSSL::Digest
|
31
|
+
digest = OpenSSL::Digest.new("SHA256")
|
30
32
|
secret = PusherFake.configuration.secret
|
31
33
|
|
32
34
|
OpenSSL::HMAC.hexdigest(digest, secret, payload)
|
@@ -1,12 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "spec_helper"
|
2
4
|
|
3
5
|
feature "Client subscribing to a channel" do
|
4
6
|
before do
|
5
|
-
|
6
|
-
|
7
|
-
# rubocop:disable RSpec/ExpectInHook
|
8
|
-
expect(page).to have_content("Client connected.")
|
9
|
-
# rubocop:enable RSpec/ExpectInHook
|
7
|
+
connect
|
10
8
|
end
|
11
9
|
|
12
10
|
scenario "successfully subscribes to a channel" do
|
@@ -57,6 +55,12 @@ feature "Client subscribing to a channel" do
|
|
57
55
|
page.execute_script("Helpers.subscribe(#{MultiJson.dump(channel)})")
|
58
56
|
end
|
59
57
|
|
58
|
+
def connect
|
59
|
+
visit "/"
|
60
|
+
|
61
|
+
expect(page).to have_content("Client connected.")
|
62
|
+
end
|
63
|
+
|
60
64
|
def override_socket_id(value)
|
61
65
|
page.execute_script(
|
62
66
|
"Pusher.instance.connection.socket_id = #{MultiJson.dump(value)};"
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "spec_helper"
|
2
4
|
|
3
5
|
describe PusherFake::Channel::Private do
|
@@ -92,7 +94,7 @@ describe PusherFake::Channel::Private, "#authentication_for" do
|
|
92
94
|
before do
|
93
95
|
allow(PusherFake).to receive(:configuration).and_return(configuration)
|
94
96
|
allow(OpenSSL::HMAC).to receive(:hexdigest).and_return(signature)
|
95
|
-
allow(OpenSSL::Digest
|
97
|
+
allow(OpenSSL::Digest).to receive(:new).with("SHA256").and_return(digest)
|
96
98
|
end
|
97
99
|
|
98
100
|
it "generates a signature" do
|
@@ -127,7 +129,7 @@ describe PusherFake::Channel::Private,
|
|
127
129
|
before do
|
128
130
|
allow(PusherFake).to receive(:configuration).and_return(configuration)
|
129
131
|
allow(OpenSSL::HMAC).to receive(:hexdigest).and_return(signature)
|
130
|
-
allow(OpenSSL::Digest
|
132
|
+
allow(OpenSSL::Digest).to receive(:new).with("SHA256").and_return(digest)
|
131
133
|
end
|
132
134
|
|
133
135
|
it "generates a signature" do
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "spec_helper"
|
2
4
|
|
3
5
|
describe PusherFake::Configuration do
|
@@ -13,7 +15,7 @@ describe PusherFake::Configuration do
|
|
13
15
|
|
14
16
|
it do
|
15
17
|
expect(subject).to have_configuration_option(:logger)
|
16
|
-
.with_default(
|
18
|
+
.with_default($stdout.to_io)
|
17
19
|
end
|
18
20
|
|
19
21
|
it do
|
@@ -88,6 +90,12 @@ describe PusherFake::Configuration, "#to_options" do
|
|
88
90
|
expect(options).to include(cluster: "us-east-1")
|
89
91
|
end
|
90
92
|
|
93
|
+
it "disables the forceTLS option" do
|
94
|
+
options = subject.to_options
|
95
|
+
|
96
|
+
expect(options).to include(forceTLS: false)
|
97
|
+
end
|
98
|
+
|
91
99
|
it "supports passing custom options" do
|
92
100
|
options = subject.to_options(custom: "option")
|
93
101
|
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "spec_helper"
|
2
4
|
|
3
5
|
shared_examples_for "#process" do
|
@@ -95,8 +97,8 @@ end
|
|
95
97
|
describe PusherFake::Connection, "#id" do
|
96
98
|
subject { described_class.new(socket) }
|
97
99
|
|
98
|
-
let(:id) { "
|
99
|
-
let(:socket) { instance_double(Object, object_id:
|
100
|
+
let(:id) { "1234.567" }
|
101
|
+
let(:socket) { instance_double(Object, object_id: 1_234_567) }
|
100
102
|
|
101
103
|
it "returns the object ID of the socket" do
|
102
104
|
expect(subject.id).to eq(id)
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "spec_helper"
|
2
4
|
|
3
5
|
shared_examples_for "an API request" do
|
@@ -210,7 +212,7 @@ describe PusherFake::Server::Application, ".events" do
|
|
210
212
|
let(:data) { { "example" => "data" } }
|
211
213
|
let(:name) { "event-name" }
|
212
214
|
let(:request) { instance_double(Rack::Request, body: body) }
|
213
|
-
let(:channels) {
|
215
|
+
let(:channels) { %w(channel-1 channel-2) }
|
214
216
|
let(:channel_1) { instance_double(PusherFake::Channel::Public, emit: true) }
|
215
217
|
let(:channel_2) { instance_double(PusherFake::Channel::Public, emit: true) }
|
216
218
|
let(:data_json) { data.to_json }
|
@@ -281,7 +283,7 @@ describe PusherFake::Server::Application, ".batch_events" do
|
|
281
283
|
let(:data) { { "example" => "data" } }
|
282
284
|
let(:name) { "event-name" }
|
283
285
|
let(:request) { instance_double(Rack::Request, body: body) }
|
284
|
-
let(:channels) {
|
286
|
+
let(:channels) { %w(channel-1 channel-2) }
|
285
287
|
let(:channel_1) { instance_double(PusherFake::Channel::Public, emit: true) }
|
286
288
|
let(:channel_2) { instance_double(PusherFake::Channel::Public, emit: true) }
|
287
289
|
let(:data_json) { data.to_json }
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "spec_helper"
|
2
4
|
|
3
5
|
describe PusherFake::Webhook, ".trigger" do
|
@@ -31,7 +33,7 @@ describe PusherFake::Webhook, ".trigger" do
|
|
31
33
|
|
32
34
|
before do
|
33
35
|
allow(OpenSSL::HMAC).to receive(:hexdigest).and_return(signature)
|
34
|
-
allow(OpenSSL::Digest
|
36
|
+
allow(OpenSSL::Digest).to receive(:new).with("SHA256").and_return(digest)
|
35
37
|
allow(EventMachine::HttpRequest).to receive(:new).and_return(http)
|
36
38
|
allow(PusherFake).to receive(:log)
|
37
39
|
allow(PusherFake).to receive(:configuration).and_return(configuration)
|