tests: filter with 401, 406, 415 errors

This commit is contained in:
amartynov 2014-07-03 13:54:10 +04:00
parent 59aba6b860
commit cb4e8d13b5
4 changed files with 152 additions and 8 deletions

View File

@ -1,6 +1,31 @@
@filter @filter
Feature: Filters Feature: Filters
@openstack
Scenario: Add openstack image filter with user without privileges
When I send PUT '/v2.0/filter/openstack/image' query with user without privileges
Then response should be '401'
@openstack
Scenario: Add openstack image filter without header 'Accept'
When I send PUT '/v2.0/filter/openstack/image' query with JSON body without header 'Accept'
"""
[
"08093b30-8393-42c3-8fb3-c4df56deb967"
]
"""
Then response should be '415'
@openstack
Scenario: Add openstack image filter without header 'Content-Type'
When I send PUT '/v2.0/filter/openstack/image' query with JSON body without header 'Content-Type'
"""
[
"08093b30-8393-42c3-8fb3-c4df56deb967"
]
"""
Then response should be '406'
@openstack @openstack
Scenario: Add openstack image filter Scenario: Add openstack image filter
When I send PUT '/v2.0/filter/openstack/image' query with JSON body When I send PUT '/v2.0/filter/openstack/image' query with JSON body
@ -14,6 +39,31 @@ Feature: Filters
And the JSON response should be an object And the JSON response should be an object
And the object should contains key 'images' with array and array should contains strings '08093b30-8393-42c3-8fb3-c4df56deb967' And the object should contains key 'images' with array and array should contains strings '08093b30-8393-42c3-8fb3-c4df56deb967'
@ec2
Scenario: Add ec2 image filter with user without privileges
When I send PUT '/v2.0/filter/ec2/image' query with user without privileges
Then response should be '401'
@ec2
Scenario: Add ec2 image filter without header 'Accept'
When I send PUT '/v2.0/filter/ec2/image' query with JSON body without header 'Accept'
"""
[
"ami-63071b0a"
]
"""
Then response should be '415'
@ec2
Scenario: Add ec2 image filter without header 'Content-Type'
When I send PUT '/v2.0/filter/ec2/image' query with JSON body without header 'Content-Type'
"""
[
"ami-63071b0a"
]
"""
Then response should be '406'
@ec2 @ec2
Scenario: Add ec2 image filter Scenario: Add ec2 image filter
When I send PUT '/v2.0/filter/ec2/image' query with JSON body When I send PUT '/v2.0/filter/ec2/image' query with JSON body

View File

@ -1,6 +1,31 @@
@filter @filter
Feature: Filters Feature: Filters
@openstack
Scenario: Delete openstack image filter with user without privileges
When I send DELETE '/v2.0/filter/openstack/image' query with user without privileges
Then response should be '401'
@openstack
Scenario: Delete openstack image filter without header 'Accept'
When I send DELETE '/v2.0/filter/openstack/image' query with JSON body without header 'Accept'
"""
[
"08093b30-8393-42c3-8fb3-c4df56deb967"
]
"""
Then response should be '415'
@openstack
Scenario: Delete openstack image filter without header 'Content-Type'
When I send DELETE '/v2.0/filter/openstack/image' query with JSON body without header 'Content-Type'
"""
[
"08093b30-8393-42c3-8fb3-c4df56deb967"
]
"""
Then response should be '406'
@openstack @openstack
Scenario: Delete openstack image filter Scenario: Delete openstack image filter
When I send DELETE '/v2.0/filter/openstack/image' query with JSON body When I send DELETE '/v2.0/filter/openstack/image' query with JSON body
@ -14,6 +39,31 @@ Feature: Filters
And the JSON response should be an object And the JSON response should be an object
And the object should contains key 'images' with array and array should not contains strings '08093b30-8393-42c3-8fb3-c4df56deb967' And the object should contains key 'images' with array and array should not contains strings '08093b30-8393-42c3-8fb3-c4df56deb967'
@ec2
Scenario: Delete ec2 image filter with user without privileges
When I send DELETE '/v2.0/filter/ec2/image' query with user without privileges
Then response should be '401'
@ec2
Scenario: Delete ec2 image filter without header 'Accept'
When I send DELETE '/v2.0/filter/ec2/image' query with JSON body without header 'Accept'
"""
[
"ami-63071b0a"
]
"""
Then response should be '415'
@ec2
Scenario: Delete ec2 image filter without header 'Content-Type'
When I send DELETE '/v2.0/filter/ec2/image' query with JSON body without header 'Content-Type'
"""
[
"ami-63071b0a"
]
"""
Then response should be '406'
@ec2 @ec2
Scenario: Delete ec2 image filter Scenario: Delete ec2 image filter
When I send DELETE '/v2.0/filter/ec2/image' query with JSON body When I send DELETE '/v2.0/filter/ec2/image' query with JSON body

View File

@ -14,7 +14,6 @@ When(/^I send GET '(.*)' query without headers '(.*)'$/) do |path, hs|
buf = hs.split(",").map{|e| e.strip} buf = hs.split(",").map{|e| e.strip}
headers = {} headers = {}
DEFAULT_HEADERS.each{|h, v| headers[h] = v unless buf.include?(h)} DEFAULT_HEADERS.each{|h, v| headers[h] = v unless buf.include?(h)}
puts headers
get(path, {}, headers) get(path, {}, headers)
end end
@ -31,6 +30,11 @@ When(/^I send POST '(.*)' query with JSON body$/) do |path, body|
res = post_body(path, body, DEFAULT_HEADERS) res = post_body(path, body, DEFAULT_HEADERS)
end end
When(/^I send POST '(.*)' query with JSON body without header '(.*)'$/) do |path, hs, body|
headers = DEFAULT_HEADERS.select{|h, v| h == hs}
res = post_body(path, body, headers)
end
When(/^I send DELETE '(.*)' query$/) do |path| When(/^I send DELETE '(.*)' query$/) do |path|
delete(path, {}, DEFAULT_HEADERS) delete(path, {}, DEFAULT_HEADERS)
end end
@ -39,10 +43,28 @@ When(/^I send DELETE '(.*)' query with JSON body$/) do |path, body|
res = delete_body(path, body, DEFAULT_HEADERS) res = delete_body(path, body, DEFAULT_HEADERS)
end end
When(/^I send DELETE '(.*)' query with JSON body without header '(.*)'$/) do |path, hs, body|
headers = DEFAULT_HEADERS.select{|h, v| h == hs}
res = delete_body(path, body, headers)
end
When(/^I send DELETE '(.*)' query with user without privileges$/) do |path|
delete_without_privileges(path, {}, DEFAULT_HEADERS)
end
When(/^I send PUT '(.*)' query with JSON body$/) do |path, body| When(/^I send PUT '(.*)' query with JSON body$/) do |path, body|
res = put_body(path, body, DEFAULT_HEADERS) res = put_body(path, body, DEFAULT_HEADERS)
end end
When(/^I send PUT '(.*)' query with user without privileges$/) do |path|
put_without_privileges(path, {}, DEFAULT_HEADERS)
end
When(/^I send PUT '(.*)' query with JSON body without header '(.*)'$/) do |path, hs, body|
headers = DEFAULT_HEADERS.select{|h, v| h == hs}
res = put_body(path, body, headers)
end
Then(/^response should be '(\d+)'$/) do |code| Then(/^response should be '(\d+)'$/) do |code|
assert(code.to_i == last_response.status, "Status is not #{code}, it is #{last_response.status}") assert(code.to_i == last_response.status, "Status is not #{code}, it is #{last_response.status}")
end end

View File

@ -63,13 +63,9 @@ class RequestSender
end end
def get_without_privileges path, query={}, headers={} def get_without_privileges path, query={}, headers={}
buf_u = @config["username"] user_without_privileges do
buf_p = @config["password"]
@config["username"] = @config["username_without_privileges"]
@config["password"] = @config["password_without_privileges"]
get(path, query, headers) get(path, query, headers)
@config["username"] = buf_u end
@config["password"] = buf_p
end end
def post path, query, headers={} def post path, query, headers={}
@ -83,6 +79,10 @@ class RequestSender
end end
end end
def put path, query, headers={}
put_body(path, JSON.pretty_generate(query), headers)
end
def put_body path, body, headers={} def put_body path, body, headers={}
submit do |http| submit do |http|
http.receive_timeout = 0 #!!! bring out to appropriate server step http.receive_timeout = 0 #!!! bring out to appropriate server step
@ -90,6 +90,12 @@ class RequestSender
end end
end end
def put_without_privileges path, query={}, headers={}
user_without_privileges do
put(path, query, headers)
end
end
def delete path, query, headers={} def delete path, query, headers={}
delete_body(path, JSON.pretty_generate(query), headers) delete_body(path, JSON.pretty_generate(query), headers)
end end
@ -100,6 +106,12 @@ class RequestSender
end end
end end
def delete_without_privileges path, query={}, headers={}
user_without_privileges do
delete(path, query, headers)
end
end
def submit def submit
http = HTTPClient.new http = HTTPClient.new
http.set_auth(nil, @config["username"], @config["password"]) http.set_auth(nil, @config["username"], @config["password"])
@ -107,6 +119,16 @@ class RequestSender
@last_res = res @last_res = res
end end
def user_without_privileges
buf_u = @config["username"]
buf_p = @config["password"]
@config["username"] = @config["username_without_privileges"]
@config["password"] = @config["password_without_privileges"]
yield
@config["username"] = buf_u
@config["password"] = buf_p
end
def config path def config path
YAML.load_file(path) YAML.load_file(path)
end end