Move rabbit_password to rabbit_common
This allows `rabbitmqctl hash_password` to run without having RabbitMQ up. Follow-up to: * #5957 * #7003
This commit is contained in:
parent
39dbbd469a
commit
d9d6e1bef6
|
|
@ -6,7 +6,6 @@
|
|||
%%
|
||||
|
||||
-module(rabbit_password).
|
||||
-include_lib("rabbit_common/include/rabbit.hrl").
|
||||
|
||||
-define(DEFAULT_HASHING_MODULE, rabbit_password_hashing_sha256).
|
||||
|
||||
|
|
@ -0,0 +1,47 @@
|
|||
%% 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/.
|
||||
%%
|
||||
%% Copyright (c) 2011-2023 VMware, Inc. or its affiliates. All rights reserved.
|
||||
%%
|
||||
|
||||
-module(unit_password_hashing_SUITE).
|
||||
|
||||
-compile(export_all).
|
||||
|
||||
all() -> [password_hashing].
|
||||
|
||||
%% -------------------------------------------------------------------
|
||||
%% Testsuite setup/teardown
|
||||
%% -------------------------------------------------------------------
|
||||
|
||||
init_per_suite(Config) -> Config.
|
||||
end_per_suite(Config) -> Config.
|
||||
|
||||
init_per_group(_Group, Config) -> Config.
|
||||
end_per_group(_Group, Config) -> Config.
|
||||
|
||||
init_per_testcase(_Testcase, Config) -> Config.
|
||||
end_per_testcase(_Testcase, Config) -> Config.
|
||||
|
||||
%% ---------------------------------------------------------------------------
|
||||
%% Test Cases
|
||||
%% ---------------------------------------------------------------------------
|
||||
|
||||
password_hashing(_Config) ->
|
||||
rabbit_password_hashing_sha256 = rabbit_password:hashing_mod(),
|
||||
application:set_env(rabbit, password_hashing_module,
|
||||
rabbit_password_hashing_md5),
|
||||
rabbit_password_hashing_md5 = rabbit_password:hashing_mod(),
|
||||
application:set_env(rabbit, password_hashing_module,
|
||||
rabbit_password_hashing_sha256),
|
||||
rabbit_password_hashing_sha256 = rabbit_password:hashing_mod(),
|
||||
|
||||
rabbit_password_hashing_sha256 =
|
||||
rabbit_password:hashing_mod(rabbit_password_hashing_sha256),
|
||||
rabbit_password_hashing_md5 =
|
||||
rabbit_password:hashing_mod(rabbit_password_hashing_md5),
|
||||
rabbit_password_hashing_md5 =
|
||||
rabbit_password:hashing_mod(undefined),
|
||||
|
||||
passed.
|
||||
|
|
@ -5,7 +5,7 @@
|
|||
## Copyright (c) 2016-2023 VMware, Inc. or its affiliates. All rights reserved.
|
||||
|
||||
defmodule RabbitMQ.CLI.Core.Distribution do
|
||||
alias RabbitMQ.CLI.Core.{ANSI, Config, Helpers}
|
||||
alias RabbitMQ.CLI.Core.{Config, Helpers}
|
||||
|
||||
#
|
||||
# API
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
## Copyright (c) 2007-2023 VMware, Inc. or its affiliates. All rights reserved.
|
||||
|
||||
defmodule RabbitMQ.CLI.Ctl.Commands.AddVhostCommand do
|
||||
alias RabbitMQ.CLI.Core.{DocGuide, ExitCodes, FeatureFlags, Helpers}
|
||||
alias RabbitMQ.CLI.Core.{DocGuide, ExitCodes, Helpers}
|
||||
|
||||
@behaviour RabbitMQ.CLI.CommandBehaviour
|
||||
|
||||
|
|
|
|||
|
|
@ -6,32 +6,27 @@
|
|||
|
||||
defmodule RabbitMQ.CLI.Ctl.Commands.HashPasswordCommand do
|
||||
alias RabbitMQ.CLI.Core.{Input}
|
||||
|
||||
@behaviour RabbitMQ.CLI.CommandBehaviour
|
||||
use RabbitMQ.CLI.Core.MergesNoDefaults
|
||||
use RabbitMQ.CLI.DefaultOutput
|
||||
|
||||
def run([cleartextpassword], %{node: node_name}) do
|
||||
hash_password(cleartextpassword, node_name)
|
||||
def run([cleartextpassword], _opts) do
|
||||
hash_password(cleartextpassword)
|
||||
end
|
||||
|
||||
def run([], %{node: node_name} = opts) do
|
||||
def run([], opts) do
|
||||
case Input.infer_password("Password: ", opts) do
|
||||
:eof ->
|
||||
{:error, :not_enough_args}
|
||||
|
||||
password ->
|
||||
hash_password(password, node_name)
|
||||
hash_password(password)
|
||||
end
|
||||
end
|
||||
|
||||
def hash_password(password, node_name) do
|
||||
hashed_pwd =
|
||||
:rabbit_misc.rpc_call(
|
||||
node_name,
|
||||
:rabbit_password,
|
||||
:hash,
|
||||
[password]
|
||||
)
|
||||
|
||||
def hash_password(password) do
|
||||
hashed_pwd = :rabbit_password.hash(password)
|
||||
Base.encode64(hashed_pwd)
|
||||
end
|
||||
|
||||
|
|
@ -51,8 +46,6 @@ defmodule RabbitMQ.CLI.Ctl.Commands.HashPasswordCommand do
|
|||
:ok
|
||||
end
|
||||
|
||||
use RabbitMQ.CLI.DefaultOutput
|
||||
|
||||
def usage, do: "hash_password <cleartext_password>"
|
||||
|
||||
def banner([arg], _options),
|
||||
|
|
|
|||
Loading…
Reference in New Issue