Commit a64f174d authored by Patricio Cano's avatar Patricio Cano

Refactored JSON header generation to its own class and added tests for it

parent dbf374e1
require 'base64'
require 'json'
class GitlabLfsAuthentication
attr_accessor :user, :repository_http_path
def initialize(user, repository_http_path)
@user = user
@repository_http_path = repository_http_path
end
def authenticate!
authorization = {
header: {
Authorization: "Basic #{Base64.strict_encode64("#{user['username']}:#{user['lfs_token']}")}"
},
href: "#{repository_http_path}/info/lfs/"
}
JSON.generate(authorization)
end
end
require 'shellwords'
require 'base64'
require 'json'
require_relative 'gitlab_net'
require_relative 'gitlab_lfs_authentication'
class GitlabShell
class AccessDeniedError < StandardError; end
......@@ -195,14 +194,7 @@ class GitlabShell
def lfs_authenticate
return unless user
authorization = {
header: {
Authorization: "Basic #{Base64.strict_encode64("#{user['username']}:#{user['lfs_token']}")}"
},
href: "#{repository_http_path}/info/lfs/"
}
puts JSON.generate(authorization)
puts GitlabLfsAuthentication.new(user, repository_http_path).authenticate!
end
private
......
require 'spec_helper'
require 'gitlab_lfs_authentication'
describe GitlabLfsAuthentication do
let(:user) { { 'username' => 'dzaporozhets', 'lfs_token' => 'wsnys8Zm8Jn7zyhHTAAK' } }
subject do
GitlabLfsAuthentication.new(user, 'http://gitlab.dev/repo')
end
describe '#initialize' do
it { subject.user.should == user }
it { subject.repository_http_path.should == 'http://gitlab.dev/repo' }
end
describe '#authenticate!' do
result = "{\"header\":{\"Authorization\":\"Basic ZHphcG9yb3poZXRzOndzbnlzOFptOEpuN3p5aEhUQUFL\"},\"href\":\"http://gitlab.dev/repo/info/lfs/\"}"
it { subject.authenticate!.should == result }
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