1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
|
# encoding: utf-8
require "spec_helper"
describe "Authentication attempt" do
#
# Environment
#
include EventedSpec::EMSpec
include EventedSpec::SpecHelper
default_timeout 7.0
describe "with default connection parameters" do
#
# Examples
#
# assuming there is an account guest with password of "guest" that has
# access to / (default vhost)
context "when guest/guest has access to /" do
after :all do
done
end
it "succeeds" do
AMQP.connect do |connection|
connection.should be_open
connection.close { done }
end
end # it
end # context
end # describe
describe "with explicitly given connection parameters" do
#
# Examples
#
# assuming there is an account amqp_gem with password of "amqp_gem_password" that has
# access to amqp_gem_testbed
context "when amqp_gem/amqp_gem_testbed has access to amqp_gem_testbed" do
context "and provided credentials are correct" do
it "succeeds" do
connection = AMQP.connect(AMQP_OPTS.merge(:username => "amqp_gem", :password => "amqp_gem_password", :vhost => "amqp_gem_testbed"))
done(3.0) {
connection.should be_connected
connection.username.should == "amqp_gem"
connection.user.should == "amqp_gem"
connection.hostname.should == "localhost"
connection.host.should == "localhost"
connection.port.should == 5672
connection.vhost.should == "amqp_gem_testbed"
connection.broker_endpoint.should == "localhost:5672/amqp_gem_testbed"
connection.close
}
end # it
end # context
context "and provided credentials ARE INCORRECT" do
default_timeout 5
after(:all) { done }
it "fails" do
handler = Proc.new { |settings|
puts "Callback has fired"
callback_has_fired = true
done
}
connection = AMQP.connect(:username => "amqp_gem", :password => Time.now.to_i.to_s, :vhost => "amqp_gem_testbed", :on_possible_authentication_failure => handler)
end # it
end
context "and provided vhost DOES NOT EXIST" do
default_timeout 10
after(:all) { done }
it "fails" do
handler = Proc.new { |settings|
puts "Callback has fired"
callback_has_fired = true
done
}
connection = AMQP.connect(:username => "amqp_gem", :password => Time.now.to_i.to_s, :vhost => "/a/b/c/#{rand}/#{Time.now.to_i}", :on_possible_authentication_failure => handler)
end # it
end
end # context
end
describe "with connection string" do
#
# Examples
#
# assuming there is an account amqp_gem with password of "amqp_gem_password" that has
# access to amqp_gem_testbed
context "when amqp_gem/amqp_gem_testbed has access to amqp_gem_testbed" do
context "and provided credentials are correct" do
it "succeeds" do
connection = AMQP.connect "amqp://amqp_gem:amqp_gem_password@localhost/amqp_gem_testbed"
done(3.0) {
connection.should be_connected
connection.close
}
end # it
end # context
context "and provided credentials ARE INCORRECT" do
default_timeout 6
after(:all) { done }
it "fails" do
connection = AMQP.connect "amqp://amqp_gem:#{Time.now.to_i}@localhost/amqp_gem_testbed", :on_possible_authentication_failure => Proc.new { |settings|
puts "Callback has fired"
done
}
end # it
end # context
end # context
end # describe
end # describe "Authentication attempt"
|