Skip to content

Commit

Permalink
Pedant test for the case if automate license is expired (#3941)
Browse files Browse the repository at this point in the history
* Updated chef-server-ctl to handle invalid license + Added grace period in X-Ops-License

Signed-off-by: jan shahid shaik <[email protected]>

* Added customer name in get_license method and license cache

Signed-off-by: jan shahid shaik <[email protected]>

* debug statements

Signed-off-by: talktovikas <[email protected]>

* case for expired license.

Signed-off-by: talktovikas <[email protected]>

making it 403

Signed-off-by: talktovikas <[email protected]>

running cases only for automate.

Signed-off-by: talktovikas <[email protected]>

test for chef-zero

Signed-off-by: talktovikas <[email protected]>

test for /users

Signed-off-by: talktovikas <[email protected]>

adding env in docker

Signed-off-by: talktovikas <[email protected]>

fixing verify syntax.

Signed-off-by: talktovikas <[email protected]>

fixing placement of env variables.

Signed-off-by: talktovikas <[email protected]>

fixing placement of executor.

Signed-off-by: talktovikas <[email protected]>

test

Signed-off-by: talktovikas <[email protected]>

* adding config for expired license from vault.

Signed-off-by: talktovikas <[email protected]>

* Added few puts inside success licese case.

Signed-off-by: sreepuramsudheer <[email protected]>

* Added IS_AUTOMATE into environment variables.

Signed-off-by: sreepuramsudheer <[email protected]>

* Replaced hardcoded expired license with one received from vault.

Signed-off-by: sreepuramsudheer <[email protected]>

* Updated chef-server-ctl to handle invalid license + Added grace period in X-Ops-License

Signed-off-by: jan shahid shaik <[email protected]>

* Added customer name in get_license method and license cache

Signed-off-by: jan shahid shaik <[email protected]>

* removing debug logs

Signed-off-by: talktovikas <[email protected]>

* code review changes.

Signed-off-by: talktovikas <[email protected]>

* adding comment for the test case.

Signed-off-by: talktovikas <[email protected]>

---------

Signed-off-by: jan shahid shaik <[email protected]>
Signed-off-by: talktovikas <[email protected]>
Signed-off-by: sreepuramsudheer <[email protected]>
Co-authored-by: jan shahid shaik <[email protected]>
Co-authored-by: sreepuramsudheer <[email protected]>
  • Loading branch information
3 people authored Nov 14, 2024
1 parent fdc25e0 commit 9e7fa34
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 11 deletions.
46 changes: 35 additions & 11 deletions .expeditor/verify.pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ steps:
- USE_OMNIBUS_FILES=0
- PEDANT_OPTS="--skip-oc_id"
- BUNDLE_GEMFILE=/workdir/oc-chef-pedant/Gemfile
- IS_AUTOMATE=false

- label: With ChefFS=1
command:
Expand All @@ -174,6 +175,7 @@ steps:
- PEDANT_OPTS="--skip-oc_id"
- CHEF_FS=1
- BUNDLE_GEMFILE=/workdir/oc-chef-pedant/Gemfile
- IS_AUTOMATE=false

- label: automate_build
command:
Expand Down Expand Up @@ -214,39 +216,61 @@ steps:
- label: "chef server"
command:
- .expeditor/chef_server.sh
env:
IS_AUTOMATE: true
timeout_in_minutes: 30 # longer timeout for chef-server
expeditor:
executor:
linux:
privileged: true
secrets:
A2_LICENSE:
path: secret/a2/license
field: license
A2_EXPIRED_LICENSE:
path: secret/a2/license
field: expLicense
executor:
linux:
privileged: true
environment:
- IS_AUTOMATE=true

- label: "chef server only"
command:
- .expeditor/chef_server_only.sh
env:
IS_AUTOMATE: true
timeout_in_minutes: 20
expeditor:
executor:
linux:
privileged: true
secrets:
A2_LICENSE:
path: secret/a2/license
field: license
A2_EXPIRED_LICENSE:
path: secret/a2/license
field: expLicense
executor:
linux:
privileged: true
environment:
- IS_AUTOMATE=true


- label: "ha chef server"
command:
- .expeditor/ha_chef_server.sh
env:
IS_AUTOMATE: true
timeout_in_minutes: 35
expeditor:
executor:
linux:
single-use: true
privileged: true
secrets:
A2_LICENSE:
path: secret/a2/license
field: license
field: license
A2_EXPIRED_LICENSE:
path: secret/a2/license
field: expLicense
executor:
linux:
privileged: true
single-use: true
environment:
- IS_AUTOMATE=true
61 changes: 61 additions & 0 deletions oc-chef-pedant/spec/api/server_license_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# -*- coding: utf-8 -*-
require 'pedant/rspec/common'

describe "server license testing", :license do

# Pedant has configurable test users.
# Selects Pedant users that are marked as associated
let(:default_pedant_user_names) { platform.users.select(&:associate).map(&:name).sort }
let(:default_users_body) { default_pedant_user_names.map { |user| {"user" => {"username" => user} } } }

# context "/users endpoint", automate: true do
context "/users endpoint" do
let(:request_url) { "#{platform.server}/users" }
let(:status_url) { "#{platform.server}/_status" }

let(:users_body) do
{
# There are other users, but these are ours, so they should always be
# somewhere in the userspace soup.
"pivotal" => "#{request_url}/pivotal",
platform.bad_user.name => "#{request_url}/#{platform.bad_user.name}",
platform.admin_user.name => "#{request_url}/#{platform.admin_user.name}",
platform.non_admin_user.name => "#{request_url}/#{platform.non_admin_user.name}",
}
end

context "when having valid license" do
it "can get all users and since the license is valid, they should show 200 as return", :smoke do
get(request_url, platform.superuser).should look_like({
:status => 200,
:body => users_body
})
end
end

# In case of Embedded chef-server in Automate, If the license of automate is Expired in that case all requests reaching to chef-server should return 403
context "when not having valid license", if: ENV["IS_AUTOMATE"] == "true" do
before(:all) do
puts "applying expired license"
puts ENV['A2_EXPIRED_LICENSE']
system("chef-automate license apply -f \"${A2_EXPIRED_LICENSE}\"")
system("sleep 50")
puts "expired license applied"
puts system("chef-automate license status")
end
after(:all) do
system("chef-automate license apply \"$A2_LICENSE\"")
system("sleep 50")
puts "valid license applied"
puts system("chef-automate license status")
end

it "returns 403", :smoke do
puts get(request_url, platform.superuser)
get(request_url, platform.superuser).should look_like({
:status => 403
})
end
end
end # context /users/<name> endpoint
end # describe users

0 comments on commit 9e7fa34

Please sign in to comment.