summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatricio Cano <suprnova32@gmail.com>2016-09-06 16:13:04 -0500
committerPatricio Cano <suprnova32@gmail.com>2016-09-06 16:27:07 -0500
commita070ae4a320f8da830862e1dd11eea8b1281ab8c (patch)
treeac2083c8cc3263de7cbebe77677838514d82392a
parentf53d09e1eb1323be9cd697813a6f47375c091f6a (diff)
downloadgitlab-shell-a070ae4a320f8da830862e1dd11eea8b1281ab8c.tar.gz
Style fixes and better tests.
-rw-r--r--lib/gitlab_lfs_authentication.rb4
-rw-r--r--lib/gitlab_shell.rb2
-rw-r--r--spec/gitlab_lfs_authentication_spec.rb27
-rw-r--r--spec/gitlab_shell_spec.rb2
4 files changed, 25 insertions, 10 deletions
diff --git a/lib/gitlab_lfs_authentication.rb b/lib/gitlab_lfs_authentication.rb
index 4b36229..196cdd7 100644
--- a/lib/gitlab_lfs_authentication.rb
+++ b/lib/gitlab_lfs_authentication.rb
@@ -11,11 +11,11 @@ class GitlabLfsAuthentication
end
def self.build_from_json(json)
- values = JSON.parse(json)
+ values = JSON.parse(json) rescue nil
self.new(values['username'], values['lfs_token'], values['repository_http_path'])
end
- def authenticate!
+ def authentication_payload
authorization = {
header: {
Authorization: "Basic #{Base64.strict_encode64("#{username}:#{lfs_token}")}"
diff --git a/lib/gitlab_shell.rb b/lib/gitlab_shell.rb
index d3f9bbe..971b22f 100644
--- a/lib/gitlab_shell.rb
+++ b/lib/gitlab_shell.rb
@@ -194,7 +194,7 @@ class GitlabShell
return unless lfs_access
- puts lfs_access.authenticate!
+ puts lfs_access.authentication_payload
end
private
diff --git a/spec/gitlab_lfs_authentication_spec.rb b/spec/gitlab_lfs_authentication_spec.rb
index ff715cf..9e93a07 100644
--- a/spec/gitlab_lfs_authentication_spec.rb
+++ b/spec/gitlab_lfs_authentication_spec.rb
@@ -1,22 +1,37 @@
require 'spec_helper'
require 'gitlab_lfs_authentication'
+require 'json'
describe GitlabLfsAuthentication do
- let(:user) { { 'username' => 'dzaporozhets', 'lfs_token' => 'wsnys8Zm8Jn7zyhHTAAK' } }
-
subject do
- GitlabLfsAuthentication.new('dzaporozhets', 'wsnys8Zm8Jn7zyhHTAAK', 'http://gitlab.dev/repo')
+ GitlabLfsAuthentication.build_from_json(
+ JSON.generate(
+ {
+ username: 'dzaporozhets',
+ lfs_token: 'wsnys8Zm8Jn7zyhHTAAK',
+ repository_http_path: 'http://gitlab.dev/repo'
+ }
+ )
+ )
end
- describe '#initialize' do
+ describe '#build_from_json' do
it { subject.username.should == 'dzaporozhets' }
it { subject.lfs_token.should == 'wsnys8Zm8Jn7zyhHTAAK' }
it { subject.repository_http_path.should == 'http://gitlab.dev/repo' }
end
- describe '#authenticate!' do
+ describe '#authentication_payload' do
result = "{\"header\":{\"Authorization\":\"Basic ZHphcG9yb3poZXRzOndzbnlzOFptOEpuN3p5aEhUQUFL\"},\"href\":\"http://gitlab.dev/repo/info/lfs/\"}"
- it { subject.authenticate!.should == result }
+ it { subject.authentication_payload.should eq(result) }
+
+ it 'should be a proper JSON' do
+ payload = subject.authentication_payload
+ json_payload = JSON.parse(payload)
+
+ json_payload['header']['Authorization'].should eq('Basic ZHphcG9yb3poZXRzOndzbnlzOFptOEpuN3p5aEhUQUFL')
+ json_payload['href'].should eq('http://gitlab.dev/repo/info/lfs/')
+ end
end
end
diff --git a/spec/gitlab_shell_spec.rb b/spec/gitlab_shell_spec.rb
index a5e75e2..96cae40 100644
--- a/spec/gitlab_shell_spec.rb
+++ b/spec/gitlab_shell_spec.rb
@@ -135,7 +135,7 @@ describe GitlabShell do
end
its(:repo_name) { should == 'dzaporozhets/gitlab.git' }
- its(:git_cmd) { should == 'git-lfs-authenticate' }
+ its(:command) { should == 'git-lfs-authenticate' }
its(:git_access) { should == 'git-upload-pack' }
end
end