summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorAsh McKenzie <amckenzie@gitlab.com>2019-02-11 17:23:03 +1100
committerAsh McKenzie <amckenzie@gitlab.com>2019-02-14 12:56:56 +1100
commitc2b101cc2d1f51a4968673756eecfb2e36bf682c (patch)
tree28ec983e58c4922196f9b1311942a6531dcf37a8 /spec
parent1fcb56f42cdb2b6f562d8875abc4e33f7ef3e258 (diff)
downloadgitlab-shell-c2b101cc2d1f51a4968673756eecfb2e36bf682c.tar.gz
Diffstat (limited to 'spec')
-rw-r--r--spec/gitlab_lfs_authentication_spec.rb48
1 files changed, 34 insertions, 14 deletions
diff --git a/spec/gitlab_lfs_authentication_spec.rb b/spec/gitlab_lfs_authentication_spec.rb
index 81b53a7..acc9e3d 100644
--- a/spec/gitlab_lfs_authentication_spec.rb
+++ b/spec/gitlab_lfs_authentication_spec.rb
@@ -3,15 +3,17 @@ require 'gitlab_lfs_authentication'
require 'json'
describe GitlabLfsAuthentication do
+ 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(
- {
- username: 'dzaporozhets',
- lfs_token: 'wsnys8Zm8Jn7zyhHTAAK',
- repository_http_path: 'http://gitlab.dev/repo'
- }
- )
+ 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/\"}"
+ 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')
+ 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 }
- it { expect(subject.authentication_payload).to eq(result) }
+ before do
+ payload_from_gitlab_api[:expires_in] = 1800
+ end
- it 'should be a proper JSON' do
- payload = subject.authentication_payload
- json_payload = JSON.parse(payload)
+ it { expect(subject.authentication_payload).to eq(result) }
- expect(json_payload['header']['Authorization']).to eq('Basic ZHphcG9yb3poZXRzOndzbnlzOFptOEpuN3p5aEhUQUFL')
- expect(json_payload['href']).to eq('http://gitlab.dev/repo/info/lfs/')
+ it_behaves_like 'a valid payload'
end
end
end