Skip to content

Commit

Permalink
fix specs - use hashed values for default_password, ensure that defau…
Browse files Browse the repository at this point in the history
…lt user and password is set after specs have run, remove spec for env variables since it does not work
  • Loading branch information
viktorerlingsson committed Feb 21, 2025
1 parent 9fe47af commit fe5ff17
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions spec/users_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -276,32 +276,28 @@ describe LavinMQ::Server do

it "allows changing default user" do
LavinMQ::Config.instance.default_user = "spec"
LavinMQ::Config.instance.default_password = "spec"
with_amqp_server do |s|
with_channel(s, user: "spec", password: "spec") { }
end
end

it "allows changing default user with env variables" do
ENV["LAVINMQ_DEFAULT_USER"] = "spec"
ENV["LAVINMQ_DEFAULT_PASSWORD"] = "spec"
LavinMQ::Config.instance.default_password = LavinMQ::User.hash_password("spec", "SHA256").to_s
with_amqp_server do |s|
with_channel(s, user: "spec", password: "spec") { }
end
ensure
ENV.delete("LAVINMQ_DEFAULT_USER")
ENV.delete("LAVINMQ_DEFAULT_PASSWORD")
LavinMQ::Config.instance.default_user = "guest"
LavinMQ::Config.instance.default_password = LavinMQ::User.hash_password("guest", "SHA256").to_s
end

it "disallows 'guest' if default user is changed" do
LavinMQ::Config.instance.default_user = "spec"
LavinMQ::Config.instance.default_password = "spec"
LavinMQ::Config.instance.default_password = LavinMQ::User.hash_password("spec", "SHA256").to_s
with_amqp_server do |s|
expect_raises(AMQP::Client::Connection::ClosedException) do
with_channel(s, user: "guest", password: "guest") { }
end
end
ensure
LavinMQ::Config.instance.default_user = "guest"
LavinMQ::Config.instance.default_password = LavinMQ::User.hash_password("guest", "SHA256").to_s
end

end

describe LavinMQ::Tag do
Expand Down

0 comments on commit fe5ff17

Please sign in to comment.