spec/mongo/auth/user_spec.rb in mongo-2.11.0.rc0 vs spec/mongo/auth/user_spec.rb in mongo-2.11.0
- old
+ new
@@ -8,19 +8,39 @@
let(:user) do
described_class.new(options)
end
+ shared_examples_for 'sets database and auth source to admin' do
+
+ it 'sets database to admin' do
+ expect(user.database).to eq('admin')
+ end
+
+ it 'sets auth source to admin' do
+ expect(user.auth_source).to eq('admin')
+ end
+ end
+
+ shared_examples_for 'sets auth source to $external' do
+
+ it 'sets auth source to $external' do
+ expect(user.auth_source).to eq('$external')
+ end
+ end
+
describe '#initialize' do
let(:user) { Mongo::Auth::User.new(options) }
context 'no options' do
let(:options) { {} }
it 'succeeds' do
expect(user).to be_a(Mongo::Auth::User)
end
+
+ it_behaves_like 'sets database and auth source to admin'
end
context 'invalid mechanism' do
let(:options) { {auth_mech: :invalid} }
@@ -43,10 +63,12 @@
end
it 'converts mechanism to symbol' do
expect(user.mechanism).to eq(:scram)
end
+
+ it_behaves_like 'sets database and auth source to admin'
end
context 'linting' do
require_linting
@@ -67,11 +89,45 @@
end
it 'stores mechanism' do
expect(user.mechanism).to eq(:scram)
end
+
+ it_behaves_like 'sets database and auth source to admin'
end
+
+ context 'mechanism is x509' do
+ let(:options) { {auth_mech: :mongodb_x509} }
+
+ it 'sets database to admin' do
+ expect(user.database).to eq('admin')
+ end
+
+ it_behaves_like 'sets auth source to $external'
+
+ context 'database is explicitly given' do
+ let(:options) { {auth_mech: :mongodb_x509, database: 'foo'} }
+
+ it 'sets database to the specified one' do
+ expect(user.database).to eq('foo')
+ end
+
+ it_behaves_like 'sets auth source to $external'
+ end
+ end
+
+ it 'sets the database' do
+ expect(user.database).to eq('testing')
+ end
+
+ it 'sets the name' do
+ expect(user.name).to eq('user')
+ end
+
+ it 'sets the password' do
+ expect(user.password).to eq('pass')
+ end
end
describe '#auth_key' do
let(:nonce) do
@@ -126,24 +182,9 @@
end
it 'returns a UTF-8 string' do
expect(user.encoded_name.encoding.name).to eq('UTF-8')
end
- end
- end
-
- describe '#initialize' do
-
- it 'sets the database' do
- expect(user.database).to eq('testing')
- end
-
- it 'sets the name' do
- expect(user.name).to eq('user')
- end
-
- it 'sets the password' do
- expect(user.password).to eq('pass')
end
end
describe '#hashed_password' do