DEV: Use WebPush fork for OpenSSL 3 compat (#19627)

* DEV: Use WebPush fork for OpenSSL 3 compat

* add some context on gemfile changes
This commit is contained in:
Rafael dos Santos Silva 2022-12-27 15:28:13 -03:00 committed by GitHub
parent 598233456d
commit 7b53973bd8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 27 additions and 16 deletions

View File

@ -258,7 +258,9 @@ if ENV["IMPORT"] == "1"
gem 'parallel', require: false gem 'parallel', require: false
end end
gem 'webpush', require: false # workaround for openssl 3.0, see
# https://github.com/pushpad/web-push/pull/2
gem 'web-push', require: false, git: 'https://github.com/xfalcox/web-push', branch: 'openssl-3-compat'
gem 'colored2', require: false gem 'colored2', require: false
gem 'maxminddb' gem 'maxminddb'
@ -271,6 +273,8 @@ gem 'faraday-retry'
# https://github.com/ruby/net-imap/issues/16#issuecomment-803086765 # https://github.com/ruby/net-imap/issues/16#issuecomment-803086765
gem 'net-http' gem 'net-http'
# workaround for prometheus-client
gem 'webrick', require: false gem 'webrick', require: false
# Workaround until Ruby ships with cgi version 0.3.6 or higher.
gem "cgi", ">= 0.3.6", require: false gem "cgi", ">= 0.3.6", require: false

View File

@ -5,6 +5,16 @@ GIT
mail (2.8.0.edge) mail (2.8.0.edge)
mini_mime (>= 0.1.1) mini_mime (>= 0.1.1)
GIT
remote: https://github.com/xfalcox/web-push
revision: 9b1ab768d195908ce478c3a9d7cf05dabfc8ef8c
branch: openssl-3-compat
specs:
web-push (2.1.0)
hkdf (~> 1.0)
jwt (~> 2.0)
openssl (~> 3.0)
GEM GEM
remote: https://rubygems.org/ remote: https://rubygems.org/
specs: specs:
@ -154,7 +164,7 @@ GEM
hashdiff (1.0.1) hashdiff (1.0.1)
hashie (5.0.0) hashie (5.0.0)
highline (2.0.3) highline (2.0.3)
hkdf (0.3.0) hkdf (1.0.0)
htmlentities (4.3.4) htmlentities (4.3.4)
http_accept_language (2.1.1) http_accept_language (2.1.1)
i18n (1.12.0) i18n (1.12.0)
@ -477,9 +487,6 @@ GEM
addressable (>= 2.8.0) addressable (>= 2.8.0)
crack (>= 0.3.2) crack (>= 0.3.2)
hashdiff (>= 0.4.0, < 2.0.0) hashdiff (>= 0.4.0, < 2.0.0)
webpush (1.1.0)
hkdf (~> 0.2)
jwt (~> 2.0)
webrick (1.7.0) webrick (1.7.0)
websocket (1.2.9) websocket (1.2.9)
xorcist (1.1.3) xorcist (1.1.3)
@ -625,9 +632,9 @@ DEPENDENCIES
uglifier uglifier
unf unf
unicorn unicorn
web-push!
webdrivers webdrivers
webmock webmock
webpush
webrick webrick
xorcist xorcist
yaml-lint yaml-lint

View File

@ -121,7 +121,7 @@ class PushNotificationPusher
end end
begin begin
Webpush.payload_send( WebPush.payload_send(
endpoint: endpoint, endpoint: endpoint,
message: message.to_json, message: message.to_json,
p256dh: p256dh, p256dh: p256dh,
@ -140,9 +140,9 @@ class PushNotificationPusher
if subscription.first_error_at || subscription.error_count != 0 if subscription.first_error_at || subscription.error_count != 0
subscription.update_columns(error_count: 0, first_error_at: nil) subscription.update_columns(error_count: 0, first_error_at: nil)
end end
rescue Webpush::ExpiredSubscription rescue WebPush::ExpiredSubscription
subscription.destroy! subscription.destroy!
rescue Webpush::ResponseError => e rescue WebPush::ResponseError => e
if e.response.message == "MismatchSenderId" if e.response.message == "MismatchSenderId"
subscription.destroy! subscription.destroy!
else else

View File

@ -3,7 +3,7 @@
return if GlobalSetting.skip_db? return if GlobalSetting.skip_db?
Rails.application.config.to_prepare do Rails.application.config.to_prepare do
require 'webpush' require 'web-push'
def generate_vapid_key? def generate_vapid_key?
SiteSetting.vapid_public_key.blank? || SiteSetting.vapid_public_key.blank? ||
@ -15,7 +15,7 @@ Rails.application.config.to_prepare do
SiteSetting.vapid_base_url = Discourse.base_url if SiteSetting.vapid_base_url.blank? SiteSetting.vapid_base_url = Discourse.base_url if SiteSetting.vapid_base_url.blank?
if generate_vapid_key? if generate_vapid_key?
vapid_key = Webpush.generate_key vapid_key = WebPush.generate_key
SiteSetting.vapid_public_key = vapid_key.public_key SiteSetting.vapid_public_key = vapid_key.public_key
SiteSetting.vapid_private_key = vapid_key.private_key SiteSetting.vapid_private_key = vapid_key.private_key

View File

@ -57,7 +57,7 @@ RSpec.describe PushNotificationPusher do
TranslationOverride.upsert!("pt_BR", "discourse_push_notifications.popup.mentioned", "pt_BR notification") TranslationOverride.upsert!("pt_BR", "discourse_push_notifications.popup.mentioned", "pt_BR notification")
Webpush.expects(:payload_send).with do |*args| WebPush.expects(:payload_send).with do |*args|
JSON.parse(args.first[:message])["title"] == "pt_BR notification" JSON.parse(args.first[:message])["title"] == "pt_BR notification"
end.once end.once
@ -71,9 +71,9 @@ RSpec.describe PushNotificationPusher do
sub = create_subscription sub = create_subscription
response = Struct.new(:body, :inspect, :message).new("test", "test", "failed") response = Struct.new(:body, :inspect, :message).new("test", "test", "failed")
error = Webpush::ResponseError.new(response, "localhost") error = WebPush::ResponseError.new(response, "localhost")
Webpush.expects(:payload_send).raises(error).times(4) WebPush.expects(:payload_send).raises(error).times(4)
# 3 failures in more than 24 hours # 3 failures in more than 24 hours
3.times do 3.times do
@ -107,7 +107,7 @@ RSpec.describe PushNotificationPusher do
{ endpoint: "endpoint 3", keys: { p256dh: "public ECDH key", auth: "private ECDH key" } }.to_json) { endpoint: "endpoint 3", keys: { p256dh: "public ECDH key", auth: "private ECDH key" } }.to_json)
expect(PushSubscription.where(user_id: user.id)).to contain_exactly(missing_endpoint, missing_p256dh, missing_auth, valid_subscription) expect(PushSubscription.where(user_id: user.id)).to contain_exactly(missing_endpoint, missing_p256dh, missing_auth, valid_subscription)
Webpush.expects(:payload_send).with(has_entries(endpoint: "endpoint 3", p256dh: "public ECDH key", auth: "private ECDH key")).once WebPush.expects(:payload_send).with(has_entries(endpoint: "endpoint 3", p256dh: "public ECDH key", auth: "private ECDH key")).once
execute_push execute_push
@ -115,7 +115,7 @@ RSpec.describe PushNotificationPusher do
end end
it "handles timeouts" do it "handles timeouts" do
Webpush.expects(:payload_send).raises(Net::ReadTimeout.new) WebPush.expects(:payload_send).raises(Net::ReadTimeout.new)
subscription = create_subscription subscription = create_subscription
expect { execute_push }.to_not raise_exception expect { execute_push }.to_not raise_exception