Skip to content

Commit

Permalink
feat(REST): RHINENG-2752 add profiles endpoint spec nested under secu…
Browse files Browse the repository at this point in the history
…rity_guides
  • Loading branch information
RoamingNoMaD committed Nov 13, 2023
1 parent ece4758 commit 2efe0e0
Show file tree
Hide file tree
Showing 2 changed files with 239 additions and 4 deletions.
36 changes: 36 additions & 0 deletions spec/api/v2/schemas/profiles.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# frozen_string_literal: true

require './spec/api/v2/schemas/util'

module Api
module V2
module Schemas
module Profiles
extend Api::V2::Schemas::Util

PROFILE = {
type: :object,
required: %w[ref_id title],
properties: {
ref_id: {
type: :string,
examples: ['xccdf_org.ssgproject.content_profile_pci-dss'],
description: 'Identificator for Profile'
},
title: {
type: :string,
examples: ['CIS Red Hat Enterprise Linux 7 Benchmark'],
description: 'Brief description of the Profile content'
},
description: {
type: :string,
examples: ['This profile defines a baseline that aligns to the Center for Internet Security®' \
'Red Hat Enterprise Linux 7 Benchmark™, v2.2.0, released 12-27-2017.'],
description: 'Longer description of the Profile content'
}
}
}.freeze
end
end
end
end
207 changes: 203 additions & 4 deletions spec/integration/v2/security_guides_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
)
end
end
let(:sg_id) { security_guides.first.id }

before do
allow(Insights::Api::Common::IdentityHeader).to receive(:new).and_return(identity_header)
Expand Down Expand Up @@ -158,8 +159,6 @@

path '/security_guides/{sg_id}' do
get 'Returns requested Security Guide' do
let(:sg_id) { security_guides.first.id }

tags 'security_guide'
description 'Returns requested Security Guide'
operationId 'ShowSecurityGuide'
Expand All @@ -185,9 +184,209 @@
end

response '404', 'Security Guide not found' do
let(:sg_id) { 'invalid' }
let(:sg_id) { Faker::Internet.uuid }

after do |e|
autogenerate_examples(e, 'Description of an error when the requested Security Guide is not found')
end

run_test!
end
end
end

let!(:profiles) do
FactoryBot.create_list(
:v2_profile,
3,
security_guide: security_guides.first
)
end
let(:prof_id) { profiles.first.id }

path '/security_guides/{sg_id}/profiles' do
get 'List all Profiles under a Security Guide' do
tags 'security_guide'
description 'Lists all Profiles under a Security Guide'
operationId 'ListProfiles'
content_types
parameter name: :sg_id, in: :path, type: :string
pagination_params_v2
sort_params_v2(V2::Profile)
search_params_v2(V2::Profile)

response '200', 'Lists all Profiles under a Security Guide requested' do
schema type: :object,
properties: {
meta: ref_schema('metadata'),
links: ref_schema('links'),
data: {
type: :array,
items: {
properties: {
type: { type: :string },
id: ref_schema('id'),
attributes: ref_schema('profiles')
}
}
}
}

after { |e| autogenerate_examples(e, 'List of Profiles under a Security Guide') }

run_test!
end

response '200', 'Lists all Profiles under a Security Guide requested' do
let(:sort_by) { ['title'] }
schema type: :object,
properties: {
meta: ref_schema('metadata'),
links: ref_schema('links'),
data: {
type: :array,
items: {
properties: {
type: { type: :string },
id: ref_schema('id'),
attributes: ref_schema('profiles')
}
}
}
}

after { |e| autogenerate_examples(e, 'List of Profiles under a Security Guide sorted by "title:asc"') }

run_test!
end

response '200', 'Lists all Profiles under a Security Guide requested' do
let(:filter) { '(ref_id=xccdf_org.ssgproject.content_profile_rht-ccp)' }
schema type: :object,
properties: {
meta: ref_schema('metadata'),
links: ref_schema('links'),
data: {
type: :array,
items: {
properties: {
type: { type: :string },
id: ref_schema('id'),
attributes: ref_schema('profiles')
}
}
}
}

after do |e|
autogenerate_examples(e, 'List of Profiles under a Security Guide filtered by ' \
'"(ref_id=xccdf_org.ssgproject.content_profile_rht-ccp)"')
end

run_test!
end

response '422', 'Returns error if wrong parameters are used' do
let(:sort_by) { ['description'] }
schema type: :object,
properties: {
meta: ref_schema('metadata'),
links: ref_schema('links'),
data: {
type: :array,
items: {
properties: {
type: { type: :string },
id: ref_schema('id'),
attributes: ref_schema('profiles')
}
}
}
}

after { |e| autogenerate_examples(e, 'Description of an error when sorting by incorrect parameter') }

run_test!
end

response '422', 'Returns error if wrong parameters are used' do
let(:limit) { 103 }
schema type: :object,
properties: {
meta: ref_schema('metadata'),
links: ref_schema('links'),
data: {
type: :array,
items: {
properties: {
type: { type: :string },
id: ref_schema('id'),
attributes: ref_schema('profiles')
}
}
}
}

after { |e| autogenerate_examples(e, 'Description of an error when requesting higher limit than supported') }

run_test!
end

response '404', 'Profile not found' do
let(:sg_id) { Faker::Internet.uuid }

after do |e|
autogenerate_examples(e, 'Description of an error when the requested Profiles are ' \
'under a different or nonexistent Security Guide')
end

run_test!
end
end
end

path '/security_guides/{sg_id}/profiles/{prof_id}' do
get 'Returns a Profile under a Security Guide' do
tags 'security_guide'
description 'Returns requested Profile under a Security Guide'
operationId 'ShowProfile'
content_types
parameter name: :sg_id, in: :path, type: :string
parameter name: :prof_id, in: :path, type: :string

response '200', 'Returns requested Profile' do
schema type: :object,
properties: {
data: {
type: :object,
properties: {
type: { type: :string },
id: ref_schema('id'),
attributes: ref_schema('profile')
}
}
}

after { |e| autogenerate_examples(e, 'Requested Profile') }

run_test!
end

response '404', 'Profile not found' do
let(:sg_id) { Faker::Internet.uuid }

after do |e|
autogenerate_examples(e, 'Description of an error when the requested Profile is ' \
'under a different or nonexistent Security Guide')
end

run_test!
end

response '404', 'Profile not found' do
let(:prof_id) { Faker::Internet.uuid }

after { |e| autogenerate_examples(e, 'Description of an error when the requested Security Guide is not found') }
after { |e| autogenerate_examples(e, 'Description of an error when the requested Profile is not found') }

run_test!
end
Expand Down

0 comments on commit 2efe0e0

Please sign in to comment.