forked from Silverfish/proton-bridge
test: Add test around account settings.
This commit is contained in:
@ -6,4 +6,14 @@ Feature: Account settings
|
||||
When bridge starts
|
||||
|
||||
Scenario: Check account default settings
|
||||
the account "[user:user]" has default draft format "HTML"
|
||||
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 |
|
||||
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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"`
|
||||
}
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user