forked from Silverfish/proton-bridge
Other: Use API call rather than server-specific method in test code
This commit is contained in:
2
go.mod
2
go.mod
@ -40,7 +40,7 @@ require (
|
||||
github.com/stretchr/testify v1.8.0
|
||||
github.com/urfave/cli/v2 v2.20.3
|
||||
github.com/vmihailenco/msgpack/v5 v5.3.5
|
||||
gitlab.protontech.ch/go/liteapi v0.43.1
|
||||
gitlab.protontech.ch/go/liteapi v0.43.2
|
||||
go.uber.org/goleak v1.2.0
|
||||
golang.org/x/exp v0.0.0-20221023144134-a1e5550cf13e
|
||||
golang.org/x/net v0.1.0
|
||||
|
||||
4
go.sum
4
go.sum
@ -403,8 +403,8 @@ github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsr
|
||||
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
|
||||
github.com/zclconf/go-cty v1.11.0 h1:726SxLdi2SDnjY+BStqB9J1hNp4+2WlzyXLuimibIe0=
|
||||
github.com/zclconf/go-cty v1.11.0/go.mod h1:s9IfD1LK5ccNMSWCVFCE2rJfHiZgi7JijgeWIMfhLvA=
|
||||
gitlab.protontech.ch/go/liteapi v0.43.1 h1:T+IsGwSKQKRFdexRS0siManrYVOA8mrohGT7mg8L58Y=
|
||||
gitlab.protontech.ch/go/liteapi v0.43.1/go.mod h1:IM7ADWjgIL2hXopzx0WNamizEuMgM2QZl7QH12FNflk=
|
||||
gitlab.protontech.ch/go/liteapi v0.43.2 h1:4/tF6pQuOg3sz2/JF1XGRff3KB0jFWM2uDstJiYmDYk=
|
||||
gitlab.protontech.ch/go/liteapi v0.43.2/go.mod h1:IM7ADWjgIL2hXopzx0WNamizEuMgM2QZl7QH12FNflk=
|
||||
go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU=
|
||||
go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU=
|
||||
go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8=
|
||||
|
||||
@ -380,6 +380,12 @@ func TestBridge_MissingGluonDir(t *testing.T) {
|
||||
|
||||
func TestBridge_AddressWithoutKeys(t *testing.T) {
|
||||
withEnv(t, func(ctx context.Context, s *server.Server, netCtl *liteapi.NetCtl, locator bridge.Locator, vaultKey []byte) {
|
||||
m := liteapi.New(
|
||||
liteapi.WithHostURL(s.GetHostURL()),
|
||||
liteapi.WithTransport(liteapi.InsecureTransport()),
|
||||
)
|
||||
defer m.Close()
|
||||
|
||||
withBridge(ctx, t, s.GetHostURL(), netCtl, locator, vaultKey, func(bridge *bridge.Bridge, mocks *bridge.Mocks) {
|
||||
// Create a user which will have an address without keys.
|
||||
userID, _, err := s.CreateUser("nokeys", "nokeys@pm.me", []byte("password"))
|
||||
@ -389,13 +395,17 @@ func TestBridge_AddressWithoutKeys(t *testing.T) {
|
||||
aliasAddrID, err := s.CreateAddress(userID, "alias@pm.me", []byte("password"))
|
||||
require.NoError(t, err)
|
||||
|
||||
// Get the address key IDs.
|
||||
aliasKeyIDs, err := s.GetAddressKeyIDs(userID, aliasAddrID)
|
||||
// Create an API client so we can remove the address keys.
|
||||
c, _, err := m.NewClientWithLogin(ctx, "nokeys", []byte("password"))
|
||||
require.NoError(t, err)
|
||||
defer c.Close()
|
||||
|
||||
// Get the alias address.
|
||||
aliasAddr, err := c.GetAddress(ctx, aliasAddrID)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, aliasKeyIDs, 1)
|
||||
|
||||
// Remove the address keys.
|
||||
require.NoError(t, s.RemoveAddressKey(userID, aliasAddrID, aliasKeyIDs[0]))
|
||||
require.NoError(t, s.RemoveAddressKey(userID, aliasAddrID, aliasAddr.Keys[0].ID))
|
||||
|
||||
// Watch for sync finished event.
|
||||
syncCh, done := chToType[events.Event, events.SyncFinished](bridge.GetEvents(events.SyncFinished{}))
|
||||
|
||||
@ -34,7 +34,6 @@ type API interface {
|
||||
|
||||
CreateAddress(userID, address string, password []byte) (string, error)
|
||||
RemoveAddress(userID, addrID string) error
|
||||
GetAddressKeyIDs(userID, addrID string) ([]string, error)
|
||||
RemoveAddressKey(userID, addrID, keyID string) error
|
||||
|
||||
UpdateDraft(userID, draftID string, changes liteapi.DraftTemplate) error
|
||||
|
||||
@ -207,18 +207,20 @@ func (s *scenario) theAddressOfAccountHasNoKeys(address, username string) error
|
||||
userID := s.t.getUserID(username)
|
||||
addrID := s.t.getUserAddrID(userID, address)
|
||||
|
||||
keyIDs, err := s.t.api.GetAddressKeyIDs(userID, addrID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, keyID := range keyIDs {
|
||||
if err := s.t.api.RemoveAddressKey(userID, addrID, keyID); err != nil {
|
||||
return s.t.withClient(context.Background(), username, func(ctx context.Context, client *liteapi.Client) error {
|
||||
address, err := client.GetAddress(ctx, addrID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
for _, key := range address.Keys {
|
||||
if err := s.t.api.RemoveAddressKey(userID, addrID, key.ID); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
// accountDraftChanged changes the draft attributes, where draftIndex is
|
||||
|
||||
Reference in New Issue
Block a user