|
705 | 705 | end |
706 | 706 |
|
707 | 707 | before do |
708 | | - allow(CloudController::DependencyLocator.instance).to receive(:uaa_shadow_user_creation_client).and_return(uaa_client) |
709 | | - allow(uaa_client).to receive(:create_shadow_user).and_return({ 'id' => user_guid }) |
| 708 | + allow(CloudController::DependencyLocator.instance).to receive_messages(uaa_shadow_user_creation_client: uaa_client, uaa_username_lookup_client: uaa_client) |
| 709 | + allow(uaa_client).to receive_messages(create_shadow_user: { 'id' => user_guid }, ids_for_usernames_and_origins: []) |
710 | 710 | end |
711 | 711 |
|
712 | 712 | it_behaves_like 'permissions for single object endpoint', ALL_PERMISSIONS |
|
867 | 867 | context 'when "allow_user_creation_by_org_manager" is enabled' do |
868 | 868 | before do |
869 | 869 | TestConfig.override(allow_user_creation_by_org_manager: true) |
870 | | - allow(CloudController::DependencyLocator.instance).to receive(:uaa_shadow_user_creation_client).and_return(uaa_client) |
| 870 | + allow(CloudController::DependencyLocator.instance).to receive_messages(uaa_shadow_user_creation_client: uaa_client, uaa_username_lookup_client: uaa_client) |
871 | 871 | end |
872 | 872 |
|
873 | 873 | describe 'when creating a user by guid' do |
|
954 | 954 | end |
955 | 955 |
|
956 | 956 | before do |
957 | | - allow(uaa_client).to receive(:create_shadow_user).and_return({ 'id' => user_guid }) |
| 957 | + allow(uaa_client).to receive_messages(create_shadow_user: { 'id' => user_guid }, ids_for_usernames_and_origins: []) |
958 | 958 | end |
959 | 959 |
|
960 | 960 | it_behaves_like 'permissions for single object endpoint', ALL_PERMISSIONS |
|
967 | 967 |
|
968 | 968 | expect(uaa_client).not_to have_received(:users_for_ids) |
969 | 969 | end |
| 970 | + |
| 971 | + context 'when user already exists in UAA' do |
| 972 | + before do |
| 973 | + allow(uaa_client).to receive(:ids_for_usernames_and_origins).and_return([user_guid]) |
| 974 | + end |
| 975 | + |
| 976 | + it 'does not try to create a shadow user' do |
| 977 | + post '/v3/users', params.to_json, admin_header |
| 978 | + |
| 979 | + expect(last_response).to have_status_code(201) |
| 980 | + expect(parsed_response).to match_json_response(user_json) |
| 981 | + |
| 982 | + expect(uaa_client).not_to have_received(:create_shadow_user) |
| 983 | + end |
| 984 | + end |
970 | 985 | end |
971 | 986 |
|
972 | 987 | context 'when parameters are invalid' do |
|
0 commit comments