Commit 7b266997 authored by Valery Sizov's avatar Valery Sizov

Invalidate stored jira password if the endpoint URL is changed

parent 5bd8b016
v 8.2.0
- Invalidate stored jira password if the endpoint URL is changed
v 8.1.0 (unreleased)
- added an issues template (Hannes Rosenögger)
- Fix "Rebase onto master"
......
......@@ -27,6 +27,14 @@ class JiraService < IssueTrackerService
before_validation :set_api_version, :set_jira_issue_transition_id
before_update :reset_password
def reset_password
if project_url_changed? && !password_touched?
self.password = nil
end
end
def help
line1 = 'Setting `project_url`, `issues_url` and `new_issue_url` will '\
'allow a user to easily navigate to the Jira issue tracker. See the '\
......
......@@ -140,4 +140,69 @@ describe JiraService do
end
end
end
describe "Execute" do
let(:user) { create(:user) }
let(:project) { create(:project) }
context "when a password was previously set" do
before do
@service = JiraService.create(
project: create(:project),
properties: {
project_url: 'http://gitlab.com',
username: 'mic',
password: "password"
}
)
end
it "reset password if url changed" do
@service.project_url = 'http://gitlab1.com'
@service.save
expect(@service.password).to be_nil
end
it "does not reset password if username changed" do
@service.username = "some_name"
@service.save
expect(@service.password).to eq("password")
end
it "does not reset password if new url is set together with password, even if it's the same password" do
@service.project_url = 'http://gitlab_edited.com'
@service.password = 'password'
@service.save
expect(@service.password).to eq("password")
expect(@service.project_url).to eq("http://gitlab_edited.com")
end
it "should reset password if url changed, even if setter called multiple times" do
@service.project_url = 'http://gitlab1.com'
@service.project_url = 'http://gitlab1.com'
@service.save
expect(@service.password).to be_nil
end
end
context "when no password was previously set" do
before do
@service = JiraService.create(
project: create(:project),
properties: {
project_url: 'http://gitlab.com',
username: 'mic'
}
)
end
it "saves password if new url is set together with password" do
@service.project_url = 'http://gitlab_edited.com'
@service.password = 'password'
@service.save
expect(@service.password).to eq("password")
expect(@service.project_url).to eq("http://gitlab_edited.com")
end
end
end
end
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