o("hex key conversion", function () { let keyPair = _getKeyPair() let hexPrivateKey = privateKeyToHex(keyPair.privateKey) let hexPublicKey = publicKeyToHex(keyPair.publicKey) o(privateKeyToHex(hexToPrivateKey(hexPrivateKey))).equals(hexPrivateKey) o(publicKeyToHex(hexToPublicKey(hexPublicKey))).equals(hexPublicKey) })
o("test randomizer adapter", function (done) { let a = [] a.length = 100 let seed = new Uint8Array(a.length) crypto.getRandomValues(seed) random.generateRandomData = (number) => seed let secureRandom = new SecureRandom(); secureRandom.nextBytes(a) o(a).deepEquals(Array.from(seed)) random.generateRandomData = (number) => { throw new CryptoError("test randomizer adapter") } try { secureRandom.nextBytes([0]) } catch (e) { o(e.message).equals("test randomizer adapter") o(e instanceof CryptoError).equals(true) done() } })
function ciphertextLengths(key, encrypt, length15BytePlainText, length16BytePlainText, useMac) { // check that 15 bytes fit into one block o(encrypt(key, stringToUtf8Uint8Array("1234567890abcde"), random.generateRandomData(IV_BYTE_LENGTH), true, useMac).length).equals(length15BytePlainText) // check that 16 bytes need two blocks (because of one byte padding length info) o(encrypt(key, stringToUtf8Uint8Array("1234567890abcdef"), random.generateRandomData(IV_BYTE_LENGTH), true, useMac).length) .equals(length16BytePlainText) }
function decryptInvalidData(done, key, decrypt, errorMessage) { try { (decrypt: any)(key, new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8, 9, 0]), true, false) // useMac is only used for aes256Decrypt } catch (e) { o(e instanceof CryptoError).equals(true) o(e.message).equals(errorMessage) done() } }
function decryptWithWrongKey(done, key, key2, encrypt, decrypt, useMac, errorMessage) { try { let encrypted = encrypt(key, stringToUtf8Uint8Array("hello"), random.generateRandomData(IV_BYTE_LENGTH), true, useMac); (decrypt: any)(key2, encrypted, true, useMac) // useMac is only used for aes256Decrypt } catch (e) { o(e instanceof CryptoError).equals(true) o(e.message).equals(errorMessage) done() } }
// o("encryptWithInvalidKey 256 webcrypto", done => encryptWithInvalidKey(done, aes256EncryptFile, true)) function encryptWithInvalidKey(done, encrypt, useMac) { let key = _hexToKey("7878787878") try { encrypt(key, stringToUtf8Uint8Array("hello"), random.generateRandomData(IV_BYTE_LENGTH), true, useMac) } catch (e) { o(e instanceof CryptoError).equals(true) o(e.message.startsWith("Illegal key length")).equals(true) done() } }
o("_mgf1 ", function () { let bytes = new Uint8Array([1, 2, 3, 4]) o(uint8ArrayToHex(mgf1(bytes, 32))).equals("e25f9f0a2c2664632d1be5e2f25b2794c371091b61eb762ad98861da3a2221ee") o(uint8ArrayToHex(mgf1(bytes, 63))) .equals("e25f9f0a2c2664632d1be5e2f25b2794c371091b61eb762ad98861da3a2221ee366dcb38806a930d052d8b7bac72a4e59bbe8a78792b4d975ed944dc0f64f6") o(uint8ArrayToHex(mgf1(bytes, 64))) .equals("e25f9f0a2c2664632d1be5e2f25b2794c371091b61eb762ad98861da3a2221ee366dcb38806a930d052d8b7bac72a4e59bbe8a78792b4d975ed944dc0f64f6e5") o(uint8ArrayToHex(mgf1(bytes, 65))) .equals("e25f9f0a2c2664632d1be5e2f25b2794c371091b61eb762ad98861da3a2221ee366dcb38806a930d052d8b7bac72a4e59bbe8a78792b4d975ed944dc0f64f6e5c3") })
// o("decryptWithInvalidKey 256 webcrypto", done => decryptWithInvalidKey(done, aes256DecryptFile)) function decryptWithInvalidKey(done, decrypt) { let key = _hexToKey("7878787878") try { (decrypt: any)(key, stringToUtf8Uint8Array("hello"), true, false) // useMac is only used for aes256Decrypt } catch (e) { o(e instanceof CryptoError).equals(true) o(e.message.startsWith("Illegal key length")).equals(true) done() } }
o("testDecodeRegisterResponse", function () { let u2f = new U2fClient(); // test data can be extracted from the yubico java impl (compile 'com.yubico:u2flib-server-core:0.16.0') let registerResponse = u2f._decodeRegisterResponse({ clientData: "dummy", registrationData: "BQRUb_WfRhQCbhg3taktvpvtHOlGaPvaLiHUBrL71JpLzMvK4V_U9Q4cwKNdhtscM3g7VkszTDudEZ_8oOnoY1BRQMdjkqXu2j1WUjPtc0pFU8PeQd3FSIPk3RF663RhtUuVFp94mRogR2O7opbkQXumPOouLbriKZqIPebdbcVTn2kwggJDMIIBLaADAgECAgQX8O1GMAsGCSqGSIb3DQEBCzAuMSwwKgYDVQQDEyNZdWJpY28gVTJGIFJvb3QgQ0EgU2VyaWFsIDQ1NzIwMDYzMTAgFw0xNDA4MDEwMDAwMDBaGA8yMDUwMDkwNDAwMDAwMFowKTEnMCUGA1UEAwweWXViaWNvIFUyRiBFRSBTZXJpYWwgNDAxNjY1MzUwMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEQ-o66R9AJgeKoH6g3FI_WXmvdxUFy__TAreJbnl45E32rKCLQMy2nnKllZs1VfZX136Ff_pQLhUr2BB0C69RpaM7MDkwIgYJKwYBBAGCxAoCBBUxLjMuNi4xLjQuMS40MTQ4Mi4xLjIwEwYLKwYBBAGC5RwCAQEEBAMCBDAwCwYJKoZIhvcNAQELA4IBAQAvwnBqkckkOuQ35S9TJNDHSuAqdwQwRJbeF4KBDEG3ZNHdb1AcS5GL1FfzCGIiCAYVpMvaQZShExivRC204PlK7yj4zLCFds0eF7U6GH9h6JNxZnLXGcXBACk653kzkHBn7LvLIps4U--50K2w0gBQu5HM-B1ev_XXc0MDD4WWwlsY1SdL_w_OFQ-jo5uWCD_surmS-Iqcu5VlZntWzPdIpSeFznGGj7dpGzB676fQsQOizggEB0ikWmur8SqijlrNcMFAlvq0eNAzWNRDCu78b6ad1anwrAEKcanqQDrh4BbEPel9P_Gs6Ft94HYPxkfLFPFeaMJdwASMeXdV8SYVMEUCIEstAWacptwmD8f7_nN0mxag92DBFL4MjlizGmvdTpbYAiEAsb38FNfO4o1Du6Hz0H2zgZACgFSyDxXS8O1fOxSr1m4" }) o(Array.from(registerResponse.userPublicKey)).deepEquals(Array.from(base64ToUint8Array(base64UrlToBase64("BFRv9Z9GFAJuGDe1qS2-m-0c6UZo-9ouIdQGsvvUmkvMy8rhX9T1DhzAo12G2xwzeDtWSzNMO50Rn_yg6ehjUFE")))) o(Array.from(registerResponse.keyHandle)).deepEquals(Array.from(base64ToUint8Array(base64UrlToBase64("x2OSpe7aPVZSM-1zSkVTw95B3cVIg-TdEXrrdGG1S5UWn3iZGiBHY7uiluRBe6Y86i4tuuIpmog95t1txVOfaQ")))) })
o("decryptMissingMac 128", function () { let key = [151050668, 1341212767, 316219065, 2150939763] let iv = new Uint8Array([233, 159, 225, 105, 170, 223, 70, 218, 139, 107, 71, 91, 179, 231, 239, 102]) let encrypted = aes128Encrypt(key, stringToUtf8Uint8Array("hello"), iv, true, false) encrypted = concat(new Uint8Array([1]), encrypted) try { aes128Decrypt(key, encrypted, true) } catch (e) { o(e instanceof CryptoError).equals(true) o(e.message).equals("invalid mac") } })
o("oaep pad ", function () { let value = [1, 2, 3, 4] // random seed and resulting block taken from Java reference test debugging let seed = [ 105, 117, -108, -12, 80, 20, -84, -108, 113, 44, 74, 19, -126, -110, -84, 124, 58, 108, 86, 28, 5, -3, -65, -76, 80, -4, -66, 12, -14, -33, -84, 13 ] let block = [ 95, -18, 112, -22, -48, -67, 43, 71, -43, 99, -112, 5, -36, 1, 120, -109, -119, -91, 113, 112, -42, -22, -31, 31, -17, 47, 32, -2, -112, -62, -53, 51, 98, 99, -58, 62, 91, -24, 35, -37, 53, 66, -18, -68, -39, -38, 91, -124, -27, 68, -10, 39, 40, -45, 87, -64, -90, 58, -3, -39, 1, 89, -75, -88, 121, -72, 40, -14, 88, 107, 7, -117, 70, 46, -7, -49, -117, 36, 98, 39, -128, 79, -63, -94, -81, -57, -71, -43, -13, 10, -69, -54, -99, 2, 21, -49, 89, 84, 111, -121, 108, 23, -107, 55, -6, 62, -86, 74, 6, 9, 58, -71, 11, 96, -115, 120, -83, 30, -63, -125, 29, 67, -80, 15, 62, -111, -40, -6, 32, 72, -5, -113, -66, -33, -91, -47, -42, -104, -61, 107, -53, 105, 78, 96, 100, 61, -94, -28, -38, -87, -44, -125, 29, 85, -108, 93, 121, -83, 63, 16, 9, -10, 123, 86, -89, -42, 30, -51, -44, 30, -46, -84, 6, -87, -83, -117, -100, -10, 99, -53, -86, -38, -70, -116, 98, -57, -101, 60, 67, 27, -81, 99, -44, 74, -74, -29, 85, 78, -17, -74, 76, 47, 97, 120, -40, 91, 91, -57, 35, -84, 28, -68, 80, 90, -91, 95, 24, -69, 96, -107, -31, -100, -33, 54, -39, -118, -28, -23, -31, -80, -30, 94, -13, 26, 56, 41, -32, 50, 14, 63, -119, -105, 106, -99, 1, -35, -43, 82, 68, -4, -94, 46, 36, -33, 67 ] // convert unsigned bytes from Java to numbers for (let i = 0; i < seed.length; i++) { if (seed[i] < 0) { seed[i] = 256 + seed[i] } } for (let i = 0; i < block.length; i++) { if (block[i] < 0) { block[i] = 256 + block[i] } } let padded = oaepPad(new Uint8Array(value), 2048, new Uint8Array(seed)) o(Array.from(padded)).deepEquals(block) })
o("rsa key roundtrip", function () { let keyPair = _getKeyPair() let hexPrivateKey = privateKeyToHex(keyPair.privateKey) o(hexPrivateKey).equals(privateKeyToHex(hexToPrivateKey(hexPrivateKey))) let hexPublicKey = publicKeyToHex(keyPair.publicKey) o(hexPublicKey).equals(publicKeyToHex(hexToPublicKey(hexPublicKey))) let plain = hexToUint8Array("88888888888888888888888888888888") // = 16 byte sym key let encrypted = rsaEncryptSync(keyPair.publicKey, plain, random.generateRandomData(32)) let plainAgain = rsaDecryptSync(keyPair.privateKey, encrypted) o(Array.from(plainAgain)).deepEquals(Array.from(plain)) })
o("decryptManipulatedData 128 without mac", function () { let key = [151050668, 1341212767, 316219065, 2150939763] let iv = new Uint8Array([233, 159, 225, 105, 170, 223, 70, 218, 139, 107, 71, 91, 179, 231, 239, 102]) let encrypted = aes128Encrypt(key, stringToUtf8Uint8Array("hello"), iv, true, false) encrypted[0] = encrypted[0] + 1 let decrypted = aes128Decrypt(key, encrypted, true) o(utf8Uint8ArrayToString(decrypted)).equals("kello") // => encrypted data has been manipulated (missing MAC) })
o("invalid hex key conversion", function (done) { let hexPublicKey = "hello" try { hexToPublicKey(hexPublicKey) } catch (e) { o(e instanceof CryptoError).equals(true) done() } })
o("pss encode ", function () { // all values are from PssTest.java for verifying an identical implementation let message = hexToUint8Array("b25371601025fcc214c4a6ac877d8db9") let seed = hexToUint8Array("0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f20") let padded = encode(message, 2048 - 1, seed) let expected = hexToUint8Array("1133b67d48f8c52349f4aa9f72de0625cbc7b2eeffb23f0ad179683a491eb5f68465a61d0b271f9d26a1bb72553a37295f76624dba6dffd809a3a712e31de45c5b4d608e62f9dd58e3c44ec467b8ae570edd14030b79248d9f52271163c488d9ae57e660e473b904c96452508db14711d47d88b5d08be563727b22bc9860ca0c6b5bab789a4056d37f47f457db224de2516a41f7650784ae1033e579e840cf6138e577f9ba2b87fc31697db183178e38e5a2ff03d20f68c4bbc82f8f13fbd7a6a93fe9503701ee985dd53df4c36096b00d06d787001b4887f6134930b4782480de9a9097660193d69d34f1a94ca3df2c3dd3a479c562aea0f496ee6ddf2eefbc") o(Array.from(padded)).deepEquals(Array.from(expected)) })
o("one mailbox extend once", async function () { transaction.put(GroupDataOS, mailGroup, {indexTimestamp: rangeEnd}) // next index update - continue indexing await indexer._indexMailLists([{mbox: mailbox, newestTimestamp: rangeEnd}], rangeEnd2) const [mailboxesData2, indexUpdateNew2] = core.writeIndexUpdate.args _checkMailsInIndexUpdate(db, indexUpdateNew2, mail1) o(mailboxesData2).deepEquals([{groupId: mailGroup, indexTimestamp: rangeEnd2}]) })
o("element is updated in cache", async function () { let initialBody = createBodyInstance("id1", "hello") cache._putIntoCache(initialBody) let bodyUpdate = createBodyInstance("id1", "goodbye") clientEntityRequest = function (typeRef, method, listId, id, entity, queryParameter, extraHeaders) { o(isSameTypeRef(typeRef, MailBodyTypeRef)).equals(true) o(method).equals(HttpMethod.GET) o(listId).equals(null) o(id).equals(createId("id1")) return Promise.resolve(bodyUpdate) } await cache.entityEventsReceived([createUpdate(MailBodyTypeRef, (null: any), createId("id1"), OperationType.UPDATE)]) o(clientSpy.callCount).equals(1) // entity is loaded from server const body = await cache.entityRequest(MailBodyTypeRef, HttpMethod.GET, null, createId("id1"), null, null) o(body.text).equals("goodbye") o(clientSpy.callCount).equals(1) // entity is provided from cache })
return cache.entityEventsReceived([createUpdate(MailTypeRef, "listId1", createId("id2"), OperationType.DELETE)]).then(() => { o(clientSpy.callCount).equals(1) // entity is not loaded from server return cache.entityRequest(MailTypeRef, HttpMethod.GET, "listId1", null, null, { start: GENERATED_MIN_ID, count: "4", reverse: "false" }).then(mails => { o(mails).deepEquals([originalMails[0], originalMails[2]]) }) })
o("stringToNameAndMailAddress", function () { // test valid strings o(stringToNameAndMailAddress(" a@b.de ")).deepEquals({name: "", mailAddress: "*****@*****.**"}) o(stringToNameAndMailAddress(" <*****@*****.** > ")).deepEquals({name: "", mailAddress: "*****@*****.**"}) o(stringToNameAndMailAddress(" Aas Bos a@b.de")).deepEquals({name: "Aas Bos", mailAddress: "*****@*****.**"}) o(stringToNameAndMailAddress(" Aas Bos <*****@*****.**>")).deepEquals({name: "Aas Bos", mailAddress: "*****@*****.**"}) o(stringToNameAndMailAddress(" Aas Bos<*****@*****.**>")).deepEquals({name: "Aas Bos", mailAddress: "*****@*****.**"}) // test invalid strings o(stringToNameAndMailAddress(" Aas Bos <a@de>")).equals(null) o(stringToNameAndMailAddress(" Aas Bos ")).equals(null) o(stringToNameAndMailAddress(" Aas Bos a@de")).equals(null) })
o(" mailAddressToFirstAndLastName", function () { o(mailAddressToFirstAndLastName("*****@*****.**")).deepEquals({firstName: "Peter", lastName: "Pan"}) o(mailAddressToFirstAndLastName("*****@*****.**")).deepEquals({firstName: "Peter", lastName: "Pan"}) o(mailAddressToFirstAndLastName("*****@*****.**")).deepEquals({firstName: "Peter", lastName: "Pan"}) o(mailAddressToFirstAndLastName("*****@*****.**")).deepEquals({firstName: "Peter", lastName: "Pan"}) o(mailAddressToFirstAndLastName("*****@*****.**")).deepEquals({firstName: "Peter", lastName: "Pan"}) o(mailAddressToFirstAndLastName("*****@*****.**")).deepEquals({firstName: "Peter", lastName: "Pater Pan"}) o(mailAddressToFirstAndLastName("*****@*****.**")).deepEquals({firstName: "Peter", lastName: ""}) })
return facade.store().then(() => { o(transactionMock.put.args[0]).equals(SearchTermSuggestionsOS) o(transactionMock.put.args[1]).equals("contact") let encSuggestions = transactionMock.put.args[2] facade.addSuggestions(["accc", "bbbb"]) // insert new values o(facade.getSuggestions("a").join(" ")).equals("aaaa accc") o(facade.getSuggestions("b").join(" ")).equals("bbbb") let transactionLoadMock = {} db.dbFacade.createTransaction = o.spy(() => Promise.resolve(transactionLoadMock)) transactionLoadMock.get = o.spy(() => Promise.resolve(encSuggestions)) return facade.load().then(() => { // restored o(transactionLoadMock.get.args[0]).equals(SearchTermSuggestionsOS) o(transactionLoadMock.get.args[1]).equals("contact") o(facade.getSuggestions("a").join(" ")).equals("aaaa") o(facade.getSuggestions("b").join(" ")).equals("") }) })
o.spec("appendBinaryBlocks", function () { o("resizes when needed", function () { const row = new Uint8Array([0x01, 0x02]) const newDataOne = new Uint8Array(256).fill(2) const newDataTwo = new Uint8Array([0x01]) const expected = concat(new Uint8Array([0x01, 0x02]), new Uint8Array([0x82, 0x01, 0x00]), newDataOne, new Uint8Array([0x01, 0x01])) o(JSON.stringify(appendBinaryBlocks([newDataOne, newDataTwo], row))).equals(JSON.stringify(expected)) }) })
setTimeout(() => { //request key o(electronMock.net.request.callCount).equals(1) o(electronMock.net.request.args[0]).equals('https://b.s') o(n.spyify(conn200).end.callCount).equals(1) o(n.spyify(conn200).on.callCount).equals(2) o(n.spyify(response200).on.callCount).equals(3) o(autoUpdaterMock.checkForUpdates.callCount).equals(1) // don't check signature o(forgeMock.pki.publicKeyFromPem.callCount).equals(0) o(n.spyify(key).verify.callCount).equals(0) // don't show notification o(notifierMock.showOneShot.callCount).equals(0) o(autoUpdaterMock.quitAndInstall.callCount).equals(0) done() upd._stopPolling() // makes the test halt }, 190)
o("that hex keys have an even number of characters", function () { let privateKey = [] privateKey.push(parseBigInt("780377be21c903ecb8bf042e24b7d2860fd0da2c8d79aded94d2fe3bd89892ee161317529a7a011bb985899277bff28ba6b9a2ac7d63caccb5fa37a24e6faa2d69ed0b7ba10279a84172d3e00561d1efe234108dd4a3335da88483c282bb178af0168245c50330fcd988018e14962efbe8bca87bbc620945453c3b559f666472bb23447c6dea5591e89ec34f73e90702dca8837ba709e5065c6aaa12628a388e941174f0cd573935e5a80ec498031a4859101735e31b45765b9d071eac4b79b7a0cc859c5e035af853fce48fd848613ba4b3c09eb6b71a09f9dfc7ac1aaa50685f60e84f75afc3c0a13123136798aa328fe17397df2687d9d82f39121bb1ed01", 16)) privateKey.push(parseBigInt("122c5441925422280281ca5c426b2391f16b2ade7c3de4bc8940ba06cdf1acae28e193328af9d699202abc7e556bd78a96209e25888747fa5fc4181097d808e8ff95499bdaf1c9025586d1d6a679fd9459a890a9297ddd155da353606cf36fc93639f25826512965e07adbe16bf4a200bb697609e6a8e1c67f897362afd48d792cbcadeaab3e9dda29f9abc49f4b5541a04233c522ab756d7b395f513788f645c1772d5f394a53d32b67e46b38f8af4b3dddc35c42b1272383965537ca62595a12f1438687aa136bc07fbe591bd91502046bf56535a6ebf69a177be25ca060cb01b3ba3c5f9a63ef0c4b31b68086e13c9ad2014c8c1487a28d06c90c9a03a0c1", 16)) privateKey.push(parseBigInt("c3bd68ca645f97614cfbe768dc3a8930d6878de4132b09703c6c8b9a1215b337956a52d7cac9b7e28257eb64012be69d93b1c865bbdb68913d61469bf22d22061ac74c4b0c8be6a0abf40e788d71b63347f455dbeacb3b00f4ce697c55c4fe761d4cc5f2c6c7a614a34b10b8bd9e04d0ae6d2165e7c7f61e36afe554f57cae05", 16)) privateKey.push(parseBigInt("9cf5f0248ab2071ef7c8aec0069b1422925c4a1df6b4a72504adac480dbdf0fe782e0661e47c7375df0e1ad5fa1b318089e88b053d8033dcb09aa922e111244bfb90757ab74b364813e0014d9d1f7e7af68b5d85f1454a4eb8244d86bd7fc00f4aacf39df38e5b8b96099e54d3f07d0cf567a057cc9f952966dab1dbd1b1b7cd", 16)) privateKey.push(parseBigInt("1ed42c37044c11f99f3865a01c5f93cfff59e63d2fcfad72e1f16ea35b89d36a43bc35440b8a6dcddd1d9fd36663d5b4a7d86e69a786cd176305792b829f1d26bcfcfac52f3ab19e48b6edb88afe87e5d7c561e87b387b18917619231e1722c4d3a48de0c8f214f4572bb17c8750e60d400bac20f2ba89c70471fbbabfd75d49", 16)) privateKey.push(parseBigInt("d03af67b8404eaad8acc12096eba0ddc4f8f6044a026ca17b23d3571e1c93b0e5d21b215eca9ae03920784529b9bb7f06f04b26a214d1380944a9a584b7e12493b544a86a2e484feda5f335b643783f45d6046928ba30111adf97b6065c63566140b9ea6cd96ee9c2050625ce74f04974c7a4d9e2d39090a0409de2b61e6039", 16)) privateKey.push(parseBigInt("59b796421c14e90568543a263f10ca4a7c0873d8a9615f969fc328900e07f7106b30b3410e94ee40069052bcc15ec419c0937a71ab855242b746129bedc947a48deffb51ed99ea3255b3bf59bc1a4d3cea9163ef5d076c5e355b07134725903e49e4cdc48c5bd096b16d54aa0d0087bd939213134ffacf9a084fb04399d03a7e", 16)) o(_keyArrayToHex(privateKey).length % 2).equals(0) })
o("loadMultiple", async function () { const listId = "listId" const inCache = [createMailInstance(listId, "1", "1"), createMailInstance(listId, "3", "3")] const notInCache = [createMailInstance(listId, "2", "2"), createMailInstance(listId, "5", "5")] inCache.forEach((i) => cache._putIntoCache(i)) const ids = inCache.concat(notInCache).map(getElementId) clientEntityRequest = () => Promise.resolve(notInCache) const result = await cache.entityRequest(MailTypeRef, HttpMethod.GET, listId, null, null, {ids: ids.join(",")}) o(result).deepEquals(notInCache.concat(inCache)) o(clientSpy.callCount).equals(1) o(clientSpy.args).deepEquals( [MailTypeRef, HttpMethod.GET, listId, null, null, {ids: notInCache.map(getElementId).join(",")}, undefined] ) inCache.concat(notInCache).forEach((e) => { o(cache._isInCache(MailTypeRef, listId, getElementId(e))).equals(true) }) })
o("load range starting outside of stored range - reverse - read only", async function () { let mailFirst = createMailInstance("listId1", "ic5", "subject") // use ids smaller than "id1" let mailSecond = createMailInstance("listId1", "ic8", "subject") await setupMailList(false, false) clientEntityRequest = function (typeRef, method, listId, id, entity, queryParameter, extraHeaders) { // load everything from network o(queryParameter).deepEquals({start: createId("ic6"), count: "4", reverse: "true"}) return Promise.resolve([mailFirst]) } const result = await cache.entityRequest(MailTypeRef, HttpMethod.GET, "listId1", null, null, { start: createId("ic6"), count: "4", reverse: "true" }, readOnlyHeaders()) o(result).deepEquals([clone(mailFirst)]) o(cache._getFromCache(MailTypeRef, getListId(mailFirst), getElementId(mailFirst))).deepEquals(undefined) o(clientSpy.callCount).equals(2) // entities are provided from server })
o("one mailbox extend till end", async function () { transaction.put(GroupDataOS, mailGroup, {indexTimestamp: rangeEnd2}) // next index update - finish indexing const rangeEnd3 = getDayShifted(new Date(rangeEnd2), -1).getTime() await indexer._indexMailLists([{mbox: mailbox, newestTimestamp: rangeEnd2}], rangeEnd3) const [mailboxesData3, indexUpdateNew3] = core.writeIndexUpdate.args _checkMailsInIndexUpdate(db, indexUpdateNew3, mail0) o(mailboxesData3).deepEquals([{groupId: mailGroup, indexTimestamp: FULL_INDEXED_TIMESTAMP}]) })
o("getLastFocused returns the last focused window", () => { // node modules const electronMock = n.mock("electron", electron).set() // our modules const applicationWindowMock = n.mock("./ApplicationWindow", applicationWindow).set() const desktopDownloadManagerMock = n.mock("./DesktopDownloadManager", desktopDownloadManager).set() n.mock("./DesktopTray", desktopTray).set() // instances const confMock = n.mock('__conf', conf).set() const desktopTrayMock = n.mock('__tray', { getIcon: () => "this is an icon", update: () => { } }).set() const notifierMock = n.mock('__notifier', notifier).set() const ipcMock = n.mock('__ipc', ipc).set() const {WindowManager} = n.subject('../../src/desktop/DesktopWindowManager.js') const wm = new WindowManager(confMock, desktopTrayMock, notifierMock) wm.setIPC(ipcMock) const w1 = wm.newWindow(true) const w2 = wm.newWindow(true) const w3 = wm.newWindow(true) w1.callbacks['ready-to-show']() w2.callbacks['ready-to-show']() w3.callbacks['ready-to-show']() o(wm.getAll().map(w => w.id)).deepEquals([w1, w2, w3].map(w => w.id)) o(wm.getLastFocused(false).id).equals(w3.id) wm.get(w2.id).show() o(wm.getAll().map(w => w.id)).deepEquals([w1, w3, w2].map(w => w.id)) o(wm.getLastFocused(false).id).equals(w2.id) const w4 = wm.newWindow(false) w4.callbacks['ready-to-show']() o(wm.getLastFocused(false).id).equals(w2.id) })
o.spec("decodeBinaryBlock", function () { o("with short length (literal length)", function () { const searchIndexData = new Uint8Array([0x01].concat([0x00])) o(JSON.stringify(decodeBinaryBlock(searchIndexData, 0))).deepEquals(JSON.stringify(new Uint8Array([0x00]))) }) o("with short length (encoded length)", function () { const searchIndexData = new Uint8Array([0x7F].concat([0x00])) o(JSON.stringify(decodeBinaryBlock(searchIndexData, 0))).deepEquals(JSON.stringify(new Uint8Array([0x00]))) }) o("with long length", function () { const searchIndexData = new Uint8Array([0x81, 0x01].concat([0x01, 0x02, 0x03])) o(JSON.stringify(decodeBinaryBlock(searchIndexData, 0))).deepEquals(JSON.stringify(new Uint8Array([0x01]))) }) o("with long length and offset", function () { const searchIndexData = new Uint8Array([0x00, 0x82, 0x01, 0x00].concat(new Array(256).fill(0x00))) o(JSON.stringify(decodeBinaryBlock(searchIndexData, 1))).deepEquals(JSON.stringify(new Uint8Array(256))) }) })
compatibilityTestData.rsaSignatureTests.forEach(td => { random.generateRandomData = (number) => hexToUint8Array(td.seed) let privateKey = hexToPrivateKey(td.privateKey) let publicKey = hexToPublicKey(td.publicKey) let signature = sign(privateKey, hexToUint8Array(td.input)) o(uint8ArrayToHex(signature)).equals(td.result) verifySignature(publicKey, hexToUint8Array(td.input), signature) })