From 312910bdb71fd50c2a0e6556b6159e35c6e3eda5 Mon Sep 17 00:00:00 2001 From: Eddy Filip Date: Sat, 8 Jan 2022 16:20:08 +0200 Subject: [PATCH 1/2] Add TOTP field for the ItemField struct With Connect 1.4.0 we introduced the capability to get the totp value through Connect. Now the SDK supports that as well. --- onepassword/items.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/onepassword/items.go b/onepassword/items.go index fd40309..a383ebb 100644 --- a/onepassword/items.go +++ b/onepassword/items.go @@ -71,7 +71,7 @@ type Item struct { UpdatedAt time.Time `json:"updatedAt,omitempty"` // Deprecated: Connect does not return trashed items. - Trashed bool `json:"trashed,omitempty"` + Trashed bool `json:"trashed,omitempty"` } // ItemVault represents the Vault the Item is found in @@ -108,9 +108,10 @@ type ItemField struct { Generate bool `json:"generate,omitempty"` Recipe *GeneratorRecipe `json:"recipe,omitempty"` Entropy float64 `json:"entropy,omitempty"` + TOTP string `json:"totp,omitempty"` } -// Get Retrieve the value of a field on the item by its label. To specify a +// GetValue Retrieve the value of a field on the item by its label. To specify a // field from a specific section pass in
.. If // no field matching the selector is found return "". func (i *Item) GetValue(field string) string { From 14f80fe19812768ab1d71d499733e4e51ccec464 Mon Sep 17 00:00:00 2001 From: Eddy Filip Date: Thu, 24 Mar 2022 16:35:07 +0100 Subject: [PATCH 2/2] Add TOTP test --- onepassword/items_test.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/onepassword/items_test.go b/onepassword/items_test.go index 16830a9..b3222df 100644 --- a/onepassword/items_test.go +++ b/onepassword/items_test.go @@ -9,6 +9,7 @@ import ( var testUsernmae = "user123" var testPassword = "Password2!" var testOther = "Test Value" +var testTOTP = "154626" func TestItemGetValuePassword(t *testing.T) { login := testLogin() @@ -52,6 +53,19 @@ func TestItemGetValueMissingField(t *testing.T) { } } +func TestItemGetTOTP(t *testing.T) { + login := testLogin() + + for _, field := range login.Fields { + if field.Type == "OTP" { + if field.TOTP != "154626" { + t.Logf("Expected other value %q, found %q", testTOTP, field.TOTP) + t.FailNow() + } + } + } +} + func testLogin() *Item { sectionUUID := uuid.New().String() return &Item{ @@ -94,6 +108,13 @@ func testLogin() *Item { Label: "other", Value: testOther, }, + { + ID: "TOTP_c624e90aae964fdaa829517c24", + Type: "OTP", + Label: "one-time password", + Value: "otpauth://totp/testop?secret=totpcode", + TOTP: "154626", + }, }, } }