Interrupting parent on error
This commit is contained in:
211
test/secrets/bitwarden_adapter_test.rb
Normal file
211
test/secrets/bitwarden_adapter_test.rb
Normal file
@@ -0,0 +1,211 @@
|
||||
require "test_helper"
|
||||
|
||||
class BitwardenAdapterTest < SecretAdapterTestCase
|
||||
test "fetch" do
|
||||
stub_unlocked
|
||||
stub_ticks.with("bw sync").returns("")
|
||||
stub_mypassword
|
||||
|
||||
json = JSON.parse(shellunescape(run_command("fetch", "mypassword")))
|
||||
|
||||
expected_json = { "mypassword"=>"secret123" }
|
||||
|
||||
assert_equal expected_json, json
|
||||
end
|
||||
|
||||
test "fetch with from" do
|
||||
stub_unlocked
|
||||
stub_ticks.with("bw sync").returns("")
|
||||
stub_myitem
|
||||
|
||||
json = JSON.parse(shellunescape(run_command("fetch", "--from", "myitem", "field1", "field2", "field3")))
|
||||
|
||||
expected_json = {
|
||||
"myitem/field1"=>"secret1", "myitem/field2"=>"blam", "myitem/field3"=>"fewgrwjgk"
|
||||
}
|
||||
|
||||
assert_equal expected_json, json
|
||||
end
|
||||
|
||||
test "fetch with multiple items" do
|
||||
stub_unlocked
|
||||
|
||||
stub_ticks.with("bw sync").returns("")
|
||||
stub_mypassword
|
||||
stub_myitem
|
||||
|
||||
stub_ticks
|
||||
.with("bw get item myitem2")
|
||||
.returns(<<~JSON)
|
||||
{
|
||||
"passwordHistory":null,
|
||||
"revisionDate":"2024-08-29T13:46:53.343Z",
|
||||
"creationDate":"2024-08-29T12:02:31.156Z",
|
||||
"deletedDate":null,
|
||||
"object":"item",
|
||||
"id":"aaaaaaaa-cccc-eeee-0000-222222222222",
|
||||
"organizationId":null,
|
||||
"folderId":null,
|
||||
"type":1,
|
||||
"reprompt":0,
|
||||
"name":"myitem2",
|
||||
"notes":null,
|
||||
"favorite":false,
|
||||
"fields":[
|
||||
{"name":"field3","value":"fewgrwjgk","type":1,"linkedId":null}
|
||||
],
|
||||
"login":{"fido2Credentials":[],"uris":[],"username":null,"password":null,"totp":null,"passwordRevisionDate":null},"collectionIds":[]
|
||||
}
|
||||
JSON
|
||||
|
||||
|
||||
json = JSON.parse(shellunescape(run_command("fetch", "mypassword", "myitem/field1", "myitem/field2", "myitem2/field3")))
|
||||
|
||||
expected_json = {
|
||||
"mypassword"=>"secret123", "myitem/field1"=>"secret1", "myitem/field2"=>"blam", "myitem2/field3"=>"fewgrwjgk"
|
||||
}
|
||||
|
||||
assert_equal expected_json, json
|
||||
end
|
||||
|
||||
test "fetch unauthenticated" do
|
||||
stub_ticks
|
||||
.with("bw status")
|
||||
.returns(
|
||||
'{"serverUrl":null,"lastSync":null,"status":"unauthenticated"}',
|
||||
'{"serverUrl":null,"lastSync":"2024-09-04T10:11:12.433Z","userEmail":"email@example.com","userId":"aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee","status":"locked"}',
|
||||
'{"serverUrl":null,"lastSync":"2024-09-04T10:11:12.433Z","userEmail":"email@example.com","userId":"aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee","status":"unlocked"}'
|
||||
)
|
||||
|
||||
stub_ticks.with("bw login email@example.com").returns("1234567890")
|
||||
stub_ticks.with("bw unlock --raw").returns("")
|
||||
stub_ticks.with("bw sync").returns("")
|
||||
stub_mypassword
|
||||
|
||||
json = JSON.parse(shellunescape(run_command("fetch", "mypassword")))
|
||||
|
||||
expected_json = { "mypassword"=>"secret123" }
|
||||
|
||||
assert_equal expected_json, json
|
||||
end
|
||||
|
||||
test "fetch locked" do
|
||||
stub_ticks
|
||||
.with("bw status")
|
||||
.returns(
|
||||
'{"serverUrl":null,"lastSync":"2024-09-04T10:11:12.433Z","userEmail":"email@example.com","userId":"aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee","status":"locked"}'
|
||||
)
|
||||
|
||||
stub_ticks
|
||||
.with("bw status")
|
||||
.returns(
|
||||
'{"serverUrl":null,"lastSync":"2024-09-04T10:11:12.433Z","userEmail":"email@example.com","userId":"aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee","status":"unlocked"}'
|
||||
)
|
||||
|
||||
stub_ticks.with("bw login email@example.com").returns("1234567890")
|
||||
stub_ticks.with("bw unlock --raw").returns("")
|
||||
stub_ticks.with("bw sync").returns("")
|
||||
stub_mypassword
|
||||
|
||||
json = JSON.parse(shellunescape(run_command("fetch", "mypassword")))
|
||||
|
||||
expected_json = { "mypassword"=>"secret123" }
|
||||
|
||||
assert_equal expected_json, json
|
||||
end
|
||||
|
||||
test "fetch locked with session" do
|
||||
stub_ticks
|
||||
.with("bw status")
|
||||
.returns(
|
||||
'{"serverUrl":null,"lastSync":"2024-09-04T10:11:12.433Z","userEmail":"email@example.com","userId":"aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee","status":"locked"}'
|
||||
)
|
||||
|
||||
stub_ticks
|
||||
.with("BW_SESSION=0987654321 bw status")
|
||||
.returns(
|
||||
'{"serverUrl":null,"lastSync":"2024-09-04T10:11:12.433Z","userEmail":"email@example.com","userId":"aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee","status":"unlocked"}'
|
||||
)
|
||||
|
||||
stub_ticks.with("bw login email@example.com").returns("1234567890")
|
||||
stub_ticks.with("bw unlock --raw").returns("0987654321")
|
||||
stub_ticks.with("BW_SESSION=0987654321 bw sync").returns("")
|
||||
stub_mypassword(session: "0987654321")
|
||||
|
||||
json = JSON.parse(shellunescape(run_command("fetch", "mypassword")))
|
||||
|
||||
expected_json = { "mypassword"=>"secret123" }
|
||||
|
||||
assert_equal expected_json, json
|
||||
end
|
||||
|
||||
private
|
||||
def run_command(*command)
|
||||
stdouted do
|
||||
Kamal::Cli::Secrets.start \
|
||||
[ *command,
|
||||
"-c", "test/fixtures/deploy_with_accessories.yml",
|
||||
"--adapter", "bitwarden",
|
||||
"--account", "email@example.com" ]
|
||||
end
|
||||
end
|
||||
|
||||
def stub_unlocked
|
||||
stub_ticks
|
||||
.with("bw status")
|
||||
.returns(<<~JSON)
|
||||
{"serverUrl":null,"lastSync":"2024-09-04T10:11:12.433Z","userEmail":"email@example.com","userId":"aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee","status":"unlocked"}
|
||||
JSON
|
||||
end
|
||||
|
||||
def stub_mypassword(session: nil)
|
||||
stub_ticks
|
||||
.with("#{"BW_SESSION=#{session} " if session}bw get item mypassword")
|
||||
.returns(<<~JSON)
|
||||
{
|
||||
"passwordHistory":null,
|
||||
"revisionDate":"2024-08-29T13:46:53.343Z",
|
||||
"creationDate":"2024-08-29T12:02:31.156Z",
|
||||
"deletedDate":null,
|
||||
"object":"item",
|
||||
"id":"aaaaaaaa-cccc-eeee-0000-222222222222",
|
||||
"organizationId":null,
|
||||
"folderId":null,
|
||||
"type":1,
|
||||
"reprompt":0,
|
||||
"name":"mypassword",
|
||||
"notes":null,
|
||||
"favorite":false,
|
||||
"login":{"fido2Credentials":[],"uris":[],"username":null,"password":"secret123","totp":null,"passwordRevisionDate":null},"collectionIds":[]
|
||||
}
|
||||
JSON
|
||||
end
|
||||
|
||||
def stub_myitem
|
||||
stub_ticks
|
||||
.with("bw get item myitem")
|
||||
.returns(<<~JSON)
|
||||
{
|
||||
"passwordHistory":null,
|
||||
"revisionDate":"2024-08-29T13:46:53.343Z",
|
||||
"creationDate":"2024-08-29T12:02:31.156Z",
|
||||
"deletedDate":null,
|
||||
"object":"item",
|
||||
"id":"aaaaaaaa-cccc-eeee-0000-222222222222",
|
||||
"organizationId":null,
|
||||
"folderId":null,
|
||||
"type":1,
|
||||
"reprompt":0,
|
||||
"name":"myitem",
|
||||
"notes":null,
|
||||
"favorite":false,
|
||||
"fields":[
|
||||
{"name":"field1","value":"secret1","type":1,"linkedId":null},
|
||||
{"name":"field2","value":"blam","type":1,"linkedId":null},
|
||||
{"name":"field3","value":"fewgrwjgk","type":1,"linkedId":null}
|
||||
],
|
||||
"login":{"fido2Credentials":[],"uris":[],"username":null,"password":null,"totp":null,"passwordRevisionDate":null},"collectionIds":[]
|
||||
}
|
||||
JSON
|
||||
end
|
||||
end
|
||||
152
test/secrets/last_pass_adapter_test.rb
Normal file
152
test/secrets/last_pass_adapter_test.rb
Normal file
@@ -0,0 +1,152 @@
|
||||
require "test_helper"
|
||||
|
||||
class LastPassAdapterTest < SecretAdapterTestCase
|
||||
setup do
|
||||
`true` # Ensure $? is 0
|
||||
end
|
||||
|
||||
test "fetch" do
|
||||
stub_ticks.with("lpass status --color never").returns("Logged in as email@example.com.")
|
||||
|
||||
stub_ticks
|
||||
.with("lpass show SECRET1 FOLDER1/FSECRET1 FOLDER1/FSECRET2 --json")
|
||||
.returns(<<~JSON)
|
||||
[
|
||||
{
|
||||
"id": "1234567891234567891",
|
||||
"name": "SECRET1",
|
||||
"fullname": "SECRET1",
|
||||
"username": "",
|
||||
"password": "secret1",
|
||||
"last_modified_gmt": "1724926054",
|
||||
"last_touch": "1724926639",
|
||||
"group": "",
|
||||
"url": "",
|
||||
"note": ""
|
||||
},
|
||||
{
|
||||
"id": "1234567891234567892",
|
||||
"name": "FSECRET1",
|
||||
"fullname": "FOLDER1/FSECRET1",
|
||||
"username": "",
|
||||
"password": "fsecret1",
|
||||
"last_modified_gmt": "1724926084",
|
||||
"last_touch": "1724926635",
|
||||
"group": "Folder",
|
||||
"url": "",
|
||||
"note": ""
|
||||
},
|
||||
{
|
||||
"id": "1234567891234567893",
|
||||
"name": "FSECRET2",
|
||||
"fullname": "FOLDER1/FSECRET2",
|
||||
"username": "",
|
||||
"password": "fsecret2",
|
||||
"last_modified_gmt": "1724926084",
|
||||
"last_touch": "1724926635",
|
||||
"group": "Folder",
|
||||
"url": "",
|
||||
"note": ""
|
||||
}
|
||||
]
|
||||
JSON
|
||||
|
||||
json = JSON.parse(shellunescape(run_command("fetch", "SECRET1", "FOLDER1/FSECRET1", "FOLDER1/FSECRET2")))
|
||||
|
||||
expected_json = {
|
||||
"SECRET1"=>"secret1",
|
||||
"FOLDER1/FSECRET1"=>"fsecret1",
|
||||
"FOLDER1/FSECRET2"=>"fsecret2"
|
||||
}
|
||||
|
||||
assert_equal expected_json, json
|
||||
end
|
||||
|
||||
test "fetch with from" do
|
||||
stub_ticks.with("lpass status --color never").returns("Logged in as email@example.com.")
|
||||
|
||||
stub_ticks
|
||||
.with("lpass show FOLDER1/FSECRET1 FOLDER1/FSECRET2 --json")
|
||||
.returns(<<~JSON)
|
||||
[
|
||||
{
|
||||
"id": "1234567891234567892",
|
||||
"name": "FSECRET1",
|
||||
"fullname": "FOLDER1/FSECRET1",
|
||||
"username": "",
|
||||
"password": "fsecret1",
|
||||
"last_modified_gmt": "1724926084",
|
||||
"last_touch": "1724926635",
|
||||
"group": "Folder",
|
||||
"url": "",
|
||||
"note": ""
|
||||
},
|
||||
{
|
||||
"id": "1234567891234567893",
|
||||
"name": "FSECRET2",
|
||||
"fullname": "FOLDER1/FSECRET2",
|
||||
"username": "",
|
||||
"password": "fsecret2",
|
||||
"last_modified_gmt": "1724926084",
|
||||
"last_touch": "1724926635",
|
||||
"group": "Folder",
|
||||
"url": "",
|
||||
"note": ""
|
||||
}
|
||||
]
|
||||
JSON
|
||||
|
||||
json = JSON.parse(shellunescape(run_command("fetch", "--from", "FOLDER1", "FSECRET1", "FSECRET2")))
|
||||
|
||||
expected_json = {
|
||||
"FOLDER1/FSECRET1"=>"fsecret1",
|
||||
"FOLDER1/FSECRET2"=>"fsecret2"
|
||||
}
|
||||
|
||||
assert_equal expected_json, json
|
||||
end
|
||||
|
||||
test "fetch with signin" do
|
||||
stub_ticks_with("lpass status --color never", succeed: false).returns("Not logged in.")
|
||||
stub_ticks_with("lpass login email@example.com", succeed: true).returns("")
|
||||
stub_ticks.with("lpass show SECRET1 --json").returns(single_item_json)
|
||||
|
||||
json = JSON.parse(shellunescape(run_command("fetch", "SECRET1")))
|
||||
|
||||
expected_json = {
|
||||
"SECRET1"=>"secret1"
|
||||
}
|
||||
|
||||
assert_equal expected_json, json
|
||||
end
|
||||
|
||||
private
|
||||
def run_command(*command)
|
||||
stdouted do
|
||||
Kamal::Cli::Secrets.start \
|
||||
[ *command,
|
||||
"-c", "test/fixtures/deploy_with_accessories.yml",
|
||||
"--adapter", "lastpass",
|
||||
"--account", "email@example.com" ]
|
||||
end
|
||||
end
|
||||
|
||||
def single_item_json
|
||||
<<~JSON
|
||||
[
|
||||
{
|
||||
"id": "1234567891234567891",
|
||||
"name": "SECRET1",
|
||||
"fullname": "SECRET1",
|
||||
"username": "",
|
||||
"password": "secret1",
|
||||
"last_modified_gmt": "1724926054",
|
||||
"last_touch": "1724926639",
|
||||
"group": "",
|
||||
"url": "",
|
||||
"note": ""
|
||||
}
|
||||
]
|
||||
JSON
|
||||
end
|
||||
end
|
||||
@@ -1,24 +1,11 @@
|
||||
require "test_helper"
|
||||
|
||||
class SecretsOnePasswordAdapterTest < ActiveSupport::TestCase
|
||||
test "login" do
|
||||
`true` # Ensure $? is 0
|
||||
Object.any_instance.stubs(:`).with("op signin --account \"myaccount\" --force --raw").returns("Logged in")
|
||||
|
||||
assert_equal "Logged in", run_command("login")
|
||||
end
|
||||
|
||||
class SecretsOnePasswordAdapterTest < SecretAdapterTestCase
|
||||
test "fetch" do
|
||||
`true` # Ensure $? is 0
|
||||
Object.any_instance.stubs(:`).with("op read op://vault/item/section/foo --account \"myaccount\"").returns("bar")
|
||||
stub_ticks.with("op account get --account myaccount")
|
||||
|
||||
assert_equal "bar", run_command("fetch", "op://vault/item/section/foo")
|
||||
end
|
||||
|
||||
test "fetch_all" do
|
||||
`true` # Ensure $? is 0
|
||||
Object.any_instance.stubs(:`)
|
||||
.with("op item get item --vault \"vault\" --fields \"label=section.SECRET1,label=section.SECRET2\" --format \"json\" --account \"myaccount\"")
|
||||
stub_ticks
|
||||
.with("op item get myitem --vault \"myvault\" --fields \"label=section.SECRET1,label=section.SECRET2,label=section2.SECRET3\" --format \"json\" --account \"myaccount\"")
|
||||
.returns(<<~JSON)
|
||||
[
|
||||
{
|
||||
@@ -30,7 +17,7 @@ class SecretsOnePasswordAdapterTest < ActiveSupport::TestCase
|
||||
"type": "CONCEALED",
|
||||
"label": "SECRET1",
|
||||
"value": "VALUE1",
|
||||
"reference": "op://vault/item/section/SECRET1"
|
||||
"reference": "op://myvault/myitem/section/SECRET1"
|
||||
},
|
||||
{
|
||||
"id": "bbbbbbbbbbbbbbbbbbbbbbbbbb",
|
||||
@@ -41,12 +28,124 @@ class SecretsOnePasswordAdapterTest < ActiveSupport::TestCase
|
||||
"type": "CONCEALED",
|
||||
"label": "SECRET2",
|
||||
"value": "VALUE2",
|
||||
"reference": "op://vault/item/section/SECRET2"
|
||||
"reference": "op://myvault/myitem/section/SECRET2"
|
||||
},
|
||||
{
|
||||
"id": "bbbbbbbbbbbbbbbbbbbbbbbbbb",
|
||||
"section": {
|
||||
"id": "dddddddddddddddddddddddddd",
|
||||
"label": "section2"
|
||||
},
|
||||
"type": "CONCEALED",
|
||||
"label": "SECRET3",
|
||||
"value": "VALUE3",
|
||||
"reference": "op://myvault/myitem/section2/SECRET3"
|
||||
}
|
||||
]
|
||||
JSON
|
||||
|
||||
assert_equal "bar", run_command("fetch_all", "op://vault/item/section/SECRET1", "op://vault/item/section/SECRET2")
|
||||
json = JSON.parse(shellunescape(run_command("fetch", "--from", "op://myvault/myitem", "section/SECRET1", "section/SECRET2", "section2/SECRET3")))
|
||||
|
||||
expected_json = {
|
||||
"myvault/myitem/section/SECRET1"=>"VALUE1",
|
||||
"myvault/myitem/section/SECRET2"=>"VALUE2",
|
||||
"myvault/myitem/section2/SECRET3"=>"VALUE3"
|
||||
}
|
||||
|
||||
assert_equal expected_json, json
|
||||
end
|
||||
|
||||
test "fetch with multiple items" do
|
||||
stub_ticks.with("op account get --account myaccount")
|
||||
|
||||
stub_ticks
|
||||
.with("op item get myitem --vault \"myvault\" --fields \"label=section.SECRET1,label=section.SECRET2\" --format \"json\" --account \"myaccount\"")
|
||||
.returns(<<~JSON)
|
||||
[
|
||||
{
|
||||
"id": "aaaaaaaaaaaaaaaaaaaaaaaaaa",
|
||||
"section": {
|
||||
"id": "cccccccccccccccccccccccccc",
|
||||
"label": "section"
|
||||
},
|
||||
"type": "CONCEALED",
|
||||
"label": "SECRET1",
|
||||
"value": "VALUE1",
|
||||
"reference": "op://myvault/myitem/section/SECRET1"
|
||||
},
|
||||
{
|
||||
"id": "bbbbbbbbbbbbbbbbbbbbbbbbbb",
|
||||
"section": {
|
||||
"id": "dddddddddddddddddddddddddd",
|
||||
"label": "section"
|
||||
},
|
||||
"type": "CONCEALED",
|
||||
"label": "SECRET2",
|
||||
"value": "VALUE2",
|
||||
"reference": "op://myvault/myitem/section/SECRET2"
|
||||
}
|
||||
]
|
||||
JSON
|
||||
|
||||
stub_ticks
|
||||
.with("op item get myitem2 --vault \"myvault\" --fields \"label=section2.SECRET3\" --format \"json\" --account \"myaccount\"")
|
||||
.returns(<<~JSON)
|
||||
{
|
||||
"id": "aaaaaaaaaaaaaaaaaaaaaaaaaa",
|
||||
"section": {
|
||||
"id": "cccccccccccccccccccccccccc",
|
||||
"label": "section"
|
||||
},
|
||||
"type": "CONCEALED",
|
||||
"label": "SECRET3",
|
||||
"value": "VALUE3",
|
||||
"reference": "op://myvault/myitem2/section/SECRET3"
|
||||
}
|
||||
JSON
|
||||
|
||||
json = JSON.parse(shellunescape(run_command("fetch", "--from", "op://myvault", "myitem/section/SECRET1", "myitem/section/SECRET2", "myitem2/section2/SECRET3")))
|
||||
|
||||
expected_json = {
|
||||
"myvault/myitem/section/SECRET1"=>"VALUE1",
|
||||
"myvault/myitem/section/SECRET2"=>"VALUE2",
|
||||
"myvault/myitem2/section/SECRET3"=>"VALUE3"
|
||||
}
|
||||
|
||||
assert_equal expected_json, json
|
||||
end
|
||||
|
||||
test "fetch with signin, no session" do
|
||||
stub_ticks_with("op account get --account myaccount", succeed: false)
|
||||
stub_ticks_with("op signin --account \"myaccount\" --force --raw", succeed: true).returns("")
|
||||
|
||||
stub_ticks
|
||||
.with("op item get myitem --vault \"myvault\" --fields \"label=section.SECRET1\" --format \"json\" --account \"myaccount\"")
|
||||
.returns(single_item_json)
|
||||
|
||||
json = JSON.parse(shellunescape(run_command("fetch", "--from", "op://myvault/myitem", "section/SECRET1")))
|
||||
|
||||
expected_json = {
|
||||
"myvault/myitem/section/SECRET1"=>"VALUE1"
|
||||
}
|
||||
|
||||
assert_equal expected_json, json
|
||||
end
|
||||
|
||||
test "fetch with signin and session" do
|
||||
stub_ticks_with("op account get --account myaccount", succeed: false)
|
||||
stub_ticks_with("op signin --account \"myaccount\" --force --raw", succeed: true).returns("1234567890")
|
||||
|
||||
stub_ticks
|
||||
.with("op item get myitem --vault \"myvault\" --fields \"label=section.SECRET1\" --format \"json\" --account \"myaccount\" --session \"1234567890\"")
|
||||
.returns(single_item_json)
|
||||
|
||||
json = JSON.parse(shellunescape(run_command("fetch", "--from", "op://myvault/myitem", "section/SECRET1")))
|
||||
|
||||
expected_json = {
|
||||
"myvault/myitem/section/SECRET1"=>"VALUE1"
|
||||
}
|
||||
|
||||
assert_equal expected_json, json
|
||||
end
|
||||
|
||||
private
|
||||
@@ -56,7 +155,23 @@ class SecretsOnePasswordAdapterTest < ActiveSupport::TestCase
|
||||
[ *command,
|
||||
"-c", "test/fixtures/deploy_with_accessories.yml",
|
||||
"--adapter", "1password",
|
||||
"--adapter-options", "account:myaccount" ]
|
||||
"--account", "myaccount" ]
|
||||
end
|
||||
end
|
||||
|
||||
def single_item_json
|
||||
<<~JSON
|
||||
{
|
||||
"id": "aaaaaaaaaaaaaaaaaaaaaaaaaa",
|
||||
"section": {
|
||||
"id": "cccccccccccccccccccccccccc",
|
||||
"label": "section"
|
||||
},
|
||||
"type": "CONCEALED",
|
||||
"label": "SECRET1",
|
||||
"value": "VALUE1",
|
||||
"reference": "op://myvault/myitem/section/SECRET1"
|
||||
}
|
||||
JSON
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user