Commit c099074f authored by Jason Hollingsworth's avatar Jason Hollingsworth

Fix 404 on project page for unauthenticated user

Eliminate a 404 error when user is not logged in and attempts to visit
a project page.

The 404 page will still show up when user is logged in and the project
doesn’t exist or the user doesn’t have access.
parent 23d180f5
...@@ -8,6 +8,7 @@ v 6.4.0 ...@@ -8,6 +8,7 @@ v 6.4.0
- Internal projects (Jason Hollingsworth) - Internal projects (Jason Hollingsworth)
- Allow removal of avatar (Drew Blessing) - Allow removal of avatar (Drew Blessing)
- Project web hooks now support issues and merge request events - Project web hooks now support issues and merge request events
- Visiting project page while not logged in will redirect to sign-in instead of 404 (Jason Hollingsworth)
v 6.3.0 v 6.3.0
- API for adding gitlab-ci service - API for adding gitlab-ci service
......
...@@ -81,6 +81,9 @@ class ApplicationController < ActionController::Base ...@@ -81,6 +81,9 @@ class ApplicationController < ActionController::Base
if @project and can?(current_user, :read_project, @project) if @project and can?(current_user, :read_project, @project)
@project @project
elsif current_user.nil?
@project = nil
authenticate_user!
else else
@project = nil @project = nil
render_404 and return render_404 and return
......
Feature: Project Redirects
Background:
Given public project "Community"
And private project "Enterprise"
Scenario: I visit public project page
When I visit project "Community" page
Then I should see project "Community" home page
Scenario: I visit private project page
When I visit project "Enterprise" page
Then I should be redirected to sign in page
Scenario: I visit a non-existent project page
When I visit project "CommunityDoesNotExist" page
Then I should be redirected to sign in page
Scenario: I visit a non-existent project page as user
Given I sign in as a user
When I visit project "CommunityDoesNotExist" page
Then page status code should be 404
Scenario: I visit unauthorized project page as user
Given I sign in as a user
When I visit project "Enterprise" page
Then page status code should be 404
...@@ -16,11 +16,11 @@ Feature: Public Projects Feature ...@@ -16,11 +16,11 @@ Feature: Public Projects Feature
Scenario: I visit internal project page Scenario: I visit internal project page
When I visit project "Internal" page When I visit project "Internal" page
Then page status code should be 404 Then I should be redirected to sign in page
Scenario: I visit private project page Scenario: I visit private project page
When I visit project "Enterprise" page When I visit project "Enterprise" page
Then page status code should be 404 Then I should be redirected to sign in page
Scenario: I visit an empty public project page Scenario: I visit an empty public project page
Given public empty project "Empty Public Project" Given public empty project "Empty Public Project"
......
...@@ -88,10 +88,6 @@ class Profile < Spinach::FeatureSteps ...@@ -88,10 +88,6 @@ class Profile < Spinach::FeatureSteps
page.should have_content "Password doesn't match confirmation" page.should have_content "Password doesn't match confirmation"
end end
step 'I should be redirected to sign in page' do
current_path.should == new_user_session_path
end
step 'I reset my token' do step 'I reset my token' do
within '.update-token' do within '.update-token' do
@old_token = @user.private_token @old_token = @user.private_token
......
class Spinach::Features::ProjectRedirects < Spinach::FeatureSteps
include SharedAuthentication
include SharedPaths
include SharedProject
step 'public project "Community"' do
create :project_with_code, name: 'Community', visibility_level: Gitlab::VisibilityLevel::PUBLIC
end
step 'private project "Enterprise"' do
create :project, name: 'Enterprise'
end
step 'I visit project "Community" page' do
project = Project.find_by_name('Community')
visit project_path(project)
end
step 'I should see project "Community" home page' do
within '.project-home-title' do
page.should have_content 'Community'
end
end
step 'I visit project "Enterprise" page' do
project = Project.find_by_name('Enterprise')
visit project_path(project)
end
step 'I visit project "CommunityDoesNotExist" page' do
project = Project.find_by_name('Community')
visit project_path(project) + 'DoesNotExist'
end
end
...@@ -12,6 +12,10 @@ module SharedAuthentication ...@@ -12,6 +12,10 @@ module SharedAuthentication
login_as :admin login_as :admin
end end
step 'I should be redirected to sign in page' do
current_path.should == new_user_session_path
end
def current_user def current_user
@user || User.first @user || User.first
end end
......
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