forked from basecamp/kamal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils_test.rb
55 lines (44 loc) · 2.05 KB
/
utils_test.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
require "test_helper"
class UtilsTest < ActiveSupport::TestCase
test "argumentize" do
assert_equal [ "--label", "foo=\"\\`bar\\`\"", "--label", "baz=\"qux\"", "--label", :quux ], \
Kamal::Utils.argumentize("--label", { foo: "`bar`", baz: "qux", quux: nil })
end
test "argumentize with redacted" do
assert_kind_of SSHKit::Redaction, \
Kamal::Utils.argumentize("--label", { foo: "bar" }, sensitive: true).last
end
test "optionize" do
assert_equal [ "--foo", "\"bar\"", "--baz", "\"qux\"", "--quux" ], \
Kamal::Utils.optionize({ foo: "bar", baz: "qux", quux: true })
end
test "optionize with" do
assert_equal [ "--foo=\"bar\"", "--baz=\"qux\"", "--quux" ], \
Kamal::Utils.optionize({ foo: "bar", baz: "qux", quux: true }, with: "=")
end
test "no redaction from #to_s" do
assert_equal "secret", Kamal::Utils.sensitive("secret").to_s
end
test "redact from #inspect" do
assert_equal "[REDACTED]".inspect, Kamal::Utils.sensitive("secret").inspect
end
test "redact from SSHKit output" do
assert_kind_of SSHKit::Redaction, Kamal::Utils.sensitive("secret")
end
test "redact from YAML output" do
assert_equal "--- ! '[REDACTED]'\n", YAML.dump(Kamal::Utils.sensitive("secret"))
end
test "escape_shell_value" do
assert_equal "\"foo\"", Kamal::Utils.escape_shell_value("foo")
assert_equal "\"\\`foo\\`\"", Kamal::Utils.escape_shell_value("`foo`")
assert_equal "\"${PWD}\"", Kamal::Utils.escape_shell_value("${PWD}")
assert_equal "\"${cat /etc/hostname}\"", Kamal::Utils.escape_shell_value("${cat /etc/hostname}")
assert_equal "\"\\${PWD]\"", Kamal::Utils.escape_shell_value("${PWD]")
assert_equal "\"\\$(PWD)\"", Kamal::Utils.escape_shell_value("$(PWD)")
assert_equal "\"\\$PWD\"", Kamal::Utils.escape_shell_value("$PWD")
assert_equal "\"^(https?://)www.example.com/(.*)\\$\"",
Kamal::Utils.escape_shell_value("^(https?://)www.example.com/(.*)$")
assert_equal "\"https://example.com/\\$2\"",
Kamal::Utils.escape_shell_value("https://example.com/$2")
end
end