From 39b366ee69437ef0d15263faecbaed2265b0948f Mon Sep 17 00:00:00 2001 From: James Houlahan Date: Thu, 6 Oct 2022 13:12:44 +0200 Subject: [PATCH] GODT-1650: Password as bytes in API login --- go.mod | 2 +- go.sum | 2 ++ internal/bridge/user.go | 2 +- internal/dialer/dialer_pinning_test.go | 10 ++++----- internal/user/user_test.go | 31 +------------------------- 5 files changed, 10 insertions(+), 37 deletions(-) diff --git a/go.mod b/go.mod index a82df419..3c5f0446 100644 --- a/go.mod +++ b/go.mod @@ -38,7 +38,7 @@ require ( github.com/sirupsen/logrus v1.9.0 github.com/stretchr/testify v1.8.0 github.com/urfave/cli/v2 v2.16.3 - gitlab.protontech.ch/go/liteapi v0.33.2-0.20221006105817-e76abecc140a + gitlab.protontech.ch/go/liteapi v0.33.2-0.20221006110959-d7a4b4b315b8 golang.org/x/exp v0.0.0-20220921164117-439092de6870 golang.org/x/net v0.1.0 golang.org/x/sys v0.1.0 diff --git a/go.sum b/go.sum index 17d5da67..89db2edc 100644 --- a/go.sum +++ b/go.sum @@ -477,6 +477,8 @@ gitlab.protontech.ch/go/liteapi v0.33.2-0.20221006095946-fc4061f2140b h1:Obu2CCC gitlab.protontech.ch/go/liteapi v0.33.2-0.20221006095946-fc4061f2140b/go.mod h1:9nsslyEJn7Utbielp4c+hc7qT6hqIJ52aGFR/tX+tYk= gitlab.protontech.ch/go/liteapi v0.33.2-0.20221006105817-e76abecc140a h1:dt6BahWRcy88dcXnEbm9m1X1W+RCZaVlo3W45V+vReQ= gitlab.protontech.ch/go/liteapi v0.33.2-0.20221006105817-e76abecc140a/go.mod h1:9nsslyEJn7Utbielp4c+hc7qT6hqIJ52aGFR/tX+tYk= +gitlab.protontech.ch/go/liteapi v0.33.2-0.20221006110959-d7a4b4b315b8 h1:/ZQr46sMG1H2ykKqBeYtScD7azHo7vgAkswmqGS0eHM= +gitlab.protontech.ch/go/liteapi v0.33.2-0.20221006110959-d7a4b4b315b8/go.mod h1:9nsslyEJn7Utbielp4c+hc7qT6hqIJ52aGFR/tX+tYk= 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= diff --git a/internal/bridge/user.go b/internal/bridge/user.go index 4536a3f2..2a766ede 100644 --- a/internal/bridge/user.go +++ b/internal/bridge/user.go @@ -81,7 +81,7 @@ func (bridge *Bridge) LoginUser( getTOTP func() (string, error), getKeyPass func() ([]byte, error), ) (string, error) { - client, auth, err := bridge.api.NewClientWithLogin(ctx, username, string(password)) + client, auth, err := bridge.api.NewClientWithLogin(ctx, username, password) if err != nil { return "", err } diff --git a/internal/dialer/dialer_pinning_test.go b/internal/dialer/dialer_pinning_test.go index 62b3537e..e4bd8d01 100644 --- a/internal/dialer/dialer_pinning_test.go +++ b/internal/dialer/dialer_pinning_test.go @@ -36,7 +36,7 @@ func getRootURL() string { func TestTLSPinValid(t *testing.T) { called, _, _, _, cm := createClientWithPinningDialer(getRootURL()) - _, _, _ = cm.NewClientWithLogin(context.Background(), "username", "password") + _, _, _ = cm.NewClientWithLogin(context.Background(), "username", []byte("password")) checkTLSIssueHandler(t, 0, called) } @@ -47,7 +47,7 @@ func TestTLSPinBackup(t *testing.T) { checker.trustedPins[1] = checker.trustedPins[0] checker.trustedPins[0] = "" - _, _, _ = cm.NewClientWithLogin(context.Background(), "username", "password") + _, _, _ = cm.NewClientWithLogin(context.Background(), "username", []byte("password")) checkTLSIssueHandler(t, 0, called) } @@ -58,7 +58,7 @@ func TestTLSPinInvalid(t *testing.T) { called, _, _, _, cm := createClientWithPinningDialer(s.GetHostURL()) - _, _, _ = cm.NewClientWithLogin(context.Background(), "username", "password") + _, _, _ = cm.NewClientWithLogin(context.Background(), "username", []byte("password")) checkTLSIssueHandler(t, 1, called) } @@ -73,8 +73,8 @@ func TestTLSPinNoMatch(t *testing.T) { checker.trustedPins[i] = "testing" } - _, _, _ = cm.NewClientWithLogin(context.Background(), "username", "password") - _, _, _ = cm.NewClientWithLogin(context.Background(), "username", "password") + _, _, _ = cm.NewClientWithLogin(context.Background(), "username", []byte("password")) + _, _, _ = cm.NewClientWithLogin(context.Background(), "username", []byte("password")) // Check that it will be reported only once per session, but notified every time. r.Equal(t, 1, len(reporter.sentReports)) diff --git a/internal/user/user_test.go b/internal/user/user_test.go index 877c1603..6f6f4ca7 100644 --- a/internal/user/user_test.go +++ b/internal/user/user_test.go @@ -10,9 +10,6 @@ import ( "github.com/ProtonMail/proton-bridge/v2/internal/user" "github.com/ProtonMail/proton-bridge/v2/internal/vault" "github.com/ProtonMail/proton-bridge/v2/tests" - "github.com/bradenaw/juniper/iterator" - "github.com/emersion/go-imap" - "github.com/emersion/go-imap/client" "github.com/stretchr/testify/require" "gitlab.protontech.ch/go/liteapi" "gitlab.protontech.ch/go/liteapi/server" @@ -114,7 +111,7 @@ func withAPI(t *testing.T, ctx context.Context, username, password string, email } func withUser(t *testing.T, ctx context.Context, apiURL, username, password string, fn func(*user.User)) { - c, apiAuth, err := liteapi.New(liteapi.WithHostURL(apiURL)).NewClientWithLogin(ctx, username, password) + c, apiAuth, err := liteapi.New(liteapi.WithHostURL(apiURL)).NewClientWithLogin(ctx, username, []byte(password)) require.NoError(t, err) defer func() { require.NoError(t, c.Close()) }() @@ -134,29 +131,3 @@ func withUser(t *testing.T, ctx context.Context, apiURL, username, password stri fn(user) } - -func withIMAPClient(t *testing.T, addr string, fn func(*client.Client)) { - c, err := client.Dial(addr) - require.NoError(t, err) - defer c.Close() - - fn(c) -} - -func fetch(t *testing.T, c *client.Client, seqset string, items ...imap.FetchItem) []*imap.Message { - msgCh := make(chan *imap.Message) - - go func() { - require.NoError(t, c.Fetch(must(imap.ParseSeqSet(seqset)), items, msgCh)) - }() - - return iterator.Collect(iterator.Chan(msgCh)) -} - -func must[T any](v T, err error) T { - if err != nil { - panic(err) - } - - return v -}