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.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/bin/pusher-fake +1 -3
  3. data/lib/pusher-fake.rb +3 -1
  4. data/lib/pusher-fake/channel.rb +4 -2
  5. data/lib/pusher-fake/channel/presence.rb +3 -3
  6. data/lib/pusher-fake/channel/private.rb +3 -1
  7. data/lib/pusher-fake/channel/public.rb +2 -0
  8. data/lib/pusher-fake/configuration.rb +4 -1
  9. data/lib/pusher-fake/connection.rb +10 -7
  10. data/lib/pusher-fake/server.rb +2 -0
  11. data/lib/pusher-fake/server/application.rb +4 -2
  12. data/lib/pusher-fake/support/base.rb +4 -2
  13. data/lib/pusher-fake/support/cucumber.rb +2 -0
  14. data/lib/pusher-fake/support/rspec.rb +2 -0
  15. data/lib/pusher-fake/webhook.rb +3 -1
  16. data/spec/features/api/channels_spec.rb +2 -0
  17. data/spec/features/api/users_spec.rb +2 -0
  18. data/spec/features/client/connect_spec.rb +2 -0
  19. data/spec/features/client/event_spec.rb +2 -0
  20. data/spec/features/client/presence_spec.rb +2 -0
  21. data/spec/features/client/subscribe_spec.rb +9 -5
  22. data/spec/features/server/event_spec.rb +2 -0
  23. data/spec/features/server/webhooks_spec.rb +2 -0
  24. data/spec/lib/pusher-fake/channel/presence_spec.rb +2 -0
  25. data/spec/lib/pusher-fake/channel/private_spec.rb +4 -2
  26. data/spec/lib/pusher-fake/channel/public_spec.rb +2 -0
  27. data/spec/lib/pusher-fake/channel_spec.rb +2 -0
  28. data/spec/lib/pusher-fake/configuration_spec.rb +9 -1
  29. data/spec/lib/pusher-fake/connection_spec.rb +4 -2
  30. data/spec/lib/pusher-fake/server/application_spec.rb +4 -2
  31. data/spec/lib/pusher-fake/server_spec.rb +2 -0
  32. data/spec/lib/pusher-fake/webhook_spec.rb +3 -1
  33. data/spec/lib/pusher_fake_spec.rb +2 -0
  34. data/spec/spec_helper.rb +3 -1
  35. data/spec/support/application.rb +3 -1
  36. data/spec/support/application/public/javascripts/vendor/polyfill.min.js +1 -0
  37. data/spec/support/application/public/javascripts/vendor/pusher-7.0.0.js +4565 -0
  38. data/spec/support/application/views/index.erb +2 -1
  39. data/spec/support/capybara.rb +4 -7
  40. data/spec/support/coveralls.rb +2 -0
  41. data/spec/support/helpers/connect.rb +2 -0
  42. data/spec/support/helpers/event.rb +2 -0
  43. data/spec/support/helpers/subscription.rb +2 -0
  44. data/spec/support/helpers/user.rb +2 -0
  45. data/spec/support/matchers/have_configuration_option.rb +2 -0
  46. data/spec/support/pusher_fake.rb +3 -1
  47. data/spec/support/webhooks.rb +17 -15
  48. metadata +104 -47
  49. data/lib/pusher-fake/cucumber.rb +0 -4
  50. 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: 0fb8ba630f2ac529c445616e37b0aede14ebb36ea1698c8014e93f8cb235fb6e
4
- data.tar.gz: 374f57795f1fe563a64d3abf9baa0eaf9debeecec203c49a5e8a4f5d155a9ed1
3
+ metadata.gz: '09cf8cbf09383dbf9ca8829c07e67da46721965a6e226e76205a92329c55b8a1'
4
+ data.tar.gz: 0b3d172aa3c5f86c507eab2a3c71177287145ae5b819b323a26c500e2c8ef423
5
5
  SHA512:
6
- metadata.gz: 3cf72af652796b675ecfe0c9f0b930018d1e8381096d85e8296c7649503d5916f3282df9aca7aa3ffeb2e6dbdd968db3ad4c56d997c79be54d5f971144eb7aa3
7
- data.tar.gz: 27c01757983cc5c3d07f6a728dddad2948636222ea580b64341dd7691e48aab023c60d43caefa89e4bf56c9c777b8397841d147ef59c363f1fe1f4d2469ec16c
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
- # rubocop:disable Metrics/BlockLength, Metrics/LineLength
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 = "1.12.0".freeze
12
+ VERSION = "3.0.0"
11
13
 
12
14
  autoload :Channel, "pusher-fake/channel"
13
15
  autoload :Configuration, "pusher-fake/configuration"
@@ -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-".freeze
11
+ PRIVATE_CHANNEL_PREFIX = "private-"
10
12
 
11
13
  # Prefix for presence channels.
12
- PRESENCE_CHANNEL_PREFIX = "presence-".freeze
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 = 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::SHA256.new
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
  module Channel
3
5
  # A public channel.
@@ -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 = STDOUT.to_io
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-".freeze
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.split("")
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(""), parts.last.join("")].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
- if event == "pusher:subscribe"
72
+ case event
73
+ when "pusher:subscribe"
71
74
  channel_for(message).add(self, message[:data])
72
- elsif event == "pusher:unsubscribe"
75
+ when "pusher:unsubscribe"
73
76
  channel_for(message).remove(self)
74
- elsif event == "pusher:ping"
77
+ when "pusher:ping"
75
78
  emit("pusher:pong")
76
79
  end
77
80
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module PusherFake
2
4
  # Socket and web server manager.
3
5
  module Server
@@ -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-".freeze
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".freeze
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
- fork { PusherFake::Server.start }.tap do |id|
28
- at_exit { Process.kill("KILL", id) }
29
+ Thread.new { PusherFake::Server.start }.tap do |thread|
30
+ at_exit { Thread.kill(thread) }
29
31
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "pusher-fake/support/base"
2
4
 
3
5
  # Reset channels between scenarios.
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "pusher-fake/support/base"
2
4
 
3
5
  # Reset channels between examples
@@ -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::SHA256.new
31
+ digest = OpenSSL::Digest.new("SHA256")
30
32
  secret = PusherFake.configuration.secret
31
33
 
32
34
  OpenSSL::HMAC.hexdigest(digest, secret, payload)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "spec_helper"
2
4
 
3
5
  feature "Requesting channel API endpoint" do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "spec_helper"
2
4
 
3
5
  feature "Requesting user API endpoint" do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "spec_helper"
2
4
 
3
5
  feature "Client connecting to the server" do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "spec_helper"
2
4
 
3
5
  feature "Client triggers a client event" do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "spec_helper"
2
4
 
3
5
  feature "Client on a presence channel" do
@@ -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
- visit "/"
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
  feature "Server triggers event" do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "spec_helper"
2
4
 
3
5
  feature "Receiving event webhooks" do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "spec_helper"
2
4
 
3
5
  describe PusherFake::Channel::Presence do
@@ -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::SHA256).to receive(:new).and_return(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::SHA256).to receive(:new).and_return(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::Channel::Public do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "spec_helper"
2
4
 
3
5
  describe PusherFake::Channel, ".factory" 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(STDOUT.to_io)
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) { "123.456" }
99
- let(:socket) { instance_double(Object, object_id: 123_456) }
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) { ["channel-1", "channel-2"] }
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) { ["channel-1", "channel-2"] }
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::Server, ".start" do
@@ -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::SHA256).to receive(:new).and_return(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)