mirror of
https://github.com/ProtonMail/proton-bridge.git
synced 2025-12-10 04:36:43 +00:00
Other: Switch from liteapi to go-proton-api
This commit is contained in:
@ -19,8 +19,8 @@ package tests
|
||||
|
||||
import (
|
||||
"github.com/Masterminds/semver/v3"
|
||||
"gitlab.protontech.ch/go/liteapi"
|
||||
"gitlab.protontech.ch/go/liteapi/server"
|
||||
"github.com/ProtonMail/go-proton-api"
|
||||
"github.com/ProtonMail/go-proton-api/server"
|
||||
)
|
||||
|
||||
type API interface {
|
||||
@ -36,7 +36,7 @@ type API interface {
|
||||
RemoveAddress(userID, addrID string) error
|
||||
RemoveAddressKey(userID, addrID, keyID string) error
|
||||
|
||||
UpdateDraft(userID, draftID string, changes liteapi.DraftTemplate) error
|
||||
UpdateDraft(userID, draftID string, changes proton.DraftTemplate) error
|
||||
|
||||
Close()
|
||||
}
|
||||
|
||||
@ -30,6 +30,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/ProtonMail/gluon/queue"
|
||||
"github.com/ProtonMail/go-proton-api"
|
||||
"github.com/ProtonMail/proton-bridge/v2/internal/bridge"
|
||||
"github.com/ProtonMail/proton-bridge/v2/internal/constants"
|
||||
"github.com/ProtonMail/proton-bridge/v2/internal/cookies"
|
||||
@ -38,7 +39,6 @@ import (
|
||||
"github.com/ProtonMail/proton-bridge/v2/internal/useragent"
|
||||
"github.com/ProtonMail/proton-bridge/v2/internal/vault"
|
||||
"github.com/sirupsen/logrus"
|
||||
"gitlab.protontech.ch/go/liteapi"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/credentials"
|
||||
"google.golang.org/grpc/metadata"
|
||||
@ -157,7 +157,7 @@ func (t *testCtx) initBridge() (<-chan events.Event, error) {
|
||||
persister,
|
||||
useragent.New(),
|
||||
t.mocks.TLSReporter,
|
||||
liteapi.NewDialer(t.netCtl, &tls.Config{InsecureSkipVerify: true}).GetRoundTripper(),
|
||||
proton.NewDialer(t.netCtl, &tls.Config{InsecureSkipVerify: true}).GetRoundTripper(),
|
||||
t.mocks.ProxyCtl,
|
||||
t.mocks.CrashHandler,
|
||||
t.reporter,
|
||||
|
||||
@ -25,19 +25,19 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/ProtonMail/gluon/reporter"
|
||||
"github.com/ProtonMail/go-proton-api"
|
||||
"github.com/ProtonMail/gopenpgp/v2/crypto"
|
||||
"github.com/bradenaw/juniper/stream"
|
||||
"github.com/bradenaw/juniper/xslices"
|
||||
"github.com/golang/mock/gomock"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"gitlab.protontech.ch/go/liteapi"
|
||||
)
|
||||
|
||||
func (t *testCtx) withClient(ctx context.Context, username string, fn func(context.Context, *liteapi.Client) error) error {
|
||||
c, _, err := liteapi.New(
|
||||
liteapi.WithHostURL(t.api.GetHostURL()),
|
||||
liteapi.WithTransport(liteapi.InsecureTransport()),
|
||||
func (t *testCtx) withClient(ctx context.Context, username string, fn func(context.Context, *proton.Client) error) error {
|
||||
c, _, err := proton.New(
|
||||
proton.WithHostURL(t.api.GetHostURL()),
|
||||
proton.WithTransport(proton.InsecureTransport()),
|
||||
).NewClientWithLogin(ctx, username, []byte(t.getUserPass(t.getUserID(username))))
|
||||
if err != nil {
|
||||
return err
|
||||
@ -58,7 +58,7 @@ func (t *testCtx) withClient(ctx context.Context, username string, fn func(conte
|
||||
|
||||
func (t *testCtx) withAddrKR(
|
||||
ctx context.Context,
|
||||
c *liteapi.Client,
|
||||
c *proton.Client,
|
||||
username, addrID string,
|
||||
fn func(context.Context, *crypto.KeyRing) error,
|
||||
) error {
|
||||
@ -82,7 +82,7 @@ func (t *testCtx) withAddrKR(
|
||||
return err
|
||||
}
|
||||
|
||||
_, addrKRs, err := liteapi.Unlock(user, addr, keyPass)
|
||||
_, addrKRs, err := proton.Unlock(user, addr, keyPass)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -90,8 +90,8 @@ func (t *testCtx) withAddrKR(
|
||||
return fn(ctx, addrKRs[addrID])
|
||||
}
|
||||
|
||||
func (t *testCtx) createMessages(ctx context.Context, username, addrID string, req []liteapi.ImportReq) error {
|
||||
return t.withClient(ctx, username, func(ctx context.Context, c *liteapi.Client) error {
|
||||
func (t *testCtx) createMessages(ctx context.Context, username, addrID string, req []proton.ImportReq) error {
|
||||
return t.withClient(ctx, username, func(ctx context.Context, c *proton.Client) error {
|
||||
return t.withAddrKR(ctx, c, username, addrID, func(ctx context.Context, addrKR *crypto.KeyRing) error {
|
||||
if _, err := stream.Collect(ctx, c.ImportMessages(
|
||||
ctx,
|
||||
|
||||
@ -27,6 +27,8 @@ import (
|
||||
|
||||
"github.com/Masterminds/semver/v3"
|
||||
"github.com/ProtonMail/gluon/queue"
|
||||
"github.com/ProtonMail/go-proton-api"
|
||||
"github.com/ProtonMail/go-proton-api/server"
|
||||
"github.com/ProtonMail/proton-bridge/v2/internal/bridge"
|
||||
frontend "github.com/ProtonMail/proton-bridge/v2/internal/frontend/grpc"
|
||||
"github.com/ProtonMail/proton-bridge/v2/internal/locations"
|
||||
@ -34,8 +36,6 @@ import (
|
||||
"github.com/emersion/go-imap/client"
|
||||
"github.com/golang/mock/gomock"
|
||||
"github.com/sirupsen/logrus"
|
||||
"gitlab.protontech.ch/go/liteapi"
|
||||
"gitlab.protontech.ch/go/liteapi/server"
|
||||
"golang.org/x/exp/maps"
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
@ -46,7 +46,7 @@ type testCtx struct {
|
||||
// These are the objects supporting the test.
|
||||
dir string
|
||||
api API
|
||||
netCtl *liteapi.NetCtl
|
||||
netCtl *proton.NetCtl
|
||||
locator *locations.Locations
|
||||
storeKey []byte
|
||||
version *semver.Version
|
||||
@ -101,7 +101,7 @@ func newTestCtx(tb testing.TB) *testCtx {
|
||||
t := &testCtx{
|
||||
dir: dir,
|
||||
api: newFakeAPI(),
|
||||
netCtl: liteapi.NewNetCtl(),
|
||||
netCtl: proton.NewNetCtl(),
|
||||
locator: locations.New(bridge.NewTestLocationsProvider(dir), "config-name"),
|
||||
storeKey: []byte("super-secret-store-key"),
|
||||
version: defaultVersion,
|
||||
@ -203,13 +203,13 @@ func (t *testCtx) getMBoxID(userID string, name string) string {
|
||||
|
||||
var labelID string
|
||||
|
||||
if err := t.withClient(ctx, t.getName(userID), func(ctx context.Context, client *liteapi.Client) error {
|
||||
labels, err := client.GetLabels(ctx, liteapi.LabelTypeLabel, liteapi.LabelTypeFolder, liteapi.LabelTypeSystem)
|
||||
if err := t.withClient(ctx, t.getName(userID), func(ctx context.Context, client *proton.Client) error {
|
||||
labels, err := client.GetLabels(ctx, proton.LabelTypeLabel, proton.LabelTypeFolder, proton.LabelTypeSystem)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
idx := xslices.IndexFunc(labels, func(label liteapi.Label) bool {
|
||||
idx := xslices.IndexFunc(labels, func(label proton.Label) bool {
|
||||
return label.Name == name
|
||||
})
|
||||
|
||||
@ -240,9 +240,9 @@ func (t *testCtx) getDraftID(username string, draftIndex int) string {
|
||||
|
||||
var draftID string
|
||||
|
||||
if err := t.withClient(ctx, username, func(ctx context.Context, client *liteapi.Client) error {
|
||||
if err := t.withClient(ctx, username, func(ctx context.Context, client *proton.Client) error {
|
||||
messages, err := client.GetMessageMetadata(
|
||||
ctx, liteapi.MessageFilter{LabelID: liteapi.DraftsLabel},
|
||||
ctx, proton.MessageFilter{LabelID: proton.DraftsLabel},
|
||||
)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
|
||||
@ -20,9 +20,9 @@ package tests
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/ProtonMail/go-proton-api/server/backend"
|
||||
"github.com/ProtonMail/proton-bridge/v2/internal/certs"
|
||||
"github.com/ProtonMail/proton-bridge/v2/internal/user"
|
||||
"gitlab.protontech.ch/go/liteapi/server/backend"
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
||||
@ -23,13 +23,13 @@ import (
|
||||
"fmt"
|
||||
"net/mail"
|
||||
|
||||
"github.com/ProtonMail/go-proton-api"
|
||||
"github.com/ProtonMail/gopenpgp/v2/crypto"
|
||||
"github.com/ProtonMail/proton-bridge/v2/internal/bridge"
|
||||
"github.com/bradenaw/juniper/iterator"
|
||||
"github.com/bradenaw/juniper/xslices"
|
||||
"github.com/cucumber/godog"
|
||||
"github.com/google/uuid"
|
||||
"gitlab.protontech.ch/go/liteapi"
|
||||
"golang.org/x/exp/slices"
|
||||
)
|
||||
|
||||
@ -82,11 +82,11 @@ func (s *scenario) theAccountHasCustomFolders(username string, count int) error
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
|
||||
return s.t.withClient(ctx, username, func(ctx context.Context, client *liteapi.Client) error {
|
||||
return s.t.withClient(ctx, username, func(ctx context.Context, client *proton.Client) error {
|
||||
for idx := 0; idx < count; idx++ {
|
||||
if _, err := client.CreateLabel(ctx, liteapi.CreateLabelReq{
|
||||
if _, err := client.CreateLabel(ctx, proton.CreateLabelReq{
|
||||
Name: uuid.NewString(),
|
||||
Type: liteapi.LabelTypeFolder,
|
||||
Type: proton.LabelTypeFolder,
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
@ -100,11 +100,11 @@ func (s *scenario) theAccountHasCustomLabels(username string, count int) error {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
|
||||
return s.t.withClient(ctx, username, func(ctx context.Context, client *liteapi.Client) error {
|
||||
return s.t.withClient(ctx, username, func(ctx context.Context, client *proton.Client) error {
|
||||
for idx := 0; idx < count; idx++ {
|
||||
if _, err := client.CreateLabel(ctx, liteapi.CreateLabelReq{
|
||||
if _, err := client.CreateLabel(ctx, proton.CreateLabelReq{
|
||||
Name: uuid.NewString(),
|
||||
Type: liteapi.LabelTypeLabel,
|
||||
Type: proton.LabelTypeLabel,
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
@ -128,19 +128,19 @@ func (s *scenario) theAccountHasTheFollowingCustomMailboxes(username string, tab
|
||||
return err
|
||||
}
|
||||
|
||||
return s.t.withClient(ctx, username, func(ctx context.Context, client *liteapi.Client) error {
|
||||
return s.t.withClient(ctx, username, func(ctx context.Context, client *proton.Client) error {
|
||||
for _, wantMailbox := range wantMailboxes {
|
||||
var labelType liteapi.LabelType
|
||||
var labelType proton.LabelType
|
||||
|
||||
switch wantMailbox.Type {
|
||||
case "folder":
|
||||
labelType = liteapi.LabelTypeFolder
|
||||
labelType = proton.LabelTypeFolder
|
||||
|
||||
case "label":
|
||||
labelType = liteapi.LabelTypeLabel
|
||||
labelType = proton.LabelTypeLabel
|
||||
}
|
||||
|
||||
if _, err := client.CreateLabel(ctx, liteapi.CreateLabelReq{
|
||||
if _, err := client.CreateLabel(ctx, proton.CreateLabelReq{
|
||||
Name: wantMailbox.Name,
|
||||
Type: labelType,
|
||||
}); err != nil {
|
||||
@ -165,13 +165,13 @@ func (s *scenario) theAddressOfAccountHasTheFollowingMessagesInMailbox(address,
|
||||
return err
|
||||
}
|
||||
|
||||
return s.t.createMessages(ctx, username, addrID, xslices.Map(wantMessages, func(message Message) liteapi.ImportReq {
|
||||
return liteapi.ImportReq{
|
||||
Metadata: liteapi.ImportMetadata{
|
||||
return s.t.createMessages(ctx, username, addrID, xslices.Map(wantMessages, func(message Message) proton.ImportReq {
|
||||
return proton.ImportReq{
|
||||
Metadata: proton.ImportMetadata{
|
||||
AddressID: addrID,
|
||||
LabelIDs: []string{mboxID},
|
||||
Unread: liteapi.Bool(message.Unread),
|
||||
Flags: liteapi.MessageFlagReceived,
|
||||
Unread: proton.Bool(message.Unread),
|
||||
Flags: proton.MessageFlagReceived,
|
||||
},
|
||||
Message: message.Build(),
|
||||
}
|
||||
@ -186,12 +186,12 @@ func (s *scenario) theAddressOfAccountHasMessagesInMailbox(address, username str
|
||||
addrID := s.t.getUserAddrID(userID, address)
|
||||
mboxID := s.t.getMBoxID(userID, mailbox)
|
||||
|
||||
return s.t.createMessages(ctx, username, addrID, iterator.Collect(iterator.Map(iterator.Counter(count), func(idx int) liteapi.ImportReq {
|
||||
return liteapi.ImportReq{
|
||||
Metadata: liteapi.ImportMetadata{
|
||||
return s.t.createMessages(ctx, username, addrID, iterator.Collect(iterator.Map(iterator.Counter(count), func(idx int) proton.ImportReq {
|
||||
return proton.ImportReq{
|
||||
Metadata: proton.ImportMetadata{
|
||||
AddressID: addrID,
|
||||
LabelIDs: []string{mboxID},
|
||||
Flags: liteapi.MessageFlagReceived,
|
||||
Flags: proton.MessageFlagReceived,
|
||||
},
|
||||
Message: Message{
|
||||
Subject: fmt.Sprintf("%d", idx),
|
||||
@ -207,7 +207,7 @@ func (s *scenario) theAddressOfAccountHasNoKeys(address, username string) error
|
||||
userID := s.t.getUserID(username)
|
||||
addrID := s.t.getUserAddrID(userID, address)
|
||||
|
||||
return s.t.withClient(context.Background(), username, func(ctx context.Context, client *liteapi.Client) error {
|
||||
return s.t.withClient(context.Background(), username, func(ctx context.Context, client *proton.Client) error {
|
||||
address, err := client.GetAddress(ctx, addrID)
|
||||
if err != nil {
|
||||
return err
|
||||
@ -244,11 +244,11 @@ func (s *scenario) addressDraftChanged(draftIndex int, address, username string,
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
|
||||
if err := s.t.withClient(ctx, username, func(ctx context.Context, c *liteapi.Client) error {
|
||||
if err := s.t.withClient(ctx, username, func(ctx context.Context, c *proton.Client) error {
|
||||
return s.t.withAddrKR(ctx, c, username, s.t.getUserAddrID(s.t.getUserID(username), address),
|
||||
func(ctx context.Context, addrKR *crypto.KeyRing) error {
|
||||
var err error
|
||||
encBody, err = liteapi.EncryptRFC822(addrKR, wantMessages[0].Build())
|
||||
encBody, err = proton.EncryptRFC822(addrKR, wantMessages[0].Build())
|
||||
return err
|
||||
})
|
||||
}); err != nil {
|
||||
@ -256,7 +256,7 @@ func (s *scenario) addressDraftChanged(draftIndex int, address, username string,
|
||||
}
|
||||
}
|
||||
|
||||
changes := liteapi.DraftTemplate{
|
||||
changes := proton.DraftTemplate{
|
||||
Subject: wantMessages[0].Subject,
|
||||
Body: string(encBody),
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user