From f18c66e044cee171d4470dcb1a3857d9e552223b Mon Sep 17 00:00:00 2001 From: Maxime Lagresle Date: Sun, 29 Sep 2024 15:25:37 +0200 Subject: [PATCH] set group for org collections --- .github/workflows/tests.yml | 2 +- internal/bitwarden/bwcli/client.go | 3 ++- internal/bitwarden/bwcli/client_test.go | 12 ++++++------ 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 1c02eb4..7d28c2f 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -23,7 +23,7 @@ jobs: services: vaultwarden: - image: vaultwarden/server:latest + image: vaultwarden/server:1.32.0 env: ADMIN_TOKEN: test1234 I_REALLY_WANT_VOLATILE_STORAGE: "true" diff --git a/internal/bitwarden/bwcli/client.go b/internal/bitwarden/bwcli/client.go index 2896f16..c1c768b 100644 --- a/internal/bitwarden/bwcli/client.go +++ b/internal/bitwarden/bwcli/client.go @@ -84,6 +84,7 @@ func DisableRetryBackoff() Options { } func (c *client) CreateObject(ctx context.Context, obj models.Object) (*models.Object, error) { + obj.Groups = []interface{}{} objEncoded, err := c.encode(obj) if err != nil { return nil, err @@ -200,7 +201,7 @@ func (c *client) GetSessionKey() string { func (c *client) ListObjects(ctx context.Context, objType models.ObjectType, options ...bitwarden.ListObjectsOption) ([]models.Object, error) { args := []string{ "list", - string(objType), + fmt.Sprintf("%ss", objType), } applyFiltersToArgs(&args, options...) diff --git a/internal/bitwarden/bwcli/client_test.go b/internal/bitwarden/bwcli/client_test.go index fa7d362..3e3ce13 100644 --- a/internal/bitwarden/bwcli/client_test.go +++ b/internal/bitwarden/bwcli/client_test.go @@ -37,16 +37,16 @@ func TestCreateObjectEncoding(t *testing.T) { func TestListObjects(t *testing.T) { removeMocks, commandsExecuted := test_command.MockCommands(t, map[string]string{ - "list item --folderid folder-id --collectionid collection-id --search search": `[]`, + "list items --folderid folder-id --collectionid collection-id --search search": `[]`, }) defer removeMocks(t) b := NewClient("dummy") - _, err := b.ListObjects(context.Background(), "item", bitwarden.WithFolderID("folder-id"), bitwarden.WithCollectionID("collection-id"), bitwarden.WithSearch("search")) + _, err := b.ListObjects(context.Background(), models.ObjectTypeItem, bitwarden.WithFolderID("folder-id"), bitwarden.WithCollectionID("collection-id"), bitwarden.WithSearch("search")) assert.NoError(t, err) if assert.Len(t, commandsExecuted(), 1) { - assert.Equal(t, "list item --folderid folder-id --collectionid collection-id --search search", commandsExecuted()[0]) + assert.Equal(t, "list items --folderid folder-id --collectionid collection-id --search search", commandsExecuted()[0]) } } @@ -82,14 +82,14 @@ func TestGetOrgCollection(t *testing.T) { func TestErrorContainsCommand(t *testing.T) { removeMocks, _ := test_command.MockCommands(t, map[string]string{ - "list org-collection --search search": ``, + "list org-collections --search search": ``, }) defer removeMocks(t) b := NewClient("dummy") - _, err := b.ListObjects(context.Background(), "org-collection", bitwarden.WithSearch("search")) + _, err := b.ListObjects(context.Background(), models.ObjectTypeOrgCollection, bitwarden.WithSearch("search")) if assert.Error(t, err) { - assert.ErrorContains(t, err, "unable to parse result of 'list org-collection', error: 'unexpected end of JSON input', output: ''") + assert.ErrorContains(t, err, "unable to parse result of 'list org-collections', error: 'unexpected end of JSON input', output: ''") } }