Skip to content

Conversation

@kekefreedog
Copy link

@kekefreedog kekefreedog commented Oct 4, 2022

Problem

When I use mongodb driver with bellow config I have error log : Authentification failed

 host: 172.26.0.4 database: myapp collection: cache port: 27017 root: login: admin password: password

Solution

Proposed changes

I discover the issue was link to buildConnectionURI, the method return mongodb://admin:password@127.0.0.1/myapp, whereas I'm waiting this : mongodb://user:password@164.152.09.84:27017 (this second option works for me)

Types of changes

What types of changes does your code introduce to Phpfastcache?

  • Bugfix (non-breaking change which fixes an issue)

Agreement

I have read the CONTRIBUTING and CODING GUIDELINE docs

Error log

PHP 8.1 (Ubuntu)
mongo:6.0

The full log message :

 Fatal error: Uncaught MongoDB\Driver\Exception\AuthenticationException: Authentication failed. in /Users/toto/Sites/myapp/vendor/mongodb/mongodb/src/Command/ListCollections.php:112 Stack trace: #0 /Users/toto/Sites/myapp/vendor/mongodb/mongodb/src/Command/ListCollections.php(112): MongoDB\Driver\Server->executeReadCommand() #1 /Users/toto/Sites/myapp/vendor/mongodb/mongodb/src/Operation/ListCollections.php(83): MongoDB\Command\ListCollections->execute() #2 /Users/toto/Sites/myapp/vendor/mongodb/mongodb/src/Database.php(466): MongoDB\Operation\ListCollections->execute() #3 /Users/toto/Sites/myapp/vendor/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Mongodb/Driver.php(340): MongoDB\Database->listCollections() #4 /Users/toto/Sites/myapp/vendor/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Mongodb/Driver.php(93): Phpfastcache\Drivers\Mongodb\Driver->collectionExists() #5 /Users/toto/Sites/myapp/vendor/phpfastcache/phpfastcache/lib/Phpfastcache/Core/Pool/DriverBaseTrait.php(81): Phpfastcache\Drivers\Mongodb\Driver->driverConnect() #6 /Users/toto/Sites/myapp/vendor/phpfastcache/phpfastcache/lib/Phpfastcache/Core/Pool/CacheItemPoolTrait.php(65): Phpfastcache\Drivers\Mongodb\Driver->__driverBaseConstruct() #7 /Users/toto/Sites/myapp/vendor/phpfastcache/phpfastcache/lib/Phpfastcache/CacheManager.php(114): Phpfastcache\Drivers\Mongodb\Driver->__construct() #8 /Users/toto/Sites/CrazyPHP/src/Library/Cache/Cache.php(101): Phpfastcache\CacheManager::getInstance() #9 /Users/toto/Sites/CrazyPHP/src/Core/Router.php(80): CrazyPHP\Library\Cache\Cache->__construct() #10 /Users/toto/Sites/CrazyPHP/src/Core/Core.php(130): CrazyPHP\Core\Router->pushCollection() #11 /Users/toto/Sites/myapp/app/Core/App.php(51): CrazyPHP\Core\Core->runRoutersPreparation() #12 /Users/toto/Sites/myapp/app/Index.php(28): App\Core\App->__construct() #13 /Users/toto/Sites/myapp/public/index.php(24): require_once('...') #14 {main} Next Phpfastcache\Exceptions\PhpfastcacheDriverConnectException: (MongoDB\Driver\Exception\AuthenticationException) Mongodb failed to connect with the following error message: "Authentication failed." line 112 in /Users/toto/Sites/myapp/vendor/mongodb/mongodb/src/Command/ListCollections.php in /Users/toto/Sites/myapp/vendor/phpfastcache/phpfastcache/lib/Phpfastcache/Core/Pool/DriverBaseTrait.php:84 Stack trace: #0 /Users/toto/Sites/myapp/vendor/phpfastcache/phpfastcache/lib/Phpfastcache/Core/Pool/CacheItemPoolTrait.php(65): Phpfastcache\Drivers\Mongodb\Driver->__driverBaseConstruct() #1 /Users/toto/Sites/myapp/vendor/phpfastcache/phpfastcache/lib/Phpfastcache/CacheManager.php(114): Phpfastcache\Drivers\Mongodb\Driver->__construct() #2 /Users/toto/Sites/CrazyPHP/src/Library/Cache/Cache.php(101): Phpfastcache\CacheManager::getInstance() #3 /Users/toto/Sites/CrazyPHP/src/Core/Router.php(80): CrazyPHP\Library\Cache\Cache->__construct() #4 /Users/toto/Sites/CrazyPHP/src/Core/Core.php(130): CrazyPHP\Core\Router->pushCollection() #5 /Users/toto/Sites/myapp/app/Core/App.php(51): CrazyPHP\Core\Core->runRoutersPreparation() #6 /Users/toto/Sites/myapp/app/Index.php(28): App\Core\App->__construct() #7 /Users/toto/Sites/myapp/public/index.php(24): require_once('...') #8 {main} thrown in /Users/toto/Sites/myapp/vendor/phpfastcache/phpfastcache/lib/Phpfastcache/Core/Pool/DriverBaseTrait.php on line 84 
# Problem When I use mongodb driver with bellow config I have error log : Authentification failed ```yml host: 172.26.0.4 database: myapp collection: cache port: 27017 root: login: admin password: password ``` # Solution I discover the issue was link to buildConnectionURI, the method return `mongodb://admin:password@127.0.0.1/myapp`, whereas I'm waiting this : `mongodb://user:password@164.152.09.84:27017` (this second option works for me)
@Geolim4
Copy link
Member

Geolim4 commented Oct 4, 2022

That's, strange, I'm using authentication with database path and it's working oO, I need to investigate first before merging your PR 🤕

@Geolim4
Copy link
Member

Geolim4 commented Oct 4, 2022

I can't merge your code as it breaks the code:

"E:\Program Files (x86)\php8\8.1\php.exe" E:\wamp\www\phpfastcache\tests\Mongodb.test.php [Begin Test: Mongodb driver] [PHPFASTCACHE: CORE v9.1.2#c2dfc471 | API v4.2.0] [PHP v8.1.7 with: apcu, bcmath, calendar, Core, couchbase, ctype, curl, date, dom, fileinfo, filter, gd, gettext, grpc, hash, iconv, json, libxml, mbstring, memcached, mongodb, mysqlnd, openssl, pcre, PDO, pdo_mysql, pdo_sqlite, Phar, readline, redis, Reflection, session, SimpleXML, SPL, standard, tokenizer, xml, xmlreader, xmlwriter, zip, zlib] --- "mongodb://travis:test@127.0.0.1:27017" [SKIP] A driver could not be initialized due to network/authentication issue: (MongoDB\Driver\Exception\AuthenticationException) Mongodb failed to connect with the following error message: "Authentication failed." line 120 in E:\wamp\www\phpfastcache\vendor\mongodb\mongodb\src\Command\ListCollections.php Test results: 0 assertions failed, 1 assertion skipped and 0 assertions passed out of a total of 1 assertion. Test duration: 0.159s Process finished with exit code 2 

Removing the path actually break the code.
Can you provide me more information about you Phpfastcache configuration and composer.lock ?

@Geolim4
Copy link
Member

Geolim4 commented Oct 5, 2022

Current working code in tests/Mongodb.test.php as per official Mongodb Doc

<?php /**  *  * This file is part of Phpfastcache.  *  * @license MIT License (MIT)  *  * For full copyright and license information, please see the docs/CREDITS.txt and LICENCE files.  *  * @author Georges.L (Geolim4) <contact@geolim4.com>  * @author Contributors https://github.com/PHPSocialNetwork/phpfastcache/graphs/contributors  */ use Phpfastcache\CacheManager; use Phpfastcache\Drivers\Mongodb\Config; use Phpfastcache\Exceptions\PhpfastcacheDriverCheckException; use Phpfastcache\Tests\Helper\TestHelper; chdir(__DIR__); require_once __DIR__ . '/../vendor/autoload.php'; $testHelper = new TestHelper('Mongodb driver'); $config = new Config(); $config->setItemDetailedDate(true) ->setDatabaseName('pfc_test') ->setCollectionName('pfc_' . str_pad('0', 3, random_int(1, 100))) ->setUsername('travis') ->setPassword('test'); $cacheInstance = CacheManager::getInstance('Mongodb', $config); $testHelper->runCRUDTests($cacheInstance); $testHelper->terminateTest();
@kekefreedog
Copy link
Author

Hello Georges.L,

Thank you for your qui response.
I'm using Mongo into docker container, I will try to change port and host and test again.

We keep in touch !

@Geolim4
Copy link
Member

Geolim4 commented Oct 25, 2022

Hello @kekefreedog is your issue solved in an other way ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants