diff options
Diffstat (limited to 'spec/controllers/profiles_controller_spec.rb')
-rw-r--r-- | spec/controllers/profiles_controller_spec.rb | 28 |
1 files changed, 17 insertions, 11 deletions
diff --git a/spec/controllers/profiles_controller_spec.rb b/spec/controllers/profiles_controller_spec.rb index 9a1f8a8442d..6e7cc058fbc 100644 --- a/spec/controllers/profiles_controller_spec.rb +++ b/spec/controllers/profiles_controller_spec.rb @@ -153,9 +153,12 @@ RSpec.describe ProfilesController, :request_store do let(:gitlab_shell) { Gitlab::Shell.new } let(:new_username) { generate(:username) } - it 'allows username change' do + before do sign_in(user) + allow(::Gitlab::ApplicationRateLimiter).to receive(:throttled?).and_return(false) + end + it 'allows username change' do put :update_username, params: { user: { username: new_username } } @@ -166,8 +169,6 @@ RSpec.describe ProfilesController, :request_store do end it 'updates a username using JSON request' do - sign_in(user) - put :update_username, params: { user: { username: new_username } @@ -179,8 +180,6 @@ RSpec.describe ProfilesController, :request_store do end it 'renders an error message when the username was not updated' do - sign_in(user) - put :update_username, params: { user: { username: 'invalid username.git' } @@ -192,8 +191,6 @@ RSpec.describe ProfilesController, :request_store do end it 'raises a correct error when the username is missing' do - sign_in(user) - expect { put :update_username, params: { user: { gandalf: 'you shall not pass' } } } .to raise_error(ActionController::ParameterMissing) end @@ -202,8 +199,6 @@ RSpec.describe ProfilesController, :request_store do it 'moves dependent projects to new namespace' do project = create(:project_empty_repo, :legacy_storage, namespace: namespace) - sign_in(user) - put :update_username, params: { user: { username: new_username } } @@ -220,8 +215,6 @@ RSpec.describe ProfilesController, :request_store do before_disk_path = project.disk_path - sign_in(user) - put :update_username, params: { user: { username: new_username } } @@ -232,5 +225,18 @@ RSpec.describe ProfilesController, :request_store do expect(before_disk_path).to eq(project.disk_path) end end + + context 'when the rate limit is reached' do + it 'does not update the username and returns status 429 Too Many Requests' do + expect(::Gitlab::ApplicationRateLimiter).to receive(:throttled?).with(:profile_update_username, scope: user).and_return(true) + + expect do + put :update_username, + params: { user: { username: new_username } } + end.not_to change { user.reload.username } + + expect(response).to have_gitlab_http_status(:too_many_requests) + end + end end end |