users tests: create and delete
This commit is contained in:
parent
2432e2f42c
commit
736d2eabd0
@ -60,6 +60,7 @@ module Version2_0
|
||||
# - body :
|
||||
# {
|
||||
# "username": "user name",
|
||||
# "email": "user email",
|
||||
# "password": "user password"
|
||||
# }
|
||||
#
|
||||
@ -69,7 +70,7 @@ module Version2_0
|
||||
check_headers :accept, :content_type
|
||||
check_privileges("user", "w")
|
||||
user = create_object_from_json_body
|
||||
["username", "password"].each do |p|
|
||||
["username", "password", "email"].each do |p|
|
||||
check_string(user[p], "Parameter '#{p}' must be a not empty string")
|
||||
end
|
||||
BaseRoutes.mongo.user_insert User.new(user)
|
||||
|
||||
@ -37,6 +37,11 @@ When(/^I send POST '(.*)' query with JSON body without header '(.*)'$/) do |path
|
||||
res = post_body(path, body, headers)
|
||||
end
|
||||
|
||||
When(/^I send POST '(.*)' query with JSON body with user without privileges$/) do |path, body|
|
||||
JSON.parse(body) unless body.strip.empty?
|
||||
res = post_without_privileges(path, body, DEFAULT_HEADERS)
|
||||
end
|
||||
|
||||
When(/^I send DELETE '(.*)' query$/) do |path|
|
||||
delete(path, {}, DEFAULT_HEADERS)
|
||||
end
|
||||
|
||||
@ -79,6 +79,12 @@ class RequestSender
|
||||
end
|
||||
end
|
||||
|
||||
def post_without_privileges path, query={}, headers={}
|
||||
user_without_privileges do
|
||||
postt(path, query, headers)
|
||||
end
|
||||
end
|
||||
|
||||
def put path, query, headers={}
|
||||
put_body(path, JSON.pretty_generate(query), headers)
|
||||
end
|
||||
|
||||
@ -38,7 +38,11 @@ templates = {
|
||||
"templates/api_v2/10_create/00_filter.feature.erb" => "features/api_v2/10_create/00_filter.feature",
|
||||
"templates/api_v2/10_create/10_image.feature.erb" => "features/api_v2/10_create/10_image.feature",
|
||||
"templates/api_v2/10_create/20_project.feature.erb" => "features/api_v2/10_create/20_project.feature",
|
||||
"templates/api_v2/10_create/30_script.feature.erb" => "features/api_v2/10_create/30_script.feature"
|
||||
"templates/api_v2/10_create/30_script.feature.erb" => "features/api_v2/10_create/30_script.feature",
|
||||
"templates/api_v2/10_create/00_user.feature.erb" => "features/api_v2/10_create/00_user.feature",
|
||||
|
||||
#delete
|
||||
"templates/api_v2/90_delete/90_user.feature.erb" => "features/api_v2/90_delete/90_user.feature"
|
||||
}
|
||||
generator = Generator.new
|
||||
generator.make_tests_config
|
||||
|
||||
@ -23,3 +23,7 @@ ec2:
|
||||
|
||||
script:
|
||||
name: "cucumber_test_script"
|
||||
|
||||
user:
|
||||
name: "cucumber_test"
|
||||
|
||||
|
||||
@ -0,0 +1,44 @@
|
||||
@user
|
||||
Feature: list user
|
||||
|
||||
Scenario: Get list of all users
|
||||
When I send GET '/v2.0/users' query
|
||||
Then response should be '200'
|
||||
And the Content-Type header should include 'application/json'
|
||||
And the JSON response should be an array
|
||||
And response array should contains elements like:
|
||||
"""
|
||||
[
|
||||
{
|
||||
"email": "test@test.test",
|
||||
"privileges": {
|
||||
"flavor": "rwx",
|
||||
"group": "rwx",
|
||||
"image": "rwx",
|
||||
"project": "rwx",
|
||||
"server": "rwx",
|
||||
"key": "rwx",
|
||||
"user": "rwx",
|
||||
"filter": "rwx",
|
||||
"network": "rwx",
|
||||
"provider": "rwx",
|
||||
"script": "rwx",
|
||||
"templates": "rwx"
|
||||
},
|
||||
"id": "test"
|
||||
}
|
||||
]
|
||||
"""
|
||||
|
||||
Scenario: Get list of all users without header 'Accept'
|
||||
When I send GET '/v2.0/users' query without headers 'Accept'
|
||||
Then response should be '406'
|
||||
|
||||
Scenario: Get list of all users without privileges
|
||||
When I send GET '/v2.0/users' query with user without privileges
|
||||
Then response should be '401'
|
||||
|
||||
Scenario: Get list of all users - invalid path
|
||||
When I send GET '/v2.0/users/foo' query
|
||||
Then response should be '404'
|
||||
|
||||
@ -0,0 +1,134 @@
|
||||
@user
|
||||
Feature: create user
|
||||
|
||||
Scenario: create user with user without privileges
|
||||
When I send POST '/v2.0/user' query with JSON body with user without privileges
|
||||
"""
|
||||
{
|
||||
"username": "<%= @config["user"]["name"] %>",
|
||||
"email": "<%= @config["user"]["name"] %>@test.test",
|
||||
"password": "<%= @config["user"]["name"] %>"
|
||||
}
|
||||
"""
|
||||
Then response should be '401'
|
||||
|
||||
Scenario: create user without header 'Accept'
|
||||
When I send POST '/v2.0/user' query with JSON body without header 'Accept'
|
||||
"""
|
||||
{
|
||||
"username": "<%= @config["user"]["name"] %>",
|
||||
"email": "<%= @config["user"]["name"] %>@test.test",
|
||||
"password": "<%= @config["user"]["name"] %>"
|
||||
}
|
||||
"""
|
||||
Then response should be '406'
|
||||
|
||||
Scenario: create user without header 'Content-Type'
|
||||
When I send POST '/v2.0/user' query with JSON body without header 'Content-Type'
|
||||
"""
|
||||
{
|
||||
"username": "<%= @config["user"]["name"] %>",
|
||||
"email": "<%= @config["user"]["name"] %>@test.test",
|
||||
"password": "<%= @config["user"]["name"] %>"
|
||||
}
|
||||
"""
|
||||
Then response should be '415'
|
||||
|
||||
Scenario: create user, invalid body: empty
|
||||
When I send POST '/v2.0/user' query with JSON body
|
||||
"""
|
||||
"""
|
||||
Then response should be '400'
|
||||
|
||||
<% ["{}", "[]"].each do |k| %>
|
||||
Scenario: create user, invalid body: body is a '<%= k %>'
|
||||
When I send POST '/v2.0/user' query with JSON body
|
||||
"""
|
||||
<%= k %>
|
||||
"""
|
||||
Then response should be '400'
|
||||
|
||||
<% end %>
|
||||
<% elements = ["{}", "[]", "null" ] %>
|
||||
<% elements.each do |k| %>
|
||||
Scenario: create user, invalid body: username is a '<%= k %>'
|
||||
When I send POST '/v2.0/user' query with JSON body
|
||||
"""
|
||||
{
|
||||
"username": <%= k %>,
|
||||
"email": "<%= @config["user"]["name"] %>@test.test",
|
||||
"password": "<%= @config["user"]["name"] %>"
|
||||
}
|
||||
"""
|
||||
Then response should be '400'
|
||||
|
||||
<% end %>
|
||||
<% elements.each do |k| %>
|
||||
Scenario: create user, invalid body: password is a '<%= k %>'
|
||||
When I send POST '/v2.0/user' query with JSON body
|
||||
"""
|
||||
{
|
||||
"username": "<%= @config["user"]["name"] %>",
|
||||
"email": "<%= @config["user"]["name"] %>@test.test",
|
||||
"password": <%= k %>
|
||||
}
|
||||
"""
|
||||
Then response should be '400'
|
||||
|
||||
<% end %>
|
||||
<% elements.each do |k| %>
|
||||
Scenario: create user, invalid body: email is a '<%= k %>'
|
||||
When I send POST '/v2.0/user' query with JSON body
|
||||
"""
|
||||
{
|
||||
"username": "<%= @config["user"]["name"] %>",
|
||||
"email": <%= k %>,
|
||||
"password": "<%= @config["user"]["name"] %>"
|
||||
}
|
||||
"""
|
||||
Then response should be '400'
|
||||
|
||||
<% end %>
|
||||
|
||||
Scenario: create user, invalid body: without username
|
||||
When I send POST '/v2.0/user' query with JSON body
|
||||
"""
|
||||
{
|
||||
"email": "<%= @config["user"]["name"] %>@test.test",
|
||||
"password": "<%= @config["user"]["name"] %>"
|
||||
}
|
||||
"""
|
||||
Then response should be '400'
|
||||
|
||||
Scenario: create user, invalid body: without email
|
||||
When I send POST '/v2.0/user' query with JSON body
|
||||
"""
|
||||
{
|
||||
"username": "<%= @config["user"]["name"] %>",
|
||||
"password": "<%= @config["user"]["name"] %>"
|
||||
}
|
||||
"""
|
||||
Then response should be '400'
|
||||
|
||||
Scenario: create user, invalid body: without password
|
||||
When I send POST '/v2.0/user' query with JSON body
|
||||
"""
|
||||
{
|
||||
"email": "<%= @config["user"]["name"] %>@test.test",
|
||||
"username": "<%= @config["user"]["name"] %>"
|
||||
}
|
||||
"""
|
||||
Then response should be '400'
|
||||
|
||||
Scenario: create user
|
||||
When I send POST '/v2.0/user' query with JSON body
|
||||
"""
|
||||
{
|
||||
"username": "<%= @config["user"]["name"] %>",
|
||||
"email": "<%= @config["user"]["name"] %>@test.test",
|
||||
"password": "<%= @config["user"]["name"] %>"
|
||||
}
|
||||
"""
|
||||
Then response should be '201'
|
||||
And the Content-Type header should include 'application/json'
|
||||
|
||||
@ -0,0 +1,20 @@
|
||||
@user
|
||||
Feature: delete user
|
||||
|
||||
Scenario: delete user with user without privileges
|
||||
When I send DELETE '/v2.0/user/<%= @config["user"]["name"] %>' query with user without privileges
|
||||
Then response should be '401'
|
||||
|
||||
Scenario: delete user without header 'Accept'
|
||||
When I send DELETE '/v2.0/user/<%= @config["user"]["name"] %>' query without header 'Accept'
|
||||
Then response should be '406'
|
||||
|
||||
Scenario: delete unknown user
|
||||
When I send DELETE '/v2.0/user/unknown' query
|
||||
Then response should be '404'
|
||||
|
||||
Scenario: delete user
|
||||
When I send DELETE '/v2.0/user/<%= @config["user"]["name"] %>' query
|
||||
Then response should be '200'
|
||||
And the Content-Type header should include 'application/json'
|
||||
|
||||
Loading…
Reference in New Issue
Block a user