Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Jérome Perrin
gitlab-ce
Commits
07f60552
Commit
07f60552
authored
Oct 09, 2015
by
Valery Sizov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Invalidate stored service password if the endpoint URL is changed
parent
882bef79
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
158 additions
and
0 deletions
+158
-0
app/models/project_services/bamboo_service.rb
app/models/project_services/bamboo_service.rb
+7
-0
app/models/project_services/teamcity_service.rb
app/models/project_services/teamcity_service.rb
+7
-0
app/models/service.rb
app/models/service.rb
+9
-0
spec/models/project_services/bamboo_service_spec.rb
spec/models/project_services/bamboo_service_spec.rb
+56
-0
spec/models/project_services/teamcity_service_spec.rb
spec/models/project_services/teamcity_service_spec.rb
+56
-0
spec/models/service_spec.rb
spec/models/service_spec.rb
+23
-0
No files found.
app/models/project_services/bamboo_service.rb
View file @
07f60552
...
...
@@ -40,12 +40,19 @@ class BambooService < CiService
attr_accessor
:response
after_save
:compose_service_hook
,
if: :activated?
before_update
:reset_password
def
compose_service_hook
hook
=
service_hook
||
build_service_hook
hook
.
save
end
def
reset_password
if
prop_updated?
(
:bamboo_url
)
self
.
password
=
nil
end
end
def
title
'Atlassian Bamboo CI'
end
...
...
app/models/project_services/teamcity_service.rb
View file @
07f60552
...
...
@@ -37,12 +37,19 @@ class TeamcityService < CiService
attr_accessor
:response
after_save
:compose_service_hook
,
if: :activated?
before_update
:reset_password
def
compose_service_hook
hook
=
service_hook
||
build_service_hook
hook
.
save
end
def
reset_password
if
prop_updated?
(
:teamcity_url
)
self
.
password
=
nil
end
end
def
title
'JetBrains TeamCity CI'
end
...
...
app/models/service.rb
View file @
07f60552
...
...
@@ -117,6 +117,15 @@ class Service < ActiveRecord::Base
end
end
# 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
)
end
def
async_execute
(
data
)
return
unless
supported_events
.
include?
(
data
[
:object_kind
])
...
...
spec/models/project_services/bamboo_service_spec.rb
0 → 100644
View file @
07f60552
# == Schema Information
#
# Table name: services
#
# id :integer not null, primary key
# type :string(255)
# title :string(255)
# project_id :integer
# created_at :datetime
# updated_at :datetime
# active :boolean default(FALSE), not null
# properties :text
# template :boolean default(FALSE)
# push_events :boolean default(TRUE)
# issues_events :boolean default(TRUE)
# merge_requests_events :boolean default(TRUE)
# tag_push_events :boolean default(TRUE)
# note_events :boolean default(TRUE), not null
#
require
'spec_helper'
describe
BambooService
,
models:
true
do
describe
"Associations"
do
it
{
is_expected
.
to
belong_to
:project
}
it
{
is_expected
.
to
have_one
:service_hook
}
end
describe
"Execute"
do
let
(
:user
)
{
create
(
:user
)
}
let
(
:project
)
{
create
(
:project
)
}
before
do
@bamboo_service
=
BambooService
.
create
(
project:
create
(
:project
),
properties:
{
bamboo_url:
'http://gitlab.com'
,
username:
'mic'
,
password:
"password"
}
)
end
it
"reset password if url changed"
do
@bamboo_service
.
bamboo_url
=
'http://gitlab1.com'
@bamboo_service
.
save
expect
(
@bamboo_service
.
password
).
to
be_nil
end
it
"does not reset password if username changed"
do
@bamboo_service
.
username
=
"some_name"
@bamboo_service
.
save
expect
(
@bamboo_service
.
password
).
to
eq
(
"password"
)
end
end
end
spec/models/project_services/teamcity_service_spec.rb
0 → 100644
View file @
07f60552
# == Schema Information
#
# Table name: services
#
# id :integer not null, primary key
# type :string(255)
# title :string(255)
# project_id :integer
# created_at :datetime
# updated_at :datetime
# active :boolean default(FALSE), not null
# properties :text
# template :boolean default(FALSE)
# push_events :boolean default(TRUE)
# issues_events :boolean default(TRUE)
# merge_requests_events :boolean default(TRUE)
# tag_push_events :boolean default(TRUE)
# note_events :boolean default(TRUE), not null
#
require
'spec_helper'
describe
TeamcityService
,
models:
true
do
describe
"Associations"
do
it
{
is_expected
.
to
belong_to
:project
}
it
{
is_expected
.
to
have_one
:service_hook
}
end
describe
"Execute"
do
let
(
:user
)
{
create
(
:user
)
}
let
(
:project
)
{
create
(
:project
)
}
before
do
@teamcity_service
=
TeamcityService
.
create
(
project:
create
(
:project
),
properties:
{
teamcity_url:
'http://gitlab.com'
,
username:
'mic'
,
password:
"password"
}
)
end
it
"reset password if url changed"
do
@teamcity_service
.
teamcity_url
=
'http://gitlab1.com'
@teamcity_service
.
save
expect
(
@teamcity_service
.
password
).
to
be_nil
end
it
"does not reset password if username changed"
do
@teamcity_service
.
username
=
"some_name"
@teamcity_service
.
save
expect
(
@teamcity_service
.
password
).
to
eq
(
"password"
)
end
end
end
spec/models/service_spec.rb
View file @
07f60552
...
...
@@ -103,4 +103,27 @@ describe Service do
end
end
end
describe
"#prop_updated?"
do
let
(
:service
)
do
BambooService
.
create
(
project:
create
(
:project
),
properties:
{
bamboo_url:
'http://gitlab.com'
,
username:
'mic'
,
password:
"password"
}
)
end
it
"returns false"
do
service
.
username
=
"key_changed"
expect
(
service
.
prop_updated?
(
:bamboo_url
)).
to
be_falsy
end
it
"returns true"
do
service
.
bamboo_url
=
"http://other.com"
expect
(
service
.
prop_updated?
(
:bamboo_url
)).
to
be_truthy
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment