debian-mirror-gitlab/spec/requests/api/pages/public_access_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

91 lines
3.8 KiB
Ruby
Raw Permalink Normal View History

2019-12-26 22:10:19 +05:30
# frozen_string_literal: true
2018-12-05 23:21:45 +05:30
require 'spec_helper'
2023-03-04 22:38:38 +05:30
RSpec.describe "Public Project Pages Access", feature_category: :pages do
2018-12-05 23:21:45 +05:30
using RSpec::Parameterized::TableSyntax
include AccessMatchers
2020-03-13 15:44:24 +05:30
let_it_be(:group) { create(:group) }
let_it_be(:project, reload: true) { create(:project, :public, pages_access_level: ProjectFeature::ENABLED, namespace: group) }
let_it_be(:admin) { create(:admin) }
let_it_be(:owner) { create(:user) }
let_it_be(:master) { create(:user) }
let_it_be(:developer) { create(:user) }
let_it_be(:reporter) { create(:user) }
let_it_be(:guest) { create(:user) }
let_it_be(:user) { create(:user) }
2018-12-05 23:21:45 +05:30
before do
allow(Gitlab.config.pages).to receive(:access_control).and_return(true)
group.add_owner(owner)
2020-04-22 19:07:51 +05:30
project.add_maintainer(master)
2018-12-05 23:21:45 +05:30
project.add_developer(developer)
project.add_reporter(reporter)
project.add_guest(guest)
end
describe "Project should be public" do
describe '#public?' do
subject { project.public? }
2019-12-21 20:55:43 +05:30
2018-12-05 23:21:45 +05:30
it { is_expected.to be_truthy }
end
end
describe "GET /projects/:id/pages_access" do
context 'access depends on the level' do
2023-05-27 22:25:52 +05:30
where(:pages_access_level, :with_user, :admin_mode, :expected_result) do
ProjectFeature::DISABLED | "admin" | false | 403
ProjectFeature::DISABLED | "owner" | false | 403
ProjectFeature::DISABLED | "master" | false | 403
ProjectFeature::DISABLED | "developer" | false | 403
ProjectFeature::DISABLED | "reporter" | false | 403
ProjectFeature::DISABLED | "guest" | false | 403
ProjectFeature::DISABLED | "user" | false | 403
ProjectFeature::DISABLED | nil | false | 403
ProjectFeature::PUBLIC | "admin" | false | 200
ProjectFeature::PUBLIC | "owner" | false | 200
ProjectFeature::PUBLIC | "master" | false | 200
ProjectFeature::PUBLIC | "developer" | false | 200
ProjectFeature::PUBLIC | "reporter" | false | 200
ProjectFeature::PUBLIC | "guest" | false | 200
ProjectFeature::PUBLIC | "user" | false | 200
ProjectFeature::PUBLIC | nil | false | 200
ProjectFeature::ENABLED | "admin" | false | 200
ProjectFeature::ENABLED | "owner" | false | 200
ProjectFeature::ENABLED | "master" | false | 200
ProjectFeature::ENABLED | "developer" | false | 200
ProjectFeature::ENABLED | "reporter" | false | 200
ProjectFeature::ENABLED | "guest" | false | 200
ProjectFeature::ENABLED | "user" | false | 200
ProjectFeature::ENABLED | nil | false | 200
ProjectFeature::PRIVATE | "admin" | true | 200
ProjectFeature::PRIVATE | "owner" | false | 200
ProjectFeature::PRIVATE | "master" | false | 200
ProjectFeature::PRIVATE | "developer" | false | 200
ProjectFeature::PRIVATE | "reporter" | false | 200
ProjectFeature::PRIVATE | "guest" | false | 200
ProjectFeature::PRIVATE | "user" | false | 403
ProjectFeature::PRIVATE | nil | false | 403
2018-12-05 23:21:45 +05:30
end
with_them do
before do
2020-11-24 15:15:51 +05:30
project.project_feature.update!(pages_access_level: pages_access_level)
2018-12-05 23:21:45 +05:30
end
it "correct return value" do
if !with_user.nil?
user = public_send(with_user)
2023-05-27 22:25:52 +05:30
get api("/projects/#{project.id}/pages_access", user, admin_mode: admin_mode)
2018-12-05 23:21:45 +05:30
else
get api("/projects/#{project.id}/pages_access")
end
expect(response).to have_gitlab_http_status(expected_result)
end
end
end
end
end