2017-06-06 11:39:54 -04:00
|
|
|
require('spec_helper')
|
|
|
|
|
2017-10-17 06:12:24 -04:00
|
|
|
describe ProfilesController, :request_store do
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
|
|
|
|
describe 'PUT update' do
|
|
|
|
it 'allows an email update from a user without an external email address' do
|
2017-06-06 11:39:54 -04:00
|
|
|
sign_in(user)
|
|
|
|
|
|
|
|
put :update,
|
|
|
|
user: { email: "john@gmail.com", name: "John" }
|
|
|
|
|
|
|
|
user.reload
|
|
|
|
|
|
|
|
expect(response.status).to eq(302)
|
|
|
|
expect(user.unconfirmed_email).to eq('john@gmail.com')
|
|
|
|
end
|
|
|
|
|
2017-09-18 13:00:38 -04:00
|
|
|
it "allows an email update without confirmation if existing verified email" do
|
|
|
|
user = create(:user)
|
2017-09-24 13:52:49 -04:00
|
|
|
create(:email, :confirmed, user: user, email: 'john@gmail.com')
|
2017-09-18 13:00:38 -04:00
|
|
|
sign_in(user)
|
|
|
|
|
|
|
|
put :update,
|
|
|
|
user: { email: "john@gmail.com", name: "John" }
|
|
|
|
|
|
|
|
user.reload
|
|
|
|
|
|
|
|
expect(response.status).to eq(302)
|
|
|
|
expect(user.unconfirmed_email).to eq nil
|
|
|
|
end
|
|
|
|
|
2017-10-17 06:12:24 -04:00
|
|
|
it 'ignores an email update from a user with an external email address' do
|
2017-08-29 04:57:41 -04:00
|
|
|
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-06-06 11:39:54 -04:00
|
|
|
sign_in(ldap_user)
|
|
|
|
|
|
|
|
put :update,
|
|
|
|
user: { email: "john@gmail.com", name: "John" }
|
|
|
|
|
|
|
|
ldap_user.reload
|
|
|
|
|
|
|
|
expect(response.status).to eq(302)
|
|
|
|
expect(ldap_user.unconfirmed_email).not_to eq('john@gmail.com')
|
|
|
|
end
|
2017-08-29 04:57:41 -04:00
|
|
|
|
2017-10-17 06:12:24 -04:00
|
|
|
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
|
2017-08-29 04:57:41 -04:00
|
|
|
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,
|
|
|
|
user: { email: "john@gmail.com", name: "John", location: "City, Country" }
|
|
|
|
|
|
|
|
ldap_user.reload
|
|
|
|
|
|
|
|
expect(response.status).to eq(302)
|
|
|
|
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
|
2017-06-06 11:39:54 -04:00
|
|
|
end
|
2017-10-17 06:12:24 -04:00
|
|
|
|
|
|
|
describe 'PUT update_username' do
|
|
|
|
let(:namespace) { user.namespace }
|
|
|
|
let(:gitlab_shell) { Gitlab::Shell.new }
|
2017-12-01 08:58:49 -05:00
|
|
|
let(:new_username) { generate(:username) }
|
2017-10-17 06:12:24 -04:00
|
|
|
|
|
|
|
it 'allows username change' do
|
|
|
|
sign_in(user)
|
|
|
|
|
|
|
|
put :update_username,
|
|
|
|
user: { username: new_username }
|
|
|
|
|
|
|
|
user.reload
|
|
|
|
|
|
|
|
expect(response.status).to eq(302)
|
|
|
|
expect(user.username).to eq(new_username)
|
|
|
|
end
|
|
|
|
|
2018-04-06 05:36:22 -04:00
|
|
|
it 'updates a username using JSON request' do
|
|
|
|
sign_in(user)
|
|
|
|
|
|
|
|
put :update_username,
|
|
|
|
user: { username: new_username },
|
|
|
|
format: :json
|
|
|
|
|
|
|
|
expect(response.status).to eq(200)
|
|
|
|
expect(json_response['message']).to eq('Username successfully changed')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'renders an error message when the username was not updated' do
|
|
|
|
sign_in(user)
|
|
|
|
|
|
|
|
put :update_username,
|
|
|
|
user: { username: 'invalid username.git' },
|
|
|
|
format: :json
|
|
|
|
|
|
|
|
expect(response.status).to eq(422)
|
|
|
|
expect(json_response['message']).to match(/Username change failed/)
|
|
|
|
end
|
|
|
|
|
2018-04-04 03:59:35 -04:00
|
|
|
it 'raises a correct error when the username is missing' do
|
|
|
|
sign_in(user)
|
|
|
|
|
|
|
|
expect { put :update_username, user: { gandalf: 'you shall not pass' } }
|
|
|
|
.to raise_error(ActionController::ParameterMissing)
|
|
|
|
end
|
|
|
|
|
2017-12-01 08:58:49 -05:00
|
|
|
context 'with legacy storage' do
|
|
|
|
it 'moves dependent projects to new namespace' do
|
|
|
|
project = create(:project_empty_repo, :legacy_storage, namespace: namespace)
|
2017-10-17 06:12:24 -04:00
|
|
|
|
2017-12-01 08:58:49 -05:00
|
|
|
sign_in(user)
|
2017-10-17 06:12:24 -04:00
|
|
|
|
2017-12-01 08:58:49 -05:00
|
|
|
put :update_username,
|
|
|
|
user: { username: new_username }
|
2017-10-17 06:12:24 -04:00
|
|
|
|
2017-12-01 08:58:49 -05:00
|
|
|
user.reload
|
|
|
|
|
|
|
|
expect(response.status).to eq(302)
|
2018-04-13 06:57:19 -04:00
|
|
|
expect(gitlab_shell.exists?(project.repository_storage, "#{new_username}/#{project.path}.git")).to be_truthy
|
2017-12-01 08:58:49 -05:00
|
|
|
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,
|
|
|
|
user: { username: new_username }
|
|
|
|
|
|
|
|
user.reload
|
|
|
|
|
|
|
|
expect(response.status).to eq(302)
|
2018-04-13 06:57:19 -04:00
|
|
|
expect(gitlab_shell.exists?(project.repository_storage, "#{project.disk_path}.git")).to be_truthy
|
2017-12-01 08:58:49 -05:00
|
|
|
expect(before_disk_path).to eq(project.disk_path)
|
|
|
|
end
|
2017-10-17 06:12:24 -04:00
|
|
|
end
|
|
|
|
end
|
2017-06-06 11:39:54 -04:00
|
|
|
end
|