Skip to content

Commit 9dc8994

Browse files
Validation tests for the new command
1 parent e1490c6 commit 9dc8994

File tree

1 file changed

+83
-0
lines changed

1 file changed

+83
-0
lines changed
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
## This Source Code Form is subject to the terms of the Mozilla Public
2+
## License, v. 2.0. If a copy of the MPL was not distributed with this
3+
## file, You can obtain one at https://mozilla.org/MPL/2.0/.
4+
##
5+
## Copyright (c) 2007-2024 Broadcom. All Rights Reserved. The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. All rights reserved.
6+
7+
defmodule DecryptConfValueCommandTest do
8+
use ExUnit.Case, async: false
9+
@command RabbitMQ.CLI.Ctl.Commands.DecryptConfValueCommand
10+
11+
setup _context do
12+
{:ok,
13+
opts: %{
14+
cipher: :rabbit_pbe.default_cipher(),
15+
hash: :rabbit_pbe.default_hash(),
16+
iterations: :rabbit_pbe.default_iterations()
17+
}}
18+
end
19+
20+
test "validate: providing exactly 2 positional arguments passes", context do
21+
assert :ok == @command.validate(["value", "secret"], context[:opts])
22+
end
23+
24+
test "validate: providing no positional arguments fails", context do
25+
assert match?(
26+
{:validation_failure, {:not_enough_args, _}},
27+
@command.validate([], context[:opts])
28+
)
29+
end
30+
31+
test "validate: providing one positional argument passes", context do
32+
assert :ok == @command.validate(["value"], context[:opts])
33+
end
34+
35+
test "validate: providing three or more positional argument fails", context do
36+
assert match?(
37+
{:validation_failure, :too_many_args},
38+
@command.validate(["value", "secret", "incorrect"], context[:opts])
39+
)
40+
end
41+
42+
test "validate: hash and cipher must be supported", context do
43+
assert match?(
44+
{:validation_failure, {:bad_argument, _}},
45+
@command.validate(
46+
["value", "secret"],
47+
Map.merge(context[:opts], %{cipher: :funny_cipher})
48+
)
49+
)
50+
51+
assert match?(
52+
{:validation_failure, {:bad_argument, _}},
53+
@command.validate(
54+
["value", "secret"],
55+
Map.merge(context[:opts], %{hash: :funny_hash})
56+
)
57+
)
58+
59+
assert match?(
60+
{:validation_failure, {:bad_argument, _}},
61+
@command.validate(
62+
["value", "secret"],
63+
Map.merge(context[:opts], %{cipher: :funny_cipher, hash: :funny_hash})
64+
)
65+
)
66+
67+
assert :ok == @command.validate(["value", "secret"], context[:opts])
68+
end
69+
70+
test "validate: number of iterations must greater than 0", context do
71+
assert match?(
72+
{:validation_failure, {:bad_argument, _}},
73+
@command.validate(["value", "secret"], Map.merge(context[:opts], %{iterations: 0}))
74+
)
75+
76+
assert match?(
77+
{:validation_failure, {:bad_argument, _}},
78+
@command.validate(["value", "secret"], Map.merge(context[:opts], %{iterations: -1}))
79+
)
80+
81+
assert :ok == @command.validate(["value", "secret"], context[:opts])
82+
end
83+
end

0 commit comments

Comments
 (0)