-
Notifications
You must be signed in to change notification settings - Fork 210
PHPC-1347: Do not allow empty string for replicaSet #1043
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
php_phongo.c
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this would be better placed within the if (mongoc_uri_option_is_utf8(key)) {
condition further down in php_phongo_apply_options_to_uri
. That already does the BSON_ITER_HOLDS_UTF8
check, which you're duplicating here. Consider:
if (mongoc_uri_option_is_utf8(key)) {
if (!BSON_ITER_HOLDS_UTF8(&iter)) {
PHONGO_URI_INVALID_TYPE(iter, "string");
return false;
}
if (!strcasecmp(key, MONGOC_URI_REPLICASET) && !strcmp("", bson_iter_utf8(&iter, NULL))) {
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "Value for URI option \"%s\" cannot be empty string.", key);
return false;
}
if (!mongoc_uri_set_option_as_utf8(uri, key, bson_iter_utf8(&iter, NULL))) {
/* Assignment uses mongoc_uri_set_appname() for the "appname"...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both errors (libmongoc URI parsing and our new exception) can be exercised without incurring I/O, so I think this test could be better rewritten like the existing Manager::__construct()
error tests (e.g. manager-ctor_error-003.phpt). Note that the 003 test already handles the invalid type check, which you had duplicated above, so there's be no need to check that again in your new test.
With the SKIPIF removed, I think this would be as simple as two cases in their own throws()
callable:
- Invalid connection string with
?replicaSet=
throws libmongoc's exception - Valid connection string with
['replicaSet' => '']
URI options throws our exception
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we rename this file to manager-ctor_error-003.phpt
? I realize we have a lot of existing tests split across various sub-directories, but the general convention is class-method-###.phpt
, with an optional _error
for error tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM with test file rename.
https://jira.mongodb.org/browse/PHPC-1347
Since libmongoc rejects an URI with an empty
replicaSet
URI option, there is different behaviour depending on whether an empty replica set name is passed via the URI string or via the URI options array. The first causes an exception:The latter lets users create the manager, but causes a connection exception on server selection:
This PR changes this and checks the
replicaSet
option when it is passed via URI options array, also throwing an exception when the option is explicitly given with an empty value. Not passing the option at all does not cause an error.