diff options
author | Nick Vatamaniuc <vatamane@apache.org> | 2019-08-20 12:18:34 -0400 |
---|---|---|
committer | Nick Vatamaniuc <nickva@users.noreply.github.com> | 2019-08-20 13:16:34 -0400 |
commit | e5baa1f30b6427b74f5afd4bc8f773fcbd497cbd (patch) | |
tree | 51a48e0d98278e46bcfc2aaf73f049c710168584 | |
parent | 24e9013051076669360f1c2aeebf415f1255b159 (diff) | |
download | couchdb-e5baa1f30b6427b74f5afd4bc8f773fcbd497cbd.tar.gz |
Fix _scheduler/docs response for local replication endpoints
When the `_scheduler/docs` response is generated, the replication docs are
parsed and credentials are stripped by `couch_replicator:strip_url_creds/1`.
When local endpoint support was removed, that function didn't properly catch
the parsing error for local endpoints and as a result was error-ing out the
whole response.
The fix is to catch the error and return the endpoint as is. The catch is
specific to that error, so turned the long binary message into a shorter, but
hopefully still obvious atom.
`_scheduler/docs` response would look like:
```
{
"docs": [
{
"database": "_replicator",
"doc_id": "r",
"error_count": 1,
"id": null,
"info": "local_endpoints_not_supported",
"last_updated": "2019-08-20T16:09:53Z",
"source": "http://adm:*****@127.0.0.1:15984/s/",
"start_time": "2019-08-20T16:09:53Z",
"state": "failed",
"target": "t"
}
],
"offset": 0,
"total_rows": 1
}
```
Interestingly, there was already a test for this case, except it wasn't
included in the EUnit test suite list.
-rw-r--r-- | src/couch_replicator/src/couch_replicator.erl | 15 | ||||
-rw-r--r-- | src/couch_replicator/src/couch_replicator_docs.erl | 4 |
2 files changed, 11 insertions, 8 deletions
diff --git a/src/couch_replicator/src/couch_replicator.erl b/src/couch_replicator/src/couch_replicator.erl index e4fa31cee..9c7e318b6 100644 --- a/src/couch_replicator/src/couch_replicator.erl +++ b/src/couch_replicator/src/couch_replicator.erl @@ -144,11 +144,13 @@ replication_states() -> -spec strip_url_creds(binary() | {[_]}) -> binary(). strip_url_creds(Endpoint) -> - case couch_replicator_docs:parse_rep_db(Endpoint, [], []) of - #httpdb{url=Url} -> - iolist_to_binary(couch_util:url_strip_password(Url)); - LocalDb when is_binary(LocalDb) -> - LocalDb + try + couch_replicator_docs:parse_rep_db(Endpoint, [], []) of + #httpdb{url = Url} -> + iolist_to_binary(couch_util:url_strip_password(Url)) + catch + throw:{error, local_endpoints_not_supported} -> + Endpoint end. @@ -359,7 +361,8 @@ strip_url_creds_test_() -> fun (_) -> meck:unload() end, [ t_strip_http_basic_creds(), - t_strip_http_props_creds() + t_strip_http_props_creds(), + t_strip_local_db_creds() ] }. diff --git a/src/couch_replicator/src/couch_replicator_docs.erl b/src/couch_replicator/src/couch_replicator_docs.erl index c07caa1aa..2d6db1b73 100644 --- a/src/couch_replicator/src/couch_replicator_docs.erl +++ b/src/couch_replicator/src/couch_replicator_docs.erl @@ -424,7 +424,7 @@ parse_rep_db(<<"https://", _/binary>> = Url, Proxy, Options) -> parse_rep_db({[{<<"url">>, Url}]}, Proxy, Options); parse_rep_db(<<_/binary>>, _Proxy, _Options) -> - throw({error, <<"Local endpoints not supported since CouchDB 3.x">>}); + throw({error, local_endpoints_not_supported}); parse_rep_db(undefined, _Proxy, _Options) -> throw({error, <<"Missing replicator database">>}). @@ -843,7 +843,7 @@ t_error_on_local_endpoint() -> {<<"source">>, <<"localdb">>}, {<<"target">>, <<"http://somehost.local/tgt">>} ]}, - Expect = <<"Local endpoints not supported since CouchDB 3.x">>, + Expect = local_endpoints_not_supported, ?assertThrow({bad_rep_doc, Expect}, parse_rep_doc_without_id(RepDoc)) end). |