Commit 26263a1c authored by Robert Speicher's avatar Robert Speicher

Merge branch 'bvl-test-geo-with-terms-enforced' into 'master'

Add specs for geo with terms enforced

See merge request gitlab-org/gitlab-ee!5679
parents b3e7c7ac e54f47ed
require 'spec_helper' require 'spec_helper'
describe API::Geo do describe API::Geo do
include TermsHelper
include ApiHelpers include ApiHelpers
include ::EE::GeoHelpers include ::EE::GeoHelpers
...@@ -16,6 +17,18 @@ describe API::Geo do ...@@ -16,6 +17,18 @@ describe API::Geo do
stub_current_geo_node(secondary_node) stub_current_geo_node(secondary_node)
end end
shared_examples 'with terms enforced' do
before do
enforce_terms
end
it 'responds with 200' do
request
expect(response).to have_gitlab_http_status(200)
end
end
describe 'GET /geo/transfers/attachment/1' do describe 'GET /geo/transfers/attachment/1' do
let(:note) { create(:note, :with_attachment) } let(:note) { create(:note, :with_attachment) }
let(:upload) { Upload.find_by(model: note, uploader: 'AttachmentUploader') } let(:upload) { Upload.find_by(model: note, uploader: 'AttachmentUploader') }
...@@ -33,13 +46,17 @@ describe API::Geo do ...@@ -33,13 +46,17 @@ describe API::Geo do
end end
context 'attachment file exists' do context 'attachment file exists' do
subject(:request) { get api("/geo/transfers/attachment/#{upload.id}"), nil, req_header }
it 'responds with 200 with X-Sendfile' do it 'responds with 200 with X-Sendfile' do
get api("/geo/transfers/attachment/#{upload.id}"), nil, req_header request
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(200)
expect(response.headers['Content-Type']).to eq('application/octet-stream') expect(response.headers['Content-Type']).to eq('application/octet-stream')
expect(response.headers['X-Sendfile']).to eq(note.attachment.path) expect(response.headers['X-Sendfile']).to eq(note.attachment.path)
end end
it_behaves_like 'with terms enforced'
end end
context 'attachment does not exist' do context 'attachment does not exist' do
...@@ -68,13 +85,17 @@ describe API::Geo do ...@@ -68,13 +85,17 @@ describe API::Geo do
end end
context 'avatar file exists' do context 'avatar file exists' do
subject(:request) { get api("/geo/transfers/avatar/#{upload.id}"), nil, req_header }
it 'responds with 200 with X-Sendfile' do it 'responds with 200 with X-Sendfile' do
get api("/geo/transfers/avatar/#{upload.id}"), nil, req_header request
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(200)
expect(response.headers['Content-Type']).to eq('application/octet-stream') expect(response.headers['Content-Type']).to eq('application/octet-stream')
expect(response.headers['X-Sendfile']).to eq(user.avatar.path) expect(response.headers['X-Sendfile']).to eq(user.avatar.path)
end end
it_behaves_like 'with terms enforced'
end end
context 'avatar does not exist' do context 'avatar does not exist' do
...@@ -105,13 +126,17 @@ describe API::Geo do ...@@ -105,13 +126,17 @@ describe API::Geo do
context 'when the Upload record exists' do context 'when the Upload record exists' do
context 'when the file exists' do context 'when the file exists' do
subject(:request) { get api("/geo/transfers/file/#{upload.id}"), nil, req_header }
it 'responds with 200 with X-Sendfile' do it 'responds with 200 with X-Sendfile' do
get api("/geo/transfers/file/#{upload.id}"), nil, req_header request
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(200)
expect(response.headers['Content-Type']).to eq('application/octet-stream') expect(response.headers['Content-Type']).to eq('application/octet-stream')
expect(response.headers['X-Sendfile']).to end_with('dk.png') expect(response.headers['X-Sendfile']).to end_with('dk.png')
end end
it_behaves_like 'with terms enforced'
end end
context 'file does not exist' do context 'file does not exist' do
...@@ -154,13 +179,17 @@ describe API::Geo do ...@@ -154,13 +179,17 @@ describe API::Geo do
context 'LFS object exists' do context 'LFS object exists' do
context 'file exists' do context 'file exists' do
subject(:request) { get api("/geo/transfers/lfs/#{lfs_object.id}"), nil, req_header }
it 'responds with 200 with X-Sendfile' do it 'responds with 200 with X-Sendfile' do
get api("/geo/transfers/lfs/#{lfs_object.id}"), nil, req_header request
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(200)
expect(response.headers['Content-Type']).to eq('application/octet-stream') expect(response.headers['Content-Type']).to eq('application/octet-stream')
expect(response.headers['X-Sendfile']).to eq(lfs_object.file.path) expect(response.headers['X-Sendfile']).to eq(lfs_object.file.path)
end end
it_behaves_like 'with terms enforced'
end end
context 'file does not exist' do context 'file does not exist' do
...@@ -185,7 +214,9 @@ describe API::Geo do ...@@ -185,7 +214,9 @@ describe API::Geo do
end end
describe 'GET /geo/status', :postgresql do describe 'GET /geo/status', :postgresql do
let(:request) { Gitlab::Geo::BaseRequest.new } let(:geo_base_request) { Gitlab::Geo::BaseRequest.new }
subject(:request) { get api('/geo/status'), nil, geo_base_request.headers }
it 'responds with 401 with invalid auth header' do it 'responds with 401 with invalid auth header' do
get api('/geo/status'), nil, Authorization: 'Test' get api('/geo/status'), nil, Authorization: 'Test'
...@@ -196,7 +227,7 @@ describe API::Geo do ...@@ -196,7 +227,7 @@ describe API::Geo do
it 'responds with 401 when the db_key_base is wrong' do it 'responds with 401 when the db_key_base is wrong' do
allow_any_instance_of(Gitlab::Geo::JwtRequestDecoder).to receive(:decode).and_raise(Gitlab::Geo::InvalidDecryptionKeyError) allow_any_instance_of(Gitlab::Geo::JwtRequestDecoder).to receive(:decode).and_raise(Gitlab::Geo::InvalidDecryptionKeyError)
get api('/geo/status'), nil, request.headers request
expect(response).to have_gitlab_http_status(401) expect(response).to have_gitlab_http_status(401)
end end
...@@ -204,31 +235,34 @@ describe API::Geo do ...@@ -204,31 +235,34 @@ describe API::Geo do
context 'when requesting secondary node with valid auth header' do context 'when requesting secondary node with valid auth header' do
before do before do
stub_current_geo_node(secondary_node) stub_current_geo_node(secondary_node)
allow(request).to receive(:requesting_node) { primary_node } allow(geo_base_request).to receive(:requesting_node) { primary_node }
allow(::GeoNodeStatus).to receive(:fast_current_node_status).and_return(::GeoNodeStatus.current_node_status)
end end
it 'responds with 200' do it 'responds with 200' do
allow(::GeoNodeStatus).to receive(:fast_current_node_status).and_return(::GeoNodeStatus.current_node_status) request
get api('/geo/status'), nil, request.headers
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(200)
expect(response).to match_response_schema('public_api/v4/geo_node_status', dir: 'ee') expect(response).to match_response_schema('public_api/v4/geo_node_status', dir: 'ee')
end end
it_behaves_like 'with terms enforced'
end end
context 'when requesting primary node with valid auth header' do context 'when requesting primary node with valid auth header' do
before do before do
stub_current_geo_node(primary_node) stub_current_geo_node(primary_node)
allow(request).to receive(:requesting_node) { secondary_node } allow(geo_base_request).to receive(:requesting_node) { secondary_node }
end end
it 'responds with 200' do it 'responds with 200' do
get api('/geo/status'), nil, request.headers request
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(200)
expect(response).to match_response_schema('public_api/v4/geo_node_status', dir: 'ee') expect(response).to match_response_schema('public_api/v4/geo_node_status', dir: 'ee')
end end
it_behaves_like 'with terms enforced'
end end
end end
end end
require 'spec_helper' require 'spec_helper'
describe "Git HTTP requests (Geo)" do describe "Git HTTP requests (Geo)" do
include TermsHelper
include ::EE::GeoHelpers include ::EE::GeoHelpers
include GitHttpHelpers include GitHttpHelpers
include WorkhorseHelpers include WorkhorseHelpers
...@@ -75,6 +76,14 @@ describe "Git HTTP requests (Geo)" do ...@@ -75,6 +76,14 @@ describe "Git HTTP requests (Geo)" do
end end
it_behaves_like 'Geo sync request' it_behaves_like 'Geo sync request'
context 'when terms are enforced' do
before do
enforce_terms
end
it_behaves_like 'Geo sync request'
end
end end
describe 'POST upload_pack' do describe 'POST upload_pack' do
...@@ -83,6 +92,14 @@ describe "Git HTTP requests (Geo)" do ...@@ -83,6 +92,14 @@ describe "Git HTTP requests (Geo)" do
end end
it_behaves_like 'Geo sync request' it_behaves_like 'Geo sync request'
context 'when terms are enforced' do
before do
enforce_terms
end
it_behaves_like 'Geo sync request'
end
end end
def valid_geo_env def valid_geo_env
......
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