require 'spec_helper' describe Socialcast::CLI do describe '#provision' do context 'with ldap.yml configuration excluding permission_mappings' do before do @entry = Net::LDAP::Entry.new("dc=example,dc=com") @entry[:mail] = 'ryan@example.com' Net::LDAP.any_instance.stub(:search).and_yield(@entry) @result = '' Zlib::GzipWriter.stub(:open).and_yield(@result) File.stub(:open).with(/ldap.yml/).and_yield(File.read(File.join(File.dirname(__FILE__), 'fixtures', 'ldap_without_permission_mappings.yml'))) File.stub(:open).with(/users.xml.gz/, anything).and_yield(@result) File.stub(:open).with(/credentials.yml/).and_yield(File.read(File.join(File.dirname(__FILE__), 'fixtures', 'credentials.yml'))) RestClient::Resource.any_instance.stub(:post) Socialcast::CLI.start ['provision', '-c', 'spec/fixtures/ldap.yml'] end it 'excludes roles element' do @result.should_not =~ %r{roles} end end context 'with external group member' do before do @entry = Net::LDAP::Entry.new("dc=example,dc=com") @entry[:mail] = 'ryan@example.com' @entry[:isMemberOf] = 'cn=External,dc=example,dc=com' Net::LDAP.any_instance.stub(:search).and_yield(@entry) @result = '' Zlib::GzipWriter.stub(:open).and_yield(@result) File.stub(:open).with(/ldap.yml/).and_yield(File.read(File.join(File.dirname(__FILE__), 'fixtures', 'ldap.yml'))) File.stub(:open).with(/users.xml.gz/, anything).and_yield(@result) File.stub(:open).with(/credentials.yml/).and_yield(File.read(File.join(File.dirname(__FILE__), 'fixtures', 'credentials.yml'))) RestClient::Resource.any_instance.stub(:post) Socialcast::CLI.start ['provision', '-c', 'spec/fixtures/ldap.yml'] end it 'sets account-type to external' do @result.should =~ %r{external} end end context 'with tenant_admin group member' do before do @entry = Net::LDAP::Entry.new("dc=example,dc=com") @entry[:mail] = 'ryan@example.com' @entry[:isMemberOf] = 'cn=Admins,dc=example,dc=com' Net::LDAP.any_instance.stub(:search).and_yield(@entry) @result = '' Zlib::GzipWriter.stub(:open).and_yield(@result) File.stub(:open).with(/ldap.yml/).and_yield(File.read(File.join(File.dirname(__FILE__), 'fixtures', 'ldap.yml'))) File.stub(:open).with(/users.xml.gz/, anything).and_yield(@result) File.stub(:open).with(/credentials.yml/).and_yield(File.read(File.join(File.dirname(__FILE__), 'fixtures', 'credentials.yml'))) RestClient::Resource.any_instance.stub(:post) Socialcast::CLI.start ['provision', '-c', 'spec/fixtures/ldap.yml'] end it 'sets account-type to member' do @result.should =~ %r{member} end it 'adds tenant_admin role' do @result.should =~ %r{tenant_admin} end end end end