Test case added for command to set both max-connections and max-channels
Clearing all user limits Testcase to test clearing all limits for user
This commit is contained in:
parent
d1301e5ce5
commit
dbbe62e8a4
|
|
@ -17,32 +17,35 @@ defmodule RabbitMQ.CLI.Ctl.Commands.ClearUserLimitsCommand do
|
|||
|
||||
@behaviour RabbitMQ.CLI.CommandBehaviour
|
||||
use RabbitMQ.CLI.DefaultOutput
|
||||
|
||||
|
||||
use RabbitMQ.CLI.Core.MergesNoDefaults
|
||||
use RabbitMQ.CLI.Core.AcceptsTwoPositionalArguments
|
||||
|
||||
def run([username, limittype], %{node: node_name}) do
|
||||
def run([username, limit_type], %{node: node_name}) do
|
||||
:rabbit_misc.rpc_call(node_name, :rabbit_auth_backend_internal, :clear_user_limits, [
|
||||
username,
|
||||
limittype
|
||||
limit_type
|
||||
])
|
||||
end
|
||||
|
||||
use RabbitMQ.CLI.Core.RequiresRabbitAppRunning
|
||||
|
||||
def usage, do: "clear_user_limits username limittype"
|
||||
def usage, do: "clear_user_limits username <limit_type> | all"
|
||||
|
||||
##ToDo def usage_doc_guides() do
|
||||
##ToDo [
|
||||
##ToDo DocGuide.virtual_hosts()
|
||||
##ToDo ]
|
||||
##ToDo end
|
||||
def usage_additional() do
|
||||
[
|
||||
["<limit_type>", "Limit type, must be max-connections or max-channels"]
|
||||
]
|
||||
end
|
||||
|
||||
##ToDo def help_section(), do: :virtual_hosts
|
||||
def help_section(), do: :user_management
|
||||
|
||||
def description(), do: "Clears user connection/channel limits"
|
||||
|
||||
def banner([username, limittype], %{}) do
|
||||
"Clearing \"#{limittype}\" limit for user \"#{username}\" ..."
|
||||
def banner([username, "all"], %{}) do
|
||||
"Clearing all limits for user \"#{username}\" ..."
|
||||
end
|
||||
def banner([username, limit_type], %{}) do
|
||||
"Clearing \"#{limit_type}\" limit for user \"#{username}\" ..."
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -39,6 +39,8 @@ defmodule RabbitMQ.CLI.Ctl.Commands.SetUserLimitsCommand do
|
|||
]
|
||||
end
|
||||
|
||||
def help_section(), do: :user_management
|
||||
|
||||
def description(), do: "Sets user limits"
|
||||
|
||||
def banner([username, definition], %{}) do
|
||||
|
|
|
|||
|
|
@ -24,7 +24,8 @@ defmodule ClearUserLimitsCommandTest do
|
|||
@user "someone"
|
||||
@password "password"
|
||||
@limittype "max-channels"
|
||||
@definition "{\"max-channels\":100}"
|
||||
@channel_definition "{\"max-channels\":100}"
|
||||
@definition "{\"max-channels\":500, \"max-connections\":100}"
|
||||
|
||||
setup_all do
|
||||
RabbitMQ.CLI.Core.Distribution.start()
|
||||
|
|
@ -80,6 +81,19 @@ defmodule ClearUserLimitsCommandTest do
|
|||
assert get_user_limits(@user) == %{}
|
||||
end
|
||||
|
||||
test "run: if limit exists, returns ok and clears all limits for the given user", context do
|
||||
:ok = set_user_limits(@user, @definition)
|
||||
|
||||
assert get_user_limits(@user) != []
|
||||
|
||||
assert @command.run(
|
||||
[@user, "all"],
|
||||
context[:opts]
|
||||
) == :ok
|
||||
|
||||
assert get_user_limits(@user) == %{}
|
||||
end
|
||||
|
||||
@tag user: "bad-user"
|
||||
test "run: a non-existent user returns an error", context do
|
||||
|
||||
|
|
@ -89,7 +103,7 @@ defmodule ClearUserLimitsCommandTest do
|
|||
) == {:error, {:no_such_user, "bad-user"}}
|
||||
end
|
||||
|
||||
test "banner", context do
|
||||
test "banner: for a limit type", context do
|
||||
|
||||
s = @command.banner(
|
||||
[@user, @limittype],
|
||||
|
|
@ -99,4 +113,14 @@ defmodule ClearUserLimitsCommandTest do
|
|||
assert s == "Clearing \"#{@limittype}\" limit for user \"#{@user}\" ..."
|
||||
end
|
||||
|
||||
test "banner: for all", context do
|
||||
|
||||
s = @command.banner(
|
||||
[@user, "all"],
|
||||
context[:opts]
|
||||
)
|
||||
|
||||
assert s == "Clearing all limits for user \"#{@user}\" ..."
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ defmodule SetUserLimitsCommandTest do
|
|||
@password "password"
|
||||
@conn_definition "{\"max-connections\":100}"
|
||||
@channel_definition "{\"max-channels\":200}"
|
||||
@definition "{\"max-connections\":50, \"max-channels\":500}"
|
||||
|
||||
setup_all do
|
||||
RabbitMQ.CLI.Core.Distribution.start()
|
||||
|
|
@ -86,6 +87,16 @@ defmodule SetUserLimitsCommandTest do
|
|||
assert_limits(context, @channel_definition)
|
||||
end
|
||||
|
||||
test "run: a well-formed command to set both max-connections and max-channels returns okay", context do
|
||||
assert @command.run(
|
||||
[context[:user],
|
||||
@definition],
|
||||
context[:opts]
|
||||
) == :ok
|
||||
|
||||
assert_limits(context, @definition)
|
||||
end
|
||||
|
||||
test "run: an unreachable node throws a badrpc" do
|
||||
opts = %{node: :jake@thedog, timeout: 200}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue