mirror of
https://github.com/ProtonMail/proton-bridge.git
synced 2025-12-17 15:46:44 +00:00
feat: improve login flow
This commit is contained in:
@ -18,7 +18,9 @@
|
||||
package liveapi
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"os"
|
||||
"sync"
|
||||
|
||||
"github.com/ProtonMail/proton-bridge/pkg/pmapi"
|
||||
@ -30,31 +32,31 @@ type Controller struct {
|
||||
calls []*fakeCall
|
||||
pmapiByUsername map[string]*pmapi.Client
|
||||
messageIDsByUsername map[string][]string
|
||||
clientManager *pmapi.ClientManager
|
||||
|
||||
// State controlled by test.
|
||||
noInternetConnection bool
|
||||
}
|
||||
|
||||
func NewController(cm *pmapi.ClientManager) *Controller {
|
||||
cntrl := &Controller{
|
||||
func NewController() *Controller {
|
||||
return &Controller{
|
||||
lock: &sync.RWMutex{},
|
||||
calls: []*fakeCall{},
|
||||
pmapiByUsername: map[string]*pmapi.Client{},
|
||||
messageIDsByUsername: map[string][]string{},
|
||||
clientManager: cm,
|
||||
|
||||
noInternetConnection: false,
|
||||
}
|
||||
|
||||
cntrl.clientManager.SetClientRoundTripper(&fakeTransport{
|
||||
cntrl: cntrl,
|
||||
transport: http.DefaultTransport,
|
||||
})
|
||||
|
||||
return cntrl
|
||||
}
|
||||
|
||||
func (cntrl *Controller) GetClient(userID string) *pmapi.Client {
|
||||
return cntrl.clientManager.GetClient(userID)
|
||||
cfg := &pmapi.ClientConfig{
|
||||
AppVersion: fmt.Sprintf("Bridge_%s", os.Getenv("VERSION")),
|
||||
ClientID: "bridge-test",
|
||||
Transport: &fakeTransport{
|
||||
cntrl: cntrl,
|
||||
transport: http.DefaultTransport,
|
||||
},
|
||||
TokenManager: pmapi.NewTokenManager(),
|
||||
}
|
||||
return pmapi.NewClient(cfg, userID)
|
||||
}
|
||||
|
||||
@ -18,7 +18,9 @@
|
||||
package liveapi
|
||||
|
||||
import (
|
||||
"github.com/ProtonMail/proton-bridge/pkg/pmapi"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/cucumber/godog"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
@ -28,7 +30,11 @@ func (cntrl *Controller) AddUser(user *pmapi.User, addresses *pmapi.AddressList,
|
||||
return godog.ErrPending
|
||||
}
|
||||
|
||||
client := cntrl.GetClient(user.ID)
|
||||
client := pmapi.NewClient(&pmapi.ClientConfig{
|
||||
AppVersion: fmt.Sprintf("Bridge_%s", os.Getenv("VERSION")),
|
||||
ClientID: "bridge-cntrl",
|
||||
TokenManager: pmapi.NewTokenManager(),
|
||||
}, user.ID)
|
||||
|
||||
authInfo, err := client.AuthInfo(user.Name)
|
||||
if err != nil {
|
||||
@ -55,6 +61,5 @@ func (cntrl *Controller) AddUser(user *pmapi.User, addresses *pmapi.AddressList,
|
||||
}
|
||||
|
||||
cntrl.pmapiByUsername[user.Name] = client
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user