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
c4e42587
Commit
c4e42587
authored
Apr 11, 2018
by
Andreas Brandl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Validate project path prior to hitting the database.
Closes #45247.
parent
ab98308d
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
49 additions
and
2 deletions
+49
-2
changelogs/unreleased/ab-45247-project-lookups-validation.yml
...gelogs/unreleased/ab-45247-project-lookups-validation.yml
+5
-0
lib/api/helpers.rb
lib/api/helpers.rb
+2
-2
spec/lib/api/helpers_spec.rb
spec/lib/api/helpers_spec.rb
+42
-0
No files found.
changelogs/unreleased/ab-45247-project-lookups-validation.yml
0 → 100644
View file @
c4e42587
---
title
:
Validate project path prior to hitting the database.
merge_request
:
18322
author
:
type
:
performance
lib/api/helpers.rb
View file @
c4e42587
...
...
@@ -103,9 +103,9 @@ module API
end
def
find_project
(
id
)
if
id
=~
/^\d+$/
if
id
.
is_a?
(
Integer
)
||
id
=~
/^\d+$/
Project
.
find_by
(
id:
id
)
els
e
els
if
id
.
include?
(
"/"
)
Project
.
find_by_full_path
(
id
)
end
end
...
...
spec/lib/api/helpers_spec.rb
View file @
c4e42587
...
...
@@ -3,6 +3,48 @@ require 'spec_helper'
describe
API
::
Helpers
do
subject
{
Class
.
new
.
include
(
described_class
).
new
}
describe
'#find_project'
do
let
(
:project
)
{
create
(
:project
)
}
shared_examples
'project finder'
do
context
'when project exists'
do
it
'returns requested project'
do
expect
(
subject
.
find_project
(
existing_id
)).
to
eq
(
project
)
end
it
'returns nil'
do
expect
(
subject
.
find_project
(
non_existing_id
)).
to
be_nil
end
end
end
context
'when ID is used as an argument'
do
let
(
:existing_id
)
{
project
.
id
}
let
(
:non_existing_id
)
{
(
Project
.
maximum
(
:id
)
||
0
)
+
1
}
it_behaves_like
'project finder'
end
context
'when PATH is used as an argument'
do
let
(
:existing_id
)
{
project
.
full_path
}
let
(
:non_existing_id
)
{
'something/else'
}
it_behaves_like
'project finder'
context
'with an invalid PATH'
do
let
(
:non_existing_id
)
{
'undefined'
}
# path without slash
it_behaves_like
'project finder'
it
'does not hit the database'
do
expect
(
Project
).
not_to
receive
(
:find_by_full_path
)
subject
.
find_project
(
non_existing_id
)
end
end
end
end
describe
'#find_namespace'
do
let
(
:namespace
)
{
create
(
:namespace
)
}
...
...
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