Commit 9a6ef53c authored by Bob Van Landuyt's avatar Bob Van Landuyt

Merge branch '260305-fix-default-rat-user-mail' into 'master'

Fix default emaildomain when creating PAT users

See merge request gitlab-org/gitlab!74506
parents 347a44a5 b8f08407
......@@ -75,7 +75,8 @@ module ResourceAccessTokens
end
def generate_email
email_pattern = "#{resource_type}#{resource.id}_bot%s@example.com"
# Default emaildomain need to be reworked. See gitlab-org/gitlab#260305
email_pattern = "#{resource_type}#{resource.id}_bot%s@noreply.#{Gitlab.config.gitlab.host}"
uniquify.string(-> (n) { Kernel.sprintf(email_pattern, n) }) do |s|
User.find_by_email(s)
......
......@@ -98,11 +98,11 @@ selected role and [scope](#scopes-for-a-project-access-token) of the project acc
- The name is set to the name of the token.
- The username is set to `project_{project_id}_bot` for the first access token. For example, `project_123_bot`.
- The email is set to `project{project_id}_bot@example.com`. For example, `project123_bot@example.com`.
- The email is set to `project{project_id}_bot@noreply.{Gitlab.config.gitlab.host}`. For example, `project123_bot@noreply.example.com`.
- For additional access tokens in the same project, the username is set to `project_{project_id}_bot{bot_count}`. For
example, `project_123_bot1`.
- For additional access tokens in the same project, the email is set to `project{project_id}_bot{bot_count}@example.com`.
For example, `project123_bot1@example.com`.
- For additional access tokens in the same project, the email is set to `project{project_id}_bot{bot_count}@noreply.{Gitlab.config.gitlab.host}`.
For example, `project123_bot1@noreply.example.com`.
API calls made with a project access token are associated with the corresponding bot user.
......
......@@ -10,6 +10,10 @@ RSpec.describe ResourceAccessTokens::CreateService do
let_it_be(:group) { create(:group, :private) }
let_it_be(:params) { {} }
before do
stub_config_setting(host: 'example.com')
end
describe '#execute' do
shared_examples 'token creation fails' do
let(:resource) { create(:project)}
......@@ -88,6 +92,15 @@ RSpec.describe ResourceAccessTokens::CreateService do
end
end
context 'bot email' do
it 'check email domain' do
response = subject
access_token = response.payload[:access_token]
expect(access_token.user.email).to end_with("@noreply.#{Gitlab.config.gitlab.host}")
end
end
context 'access level' do
context 'when user does not specify an access level' do
it 'adds the bot user as a maintainer in the resource' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment