mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
Check that common passwords list is greater than 0
This commit is contained in:
@@ -41,8 +41,9 @@ describe CommonPasswords do
|
||||
it "loads the passwords file if redis doesn't have it" do
|
||||
mock_redis = mock("redis")
|
||||
mock_redis.stubs(:exists).returns(false)
|
||||
mock_redis.stubs(:scard).returns(0)
|
||||
described_class.stubs(:redis).returns(mock_redis)
|
||||
described_class.expects(:load_passwords).returns([])
|
||||
described_class.expects(:load_passwords).returns(['password'])
|
||||
list = described_class.password_list
|
||||
list.should respond_to(:include?)
|
||||
end
|
||||
@@ -50,16 +51,27 @@ describe CommonPasswords do
|
||||
it "doesn't load the passwords file if redis has it" do
|
||||
mock_redis = mock("redis")
|
||||
mock_redis.stubs(:exists).returns(true)
|
||||
mock_redis.stubs(:scard).returns(5000)
|
||||
described_class.stubs(:redis).returns(mock_redis)
|
||||
described_class.expects(:load_passwords).never
|
||||
list = described_class.password_list
|
||||
list.should respond_to(:include?)
|
||||
end
|
||||
|
||||
it "loads the passwords file if redis has an empty list" do
|
||||
mock_redis = mock("redis")
|
||||
mock_redis.stubs(:exists).returns(true)
|
||||
mock_redis.stubs(:scard).returns(0)
|
||||
described_class.stubs(:redis).returns(mock_redis)
|
||||
described_class.expects(:load_passwords).returns(['password'])
|
||||
list = described_class.password_list
|
||||
list.should respond_to(:include?)
|
||||
end
|
||||
end
|
||||
|
||||
context "missing password file" do
|
||||
it "tolerates it" do
|
||||
described_class.stubs(:redis).returns(stub_everything(sismember: false))
|
||||
described_class.stubs(:redis).returns(stub_everything(sismember: false, exists: false, scard: 0))
|
||||
File.stubs(:readlines).with(described_class::PASSWORD_FILE).raises(Errno::ENOENT)
|
||||
described_class.common_password?("password").should eq(false)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user