Merge pull request #995 from honzasterba/bw_nicer_error_message_on_non_field_fetch
[bitwarden] default fetch raises NoMethodError
This commit is contained in:
@@ -35,8 +35,10 @@ class Kamal::Secrets::Adapters::Bitwarden < Kamal::Secrets::Adapters::Base
|
|||||||
value = item_field["value"]
|
value = item_field["value"]
|
||||||
results["#{item}/#{field}"] = value
|
results["#{item}/#{field}"] = value
|
||||||
end
|
end
|
||||||
|
elsif item_json.dig("login", "password")
|
||||||
|
results[item] = item_json.dig("login", "password")
|
||||||
else
|
else
|
||||||
results[item] = item_json["login"]["password"]
|
raise RuntimeError, "Item #{item} is not a login type item and no fields were specified"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -13,6 +13,17 @@ class BitwardenAdapterTest < SecretAdapterTestCase
|
|||||||
assert_equal expected_json, json
|
assert_equal expected_json, json
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "fetch with no login" do
|
||||||
|
stub_unlocked
|
||||||
|
stub_ticks.with("bw sync").returns("")
|
||||||
|
stub_noteitem
|
||||||
|
|
||||||
|
error = assert_raises RuntimeError do
|
||||||
|
JSON.parse(shellunescape(run_command("fetch", "mynote")))
|
||||||
|
end
|
||||||
|
assert_match(/not a login type item/, error.message)
|
||||||
|
end
|
||||||
|
|
||||||
test "fetch with from" do
|
test "fetch with from" do
|
||||||
stub_unlocked
|
stub_unlocked
|
||||||
stub_ticks.with("bw sync").returns("")
|
stub_ticks.with("bw sync").returns("")
|
||||||
@@ -181,6 +192,30 @@ class BitwardenAdapterTest < SecretAdapterTestCase
|
|||||||
JSON
|
JSON
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def stub_noteitem(session: nil)
|
||||||
|
stub_ticks
|
||||||
|
.with("#{"BW_SESSION=#{session} " if session}bw get item mynote")
|
||||||
|
.returns(<<~JSON)
|
||||||
|
{
|
||||||
|
"passwordHistory":null,
|
||||||
|
"revisionDate":"2024-09-28T09:07:27.461Z",
|
||||||
|
"creationDate":"2024-09-28T09:07:00.740Z",
|
||||||
|
"deletedDate":null,
|
||||||
|
"object":"item",
|
||||||
|
"id":"aaaaaaaa-cccc-eeee-0000-222222222222",
|
||||||
|
"organizationId":null,
|
||||||
|
"folderId":null,
|
||||||
|
"type":2,
|
||||||
|
"reprompt":0,
|
||||||
|
"name":"noteitem",
|
||||||
|
"notes":"NOTES",
|
||||||
|
"favorite":false,
|
||||||
|
"secureNote":{"type":0},
|
||||||
|
"collectionIds":[]
|
||||||
|
}
|
||||||
|
JSON
|
||||||
|
end
|
||||||
|
|
||||||
def stub_myitem
|
def stub_myitem
|
||||||
stub_ticks
|
stub_ticks
|
||||||
.with("bw get item myitem")
|
.with("bw get item myitem")
|
||||||
|
|||||||
Reference in New Issue
Block a user