# encoding: UTF-8 require 'test_helper' describe Vines::Stream::Server::Outbound::AuthExternal do before do @stream = MiniTest::Mock.new @state = Vines::Stream::Server::Outbound::AuthExternal.new(@stream) end def test_invalid_element node = node('') assert_raises(Vines::StreamErrors::NotAuthorized) { @state.node(node) } end def test_invalid_sasl_element node = node(%Q{}) assert_raises(Vines::StreamErrors::NotAuthorized) { @state.node(node) } end def test_missing_namespace node = node('') assert_raises(Vines::StreamErrors::NotAuthorized) { @state.node(node) } end def test_invalid_namespace node = node('') assert_raises(Vines::StreamErrors::NotAuthorized) { @state.node(node) } end def test_missing_mechanisms node = node(%Q{}) assert_raises(Vines::StreamErrors::NotAuthorized) { @state.node(node) } end def test_missing_mechanisms_namespace node = node(%Q{}) assert_raises(Vines::StreamErrors::NotAuthorized) { @state.node(node) } end def test_missing_mechanism mechanisms = %q{} node = node(%Q{#{mechanisms}}) assert_raises(Vines::StreamErrors::NotAuthorized) { @state.node(node) } end def test_missing_mechanism_text mechanisms = %q{} node = node(%Q{#{mechanisms}}) assert_raises(Vines::StreamErrors::NotAuthorized) { @state.node(node) } end def test_invalid_mechanism_text mechanisms = %q{BOGUS} node = node(%Q{#{mechanisms}}) assert_raises(Vines::StreamErrors::NotAuthorized) { @state.node(node) } end def test_valid_mechanism @stream.expect(:domain, 'wonderland.lit') expected = %Q{d29uZGVybGFuZC5saXQ=} @stream.expect(:write, nil, [expected]) @stream.expect(:advance, nil, [Vines::Stream::Server::Outbound::AuthExternalResult.new(@stream)]) mechanisms = %q{EXTERNAL} node = node(%Q{#{mechanisms}}) @state.node(node) assert @stream.verify end private def node(xml) Nokogiri::XML(xml).root end end