feat(GODT-2283): Limit max import size to 30MB (bump GPA to v0.4.0)

This commit is contained in:
James Houlahan
2023-02-09 16:24:40 +01:00
parent 5f930c262c
commit 8b9265ad96
5 changed files with 23 additions and 10 deletions

2
go.mod
View File

@ -7,7 +7,7 @@ require (
github.com/Masterminds/semver/v3 v3.1.1 github.com/Masterminds/semver/v3 v3.1.1
github.com/ProtonMail/gluon v0.14.2-0.20230206162331-cf36d870802b github.com/ProtonMail/gluon v0.14.2-0.20230206162331-cf36d870802b
github.com/ProtonMail/go-autostart v0.0.0-20210130080809-00ed301c8e9a github.com/ProtonMail/go-autostart v0.0.0-20210130080809-00ed301c8e9a
github.com/ProtonMail/go-proton-api v0.3.1-0.20230209105544-b185be77ce15 github.com/ProtonMail/go-proton-api v0.4.0
github.com/ProtonMail/go-rfc5322 v0.11.0 github.com/ProtonMail/go-rfc5322 v0.11.0
github.com/ProtonMail/gopenpgp/v2 v2.4.10 github.com/ProtonMail/gopenpgp/v2 v2.4.10
github.com/PuerkitoBio/goquery v1.8.0 github.com/PuerkitoBio/goquery v1.8.0

4
go.sum
View File

@ -41,8 +41,8 @@ github.com/ProtonMail/go-message v0.0.0-20210611055058-fabeff2ec753/go.mod h1:NB
github.com/ProtonMail/go-mime v0.0.0-20220302105931-303f85f7fe0f/go.mod h1:NYt+V3/4rEeDuaev/zw1zCq8uqVEuPHzDPo3OZrlGJ4= github.com/ProtonMail/go-mime v0.0.0-20220302105931-303f85f7fe0f/go.mod h1:NYt+V3/4rEeDuaev/zw1zCq8uqVEuPHzDPo3OZrlGJ4=
github.com/ProtonMail/go-mime v0.0.0-20220429130430-2192574d760f h1:4IWzKjHzZxdrW9k4zl/qCwenOVHDbVDADPPHFLjs0Oc= github.com/ProtonMail/go-mime v0.0.0-20220429130430-2192574d760f h1:4IWzKjHzZxdrW9k4zl/qCwenOVHDbVDADPPHFLjs0Oc=
github.com/ProtonMail/go-mime v0.0.0-20220429130430-2192574d760f/go.mod h1:qRZgbeASl2a9OwmsV85aWwRqic0NHPh+9ewGAzb4cgM= github.com/ProtonMail/go-mime v0.0.0-20220429130430-2192574d760f/go.mod h1:qRZgbeASl2a9OwmsV85aWwRqic0NHPh+9ewGAzb4cgM=
github.com/ProtonMail/go-proton-api v0.3.1-0.20230209105544-b185be77ce15 h1:OiyETrhilrJGS4WXqKXdTO7LnzaDb00/4F3W4JqICrM= github.com/ProtonMail/go-proton-api v0.4.0 h1:Tw8Ieuc355ljPqpIzh/uttpE+5ia0z8GA/ca5iyl/9w=
github.com/ProtonMail/go-proton-api v0.3.1-0.20230209105544-b185be77ce15/go.mod h1:JUo5IQG0hNuPRuDpOUsCOvtee6UjTEHHF1QN2i8RSos= github.com/ProtonMail/go-proton-api v0.4.0/go.mod h1:JUo5IQG0hNuPRuDpOUsCOvtee6UjTEHHF1QN2i8RSos=
github.com/ProtonMail/go-rfc5322 v0.11.0 h1:o5Obrm4DpmQEffvgsVqG6S4BKwC1Wat+hYwjIp2YcCY= github.com/ProtonMail/go-rfc5322 v0.11.0 h1:o5Obrm4DpmQEffvgsVqG6S4BKwC1Wat+hYwjIp2YcCY=
github.com/ProtonMail/go-rfc5322 v0.11.0/go.mod h1:6oOKr0jXvpoE6pwTx/HukigQpX2J9WUf6h0auplrFTw= github.com/ProtonMail/go-rfc5322 v0.11.0/go.mod h1:6oOKr0jXvpoE6pwTx/HukigQpX2J9WUf6h0auplrFTw=
github.com/ProtonMail/go-srp v0.0.5 h1:xhUioxZgDbCnpo9JehyFhwwsn9JLWkUGfB0oiKXgiGg= github.com/ProtonMail/go-srp v0.0.5 h1:xhUioxZgDbCnpo9JehyFhwwsn9JLWkUGfB0oiKXgiGg=

View File

@ -431,7 +431,7 @@ func createMessages(ctx context.Context, t *testing.T, c *proton.Client, addrID,
_, ok := addrKRs[addrID] _, ok := addrKRs[addrID]
require.True(t, ok) require.True(t, ok)
res, err := stream.Collect(ctx, c.ImportMessages( str, err := c.ImportMessages(
ctx, ctx,
addrKRs[addrID], addrKRs[addrID],
runtime.NumCPU(), runtime.NumCPU(),
@ -446,7 +446,10 @@ func createMessages(ctx context.Context, t *testing.T, c *proton.Client, addrID,
Message: message, Message: message,
} }
})..., })...,
)) )
require.NoError(t, err)
res, err := stream.Collect(ctx, str)
require.NoError(t, err) require.NoError(t, err)
return xslices.Map(res, func(res proton.ImportRes) string { return xslices.Map(res, func(res proton.ImportRes) string {

View File

@ -538,7 +538,7 @@ func (conn *imapConnector) importMessage(
messageID = msg.ID messageID = msg.ID
} else { } else {
res, err := stream.Collect(ctx, conn.client.ImportMessages(ctx, addrKR, 1, 1, []proton.ImportReq{{ str, err := conn.client.ImportMessages(ctx, addrKR, 1, 1, []proton.ImportReq{{
Metadata: proton.ImportMetadata{ Metadata: proton.ImportMetadata{
AddressID: conn.addrID, AddressID: conn.addrID,
LabelIDs: labelIDs, LabelIDs: labelIDs,
@ -546,7 +546,12 @@ func (conn *imapConnector) importMessage(
Flags: flags, Flags: flags,
}, },
Message: literal, Message: literal,
}}...)) }}...)
if err != nil {
return fmt.Errorf("failed to prepare message for import: %w", err)
}
res, err := stream.Collect(ctx, str)
if err != nil { if err != nil {
return fmt.Errorf("failed to import message: %w", err) return fmt.Errorf("failed to import message: %w", err)
} }

View File

@ -124,14 +124,19 @@ func (t *testCtx) withAddrKR(
func (t *testCtx) createMessages(ctx context.Context, username, addrID string, req []proton.ImportReq) 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.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 { return t.withAddrKR(ctx, c, username, addrID, func(ctx context.Context, addrKR *crypto.KeyRing) error {
if _, err := stream.Collect(ctx, c.ImportMessages( str, err := c.ImportMessages(
ctx, ctx,
addrKR, addrKR,
runtime.NumCPU(), runtime.NumCPU(),
runtime.NumCPU(), runtime.NumCPU(),
req..., req...,
)); err != nil { )
return err if err != nil {
return fmt.Errorf("failed to prepare messages for import: %w", err)
}
if _, err := stream.Collect(ctx, str); err != nil {
return fmt.Errorf("failed to import messages: %w", err)
} }
return nil return nil