Fixing lint and integration tests, changelog, GODT-880, and typos

This commit is contained in:
Jakub
2020-11-18 20:33:51 +01:00
committed by Jakub Cuth
parent 87c8228cd0
commit d380485bb6
3 changed files with 72 additions and 143 deletions

View File

@ -161,15 +161,17 @@ func NewSendMessageReq(
} }
var ( var (
errUnknownContentType = errors.New("unknown content type")
errMultipartInNonMIME = errors.New("multipart mixed not allowed in this scheme") errMultipartInNonMIME = errors.New("multipart mixed not allowed in this scheme")
errAttSignNotSupported = errors.New("attached signature not supported") errAttSignNotSupported = errors.New("attached signature not supported")
errEncryptMustSign = errors.New("encrypted package must be signed") errEncryptMustSign = errors.New("encrypted package must be signed")
errEONotSupported = errors.New("encrypted outside is not supported") errEONotSupported = errors.New("encrypted outside is not supported")
errWrongSendScheme = errors.New("wrong send scheme") errWrongSendScheme = errors.New("wrong send scheme")
errInternalMustEncrypt = errors.New("internal package must be encrypted") errInternalMustEncrypt = errors.New("internal package must be encrypted")
errInlinelMustEncrypt = errors.New("PGP Inline package must be encrypted") errInlineMustEncrypt = errors.New("PGP Inline package must be encrypted")
errMisingPubkey = errors.New("cannot encrypt body key packet: missing pubkey") errInlineMustBePlain = errors.New("PGP Inline package must be plain text")
errSignMustBeMultipart = errors.New("clear singed packet must be multipart") errMissingPubkey = errors.New("cannot encrypt body key packet: missing pubkey")
errSignMustBeMultipart = errors.New("clear signed html packet must be multipart")
errMIMEMustBeMultipart = errors.New("MIME packet must be multipart") errMIMEMustBeMultipart = errors.New("MIME packet must be multipart")
) )
@ -196,8 +198,9 @@ func (req *SendMessageReq) AddRecipient(
return req.addNonMIMERecipient(email, sendScheme, pubkey, signature, contentType, doEncrypt) return req.addNonMIMERecipient(email, sendScheme, pubkey, signature, contentType, doEncrypt)
case EncryptedOutsidePackage: case EncryptedOutsidePackage:
return errEONotSupported return errEONotSupported
default:
return errWrongSendScheme
} }
return errWrongSendScheme
} }
func (req *SendMessageReq) addNonMIMERecipient( func (req *SendMessageReq) addNonMIMERecipient(
@ -205,20 +208,25 @@ func (req *SendMessageReq) addNonMIMERecipient(
pubkey *crypto.KeyRing, signature int, pubkey *crypto.KeyRing, signature int,
contentType string, doEncrypt bool, contentType string, doEncrypt bool,
) (err error) { ) (err error) {
if sendScheme == ClearPackage && signature == SignatureDetached { if sendScheme == ClearPackage &&
signature == SignatureDetached &&
contentType == ContentTypeHTML {
return errSignMustBeMultipart return errSignMustBeMultipart
} }
var send *sendData var send *sendData
switch contentType { switch contentType {
case ContentTypePlainText: case ContentTypePlainText:
send = &req.plain send = &req.plain
send.contentType = contentType send.contentType = ContentTypePlainText
case ContentTypeHTML: case ContentTypeHTML, "":
send = &req.rich send = &req.rich
send.contentType = contentType send.contentType = ContentTypeHTML
case ContentTypeMultipartMixed: case ContentTypeMultipartMixed:
return errMultipartInNonMIME return errMultipartInNonMIME
default:
return errUnknownContentType
} }
if send.decryptedBodyKey == nil { if send.decryptedBodyKey == nil {
@ -229,13 +237,16 @@ func (req *SendMessageReq) addNonMIMERecipient(
newAddress := &MessageAddress{Type: sendScheme, Signature: signature} newAddress := &MessageAddress{Type: sendScheme, Signature: signature}
if sendScheme == PGPInlinePackage && !doEncrypt { if sendScheme == PGPInlinePackage && !doEncrypt {
return errInlinelMustEncrypt return errInlineMustEncrypt
}
if sendScheme == PGPInlinePackage && contentType == ContentTypeHTML {
return errInlineMustBePlain
} }
if sendScheme == InternalPackage && !doEncrypt { if sendScheme == InternalPackage && !doEncrypt {
return errInternalMustEncrypt return errInternalMustEncrypt
} }
if doEncrypt && pubkey == nil { if doEncrypt && pubkey == nil {
return errMisingPubkey return errMissingPubkey
} }
if doEncrypt { if doEncrypt {
@ -254,7 +265,6 @@ func (req *SendMessageReq) addMIMERecipient(
email string, sendScheme int, email string, sendScheme int,
pubkey *crypto.KeyRing, signature int, pubkey *crypto.KeyRing, signature int,
) (err error) { ) (err error) {
req.mime.contentType = ContentTypeMultipartMixed req.mime.contentType = ContentTypeMultipartMixed
if req.mime.decryptedBodyKey == nil { if req.mime.decryptedBodyKey == nil {
if req.mime.decryptedBodyKey, req.mime.ciphertext, err = encryptSymmDecryptKey(req.kr, req.mime.cleartext); err != nil { if req.mime.decryptedBodyKey, req.mime.ciphertext, err = encryptSymmDecryptKey(req.kr, req.mime.cleartext); err != nil {
@ -264,7 +274,7 @@ func (req *SendMessageReq) addMIMERecipient(
if sendScheme == PGPMIMEPackage { if sendScheme == PGPMIMEPackage {
if pubkey == nil { if pubkey == nil {
return errMisingPubkey return errMissingPubkey
} }
// Attachment keys are not needed because attachments are part // Attachment keys are not needed because attachments are part
// of MIME body and therefore attachments are encrypted with // of MIME body and therefore attachments are encrypted with

View File

@ -46,7 +46,7 @@ type testData struct {
func (td *testData) prepareAndCheck(t *testing.T) { func (td *testData) prepareAndCheck(t *testing.T) {
r := require.New(t) r := require.New(t)
shouldBeEmpty := func(want string) require.ValueAssertionFunc { matchPresence := func(want string) require.ValueAssertionFunc {
if len(want) == 0 { if len(want) == 0 {
return require.Empty return require.Empty
} }
@ -76,7 +76,7 @@ func (td *testData) prepareAndCheck(t *testing.T) {
r.True(ok, "pkg %d email %s", i, email) r.True(ok, "pkg %d email %s", i, email)
r.Equal(wantAddress.Type, haveAddress.Type, "pkg %d email %s", i, email) r.Equal(wantAddress.Type, haveAddress.Type, "pkg %d email %s", i, email)
shouldBeEmpty(wantAddress.EncryptedBodyKeyPacket)(t, haveAddress.EncryptedBodyKeyPacket, "pkg %d email %s", i, email) matchPresence(wantAddress.EncryptedBodyKeyPacket)(t, haveAddress.EncryptedBodyKeyPacket, "pkg %d email %s", i, email)
r.Equal(wantAddress.Signature, haveAddress.Signature, "pkg %d email %s", i, email) r.Equal(wantAddress.Signature, haveAddress.Signature, "pkg %d email %s", i, email)
if len(td.attKeys) == 0 { if len(td.attKeys) == 0 {
@ -90,7 +90,7 @@ func (td *testData) prepareAndCheck(t *testing.T) {
for attID, wantAttKey := range wantAddress.EncryptedAttachmentKeyPackets { for attID, wantAttKey := range wantAddress.EncryptedAttachmentKeyPackets {
haveAttKey, ok := haveAddress.EncryptedAttachmentKeyPackets[attID] haveAttKey, ok := haveAddress.EncryptedAttachmentKeyPackets[attID]
r.True(ok, "pkg %d email %s att %s", i, email, attID) r.True(ok, "pkg %d email %s att %s", i, email, attID)
shouldBeEmpty(wantAttKey)(t, haveAttKey, "pkg %d email %s att %s", i, email, attID) matchPresence(wantAttKey)(t, haveAttKey, "pkg %d email %s att %s", i, email, attID)
} }
} }
} }
@ -98,13 +98,13 @@ func (td *testData) prepareAndCheck(t *testing.T) {
r.Equal(wantPackage.Type, havePackage.Type, "pkg %d", i) r.Equal(wantPackage.Type, havePackage.Type, "pkg %d", i)
r.Equal(wantPackage.MIMEType, havePackage.MIMEType, "pkg %d", i) r.Equal(wantPackage.MIMEType, havePackage.MIMEType, "pkg %d", i)
shouldBeEmpty(wantPackage.EncryptedBody)(t, havePackage.EncryptedBody, "pkg %d", i) matchPresence(wantPackage.EncryptedBody)(t, havePackage.EncryptedBody, "pkg %d", i)
wantBodyKey := wantPackage.DecryptedBodyKey wantBodyKey := wantPackage.DecryptedBodyKey
haveBodyKey := havePackage.DecryptedBodyKey haveBodyKey := havePackage.DecryptedBodyKey
shouldBeEmpty(wantBodyKey.Algorithm)(t, haveBodyKey.Algorithm, "pkg %d", i) matchPresence(wantBodyKey.Algorithm)(t, haveBodyKey.Algorithm, "pkg %d", i)
shouldBeEmpty(wantBodyKey.Key)(t, haveBodyKey.Key, "pkg %d", i) matchPresence(wantBodyKey.Key)(t, haveBodyKey.Key, "pkg %d", i)
if len(td.attKeys) == 0 { if len(td.attKeys) == 0 {
r.Len(havePackage.DecryptedAttachmentKeys, 0) r.Len(havePackage.DecryptedAttachmentKeys, 0)
@ -117,8 +117,8 @@ func (td *testData) prepareAndCheck(t *testing.T) {
for attID, wantAttKey := range wantPackage.DecryptedAttachmentKeys { for attID, wantAttKey := range wantPackage.DecryptedAttachmentKeys {
haveAttKey, ok := havePackage.DecryptedAttachmentKeys[attID] haveAttKey, ok := havePackage.DecryptedAttachmentKeys[attID]
r.True(ok, "pkg %d att %s", i, attID) r.True(ok, "pkg %d att %s", i, attID)
shouldBeEmpty(wantAttKey.Key)(t, haveAttKey.Key, "pkg %d att %s", i, attID) matchPresence(wantAttKey.Key)(t, haveAttKey.Key, "pkg %d att %s", i, attID)
shouldBeEmpty(wantAttKey.Algorithm)(t, haveAttKey.Algorithm, "pkg %d att %s", i, attID) matchPresence(wantAttKey.Algorithm)(t, haveAttKey.Algorithm, "pkg %d att %s", i, attID)
} }
} }
} }
@ -134,8 +134,8 @@ func TestSendReq(t *testing.T) {
attAlgoKeys := map[string]AlgoKey{"attID": {"not-empty", "not-empty"}} attAlgoKeys := map[string]AlgoKey{"attID": {"not-empty", "not-empty"}}
// NOTE naming // NOTE naming
// Single: there should be one packet // Single: there should be one package
// Multiple: there should be more than one packet // Multiple: there should be more than one package
// Internal: there should be internal package // Internal: there should be internal package
// Clear: there should be non-encrypted package // Clear: there should be non-encrypted package
// Encrypted: there should be encrypted package // Encrypted: there should be encrypted package
@ -144,6 +144,7 @@ func TestSendReq(t *testing.T) {
"SingleInternalHTML": { "SingleInternalHTML": {
recipients: []recipient{ recipients: []recipient{
{"html@pm.me", InternalPackage, testPublicKeyRing, SignatureDetached, ContentTypeHTML, true, nil}, {"html@pm.me", InternalPackage, testPublicKeyRing, SignatureDetached, ContentTypeHTML, true, nil},
{"none@pm.me", InternalPackage, testPublicKeyRing, SignatureDetached, "", true, nil},
}, },
wantPackages: []*MessagePackage{ wantPackages: []*MessagePackage{
{ {
@ -154,6 +155,12 @@ func TestSendReq(t *testing.T) {
EncryptedBodyKeyPacket: "not-empty", EncryptedBodyKeyPacket: "not-empty",
EncryptedAttachmentKeyPackets: attKeyPackets, EncryptedAttachmentKeyPackets: attKeyPackets,
}, },
"none@pm.me": {
Type: InternalPackage,
Signature: SignatureDetached,
EncryptedBodyKeyPacket: "not-empty",
EncryptedAttachmentKeyPackets: attKeyPackets,
},
}, },
Type: InternalPackage, Type: InternalPackage,
MIMEType: ContentTypeHTML, MIMEType: ContentTypeHTML,
@ -183,9 +190,10 @@ func TestSendReq(t *testing.T) {
}, },
"InternalNotAllowed": { "InternalNotAllowed": {
recipients: []recipient{ recipients: []recipient{
{"wrongtype@pm.me", InternalPackage, testPublicKeyRing, SignatureDetached, "application/rfc822", true, errUnknownContentType},
{"multipart@pm.me", InternalPackage, testPublicKeyRing, SignatureDetached, ContentTypeMultipartMixed, true, errMultipartInNonMIME}, {"multipart@pm.me", InternalPackage, testPublicKeyRing, SignatureDetached, ContentTypeMultipartMixed, true, errMultipartInNonMIME},
{"noencrypt@pm.me", InternalPackage, testPublicKeyRing, SignatureDetached, ContentTypeHTML, false, errInternalMustEncrypt}, {"noencrypt@pm.me", InternalPackage, testPublicKeyRing, SignatureDetached, ContentTypeHTML, false, errInternalMustEncrypt},
{"no-pubkey@pm.me", InternalPackage, nil, SignatureDetached, ContentTypeHTML, true, errMisingPubkey}, {"no-pubkey@pm.me", InternalPackage, nil, SignatureDetached, ContentTypeHTML, true, errMissingPubkey},
{"nosigning@pm.me", InternalPackage, testPublicKeyRing, SignatureNone, ContentTypeHTML, true, errEncryptMustSign}, {"nosigning@pm.me", InternalPackage, testPublicKeyRing, SignatureNone, ContentTypeHTML, true, errEncryptMustSign},
}, },
}, },
@ -194,7 +202,7 @@ func TestSendReq(t *testing.T) {
{"internal1@pm.me", InternalPackage, testPublicKeyRing, SignatureDetached, ContentTypePlainText, true, nil}, {"internal1@pm.me", InternalPackage, testPublicKeyRing, SignatureDetached, ContentTypePlainText, true, nil},
{"internal2@pm.me", InternalPackage, testPublicKeyRing, SignatureDetached, ContentTypeHTML, true, nil}, {"internal2@pm.me", InternalPackage, testPublicKeyRing, SignatureDetached, ContentTypeHTML, true, nil},
{"internal3@pm.me", InternalPackage, testPublicKeyRing, SignatureDetached, ContentTypePlainText, true, nil}, {"internal3@pm.me", InternalPackage, testPublicKeyRing, SignatureDetached, ContentTypePlainText, true, nil},
{"internal4@pm.me", InternalPackage, testPublicKeyRing, SignatureDetached, ContentTypeHTML, true, nil}, {"internal4@pm.me", InternalPackage, testPublicKeyRing, SignatureDetached, "", true, nil},
}, },
wantPackages: []*MessagePackage{ wantPackages: []*MessagePackage{
{ {
@ -241,6 +249,7 @@ func TestSendReq(t *testing.T) {
"SingleClearHTML": { "SingleClearHTML": {
recipients: []recipient{ recipients: []recipient{
{"html@email.com", ClearPackage, nil, SignatureNone, ContentTypeHTML, false, nil}, {"html@email.com", ClearPackage, nil, SignatureNone, ContentTypeHTML, false, nil},
{"nothing@email.com", ClearPackage, nil, SignatureNone, "", false, nil},
}, },
wantPackages: []*MessagePackage{ wantPackages: []*MessagePackage{
{ {
@ -249,6 +258,10 @@ func TestSendReq(t *testing.T) {
Type: ClearPackage, Type: ClearPackage,
Signature: SignatureNone, Signature: SignatureNone,
}, },
"nothing@email.com": {
Type: ClearPackage,
Signature: SignatureNone,
},
}, },
Type: ClearPackage, Type: ClearPackage,
MIMEType: ContentTypeHTML, MIMEType: ContentTypeHTML,
@ -261,6 +274,7 @@ func TestSendReq(t *testing.T) {
"SingleClearPlain": { "SingleClearPlain": {
recipients: []recipient{ recipients: []recipient{
{"plain@email.com", ClearPackage, nil, SignatureNone, ContentTypePlainText, false, nil}, {"plain@email.com", ClearPackage, nil, SignatureNone, ContentTypePlainText, false, nil},
{"plain-sign@email.com", ClearPackage, nil, SignatureDetached, ContentTypePlainText, false, nil},
}, },
wantPackages: []*MessagePackage{ wantPackages: []*MessagePackage{
{ {
@ -269,6 +283,10 @@ func TestSendReq(t *testing.T) {
Type: ClearPackage, Type: ClearPackage,
Signature: SignatureNone, Signature: SignatureNone,
}, },
"plain-sign@email.com": {
Type: ClearPackage,
Signature: SignatureDetached,
},
}, },
Type: ClearPackage, Type: ClearPackage,
MIMEType: ContentTypePlainText, MIMEType: ContentTypePlainText,
@ -281,6 +299,7 @@ func TestSendReq(t *testing.T) {
"SingleClearMIME": { "SingleClearMIME": {
recipients: []recipient{ recipients: []recipient{
{"mime@email.com", ClearMIMEPackage, nil, SignatureNone, ContentTypeMultipartMixed, false, nil}, {"mime@email.com", ClearMIMEPackage, nil, SignatureNone, ContentTypeMultipartMixed, false, nil},
{"mime-sign@email.com", ClearMIMEPackage, nil, SignatureDetached, ContentTypeMultipartMixed, false, nil},
}, },
wantPackages: []*MessagePackage{ wantPackages: []*MessagePackage{
{ {
@ -289,22 +308,7 @@ func TestSendReq(t *testing.T) {
Type: ClearMIMEPackage, Type: ClearMIMEPackage,
Signature: SignatureNone, Signature: SignatureNone,
}, },
}, "mime-sign@email.com": {
Type: ClearMIMEPackage,
MIMEType: ContentTypeMultipartMixed,
EncryptedBody: "non-empty",
DecryptedBodyKey: AlgoKey{"non-empty", "non-empty"},
},
},
},
"SingleClearSign": {
recipients: []recipient{
{"signed@email.com", ClearMIMEPackage, nil, SignatureDetached, ContentTypeMultipartMixed, false, nil},
},
wantPackages: []*MessagePackage{
{
Addresses: map[string]*MessageAddress{
"signed@email.com": {
Type: ClearMIMEPackage, Type: ClearMIMEPackage,
Signature: SignatureDetached, Signature: SignatureDetached,
}, },
@ -318,7 +322,6 @@ func TestSendReq(t *testing.T) {
}, },
"ClearNotAllowed": { "ClearNotAllowed": {
recipients: []recipient{ recipients: []recipient{
{"plain@email.com", ClearPackage, nil, SignatureDetached, ContentTypePlainText, false, errSignMustBeMultipart},
{"html-1@email.com", ClearPackage, nil, SignatureDetached, ContentTypeHTML, false, errSignMustBeMultipart}, {"html-1@email.com", ClearPackage, nil, SignatureDetached, ContentTypeHTML, false, errSignMustBeMultipart},
{"plain@email.com", ClearMIMEPackage, nil, SignatureDetached, ContentTypePlainText, false, errMIMEMustBeMultipart}, {"plain@email.com", ClearMIMEPackage, nil, SignatureDetached, ContentTypePlainText, false, errMIMEMustBeMultipart},
{"html-@email.com", ClearMIMEPackage, nil, SignatureDetached, ContentTypeHTML, false, errMIMEMustBeMultipart}, {"html-@email.com", ClearMIMEPackage, nil, SignatureDetached, ContentTypeHTML, false, errMIMEMustBeMultipart},
@ -333,7 +336,7 @@ func TestSendReq(t *testing.T) {
}, },
wantPackages: []*MessagePackage{ wantPackages: []*MessagePackage{
{ {
Addresses: map[string]*MessageAddress{ // TODO can this two be combined Addresses: map[string]*MessageAddress{
"sign@email.com": { "sign@email.com": {
Type: ClearMIMEPackage, Type: ClearMIMEPackage,
Signature: SignatureDetached, Signature: SignatureDetached,
@ -416,33 +419,14 @@ func TestSendReq(t *testing.T) {
}, },
}, },
}, },
"SingleEncryptedInlineHTML": {
recipients: []recipient{
{"inline-html@gpg.com", PGPInlinePackage, testPublicKeyRing, SignatureDetached, ContentTypeHTML, true, nil},
},
wantPackages: []*MessagePackage{
{
Addresses: map[string]*MessageAddress{
"inline-html@gpg.com": {
Type: PGPInlinePackage,
Signature: SignatureDetached,
EncryptedBodyKeyPacket: "non-empty",
EncryptedAttachmentKeyPackets: attKeyPackets,
},
},
Type: PGPInlinePackage,
MIMEType: ContentTypeHTML,
EncryptedBody: "non-empty",
},
},
},
"EncryptedNotAllowed": { "EncryptedNotAllowed": {
recipients: []recipient{ recipients: []recipient{
{"inline-html@gpg.com", PGPInlinePackage, testPublicKeyRing, SignatureDetached, ContentTypeHTML, true, errInlineMustBePlain},
{"inline-mixed@gpg.com", PGPInlinePackage, testPublicKeyRing, SignatureDetached, ContentTypeMultipartMixed, true, errMultipartInNonMIME}, {"inline-mixed@gpg.com", PGPInlinePackage, testPublicKeyRing, SignatureDetached, ContentTypeMultipartMixed, true, errMultipartInNonMIME},
{"inline-clear@gpg.com", PGPInlinePackage, nil, SignatureDetached, ContentTypePlainText, false, errInlinelMustEncrypt}, {"inline-clear@gpg.com", PGPInlinePackage, nil, SignatureDetached, ContentTypePlainText, false, errInlineMustEncrypt},
{"mime-plain@gpg.com", PGPMIMEPackage, nil, SignatureDetached, ContentTypePlainText, true, errMIMEMustBeMultipart}, {"mime-plain@gpg.com", PGPMIMEPackage, nil, SignatureDetached, ContentTypePlainText, true, errMIMEMustBeMultipart},
{"mime-html@gpg.com", PGPMIMEPackage, nil, SignatureDetached, ContentTypeHTML, true, errMIMEMustBeMultipart}, {"mime-html@sgpg.com", PGPMIMEPackage, nil, SignatureDetached, ContentTypeHTML, true, errMIMEMustBeMultipart},
{"no-pubkey@gpg.com", PGPMIMEPackage, nil, SignatureDetached, ContentTypeMultipartMixed, true, errMisingPubkey}, {"no-pubkey@gpg.com", PGPMIMEPackage, nil, SignatureDetached, ContentTypeMultipartMixed, true, errMissingPubkey},
{"not-signed@gpg.com", PGPMIMEPackage, testPublicKeyRing, SignatureNone, ContentTypeMultipartMixed, true, errEncryptMustSign}, {"not-signed@gpg.com", PGPMIMEPackage, testPublicKeyRing, SignatureNone, ContentTypeMultipartMixed, true, errEncryptMustSign},
}, },
}, },
@ -450,7 +434,6 @@ func TestSendReq(t *testing.T) {
recipients: []recipient{ recipients: []recipient{
{"mime@gpg.com", PGPMIMEPackage, testPublicKeyRing, SignatureDetached, ContentTypeMultipartMixed, true, nil}, {"mime@gpg.com", PGPMIMEPackage, testPublicKeyRing, SignatureDetached, ContentTypeMultipartMixed, true, nil},
{"inline-plain@gpg.com", PGPInlinePackage, testPublicKeyRing, SignatureDetached, ContentTypePlainText, true, nil}, {"inline-plain@gpg.com", PGPInlinePackage, testPublicKeyRing, SignatureDetached, ContentTypePlainText, true, nil},
{"inline-html@gpg.com", PGPInlinePackage, testPublicKeyRing, SignatureDetached, ContentTypeHTML, true, nil},
}, },
wantPackages: []*MessagePackage{ wantPackages: []*MessagePackage{
{ {
@ -478,49 +461,9 @@ func TestSendReq(t *testing.T) {
MIMEType: ContentTypePlainText, MIMEType: ContentTypePlainText,
EncryptedBody: "non-empty", EncryptedBody: "non-empty",
}, },
{
Addresses: map[string]*MessageAddress{
"inline-html@gpg.com": {
Type: PGPInlinePackage,
Signature: SignatureDetached,
EncryptedBodyKeyPacket: "non-empty",
EncryptedAttachmentKeyPackets: attKeyPackets,
},
},
Type: PGPInlinePackage,
MIMEType: ContentTypeHTML,
EncryptedBody: "non-empty",
},
}, },
}, },
"SingleInternalEncryptedHTML": {
recipients: []recipient{
{"inline-html@gpg.com", PGPInlinePackage, testPublicKeyRing, SignatureDetached, ContentTypeHTML, true, nil},
{"internal@pm.me", InternalPackage, testPublicKeyRing, SignatureDetached, ContentTypeHTML, true, nil},
},
wantPackages: []*MessagePackage{
{
Addresses: map[string]*MessageAddress{
"inline-html@gpg.com": {
Type: PGPInlinePackage,
Signature: SignatureDetached,
EncryptedBodyKeyPacket: "non-empty",
EncryptedAttachmentKeyPackets: attKeyPackets,
},
"internal@pm.me": {
Type: InternalPackage,
Signature: SignatureDetached,
EncryptedBodyKeyPacket: "non-empty",
EncryptedAttachmentKeyPackets: attKeyPackets,
},
},
Type: PGPInlinePackage | InternalPackage,
MIMEType: ContentTypeHTML,
EncryptedBody: "non-empty",
},
},
},
"SingleInternalEncryptedPlain": { "SingleInternalEncryptedPlain": {
recipients: []recipient{ recipients: []recipient{
{"inline-plain@gpg.com", PGPInlinePackage, testPublicKeyRing, SignatureDetached, ContentTypePlainText, true, nil}, {"inline-plain@gpg.com", PGPInlinePackage, testPublicKeyRing, SignatureDetached, ContentTypePlainText, true, nil},
@ -602,33 +545,6 @@ func TestSendReq(t *testing.T) {
}, },
}, },
}, },
"SingleClearEncryptedHTML": {
recipients: []recipient{
{"html@email.com", ClearPackage, nil, SignatureNone, ContentTypeHTML, false, nil},
{"inline-html@gpg.com", PGPInlinePackage, testPublicKeyRing, SignatureDetached, ContentTypeHTML, true, nil},
},
wantPackages: []*MessagePackage{
{
Addresses: map[string]*MessageAddress{
"inline-html@gpg.com": {
Type: PGPInlinePackage,
Signature: SignatureDetached,
EncryptedBodyKeyPacket: "non-empty",
EncryptedAttachmentKeyPackets: attKeyPackets,
},
"html@email.com": {
Type: ClearPackage,
Signature: SignatureNone,
},
},
Type: PGPInlinePackage | ClearPackage,
MIMEType: ContentTypeHTML,
EncryptedBody: "non-empty",
DecryptedBodyKey: AlgoKey{"non-empty", "non-empty"},
DecryptedAttachmentKeys: attAlgoKeys,
},
},
},
"SingleClearEncryptedPlain": { "SingleClearEncryptedPlain": {
recipients: []recipient{ recipients: []recipient{
{"plain@email.com", ClearPackage, nil, SignatureNone, ContentTypePlainText, false, nil}, {"plain@email.com", ClearPackage, nil, SignatureNone, ContentTypePlainText, false, nil},
@ -684,6 +600,7 @@ func TestSendReq(t *testing.T) {
"SingleClearEncryptedMIMENoSign": { "SingleClearEncryptedMIMENoSign": {
recipients: []recipient{ recipients: []recipient{
{"mime@email.com", ClearMIMEPackage, nil, SignatureNone, ContentTypeMultipartMixed, false, nil}, {"mime@email.com", ClearMIMEPackage, nil, SignatureNone, ContentTypeMultipartMixed, false, nil},
{"mime-signed@email.com", ClearMIMEPackage, nil, SignatureDetached, ContentTypeMultipartMixed, false, nil},
{"mime@gpg.com", PGPMIMEPackage, testPublicKeyRing, SignatureDetached, ContentTypeMultipartMixed, true, nil}, {"mime@gpg.com", PGPMIMEPackage, testPublicKeyRing, SignatureDetached, ContentTypeMultipartMixed, true, nil},
}, },
wantPackages: []*MessagePackage{ wantPackages: []*MessagePackage{
@ -694,10 +611,14 @@ func TestSendReq(t *testing.T) {
Signature: SignatureDetached, Signature: SignatureDetached,
EncryptedBodyKeyPacket: "non-empty", EncryptedBodyKeyPacket: "non-empty",
}, },
"mime@email.com": { // can this be combined ? "mime@email.com": {
Type: ClearMIMEPackage, Type: ClearMIMEPackage,
Signature: SignatureNone, Signature: SignatureNone,
}, },
"mime-signed@email.com": {
Type: ClearMIMEPackage,
Signature: SignatureDetached,
},
}, },
Type: ClearMIMEPackage | PGPMIMEPackage, Type: ClearMIMEPackage | PGPMIMEPackage,
MIMEType: ContentTypeMultipartMixed, MIMEType: ContentTypeMultipartMixed,
@ -718,11 +639,10 @@ func TestSendReq(t *testing.T) {
{"html@pm.me", InternalPackage, testPublicKeyRing, SignatureDetached, ContentTypeHTML, true, nil}, {"html@pm.me", InternalPackage, testPublicKeyRing, SignatureDetached, ContentTypeHTML, true, nil},
{"html@email.com", ClearPackage, nil, SignatureNone, ContentTypeHTML, false, nil}, {"html@email.com", ClearPackage, nil, SignatureNone, ContentTypeHTML, false, nil},
{"inline-html@gpg.com", PGPInlinePackage, testPublicKeyRing, SignatureDetached, ContentTypeHTML, true, nil},
}, },
wantPackages: []*MessagePackage{ wantPackages: []*MessagePackage{
{ {
Addresses: map[string]*MessageAddress{ // TODO can this three be combined Addresses: map[string]*MessageAddress{
"mime@gpg.com": { "mime@gpg.com": {
Type: PGPMIMEPackage, Type: PGPMIMEPackage,
Signature: SignatureDetached, Signature: SignatureDetached,
@ -779,14 +699,8 @@ func TestSendReq(t *testing.T) {
Type: ClearPackage, Type: ClearPackage,
Signature: SignatureNone, Signature: SignatureNone,
}, },
"inline-html@gpg.com": {
Type: PGPInlinePackage,
Signature: SignatureDetached,
EncryptedBodyKeyPacket: "non-empty",
EncryptedAttachmentKeyPackets: attKeyPackets,
},
}, },
Type: InternalPackage | ClearPackage | PGPInlinePackage, Type: InternalPackage | ClearPackage,
MIMEType: ContentTypeHTML, MIMEType: ContentTypeHTML,
EncryptedBody: "non-empty", EncryptedBody: "non-empty",
DecryptedBodyKey: AlgoKey{"non-empty", "non-empty"}, DecryptedBodyKey: AlgoKey{"non-empty", "non-empty"},

View File

@ -9,3 +9,8 @@ Changelog [format](http://keepachangelog.com/en/1.0.0/)
### Changed ### Changed
* GODT-651 Build creates proper binary names. * GODT-651 Build creates proper binary names.
## Added
* GODT-878 Tests for send packet creation logic
## Changed
* GODT-878 Refactor and move the send packet creation login to `pmapi.SendMessageReq`