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
e31b982a
Commit
e31b982a
authored
Feb 07, 2017
by
Pawel Chojnacki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make deploy key not show in User's keys list
parent
027a4bd2
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
53 additions
and
13 deletions
+53
-13
app/models/user.rb
app/models/user.rb
+6
-1
changelogs/unreleased/27480-deploy_keys_should_not_show_up_in_users_keys_list.yml
...480-deploy_keys_should_not_show_up_in_users_keys_list.yml
+4
-0
spec/controllers/profiles/keys_controller_spec.rb
spec/controllers/profiles/keys_controller_spec.rb
+9
-10
spec/factories/keys.rb
spec/factories/keys.rb
+5
-2
spec/models/user_spec.rb
spec/models/user_spec.rb
+29
-0
No files found.
app/models/user.rb
View file @
e31b982a
...
@@ -51,7 +51,12 @@ class User < ActiveRecord::Base
...
@@ -51,7 +51,12 @@ class User < ActiveRecord::Base
has_one
:namespace
,
->
{
where
type:
nil
},
dependent: :destroy
,
foreign_key: :owner_id
has_one
:namespace
,
->
{
where
type:
nil
},
dependent: :destroy
,
foreign_key: :owner_id
# Profile
# Profile
has_many
:keys
,
dependent: :destroy
has_many
:keys
,
->
do
type
=
Key
.
arel_table
[
:type
]
where
(
type
.
not_eq
(
'DeployKey'
).
or
(
type
.
eq
(
nil
)))
end
,
dependent: :destroy
has_many
:deploy_keys
,
->
{
where
(
type:
'DeployKey'
)
},
dependent: :destroy
has_many
:emails
,
dependent: :destroy
has_many
:emails
,
dependent: :destroy
has_many
:personal_access_tokens
,
dependent: :destroy
has_many
:personal_access_tokens
,
dependent: :destroy
has_many
:identities
,
dependent: :destroy
,
autosave:
true
has_many
:identities
,
dependent: :destroy
,
autosave:
true
...
...
changelogs/unreleased/27480-deploy_keys_should_not_show_up_in_users_keys_list.yml
0 → 100644
View file @
e31b982a
---
title
:
Do not display deploy keys in user's own ssh keys list
merge_request
:
9024
author
:
spec/controllers/profiles/keys_controller_spec.rb
View file @
e31b982a
...
@@ -42,10 +42,9 @@ describe Profiles::KeysController do
...
@@ -42,10 +42,9 @@ describe Profiles::KeysController do
end
end
describe
"user with keys"
do
describe
"user with keys"
do
before
do
let!
(
:key
)
{
create
(
:key
,
user:
user
)
}
user
.
keys
<<
create
(
:key
)
let!
(
:another_key
)
{
create
(
:another_key
,
user:
user
)
}
user
.
keys
<<
create
(
:another_key
)
let!
(
:deploy_key
)
{
create
(
:deploy_key
,
user:
user
)
}
end
it
"does generally work"
do
it
"does generally work"
do
get
:get_keys
,
username:
user
.
username
get
:get_keys
,
username:
user
.
username
...
@@ -53,16 +52,16 @@ describe Profiles::KeysController do
...
@@ -53,16 +52,16 @@ describe Profiles::KeysController do
expect
(
response
).
to
be_success
expect
(
response
).
to
be_success
end
end
it
"renders all keys separated with a new line"
do
it
"renders all
non deploy
keys separated with a new line"
do
get
:get_keys
,
username:
user
.
username
get
:get_keys
,
username:
user
.
username
expect
(
response
.
body
).
not_to
eq
(
""
)
expect
(
response
.
body
).
not_to
eq
(
''
)
expect
(
response
.
body
).
to
eq
(
user
.
all_ssh_keys
.
join
(
"
\n
"
))
expect
(
response
.
body
).
to
eq
(
user
.
all_ssh_keys
.
join
(
"
\n
"
))
# Unique part of key 1
expect
(
response
.
body
).
to
include
(
key
.
key
.
sub
(
' dummy@gitlab.com'
,
''
))
expect
(
response
.
body
).
to
match
(
/PWx6WM4lhHNedGfBpPJNPpZ/
)
expect
(
response
.
body
).
to
include
(
another_key
.
key
)
# Key 2
expect
(
response
.
body
).
to
match
(
/AQDmTillFzNTrrGgwaCKaSj/
)
expect
(
response
.
body
).
not_to
include
(
deploy_key
.
key
)
end
end
it
"does not render the comment of the key"
do
it
"does not render the comment of the key"
do
...
...
spec/factories/keys.rb
View file @
e31b982a
...
@@ -2,10 +2,13 @@ FactoryGirl.define do
...
@@ -2,10 +2,13 @@ FactoryGirl.define do
factory
:key
do
factory
:key
do
title
title
key
do
key
do
"ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAIEAiPWx6WM4lhHNedGfBpPJNPpZ7yKu+dnn1SJejgt4596k6YjzGGphH2TUxwKzxcKDKKezwkpfnxPkSMkuEspGRt/aZZ9wa++Oi7Qkr8prgHc4soW6NUlfDzpvZK2H5E7eQaSeP3SAwGmQKUFHCddNaP0L+hM7zhFNzjFvpaMgJw0= dummy@gitlab.com"
'ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAIEAiPWx6WM4lhHNedGfBpPJNPpZ7yKu+dnn1SJejgt4596k6YjzGGphH2TUxwKzxcKDKKezwkpfnxPkSMkuEspGRt/aZZ9wa++Oi7Qkr8prgHc4soW6NUlfDzpvZK2H5E7eQaSeP3SAwGmQKUFHCddNaP0L+hM7zhFNzjFvpaMgJw0= dummy@gitlab.com'
end
end
factory
:deploy_key
,
class:
'DeployKey'
do
factory
:deploy_key
,
class:
'DeployKey'
do
key
do
'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDFf6RYK3qu/RKF/3ndJmL5xgMLp3O96x8lTay+QGZ0+9FnnAXMdUqBq/ZU6d/gyMB4IaW3nHzM1w049++yAB6UPCzMB8Uo27K5/jyZCtj7Vm9PFNjF/8am1kp46c/SeYicQgQaSBdzIW3UDEa1Ef68qroOlvpi9PYZ/tA7M0YP0K5PXX+E36zaIRnJVMPT3f2k+GnrxtjafZrwFdpOP/Fol5BQLBgcsyiU+LM1SuaCrzd8c9vyaTA1CxrkxaZh+buAi0PmdDtaDrHd42gqZkXCKavyvgM5o2CkQ5LJHCgzpXy05qNFzmThBSkb+XtoxbyagBiGbVZtSVow6Xa7qewz'
end
end
end
factory
:personal_key
do
factory
:personal_key
do
...
@@ -14,7 +17,7 @@ FactoryGirl.define do
...
@@ -14,7 +17,7 @@ FactoryGirl.define do
factory
:another_key
do
factory
:another_key
do
key
do
key
do
"ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDmTillFzNTrrGgwaCKaSj+QCz81E6jBc/s9av0+3b1Hwfxgkqjl4nAK/OD2NjgyrONDTDfR8cRN4eAAy6nY8GLkOyYBDyuc5nTMqs5z3yVuTwf3koGm/YQQCmo91psZ2BgDFTor8SVEE5Mm1D1k3JDMhDFxzzrOtRYFPci9lskTJaBjpqWZ4E9rDTD2q/QZntCqbC3wE9uSemRQB5f8kik7vD/AD8VQXuzKladrZKkzkONCPWsXDspUitjM8HkQdOf0PsYn1CMUC1xKYbCxkg5TkEosIwGv6CoEArUrdu/4+10LVslq494mAvEItywzrluCLCnwELfW+h/m8UHoVhZ"
'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDmTillFzNTrrGgwaCKaSj+QCz81E6jBc/s9av0+3b1Hwfxgkqjl4nAK/OD2NjgyrONDTDfR8cRN4eAAy6nY8GLkOyYBDyuc5nTMqs5z3yVuTwf3koGm/YQQCmo91psZ2BgDFTor8SVEE5Mm1D1k3JDMhDFxzzrOtRYFPci9lskTJaBjpqWZ4E9rDTD2q/QZntCqbC3wE9uSemRQB5f8kik7vD/AD8VQXuzKladrZKkzkONCPWsXDspUitjM8HkQdOf0PsYn1CMUC1xKYbCxkg5TkEosIwGv6CoEArUrdu/4+10LVslq494mAvEItywzrluCLCnwELfW+h/m8UHoVhZ'
end
end
factory
:another_deploy_key
,
class:
'DeployKey'
do
factory
:another_deploy_key
,
class:
'DeployKey'
do
...
...
spec/models/user_spec.rb
View file @
e31b982a
...
@@ -19,6 +19,7 @@ describe User, models: true do
...
@@ -19,6 +19,7 @@ describe User, models: true do
it
{
is_expected
.
to
have_many
(
:project_members
).
dependent
(
:destroy
)
}
it
{
is_expected
.
to
have_many
(
:project_members
).
dependent
(
:destroy
)
}
it
{
is_expected
.
to
have_many
(
:groups
)
}
it
{
is_expected
.
to
have_many
(
:groups
)
}
it
{
is_expected
.
to
have_many
(
:keys
).
dependent
(
:destroy
)
}
it
{
is_expected
.
to
have_many
(
:keys
).
dependent
(
:destroy
)
}
it
{
is_expected
.
to
have_many
(
:deploy_keys
).
dependent
(
:destroy
)
}
it
{
is_expected
.
to
have_many
(
:events
).
dependent
(
:destroy
)
}
it
{
is_expected
.
to
have_many
(
:events
).
dependent
(
:destroy
)
}
it
{
is_expected
.
to
have_many
(
:recent_events
).
class_name
(
'Event'
)
}
it
{
is_expected
.
to
have_many
(
:recent_events
).
class_name
(
'Event'
)
}
it
{
is_expected
.
to
have_many
(
:issues
).
dependent
(
:destroy
)
}
it
{
is_expected
.
to
have_many
(
:issues
).
dependent
(
:destroy
)
}
...
@@ -303,6 +304,34 @@ describe User, models: true do
...
@@ -303,6 +304,34 @@ describe User, models: true do
end
end
end
end
shared_context
'user keys'
do
let
(
:user
)
{
create
(
:user
)
}
let!
(
:key
)
{
create
(
:key
,
user:
user
)
}
let!
(
:deploy_key
)
{
create
(
:deploy_key
,
user:
user
)
}
end
describe
'#keys'
do
include_context
'user keys'
context
'with key and deploy key stored'
do
it
'returns stored key, but not deploy_key'
do
expect
(
user
.
keys
).
to
include
key
expect
(
user
.
keys
).
not_to
include
deploy_key
end
end
end
describe
'#deploy_keys'
do
include_context
'user keys'
context
'with key and deploy key stored'
do
it
'returns stored deploy key, but not normal key'
do
expect
(
user
.
deploy_keys
).
to
include
deploy_key
expect
(
user
.
deploy_keys
).
not_to
include
key
end
end
end
describe
'#confirm'
do
describe
'#confirm'
do
before
do
before
do
allow_any_instance_of
(
ApplicationSetting
).
to
receive
(
:send_user_confirmation_email
).
and_return
(
true
)
allow_any_instance_of
(
ApplicationSetting
).
to
receive
(
:send_user_confirmation_email
).
and_return
(
true
)
...
...
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