GODT-35: Finish all details and make tests pass

This commit is contained in:
Michal Horejsek
2021-03-11 14:37:15 +01:00
committed by Jakub
parent 2284e9ede1
commit 8109831c07
173 changed files with 4697 additions and 2897 deletions

View File

@ -96,17 +96,16 @@ type TestContext struct {
func New(app string) *TestContext {
setLogrusVerbosityFromEnv()
userAgent := useragent.New()
pmapiController, clientManager := newPMAPIController()
listener := listener.New()
pmapiController, clientManager := newPMAPIController(app, listener)
ctx := &TestContext{
t: &bddT{},
cache: newFakeCache(),
locations: newFakeLocations(),
settings: newFakeSettings(),
listener: listener.New(),
userAgent: userAgent,
listener: listener,
userAgent: useragent.New(),
pmapiController: pmapiController,
clientManager: clientManager,
testAccounts: newTestAccounts(),
@ -137,14 +136,6 @@ func New(app string) *TestContext {
return ctx
}
func getConfigName(app string) string {
if app == "ie" {
return "importExport"
}
return app
}
// Cleanup runs through all cleanup steps.
// This can be a deferred call so that it is run even if the test steps failed the test.
func (ctx *TestContext) Cleanup() *TestContext {

View File

@ -65,7 +65,6 @@ func (c *fakeCredStore) Add(userID, userName, uid, ref, mailboxPassword string,
BridgePassword: bridgePassword,
IsCombinedAddressMode: true, // otherwise by default starts in split mode
}
return c.Get(userID)
}
@ -74,12 +73,10 @@ func (c *fakeCredStore) Get(userID string) (*credentials.Credentials, error) {
}
func (c *fakeCredStore) SwitchAddressMode(userID string) (*credentials.Credentials, error) {
// FIXME(conman): Why is this empty?
return c.credentials[userID], nil
}
func (c *fakeCredStore) UpdateEmails(userID string, emails []string) (*credentials.Credentials, error) {
// FIXME(conman): Why is this empty?
return c.credentials[userID], nil
}

View File

@ -20,6 +20,8 @@ package context
import (
"os"
"github.com/ProtonMail/proton-bridge/internal/events"
"github.com/ProtonMail/proton-bridge/pkg/listener"
"github.com/ProtonMail/proton-bridge/pkg/pmapi"
"github.com/ProtonMail/proton-bridge/test/fakeapi"
"github.com/ProtonMail/proton-bridge/test/liveapi"
@ -39,15 +41,26 @@ type PMAPIController interface {
GetCalls(method, path string) [][]byte
}
func newPMAPIController() (PMAPIController, pmapi.Manager) {
func newPMAPIController(app string, listener listener.Listener) (PMAPIController, pmapi.Manager) {
switch os.Getenv(EnvName) {
case EnvFake:
return fakeapi.NewController()
cntl, cm := fakeapi.NewController()
addConnectionObserver(cm, listener)
return cntl, cm
case EnvLive:
return liveapi.NewController()
cntl, cm := liveapi.NewController(app)
addConnectionObserver(cm, listener)
return cntl, cm
default:
panic("unknown env")
}
}
func addConnectionObserver(cm pmapi.Manager, listener listener.Listener) {
cm.AddConnectionObserver(pmapi.NewConnectionObserver(
func() { listener.Emit(events.InternetOffEvent, "") },
func() { listener.Emit(events.InternetOnEvent, "") },
))
}

View File

@ -1,65 +0,0 @@
package context
import (
"context"
"net/http"
"time"
"github.com/ProtonMail/gopenpgp/v2/crypto"
"github.com/ProtonMail/proton-bridge/pkg/pmapi"
"github.com/go-resty/resty/v2"
)
func newLivePMAPIManager() pmapi.Manager {
return pmapi.New(pmapi.DefaultConfig)
}
func newFakePMAPIManager() pmapi.Manager {
return &fakePMAPIManager{}
}
type fakePMAPIManager struct{}
func (*fakePMAPIManager) NewClient(string, string, string, time.Time) pmapi.Client {
panic("TODO")
}
func (*fakePMAPIManager) NewClientWithRefresh(context.Context, string, string) (pmapi.Client, *pmapi.Auth, error) {
panic("TODO")
}
func (*fakePMAPIManager) NewClientWithLogin(context.Context, string, string) (pmapi.Client, *pmapi.Auth, error) {
panic("TODO")
}
func (*fakePMAPIManager) DownloadAndVerify(kr *crypto.KeyRing, url, sig string) ([]byte, error) {
panic("TODO")
}
func (*fakePMAPIManager) ReportBug(context.Context, pmapi.ReportBugReq) error {
panic("TODO")
}
func (*fakePMAPIManager) SendSimpleMetric(context.Context, string, string, string) error {
panic("TODO")
}
func (*fakePMAPIManager) SetLogger(resty.Logger) {
panic("TODO")
}
func (*fakePMAPIManager) SetTransport(http.RoundTripper) {
panic("TODO")
}
func (*fakePMAPIManager) SetCookieJar(http.CookieJar) {
panic("TODO")
}
func (*fakePMAPIManager) SetRetryCount(int) {
panic("TODO")
}
func (*fakePMAPIManager) AddConnectionObserver(pmapi.ConnectionObserver) {
panic("TODO")
}

View File

@ -26,7 +26,6 @@ import (
"github.com/ProtonMail/proton-bridge/internal/store"
"github.com/ProtonMail/proton-bridge/internal/users"
"github.com/ProtonMail/proton-bridge/pkg/pmapi"
"github.com/ProtonMail/proton-bridge/pkg/srp"
"github.com/pkg/errors"
"github.com/stretchr/testify/assert"
@ -46,8 +45,8 @@ func (ctx *TestContext) LoginUser(username, password, mailboxPassword string) er
return errors.Wrap(err, "failed to login")
}
if auth.TwoFA.Enabled == pmapi.TOTPEnabled {
if err := client.Auth2FA(context.TODO(), pmapi.Auth2FAReq{TwoFactorCode: "2fa code"}); err != nil {
if auth.HasTwoFactor() {
if err := client.Auth2FA(context.Background(), "2fa code"); err != nil {
return errors.Wrap(err, "failed to login with 2FA")
}
}