Skip to content

Commit

Permalink
create organization test resources
Browse files Browse the repository at this point in the history
  • Loading branch information
maxlaverse committed Nov 14, 2024
1 parent b3270bb commit a381731
Showing 1 changed file with 38 additions and 3 deletions.
41 changes: 38 additions & 3 deletions internal/bitwarden/embedded/testhelper_create_accounts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"fmt"
"net/http"
"os"
"path"
"strings"
"testing"

Expand All @@ -25,11 +26,11 @@ import (
// This is only used to generate test data
func TestCreateTestAccounts(t *testing.T) {
t.Skip()
createTestAccount(t, Pdkdf2Email, models.KdfConfiguration{
createTestAccount(t, AccountPbkdf2.Email, models.KdfConfiguration{
KdfType: models.KdfTypePBKDF2_SHA256,
KdfIterations: 600000,
})
createTestAccount(t, Argon2Email, models.KdfConfiguration{
createTestAccount(t, AccountArgon2.Email, models.KdfConfiguration{
KdfType: models.KdfTypeArgon2,
KdfIterations: 3,
KdfMemory: 64,
Expand Down Expand Up @@ -148,7 +149,7 @@ func createTestAccount(t *testing.T, accountEmail string, kdfConfig models.KdfCo

httpClient := http.Client{
Transport: &diskTransport{
Prefix: mockName,
Prefix: path.Join(fixturesDir(t), mockName),
},
}
vault := NewPasswordManagerClient(ServerURL, testDeviceIdentifer, "dev", WithPasswordManagerHttpOptions(webapi.WithCustomClient(httpClient)))
Expand All @@ -163,6 +164,11 @@ func createTestAccount(t *testing.T, accountEmail string, kdfConfig models.KdfCo
t.Fatal(err)
}

err = vault.Logout(ctx)
if err != nil {
t.Fatal(err)
}

err = vault.LoginWithAPIKey(ctx, TestPassword, apiKey.ClientID, apiKey.ClientSecret)
if err != nil {
t.Fatal(err)
Expand All @@ -179,4 +185,33 @@ func createTestAccount(t *testing.T, accountEmail string, kdfConfig models.KdfCo
if err != nil {
t.Fatal(err)
}

orgId, err := vault.CreateOrganization(ctx, "test-organization", "test-organization-label", "test@laverse.net")
if err != nil {
t.Fatal(err)
}

orgCol, err := vault.CreateObject(ctx, models.Object{
Object: models.ObjectTypeOrgCollection,
Name: "org-collection",
OrganizationID: orgId,
})
if err != nil {
t.Fatal(err)
}

_, err = vault.CreateObject(ctx, models.Object{
Object: models.ObjectTypeItem,
Type: models.ItemTypeLogin,
Name: "Item in org Vault",
OrganizationID: orgCol.OrganizationID,
CollectionIds: []string{orgCol.ID},
Login: models.Login{
Username: "my-org-username",
},
})

if err != nil {
t.Fatal(err)
}
}

0 comments on commit a381731

Please sign in to comment.