Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-03-13 03:09:34 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-03-13 03:09:34 +0300
commit3cd08f4bf96cda3e9d3abf233095107832b17c20 (patch)
treedc09a618783a79d70f2a404374d4b850ccf9cc84 /spec/services
parentdd4bee69b7d55620f7dc9db8c36b478bd4959755 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/services')
-rw-r--r--spec/services/pod_logs/elasticsearch_service_spec.rb54
-rw-r--r--spec/services/projects/fork_service_spec.rb7
-rw-r--r--spec/services/projects/update_repository_storage_service_spec.rb24
-rw-r--r--spec/services/x509_certificate_revoke_service_spec.rb43
4 files changed, 111 insertions, 17 deletions
diff --git a/spec/services/pod_logs/elasticsearch_service_spec.rb b/spec/services/pod_logs/elasticsearch_service_spec.rb
index 0f0c36da56a..984a303e9e3 100644
--- a/spec/services/pod_logs/elasticsearch_service_spec.rb
+++ b/spec/services/pod_logs/elasticsearch_service_spec.rb
@@ -11,6 +11,7 @@ describe ::PodLogs::ElasticsearchService do
let(:search) { 'foo -bar' }
let(:start_time) { '2019-01-02T12:13:14+02:00' }
let(:end_time) { '2019-01-03T12:13:14+02:00' }
+ let(:cursor) { '9999934,1572449784442' }
let(:params) { {} }
let(:expected_logs) do
[
@@ -116,6 +117,36 @@ describe ::PodLogs::ElasticsearchService do
end
end
+ describe '#check_cursor' do
+ context 'with cursor provided and valid' do
+ let(:params) do
+ {
+ 'cursor' => cursor
+ }
+ end
+
+ it 'returns success with cursor' do
+ result = subject.send(:check_cursor, {})
+
+ expect(result[:status]).to eq(:success)
+ expect(result[:cursor]).to eq(cursor)
+ end
+ end
+
+ context 'with cursor not provided' do
+ let(:params) do
+ {}
+ end
+
+ it 'returns success with nothing else' do
+ result = subject.send(:check_cursor, {})
+
+ expect(result.keys.length).to eq(1)
+ expect(result[:status]).to eq(:success)
+ end
+ end
+ end
+
describe '#pod_logs' do
let(:result_arg) do
{
@@ -123,9 +154,11 @@ describe ::PodLogs::ElasticsearchService do
container_name: container_name,
search: search,
start: start_time,
- end: end_time
+ end: end_time,
+ cursor: cursor
}
end
+ let(:expected_cursor) { '9999934,1572449784442' }
before do
create(:clusters_applications_elastic_stack, :installed, cluster: cluster)
@@ -137,13 +170,14 @@ describe ::PodLogs::ElasticsearchService do
.and_return(Elasticsearch::Transport::Client.new)
allow_any_instance_of(::Gitlab::Elasticsearch::Logs)
.to receive(:pod_logs)
- .with(namespace, pod_name, container_name, search, start_time, end_time)
- .and_return(expected_logs)
+ .with(namespace, pod_name, container_name: container_name, search: search, start_time: start_time, end_time: end_time, cursor: cursor)
+ .and_return({ logs: expected_logs, cursor: expected_cursor })
result = subject.send(:pod_logs, result_arg)
expect(result[:status]).to eq(:success)
expect(result[:logs]).to eq(expected_logs)
+ expect(result[:cursor]).to eq(expected_cursor)
end
it 'returns an error when ES is unreachable' do
@@ -170,5 +204,19 @@ describe ::PodLogs::ElasticsearchService do
expect(result[:status]).to eq(:error)
expect(result[:message]).to eq('Elasticsearch returned status code: ServiceUnavailable')
end
+
+ it 'handles cursor errors from elasticsearch' do
+ allow_any_instance_of(::Clusters::Applications::ElasticStack)
+ .to receive(:elasticsearch_client)
+ .and_return(Elasticsearch::Transport::Client.new)
+ allow_any_instance_of(::Gitlab::Elasticsearch::Logs)
+ .to receive(:pod_logs)
+ .and_raise(::Gitlab::Elasticsearch::Logs::InvalidCursor.new)
+
+ result = subject.send(:pod_logs, result_arg)
+
+ expect(result[:status]).to eq(:error)
+ expect(result[:message]).to eq('Invalid cursor value provided')
+ end
end
end
diff --git a/spec/services/projects/fork_service_spec.rb b/spec/services/projects/fork_service_spec.rb
index 4e5f10b3947..731febe75b3 100644
--- a/spec/services/projects/fork_service_spec.rb
+++ b/spec/services/projects/fork_service_spec.rb
@@ -311,9 +311,10 @@ describe Projects::ForkService do
fork_before_move = fork_project(project)
# Stub everything required to move a project to a Gitaly shard that does not exist
- stub_storage_settings('test_second_storage' => { 'path' => 'tmp/tests/second_storage' })
- allow_any_instance_of(Gitlab::Git::Repository).to receive(:fetch_repository_as_mirror).and_return(true)
- allow_any_instance_of(Gitlab::Git::Repository).to receive(:checksum).and_return(::Gitlab::Git::BLANK_SHA)
+ stub_storage_settings('test_second_storage' => { 'path' => TestEnv::SECOND_STORAGE_PATH })
+ allow_any_instance_of(Gitlab::Git::Repository).to receive(:replicate)
+ allow_any_instance_of(Gitlab::Git::Repository).to receive(:checksum)
+ .and_return(::Gitlab::Git::BLANK_SHA)
Projects::UpdateRepositoryStorageService.new(project).execute('test_second_storage')
fork_after_move = fork_project(project)
diff --git a/spec/services/projects/update_repository_storage_service_spec.rb b/spec/services/projects/update_repository_storage_service_spec.rb
index 2e9a4626abb..106a639ba28 100644
--- a/spec/services/projects/update_repository_storage_service_spec.rb
+++ b/spec/services/projects/update_repository_storage_service_spec.rb
@@ -32,8 +32,8 @@ describe Projects::UpdateRepositoryStorageService do
project.repository.path_to_repo
end
- expect(project_repository_double).to receive(:fetch_repository_as_mirror)
- .with(project.repository.raw).and_return(true)
+ expect(project_repository_double).to receive(:replicate)
+ .with(project.repository.raw)
expect(project_repository_double).to receive(:checksum)
.and_return(checksum)
@@ -49,16 +49,18 @@ describe Projects::UpdateRepositoryStorageService do
context 'when the project is already on the target storage' do
it 'bails out and does nothing' do
- expect do
- subject.execute(project.repository_storage)
- end.to raise_error(described_class::RepositoryAlreadyMoved)
+ result = subject.execute(project.repository_storage)
+
+ expect(result[:status]).to eq(:error)
+ expect(result[:message]).to match(/repository and source have the same storage/)
end
end
context 'when the move fails' do
it 'unmarks the repository as read-only without updating the repository storage' do
- expect(project_repository_double).to receive(:fetch_repository_as_mirror)
- .with(project.repository.raw).and_return(false)
+ expect(project_repository_double).to receive(:replicate)
+ .with(project.repository.raw)
+ .and_raise(Gitlab::Git::CommandError)
expect(GitlabShellWorker).not_to receive(:perform_async)
result = subject.execute('test_second_storage')
@@ -71,8 +73,8 @@ describe Projects::UpdateRepositoryStorageService do
context 'when the checksum does not match' do
it 'unmarks the repository as read-only without updating the repository storage' do
- expect(project_repository_double).to receive(:fetch_repository_as_mirror)
- .with(project.repository.raw).and_return(true)
+ expect(project_repository_double).to receive(:replicate)
+ .with(project.repository.raw)
expect(project_repository_double).to receive(:checksum)
.and_return('not matching checksum')
expect(GitlabShellWorker).not_to receive(:perform_async)
@@ -89,8 +91,8 @@ describe Projects::UpdateRepositoryStorageService do
let!(:pool) { create(:pool_repository, :ready, source_project: project) }
it 'leaves the pool' do
- expect(project_repository_double).to receive(:fetch_repository_as_mirror)
- .with(project.repository.raw).and_return(true)
+ expect(project_repository_double).to receive(:replicate)
+ .with(project.repository.raw)
expect(project_repository_double).to receive(:checksum)
.and_return(checksum)
diff --git a/spec/services/x509_certificate_revoke_service_spec.rb b/spec/services/x509_certificate_revoke_service_spec.rb
new file mode 100644
index 00000000000..ef76f616c93
--- /dev/null
+++ b/spec/services/x509_certificate_revoke_service_spec.rb
@@ -0,0 +1,43 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe X509CertificateRevokeService do
+ describe '#execute' do
+ let(:service) { described_class.new }
+ let!(:x509_signature_1) { create(:x509_commit_signature, x509_certificate: x509_certificate, verification_status: :verified ) }
+ let!(:x509_signature_2) { create(:x509_commit_signature, x509_certificate: x509_certificate, verification_status: :verified ) }
+
+ context 'for revoked certificates' do
+ let(:x509_certificate) { create(:x509_certificate, certificate_status: :revoked ) }
+
+ it 'update all commit signatures' do
+ expect do
+ service.execute(x509_certificate)
+
+ x509_signature_1.reload
+ x509_signature_2.reload
+ end
+ .to change(x509_signature_1, :verification_status).from('verified').to('unverified')
+ .and change(x509_signature_2, :verification_status).from('verified').to('unverified')
+ end
+ end
+
+ context 'for good certificates' do
+ RSpec::Matchers.define_negated_matcher :not_change, :change
+
+ let(:x509_certificate) { create(:x509_certificate) }
+
+ it 'do not update any commit signature' do
+ expect do
+ service.execute(x509_certificate)
+
+ x509_signature_1.reload
+ x509_signature_2.reload
+ end
+ .to not_change(x509_signature_1, :verification_status)
+ .and not_change(x509_signature_2, :verification_status)
+ end
+ end
+ end
+end