From 5747b85543442c794bd8a9157adc70036de7f3d3 Mon Sep 17 00:00:00 2001 From: Romain Le Jeune Date: Wed, 18 Oct 2023 07:45:08 +0000 Subject: [PATCH] test: Add test around account settings. --- go.mod | 2 +- go.sum | 4 ++-- tests/features/user/account.feature | 12 +++++++++++- tests/steps_test.go | 1 + tests/types_test.go | 8 ++++++++ tests/user_test.go | 26 ++++++++++++++++++++++++++ 6 files changed, 49 insertions(+), 4 deletions(-) diff --git a/go.mod b/go.mod index d0fed8e9..972bfa36 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ require ( github.com/Masterminds/semver/v3 v3.2.0 github.com/ProtonMail/gluon v0.17.1-0.20231009084701-3af0474b0b3c github.com/ProtonMail/go-autostart v0.0.0-20210130080809-00ed301c8e9a - github.com/ProtonMail/go-proton-api v0.4.1-0.20231016151024-8f03c5a977df + github.com/ProtonMail/go-proton-api v0.4.1-0.20231018070752-2449db500edd github.com/ProtonMail/gopenpgp/v2 v2.7.3-proton github.com/PuerkitoBio/goquery v1.8.1 github.com/abiosoft/ishell v2.0.0+incompatible diff --git a/go.sum b/go.sum index c8cc7f78..17abd677 100644 --- a/go.sum +++ b/go.sum @@ -34,8 +34,8 @@ github.com/ProtonMail/go-message v0.13.1-0.20230526094639-b62c999c85b7 h1:+j+Kd/ github.com/ProtonMail/go-message v0.13.1-0.20230526094639-b62c999c85b7/go.mod h1:NBAn21zgCJ/52WLDyed18YvYFm5tEoeDauubFqLokM4= github.com/ProtonMail/go-mime v0.0.0-20230322103455-7d82a3887f2f h1:tCbYj7/299ekTTXpdwKYF8eBlsYsDVoggDAuAjoK66k= github.com/ProtonMail/go-mime v0.0.0-20230322103455-7d82a3887f2f/go.mod h1:gcr0kNtGBqin9zDW9GOHcVntrwnjrK+qdJ06mWYBybw= -github.com/ProtonMail/go-proton-api v0.4.1-0.20231016151024-8f03c5a977df h1:4UteX2UmmLe1xvn3HmdhLUjtwKuOMxzSa/tPsUvnX7s= -github.com/ProtonMail/go-proton-api v0.4.1-0.20231016151024-8f03c5a977df/go.mod h1:ZmvQMA8hanLiD1tFsvu9+qGBcuxbIRfch/4z/nqBhXA= +github.com/ProtonMail/go-proton-api v0.4.1-0.20231018070752-2449db500edd h1:/Z3nwzsVeSwTFkrIKG7BLD24P4cxpaJBn8mzbSe2kPg= +github.com/ProtonMail/go-proton-api v0.4.1-0.20231018070752-2449db500edd/go.mod h1:ZmvQMA8hanLiD1tFsvu9+qGBcuxbIRfch/4z/nqBhXA= github.com/ProtonMail/go-srp v0.0.7 h1:Sos3Qk+th4tQR64vsxGIxYpN3rdnG9Wf9K4ZloC1JrI= github.com/ProtonMail/go-srp v0.0.7/go.mod h1:giCp+7qRnMIcCvI6V6U3S1lDDXDQYx2ewJ6F/9wdlJk= github.com/ProtonMail/gopenpgp/v2 v2.7.3-proton h1:wuAxBUU9qF2wyDVJprn/2xPDx000eol5gwlKbOUYY88= diff --git a/tests/features/user/account.feature b/tests/features/user/account.feature index 21da4a6d..c5acef2a 100644 --- a/tests/features/user/account.feature +++ b/tests/features/user/account.feature @@ -6,4 +6,14 @@ Feature: Account settings When bridge starts Scenario: Check account default settings - the account "[user:user]" has default draft format "HTML" \ No newline at end of file + Then the account "[user:user]" matches the following settings: + | DraftMIMEType | AttachPublicKey | Sign | PGPScheme | + | text/html | false | 0 | 0 | + When the account "[user:user]" has public key attachment "enabled" + And the account "[user:user]" has sign external messages "enabled" + And the account "[user:user]" has default draft format "plain" + And the account "[user:user]" has default PGP schema "inline" + Then the account "[user:user]" matches the following settings: + | DraftMIMEType | AttachPublicKey | Sign | PGPScheme | + | text/plain | true | 1 | 8 | + diff --git a/tests/steps_test.go b/tests/steps_test.go index 5df03455..cc68deba 100644 --- a/tests/steps_test.go +++ b/tests/steps_test.go @@ -114,6 +114,7 @@ func (s *scenario) steps(ctx *godog.ScenarioContext) { ctx.Step(`^the account "([^"]*)" has sign external messages "([^"]*)"`, s.accountHasSignExternalMessages) ctx.Step(`^the account "([^"]*)" has default draft format "([^"]*)"`, s.accountHasDefaultDraftFormat) ctx.Step(`^the account "([^"]*)" has default PGP schema "([^"]*)"`, s.accountHasDefaultPGPSchema) + ctx.Step(`^the account "([^"]*)" matches the following settings:$`, s.accountMatchesSettings) // ==== IMAP ==== ctx.Step(`^user "([^"]*)" connects IMAP client "([^"]*)"$`, s.userConnectsIMAPClient) diff --git a/tests/types_test.go b/tests/types_test.go index b0da0668..083cf669 100644 --- a/tests/types_test.go +++ b/tests/types_test.go @@ -28,6 +28,7 @@ import ( "time" "github.com/ProtonMail/gluon/rfc822" + "github.com/ProtonMail/go-proton-api" "github.com/ProtonMail/proton-bridge/v3/pkg/message" "github.com/ProtonMail/proton-bridge/v3/pkg/message/parser" pmmime "github.com/ProtonMail/proton-bridge/v3/pkg/mime" @@ -555,3 +556,10 @@ type Contact struct { Sign string `bdd:"signature"` Encrypt string `bdd:"encryption"` } + +type MailSettings struct { + DraftMIMEType rfc822.MIMEType `bdd:"DraftMIMEType"` + AttachPublicKey proton.Bool `bdd:"AttachPublicKey"` + Sign proton.SignExternalMessages `bdd:"Sign"` + PGPScheme proton.EncryptionScheme `bdd:"PGPScheme"` +} diff --git a/tests/user_test.go b/tests/user_test.go index 7670cb3d..569dc05c 100644 --- a/tests/user_test.go +++ b/tests/user_test.go @@ -643,3 +643,29 @@ func (s *scenario) accountHasDefaultPGPSchema(account, schema string) error { return err }) } + +func (s *scenario) accountMatchesSettings(account string, table *godog.Table) error { + return s.t.withClient(context.Background(), account, func(ctx context.Context, c *proton.Client) error { + wantSettings, err := unmarshalTable[MailSettings](table) + if err != nil { + return err + } + settings, err := c.GetMailSettings(ctx) + if err != nil { + return err + } + if len(wantSettings) != 1 { + return errors.New("this step only supports one settings definition at a time") + } + + return matchSettings(settings, wantSettings[0]) + }) +} + +func matchSettings(have proton.MailSettings, want MailSettings) error { + if !IsSub(ToAny(have), ToAny(want)) { + return fmt.Errorf("missing mailsettings: have %#v, want %#v", have, want) + } + + return nil +}