From cb4e8d13b57431a0cced9f270910b38d6ec5f414 Mon Sep 17 00:00:00 2001 From: amartynov Date: Thu, 3 Jul 2014 13:54:10 +0400 Subject: [PATCH] tests: filter with 401, 406, 415 errors --- .../api_v2/10_create/00_filter.feature | 50 +++++++++++++++++++ .../api_v2/20_delete/99_filter.feature | 50 +++++++++++++++++++ .../step_definitions/http_queries_steps.rb | 24 ++++++++- devops-service/features/support/env.rb | 36 ++++++++++--- 4 files changed, 152 insertions(+), 8 deletions(-) diff --git a/devops-service/features/api_v2/10_create/00_filter.feature b/devops-service/features/api_v2/10_create/00_filter.feature index 2fc767d..a196a93 100644 --- a/devops-service/features/api_v2/10_create/00_filter.feature +++ b/devops-service/features/api_v2/10_create/00_filter.feature @@ -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 diff --git a/devops-service/features/api_v2/20_delete/99_filter.feature b/devops-service/features/api_v2/20_delete/99_filter.feature index 054e9cb..eab631d 100644 --- a/devops-service/features/api_v2/20_delete/99_filter.feature +++ b/devops-service/features/api_v2/20_delete/99_filter.feature @@ -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 diff --git a/devops-service/features/step_definitions/http_queries_steps.rb b/devops-service/features/step_definitions/http_queries_steps.rb index 91ab188..f08c3a6 100644 --- a/devops-service/features/step_definitions/http_queries_steps.rb +++ b/devops-service/features/step_definitions/http_queries_steps.rb @@ -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 diff --git a/devops-service/features/support/env.rb b/devops-service/features/support/env.rb index 2f6ff62..418913b 100644 --- a/devops-service/features/support/env.rb +++ b/devops-service/features/support/env.rb @@ -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