Skip to content

Commit 0fa7df9

Browse files
committed
Fix wrong exception when using external auth source
1 parent cc5d769 commit 0fa7df9

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

php_phongo.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1426,7 +1426,7 @@ static bool php_phongo_uri_finalize_auth(mongoc_uri_t* uri) /* {{{ */
14261426
}
14271427
}
14281428
} else if (require_auth) {
1429-
if (!username || strcmp(username, "") == 0) {
1429+
if (source && strcmp(source, "$external") != 0 && (!username || strcmp(username, "") == 0)) {
14301430
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT, "Failed to parse URI options: Default authentication mechanism requires username.");
14311431
return false;
14321432
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
--TEST--
2+
MongoDB\Driver\Manager::__construct(): authSource option
3+
--FILE--
4+
<?php
5+
6+
$tests = [
7+
['mongodb://[email protected]/?authSource=$external', []],
8+
[null, ['authSource' => '$external']],
9+
];
10+
11+
foreach ($tests as $test) {
12+
list($uri, $options) = $test;
13+
14+
/* Note: the Manager's debug information does not include the auth mechanism
15+
* so we are merely testing that no exception is thrown. */
16+
$manager = new MongoDB\Driver\Manager($uri, $options);
17+
}
18+
19+
?>
20+
===DONE===
21+
<?php exit(0); ?>
22+
--EXPECT--
23+
===DONE===

0 commit comments

Comments
 (0)