Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-shell
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
nexedi
gitlab-shell
Commits
28ff5940
Commit
28ff5940
authored
Jul 26, 2018
by
Ash McKenzie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
New User class
parent
5ef06ac7
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
77 additions
and
0 deletions
+77
-0
lib/user.rb
lib/user.rb
+25
-0
spec/user_spec.rb
spec/user_spec.rb
+52
-0
No files found.
lib/user.rb
0 → 100644
View file @
28ff5940
require_relative
'gitlab_net'
class
User
ANONYMOUS_USER
=
'Anonymous'
.
freeze
def
initialize
(
key_id
,
audit_usernames:
false
)
@key_id
=
key_id
@audit_usernames
=
audit_usernames
end
def
username
@username
||=
begin
user
=
GitlabNet
.
new
.
discover
(
key_id
)
user
?
"@
#{
user
[
'username'
]
}
"
:
ANONYMOUS_USER
end
end
def
log_username
audit_usernames
?
username
:
"user with key
#{
key_id
}
"
end
private
attr_reader
:key_id
,
:audit_usernames
end
spec/user_spec.rb
0 → 100644
View file @
28ff5940
require_relative
'spec_helper'
require_relative
'../lib/user'
describe
User
,
vcr:
true
do
let
(
:key_id
)
{
'key-1'
}
let
(
:username
)
{
'testuser'
}
let
(
:api
)
{
double
(
GitlabNet
)
}
let
(
:discover_payload
)
{
{
'username'
=>
username
}
}
let
(
:audit_usernames
)
{
nil
}
before
do
allow
(
GitlabNet
).
to
receive
(
:new
).
and_return
(
api
)
allow
(
api
).
to
receive
(
:discover
).
with
(
key_id
).
and_return
(
discover_payload
)
end
subject
{
described_class
.
new
(
key_id
,
audit_usernames:
audit_usernames
)
}
describe
'#username'
do
context
'with a valid user'
do
it
"returns '@testuser'"
do
expect
(
subject
.
username
).
to
eql
'@testuser'
end
end
context
'without a valid user'
do
let
(
:discover_payload
)
{
nil
}
it
"returns 'Anonymous'"
do
expect
(
subject
.
username
).
to
eql
'Anonymous'
end
end
end
describe
'#log_username'
do
context
'when audit_usernames is true'
do
let
(
:audit_usernames
)
{
true
}
it
"returns 'testuser'"
do
expect
(
subject
.
log_username
).
to
eql
'@testuser'
end
end
context
'when audit_usernames is false'
do
let
(
:audit_usernames
)
{
false
}
it
"returns 'user with key key-1'"
do
expect
(
subject
.
log_username
).
to
eql
'user with key key-1'
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