From c2b0584713d7708986edfc84e2d2b20e8c4f064d Mon Sep 17 00:00:00 2001 From: Stephen Paul Weber Date: Wed, 13 Jul 2022 09:36:10 -0500 Subject: [PATCH] Update to latest blather upstream Which has merged our changes --- Gemfile | 2 +- lib/admin_command.rb | 4 ++- lib/backend_sgx.rb | 8 +++--- lib/customer.rb | 1 - lib/ibr.rb | 59 --------------------------------------- lib/ibr_repo.rb | 5 ++-- sgx_jmp.rb | 3 +- test/test_backend_sgx.rb | 8 ++++-- test/test_ibr.rb | 38 ------------------------- test/test_registration.rb | 8 ++++-- test/test_web.rb | 28 +++++++++++-------- 11 files changed, 38 insertions(+), 126 deletions(-) delete mode 100644 lib/ibr.rb delete mode 100644 test/test_ibr.rb diff --git a/Gemfile b/Gemfile index e1424ee..14c2be4 100644 --- a/Gemfile +++ b/Gemfile @@ -4,7 +4,7 @@ source "https://rubygems.org" gem "amazing_print" gem "bandwidth-sdk", "<= 6.1.0" -gem "blather", git: "https://github.com/singpolyma/blather.git", branch: "ergonomics" +gem "blather", git: "https://github.com/adhearsion/blather", branch: "develop" gem "braintree" gem "dhall", ">= 0.5.3.fixed" gem "em-hiredis" diff --git a/lib/admin_command.rb b/lib/admin_command.rb index 627c5bb..ac7659b 100644 --- a/lib/admin_command.rb +++ b/lib/admin_command.rb @@ -85,7 +85,9 @@ class AdminCommand def action_cancel_account notify_customer("Your JMP account has been cancelled.").then { EMPromise.all([ - @target_customer.stanza_to(IBR.new(:set).tap(&:remove!)), + @target_customer.stanza_to( + Blather::Stanza::Iq::IBR.new(:set).tap(&:remove!) + ), @target_customer.deregister!, @customer_repo.disconnect_tel(@target_customer) ]) diff --git a/lib/backend_sgx.rb b/lib/backend_sgx.rb index d66290c..7f58711 100644 --- a/lib/backend_sgx.rb +++ b/lib/backend_sgx.rb @@ -1,9 +1,9 @@ # frozen_string_literal: true +require "blather" require "value_semantics/monkey_patched" require_relative "customer_fwd" -require_relative "ibr" require_relative "not_loaded" class BackendSgx @@ -15,11 +15,11 @@ class BackendSgx fwd Either(CustomerFwd, nil, NotLoaded) transcription_enabled Either(Bool(), NotLoaded) alternate_transcription_enabled Either(Bool(), NotLoaded) - registered? Either(IBR, FalseClass, NotLoaded) + registered? Either(Blather::Stanza::Iq::IBR, FalseClass, NotLoaded) end def register!(tel) - ibr = IBR.new(:set, @jid) + ibr = Blather::Stanza::Iq::IBR.new(:set, @jid) ibr.from = from_jid ibr.nick = creds[:account] ibr.username = creds[:username] @@ -29,7 +29,7 @@ class BackendSgx end def deregister! - ibr = IBR.new(:set, @jid) + ibr = Blather::Stanza::Iq::IBR.new(:set, @jid) ibr.from = from_jid ibr.remove! IQ_MANAGER.write(ibr) diff --git a/lib/customer.rb b/lib/customer.rb index 1384570..0729e8b 100644 --- a/lib/customer.rb +++ b/lib/customer.rb @@ -10,7 +10,6 @@ require_relative "./customer_ogm" require_relative "./customer_info" require_relative "./customer_finacials" require_relative "./backend_sgx" -require_relative "./ibr" require_relative "./payment_methods" require_relative "./plan" require_relative "./proxied_jid" diff --git a/lib/ibr.rb b/lib/ibr.rb deleted file mode 100644 index f8fe33a..0000000 --- a/lib/ibr.rb +++ /dev/null @@ -1,59 +0,0 @@ -# frozen_string_literal: true - -require "blather" - -class IBR < Blather::Stanza::Iq::Query - register :ibr, nil, "jabber:iq:register" - - def registered=(reg) - query.at_xpath("./ns:registered", ns: self.class.registered_ns)&.remove - node = Nokogiri::XML::Node.new("registered", document) - node.default_namespace = self.class.registered_ns - query << node if reg - end - - def registered? - !!query.at_xpath("./ns:registered", ns: self.class.registered_ns) - end - - def remove! - query.children.remove - node = Nokogiri::XML::Node.new("remove", document) - node.default_namespace = self.class.registered_ns - query << node - end - - def remove? - !!query.at_xpath("./ns:remove", ns: self.class.registered_ns) - end - - [ - "instructions", - "username", - "nick", - "password", - "name", - "first", - "last", - "email", - "address", - "city", - "state", - "zip", - "phone", - "url", - "date" - ].each do |tag| - define_method("#{tag}=") do |v| - query.at_xpath("./ns:#{tag}", ns: self.class.registered_ns)&.remove - node = Nokogiri::XML::Node.new(tag, document) - node.default_namespace = self.class.registered_ns - node.content = v - query << node - end - - define_method(tag) do - query.at_xpath("./ns:#{tag}", ns: self.class.registered_ns)&.content - end - end -end diff --git a/lib/ibr_repo.rb b/lib/ibr_repo.rb index 22faa6c..fb0ae9c 100644 --- a/lib/ibr_repo.rb +++ b/lib/ibr_repo.rb @@ -1,17 +1,16 @@ # frozen_string_literal: true +require "blather" require "lazy_object" require "value_semantics/monkey_patched" -require_relative "ibr" - class IBRRepo value_semantics do iq_manager Anything(), default: LazyObject.new { IQ_MANAGER } end def registered?(jid, from:) - ibr = IBR.new(:get, jid) + ibr = Blather::Stanza::Iq::IBR.new(:get, jid) ibr.from = from iq_manager.write(ibr).then do |result| diff --git a/sgx_jmp.rb b/sgx_jmp.rb index b585d75..a402a2f 100644 --- a/sgx_jmp.rb +++ b/sgx_jmp.rb @@ -250,7 +250,6 @@ when_ready do Web.run(LOG.child, *WEB_LISTEN) end -# workqueue_count MUST be 0 or else Blather uses threads! setup( CONFIG[:component][:jid], CONFIG[:component][:secret], @@ -258,7 +257,7 @@ setup( CONFIG[:server][:port], nil, nil, - workqueue_count: 0 + async: true ) message to: /\Aaccount@/, body: /./ do |m| diff --git a/test/test_backend_sgx.rb b/test/test_backend_sgx.rb index 361ddc4..9f58da5 100644 --- a/test/test_backend_sgx.rb +++ b/test/test_backend_sgx.rb @@ -12,7 +12,9 @@ class BackendSgxTest < Minitest::Test def test_registered IBRRepo::IQ_MANAGER.expect( :write, - EMPromise.resolve(IBR.new.tap { |ibr| ibr.registered = true }), + EMPromise.resolve(Blather::Stanza::Iq::IBR.new.tap { |ibr| + ibr.registered = true + }), [Matching.new do |ibr| assert_equal :get, ibr.type assert_equal "customer_test@component", ibr.from.to_s @@ -26,7 +28,9 @@ class BackendSgxTest < Minitest::Test def test_registered_not_registered IBRRepo::IQ_MANAGER.expect( :write, - EMPromise.resolve(IBR.new.tap { |ibr| ibr.registered = false }), + EMPromise.resolve(Blather::Stanza::Iq::IBR.new.tap { |ibr| + ibr.registered = false + }), [Matching.new do |ibr| assert_equal :get, ibr.type assert_equal "customer_test@component", ibr.from.to_s diff --git a/test/test_ibr.rb b/test/test_ibr.rb deleted file mode 100644 index a64eb36..0000000 --- a/test/test_ibr.rb +++ /dev/null @@ -1,38 +0,0 @@ -# frozen_string_literal: true - -require "test_helper" -require "ibr" - -class IBRTest < Minitest::Test - property(:registered) { boolean } - def registered(val) - ibr = IBR.new - ibr.registered = val - assert_equal val, ibr.registered? - end - - { - instructions: :string, - username: :string, - nick: :string, - password: :string, - name: :string, - first: :string, - last: :string, - email: :string, - address: :string, - city: :string, - state: :string, - zip: :string, - phone: [:string, :digit], - url: :string, - date: ->(*) { Time.at(range(0, 4294967295)).iso8601 } - }.each do |prop, type| - property("prop_#{prop}") { call(type) } - define_method("prop_#{prop}") do |val| - ibr = IBR.new - ibr.public_send("#{prop}=", val) - assert_equal val, ibr.public_send(prop) - end - end -end diff --git a/test/test_registration.rb b/test/test_registration.rb index fb68154..8a150e8 100644 --- a/test/test_registration.rb +++ b/test/test_registration.rb @@ -725,9 +725,11 @@ class RegistrationTest < Minitest::Test execute_command(blather: blather) do @sgx.expect( :register!, - EMPromise.resolve(@sgx.with(registered?: IBR.new.tap do |ibr| - ibr.phone = "+15555550000" - end)), + EMPromise.resolve(@sgx.with( + registered?: Blather::Stanza::Iq::IBR.new.tap do |ibr| + ibr.phone = "+15555550000" + end + )), ["+15555550000"] ) diff --git a/test/test_web.rb b/test/test_web.rb index ab2f5be..a675d96 100644 --- a/test/test_web.rb +++ b/test/test_web.rb @@ -62,18 +62,22 @@ class WebTest < Minitest::Test ), ibr_repo: FakeIBRRepo.new( "sgx" => { - "customer_customerid@component" => IBR.new.tap do |ibr| - ibr.phone = "+15551234567" - end, - "customer_customerid_low@component" => IBR.new.tap do |ibr| - ibr.phone = "+15551234567" - end, - "customer_customerid_topup@component" => IBR.new.tap do |ibr| - ibr.phone = "+15551234567" - end, - "customer_customerid_limit@component" => IBR.new.tap do |ibr| - ibr.phone = "+15551234567" - end + "customer_customerid@component" => + Blather::Stanza::Iq::IBR.new.tap do |ibr| + ibr.phone = "+15551234567" + end, + "customer_customerid_low@component" => + Blather::Stanza::Iq::IBR.new.tap do |ibr| + ibr.phone = "+15551234567" + end, + "customer_customerid_topup@component" => + Blather::Stanza::Iq::IBR.new.tap do |ibr| + ibr.phone = "+15551234567" + end, + "customer_customerid_limit@component" => + Blather::Stanza::Iq::IBR.new.tap do |ibr| + ibr.phone = "+15551234567" + end } ) ) -- 2.45.2