|
| 1 | +require "test_helper" |
| 2 | + |
| 3 | +class EnpassAdapterTest < SecretAdapterTestCase |
| 4 | + test "fetch without CLI installed" do |
| 5 | + stub_ticks_with("enpass-cli version 2> /dev/null", succeed: false) |
| 6 | + |
| 7 | + error = assert_raises RuntimeError do |
| 8 | + JSON.parse(shellunescape(run_command("fetch", "mynote"))) |
| 9 | + end |
| 10 | + |
| 11 | + assert_equal "Enpass CLI is not installed", error.message |
| 12 | + end |
| 13 | + |
| 14 | + test "fetch one item" do |
| 15 | + stub_ticks_with("enpass-cli version 2> /dev/null") |
| 16 | + |
| 17 | + stub_ticks |
| 18 | + .with("enpass-cli -json -vault vault-path show FooBar") |
| 19 | + .returns(<<~JSON) |
| 20 | + [{"category":"computer","label":"SECRET_1","login":"","password":"my-password-1","title":"FooBar","type":"password"}] |
| 21 | + JSON |
| 22 | + |
| 23 | + json = JSON.parse(shellunescape(run_command("fetch", "FooBar/SECRET_1"))) |
| 24 | + |
| 25 | + expected_json = { "FooBar/SECRET_1" => "my-password-1" } |
| 26 | + |
| 27 | + assert_equal expected_json, json |
| 28 | + end |
| 29 | + |
| 30 | + test "fetch multiple items" do |
| 31 | + stub_ticks_with("enpass-cli version 2> /dev/null") |
| 32 | + |
| 33 | + stub_ticks |
| 34 | + .with("enpass-cli -json -vault vault-path show FooBar") |
| 35 | + .returns(<<~JSON) |
| 36 | + [ |
| 37 | + {"category":"computer","label":"SECRET_1","login":"","password":"my-password-1","title":"FooBar","type":"password"}, |
| 38 | + {"category":"computer","label":"SECRET_2","login":"","password":"my-password-2","title":"FooBar","type":"password"}, |
| 39 | + {"category":"computer","label":"SECRET_3","login":"","password":"my-password-1","title":"Hello","type":"password"} |
| 40 | + ] |
| 41 | + JSON |
| 42 | + |
| 43 | + json = JSON.parse(shellunescape(run_command("fetch", "FooBar/SECRET_1", "FooBar/SECRET_2"))) |
| 44 | + |
| 45 | + expected_json = { "FooBar/SECRET_1" => "my-password-1", "FooBar/SECRET_2" => "my-password-2" } |
| 46 | + |
| 47 | + assert_equal expected_json, json |
| 48 | + end |
| 49 | + |
| 50 | + test "fetch all with from" do |
| 51 | + stub_ticks_with("enpass-cli version 2> /dev/null") |
| 52 | + |
| 53 | + stub_ticks |
| 54 | + .with("enpass-cli -json -vault vault-path show FooBar") |
| 55 | + .returns(<<~JSON) |
| 56 | + [ |
| 57 | + {"category":"computer","label":"SECRET_1","login":"","password":"my-password-1","title":"FooBar","type":"password"}, |
| 58 | + {"category":"computer","label":"SECRET_2","login":"","password":"my-password-2","title":"FooBar","type":"password"}, |
| 59 | + {"category":"computer","label":"SECRET_3","login":"","password":"my-password-1","title":"Hello","type":"password"}, |
| 60 | + {"category":"computer","label":"","login":"","password":"my-password-3","title":"FooBar","type":"password"} |
| 61 | + ] |
| 62 | + JSON |
| 63 | + |
| 64 | + json = JSON.parse(shellunescape(run_command("fetch", "FooBar"))) |
| 65 | + |
| 66 | + expected_json = { "FooBar/SECRET_1" => "my-password-1", "FooBar/SECRET_2" => "my-password-2", "FooBar" => "my-password-3" } |
| 67 | + |
| 68 | + assert_equal expected_json, json |
| 69 | + end |
| 70 | + |
| 71 | + private |
| 72 | + def run_command(*command) |
| 73 | + stdouted do |
| 74 | + Kamal::Cli::Secrets.start \ |
| 75 | + [ *command, |
| 76 | + "-c", "test/fixtures/deploy_with_accessories.yml", |
| 77 | + "--adapter", "enpass", |
| 78 | + "--from", "vault-path" ] |
| 79 | + end |
| 80 | + end |
| 81 | +end |
0 commit comments