Commit 0d40c074 authored by Stan Hu's avatar Stan Hu

Don't validate Jenkins username if password is blank

Users attempting to activate Jenkins with an empty username
and password would still encounter a validation error because
it appeared that the password was changed from `nil` to an
empty string. Relax this validation to check the
password must actually have contents to require a username.

Closes https://gitlab.com/gitlab-org/gitlab-ee/issues/9246
parent 93e6eb3c
......@@ -7,7 +7,7 @@ class JenkinsService < CiService
validates :jenkins_url, presence: true, url: true, if: :activated?
validates :project_name, presence: true, if: :activated?
validates :username, presence: true, if: ->(service) { service.activated? && service.password_touched? }
validates :username, presence: true, if: ->(service) { service.activated? && service.password_touched? && service.password.present? }
default_value_for :push_events, true
default_value_for :merge_requests_events, false
......
---
title: Don't validate Jenkins username if password is blank
merge_request: 9198
author:
type: fixed
......@@ -60,6 +60,15 @@ describe JenkinsService do
it { is_expected.to validate_presence_of :username }
end
context 'when password is blank' do
it 'does not validate the username' do
expect(subject).not_to validate_presence_of :username
subject.password = ''
subject.save
end
end
end
context 'when the service is inactive' 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