diff options
Diffstat (limited to 'spec/lib/gitlab/database/query_analyzers/gitlab_schemas_validate_connection_spec.rb')
-rw-r--r-- | spec/lib/gitlab/database/query_analyzers/gitlab_schemas_validate_connection_spec.rb | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/spec/lib/gitlab/database/query_analyzers/gitlab_schemas_validate_connection_spec.rb b/spec/lib/gitlab/database/query_analyzers/gitlab_schemas_validate_connection_spec.rb index 5e8afc0102e..ddf5793049d 100644 --- a/spec/lib/gitlab/database/query_analyzers/gitlab_schemas_validate_connection_spec.rb +++ b/spec/lib/gitlab/database/query_analyzers/gitlab_schemas_validate_connection_spec.rb @@ -5,6 +5,13 @@ require 'spec_helper' RSpec.describe Gitlab::Database::QueryAnalyzers::GitlabSchemasValidateConnection, query_analyzers: false do let(:analyzer) { described_class } + # We keep only the GitlabSchemasValidateConnection analyzer running + around do |example| + Gitlab::Database::QueryAnalyzers::GitlabSchemasValidateConnection.with_suppressed(false) do + example.run + end + end + context 'properly observes all queries', :request_store do using RSpec::Parameterized::TableSyntax @@ -61,6 +68,24 @@ RSpec.describe Gitlab::Database::QueryAnalyzers::GitlabSchemasValidateConnection end end + context "when analyzer is enabled for tests", :query_analyzers do + before do + skip_if_multiple_databases_not_setup + end + + it "throws an error when trying to access a table that belongs to the gitlab_main schema from the ci database" do + expect do + Ci::ApplicationRecord.connection.execute("select * from users limit 1") + end.to raise_error(Gitlab::Database::QueryAnalyzers::GitlabSchemasValidateConnection::CrossSchemaAccessError) + end + + it "throws an error when trying to access a table that belongs to the gitlab_ci schema from the main database" do + expect do + ApplicationRecord.connection.execute("select * from ci_builds limit 1") + end.to raise_error(Gitlab::Database::QueryAnalyzers::GitlabSchemasValidateConnection::CrossSchemaAccessError) + end + end + def process_sql(model, sql) Gitlab::Database::QueryAnalyzer.instance.within([analyzer]) do # Skip load balancer and retrieve connection assigned to model |