base = File.dirname(__FILE__)
require base + '/../test_setup'
context 'S33r ACL functions' do
setup do
@acl_grant_xml1 = load_test_xml('acl_grant1.xml')
@canonical_user = CanonicalUser.new('a9a7b886d6fd24a52fe8ca5bef65f89a64e0193f23000e241bf9b1c61be666e9',
'chriscustomer')
@canonical_user_grant = Grant.new(@canonical_user, :all)
@canonical_user2 = CanonicalUser.new('baa7b886d6fd24a52fe8ca5bef65f89a64e0193f23000e241bf9b1c61be666e9',
'mimbo')
@canonical_user_grant2 = Grant.new(@canonical_user2, :read)
@acl_grant_xml2 = load_test_xml('acl_grant2.xml')
@amazon_grantee = AmazonCustomer.new('elliot@test.org')
@amazon_grant = Grant.new(@amazon_grantee, :read)
@acl_grant_xml3 = load_test_xml('acl_grant3.xml')
@group_grantee = Group.new(:all_users)
@group_grant = Grant.new(@group_grantee, :write)
@acl_grant_xml4 = load_test_xml('acl_grant4.xml')
@group_grantee2 = Group.new(:authenticated_users)
@group_grant2 = Grant.new(@group_grantee2, :read_acl)
@full_acl_xml = load_test_xml('acl.xml')
@full_acl_doc = Policy.new(@canonical_user)
@full_acl_doc.grants = [@canonical_user_grant, @canonical_user_grant2, @amazon_grant,
@group_grant, @group_grant2]
# Grants created using convenience methods
@con_canonical_user_grant = Grant.for_canonical_user('a9a7b886d6fd24a52fe8ca5bef65f89a64e0193f23000e241bf9b1c61be666e9',
'chriscustomer', :all)
@con_canonical_user_grant2 = Grant.for_canonical_user('baa7b886d6fd24a52fe8ca5bef65f89a64e0193f23000e241bf9b1c61be666e9',
'mimbo', :read)
@con_amazon_grant = Grant.for_amazon_customer('elliot@test.org', :read)
@con_group_grant1 = Grant.for_group(:all_users, :write)
@con_group_grant2 = Grant.for_group(:authenticated_users, :read_acl)
@con_full_acl_doc = Policy.new(@canonical_user)
@con_full_acl_doc.grants = [@con_canonical_user_grant, @con_canonical_user_grant2,
@con_amazon_grant, @con_group_grant1, @con_group_grant2]
end
specify 'should represent a grant for a CanonicalUser' do
clean_xml(@canonical_user_grant.to_xml).should == @acl_grant_xml1
end
specify 'should represent a grant for an AmazonUserByEmail' do
clean_xml(@amazon_grant.to_xml).should == @acl_grant_xml2
end
specify 'should represent a grant for AllUsers' do
clean_xml(@group_grant.to_xml).should == @acl_grant_xml3
end
specify 'should represent a grant for AuthenticatedUsers' do
clean_xml(@group_grant2.to_xml).should == @acl_grant_xml4
end
specify 'should generate a valid AccessControlPolicy document' do
clean_xml(@full_acl_doc.to_xml).should == @full_acl_xml
end
specify 'should provide convenience classes for grants' do
clean_xml(@con_full_acl_doc.to_xml).should == @full_acl_xml
end
specify 'needs equality method for grantees' do
test_grantee = Group.new(:all_users)
test_grantee.should == @group_grantee
test_grantee.should.not.equal @amazon_grantee
end
specify 'should only accept valid permission specifiers' do
lambda { Grant.new(@group_grantee, nil) }.should.raise InvalidPermission
lambda { Grant.new(@group_grantee, :broken) }.should.raise InvalidPermission
end
specify 'should correctly create AmazonCustomer grantee from XML node' do
xml = "" +
"elliot@test.org" +
""
doc = XML.get_xml_doc(xml)
grantee = Grantee.from_xml(doc)
grantee.should == @amazon_grantee
end
specify 'should correctly create Group grantee from XML node' do
xml = "" +
"http://acs.amazonaws.com/groups/global/AllUsers" +
""
doc = XML.get_xml_doc(xml)
grantee = Grantee.from_xml(doc)
grantee.should == @group_grantee
end
specify 'should correctly create Group grantee for AuthenticatedUsers from XML node' do
xml = "" +
"http://acs.amazonaws.com/groups/global/AuthenticatedUsers" +
""
doc = XML.get_xml_doc(xml)
grantee = Grantee.from_xml(doc)
grantee.should == @group_grantee2
p grantee.group_type
p @group_grantee2.group_type
end
specify 'should parse AccessControlPolicy documents' do
acl_doc_from_xml = Policy.from_xml(@full_acl_xml)
acl_doc_from_xml.owner.should == @full_acl_doc.owner
@full_acl_doc.grants.each do |g|
acl_doc_from_xml.grants = acl_doc_from_xml.grants.delete_if { |i| i == g }
end
acl_doc_from_xml.grants.should.be.empty
end
end