This repository has been archived by the owner on Nov 18, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #147 from rabbitmq/rabbitmq-cli-141
Introduce `rabbitmq-diagnostics cipher_suites [--openssl-format]`
- Loading branch information
Showing
4 changed files
with
150 additions
and
10 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
lib/rabbitmq/cli/diagnostics/commands/cipher_suites_command.ex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
## The contents of this file are subject to the Mozilla Public License | ||
## Version 1.1 (the "License"); you may not use this file except in | ||
## compliance with the License. You may obtain a copy of the License | ||
## at http://www.mozilla.org/MPL/ | ||
## | ||
## Software distributed under the License is distributed on an "AS IS" | ||
## basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See | ||
## the License for the specific language governing rights and | ||
## limitations under the License. | ||
## | ||
## The Original Code is RabbitMQ. | ||
## | ||
## The Initial Developer of the Original Code is GoPivotal, Inc. | ||
## Copyright (c) 2007-2016 Pivotal Software, Inc. All rights reserved. | ||
|
||
|
||
defmodule RabbitMQ.CLI.Diagnostics.Commands.CipherSuitesCommand do | ||
@behaviour RabbitMQ.CLI.CommandBehaviour | ||
use RabbitMQ.CLI.DefaultOutput | ||
|
||
def merge_defaults(args, opts), do: {args, Map.merge(%{openssl_format: false}, opts)} | ||
|
||
def switches(), do: [openssl_format: :boolean] | ||
|
||
def validate(args, _) when length(args) > 0 do | ||
{:validation_failure, :too_many_args} | ||
end | ||
def validate(_, _), do: :ok | ||
|
||
def usage, do: "cipher_suites [--openssl-format]" | ||
|
||
def run([], %{node: node_name, timeout: timeout, openssl_format: openssl_format}) do | ||
args = case openssl_format do | ||
true -> [:openssl] | ||
false -> [] | ||
end | ||
:rabbit_misc.rpc_call(node_name, :ssl, :cipher_suites, args, timeout) | ||
end | ||
|
||
def banner([], %{openssl_format: true}), do: "Listing available cipher suites in the OpenSSL format" | ||
def banner([], %{openssl_format: false}), do: "Listing available cipher suites in the Erlang term format" | ||
|
||
def formatter(), do: RabbitMQ.CLI.Formatters.Erlang | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
## The contents of this file are subject to the Mozilla Public License | ||
## Version 1.1 (the "License"); you may not use this file except in | ||
## compliance with the License. You may obtain a copy of the License | ||
## at http://www.mozilla.org/MPL/ | ||
## | ||
## Software distributed under the License is distributed on an "AS IS" | ||
## basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See | ||
## the License for the specific language governing rights and | ||
## limitations under the License. | ||
## | ||
## The Original Code is RabbitMQ. | ||
## | ||
## The Initial Developer of the Original Code is GoPivotal, Inc. | ||
## Copyright (c) 2007-2016 Pivotal Software, Inc. All rights reserved. | ||
|
||
|
||
defmodule CipherSuitesCommandTest do | ||
use ExUnit.Case | ||
import TestHelper | ||
|
||
@command RabbitMQ.CLI.Diagnostics.Commands.CipherSuitesCommand | ||
|
||
setup_all do | ||
RabbitMQ.CLI.Core.Distribution.start() | ||
:net_kernel.connect_node(get_rabbit_hostname) | ||
|
||
on_exit([], fn -> | ||
:erlang.disconnect_node(get_rabbit_hostname) | ||
|
||
end) | ||
|
||
:ok | ||
end | ||
|
||
setup context do | ||
{:ok, opts: %{ | ||
node: get_rabbit_hostname, | ||
timeout: context[:test_timeout] || 15, | ||
openssl_format: context[:openssl_format] || false | ||
}} | ||
end | ||
|
||
test "merge_defaults: defaults to the Erlang term format (that is, non-OpenSSL)" do | ||
assert @command.merge_defaults([], %{}) == {[], %{openssl_format: false}} | ||
end | ||
|
||
test "merge_defaults: OpenSSL format can be switched on" do | ||
assert @command.merge_defaults([], %{openssl_format: true}) == {[], %{openssl_format: true}} | ||
end | ||
|
||
test "merge_defaults: OpenSSL format can be switched off" do | ||
assert @command.merge_defaults([], %{openssl_format: false}) == {[], %{openssl_format: false}} | ||
end | ||
|
||
test "validate: treats positional arguments as a failure" do | ||
assert @command.validate(["extra-arg"], %{openssl_format: false}) == {:validation_failure, :too_many_args} | ||
end | ||
|
||
test "validate: treats empty positional arguments and default switches as a success" do | ||
assert @command.validate([], %{openssl_format: false}) == :ok | ||
end | ||
|
||
test "validate: treats empty positional arguments and an OpenSSL format flag as a success" do | ||
assert @command.validate([], %{openssl_format: true}) == :ok | ||
end | ||
|
||
@tag test_timeout: 0 | ||
test "run: targeting an unreachable node throws a badrpc", context do | ||
target = :jake@thedog | ||
:net_kernel.connect_node(target) | ||
opts = %{node: target} | ||
assert @command.run([], Map.merge(context[:opts], opts)) == {:badrpc, :nodedown} | ||
end | ||
|
||
test "run: returns a list of cipher suites", context do | ||
res = @command.run([], context[:opts]) | ||
# the list is long and its values are environment-specific, | ||
# so we simply assert that it is non-empty. MK. | ||
assert length(res) > 0 | ||
end | ||
|
||
@tag openssl_format: true | ||
test "run: returns a list cipher suites in the OpenSSL format", context do | ||
res = @command.run([], context[:opts]) | ||
# see the test above | ||
assert length(res) > 0 | ||
end | ||
end |