Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ export class ComposeQuoteModule extends ViewModule<ComposeView> {
return {
headers,
text: decryptedAndFormatedContent.join('\n'),
isOnlySigned: !!(decoded.rawSignedContent || (message.blocks.length > 0 && message.blocks[0].type === 'signedMsg')),
isOnlySigned: Mime.isOnlySigned(decoded.rawSignedContent, message.blocks),
decryptedFiles,
};
} catch (e) {
Expand Down
5 changes: 5 additions & 0 deletions extension/js/common/core/mime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ export class Mime {
return !(text && !/^(\r)?(\n)?$/.test(text));
}

public static isOnlySigned(rawSignedContent: string | undefined, blocks: MsgBlock[]): boolean {
const hasEncryptedContent = blocks.some(block => ['encryptedMsg', 'encryptedAttachment'].includes(block.type));
return !hasEncryptedContent && !!(rawSignedContent || (blocks.length > 0 && blocks[0].type === 'signedMsg'));
}

public static processAttachments(bodyBlocks: MsgBlock[], decoded: MimeContent): MimeProccesedMsg {
const attachmentBlocks: MsgBlock[] = [];
const signatureAttachments: Attachment[] = [];
Expand Down
41 changes: 41 additions & 0 deletions test/source/tests/unit-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import test from 'ava';

import { MsgBlock } from '../core/msg-block';
import { MsgBlockParser } from '../core/msg-block-parser';
import { Mime } from '../core/mime';
import { Config, TestVariant } from '../util';
import { use, expect } from 'chai';
import chaiAsPromised from 'chai-as-promised';
Expand Down Expand Up @@ -46,6 +47,46 @@ export const equals = (a: string | Uint8Array, b: string | Uint8Array) => {

export const defineUnitNodeTests = (testVariant: TestVariant) => {
if (testVariant !== 'CONSUMER-LIVE-GMAIL') {
test(`[unit][Mime.isOnlySigned] signed-only message stays signed-only`, t => {
t.true(Mime.isOnlySigned('signed content', [new MsgBlock('signedMsg', 'signed content', true)]));
});

test(`[unit][Mime.isOnlySigned] outer signed wrapper with encrypted body is not signed-only`, t => {
t.false(Mime.isOnlySigned('signed content', [new MsgBlock('encryptedMsg', 'encrypted content', true)]));
});

test(`[unit][Mime.isOnlySigned] outer signed wrapper with encrypted attachment is not signed-only`, t => {
t.false(
Mime.isOnlySigned('signed content', [MsgBlock.fromAttachment('encryptedAttachment', '', { data: new Uint8Array(0), name: 'statement.pdf.pgp' })])
);
});

test(`[unit][Mime.isOnlySigned] leading signedMsg block with later encrypted body is not signed-only`, t => {
t.false(Mime.isOnlySigned(undefined, [new MsgBlock('signedMsg', 'signed content', true), new MsgBlock('encryptedMsg', 'encrypted content', true)]));
});

test(`[unit][Mime.isOnlySigned] leading signedMsg block with later encrypted attachment is not signed-only`, t => {
t.false(
Mime.isOnlySigned(undefined, [
new MsgBlock('signedMsg', 'signed content', true),
MsgBlock.fromAttachment('encryptedAttachment', '', { data: new Uint8Array(0), name: 'statement.pdf.pgp' }),
])
);
});

test(`[unit][Mime.isOnlySigned] plain attachment does not disqualify signed-only`, t => {
t.true(
Mime.isOnlySigned('signed content', [
new MsgBlock('signedMsg', 'signed content', true),
MsgBlock.fromAttachment('plainAttachment', '', { data: new Uint8Array(0), name: 'notes.txt' }),
])
);
});

test(`[unit][Mime.isOnlySigned] unsigned message is not signed-only`, t => {
t.false(Mime.isOnlySigned(undefined, [new MsgBlock('plainText', 'hello', true)]));
});

test(`[unit][emailKeyIndex] gives distinct keys to emails that differ only in punctuation`, async t => {
t.not(emailKeyIndex('a-b@corp.test', 'keys'), emailKeyIndex('ab@corp.test', 'keys'));
t.is(emailKeyIndex('a-b@corp.test', 'keys'), emailKeyIndex('A-B@corp.test', 'keys'));
Expand Down