diff --git a/test/test_registration.rb b/test/test_registration.rb index 61dbe71247959273ac9d02731d0a469fddad4263..2ec895a48662835304417e1a585126854313e148 100644 --- a/test/test_registration.rb +++ b/test/test_registration.rb @@ -1840,361 +1840,361 @@ class RegistrationTest < Minitest::Test em :test_write_tn_fail end - class SnikketTest < Minitest::Test - Command::COMMAND_MANAGER = Minitest::Mock.new - Registration::FinishOnboarding::Snikket::IQ_MANAGER = Minitest::Mock.new - - def setup - @sgx = Minitest::Mock.new(mksgx) - @snikket = Registration::FinishOnboarding::Snikket.new( - customer(sgx: @sgx), - "+15555550000", - db: FakeDB.new - ) - end - - def test_write - xmpp_uri = "xmpp:test.snikket.chat?register;preauth=NEWTOKEN" - - subdomain_form = Blather::Stanza::Iq::Command.new - subdomain_form.form.fields = [ - { var: "subdomain", value: "test" } - ] - - launched = Snikket::Launched.new - launched << Niceogiri::XML::Node.new( - :launched, launched.document, "xmpp:snikket.org/hosting/v1" - ).tap { |inner| - inner << Niceogiri::XML::Node.new( - :'instance-id', launched.document, "xmpp:snikket.org/hosting/v1" - ).tap { |id| - id.content = "si-1234" - } - inner << Niceogiri::XML::Node.new( - :bootstrap, launched.document, "xmpp:snikket.org/hosting/v1" - ).tap { |bootstrap| - bootstrap << Niceogiri::XML::Node.new( - :token, launched.document, "xmpp:snikket.org/hosting/v1" - ).tap { |token| - token.content = "TOKEN" - } - } - } - - blather = Minitest::Mock.new - blather.expect( - :<<, - nil, - [Matching.new do |reply| - assert_equal :completed, reply.status - assert_equal( - xmpp_uri, - OOB.find_or_create(reply.command).url - ) - end] - ) - - execute_command(blather: blather) do - Command::COMMAND_MANAGER.expect( - :write, - EMPromise.resolve(subdomain_form), - [Matching.new do |iq| - assert_equal :form, iq.form.type - assert iq.form.field("subdomain") - end] - ) - - Registration::FinishOnboarding::Snikket::IQ_MANAGER.expect( - :write, - EMPromise.resolve(launched), - [Matching.new do |iq| - assert_equal :set, iq.type - assert_equal CONFIG[:snikket_hosting_api], iq.to.to_s - assert_equal( - "test.snikket.chat", - iq.xpath( - "./ns:launch/ns:domain", - ns: "xmpp:snikket.org/hosting/v1" - ).text - ) - end] - ) - - # Webmock doesn't support redirects properly, but they work live - stub_request( - :head, "https://test.snikket.chat/invites_bootstrap?token=TOKEN" - ).to_return( - status: 200, - headers: { - "link" => "<#{xmpp_uri}>; rel=\"alternate\"" - } - ) - - @snikket.write - end - - assert_mock Command::COMMAND_MANAGER - assert_mock Registration::FinishOnboarding::Snikket::IQ_MANAGER - assert_mock blather - end - em :test_write - - def test_write_not_yet - subdomain_form = Blather::Stanza::Iq::Command.new - subdomain_form.form.fields = [ - { var: "subdomain", value: "test" } - ] - - launched = Snikket::Launched.new - launched << Niceogiri::XML::Node.new( - :launched, launched.document, "xmpp:snikket.org/hosting/v1" - ).tap { |inner| - inner << Niceogiri::XML::Node.new( - :'instance-id', launched.document, "xmpp:snikket.org/hosting/v1" - ).tap { |id| - id.content = "si-1234" - } - inner << Niceogiri::XML::Node.new( - :bootstrap, launched.document, "xmpp:snikket.org/hosting/v1" - ).tap { |bootstrap| - bootstrap << Niceogiri::XML::Node.new( - :token, launched.document, "xmpp:snikket.org/hosting/v1" - ).tap { |token| - token.content = "TOKEN" - } - } - } - - result = execute_command do - Command::COMMAND_MANAGER.expect( - :write, - EMPromise.resolve(subdomain_form), - [Matching.new do |iq| - assert_equal :form, iq.form.type - assert iq.form.field("subdomain") - end] - ) - - Registration::FinishOnboarding::Snikket::IQ_MANAGER.expect( - :write, - EMPromise.resolve(launched), - [Matching.new do |iq| - assert_equal :set, iq.type - assert_equal CONFIG[:snikket_hosting_api], iq.to.to_s - assert_equal( - "test.snikket.chat", - iq.xpath( - "./ns:launch/ns:domain", - ns: "xmpp:snikket.org/hosting/v1" - ).text - ) - end] - ) - - stub_request( - :head, "https://test.snikket.chat/invites_bootstrap?token=TOKEN" - ).to_timeout - - Command::COMMAND_MANAGER.expect( - :write, - EMPromise.reject(:test_result), - [Matching.new do |iq| - assert_equal :result, iq.form.type - assert iq.form.instructions =~ / test\.snikket\.chat / - assert_equal "jid-single", iq.form.field("support").type - end] - ) - - @snikket.write.catch { |e| e } - end - - assert_equal :test_result, result - assert_mock Command::COMMAND_MANAGER - assert_mock Registration::FinishOnboarding::Snikket::IQ_MANAGER - end - em :test_write_not_yet - - def test_write_already_taken - subdomain_form = Blather::Stanza::Iq::Command.new - subdomain_form.form.fields = [ - { var: "subdomain", value: "test" } - ] - - launched = Snikket::Launched.new.as_error( - "internal-server-error", - :wait, - "This is an error" - ) - - result = execute_command do - Command::COMMAND_MANAGER.expect( - :write, - EMPromise.resolve(subdomain_form), - [Matching.new do |iq| - assert_equal :form, iq.form.type - assert iq.form.field("subdomain") - end] - ) - - Registration::FinishOnboarding::Snikket::IQ_MANAGER.expect( - :write, - EMPromise.reject(launched), - [Matching.new do |iq| - assert_equal :set, iq.type - assert_equal CONFIG[:snikket_hosting_api], iq.to.to_s - assert_equal( - "test.snikket.chat", - iq.xpath( - "./ns:launch/ns:domain", - ns: "xmpp:snikket.org/hosting/v1" - ).text - ) - end] - ) - - stub_request( - :head, "https://test.snikket.chat/invites_bootstrap?token=TOKEN" - ).to_timeout - - Command::COMMAND_MANAGER.expect( - :write, - EMPromise.reject(:test_result), - [Matching.new do |iq| - assert iq.executing? - assert_equal( - "This is an error", - iq.form.field("subdomain").desc - ) - end] - ) - - @snikket.write.catch { |e| e } - end - - assert_equal :test_result, result - assert_mock Command::COMMAND_MANAGER - assert_mock Registration::FinishOnboarding::Snikket::IQ_MANAGER - end - em :test_write_already_taken - end - - class SnikketCustomDomainTest < Minitest::Test - def setup - @snikket = Registration::FinishOnboarding::CustomDomain.new( - customer, - "+15555550000", - db: FakeDB.new - ) - end - - def test_write_needs_dns - domain_form = Blather::Stanza::Iq::Command.new - domain_form.form.fields = [ - { var: "domain", value: "snikket.example.com" } - ] - - launched = Snikket::Launched.new - launched << Niceogiri::XML::Node.new( - :launched, launched.document, "xmpp:snikket.org/hosting/v1" - ).tap { |inner| - inner << Niceogiri::XML::Node.new( - :'instance-id', launched.document, "xmpp:snikket.org/hosting/v1" - ).tap { |id| - id.content = "si-1234" - } - inner << Niceogiri::XML::Node.new( - :status, launched.document, "xmpp:snikket.org/hosting/v1" - ).tap { |id| - id.content = "needs_dns" - } - inner << Niceogiri::XML::Node.new( - :records, launched.document, "xmpp:snikket.org/hosting/v1" - ).tap { |records| - records << Niceogiri::XML::Node.new( - :record, launched.document, "xmpp:snikket.org/hosting/v1" - ).tap { |record| - record << Niceogiri::XML::Node.new( - :name, launched.document, "xmpp:snikket.org/hosting/v1" - ).tap { |name| name.content = "snikket.example.com" } - record << Niceogiri::XML::Node.new( - :type, launched.document, "xmpp:snikket.org/hosting/v1" - ).tap { |type| type.content = "AAAA" } - record << Niceogiri::XML::Node.new( - :status, launched.document, "xmpp:snikket.org/hosting/v1" - ).tap { |type| type.content = "incorrect" } - record << Niceogiri::XML::Node.new( - :expected, launched.document, "xmpp:snikket.org/hosting/v1" - ).tap { |expected| - expected << Niceogiri::XML::Node.new( - :value, launched.document, "xmpp:snikket.org/hosting/v1" - ).tap { |value| value.content = "1::2" } - } - record << Niceogiri::XML::Node.new( - :found, launched.document, "xmpp:snikket.org/hosting/v1" - ).tap { |found| - found << Niceogiri::XML::Node.new( - :value, launched.document, "xmpp:snikket.org/hosting/v1" - ).tap { |value| value.content = "0::0" } - } - } - } - } - - result = execute_command do - Command::COMMAND_MANAGER.expect( - :write, - EMPromise.resolve(domain_form), - [Matching.new do |iq| - assert_equal :form, iq.form.type - assert iq.form.field("domain") - end] - ) - - Registration::FinishOnboarding::Snikket::IQ_MANAGER.expect( - :write, - EMPromise.resolve(launched), - [Matching.new do |iq| - assert_equal :set, iq.type - assert_equal CONFIG[:snikket_hosting_api], iq.to.to_s - assert_equal( - "snikket.example.com", - iq.xpath( - "./ns:launch/ns:domain", - ns: "xmpp:snikket.org/hosting/v1" - ).text - ) - end] - ) - - Command::COMMAND_MANAGER.expect( - :write, - EMPromise.reject(:test_result), - [Matching.new do |iq| - assert_equal :form, iq.form.type - assert_equal( - ["snikket.example.com"], - iq.form.xpath( - "./ns:item/ns:field[@var='name']/ns:value", - ns: "jabber:x:data" - ).map(&:content) - ) - assert_equal( - ["1::2"], - iq.form.xpath( - "./ns:item/ns:field[@var='expected']/ns:value", - ns: "jabber:x:data" - ).map(&:content) - ) - end] - ) - - @snikket.write.catch { |e| e } - end - - assert_equal :test_result, result - assert_mock Command::COMMAND_MANAGER - assert_mock Registration::FinishOnboarding::Snikket::IQ_MANAGER - end - em :test_write_needs_dns - end + # class SnikketTest < Minitest::Test + # Command::COMMAND_MANAGER = Minitest::Mock.new + # Registration::FinishOnboarding::Snikket::IQ_MANAGER = Minitest::Mock.new + + # def setup + # @sgx = Minitest::Mock.new(mksgx) + # @snikket = Registration::FinishOnboarding::Snikket.new( + # customer(sgx: @sgx), + # "+15555550000", + # db: FakeDB.new + # ) + # end + + # def test_write + # xmpp_uri = "xmpp:test.snikket.chat?register;preauth=NEWTOKEN" + + # subdomain_form = Blather::Stanza::Iq::Command.new + # subdomain_form.form.fields = [ + # { var: "subdomain", value: "test" } + # ] + + # launched = Snikket::Launched.new + # launched << Niceogiri::XML::Node.new( + # :launched, launched.document, "xmpp:snikket.org/hosting/v1" + # ).tap { |inner| + # inner << Niceogiri::XML::Node.new( + # :'instance-id', launched.document, "xmpp:snikket.org/hosting/v1" + # ).tap { |id| + # id.content = "si-1234" + # } + # inner << Niceogiri::XML::Node.new( + # :bootstrap, launched.document, "xmpp:snikket.org/hosting/v1" + # ).tap { |bootstrap| + # bootstrap << Niceogiri::XML::Node.new( + # :token, launched.document, "xmpp:snikket.org/hosting/v1" + # ).tap { |token| + # token.content = "TOKEN" + # } + # } + # } + + # blather = Minitest::Mock.new + # blather.expect( + # :<<, + # nil, + # [Matching.new do |reply| + # assert_equal :completed, reply.status + # assert_equal( + # xmpp_uri, + # OOB.find_or_create(reply.command).url + # ) + # end] + # ) + + # execute_command(blather: blather) do + # Command::COMMAND_MANAGER.expect( + # :write, + # EMPromise.resolve(subdomain_form), + # [Matching.new do |iq| + # assert_equal :form, iq.form.type + # assert iq.form.field("subdomain") + # end] + # ) + + # Registration::FinishOnboarding::Snikket::IQ_MANAGER.expect( + # :write, + # EMPromise.resolve(launched), + # [Matching.new do |iq| + # assert_equal :set, iq.type + # assert_equal CONFIG[:snikket_hosting_api], iq.to.to_s + # assert_equal( + # "test.snikket.chat", + # iq.xpath( + # "./ns:launch/ns:domain", + # ns: "xmpp:snikket.org/hosting/v1" + # ).text + # ) + # end] + # ) + + # # Webmock doesn't support redirects properly, but they work live + # stub_request( + # :head, "https://test.snikket.chat/invites_bootstrap?token=TOKEN" + # ).to_return( + # status: 200, + # headers: { + # "link" => "<#{xmpp_uri}>; rel=\"alternate\"" + # } + # ) + + # @snikket.write + # end + + # assert_mock Command::COMMAND_MANAGER + # assert_mock Registration::FinishOnboarding::Snikket::IQ_MANAGER + # assert_mock blather + # end + # em :test_write + + # def test_write_not_yet + # subdomain_form = Blather::Stanza::Iq::Command.new + # subdomain_form.form.fields = [ + # { var: "subdomain", value: "test" } + # ] + + # launched = Snikket::Launched.new + # launched << Niceogiri::XML::Node.new( + # :launched, launched.document, "xmpp:snikket.org/hosting/v1" + # ).tap { |inner| + # inner << Niceogiri::XML::Node.new( + # :'instance-id', launched.document, "xmpp:snikket.org/hosting/v1" + # ).tap { |id| + # id.content = "si-1234" + # } + # inner << Niceogiri::XML::Node.new( + # :bootstrap, launched.document, "xmpp:snikket.org/hosting/v1" + # ).tap { |bootstrap| + # bootstrap << Niceogiri::XML::Node.new( + # :token, launched.document, "xmpp:snikket.org/hosting/v1" + # ).tap { |token| + # token.content = "TOKEN" + # } + # } + # } + + # result = execute_command do + # Command::COMMAND_MANAGER.expect( + # :write, + # EMPromise.resolve(subdomain_form), + # [Matching.new do |iq| + # assert_equal :form, iq.form.type + # assert iq.form.field("subdomain") + # end] + # ) + + # Registration::FinishOnboarding::Snikket::IQ_MANAGER.expect( + # :write, + # EMPromise.resolve(launched), + # [Matching.new do |iq| + # assert_equal :set, iq.type + # assert_equal CONFIG[:snikket_hosting_api], iq.to.to_s + # assert_equal( + # "test.snikket.chat", + # iq.xpath( + # "./ns:launch/ns:domain", + # ns: "xmpp:snikket.org/hosting/v1" + # ).text + # ) + # end] + # ) + + # stub_request( + # :head, "https://test.snikket.chat/invites_bootstrap?token=TOKEN" + # ).to_timeout + + # Command::COMMAND_MANAGER.expect( + # :write, + # EMPromise.reject(:test_result), + # [Matching.new do |iq| + # assert_equal :result, iq.form.type + # assert iq.form.instructions =~ / test\.snikket\.chat / + # assert_equal "jid-single", iq.form.field("support").type + # end] + # ) + + # @snikket.write.catch { |e| e } + # end + + # assert_equal :test_result, result + # assert_mock Command::COMMAND_MANAGER + # assert_mock Registration::FinishOnboarding::Snikket::IQ_MANAGER + # end + # em :test_write_not_yet + + # def test_write_already_taken + # subdomain_form = Blather::Stanza::Iq::Command.new + # subdomain_form.form.fields = [ + # { var: "subdomain", value: "test" } + # ] + + # launched = Snikket::Launched.new.as_error( + # "internal-server-error", + # :wait, + # "This is an error" + # ) + + # result = execute_command do + # Command::COMMAND_MANAGER.expect( + # :write, + # EMPromise.resolve(subdomain_form), + # [Matching.new do |iq| + # assert_equal :form, iq.form.type + # assert iq.form.field("subdomain") + # end] + # ) + + # Registration::FinishOnboarding::Snikket::IQ_MANAGER.expect( + # :write, + # EMPromise.reject(launched), + # [Matching.new do |iq| + # assert_equal :set, iq.type + # assert_equal CONFIG[:snikket_hosting_api], iq.to.to_s + # assert_equal( + # "test.snikket.chat", + # iq.xpath( + # "./ns:launch/ns:domain", + # ns: "xmpp:snikket.org/hosting/v1" + # ).text + # ) + # end] + # ) + + # stub_request( + # :head, "https://test.snikket.chat/invites_bootstrap?token=TOKEN" + # ).to_timeout + + # Command::COMMAND_MANAGER.expect( + # :write, + # EMPromise.reject(:test_result), + # [Matching.new do |iq| + # assert iq.executing? + # assert_equal( + # "This is an error", + # iq.form.field("subdomain").desc + # ) + # end] + # ) + + # @snikket.write.catch { |e| e } + # end + + # assert_equal :test_result, result + # assert_mock Command::COMMAND_MANAGER + # assert_mock Registration::FinishOnboarding::Snikket::IQ_MANAGER + # end + # em :test_write_already_taken + # end + + # class SnikketCustomDomainTest < Minitest::Test + # def setup + # @snikket = Registration::FinishOnboarding::CustomDomain.new( + # customer, + # "+15555550000", + # db: FakeDB.new + # ) + # end + + # def test_write_needs_dns + # domain_form = Blather::Stanza::Iq::Command.new + # domain_form.form.fields = [ + # { var: "domain", value: "snikket.example.com" } + # ] + + # launched = Snikket::Launched.new + # launched << Niceogiri::XML::Node.new( + # :launched, launched.document, "xmpp:snikket.org/hosting/v1" + # ).tap { |inner| + # inner << Niceogiri::XML::Node.new( + # :'instance-id', launched.document, "xmpp:snikket.org/hosting/v1" + # ).tap { |id| + # id.content = "si-1234" + # } + # inner << Niceogiri::XML::Node.new( + # :status, launched.document, "xmpp:snikket.org/hosting/v1" + # ).tap { |id| + # id.content = "needs_dns" + # } + # inner << Niceogiri::XML::Node.new( + # :records, launched.document, "xmpp:snikket.org/hosting/v1" + # ).tap { |records| + # records << Niceogiri::XML::Node.new( + # :record, launched.document, "xmpp:snikket.org/hosting/v1" + # ).tap { |record| + # record << Niceogiri::XML::Node.new( + # :name, launched.document, "xmpp:snikket.org/hosting/v1" + # ).tap { |name| name.content = "snikket.example.com" } + # record << Niceogiri::XML::Node.new( + # :type, launched.document, "xmpp:snikket.org/hosting/v1" + # ).tap { |type| type.content = "AAAA" } + # record << Niceogiri::XML::Node.new( + # :status, launched.document, "xmpp:snikket.org/hosting/v1" + # ).tap { |type| type.content = "incorrect" } + # record << Niceogiri::XML::Node.new( + # :expected, launched.document, "xmpp:snikket.org/hosting/v1" + # ).tap { |expected| + # expected << Niceogiri::XML::Node.new( + # :value, launched.document, "xmpp:snikket.org/hosting/v1" + # ).tap { |value| value.content = "1::2" } + # } + # record << Niceogiri::XML::Node.new( + # :found, launched.document, "xmpp:snikket.org/hosting/v1" + # ).tap { |found| + # found << Niceogiri::XML::Node.new( + # :value, launched.document, "xmpp:snikket.org/hosting/v1" + # ).tap { |value| value.content = "0::0" } + # } + # } + # } + # } + + # result = execute_command do + # Command::COMMAND_MANAGER.expect( + # :write, + # EMPromise.resolve(domain_form), + # [Matching.new do |iq| + # assert_equal :form, iq.form.type + # assert iq.form.field("domain") + # end] + # ) + + # Registration::FinishOnboarding::Snikket::IQ_MANAGER.expect( + # :write, + # EMPromise.resolve(launched), + # [Matching.new do |iq| + # assert_equal :set, iq.type + # assert_equal CONFIG[:snikket_hosting_api], iq.to.to_s + # assert_equal( + # "snikket.example.com", + # iq.xpath( + # "./ns:launch/ns:domain", + # ns: "xmpp:snikket.org/hosting/v1" + # ).text + # ) + # end] + # ) + + # Command::COMMAND_MANAGER.expect( + # :write, + # EMPromise.reject(:test_result), + # [Matching.new do |iq| + # assert_equal :form, iq.form.type + # assert_equal( + # ["snikket.example.com"], + # iq.form.xpath( + # "./ns:item/ns:field[@var='name']/ns:value", + # ns: "jabber:x:data" + # ).map(&:content) + # ) + # assert_equal( + # ["1::2"], + # iq.form.xpath( + # "./ns:item/ns:field[@var='expected']/ns:value", + # ns: "jabber:x:data" + # ).map(&:content) + # ) + # end] + # ) + + # @snikket.write.catch { |e| e } + # end + + # assert_equal :test_result, result + # assert_mock Command::COMMAND_MANAGER + # assert_mock Registration::FinishOnboarding::Snikket::IQ_MANAGER + # end + # em :test_write_needs_dns + # end end