Pārlūkot izejas kodu

Merge pull request #173 from alcaeus/add-auth-tests

Add tests for authentication options
Andreas 8 gadi atpakaļ
vecāks
revīzija
69d66a5992
1 mainītis faili ar 26 papildinājumiem un 0 dzēšanām
  1. 26 0
      tests/Alcaeus/MongoDbAdapter/Mongo/MongoClientTest.php

+ 26 - 0
tests/Alcaeus/MongoDbAdapter/Mongo/MongoClientTest.php

@@ -225,6 +225,32 @@ class MongoClientTest extends TestCase
         ];
     }
 
+    public function testConnectWithUsernameAndPassword()
+    {
+        $this->expectException(\MongoConnectionException::class);
+        $this->expectExceptionMessage('Authentication failed');
+
+        $client = $this->getClient(['username' => 'alcaeus', 'password' => 'mySuperSecurePassword']);
+        $collection = $client->selectCollection('test', 'foo');
+
+        $document = ['foo' => 'bar'];
+
+        $collection->insert($document);
+    }
+    
+    public function testConnectWithUsernameAndPasswordInConnectionUrl()
+    {
+        $this->expectException(\MongoConnectionException::class);
+        $this->expectExceptionMessage('Authentication failed');
+
+        $client = $this->getClient([], 'mongodb://alcaeus:mySuperSecurePassword@localhost');
+        $collection = $client->selectCollection('test', 'foo');
+
+        $document = ['foo' => 'bar'];
+
+        $collection->insert($document);
+    }
+
     /**
      * @param array $options
      * @return string