spec/auth_store_spec.rb in spidr-0.2.7 vs spec/auth_store_spec.rb in spidr-0.3.0
- old
+ new
@@ -1,73 +1,73 @@
require 'spidr/auth_store'
require 'spec_helper'
describe AuthStore do
+ let(:root_uri) { URI('http://zerosum.org/') }
+ let(:uri) { root_uri.merge('/course/auth') }
+
before(:each) do
@auth_store = AuthStore.new
- @uri = URI('http://zerosum.org/course/auth')
- @auth_store.add(@uri, 'admin', 'password')
+ @auth_store.add(uri, 'admin', 'password')
end
after(:each) do
@auth_store.clear!
end
it 'should retrieve auth credentials for the URL' do
- uri = @uri.merge('/')
-
- @auth_store[uri] = AuthCredential.new('user1', 'pass1')
- @auth_store[uri].username.should == 'user1'
- @auth_store[uri].password.should == 'pass1'
+ @auth_store[root_uri] = AuthCredential.new('user1', 'pass1')
+ @auth_store[root_uri].username.should == 'user1'
+ @auth_store[root_uri].password.should == 'pass1'
end
it 'should add auth credentials for the URL' do
- uri = @uri.merge('/')
-
lambda {
- @auth_store.add(uri, 'user1', 'pass1')
+ @auth_store.add(root_uri, 'user1', 'pass1')
}.should change(@auth_store, :size)
- @auth_store[uri].username.should == 'user1'
- @auth_store[uri].password.should == 'pass1'
+ @auth_store[root_uri].username.should == 'user1'
+ @auth_store[root_uri].password.should == 'pass1'
end
describe 'matching' do
- it 'should match a longer URL to the base' do
- uri = @uri.merge('/course/auth/protected.html')
+ let(:sub_uri) { uri.merge('/course/auth/protected.html') }
- @auth_store[uri].username.should == 'admin'
- @auth_store[uri].password.should == 'password'
+ it 'should match a longer URL to the base' do
+ @auth_store[sub_uri].username.should == 'admin'
+ @auth_store[sub_uri].password.should == 'password'
end
it 'should match the longest of all matching URLs' do
- @auth_store.add(@uri.merge('/course'), 'user1', 'pass1')
- @auth_store.add(@uri.merge('/course/auth/special'), 'user2', 'pass2')
- @auth_store.add(@uri.merge('/course/auth/special/extra'), 'user3', 'pass3')
+ @auth_store.add(uri.merge('/course'), 'user1', 'pass1')
+ @auth_store.add(uri.merge('/course/auth/special'), 'user2', 'pass2')
+ @auth_store.add(uri.merge('/course/auth/special/extra'), 'user3', 'pass3')
- auth = @auth_store[@uri.merge('/course/auth/special/1.html')]
+ auth = @auth_store[uri.merge('/course/auth/special/1.html')]
auth.username.should == 'user2'
auth.password.should == 'pass2'
end
it 'should not match a URL with a different host' do
- uri = URI('http://spidr.rubyforge.org/course/auth')
- @auth_store[uri].should be_nil
+ remote_uri = URI('http://spidr.rubyforge.org/course/auth')
+
+ @auth_store[remote_uri].should be_nil
end
it 'should not match a URL with an alternate path' do
- uri = @uri.merge('/course/admin/protected.html')
- @auth_store[uri].should be_nil
+ relative_uri = uri.merge('/course/admin/protected.html')
+
+ @auth_store[relative_uri].should be_nil
end
end
it 'should override previous auth credentials' do
- @auth_store.add(@uri, 'newuser', 'newpass')
+ @auth_store.add(uri, 'newuser', 'newpass')
- @auth_store[@uri].username.should == 'newuser'
- @auth_store[@uri].password.should == 'newpass'
+ @auth_store[uri].username.should == 'newuser'
+ @auth_store[uri].password.should == 'newpass'
end
it 'should clear all cookies' do
@auth_store.clear!
@auth_store.size.should == 0
@@ -77,9 +77,9 @@
it 'should return nil if no authorization exists' do
@auth_store.for_url(URI('http://php.net')).should be_nil
end
it 'should create an encoded authorization string' do
- @auth_store.for_url(@uri).should == "YWRtaW46cGFzc3dvcmQ=\n"
+ @auth_store.for_url(uri).should == "YWRtaW46cGFzc3dvcmQ=\n"
end
end
end