mirror of
https://github.com/ProtonMail/proton-bridge.git
synced 2025-12-17 23:56:56 +00:00
GODT-1650: Password as bytes in API login
This commit is contained in:
@ -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
|
||||
}
|
||||
|
||||
@ -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))
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user