From f1f8dd4b5c3dbd1ebfe3f7f8f9017f39bc7e8872 Mon Sep 17 00:00:00 2001 From: gspasov Date: Fri, 2 Aug 2019 14:51:09 +0300 Subject: [PATCH] [NY-7917] Add one more fix in micro_roster --- apps/roster/src/protocol/micro_roster.erl | 4 +++- apps/roster/src/test/micro_test.erl | 21 +++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/apps/roster/src/protocol/micro_roster.erl b/apps/roster/src/protocol/micro_roster.erl index 549febc8f..29762e223 100644 --- a/apps/roster/src/protocol/micro_roster.erl +++ b/apps/roster/src/protocol/micro_roster.erl @@ -31,7 +31,9 @@ info(#'Roster'{status = add, phone = LinkPhone, nick = Nick, id = LinkRosterId} kvs:put(Profile#'Profile'{phone = Phone, rosters = RosterIds++[NewRosterId], update = roster:now_msec()}), Roster; - {reply, {bert, #io{code = #error{}} = Err}, _, _} -> Err + {reply, {bert, #io{code = #error{}} = Err}, _, _} -> + kvs:delete('Roster', NewRosterId), + Err end end; #error{} -> #io{code = #error{code = profile_not_found}} diff --git a/apps/roster/src/test/micro_test.erl b/apps/roster/src/test/micro_test.erl index 7e6d96c4d..793b62026 100644 --- a/apps/roster/src/test/micro_test.erl +++ b/apps/roster/src/test/micro_test.erl @@ -111,6 +111,26 @@ test_profile_import_error() -> {ok, Profile} = kvs:get('Profile', Phone), %% Check that the Profile hasn't change in the DB ok. +%% Create scenario where we try to create Profile with Roster that has nick that is already taken by another Roster +test_creation_of_account_with_taken_username() -> + RosterAmount = length(kvs:all('Roster')), + Nick = <<"already_used_nick">>, + P_UUID = list_to_binary(uuid:to_string(uuid:uuid4())), + R_UUID = list_to_binary(uuid:to_string(uuid:uuid4())), + kvs:put(#'Index'{id = {nick, Nick}, roster = [50000]}), %% Give nick to some Roster + {reply, {bert, {io, {error, nick}, P_UUID}}, _, _} = + roster_client:test_info(micro_profile, #'Profile'{status = create, + phone = P_UUID, + rosters = [#'Roster'{status = add, + nick = Nick, %% Use the same nick for the New Roster (This should cause an error of used nick) + id = R_UUID, + phone = P_UUID}]}, #cx{params = <<"sys_test">>}), + case length(kvs:all('Roster')) =:= RosterAmount of + false -> throw("Unwanted Roster!"); + true -> ok + end, + ok. + test_micro() -> APhone = <<"MICRO">>, Token = <>, @@ -289,6 +309,7 @@ test_account2() -> suite() -> [ + test_creation_of_account_with_taken_username(), test_roster_mismatch_data(), test_roster_account_already_exists(), test_profile_import_error(), -- GitLab