Skip to content

Commit a070ae4

Browse files
committed
Style fixes and better tests.
1 parent f53d09e commit a070ae4

File tree

4 files changed

+25
-10
lines changed

4 files changed

+25
-10
lines changed

lib/gitlab_lfs_authentication.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ def initialize(username, lfs_token, repository_http_path)
1111
end
1212

1313
def self.build_from_json(json)
14-
values = JSON.parse(json)
14+
values = JSON.parse(json) rescue nil
1515
self.new(values['username'], values['lfs_token'], values['repository_http_path'])
1616
end
1717

18-
def authenticate!
18+
def authentication_payload
1919
authorization = {
2020
header: {
2121
Authorization: "Basic #{Base64.strict_encode64("#{username}:#{lfs_token}")}"

lib/gitlab_shell.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ def lfs_authenticate
194194

195195
return unless lfs_access
196196

197-
puts lfs_access.authenticate!
197+
puts lfs_access.authentication_payload
198198
end
199199

200200
private
Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,37 @@
11
require 'spec_helper'
22
require 'gitlab_lfs_authentication'
3+
require 'json'
34

45
describe GitlabLfsAuthentication do
5-
let(:user) { { 'username' => 'dzaporozhets', 'lfs_token' => 'wsnys8Zm8Jn7zyhHTAAK' } }
6-
76
subject do
8-
GitlabLfsAuthentication.new('dzaporozhets', 'wsnys8Zm8Jn7zyhHTAAK', 'http://gitlab.dev/repo')
7+
GitlabLfsAuthentication.build_from_json(
8+
JSON.generate(
9+
{
10+
username: 'dzaporozhets',
11+
lfs_token: 'wsnys8Zm8Jn7zyhHTAAK',
12+
repository_http_path: 'http://gitlab.dev/repo'
13+
}
14+
)
15+
)
916
end
1017

11-
describe '#initialize' do
18+
describe '#build_from_json' do
1219
it { subject.username.should == 'dzaporozhets' }
1320
it { subject.lfs_token.should == 'wsnys8Zm8Jn7zyhHTAAK' }
1421
it { subject.repository_http_path.should == 'http://gitlab.dev/repo' }
1522
end
1623

17-
describe '#authenticate!' do
24+
describe '#authentication_payload' do
1825
result = "{\"header\":{\"Authorization\":\"Basic ZHphcG9yb3poZXRzOndzbnlzOFptOEpuN3p5aEhUQUFL\"},\"href\":\"http://gitlab.dev/repo/info/lfs/\"}"
1926

20-
it { subject.authenticate!.should == result }
27+
it { subject.authentication_payload.should eq(result) }
28+
29+
it 'should be a proper JSON' do
30+
payload = subject.authentication_payload
31+
json_payload = JSON.parse(payload)
32+
33+
json_payload['header']['Authorization'].should eq('Basic ZHphcG9yb3poZXRzOndzbnlzOFptOEpuN3p5aEhUQUFL')
34+
json_payload['href'].should eq('http://gitlab.dev/repo/info/lfs/')
35+
end
2136
end
2237
end

spec/gitlab_shell_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@
135135
end
136136

137137
its(:repo_name) { should == 'dzaporozhets/gitlab.git' }
138-
its(:git_cmd) { should == 'git-lfs-authenticate' }
138+
its(:command) { should == 'git-lfs-authenticate' }
139139
its(:git_access) { should == 'git-upload-pack' }
140140
end
141141
end

0 commit comments

Comments
 (0)