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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
3bcb345e
Commit
3bcb345e
authored
Aug 09, 2018
by
Ash McKenzie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
New Geo::PushUser
parent
9e0dffa3
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
115 additions
and
0 deletions
+115
-0
ee/app/models/geo/push_user.rb
ee/app/models/geo/push_user.rb
+27
-0
ee/spec/models/geo/push_user_spec.rb
ee/spec/models/geo/push_user_spec.rb
+88
-0
No files found.
ee/app/models/geo/push_user.rb
0 → 100644
View file @
3bcb345e
# frozen_string_literal: true
class
Geo::PushUser
include
::
Gitlab
::
Identifier
def
initialize
(
gl_id
)
@gl_id
=
gl_id
end
def
self
.
needed_headers_provided?
(
headers
)
headers
[
'Geo-GL-Id'
].
present?
end
def
self
.
new_from_headers
(
headers
)
return
nil
unless
needed_headers_provided?
(
headers
)
new
(
headers
[
'Geo-GL-Id'
])
end
def
user
@user
||=
identify_using_ssh_key
(
gl_id
)
end
private
attr_reader
:gl_id
end
ee/spec/models/geo/push_user_spec.rb
0 → 100644
View file @
3bcb345e
# frozen_string_literal: true
require
'spec_helper'
describe
Geo
::
PushUser
do
let!
(
:user
)
{
create
(
:user
)
}
let!
(
:key
)
{
create
(
:key
,
user:
user
)
}
let
(
:gl_id
)
{
"key-
#{
key
.
id
}
"
}
subject
{
described_class
.
new
(
gl_id
)
}
describe
'.needed_headers_provided?'
do
where
(
:headers
)
do
[
{},
{
'Geo-GL-Id'
=>
nil
},
{
'Geo-GL-Id'
=>
''
}
]
end
with_them
do
it
'returns false'
do
expect
(
described_class
.
needed_headers_provided?
(
headers
)).
to
be
(
false
)
end
end
context
'where gl_id is not nil'
do
let
(
:headers
)
do
{
'Geo-GL-Id'
=>
gl_id
}
end
it
'returns true'
do
expect
(
described_class
.
needed_headers_provided?
(
headers
)).
to
be
(
true
)
end
end
end
describe
'.new_from_headers'
do
where
(
:headers
)
do
[
{},
{
'Geo-GL-Id'
=>
nil
},
{
'Geo-GL-Id'
=>
''
}
]
end
with_them
do
it
'returns false'
do
expect
(
described_class
.
new_from_headers
(
headers
)).
to
be_nil
end
end
context
'where gl_id is not nil'
do
let
(
:headers
)
do
{
'Geo-GL-Id'
=>
gl_id
}
end
it
'returns an instance of Geo::PushUser'
do
expect
(
described_class
.
new_from_headers
(
headers
)).
to
be_a
(
described_class
)
end
end
end
describe
'#user'
do
context
'with a junk gl_id'
do
let
(
:gl_id
)
{
"test"
}
it
'returns nil'
do
expect
(
subject
.
user
).
to
be_nil
end
end
context
'with an unsupported gl_id type'
do
let
(
:gl_id
)
{
"user-
#{
user
.
id
}
"
}
it
'returns nil'
do
expect
(
subject
.
user
).
to
be_nil
end
end
context
'when the User associated to gl_id matches the User associated to gl_username'
do
it
'returns a User'
do
expect
(
subject
.
user
).
to
be_a
(
User
)
end
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