Commit a070ae4a authored by Patricio Cano's avatar Patricio Cano

Style fixes and better tests.

parent f53d09e1
...@@ -11,11 +11,11 @@ class GitlabLfsAuthentication ...@@ -11,11 +11,11 @@ class GitlabLfsAuthentication
end end
def self.build_from_json(json) 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']) self.new(values['username'], values['lfs_token'], values['repository_http_path'])
end end
def authenticate! def authentication_payload
authorization = { authorization = {
header: { header: {
Authorization: "Basic #{Base64.strict_encode64("#{username}:#{lfs_token}")}" Authorization: "Basic #{Base64.strict_encode64("#{username}:#{lfs_token}")}"
......
...@@ -194,7 +194,7 @@ class GitlabShell ...@@ -194,7 +194,7 @@ class GitlabShell
return unless lfs_access return unless lfs_access
puts lfs_access.authenticate! puts lfs_access.authentication_payload
end end
private private
......
require 'spec_helper' require 'spec_helper'
require 'gitlab_lfs_authentication' require 'gitlab_lfs_authentication'
require 'json'
describe GitlabLfsAuthentication do describe GitlabLfsAuthentication do
let(:user) { { 'username' => 'dzaporozhets', 'lfs_token' => 'wsnys8Zm8Jn7zyhHTAAK' } }
subject do 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 end
describe '#initialize' do describe '#build_from_json' do
it { subject.username.should == 'dzaporozhets' } it { subject.username.should == 'dzaporozhets' }
it { subject.lfs_token.should == 'wsnys8Zm8Jn7zyhHTAAK' } it { subject.lfs_token.should == 'wsnys8Zm8Jn7zyhHTAAK' }
it { subject.repository_http_path.should == 'http://gitlab.dev/repo' } it { subject.repository_http_path.should == 'http://gitlab.dev/repo' }
end end
describe '#authenticate!' do describe '#authentication_payload' do
result = "{\"header\":{\"Authorization\":\"Basic ZHphcG9yb3poZXRzOndzbnlzOFptOEpuN3p5aEhUQUFL\"},\"href\":\"http://gitlab.dev/repo/info/lfs/\"}" 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
end end
...@@ -135,7 +135,7 @@ describe GitlabShell do ...@@ -135,7 +135,7 @@ describe GitlabShell do
end end
its(:repo_name) { should == 'dzaporozhets/gitlab.git' } 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' } its(:git_access) { should == 'git-upload-pack' }
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment