2020-07-12 02:23:07 +08:00
|
|
|
## This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
## License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
## file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
2016-03-16 23:29:56 +08:00
|
|
|
##
|
2020-03-10 22:39:56 +08:00
|
|
|
## Copyright (c) 2007-2020 VMware, Inc. or its affiliates. All rights reserved.
|
2016-03-16 23:29:56 +08:00
|
|
|
|
|
|
|
|
|
|
|
defmodule DeleteUserCommandTest do
|
|
|
|
use ExUnit.Case, async: false
|
|
|
|
import TestHelper
|
|
|
|
|
2016-06-10 07:54:22 +08:00
|
|
|
@command RabbitMQ.CLI.Ctl.Commands.DeleteUserCommand
|
2016-05-03 23:50:06 +08:00
|
|
|
@user "username"
|
2016-03-23 00:21:12 +08:00
|
|
|
@password "password"
|
2016-03-18 00:59:55 +08:00
|
|
|
|
2016-03-16 23:29:56 +08:00
|
|
|
setup_all do
|
2016-11-15 01:52:08 +08:00
|
|
|
RabbitMQ.CLI.Core.Distribution.start()
|
2016-03-16 23:29:56 +08:00
|
|
|
:ok
|
|
|
|
end
|
|
|
|
|
|
|
|
setup context do
|
2016-03-18 00:59:55 +08:00
|
|
|
add_user(context[:user], @password)
|
2016-03-18 00:48:11 +08:00
|
|
|
on_exit(context, fn -> delete_user(context[:user]) end)
|
2016-03-16 23:29:56 +08:00
|
|
|
|
2017-01-24 20:33:48 +08:00
|
|
|
{:ok, opts: %{node: get_rabbit_hostname()}}
|
2016-03-16 23:29:56 +08:00
|
|
|
end
|
|
|
|
|
2016-05-03 23:50:06 +08:00
|
|
|
@tag user: @user
|
2016-05-24 19:33:11 +08:00
|
|
|
test "validate: argument count validates" do
|
2016-06-02 08:19:41 +08:00
|
|
|
assert @command.validate(["one"], %{}) == :ok
|
|
|
|
assert @command.validate([], %{}) == {:validation_failure, :not_enough_args}
|
|
|
|
assert @command.validate(["too", "many"], %{}) == {:validation_failure, :too_many_args}
|
2016-03-23 00:21:12 +08:00
|
|
|
end
|
|
|
|
|
2016-05-03 23:50:06 +08:00
|
|
|
@tag user: @user
|
2016-05-24 19:33:11 +08:00
|
|
|
test "run: A valid username returns ok", context do
|
2016-06-02 08:19:41 +08:00
|
|
|
assert @command.run([context[:user]], context[:opts]) == :ok
|
2016-05-03 23:50:06 +08:00
|
|
|
|
2017-02-28 23:16:54 +08:00
|
|
|
assert list_users() |> Enum.count(fn(record) -> record[:user] == context[:user] end) == 0
|
2016-03-23 00:21:12 +08:00
|
|
|
end
|
|
|
|
|
2016-05-24 19:33:11 +08:00
|
|
|
test "run: An invalid Rabbit node returns a bad rpc message" do
|
2019-04-12 06:27:15 +08:00
|
|
|
opts = %{node: :jake@thedog, timeout: 200}
|
2017-06-07 23:21:53 +08:00
|
|
|
|
2019-04-12 06:27:15 +08:00
|
|
|
assert match?({:badrpc, _}, @command.run(["username"], opts))
|
2016-05-03 23:50:06 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
@tag user: @user
|
2016-05-24 19:33:11 +08:00
|
|
|
test "run: An invalid username returns an error", context do
|
2016-06-02 08:19:41 +08:00
|
|
|
assert @command.run(["no_one"], context[:opts]) == {:error, {:no_such_user, "no_one"}}
|
2016-05-03 23:50:06 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
@tag user: @user
|
2016-05-24 19:33:11 +08:00
|
|
|
test "banner", context do
|
2016-06-02 08:19:41 +08:00
|
|
|
s = @command.banner([context[:user]], context[:opts])
|
|
|
|
assert s =~ ~r/Deleting user/
|
|
|
|
assert s =~ ~r/\"#{context[:user]}\"/
|
2016-03-23 00:21:12 +08:00
|
|
|
end
|
2016-03-16 23:29:56 +08:00
|
|
|
end
|