tutanota/test/tests/api/common/mail/CommonMailUtilsTest.ts

325 lines
11 KiB
TypeScript
Raw Normal View History

import o from "@tutao/otest"
import { createMail, createMailAddress, Mail, MailTypeRef } from "../../../../../src/api/entities/tutanota/TypeRefs.js"
import { EncryptionAuthStatus, MailState } from "../../../../../src/api/common/TutanotaConstants.js"
import { getDisplayedSender, isSystemNotification, isTutanotaTeamAddress, isTutanotaTeamMail } from "../../../../../src/api/common/mail/CommonMailUtils.js"
import { createTestEntity } from "../../../TestUtils.js"
import { getConfidentialIcon } from "../../../../../src/mail/model/MailUtils.js"
import { Icons } from "../../../../../src/gui/base/icons/Icons.js"
import { ProgrammingError } from "../../../../../src/api/common/error/ProgrammingError.js"
o.spec("MailUtilsTest", function () {
function createSystemMail(overrides: Partial<Mail> = {}): Mail {
return createMail({
...{
sender: createMailAddress({
address: "system@tutanota.de",
name: "System",
_id: "",
_ownerGroup: "",
contact: null,
}),
replyTos: [],
state: MailState.RECEIVED,
authStatus: null,
_errors: {},
_id: ["", ""],
_ownerEncSessionKey: null,
_ownerGroup: "",
_permissions: "",
attachments: [],
bccRecipients: [],
body: null,
bucketKey: null,
ccRecipients: [],
confidential: true,
conversationEntry: ["", ""],
differentEnvelopeSender: null,
encryptionAuthStatus: null,
firstRecipient: null,
headers: null,
listUnsubscribe: false,
mailDetails: null,
mailDetailsDraft: null,
method: "",
movedTime: null,
phishingStatus: "",
receivedDate: new Date(),
recipientCount: "",
replyType: "",
sentDate: null,
subject: "",
toRecipients: [],
unread: false,
},
...overrides,
})
}
const tutanotaSender = () => createMailAddress({ address: "sender@tutanota.de", name: "Tutanota sender", contact: null })
const tutaoSender = () => createMailAddress({ address: "sender@tutao.de", name: "Tutao sender", contact: null })
const tutanotaNoReplySender = () => createMailAddress({ address: "no-reply@tutanota.de", name: "Tutanota no-reply", contact: null })
const tutaoNoReplySender = () => createMailAddress({ address: "no-reply@tutao.de", name: "Tutao no-reply", contact: null })
o("getDisplayedSender", function () {
const mail = createSystemMail()
o(getDisplayedSender(mail)).deepEquals({ address: "system@tutanota.de", name: "System" })
})
o("isTutanotaTeamAddress", function () {
o(isTutanotaTeamAddress("system@tutanota.de")).deepEquals(false)
o(isTutanotaTeamAddress("bed-free@tutanota.de")).deepEquals(false)
o(isTutanotaTeamAddress("admin@somesite.com")).deepEquals(false)
o(isTutanotaTeamAddress("no-reply@tutao.de")).deepEquals(true)
o(isTutanotaTeamAddress("sales@tutao.de")).deepEquals(true)
o(isTutanotaTeamAddress("no-reply@tutanota.de")).deepEquals(true)
})
o("getConfidentialIcon", function () {
const mail: Mail = createTestEntity(MailTypeRef, { confidential: true, encryptionAuthStatus: EncryptionAuthStatus.PQ_AUTHENTICATION_SUCCEEDED })
o(getConfidentialIcon(mail)).equals(Icons.PQLock)
mail.encryptionAuthStatus = EncryptionAuthStatus.PQ_AUTHENTICATION_FAILED
o(getConfidentialIcon(mail)).equals(Icons.PQLock)
mail.encryptionAuthStatus = EncryptionAuthStatus.AES_NO_AUTHENTICATION
o(getConfidentialIcon(mail)).equals(Icons.Lock)
mail.encryptionAuthStatus = null
o(getConfidentialIcon(mail)).equals(Icons.Lock)
mail.encryptionAuthStatus = EncryptionAuthStatus.RSA_NO_AUTHENTICATION
o(getConfidentialIcon(mail)).equals(Icons.Lock)
mail.confidential = false
o(() => getConfidentialIcon(mail)).throws(ProgrammingError)
})
o.spec("isTutanotaTeamMail", function () {
o("regular non-confidential email is not", function () {
const mail = createTestEntity(MailTypeRef, {
confidential: false,
state: MailState.RECEIVED,
sender: tutanotaSender(),
})
o(isTutanotaTeamMail(mail)).equals(false)
})
o("regular confidential email is not", function () {
const mail = createTestEntity(MailTypeRef, {
confidential: true,
state: MailState.RECEIVED,
sender: tutanotaSender(),
})
o(isTutanotaTeamMail(mail)).equals(false)
})
o("system email without auth is", function () {
const mail = createSystemMail()
o(isTutanotaTeamMail(mail)).equals(true)
})
o("system email failing PQ auth is not", function () {
const mail = createSystemMail({ encryptionAuthStatus: EncryptionAuthStatus.PQ_AUTHENTICATION_FAILED })
o(isTutanotaTeamMail(mail)).equals(false)
})
o("system email with RSA (no) auth is", function () {
const mail = createSystemMail({ encryptionAuthStatus: EncryptionAuthStatus.RSA_NO_AUTHENTICATION })
o(isTutanotaTeamMail(mail)).equals(true)
})
o("system email with AES (no) auth is not", function () {
const mail = createSystemMail({ encryptionAuthStatus: EncryptionAuthStatus.AES_NO_AUTHENTICATION })
o(isTutanotaTeamMail(mail)).equals(false)
})
o("confidential email from tutao without auth is", function () {
const mail = createTestEntity(MailTypeRef, {
confidential: true,
state: MailState.RECEIVED,
sender: tutaoSender(),
encryptionAuthStatus: null,
})
o(isTutanotaTeamMail(mail)).equals(true)
})
o("confidential email from tutao with PQ auth is", function () {
const mail = createTestEntity(MailTypeRef, {
confidential: true,
state: MailState.RECEIVED,
sender: tutaoSender(),
encryptionAuthStatus: EncryptionAuthStatus.PQ_AUTHENTICATION_SUCCEEDED,
})
o(isTutanotaTeamMail(mail)).equals(true)
})
o("confidential email from tutao with failing PQ auth is not", function () {
const mail = createTestEntity(MailTypeRef, {
confidential: true,
state: MailState.RECEIVED,
sender: tutaoSender(),
encryptionAuthStatus: EncryptionAuthStatus.PQ_AUTHENTICATION_FAILED,
})
o(isTutanotaTeamMail(mail)).equals(false)
})
o("confidential email from tutao with RSA (no) auth is", function () {
const mail = createTestEntity(MailTypeRef, {
confidential: true,
state: MailState.RECEIVED,
sender: tutaoSender(),
encryptionAuthStatus: EncryptionAuthStatus.RSA_NO_AUTHENTICATION,
})
o(isTutanotaTeamMail(mail)).equals(true)
})
o("confidential email from tutao with AES (no) auth is not", function () {
const mail = createTestEntity(MailTypeRef, {
confidential: true,
state: MailState.RECEIVED,
sender: tutaoSender(),
encryptionAuthStatus: EncryptionAuthStatus.AES_NO_AUTHENTICATION,
})
o(isTutanotaTeamMail(mail)).equals(false)
})
o("confidential email from no-reply is", function () {
const mail = createTestEntity(MailTypeRef, {
confidential: true,
state: MailState.RECEIVED,
sender: tutanotaNoReplySender(),
})
o(isTutanotaTeamMail(mail)).equals(true)
})
o(`non-confidential "system" email is not`, function () {
const mail = createMail({ ...createSystemMail(), confidential: false })
o(isTutanotaTeamMail(mail)).equals(false)
})
o("non-confidential email from tutao is not", function () {
const mail = createTestEntity(MailTypeRef, {
confidential: false,
state: MailState.RECEIVED,
sender: tutaoSender(),
})
o(isTutanotaTeamMail(mail)).equals(false)
})
o("non confidential email from no-reply is not", function () {
const mail = createTestEntity(MailTypeRef, {
confidential: false,
state: MailState.RECEIVED,
sender: tutanotaNoReplySender(),
})
o(isTutanotaTeamMail(mail)).equals(false)
})
})
o.spec("isSystemNotification", function () {
o("regular non-confidential email is not", function () {
const mail = createTestEntity(MailTypeRef, {
confidential: false,
state: MailState.RECEIVED,
sender: tutanotaSender(),
})
o(isSystemNotification(mail)).equals(false)
})
o("regular confidential email is not", function () {
const mail = createTestEntity(MailTypeRef, {
confidential: true,
state: MailState.RECEIVED,
sender: tutanotaSender(),
})
o(isSystemNotification(mail)).equals(false)
})
o("system email without auth is", function () {
const mail = createSystemMail()
o(isSystemNotification(mail)).equals(true)
})
o("system email with PQ auth is", function () {
const mail = createSystemMail({ encryptionAuthStatus: EncryptionAuthStatus.PQ_AUTHENTICATION_SUCCEEDED })
o(isSystemNotification(mail)).equals(true)
})
o("system email with failing PQ auth is not", function () {
const mail = createSystemMail({ encryptionAuthStatus: EncryptionAuthStatus.PQ_AUTHENTICATION_FAILED })
o(isSystemNotification(mail)).equals(false)
})
o("system email with RSA (no) auth is", function () {
const mail = createSystemMail({ encryptionAuthStatus: EncryptionAuthStatus.RSA_NO_AUTHENTICATION })
o(isSystemNotification(mail)).equals(true)
})
o("system email with AES (no) auth is not", function () {
const mail = createSystemMail({ encryptionAuthStatus: EncryptionAuthStatus.AES_NO_AUTHENTICATION })
o(isSystemNotification(mail)).equals(false)
})
o("confidential email from tutao is not", function () {
const mail = createTestEntity(MailTypeRef, {
confidential: true,
state: MailState.RECEIVED,
sender: tutaoSender(),
authStatus: null,
})
o(isSystemNotification(mail)).equals(false)
})
o("confidential email from tutao with PQ auth is not", function () {
const mail = createTestEntity(MailTypeRef, {
confidential: true,
state: MailState.RECEIVED,
sender: tutaoSender(),
authStatus: EncryptionAuthStatus.PQ_AUTHENTICATION_SUCCEEDED,
})
o(isSystemNotification(mail)).equals(false)
})
o("confidential email from tutanota no-reply is", function () {
const mail = createTestEntity(MailTypeRef, {
confidential: true,
state: MailState.RECEIVED,
sender: tutanotaNoReplySender(),
})
o(isSystemNotification(mail)).equals(true)
})
o("confidential email from tutao no-reply is", function () {
const mail = createTestEntity(MailTypeRef, {
confidential: true,
state: MailState.RECEIVED,
sender: tutaoNoReplySender(),
})
o(isSystemNotification(mail)).equals(true)
})
o(`non-confidential "system" email is not`, function () {
const mail = createMail({ ...createSystemMail(), confidential: false })
o(isSystemNotification(mail)).equals(false)
})
o("non-confidential email from tutao is not", function () {
const mail = createTestEntity(MailTypeRef, {
confidential: false,
state: MailState.RECEIVED,
sender: tutaoSender(),
})
o(isSystemNotification(mail)).equals(false)
})
o("non confidential email from no-reply is not", function () {
const mail = createTestEntity(MailTypeRef, {
confidential: false,
state: MailState.RECEIVED,
sender: tutanotaNoReplySender(),
})
o(isSystemNotification(mail)).equals(false)
})
})
})