Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
56b66f21
Commit
56b66f21
authored
Aug 31, 2021
by
GitLab Bot
Browse files
Options
Browse Files
Download
Plain Diff
Automatic merge of gitlab-org/gitlab master
parents
4680796d
dfa10174
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
13 deletions
+16
-13
spec/support/database/prevent_cross_joins.rb
spec/support/database/prevent_cross_joins.rb
+15
-4
spec/support_specs/database/prevent_cross_joins_spec.rb
spec/support_specs/database/prevent_cross_joins_spec.rb
+1
-9
No files found.
spec/support/database/prevent_cross_joins.rb
View file @
56b66f21
...
@@ -30,7 +30,15 @@ module Database
...
@@ -30,7 +30,15 @@ module Database
# PgQuery might fail in some cases due to limited nesting:
# PgQuery might fail in some cases due to limited nesting:
# https://github.com/pganalyze/pg_query/issues/209
# https://github.com/pganalyze/pg_query/issues/209
#
# Also, we disable GC while parsing because of https://github.com/pganalyze/pg_query/issues/226
begin
GC
.
disable
tables
=
PgQuery
.
parse
(
sql
).
tables
tables
=
PgQuery
.
parse
(
sql
).
tables
ensure
GC
.
enable
end
schemas
=
Database
::
GitlabSchema
.
table_schemas
(
tables
)
schemas
=
Database
::
GitlabSchema
.
table_schemas
(
tables
)
if
schemas
.
include?
(
:gitlab_ci
)
&&
schemas
.
include?
(
:gitlab_main
)
if
schemas
.
include?
(
:gitlab_ci
)
&&
schemas
.
include?
(
:gitlab_main
)
...
@@ -72,10 +80,13 @@ ALLOW_LIST = Set.new(YAML.load_file(Rails.root.join('.cross-join-allowlist.yml')
...
@@ -72,10 +80,13 @@ ALLOW_LIST = Set.new(YAML.load_file(Rails.root.join('.cross-join-allowlist.yml')
RSpec
.
configure
do
|
config
|
RSpec
.
configure
do
|
config
|
config
.
include
(
::
Database
::
PreventCrossJoins
::
SpecHelpers
)
config
.
include
(
::
Database
::
PreventCrossJoins
::
SpecHelpers
)
# TODO: remove `:prevent_cross_joins` to enable the check by default
config
.
around
do
|
example
|
config
.
around
(
:each
,
:prevent_cross_joins
)
do
|
example
|
Thread
.
current
[
:has_cross_join_exception
]
=
false
Thread
.
current
[
:has_cross_join_exception
]
=
false
if
ALLOW_LIST
.
include?
(
example
.
file_path
)
example
.
run
else
with_cross_joins_prevented
{
example
.
run
}
with_cross_joins_prevented
{
example
.
run
}
end
end
end
end
end
spec/support_specs/database/prevent_cross_joins_spec.rb
View file @
56b66f21
...
@@ -3,7 +3,7 @@
...
@@ -3,7 +3,7 @@
require
'spec_helper'
require
'spec_helper'
RSpec
.
describe
Database
::
PreventCrossJoins
do
RSpec
.
describe
Database
::
PreventCrossJoins
do
context
'when running in
:prevent_cross_joins scope'
,
:prevent_cross_joins
do
context
'when running in
a default scope'
do
context
'when only non-CI tables are used'
do
context
'when only non-CI tables are used'
do
it
'does not raise exception'
do
it
'does not raise exception'
do
expect
{
main_only_query
}.
not_to
raise_error
expect
{
main_only_query
}.
not_to
raise_error
...
@@ -32,14 +32,6 @@ RSpec.describe Database::PreventCrossJoins do
...
@@ -32,14 +32,6 @@ RSpec.describe Database::PreventCrossJoins do
end
end
end
end
context
'when running in a default scope'
do
context
'when CI and non-CI tables are used'
do
it
'does not raise exception'
do
expect
{
main_and_ci_query
}.
not_to
raise_error
end
end
end
private
private
def
main_only_query
def
main_only_query
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment