2019-07-31 22:56:46 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
require('spec_helper')
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
describe ProfilesController, :request_store do
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
|
2018-06-03 19:52:53 +05:30
|
|
|
describe 'POST update' do
|
|
|
|
it 'does not update password' do
|
|
|
|
sign_in(user)
|
|
|
|
|
|
|
|
expect do
|
|
|
|
post :update,
|
2019-02-15 15:39:39 +05:30
|
|
|
params: { user: { password: 'hello12345', password_confirmation: 'hello12345' } }
|
2018-06-03 19:52:53 +05:30
|
|
|
end.not_to change { user.reload.encrypted_password }
|
|
|
|
|
2020-04-22 19:07:51 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:found)
|
2018-06-03 19:52:53 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
describe 'PUT update' do
|
|
|
|
it 'allows an email update from a user without an external email address' do
|
2017-09-10 17:25:29 +05:30
|
|
|
sign_in(user)
|
|
|
|
|
|
|
|
put :update,
|
2019-02-15 15:39:39 +05:30
|
|
|
params: { user: { email: "john@gmail.com", name: "John" } }
|
2017-09-10 17:25:29 +05:30
|
|
|
|
|
|
|
user.reload
|
|
|
|
|
2020-04-22 19:07:51 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:found)
|
2017-09-10 17:25:29 +05:30
|
|
|
expect(user.unconfirmed_email).to eq('john@gmail.com')
|
|
|
|
end
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
it "allows an email update without confirmation if existing verified email" do
|
|
|
|
user = create(:user)
|
|
|
|
create(:email, :confirmed, user: user, email: 'john@gmail.com')
|
|
|
|
sign_in(user)
|
|
|
|
|
|
|
|
put :update,
|
2019-02-15 15:39:39 +05:30
|
|
|
params: { user: { email: "john@gmail.com", name: "John" } }
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
user.reload
|
|
|
|
|
2020-04-22 19:07:51 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:found)
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(user.unconfirmed_email).to eq nil
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'ignores an email update from a user with an external email address' do
|
|
|
|
stub_omniauth_setting(sync_profile_from_provider: ['ldap'])
|
|
|
|
stub_omniauth_setting(sync_profile_attributes: true)
|
|
|
|
|
|
|
|
ldap_user = create(:omniauth_user)
|
|
|
|
ldap_user.create_user_synced_attributes_metadata(provider: 'ldap', name_synced: true, email_synced: true)
|
2017-09-10 17:25:29 +05:30
|
|
|
sign_in(ldap_user)
|
|
|
|
|
|
|
|
put :update,
|
2019-02-15 15:39:39 +05:30
|
|
|
params: { user: { email: "john@gmail.com", name: "John" } }
|
2017-09-10 17:25:29 +05:30
|
|
|
|
|
|
|
ldap_user.reload
|
|
|
|
|
2020-04-22 19:07:51 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:found)
|
2017-09-10 17:25:29 +05:30
|
|
|
expect(ldap_user.unconfirmed_email).not_to eq('john@gmail.com')
|
|
|
|
end
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
it 'ignores an email and name update but allows a location update from a user with external email and name, but not external location' do
|
|
|
|
stub_omniauth_setting(sync_profile_from_provider: ['ldap'])
|
|
|
|
stub_omniauth_setting(sync_profile_attributes: true)
|
|
|
|
|
|
|
|
ldap_user = create(:omniauth_user, name: 'Alex')
|
|
|
|
ldap_user.create_user_synced_attributes_metadata(provider: 'ldap', name_synced: true, email_synced: true, location_synced: false)
|
|
|
|
sign_in(ldap_user)
|
|
|
|
|
|
|
|
put :update,
|
2019-02-15 15:39:39 +05:30
|
|
|
params: { user: { email: "john@gmail.com", name: "John", location: "City, Country" } }
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
ldap_user.reload
|
|
|
|
|
2020-04-22 19:07:51 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:found)
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(ldap_user.unconfirmed_email).not_to eq('john@gmail.com')
|
|
|
|
expect(ldap_user.name).not_to eq('John')
|
|
|
|
expect(ldap_user.location).to eq('City, Country')
|
|
|
|
end
|
2018-11-18 11:00:15 +05:30
|
|
|
|
|
|
|
it 'allows setting a user status' do
|
|
|
|
sign_in(user)
|
|
|
|
|
2019-02-15 15:39:39 +05:30
|
|
|
put :update, params: { user: { status: { message: 'Working hard!' } } }
|
2018-11-18 11:00:15 +05:30
|
|
|
|
|
|
|
expect(user.reload.status.message).to eq('Working hard!')
|
2020-03-13 15:44:24 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:found)
|
2018-11-18 11:00:15 +05:30
|
|
|
end
|
2020-04-08 14:13:33 +05:30
|
|
|
|
|
|
|
it 'allows updating user specified job title' do
|
|
|
|
title = 'Marketing Executive'
|
|
|
|
sign_in(user)
|
|
|
|
|
|
|
|
put :update, params: { user: { job_title: title } }
|
|
|
|
|
|
|
|
expect(user.reload.job_title).to eq(title)
|
|
|
|
expect(response).to have_gitlab_http_status(:found)
|
|
|
|
end
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
describe 'PUT update_username' do
|
|
|
|
let(:namespace) { user.namespace }
|
|
|
|
let(:gitlab_shell) { Gitlab::Shell.new }
|
2018-03-27 19:54:05 +05:30
|
|
|
let(:new_username) { generate(:username) }
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
it 'allows username change' do
|
|
|
|
sign_in(user)
|
|
|
|
|
|
|
|
put :update_username,
|
2019-02-15 15:39:39 +05:30
|
|
|
params: { user: { username: new_username } }
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
user.reload
|
|
|
|
|
2020-04-22 19:07:51 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:found)
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(user.username).to eq(new_username)
|
|
|
|
end
|
|
|
|
|
2018-05-09 12:01:36 +05:30
|
|
|
it 'updates a username using JSON request' do
|
|
|
|
sign_in(user)
|
|
|
|
|
|
|
|
put :update_username,
|
2019-02-15 15:39:39 +05:30
|
|
|
params: {
|
|
|
|
user: { username: new_username }
|
|
|
|
},
|
2018-05-09 12:01:36 +05:30
|
|
|
format: :json
|
|
|
|
|
2020-04-22 19:07:51 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2020-01-01 13:55:28 +05:30
|
|
|
expect(json_response['message']).to eq(s_('Profiles|Username successfully changed'))
|
2018-05-09 12:01:36 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'renders an error message when the username was not updated' do
|
|
|
|
sign_in(user)
|
|
|
|
|
|
|
|
put :update_username,
|
2019-02-15 15:39:39 +05:30
|
|
|
params: {
|
|
|
|
user: { username: 'invalid username.git' }
|
|
|
|
},
|
2018-05-09 12:01:36 +05:30
|
|
|
format: :json
|
|
|
|
|
2020-04-22 19:07:51 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:unprocessable_entity)
|
2018-05-09 12:01:36 +05:30
|
|
|
expect(json_response['message']).to match(/Username change failed/)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'raises a correct error when the username is missing' do
|
|
|
|
sign_in(user)
|
|
|
|
|
2019-02-15 15:39:39 +05:30
|
|
|
expect { put :update_username, params: { user: { gandalf: 'you shall not pass' } } }
|
2018-05-09 12:01:36 +05:30
|
|
|
.to raise_error(ActionController::ParameterMissing)
|
|
|
|
end
|
|
|
|
|
2018-03-27 19:54:05 +05:30
|
|
|
context 'with legacy storage' do
|
|
|
|
it 'moves dependent projects to new namespace' do
|
|
|
|
project = create(:project_empty_repo, :legacy_storage, namespace: namespace)
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2018-03-27 19:54:05 +05:30
|
|
|
sign_in(user)
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2018-03-27 19:54:05 +05:30
|
|
|
put :update_username,
|
2019-02-15 15:39:39 +05:30
|
|
|
params: { user: { username: new_username } }
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2018-03-27 19:54:05 +05:30
|
|
|
user.reload
|
|
|
|
|
2020-04-22 19:07:51 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:found)
|
2019-12-21 20:55:43 +05:30
|
|
|
expect(gitlab_shell.repository_exists?(project.repository_storage, "#{new_username}/#{project.path}.git")).to be_truthy
|
2018-03-27 19:54:05 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with hashed storage' do
|
|
|
|
it 'keeps repository location unchanged on disk' do
|
|
|
|
project = create(:project_empty_repo, namespace: namespace)
|
|
|
|
|
|
|
|
before_disk_path = project.disk_path
|
|
|
|
|
|
|
|
sign_in(user)
|
|
|
|
|
|
|
|
put :update_username,
|
2019-02-15 15:39:39 +05:30
|
|
|
params: { user: { username: new_username } }
|
2018-03-27 19:54:05 +05:30
|
|
|
|
|
|
|
user.reload
|
|
|
|
|
2020-04-22 19:07:51 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:found)
|
2019-12-21 20:55:43 +05:30
|
|
|
expect(gitlab_shell.repository_exists?(project.repository_storage, "#{project.disk_path}.git")).to be_truthy
|
2018-03-27 19:54:05 +05:30
|
|
|
expect(before_disk_path).to eq(project.disk_path)
|
|
|
|
end
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
2017-09-10 17:25:29 +05:30
|
|
|
end
|
|
|
|
end
|