Commit 43863343 authored by Sanad Liaquat's avatar Sanad Liaquat

Merge branch 'cancel-pipeline-when-block-user' into 'master'

E2E test cancel pipeline schedule when user is blocked

See merge request gitlab-org/gitlab!57301
parents f0f75827 899a7250
......@@ -98,6 +98,7 @@ module QA
autoload :Design, 'qa/resource/design'
autoload :RegistryRepository, 'qa/resource/registry_repository'
autoload :Package, 'qa/resource/package'
autoload :PipelineSchedules, 'qa/resource/pipeline_schedules'
module KubernetesCluster
autoload :Base, 'qa/resource/kubernetes_cluster/base'
......
# frozen_string_literal: true
module QA
module Resource
class PipelineSchedules < Base
attribute :id
attribute :ref
attribute :description
# Cron schedule form "* * * * *"
# String of integers in order of "minute hour day-of-month month day-of-week"
attribute :cron
attribute :project do
Resource::Project.fabricate! do |project|
project.name = 'project-with-pipeline-schedule'
end
end
def initialize
@cron = '0 * * * *' # default to schedule at the beginning of the hour
@description = 'QA test scheduling pipeline.'
@ref = project.default_branch
end
def api_get_path
"/projects/#{project.id}/pipeline_schedules/#{id}"
end
def api_post_path
"/projects/#{project.id}/pipeline_schedules"
end
def api_post_body
{
description: description,
ref: ref,
cron: cron
}
end
private
def resource_web_url(resource)
resource = resource.has_key?(:owner) ? resource.fetch(:owner) : resource
super
end
end
end
end
......@@ -179,6 +179,10 @@ module QA
"#{api_get_path}/pipelines"
end
def api_pipeline_schedules_path
"#{api_get_path}/pipeline_schedules"
end
def api_put_path
"/projects/#{id}"
end
......@@ -290,6 +294,10 @@ module QA
parse_body(get(Runtime::API::Request.new(api_client, api_pipelines_path).url))
end
def pipeline_schedules
parse_body(get(Runtime::API::Request.new(api_client, api_pipeline_schedules_path).url))
end
private
def transform_api_resource(api_resource)
......
......@@ -118,6 +118,10 @@ module QA
'/users'
end
def api_block_path
"/users/#{id}/block"
end
def api_post_body
{
admin: admin,
......@@ -143,6 +147,14 @@ module QA
end
end
def block!
response = post(Runtime::API::Request.new(api_client, api_block_path).url, nil)
unless response.code == HTTP_STATUS_CREATED
raise ResourceUpdateFailedError, "Failed to block user. Request returned (#{response.code}): `#{response}`."
end
end
private
def ldap_post_body
......
# frozen_string_literal: true
module QA
RSpec.describe 'Verify', :requires_admin do
describe 'When user is blocked' do
let!(:admin_api_client) { Runtime::API::Client.as_admin }
let!(:user_api_client) { Runtime::API::Client.new(:gitlab, user: user) }
let(:user) do
Resource::User.fabricate_via_api! do |resource|
resource.api_client = admin_api_client
end
end
let(:project) do
Resource::Project.fabricate_via_api! do |project|
project.name = 'project-for-canceled-schedule'
end
end
before do
project.add_member(user, Resource::Members::AccessLevel::MAINTAINER)
Resource::PipelineSchedules.fabricate_via_api! do |schedule|
schedule.api_client = user_api_client
schedule.project = project
end
Support::Waiter.wait_until { !pipeline_schedule[:id].nil? && pipeline_schedule[:active] == true }
end
after do
user.remove_via_api!
project.remove_via_api!
end
it 'pipeline schedule is canceled', testcase: 'https://gitlab.com/gitlab-org/quality/testcases/-/issues/1730' do
user.block!
expect(pipeline_schedule[:active]).not_to be_truthy, "Expected schedule active state to be false - active state #{pipeline_schedule[:active]}"
end
private
def pipeline_schedule
project.pipeline_schedules.first
end
end
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