Skip to content

Commit

Permalink
set group for org collections
Browse files Browse the repository at this point in the history
  • Loading branch information
maxlaverse committed Sep 29, 2024
1 parent f6d7453 commit f18c66e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 2 additions & 1 deletion internal/bitwarden/bwcli/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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...)
Expand Down
12 changes: 6 additions & 6 deletions internal/bitwarden/bwcli/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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])
}
}

Expand Down Expand Up @@ -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: ''")
}
}

0 comments on commit f18c66e

Please sign in to comment.