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
975fff2c
Commit
975fff2c
authored
Aug 30, 2021
by
Thong Kuah
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix nested calls of allowlist method
parent
1a614fb8
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
4 deletions
+21
-4
spec/support/database/prevent_cross_joins.rb
spec/support/database/prevent_cross_joins.rb
+7
-4
spec/support_specs/database/prevent_cross_joins_spec.rb
spec/support_specs/database/prevent_cross_joins_spec.rb
+14
-0
No files found.
spec/support/database/prevent_cross_joins.rb
View file @
975fff2c
...
...
@@ -21,8 +21,10 @@ module Database
module
PreventCrossJoins
CrossJoinAcrossUnsupportedTablesError
=
Class
.
new
(
StandardError
)
ALLOW_THREAD_KEY
=
:allow_cross_joins_across_databases
def
self
.
validate_cross_joins!
(
sql
)
return
if
Thread
.
current
[
:allow_cross_joins_across_databases
]
return
if
Thread
.
current
[
ALLOW_THREAD_KEY
]
# Allow spec/support/database_cleaner.rb queries to disable/enable triggers for many tables
# See https://gitlab.com/gitlab-org/gitlab/-/issues/339396
...
...
@@ -55,7 +57,7 @@ module Database
::
Database
::
PreventCrossJoins
.
validate_cross_joins!
(
event
.
payload
[
:sql
])
end
Thread
.
current
[
:allow_cross_joins_across_databases
]
=
false
Thread
.
current
[
ALLOW_THREAD_KEY
]
=
false
yield
ensure
...
...
@@ -65,11 +67,12 @@ module Database
module
GitlabDatabaseMixin
def
allow_cross_joins_across_databases
(
url
:)
Thread
.
current
[
:allow_cross_joins_across_databases
]
=
true
old_value
=
Thread
.
current
[
ALLOW_THREAD_KEY
]
Thread
.
current
[
ALLOW_THREAD_KEY
]
=
true
yield
ensure
Thread
.
current
[
:allow_cross_joins_across_databases
]
=
fals
e
Thread
.
current
[
ALLOW_THREAD_KEY
]
=
old_valu
e
end
end
end
...
...
spec/support_specs/database/prevent_cross_joins_spec.rb
View file @
975fff2c
...
...
@@ -27,6 +27,12 @@ RSpec.describe Database::PreventCrossJoins do
expect
{
main_and_ci_query_allowlisted
}.
not_to
raise_error
end
end
context
'when allow_cross_joins_across_databases is used'
do
it
'does not raise exception'
do
expect
{
main_and_ci_query_allowlist_nested
}.
not_to
raise_error
end
end
end
end
...
...
@@ -38,6 +44,14 @@ RSpec.describe Database::PreventCrossJoins do
end
end
def
main_and_ci_query_allowlist_nested
Gitlab
::
Database
.
allow_cross_joins_across_databases
(
url:
'http://issue-url'
)
do
main_and_ci_query_allowlisted
main_and_ci_query
end
end
def
main_only_query
Issue
.
joins
(
:project
).
last
end
...
...
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