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
c2b101cc
Commit
c2b101cc
authored
Feb 11, 2019
by
Ash McKenzie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Provide expires_in for LFS if available
parent
1fcb56f4
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
57 additions
and
24 deletions
+57
-24
lib/gitlab_lfs_authentication.rb
lib/gitlab_lfs_authentication.rb
+23
-10
spec/gitlab_lfs_authentication_spec.rb
spec/gitlab_lfs_authentication_spec.rb
+34
-14
No files found.
lib/gitlab_lfs_authentication.rb
View file @
c2b101cc
...
...
@@ -2,29 +2,42 @@ require 'base64'
require
'json'
class
GitlabLfsAuthentication
# TODO: These don't need to be public
attr_accessor
:username
,
:lfs_token
,
:repository_http_path
def
initialize
(
username
,
lfs_token
,
repository_http_path
)
def
initialize
(
username
,
lfs_token
,
repository_http_path
,
expires_in
=
nil
)
@username
=
username
@lfs_token
=
lfs_token
@repository_http_path
=
repository_http_path
@expires_in
=
expires_in
end
def
self
.
build_from_json
(
json
)
values
=
JSON
.
parse
(
json
)
new
(
values
[
'username'
],
values
[
'lfs_token'
],
values
[
'repository_http_path'
])
new
(
values
[
'username'
],
values
[
'lfs_token'
],
values
[
'repository_http_path'
],
values
[
'expires_in'
])
rescue
nil
end
# Source: https://github.com/git-lfs/git-lfs/blob/master/docs/api/server-discovery.md#ssh
#
def
authentication_payload
authorization
=
{
header:
{
Authorization
:
"Basic
#{
Base64
.
strict_encode64
(
"
#{
username
}
:
#{
lfs_token
}
"
)
}
"
},
href:
"
#{
repository_http_path
}
/info/lfs/"
}
JSON
.
generate
(
authorization
)
payload
=
{
header:
{
Authorization
:
authorization
},
href:
href
}
payload
[
:expires_in
]
=
@expires_in
if
@expires_in
JSON
.
generate
(
payload
)
end
private
def
authorization
"Basic
#{
Base64
.
strict_encode64
(
"
#{
username
}
:
#{
lfs_token
}
"
)
}
"
end
def
href
"
#{
repository_http_path
}
/info/lfs"
end
end
spec/gitlab_lfs_authentication_spec.rb
View file @
c2b101cc
...
...
@@ -3,15 +3,17 @@ require 'gitlab_lfs_authentication'
require
'json'
describe
GitlabLfsAuthentication
do
subject
do
GitlabLfsAuthentication
.
build_from_json
(
JSON
.
generate
(
let
(
:payload_from_gitlab_api
)
do
{
username:
'dzaporozhets'
,
lfs_token:
'wsnys8Zm8Jn7zyhHTAAK'
,
repository_http_path:
'http://gitlab.dev/repo'
}
)
end
subject
do
GitlabLfsAuthentication
.
build_from_json
(
JSON
.
generate
(
payload_from_gitlab_api
)
)
end
...
...
@@ -22,16 +24,34 @@ describe GitlabLfsAuthentication do
end
describe
'#authentication_payload'
do
result
=
"{
\"
header
\"
:{
\"
Authorization
\"
:
\"
Basic ZHphcG9yb3poZXRzOndzbnlzOFptOEpuN3p5aEhUQUFL
\"
},
\"
href
\"
:
\"
http://gitlab.dev/repo/info/lfs/
\"
}"
it
{
expect
(
subject
.
authentication_payload
).
to
eq
(
result
)
}
it
'should be a proper JSON'
do
shared_examples
'a valid payload'
do
it
'should be proper JSON'
do
payload
=
subject
.
authentication_payload
json_payload
=
JSON
.
parse
(
payload
)
expect
(
json_payload
[
'header'
][
'Authorization'
]).
to
eq
(
'Basic ZHphcG9yb3poZXRzOndzbnlzOFptOEpuN3p5aEhUQUFL'
)
expect
(
json_payload
[
'href'
]).
to
eq
(
'http://gitlab.dev/repo/info/lfs/'
)
expect
(
json_payload
[
'href'
]).
to
eq
(
'http://gitlab.dev/repo/info/lfs'
)
end
end
context
'without expires_in'
do
let
(
:result
)
{
{
'header'
=>
{
'Authorization'
=>
'Basic ZHphcG9yb3poZXRzOndzbnlzOFptOEpuN3p5aEhUQUFL'
},
'href'
=>
'http://gitlab.dev/repo/info/lfs'
}.
to_json
}
it
{
expect
(
subject
.
authentication_payload
).
to
eq
(
result
)
}
it_behaves_like
'a valid payload'
end
context
'with expires_in'
do
let
(
:result
)
{
{
'header'
=>
{
'Authorization'
=>
'Basic ZHphcG9yb3poZXRzOndzbnlzOFptOEpuN3p5aEhUQUFL'
},
'href'
=>
'http://gitlab.dev/repo/info/lfs'
,
'expires_in'
=>
1800
}.
to_json
}
before
do
payload_from_gitlab_api
[
:expires_in
]
=
1800
end
it
{
expect
(
subject
.
authentication_payload
).
to
eq
(
result
)
}
it_behaves_like
'a valid payload'
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