Skip to content

Commit 9581b74

Browse files
committed
Tests should be able to run without --auth
1 parent d2921d2 commit 9581b74

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

spec/mongo/collection_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,7 @@
521521
end
522522
end
523523

524-
context 'when the user is not authorized' do
524+
context 'when the user is not authorized', if: auth_enabled? do
525525

526526
let(:view) do
527527
unauthorized_collection.find

spec/mongo/database_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@
180180
end
181181
end
182182

183-
context 'when the user is not authorized', unless: sharded? do
183+
context 'when the user is not authorized', if: auth_enabled? do
184184

185185
let(:database) do
186186
described_class.new(unauthorized_client, TEST_DB)

spec/spec_helper.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
Mongo::Logger.logger = Logger.new($stdout)
2121
Mongo::Logger.logger.level = Logger::INFO
2222

23+
require 'pry'
2324
require 'support/travis'
2425
require 'support/matchers'
2526
require 'support/authorization'
@@ -171,6 +172,15 @@ def failing_delete_doc
171172
{ que: { field: 'test' } }
172173
end
173174

175+
# Try running a command on the admin database to see if the mongod was started with auth.
176+
#
177+
# @since 2.2.0
178+
def auth_enabled?
179+
$mongo_client ||= initialize_scanned_client!
180+
begin; $mongo_client.use(:admin).command(getCmdLineOpts: 1); rescue; return true; end
181+
false
182+
end
183+
174184
# Initializes a basic scanned client to do an ismaster check.
175185
#
176186
# @since 2.0.0

0 commit comments

Comments
 (0)