Skip to content
Snippets Groups Projects
Commit dc9100d1 authored by Valery Sizov's avatar Valery Sizov
Browse files

Invalidate stored service password if the endpoint URL is changed. STEP 2

parent b83a18a5
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -39,7 +39,10 @@ class Admin::ServicesController < Admin::ApplicationController
end
 
def application_services_params
params.permit(:id,
service_params = params.permit(:id,
service: Projects::ServicesController::ALLOWED_PARAMS)
service_params[:service].delete("password") if service_params[:service]["password"].blank?
service_params
end
end
Loading
Loading
@@ -48,7 +48,7 @@ class BambooService < CiService
end
 
def reset_password
if prop_updated?(:bamboo_url)
if prop_updated?(:bamboo_url) && !prop_updated?(:password)
self.password = nil
end
end
Loading
Loading
Loading
Loading
@@ -45,7 +45,7 @@ class TeamcityService < CiService
end
 
def reset_password
if prop_updated?(:teamcity_url)
if prop_updated?(:teamcity_url) && !prop_updated?(:password)
self.password = nil
end
end
Loading
Loading
Loading
Loading
@@ -110,7 +110,12 @@ class Service < ActiveRecord::Base
properties['#{arg}']
end
 
def #{arg}_was
@#{arg}_was
end
def #{arg}=(value)
@#{arg}_was = self.properties['#{arg}']
self.properties['#{arg}'] = value
end
}
Loading
Loading
@@ -120,10 +125,8 @@ class Service < ActiveRecord::Base
# ActiveRecord does not provide a mechanism to track changes in serialized keys.
# This is why we need to perform extra query to do it mannually.
def prop_updated?(prop_name)
relation_name = self.type.underscore
previous_value = project.send(relation_name).send(prop_name)
return false if previous_value.nil?
previous_value != send(prop_name)
return false if send("#{prop_name}_was").nil?
send("#{prop_name}_was") != send(prop_name)
end
 
def async_execute(data)
Loading
Loading
Loading
Loading
@@ -52,5 +52,13 @@ describe BambooService, models: true do
@bamboo_service.save
expect(@bamboo_service.password).to eq("password")
end
it "does not reset password if new url is set together with password" do
@bamboo_service.bamboo_url = 'http://gitlab_edited.com'
@bamboo_service.password = '123'
@bamboo_service.save
expect(@bamboo_service.password).to eq("123")
expect(@bamboo_service.bamboo_url).to eq("http://gitlab_edited.com")
end
end
end
Loading
Loading
@@ -52,5 +52,13 @@ describe TeamcityService, models: true do
@teamcity_service.save
expect(@teamcity_service.password).to eq("password")
end
it "does not reset password if new url is set together with password" do
@teamcity_service.teamcity_url = 'http://gitlab_edited.com'
@teamcity_service.password = '123'
@teamcity_service.save
expect(@teamcity_service.password).to eq("123")
expect(@teamcity_service.teamcity_url).to eq("http://gitlab_edited.com")
end
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment