mirror of
https://github.com/ProtonMail/proton-bridge.git
synced 2025-12-10 04:36:43 +00:00
feat(BRIDGE-120): use appropriate address key when importing / saving draft.
This commit is contained in:
@ -20,11 +20,15 @@ package tests
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/ProtonMail/go-proton-api"
|
||||
"github.com/ProtonMail/gopenpgp/v2/crypto"
|
||||
"github.com/cucumber/godog"
|
||||
)
|
||||
|
||||
@ -116,7 +120,7 @@ func (s *scenario) checkParsedMultipartFormForFile(method, path, file string, ha
|
||||
}
|
||||
|
||||
if _, ok := req.MultipartForm.File[file]; hasFile != ok {
|
||||
return fmt.Errorf("Multipart file in bug report is %t, want it to be %t", ok, hasFile)
|
||||
return fmt.Errorf("multipart file in bug report is %t, want it to be %t", ok, hasFile)
|
||||
}
|
||||
|
||||
return nil
|
||||
@ -240,3 +244,57 @@ func (s *scenario) theMessageUsedKeyForSending(address string) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *scenario) theKeyForAddressWasUsedToImport(address string) error {
|
||||
// Response does not include the address ID, only the messageID, so we extract the messageID from the response body
|
||||
call, err := s.t.getLastCallExcludingHTTPOverride("POST", "/mail/v4/messages/import")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var resp struct {
|
||||
Responses []struct{ Response struct{ MessageID string } }
|
||||
}
|
||||
|
||||
if err := json.Unmarshal(call.ResponseBody, &resp); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return s.checkMessageIsEncryptedForAddress(resp.Responses[0].Response.MessageID, address)
|
||||
}
|
||||
|
||||
func (s *scenario) theKeyForAddressWasUsedToCreateDraft(address string) error {
|
||||
call, err := s.t.getLastCallExcludingHTTPOverride("POST", "/mail/v4/messages")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var resp struct{ Message struct{ ID string } }
|
||||
if err := json.Unmarshal(call.ResponseBody, &resp); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return s.checkMessageIsEncryptedForAddress(resp.Message.ID, address)
|
||||
}
|
||||
|
||||
func (s *scenario) checkMessageIsEncryptedForAddress(messageID string, address string) error {
|
||||
user := s.t.getUserByAddress(address)
|
||||
addrID := user.getAddrID(address)
|
||||
return s.t.withClient(context.Background(), user.getName(), func(ctx context.Context, client *proton.Client) error {
|
||||
message, err := client.GetMessage(ctx, messageID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Check 1: the address associated with the message is the one we expect.
|
||||
if message.AddressID != addrID {
|
||||
return errors.New("the message is not encrypted with the specified address")
|
||||
}
|
||||
|
||||
// Check 2: we indeed encrypted the message with this address' key ring.
|
||||
return s.t.withAddrKR(ctx, client, user.name, addrID, func(_ context.Context, kr *crypto.KeyRing) error {
|
||||
_, err := message.Decrypt(kr)
|
||||
return err
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
136
tests/features/imap/message/import_key.feature
Normal file
136
tests/features/imap/message/import_key.feature
Normal file
@ -0,0 +1,136 @@
|
||||
Feature: IMAP import messages
|
||||
|
||||
Background:
|
||||
Given there exists an account with username "[user:user]" and password "password"
|
||||
And the account "[user:user]" has additional address "[alias:secondary]@[domain]"
|
||||
And the account "[user:user]" has additional disabled address "[alias:disabled]@[domain]"
|
||||
Then it succeeds
|
||||
When bridge starts
|
||||
And the user logs in with username "[user:user]" and password "password"
|
||||
And user "[user:user]" finishes syncing
|
||||
And user "[user:user]" connects and authenticates IMAP client "1"
|
||||
Then it succeeds
|
||||
|
||||
@skip-black
|
||||
Scenario: Messages imported with default address as sender are encrypted with the default address key
|
||||
When IMAP client "1" appends the following message to "INBOX":
|
||||
"""
|
||||
From: Bridge Test <[user:user]@[domain]>
|
||||
Date: 01 Jan 1980 00:00:00 +0000
|
||||
To: Internal Bridge <bridgetest@example.com>
|
||||
Received: by 2002:0:0:0:0:0:0:0 with SMTP id 0123456789abcdef; Wed, 30 Dec 2020 01:23:45 0000
|
||||
Subject: Basic text/plain message
|
||||
Content-Type: text/plain
|
||||
|
||||
Hello
|
||||
"""
|
||||
Then it succeeds
|
||||
And the key for address "[user:user]@[domain]" was used to import
|
||||
|
||||
@skip-black
|
||||
Scenario: Messages imported with alias as sender are encrypted with secondary address key
|
||||
When IMAP client "1" appends the following message to "INBOX":
|
||||
"""
|
||||
From: Bridge Test <[alias:secondary]@[domain]>
|
||||
Date: 01 Jan 1980 00:00:00 +0000
|
||||
To: Internal Bridge <bridgetest@example.com>
|
||||
Received: by 2002:0:0:0:0:0:0:0 with SMTP id 0123456789abcdef; Wed, 30 Dec 2020 01:23:45 0000
|
||||
Subject: Basic text/plain message
|
||||
Content-Type: text/plain
|
||||
|
||||
Hello
|
||||
"""
|
||||
Then it succeeds
|
||||
And the key for address "[alias:secondary]@[domain]" was used to import
|
||||
|
||||
@skip-black
|
||||
Scenario: Messages imported with a disabled alias as sender are encrypted with the disabled address key
|
||||
When IMAP client "1" appends the following message to "INBOX":
|
||||
"""
|
||||
From: Bridge Test <[alias:disabled]@[domain]>
|
||||
Date: 01 Jan 1980 00:00:00 +0000
|
||||
To: Internal Bridge <bridgetest@example.com>
|
||||
Received: by 2002:0:0:0:0:0:0:0 with SMTP id 0123456789abcdef; Wed, 30 Dec 2020 01:23:45 0000
|
||||
Subject: Basic text/plain message
|
||||
Content-Type: text/plain
|
||||
|
||||
Hello
|
||||
"""
|
||||
Then it succeeds
|
||||
And the key for address "[alias:disabled]@[domain]" was used to import
|
||||
|
||||
@skip-black
|
||||
Scenario: Messages imported with an unknown address as sender are encrypted with primary address key
|
||||
When IMAP client "1" appends the following message to "INBOX":
|
||||
"""
|
||||
From: Bridge Test <bridgeqa@example.com>
|
||||
Date: 01 Jan 1980 00:00:00 +0000
|
||||
To: Internal Bridge <bridgetest@example.com>
|
||||
Received: by 2002:0:0:0:0:0:0:0 with SMTP id 0123456789abcdef; Wed, 30 Dec 2020 01:23:45 0000
|
||||
Subject: Basic text/plain message
|
||||
Content-Type: text/plain
|
||||
|
||||
Hello
|
||||
"""
|
||||
Then it succeeds
|
||||
And the key for address "[user:user]@[domain]" was used to import
|
||||
|
||||
@skip-black
|
||||
Scenario: Drafts imported with default address as sender are encrypted with the default address key
|
||||
When IMAP client "1" appends the following message to "Drafts":
|
||||
"""
|
||||
From: Bridge Test <[user:user]@[domain]>
|
||||
Date: 01 Jan 1980 00:00:00 +0000
|
||||
To: Internal Bridge <bridgetest@example.com>
|
||||
Subject: Basic text/plain message
|
||||
Content-Type: text/plain
|
||||
|
||||
Hello
|
||||
"""
|
||||
Then it succeeds
|
||||
And the key for address "[user:user]@[domain]" was used to create draft
|
||||
|
||||
@skip-black
|
||||
Scenario: Drafts imported with alias as sender are encrypted with secondary key
|
||||
When IMAP client "1" appends the following message to "Drafts":
|
||||
"""
|
||||
From: Bridge Test <[alias:secondary]@[domain]>
|
||||
Date: 01 Jan 1980 00:00:00 +0000
|
||||
To: Internal Bridge <bridgetest@example.com>
|
||||
Subject: Basic text/plain message
|
||||
Content-Type: text/plain
|
||||
|
||||
Hello
|
||||
"""
|
||||
Then it succeeds
|
||||
And the key for address "[alias:secondary]@[domain]" was used to create draft
|
||||
|
||||
@skip-black
|
||||
Scenario: Drafts imported with a disabled alias as sender are encrypted with the disabled address key
|
||||
When IMAP client "1" appends the following message to "Drafts":
|
||||
"""
|
||||
From: Bridge Test <[alias:disabled]@[domain]>
|
||||
Date: 01 Jan 1980 00:00:00 +0000
|
||||
To: Internal Bridge <bridgetest@example.com>
|
||||
Subject: Basic text/plain message
|
||||
Content-Type: text/plain
|
||||
|
||||
Hello
|
||||
"""
|
||||
Then it succeeds
|
||||
And the key for address "[user:user]@[domain]" was used to create drafts
|
||||
|
||||
@skip-black
|
||||
Scenario: Drafts imported with an unknown address as sender are encrypted with primary address key
|
||||
When IMAP client "1" appends the following message to "Drafts":
|
||||
"""
|
||||
From: Bridge Test <bridgeqa@example.com>
|
||||
Date: 01 Jan 1980 00:00:00 +0000
|
||||
To: Internal Bridge <bridgetest@example.com>
|
||||
Subject: Basic text/plain message
|
||||
Content-Type: text/plain
|
||||
|
||||
Hello
|
||||
"""
|
||||
Then it succeeds
|
||||
And the key for address "[user:user]@[domain]" was used to create draft
|
||||
@ -39,6 +39,8 @@ func (s *scenario) steps(ctx *godog.ScenarioContext) {
|
||||
ctx.Step(`^bridge IMAP port is (\d+)`, s.bridgeIMAPPortIs)
|
||||
ctx.Step(`^bridge SMTP port is (\d+)`, s.bridgeSMTPPortIs)
|
||||
ctx.Step(`^the message used "([^"]*)" key for sending$`, s.theMessageUsedKeyForSending)
|
||||
ctx.Step(`^the key for address "([^"]*)" was used to import`, s.theKeyForAddressWasUsedToImport)
|
||||
ctx.Step(`^the key for address "([^"]*)" was used to create draft`, s.theKeyForAddressWasUsedToCreateDraft)
|
||||
|
||||
// ==== SETUP ====
|
||||
ctx.Step(`^there exists an account with username "([^"]*)" and password "([^"]*)"$`, s.thereExistsAnAccountWithUsernameAndPassword)
|
||||
|
||||
Reference in New Issue
Block a user