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
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
Scenario: Add openstack image filter
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 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
Scenario: Add ec2 image filter
When I send PUT '/v2.0/filter/ec2/image' query with JSON body

View File

@ -1,6 +1,31 @@
@filter
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
Scenario: Delete openstack image filter
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 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
Scenario: Delete ec2 image filter
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}
headers = {}
DEFAULT_HEADERS.each{|h, v| headers[h] = v unless buf.include?(h)}
puts headers
get(path, {}, headers)
end
@ -31,6 +30,11 @@ When(/^I send POST '(.*)' query with JSON body$/) do |path, body|
res = post_body(path, body, DEFAULT_HEADERS)
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|
delete(path, {}, DEFAULT_HEADERS)
end
@ -39,10 +43,28 @@ When(/^I send DELETE '(.*)' query with JSON body$/) do |path, body|
res = delete_body(path, body, DEFAULT_HEADERS)
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|
res = put_body(path, body, DEFAULT_HEADERS)
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|
assert(code.to_i == last_response.status, "Status is not #{code}, it is #{last_response.status}")
end

View File

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