From 79524185a85ba67e0ee26cd39070a02dc741872e Mon Sep 17 00:00:00 2001 From: Romain LE JEUNE Date: Mon, 4 Sep 2023 16:48:59 +0200 Subject: [PATCH] feat(GODT-2734): Add testing steps to modify account settings. --- tests/steps_test.go | 6 +++++ tests/user_test.go | 65 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+) diff --git a/tests/steps_test.go b/tests/steps_test.go index eb6d7af6..afe452b8 100644 --- a/tests/steps_test.go +++ b/tests/steps_test.go @@ -109,6 +109,12 @@ func (s *scenario) steps(ctx *godog.ScenarioContext) { ctx.Step(`^the bridge password of user "([^"]*)" is changed to "([^"]*)"`, s.bridgePasswordOfUserIsChangedTo) ctx.Step(`^the bridge password of user "([^"]*)" is equal to "([^"]*)"`, s.bridgePasswordOfUserIsEqualTo) + // ==== ACCOUNT SETTINGS ==== + ctx.Step(`^the account "([^"]*)" has public key attachment "([^"]*)"`, s.accountHasPublicKeyAttachment) + 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) + // ==== IMAP ==== ctx.Step(`^user "([^"]*)" connects IMAP client "([^"]*)"$`, s.userConnectsIMAPClient) ctx.Step(`^user "([^"]*)" connects IMAP client "([^"]*)" on port (\d+)$`, s.userConnectsIMAPClientOnPort) diff --git a/tests/user_test.go b/tests/user_test.go index a6b31636..afc446fa 100644 --- a/tests/user_test.go +++ b/tests/user_test.go @@ -578,3 +578,68 @@ func (s *scenario) createUserAccount(username, password string, disabled bool) e return nil }) } + +func (s *scenario) accountHasPublicKeyAttachment(account, enabled string) error { + value := true + switch { + case enabled == "enabled": + value = true + case enabled == "disabled": + value = false + default: + return errors.New("parameter should either be 'enabled' or 'disabled'") + } + + return s.t.withClient(context.Background(), account, func(ctx context.Context, c *proton.Client) error { + _, err := c.SetAttachPublicKey(ctx, proton.SetAttachPublicKeyReq{AttachPublicKey: proton.Bool(value)}) + return err + }) +} + +func (s *scenario) accountHasSignExternalMessages(account, enabled string) error { + value := proton.SignExternalMessagesDisabled + switch { + case enabled == "enabled": + value = proton.SignExternalMessagesEnabled + case enabled == "disabled": + value = proton.SignExternalMessagesDisabled + default: + return errors.New("parameter should either be 'enabled' or 'disabled'") + } + return s.t.withClient(context.Background(), account, func(ctx context.Context, c *proton.Client) error { + _, err := c.SetSignExternalMessages(ctx, proton.SetSignExternalMessagesReq{Sign: value}) + return err + }) +} + +func (s *scenario) accountHasDefaultDraftFormat(account, format string) error { + value := rfc822.TextPlain + switch { + case format == "plain": + value = rfc822.TextPlain + case format == "HTML": + value = rfc822.TextHTML + default: + return errors.New("parameter should either be 'plain' or 'HTML'") + } + return s.t.withClient(context.Background(), account, func(ctx context.Context, c *proton.Client) error { + _, err := c.SetDraftMIMEType(ctx, proton.SetDraftMIMETypeReq{MIMEType: value}) + return err + }) +} + +func (s *scenario) accountHasDefaultPGPSchema(account, schema string) error { + value := proton.PGPInlineScheme + switch { + case schema == "inline": + value = proton.PGPInlineScheme + case schema == "MIME": + value = proton.PGPMIMEScheme + default: + return errors.New("parameter should either be 'inline' or 'MIME'") + } + return s.t.withClient(context.Background(), account, func(ctx context.Context, c *proton.Client) error { + _, err := c.SetDefaultPGPScheme(ctx, proton.SetDefaultPGPSchemeReq{PGPScheme: value}) + return err + }) +}