-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Validation tests for the new command
(cherry picked from commit 9dc8994)
- Loading branch information
1 parent
e6b073e
commit b5c9064
Showing
1 changed file
with
83 additions
and
0 deletions.
There are no files selected for viewing
83 changes: 83 additions & 0 deletions
83
deps/rabbitmq_cli/test/ctl/decrypt_conf_value_command_test.exs
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,83 @@ | ||
## 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) 2007-2024 Broadcom. All Rights Reserved. The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. All rights reserved. | ||
|
||
defmodule DecryptConfValueCommandTest do | ||
use ExUnit.Case, async: false | ||
@command RabbitMQ.CLI.Ctl.Commands.DecryptConfValueCommand | ||
|
||
setup _context do | ||
{:ok, | ||
opts: %{ | ||
cipher: :rabbit_pbe.default_cipher(), | ||
hash: :rabbit_pbe.default_hash(), | ||
iterations: :rabbit_pbe.default_iterations() | ||
}} | ||
end | ||
|
||
test "validate: providing exactly 2 positional arguments passes", context do | ||
assert :ok == @command.validate(["value", "secret"], context[:opts]) | ||
end | ||
|
||
test "validate: providing no positional arguments fails", context do | ||
assert match?( | ||
{:validation_failure, {:not_enough_args, _}}, | ||
@command.validate([], context[:opts]) | ||
) | ||
end | ||
|
||
test "validate: providing one positional argument passes", context do | ||
assert :ok == @command.validate(["value"], context[:opts]) | ||
end | ||
|
||
test "validate: providing three or more positional argument fails", context do | ||
assert match?( | ||
{:validation_failure, :too_many_args}, | ||
@command.validate(["value", "secret", "incorrect"], context[:opts]) | ||
) | ||
end | ||
|
||
test "validate: hash and cipher must be supported", context do | ||
assert match?( | ||
{:validation_failure, {:bad_argument, _}}, | ||
@command.validate( | ||
["value", "secret"], | ||
Map.merge(context[:opts], %{cipher: :funny_cipher}) | ||
) | ||
) | ||
|
||
assert match?( | ||
{:validation_failure, {:bad_argument, _}}, | ||
@command.validate( | ||
["value", "secret"], | ||
Map.merge(context[:opts], %{hash: :funny_hash}) | ||
) | ||
) | ||
|
||
assert match?( | ||
{:validation_failure, {:bad_argument, _}}, | ||
@command.validate( | ||
["value", "secret"], | ||
Map.merge(context[:opts], %{cipher: :funny_cipher, hash: :funny_hash}) | ||
) | ||
) | ||
|
||
assert :ok == @command.validate(["value", "secret"], context[:opts]) | ||
end | ||
|
||
test "validate: number of iterations must greater than 0", context do | ||
assert match?( | ||
{:validation_failure, {:bad_argument, _}}, | ||
@command.validate(["value", "secret"], Map.merge(context[:opts], %{iterations: 0})) | ||
) | ||
|
||
assert match?( | ||
{:validation_failure, {:bad_argument, _}}, | ||
@command.validate(["value", "secret"], Map.merge(context[:opts], %{iterations: -1})) | ||
) | ||
|
||
assert :ok == @command.validate(["value", "secret"], context[:opts]) | ||
end | ||
end |