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
3f421a01
Commit
3f421a01
authored
Aug 01, 2018
by
Ash McKenzie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update Actor::Username, add specs
parent
5663f7a1
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
96 additions
and
5 deletions
+96
-5
lib/actor/username.rb
lib/actor/username.rb
+10
-4
lib/gitlab_shell.rb
lib/gitlab_shell.rb
+1
-1
spec/actor/username_spec.rb
spec/actor/username_spec.rb
+79
-0
spec/actor_spec.rb
spec/actor_spec.rb
+6
-0
No files found.
lib/actor/username.rb
View file @
3f421a01
require_relative
'base'
require_relative
'key'
module
Actor
class
Username
<
Base
alias
username
identifier
class
Username
<
Key
def
self
.
identifier_prefix
'username'
.
freeze
end
...
...
@@ -13,7 +12,14 @@ module Actor
end
def
self
.
id_regex
/\Ausername\-\d+\Z/
/\Ausername\-[a-z0-9-]+\z/
end
private
# Override Base#label
def
label
'user'
end
end
end
lib/gitlab_shell.rb
View file @
3f421a01
...
...
@@ -33,7 +33,7 @@ class GitlabShell
end
parsed_command
=
parse_cmd
(
origin_cmd
)
action
=
determine_action
(
parsed_command
)
# FIXME: watch out
action
=
determine_action
(
parsed_command
)
action
.
execute
(
parsed_command
.
command
,
parsed_command
.
args
)
rescue
GitlabNet
::
ApiUnreachableError
$stderr
.
puts
"GitLab: Failed to authorize your Git request: internal API unreachable"
...
...
spec/actor/username_spec.rb
0 → 100644
View file @
3f421a01
require_relative
'../spec_helper'
require_relative
'../../lib/actor/username'
describe
Actor
::
Username
do
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
(
subject
).
and_return
(
discover_payload
)
end
describe
'.from'
do
it
'returns an instance of Actor::Username'
do
expect
(
described_class
.
from
(
"username-
#{
username
}
"
)).
to
be_a
(
Actor
::
Username
)
end
it
'has an id == 1'
do
expect
(
described_class
.
from
(
'username-1'
).
id
).
to
eq
'1'
end
end
describe
'.identifier_prefix'
do
it
"returns 'user'"
do
expect
(
described_class
.
identifier_prefix
).
to
eql
'username'
end
end
describe
'.identifier_key'
do
it
"returns 'username'"
do
expect
(
described_class
.
identifier_key
).
to
eql
'username'
end
end
subject
{
described_class
.
new
(
username
,
audit_usernames:
audit_usernames
)
}
describe
'#username'
do
context
'without a valid user'
do
it
"returns '@testuser'"
do
expect
(
subject
.
username
).
to
eql
"@
#{
username
}
"
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
'#identifier'
do
it
"returns 'username-testuser'"
do
expect
(
subject
.
identifier
).
to
eql
'username-testuser'
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
"@
#{
username
}
"
end
end
context
'when audit_usernames is false'
do
let
(
:audit_usernames
)
{
false
}
it
"returns 'user with identifier username-testuser'"
do
expect
(
subject
.
log_username
).
to
eql
"user with identifier username-
#{
username
}
"
end
end
end
end
spec/actor_spec.rb
View file @
3f421a01
...
...
@@ -23,6 +23,12 @@ describe Actor do
expect
(
described_class
.
new_from
(
'user-1'
)).
to
be_a
(
Actor
::
User
)
end
end
context
'of Username'
do
it
'returns an instance of Username'
do
expect
(
described_class
.
new_from
(
'username-john1'
)).
to
be_a
(
Actor
::
Username
)
end
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