diff options
author | Eric Avdey <eiri@eiri.ca> | 2019-02-14 16:52:58 -0400 |
---|---|---|
committer | Eric Avdey <eiri@eiri.ca> | 2019-02-15 21:45:04 -0400 |
commit | 35c2ac8e1f2ab6465c0fe0377068169867444b7d (patch) | |
tree | 31141575700a678a31dd08a57f4879b6a7e03914 | |
parent | 92d406f74f81ab959c25d64ddd456c948aa571c2 (diff) | |
download | couchdb-shard-split-couch-tests.tar.gz |
Validate target's name before creationshard-split-couch-tests
-rw-r--r-- | src/couch/src/couch_db_split.erl | 5 | ||||
-rw-r--r-- | src/couch/test/couch_db_split_tests.erl | 12 |
2 files changed, 17 insertions, 0 deletions
diff --git a/src/couch/src/couch_db_split.erl b/src/couch/src/couch_db_split.erl index 87570b4f3..8ffa5b49a 100644 --- a/src/couch/src/couch_db_split.erl +++ b/src/couch/src/couch_db_split.erl @@ -125,6 +125,11 @@ cleanup_target(Source, Target) when is_binary(Source), is_binary(Target) -> split(SourceDb, Partitioned, Engine, Targets0, PickFun, {M, F, A} = HashFun) -> Targets = maps:fold(fun(Key, DbName, Map) -> + case couch_db:validate_dbname(DbName) of + ok -> ok; + {error, E} -> + throw({target_create_error, DbName, E, Map}) + end, {ok, Filepath} = couch_server:get_engine_path(DbName, Engine), Opts = [create, ?ADMIN_CTX] ++ case Partitioned of true -> [{partitioned, true}, {hash, [M, F, A]}]; diff --git a/src/couch/test/couch_db_split_tests.erl b/src/couch/test/couch_db_split_tests.erl index 14c42fd47..5361c3b8e 100644 --- a/src/couch/test/couch_db_split_tests.erl +++ b/src/couch/test/couch_db_split_tests.erl @@ -54,6 +54,7 @@ split_test_() -> [ fun should_fail_on_missing_source/1, fun should_fail_on_existing_target/1, + fun should_fail_on_invalid_target_name/1, fun should_crash_on_invalid_tmap/1 ] } @@ -107,6 +108,17 @@ should_fail_on_existing_target(DbName) -> ?_assertMatch({error, {target_create_error, DbName, eexist}}, Response). +should_fail_on_invalid_target_name(DbName) -> + Ranges = make_ranges(2), + TMap = maps:map(fun([B, _], _) -> + iolist_to_binary(["_$", couch_util:to_hex(<<B:32/integer>>)]) + end, make_targets(Ranges)), + Expect = {error, {target_create_error, <<"_$00000000">>, + {illegal_database_name, <<"_$00000000">>}}}, + Response = couch_db_split:split(DbName, TMap, fun fake_pickfun/3), + ?_assertMatch(Expect, Response). + + should_crash_on_invalid_tmap(DbName) -> Ranges = make_ranges(1), TMap = make_targets(Ranges), |