mirror of
https://github.com/ProtonMail/proton-bridge.git
synced 2025-12-17 23:56:56 +00:00
GODT-1657: More stable sync, with some tests
This commit is contained in:
@ -12,8 +12,8 @@ type API interface {
|
||||
GetHostURL() string
|
||||
AddCallWatcher(func(server.Call), ...string)
|
||||
|
||||
CreateUser(username, password, address string) (string, string, error)
|
||||
CreateAddress(userID, address, password string) (string, error)
|
||||
CreateUser(username, address string, password []byte) (string, string, error)
|
||||
CreateAddress(userID, address string, password []byte) (string, error)
|
||||
RemoveAddress(userID, addrID string) error
|
||||
RevokeUser(userID string) error
|
||||
|
||||
|
||||
@ -2,17 +2,19 @@ package tests
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/tls"
|
||||
"fmt"
|
||||
|
||||
"github.com/ProtonMail/proton-bridge/v2/internal/bridge"
|
||||
"github.com/ProtonMail/proton-bridge/v2/internal/events"
|
||||
"github.com/ProtonMail/proton-bridge/v2/internal/useragent"
|
||||
"github.com/ProtonMail/proton-bridge/v2/internal/vault"
|
||||
"gitlab.protontech.ch/go/liteapi"
|
||||
)
|
||||
|
||||
func (t *testCtx) startBridge() error {
|
||||
// Bridge will enable the proxy by default at startup.
|
||||
t.mocks.ProxyDialer.EXPECT().AllowProxy()
|
||||
t.mocks.ProxyCtl.EXPECT().AllowProxy()
|
||||
|
||||
// Get the path to the vault.
|
||||
vaultDir, err := t.locator.ProvideSettingsPath()
|
||||
@ -41,7 +43,8 @@ func (t *testCtx) startBridge() error {
|
||||
vault,
|
||||
useragent.New(),
|
||||
t.mocks.TLSReporter,
|
||||
t.mocks.ProxyDialer,
|
||||
liteapi.NewDialer(t.netCtl, &tls.Config{InsecureSkipVerify: true}).GetRoundTripper(),
|
||||
t.mocks.ProxyCtl,
|
||||
t.mocks.Autostarter,
|
||||
t.mocks.Updater,
|
||||
t.version,
|
||||
|
||||
@ -24,7 +24,7 @@ type testCtx struct {
|
||||
// These are the objects supporting the test.
|
||||
dir string
|
||||
api API
|
||||
dialer *bridge.TestDialer
|
||||
netCtl *liteapi.NetCtl
|
||||
locator *locations.Locations
|
||||
storeKey []byte
|
||||
version *semver.Version
|
||||
@ -76,15 +76,13 @@ type smtpClient struct {
|
||||
func newTestCtx(tb testing.TB) *testCtx {
|
||||
dir := tb.TempDir()
|
||||
|
||||
dialer := bridge.NewTestDialer()
|
||||
|
||||
ctx := &testCtx{
|
||||
dir: dir,
|
||||
api: newFakeAPI(),
|
||||
dialer: dialer,
|
||||
netCtl: liteapi.NewNetCtl(),
|
||||
locator: locations.New(bridge.NewTestLocationsProvider(dir), "config-name"),
|
||||
storeKey: []byte("super-secret-store-key"),
|
||||
mocks: bridge.NewMocks(tb, dialer, defaultVersion, defaultVersion),
|
||||
mocks: bridge.NewMocks(tb, defaultVersion, defaultVersion),
|
||||
version: defaultVersion,
|
||||
|
||||
userIDByName: make(map[string]string),
|
||||
|
||||
@ -38,12 +38,12 @@ func (s *scenario) itFailsWithError(wantErr string) error {
|
||||
}
|
||||
|
||||
func (s *scenario) internetIsTurnedOff() error {
|
||||
s.t.dialer.SetCanDial(false)
|
||||
s.t.netCtl.SetCanDial(false)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *scenario) internetIsTurnedOn() error {
|
||||
s.t.dialer.SetCanDial(true)
|
||||
s.t.netCtl.SetCanDial(true)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@ -14,7 +14,7 @@ import (
|
||||
|
||||
func (s *scenario) thereExistsAnAccountWithUsernameAndPassword(username, password string) error {
|
||||
// Create the user.
|
||||
userID, addrID, err := s.t.api.CreateUser(username, password, username)
|
||||
userID, addrID, err := s.t.api.CreateUser(username, username, []byte(password))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -34,7 +34,7 @@ func (s *scenario) thereExistsAnAccountWithUsernameAndPassword(username, passwor
|
||||
func (s *scenario) theAccountHasAdditionalAddress(username, address string) error {
|
||||
userID := s.t.getUserID(username)
|
||||
|
||||
addrID, err := s.t.api.CreateAddress(userID, address, s.t.getUserPass(userID))
|
||||
addrID, err := s.t.api.CreateAddress(userID, address, []byte(s.t.getUserPass(userID)))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user