@user Feature: change user privileges and password <% user_hash = @formatter.get_fixture('user/create') %> <% username = user_hash["username"] %> <% update_user_hash = @formatter.get_fixture('user/update') %> <% update_user_hash.keys.each do |k| %> Scenario: change user <%= k %> with user without privileges When I send PUT '/v2.0/user/<%= username %>/<%= k %>' query with JSON body with user without privileges """ { "<%= k %>": "<%= update_user_hash[k] %>" } """ Then response should be '401' Scenario: change root <%= k %> When I send PUT '/v2.0/user/root/<%= k %>' query with JSON body """ { "<%= k %>": "<%= update_user_hash[k] %>" } """ Then response should be '401' Scenario: change user <%= k %> without header 'Content-Type' When I send PUT '/v2.0/user/<%= username %>/<%= k %>' query with JSON body without header 'Content-Type' """ { "<%= k %>": "<%= update_user_hash[k] %>" } """ Then response should be '415' Scenario: change user <%= k %>, invalid body: empty When I send PUT '/v2.0/user/<%= username %>/<%= k %>' query with JSON body """ """ Then response should be '400' <% ["", "[]"].each do |body| %> Scenario: change user <%= k %>, invalid body: body is a '<%= body %>' When I send PUT '/v2.0/user/<%= username %>/<%= k %>' query with JSON body """ <%= body %> """ Then response should be '400' <% end %> <% elements = ["{}", "[]", "null" ] %> <% elements.each do |value| %> Scenario: change user <%= k %>, invalid body: <%= k %> is a '<%= value %>' When I send PUT '/v2.0/user/<%= username %>/<%= k %>' query with JSON body """ { "<%= k %>": <%= value %> } """ Then response should be '400' <% end %> Scenario: change user <%= k %> When I send PUT '/v2.0/user/<%= username %>/<%= k %>' query with JSON body """ { "<%= k %>": "<%= update_user_hash[k] %>" } """ Then response should be '200' And the Content-Type header should include 'application/json' <% end %> Scenario: change user privileges with user without privileges When I send PUT '/v2.0/user/<%= username %>' query with JSON body with user without privileges """ <%= @formatter.json('user/privileges', {spaces: 4}) %> """ Then response should be '401' Scenario: change root privileges When I send PUT '/v2.0/user/root' query with JSON body """ <%= @formatter.json('user/privileges', {spaces: 4}) %> """ Then response should be '401' Scenario: change user privileges without header 'Content-Type' When I send PUT '/v2.0/user/<%= username %>' query with JSON body without header 'Content-Type' """ <%= @formatter.json('user/privileges', {spaces: 4}) %> """ Then response should be '415' Scenario: change user privileges with header 'Accept' value is not application/json When I send PUT '/v2.0/user/<%= username %>' query with JSON body with header 'Accept' value 'application/xml' """ <%= @formatter.json('user/privileges', {spaces: 4}) %> """ Then response should be '406' <% elements = ["{}", "[]" ] %> <% elements.each do |value| %> Scenario: change user privileges, invalid body: cmd is a '<%= value %>' When I send PUT '/v2.0/user/<%= username %>' query with JSON body """ <%= @formatter.json('user/privileges_update', {spaces: 4, value: {"cmd" => value, "privileges" => "r"}}) %> """ Then response should be '400' Scenario: change user privileges, invalid body: privileges is a '<%= value %>' When I send PUT '/v2.0/user/<%= username %>' query with JSON body """ <%= @formatter.json('user/privileges_update', {spaces: 4, value: {"cmd" => "foo", "privileges" => value}}) %> """ Then response should be '400' <% end %> Scenario: change user privileges: foo - r When I send PUT '/v2.0/user/<%= username %>' query with JSON body """ <%= @formatter.json('user/privileges_update', {spaces: 4, value: {"cmd" => "foo", "privileges" => "r"}}) %> """ Then response should be '400' <% %w{foo, rr, rwwww, rwxxx, rwf}.each do |priv| %> Scenario: change user privileges: all - <%= priv %> When I send PUT '/v2.0/user/<%= @config["user"]["name"] %>' query with JSON body """ <%= @formatter.json('user/privileges_update', {spaces: 4, value: {"cmd" => "all", "privileges" => priv}}) %> """ Then response should be '400' <% end %> <% privs = @formatter.get_fixture('user/privileges_values') %> <% (@formatter.get_fixture('user/privileges').keys.map(&:to_s) << "all").each do |cmd| %> <% privs.each do |priv| %> Scenario: change user privileges: <%= cmd %> - <%= priv %> When I send PUT '/v2.0/user/<%= username %>' query with JSON body """ <%= @formatter.json('user/privileges_update', {spaces: 4, value: {"cmd" => cmd, "privileges" => priv}}) %> """ Then response should be '200' <% end %> Scenario: change user privileges: <%= cmd %> - without privileges When I send PUT '/v2.0/user/<%= username %>' query with JSON body """ <%= @formatter.json('user/privileges_update', {spaces: 4, value: {"cmd" => cmd}, without_field: "privileges"}) %> """ Then response should be '200' Scenario: change user privileges: <%= cmd %> - ' ' When I send PUT '/v2.0/user/<%= username %>' query with JSON body """ <%= @formatter.json('user/privileges_update', {spaces: 4, value: {"cmd" => cmd, "privileges" => " "}}) %> """ Then response should be '400' <% end %> Scenario: change user privileges: set default privileges When I send PUT '/v2.0/user/<%= username %>' query with JSON body """ { } """ Then response should be '200'