Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add TOTP field for the ItemField struct #44

Merged
merged 2 commits into from
Mar 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions onepassword/items.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 <section label>.<field label>. If
// no field matching the selector is found return "".
func (i *Item) GetValue(field string) string {
Expand Down
21 changes: 21 additions & 0 deletions onepassword/items_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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",
},
},
}
}