Commit 0f813189 authored by Oswaldo Ferreira's avatar Oswaldo Ferreira

Allow all but "/" chars for groups and projects paths on Jira dev panel integration

parent d555a8a4
---
title: Allow all but "/" chars for groups and projects paths on Jira dev panel integration
merge_request:
author:
type: fixed
......@@ -7,6 +7,9 @@ module API
module V3
class Github < Grape::API
JIRA_DEV_PANEL_FEATURE = :jira_dev_panel_integration.freeze
NO_SLASH_URL_PART_REGEX = %r{[^/]+}
NAMESPACE_ENDPOINT_REQUIREMENTS = { namespace: NO_SLASH_URL_PART_REGEX }.freeze
PROJECT_ENDPOINT_REQUIREMENTS = NAMESPACE_ENDPOINT_REQUIREMENTS.merge(project: NO_SLASH_URL_PART_REGEX).freeze
include PaginationParams
......@@ -60,7 +63,7 @@ module API
end
resource :orgs do
get ':namespace/repos' do
get ':namespace/repos', requirements: NAMESPACE_ENDPOINT_REQUIREMENTS do
present []
end
end
......@@ -75,7 +78,7 @@ module API
params do
use :pagination
end
get ':namespace/repos' do
get ':namespace/repos', requirements: NAMESPACE_ENDPOINT_REQUIREMENTS do
projects = current_user.authorized_projects.select { |project| licensed_project?(project) }
projects = ::Kaminari.paginate_array(projects)
present paginate(projects), with: ::API::Github::Entities::Repository
......@@ -120,7 +123,7 @@ module API
use :project_full_path
use :pagination
end
get ':namespace/:project/branches' do
get ':namespace/:project/branches', requirements: PROJECT_ENDPOINT_REQUIREMENTS do
namespace = params[:namespace]
project = params[:project]
user_project = find_project_with_access("#{namespace}/#{project}")
......@@ -133,7 +136,7 @@ module API
params do
use :project_full_path
end
get ':namespace/:project/commits/:sha' do
get ':namespace/:project/commits/:sha', requirements: PROJECT_ENDPOINT_REQUIREMENTS do
namespace = params[:namespace]
project = params[:project]
user_project = find_project_with_access("#{namespace}/#{project}")
......
......@@ -18,6 +18,14 @@ describe API::V3::Github do
expect(response).to have_gitlab_http_status(200)
expect(json_response).to eq([])
end
it 'returns 200 when namespace path include a dot' do
group = create(:group, path: 'foo.bar')
get v3_api("/orgs/#{group.path}/repos", user)
expect(response).to have_gitlab_http_status(200)
end
end
describe 'GET /user/repos' do
......@@ -116,11 +124,11 @@ describe API::V3::Github do
before do
stub_licensed_features(jira_dev_panel_integration: true)
group.add_master(user)
get v3_api('/users/foo/repos', user)
end
it 'returns an array of projects with github format' do
get v3_api('/users/foo/repos', user)
expect(response).to have_gitlab_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an(Array)
......@@ -129,7 +137,17 @@ describe API::V3::Github do
expect(response).to match_response_schema('entities/github/repositories', dir: 'ee')
end
it 'returns 200 when namespace path include a dot' do
group = create(:group, path: 'foo.bar')
get v3_api("/users/#{group.path}/repos", user)
expect(response).to have_gitlab_http_status(200)
end
it 'returns valid project path as name' do
get v3_api('/users/foo/repos', user)
project_names = json_response.map { |r| r['name'] }
expect(project_names).to include(project.path, group_project.path)
......@@ -165,9 +183,11 @@ describe API::V3::Github do
describe 'GET /repos/:namespace/:project/branches' do
context 'authenticated' do
it 'returns an array of project branches with github format' do
before do
stub_licensed_features(jira_dev_panel_integration: true)
end
it 'returns an array of project branches with github format' do
get v3_api("/repos/#{project.namespace.path}/#{project.path}/branches", user)
expect(response).to have_gitlab_http_status(200)
......@@ -176,6 +196,24 @@ describe API::V3::Github do
expect(response).to match_response_schema('entities/github/branches', dir: 'ee')
end
it 'returns 200 when project path include a dot' do
project.update!(path: 'foo.bar')
get v3_api("/repos/#{project.namespace.path}/#{project.path}/branches", user)
expect(response).to have_gitlab_http_status(200)
end
it 'returns 200 when namespace path include a dot' do
group = create(:group, path: 'foo.bar')
project = create(:project, :repository, group: group)
project.add_reporter(user)
get v3_api("/repos/#{group.path}/#{project.path}/branches", user)
expect(response).to have_gitlab_http_status(200)
end
end
context 'unauthenticated' do
......@@ -206,14 +244,34 @@ describe API::V3::Github do
let(:commit_id) { commit.id }
context 'authenticated' do
it 'returns commit with github format' do
before do
stub_licensed_features(jira_dev_panel_integration: true)
end
it 'returns commit with github format' do
get v3_api("/repos/#{project.namespace.path}/#{project.path}/commits/#{commit_id}", user)
expect(response).to have_gitlab_http_status(200)
expect(response).to match_response_schema('entities/github/commit', dir: 'ee')
end
it 'returns 200 when project path include a dot' do
project.update!(path: 'foo.bar')
get v3_api("/repos/#{project.namespace.path}/#{project.path}/commits/#{commit_id}", user)
expect(response).to have_gitlab_http_status(200)
end
it 'returns 200 when namespace path include a dot' do
group = create(:group, path: 'foo.bar')
project = create(:project, :repository, group: group)
project.add_reporter(user)
get v3_api("/repos/#{group.path}/#{project.path}/commits/#{commit_id}", user)
expect(response).to have_gitlab_http_status(200)
end
end
context 'unauthenticated' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment