|
720 | 720 | let(:uaa_client_id) { 'cc_routing' } |
721 | 721 |
|
722 | 722 | before do |
723 | | - allow(uaa_client).to receive_messages(users_for_ids: {}, get_clients: [{ client_id: uaa_client_id }]) |
| 723 | + allow(uaa_client).to receive_messages(users_for_ids: {}) |
724 | 724 | end |
725 | 725 |
|
726 | 726 | let(:api_call) { ->(user_headers) { post '/v3/users', params.to_json, user_headers } } |
|
814 | 814 | end |
815 | 815 | end |
816 | 816 | end |
| 817 | + |
| 818 | + context 'when "allow_user_creation_by_org_manager" is enabled' do |
| 819 | + before do |
| 820 | + TestConfig.override(allow_user_creation_by_org_manager: true) |
| 821 | + allow(CloudController::DependencyLocator.instance).to receive(:uaa_shadow_user_creation_client).and_return(uaa_client) |
| 822 | + end |
| 823 | + |
| 824 | + describe 'when creating a user by guid' do |
| 825 | + before do |
| 826 | + allow(uaa_client).to receive(:users_for_ids).and_return({}) |
| 827 | + end |
| 828 | + |
| 829 | + let(:api_call) { ->(user_headers) { post '/v3/users', params.to_json, user_headers } } |
| 830 | + |
| 831 | + let(:user_json) do |
| 832 | + { |
| 833 | + guid: params[:guid], |
| 834 | + created_at: iso8601, |
| 835 | + updated_at: iso8601, |
| 836 | + username: nil, |
| 837 | + presentation_name: params[:guid], |
| 838 | + origin: nil, |
| 839 | + metadata: { |
| 840 | + labels: {}, |
| 841 | + annotations: {} |
| 842 | + }, |
| 843 | + links: { |
| 844 | + self: { href: %r{#{Regexp.escape(link_prefix)}/v3/users/#{params[:guid]}} } |
| 845 | + } |
| 846 | + } |
| 847 | + end |
| 848 | + |
| 849 | + let(:expected_codes_and_responses) do |
| 850 | + h = Hash.new( |
| 851 | + code: 403 |
| 852 | + ) |
| 853 | + h['admin'] = { |
| 854 | + code: 201, |
| 855 | + response_object: user_json |
| 856 | + } |
| 857 | + h |
| 858 | + end |
| 859 | + |
| 860 | + it_behaves_like 'permissions for single object endpoint', ALL_PERMISSIONS |
| 861 | + end |
| 862 | + |
| 863 | + describe 'when creating a user by username and origin' do |
| 864 | + let(:params) do |
| 865 | + { |
| 866 | + username: 'some-user', |
| 867 | + origin: 'idp.local' |
| 868 | + } |
| 869 | + end |
| 870 | + let(:user_guid) { 'new-user-guid' } |
| 871 | + |
| 872 | + let(:api_call) { ->(user_headers) { post '/v3/users', params.to_json, user_headers } } |
| 873 | + |
| 874 | + let(:user_json) do |
| 875 | + { |
| 876 | + guid: user_guid, |
| 877 | + created_at: iso8601, |
| 878 | + updated_at: iso8601, |
| 879 | + username: params[:username], |
| 880 | + presentation_name: params[:username], |
| 881 | + origin: params[:origin], |
| 882 | + metadata: { |
| 883 | + labels: {}, |
| 884 | + annotations: {} |
| 885 | + }, |
| 886 | + links: { |
| 887 | + self: { href: %r{#{Regexp.escape(link_prefix)}/v3/users/#{user_guid}} } |
| 888 | + } |
| 889 | + } |
| 890 | + end |
| 891 | + |
| 892 | + let(:expected_codes_and_responses) do |
| 893 | + h = Hash.new( |
| 894 | + code: 403 |
| 895 | + ) |
| 896 | + h['admin'] = { |
| 897 | + code: 201, |
| 898 | + response_object: user_json |
| 899 | + } |
| 900 | + h['org_manager'] = { |
| 901 | + code: 201, |
| 902 | + response_object: user_json |
| 903 | + } |
| 904 | + h |
| 905 | + end |
| 906 | + |
| 907 | + before do |
| 908 | + allow(uaa_client).to receive(:users_for_ids).with(['new-user-guid']).and_return( |
| 909 | + { |
| 910 | + user_guid => { |
| 911 | + 'username' => 'some-user', |
| 912 | + 'origin' => 'idp.local' |
| 913 | + } |
| 914 | + } |
| 915 | + ) |
| 916 | + allow(uaa_client).to receive(:create_shadow_user).and_return({ 'id' => user_guid }) |
| 917 | + end |
| 918 | + |
| 919 | + it_behaves_like 'permissions for single object endpoint', ALL_PERMISSIONS |
| 920 | + end |
| 921 | + |
| 922 | + context 'when parameters are invalid' do |
| 923 | + let(:params) do |
| 924 | + { |
| 925 | + guid: user_guid, |
| 926 | + username: 'some-user', |
| 927 | + origin: 'idp.local' |
| 928 | + } |
| 929 | + end |
| 930 | + let(:user_guid) { 'new-user-guid' } |
| 931 | + |
| 932 | + let(:api_call) { ->(user_headers) { post '/v3/users', params.to_json, user_headers } } |
| 933 | + |
| 934 | + let(:user_json) do |
| 935 | + { |
| 936 | + guid: user_guid, |
| 937 | + created_at: iso8601, |
| 938 | + updated_at: iso8601, |
| 939 | + username: params[:username], |
| 940 | + presentation_name: params[:username], |
| 941 | + origin: params[:origin], |
| 942 | + metadata: { |
| 943 | + labels: {}, |
| 944 | + annotations: {} |
| 945 | + }, |
| 946 | + links: { |
| 947 | + self: { href: %r{#{Regexp.escape(link_prefix)}/v3/users/#{user_guid}} } |
| 948 | + } |
| 949 | + } |
| 950 | + end |
| 951 | + |
| 952 | + let(:expected_codes_and_responses) do |
| 953 | + h = Hash.new( |
| 954 | + code: 403 |
| 955 | + ) |
| 956 | + h['admin'] = { |
| 957 | + code: 422, |
| 958 | + response_object: user_json |
| 959 | + } |
| 960 | + h['org_manager'] = { |
| 961 | + code: 422, |
| 962 | + response_object: user_json |
| 963 | + } |
| 964 | + h |
| 965 | + end |
| 966 | + |
| 967 | + it_behaves_like 'permissions for single object endpoint', ALL_PERMISSIONS |
| 968 | + end |
| 969 | + end |
817 | 970 | end |
818 | 971 |
|
819 | 972 | describe 'PATCH /v3/users/:guid' do |
|
0 commit comments