GODT-2170: Use client-side draft update in integration tests

This commit is contained in:
James Houlahan
2022-12-02 12:47:12 +01:00
parent 01c7daaba7
commit 7bc608ce6c
7 changed files with 63 additions and 54 deletions

2
go.mod
View File

@ -7,7 +7,7 @@ require (
github.com/Masterminds/semver/v3 v3.1.1
github.com/ProtonMail/gluon v0.14.2-0.20221202093012-ad1570c49c8c
github.com/ProtonMail/go-autostart v0.0.0-20210130080809-00ed301c8e9a
github.com/ProtonMail/go-proton-api v0.1.4-0.20221201145430-b0a0286c470e
github.com/ProtonMail/go-proton-api v0.1.5
github.com/ProtonMail/go-rfc5322 v0.11.0
github.com/ProtonMail/gopenpgp/v2 v2.4.10
github.com/PuerkitoBio/goquery v1.8.0

4
go.sum
View File

@ -43,8 +43,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-20220429130430-2192574d760f h1:4IWzKjHzZxdrW9k4zl/qCwenOVHDbVDADPPHFLjs0Oc=
github.com/ProtonMail/go-mime v0.0.0-20220429130430-2192574d760f/go.mod h1:qRZgbeASl2a9OwmsV85aWwRqic0NHPh+9ewGAzb4cgM=
github.com/ProtonMail/go-proton-api v0.1.4-0.20221201145430-b0a0286c470e h1:PQIbcD4ZpHsZaLT2RcVuoWi7yl2f2x51KthTrerOpqI=
github.com/ProtonMail/go-proton-api v0.1.4-0.20221201145430-b0a0286c470e/go.mod h1:jqvJ2HqLHqiPJoEb+BTIB1IF7wvr6p+8ZfA6PO2NRNk=
github.com/ProtonMail/go-proton-api v0.1.5 h1:6RJO3jXP3opFfGqrXNvFTefdD4MlfxKjIebT8r5ROf8=
github.com/ProtonMail/go-proton-api v0.1.5/go.mod h1:jqvJ2HqLHqiPJoEb+BTIB1IF7wvr6p+8ZfA6PO2NRNk=
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-srp v0.0.5 h1:xhUioxZgDbCnpo9JehyFhwwsn9JLWkUGfB0oiKXgiGg=

View File

@ -19,7 +19,6 @@ package tests
import (
"github.com/Masterminds/semver/v3"
"github.com/ProtonMail/go-proton-api"
"github.com/ProtonMail/go-proton-api/server"
)
@ -36,8 +35,6 @@ type API interface {
RemoveAddress(userID, addrID string) error
RemoveAddressKey(userID, addrID, keyID string) error
UpdateDraft(userID, draftID string, changes proton.DraftTemplate) error
Close()
}

View File

@ -98,7 +98,7 @@ func TestFeatures(testingT *testing.T) {
ctx.Step(`^the address "([^"]*)" of account "([^"]*)" has the following messages in "([^"]*)":$`, s.theAddressOfAccountHasTheFollowingMessagesInMailbox)
ctx.Step(`^the address "([^"]*)" of account "([^"]*)" has (\d+) messages in "([^"]*)"$`, s.theAddressOfAccountHasMessagesInMailbox)
ctx.Step(`^the address "([^"]*)" of account "([^"]*)" has no keys$`, s.theAddressOfAccountHasNoKeys)
ctx.Step(`^the following fields where changed in draft (\d+) for address "([^"]*)" of account "([^"]*)":$`, s.addressDraftChanged)
ctx.Step(`^the following fields were changed in draft (\d+) for address "([^"]*)" of account "([^"]*)":$`, s.theFollowingFieldsWereChangedInDraftForAddressOfAccount)
// ==== BRIDGE ====
ctx.Step(`^bridge starts$`, s.bridgeStarts)

View File

@ -230,36 +230,28 @@ func (t *testCtx) getMBoxID(userID string, name string) string {
// getDraftID will return the API ID of draft message with draftIndex, where
// draftIndex is similar to sequential ID i.e. 1 represents the first message
// of draft folder sorted by API creation time.
func (t *testCtx) getDraftID(username string, draftIndex int) string {
if draftIndex < 1 {
panic(fmt.Sprintf("draft index suppose to be non-zero positive integer, but have %d", draftIndex))
}
func (t *testCtx) getDraftID(username string, draftIndex int) (string, error) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
var draftID string
if err := t.withClient(ctx, username, func(ctx context.Context, client *proton.Client) error {
messages, err := client.GetMessageMetadata(
ctx, proton.MessageFilter{LabelID: proton.DraftsLabel},
)
messages, err := client.GetMessageMetadata(ctx, proton.MessageFilter{LabelID: proton.DraftsLabel})
if err != nil {
panic(err)
}
if len(messages) < draftIndex {
panic("draft index too high")
return fmt.Errorf("failed to get message metadata: %w", err)
} else if len(messages) < draftIndex {
return fmt.Errorf("draft index %d is out of range", draftIndex)
}
draftID = messages[draftIndex-1].ID
return nil
}); err != nil {
panic(err)
return "", err
}
return draftID
return draftID, nil
}
func (t *testCtx) getLastCall(method, pathExp string) (server.Call, error) {

View File

@ -34,7 +34,7 @@ Feature: IMAP Draft messages
And IMAP client "1" sees 1 messages in "Drafts"
Scenario: Draft edited remotely
When the following fields where changed in draft 1 for address "user@pm.me" of account "user@pm.me":
When the following fields were changed in draft 1 for address "user@pm.me" of account "user@pm.me":
| to | subject | body |
| someone@proton.me | Basic Draft | This is a draft body, but longer |
Then IMAP client "1" eventually sees the following messages in "Drafts":

View File

@ -226,7 +226,7 @@ func (s *scenario) theAddressOfAccountHasNoKeys(address, username string) error
// accountDraftChanged changes the draft attributes, where draftIndex is
// similar to sequential ID i.e. 1 represents the first message of draft folder
// sorted by API creation time.
func (s *scenario) addressDraftChanged(draftIndex int, address, username string, table *godog.Table) error {
func (s *scenario) theFollowingFieldsWereChangedInDraftForAddressOfAccount(draftIndex int, address, username string, table *godog.Table) error {
wantMessages, err := unmarshalTable[Message](table)
if err != nil {
return err
@ -236,39 +236,59 @@ func (s *scenario) addressDraftChanged(draftIndex int, address, username string,
return fmt.Errorf("expected to have one row in table but got %d instead", len(wantMessages))
}
draftID := s.t.getDraftID(username, draftIndex)
draftID, err := s.t.getDraftID(username, draftIndex)
if err != nil {
return fmt.Errorf("failed to get draft ID: %w", err)
}
encBody := ""
if wantMessages[0].Body != "" {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
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 {
msg, err := addrKR.Encrypt(crypto.NewPlainMessage([]byte(wantMessages[0].Body)), addrKR)
if err != nil {
return err
return 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(_ context.Context, addrKR *crypto.KeyRing) error {
var changes proton.DraftTemplate
if wantMessages[0].From != "" {
return fmt.Errorf("changing from address is not supported")
}
encBody, err = msg.GetArmored()
return err
})
}); err != nil {
return err
}
}
changes := proton.DraftTemplate{
Subject: wantMessages[0].Subject,
Body: encBody,
}
if wantMessages[0].To != "" {
changes.ToList = []*mail.Address{{Address: wantMessages[0].To}}
}
return s.t.api.UpdateDraft(s.t.getUserID(username), draftID, changes)
if wantMessages[0].CC != "" {
changes.CCList = []*mail.Address{{Address: wantMessages[0].CC}}
}
if wantMessages[0].BCC != "" {
changes.BCCList = []*mail.Address{{Address: wantMessages[0].BCC}}
}
if wantMessages[0].Subject != "" {
changes.Subject = wantMessages[0].Subject
}
if wantMessages[0].Body != "" {
enc, err := addrKR.Encrypt(crypto.NewPlainMessageFromString(wantMessages[0].Body), addrKR)
if err != nil {
return fmt.Errorf("failed to encrypt message body: %w", err)
}
arm, err := enc.GetArmored()
if err != nil {
return fmt.Errorf("failed to get armored message: %w", err)
}
changes.Body = arm
}
if _, err := c.UpdateDraft(ctx, draftID, proton.UpdateDraftReq{Message: changes}); err != nil {
return fmt.Errorf("failed to update draft: %w", err)
}
return nil
})
})
}
func (s *scenario) userLogsInWithUsernameAndPassword(username, password string) error {