2018-12-13 21:41:42 +00:00
/* global Signal, Whisper, assert, textsecure, _, libsignal */
2018-04-20 19:11:56 +00:00
2018-12-13 21:41:42 +00:00
/* eslint-disable no-console */
2018-06-16 00:31:16 +00:00
2017-09-07 01:20:42 +00:00
'use strict' ;
2018-04-20 19:11:56 +00:00
describe ( 'Backup' , ( ) => {
describe ( '_sanitizeFileName' , ( ) => {
it ( 'leaves a basic string alone' , ( ) => {
2018-04-27 21:25:04 +00:00
const initial = "Hello, how are you #5 ('fine' + great).jpg" ;
2018-04-20 19:11:56 +00:00
const expected = initial ;
2018-03-19 19:42:12 +00:00
assert . strictEqual ( Signal . Backup . _sanitizeFileName ( initial ) , expected ) ;
2017-09-07 01:20:42 +00:00
} ) ;
2018-04-20 19:11:56 +00:00
it ( 'replaces all unknown characters' , ( ) => {
const initial = '!@$%^&*=' ;
const expected = '________' ;
2018-03-19 19:42:12 +00:00
assert . strictEqual ( Signal . Backup . _sanitizeFileName ( initial ) , expected ) ;
2017-09-07 01:20:42 +00:00
} ) ;
} ) ;
2018-04-20 19:11:56 +00:00
describe ( '_trimFileName' , ( ) => {
it ( 'handles a file with no extension' , ( ) => {
const initial = '0123456789012345678901234567890123456789' ;
const expected = '012345678901234567890123456789' ;
2018-03-19 19:42:12 +00:00
assert . strictEqual ( Signal . Backup . _trimFileName ( initial ) , expected ) ;
2017-09-07 01:20:42 +00:00
} ) ;
2018-04-20 19:11:56 +00:00
it ( 'handles a file with a long extension' , ( ) => {
2018-04-27 21:25:04 +00:00
const initial =
'0123456789012345678901234567890123456789.01234567890123456789' ;
2018-04-20 19:11:56 +00:00
const expected = '012345678901234567890123456789' ;
2018-03-19 19:42:12 +00:00
assert . strictEqual ( Signal . Backup . _trimFileName ( initial ) , expected ) ;
2017-09-07 01:20:42 +00:00
} ) ;
2018-04-20 19:11:56 +00:00
it ( 'handles a file with a normal extension' , ( ) => {
const initial = '01234567890123456789012345678901234567890123456789.jpg' ;
const expected = '012345678901234567890123.jpg' ;
2018-03-19 19:42:12 +00:00
assert . strictEqual ( Signal . Backup . _trimFileName ( initial ) , expected ) ;
2017-09-07 01:20:42 +00:00
} ) ;
} ) ;
2018-04-20 19:11:56 +00:00
describe ( '_getExportAttachmentFileName' , ( ) => {
it ( 'uses original filename if attachment has one' , ( ) => {
const message = {
2018-03-19 19:42:12 +00:00
body : 'something' ,
} ;
2018-04-20 19:11:56 +00:00
const index = 0 ;
const attachment = {
fileName : 'blah.jpg' ,
2017-09-07 01:20:42 +00:00
} ;
2018-04-20 19:11:56 +00:00
const expected = 'blah.jpg' ;
2018-03-19 19:42:12 +00:00
2018-04-20 19:11:56 +00:00
const actual = Signal . Backup . _getExportAttachmentFileName (
2018-03-19 19:42:12 +00:00
message ,
index ,
attachment
) ;
assert . strictEqual ( actual , expected ) ;
2017-09-07 01:20:42 +00:00
} ) ;
2018-04-20 19:11:56 +00:00
it ( 'uses attachment id if no filename' , ( ) => {
const message = {
2018-03-19 19:42:12 +00:00
body : 'something' ,
} ;
2018-04-20 19:11:56 +00:00
const index = 0 ;
const attachment = {
id : '123' ,
2017-09-07 01:20:42 +00:00
} ;
2018-04-20 19:11:56 +00:00
const expected = '123' ;
2018-03-19 19:42:12 +00:00
2018-04-20 19:11:56 +00:00
const actual = Signal . Backup . _getExportAttachmentFileName (
2018-03-19 19:42:12 +00:00
message ,
index ,
attachment
) ;
assert . strictEqual ( actual , expected ) ;
2017-09-07 01:20:42 +00:00
} ) ;
2018-04-20 19:11:56 +00:00
it ( 'uses filename and contentType if available' , ( ) => {
const message = {
2018-03-19 19:42:12 +00:00
body : 'something' ,
} ;
2018-04-20 19:11:56 +00:00
const index = 0 ;
const attachment = {
2017-09-07 01:20:42 +00:00
id : '123' ,
2018-04-20 19:11:56 +00:00
contentType : 'image/jpeg' ,
2017-09-07 01:20:42 +00:00
} ;
2018-04-20 19:11:56 +00:00
const expected = '123.jpeg' ;
2018-03-19 19:42:12 +00:00
2018-04-20 19:11:56 +00:00
const actual = Signal . Backup . _getExportAttachmentFileName (
2018-03-19 19:42:12 +00:00
message ,
index ,
attachment
) ;
assert . strictEqual ( actual , expected ) ;
2017-09-07 01:20:42 +00:00
} ) ;
2018-04-20 19:11:56 +00:00
it ( 'handles strange contentType' , ( ) => {
const message = {
2018-03-19 19:42:12 +00:00
body : 'something' ,
} ;
2018-04-20 19:11:56 +00:00
const index = 0 ;
const attachment = {
2017-09-07 01:20:42 +00:00
id : '123' ,
2018-04-20 19:11:56 +00:00
contentType : 'something' ,
2017-09-07 01:20:42 +00:00
} ;
2018-04-20 19:11:56 +00:00
const expected = '123.something' ;
2018-03-19 19:42:12 +00:00
2018-04-20 19:11:56 +00:00
const actual = Signal . Backup . _getExportAttachmentFileName (
2018-03-19 19:42:12 +00:00
message ,
index ,
attachment
) ;
assert . strictEqual ( actual , expected ) ;
} ) ;
} ) ;
2018-04-20 19:11:56 +00:00
describe ( '_getAnonymousAttachmentFileName' , ( ) => {
it ( 'uses message id' , ( ) => {
const message = {
2018-03-19 19:42:12 +00:00
id : 'id-45' ,
body : 'something' ,
} ;
2018-04-20 19:11:56 +00:00
const index = 0 ;
const attachment = {
fileName : 'blah.jpg' ,
2018-03-19 19:42:12 +00:00
} ;
2018-04-20 19:11:56 +00:00
const expected = 'id-45' ;
2018-03-19 19:42:12 +00:00
2018-04-20 19:11:56 +00:00
const actual = Signal . Backup . _getAnonymousAttachmentFileName (
2018-03-19 19:42:12 +00:00
message ,
index ,
attachment
) ;
assert . strictEqual ( actual , expected ) ;
} ) ;
2018-04-20 19:11:56 +00:00
it ( 'appends index if it is above zero' , ( ) => {
const message = {
2018-03-19 19:42:12 +00:00
id : 'id-45' ,
body : 'something' ,
} ;
2018-04-20 19:11:56 +00:00
const index = 1 ;
const attachment = {
fileName : 'blah.jpg' ,
2018-03-19 19:42:12 +00:00
} ;
2018-04-20 19:11:56 +00:00
const expected = 'id-45-1' ;
2018-03-19 19:42:12 +00:00
2018-04-20 19:11:56 +00:00
const actual = Signal . Backup . _getAnonymousAttachmentFileName (
2018-03-19 19:42:12 +00:00
message ,
index ,
attachment
) ;
assert . strictEqual ( actual , expected ) ;
2017-09-07 01:20:42 +00:00
} ) ;
} ) ;
2018-04-20 19:11:56 +00:00
describe ( '_getConversationDirName' , ( ) => {
it ( 'uses name if available' , ( ) => {
const conversation = {
2017-09-07 01:20:42 +00:00
active _at : 123 ,
name : '0123456789012345678901234567890123456789' ,
2018-04-20 19:11:56 +00:00
id : 'id' ,
2017-09-07 01:20:42 +00:00
} ;
2018-04-20 19:11:56 +00:00
const expected = '123 (012345678901234567890123456789 id)' ;
2018-04-27 21:25:04 +00:00
assert . strictEqual (
Signal . Backup . _getConversationDirName ( conversation ) ,
expected
) ;
2017-09-07 01:20:42 +00:00
} ) ;
2018-04-20 19:11:56 +00:00
it ( 'uses just id if name is not available' , ( ) => {
const conversation = {
2017-09-07 01:20:42 +00:00
active _at : 123 ,
2018-04-20 19:11:56 +00:00
id : 'id' ,
2017-09-07 01:20:42 +00:00
} ;
2018-04-20 19:11:56 +00:00
const expected = '123 (id)' ;
2018-04-27 21:25:04 +00:00
assert . strictEqual (
Signal . Backup . _getConversationDirName ( conversation ) ,
expected
) ;
2017-09-07 01:20:42 +00:00
} ) ;
2018-04-20 19:11:56 +00:00
it ( 'uses inactive for missing active_at' , ( ) => {
const conversation = {
2017-09-07 01:20:42 +00:00
name : 'name' ,
2018-04-20 19:11:56 +00:00
id : 'id' ,
2017-09-07 01:20:42 +00:00
} ;
2018-04-20 19:11:56 +00:00
const expected = 'inactive (name id)' ;
2018-04-27 21:25:04 +00:00
assert . strictEqual (
Signal . Backup . _getConversationDirName ( conversation ) ,
expected
) ;
2017-09-07 01:20:42 +00:00
} ) ;
} ) ;
2018-04-20 19:11:56 +00:00
describe ( '_getConversationLoggingName' , ( ) => {
it ( 'uses plain id if conversation is private' , ( ) => {
const conversation = {
2017-09-07 01:20:42 +00:00
active _at : 123 ,
id : 'id' ,
2018-04-20 19:11:56 +00:00
type : 'private' ,
2017-09-07 01:20:42 +00:00
} ;
2018-04-20 19:11:56 +00:00
const expected = '123 (id)' ;
assert . strictEqual (
Signal . Backup . _getConversationLoggingName ( conversation ) ,
expected
) ;
2017-09-07 01:20:42 +00:00
} ) ;
2018-04-20 19:11:56 +00:00
it ( 'uses just id if name is not available' , ( ) => {
const conversation = {
2017-09-07 01:20:42 +00:00
active _at : 123 ,
id : 'groupId' ,
2018-04-20 19:11:56 +00:00
type : 'group' ,
2017-09-07 01:20:42 +00:00
} ;
2018-04-20 19:11:56 +00:00
const expected = '123 ([REDACTED_GROUP]pId)' ;
assert . strictEqual (
Signal . Backup . _getConversationLoggingName ( conversation ) ,
expected
) ;
2017-09-07 01:20:42 +00:00
} ) ;
2018-04-20 19:11:56 +00:00
it ( 'uses inactive for missing active_at' , ( ) => {
const conversation = {
2017-09-07 01:20:42 +00:00
id : 'id' ,
2018-04-20 19:11:56 +00:00
type : 'private' ,
2017-09-07 01:20:42 +00:00
} ;
2018-04-20 19:11:56 +00:00
const expected = 'inactive (id)' ;
assert . strictEqual (
Signal . Backup . _getConversationLoggingName ( conversation ) ,
expected
) ;
2017-09-07 01:20:42 +00:00
} ) ;
} ) ;
2018-04-20 21:55:33 +00:00
describe ( 'end-to-end' , ( ) => {
2018-12-13 21:41:42 +00:00
it ( 'exports then imports to produce the same data we started with' , async function thisNeeded ( ) {
this . timeout ( 6000 ) ;
2018-06-16 00:31:16 +00:00
2018-04-27 21:25:04 +00:00
const { attachmentsPath , fse , glob , path , tmp } = window . test ;
2018-04-20 21:55:33 +00:00
const {
upgradeMessageSchema ,
loadAttachmentData ,
} = window . Signal . Migrations ;
2018-12-13 21:41:42 +00:00
const staticKeyPair = await libsignal . KeyHelper . generateIdentityKeyPair ( ) ;
2018-04-20 21:55:33 +00:00
const attachmentsPattern = path . join ( attachmentsPath , '**' ) ;
const OUR _NUMBER = '+12025550000' ;
const CONTACT _ONE _NUMBER = '+12025550001' ;
2018-04-27 16:32:31 +00:00
const CONTACT _TWO _NUMBER = '+12025550002' ;
2018-04-20 21:55:33 +00:00
2018-12-13 21:41:42 +00:00
const toArrayBuffer = nodeBuffer =>
nodeBuffer . buffer . slice (
nodeBuffer . byteOffset ,
nodeBuffer . byteOffset + nodeBuffer . byteLength
) ;
const getFixture = target => toArrayBuffer ( fse . readFileSync ( target ) ) ;
const FIXTURES = {
gif : getFixture ( 'fixtures/giphy-7GFfijngKbeNy.gif' ) ,
mp4 : getFixture ( 'fixtures/pixabay-Soap-Bubble-7141.mp4' ) ,
jpg : getFixture ( 'fixtures/koushik-chowdavarapu-105425-unsplash.jpg' ) ,
mp3 : getFixture ( 'fixtures/incompetech-com-Agnus-Dei-X.mp3' ) ,
txt : getFixture ( 'fixtures/lorem-ipsum.txt' ) ,
png : getFixture (
'fixtures/freepngs-2cd43b_bed7d1327e88454487397574d87b64dc_mv2.png'
) ,
} ;
2018-04-20 21:55:33 +00:00
async function wrappedLoadAttachment ( attachment ) {
return _ . omit ( await loadAttachmentData ( attachment ) , [ 'path' ] ) ;
}
async function clearAllData ( ) {
await textsecure . storage . protocol . removeAllData ( ) ;
await fse . emptyDir ( attachmentsPath ) ;
}
function removeId ( model ) {
return _ . omit ( model , [ 'id' ] ) ;
}
2018-04-25 19:03:04 +00:00
const getUndefinedKeys = object =>
Object . entries ( object )
. filter ( ( [ , value ] ) => value === undefined )
. map ( ( [ name ] ) => name ) ;
const omitUndefinedKeys = object =>
_ . omit ( object , getUndefinedKeys ( object ) ) ;
2018-04-23 22:36:47 +00:00
// We want to know which paths have two slashes, since that tells us which files
// in the attachment fan-out are files vs. directories.
const TWO _SLASHES = /[^/]*\/[^/]*\/[^/]*/ ;
2018-04-21 00:29:55 +00:00
// On windows, attachmentsPath has a normal windows path format (\ separators), but
// glob returns only /. We normalize to / separators for our manipulations.
const normalizedBase = attachmentsPath . replace ( /\\/g , '/' ) ;
2018-04-20 21:55:33 +00:00
function removeDirs ( dirs ) {
2018-04-27 21:25:04 +00:00
return _ . filter ( dirs , fullDir => {
2018-04-21 00:29:55 +00:00
const dir = fullDir . replace ( normalizedBase , '' ) ;
2018-04-23 22:36:47 +00:00
return TWO _SLASHES . test ( dir ) ;
2018-04-20 21:55:33 +00:00
} ) ;
}
function _mapQuotedAttachments ( mapper ) {
return async ( message , context ) => {
if ( ! message . quote ) {
return message ;
}
2018-04-27 21:25:04 +00:00
const wrappedMapper = async attachment => {
2018-04-20 21:55:33 +00:00
if ( ! attachment || ! attachment . thumbnail ) {
return attachment ;
}
return Object . assign ( { } , attachment , {
thumbnail : await mapper ( attachment . thumbnail , context ) ,
} ) ;
} ;
2018-04-27 21:25:04 +00:00
const quotedAttachments =
( message . quote && message . quote . attachments ) || [ ] ;
2018-04-20 21:55:33 +00:00
return Object . assign ( { } , message , {
quote : Object . assign ( { } , message . quote , {
2018-04-27 21:25:04 +00:00
attachments : await Promise . all (
quotedAttachments . map ( wrappedMapper )
) ,
2018-04-20 21:55:33 +00:00
} ) ,
} ) ;
} ;
}
async function loadAllFilesFromDisk ( message ) {
2018-04-27 21:25:04 +00:00
const loadThumbnails = _mapQuotedAttachments ( thumbnail => {
2018-04-20 21:55:33 +00:00
// we want to be bulletproof to thumbnails without data
if ( ! thumbnail . path ) {
return thumbnail ;
}
return wrappedLoadAttachment ( thumbnail ) ;
} ) ;
2018-04-27 21:25:04 +00:00
return Object . assign ( { } , await loadThumbnails ( message ) , {
2018-04-27 16:32:31 +00:00
contact : await Promise . all (
( message . contact || [ ] ) . map ( async contact => {
return contact && contact . avatar && contact . avatar . avatar
? Object . assign ( { } , contact , {
avatar : Object . assign ( { } , contact . avatar , {
avatar : await wrappedLoadAttachment (
contact . avatar . avatar
) ,
} ) ,
} )
: contact ;
} )
) ,
attachments : await Promise . all (
2018-12-13 21:41:42 +00:00
( message . attachments || [ ] ) . map ( async attachment => {
await wrappedLoadAttachment ( attachment ) ;
if ( attachment . thumbnail ) {
await wrappedLoadAttachment ( attachment . thumbnail ) ;
}
if ( attachment . screenshot ) {
await wrappedLoadAttachment ( attachment . screenshot ) ;
}
return attachment ;
} )
2018-04-27 16:32:31 +00:00
) ,
2019-01-16 03:03:56 +00:00
preview : await Promise . all (
( message . preview || [ ] ) . map ( async item => {
if ( item . image ) {
await wrappedLoadAttachment ( item . image ) ;
}
return item ;
} )
) ,
2018-04-27 21:25:04 +00:00
} ) ;
2018-04-20 21:55:33 +00:00
}
let backupDir ;
try {
2018-12-13 21:41:42 +00:00
// Seven total:
// - Five from image/video attachments
// - One from embedded contact avatar
2019-01-16 03:03:56 +00:00
// - One from embedded quoted attachment thumbnail
// - One from a link preview image
const ATTACHMENT _COUNT = 8 ;
2018-04-20 21:55:33 +00:00
const MESSAGE _COUNT = 1 ;
const CONVERSATION _COUNT = 1 ;
const messageWithAttachments = {
conversationId : CONTACT _ONE _NUMBER ,
body : 'Totally!' ,
source : OUR _NUMBER ,
received _at : 1524185933350 ,
timestamp : 1524185933350 ,
errors : [ ] ,
2018-04-27 21:25:04 +00:00
attachments : [
2018-12-13 21:41:42 +00:00
// Note: generates two more files: screenshot and thumbnail
{
contentType : 'video/mp4' ,
fileName : 'video.mp4' ,
data : FIXTURES . mp4 ,
} ,
// Note: generates one more file: thumbnail
2018-04-27 21:25:04 +00:00
{
2018-12-13 21:41:42 +00:00
contentType : 'image/png' ,
fileName : 'landscape.png' ,
data : FIXTURES . png ,
2018-04-27 21:25:04 +00:00
} ,
] ,
2018-04-24 22:44:57 +00:00
hasAttachments : 1 ,
hasVisualMediaAttachments : 1 ,
2018-04-20 21:55:33 +00:00
quote : {
text : "Isn't it cute?" ,
author : CONTACT _ONE _NUMBER ,
id : 12345678 ,
2018-04-27 21:25:04 +00:00
attachments : [
{
contentType : 'audio/mp3' ,
fileName : 'song.mp3' ,
2018-04-20 21:55:33 +00:00
} ,
2018-04-27 21:25:04 +00:00
{
contentType : 'image/gif' ,
2018-12-13 21:41:42 +00:00
fileName : 'avatar.gif' ,
2018-04-27 21:25:04 +00:00
thumbnail : {
contentType : 'image/png' ,
2018-12-13 21:41:42 +00:00
data : FIXTURES . gif ,
2018-04-27 21:25:04 +00:00
} ,
} ,
] ,
2018-04-20 21:55:33 +00:00
} ,
2018-04-27 16:32:31 +00:00
contact : [
{
name : {
displayName : 'Someone Somewhere' ,
} ,
number : [
{
value : CONTACT _TWO _NUMBER ,
type : 1 ,
} ,
] ,
avatar : {
isProfile : false ,
avatar : {
contentType : 'image/png' ,
2018-12-13 21:41:42 +00:00
data : FIXTURES . png ,
2018-04-27 16:32:31 +00:00
} ,
} ,
} ,
] ,
2019-01-16 03:03:56 +00:00
preview : [
{
url : 'https://www.instagram.com/p/BsOGulcndj-/' ,
title :
'EGG GANG 🌍 on Instagram: “Let’ s set a world record together and get the most liked post on Instagram. Beating the current world record held by Kylie Jenner (18…”' ,
image : {
contentType : 'image/jpeg' ,
data : FIXTURES . jpg ,
} ,
} ,
] ,
2018-04-20 21:55:33 +00:00
} ;
console . log ( 'Backup test: Clear all data' ) ;
await clearAllData ( ) ;
console . log ( 'Backup test: Create models, save to db/disk' ) ;
const message = await upgradeMessageSchema ( messageWithAttachments ) ;
console . log ( { message } ) ;
2018-12-13 21:41:42 +00:00
await window . Signal . Data . saveMessage ( message , {
Message : Whisper . Message ,
} ) ;
2018-04-20 21:55:33 +00:00
const conversation = {
active _at : 1524185933350 ,
color : 'orange' ,
expireTimer : 0 ,
id : CONTACT _ONE _NUMBER ,
name : 'Someone Somewhere' ,
profileAvatar : {
contentType : 'image/jpeg' ,
2018-12-13 21:41:42 +00:00
data : FIXTURES . jpeg ,
2018-04-20 21:55:33 +00:00
size : 64 ,
} ,
2018-12-13 21:41:42 +00:00
profileKey : 'BASE64KEY' ,
2018-04-20 21:55:33 +00:00
profileName : 'Someone! 🤔' ,
profileSharing : true ,
timestamp : 1524185933350 ,
type : 'private' ,
unreadCount : 0 ,
verified : 0 ,
2018-12-13 21:41:42 +00:00
sealedSender : 0 ,
version : 2 ,
2018-04-20 21:55:33 +00:00
} ;
console . log ( { conversation } ) ;
2018-09-21 01:47:19 +00:00
await window . Signal . Data . saveConversation ( conversation , {
Conversation : Whisper . Conversation ,
} ) ;
2018-04-20 21:55:33 +00:00
2018-04-27 21:25:04 +00:00
console . log (
'Backup test: Ensure that all attachments were saved to disk'
) ;
2018-04-20 21:55:33 +00:00
const attachmentFiles = removeDirs ( glob . sync ( attachmentsPattern ) ) ;
console . log ( { attachmentFiles } ) ;
assert . strictEqual ( ATTACHMENT _COUNT , attachmentFiles . length ) ;
console . log ( 'Backup test: Export!' ) ;
backupDir = tmp . dirSync ( ) . name ;
console . log ( { backupDir } ) ;
2018-12-13 21:41:42 +00:00
await Signal . Backup . exportToDirectory ( backupDir , {
key : staticKeyPair . pubKey ,
} ) ;
2018-04-20 21:55:33 +00:00
2018-12-13 21:41:42 +00:00
console . log ( 'Backup test: Ensure that messages.tar.gz exists' ) ;
const archivePath = path . join ( backupDir , 'messages.tar.gz' ) ;
const messageZipExists = fse . existsSync ( archivePath ) ;
2018-04-20 21:55:33 +00:00
assert . strictEqual ( true , messageZipExists ) ;
2018-04-27 21:25:04 +00:00
console . log (
'Backup test: Ensure that all attachments made it to backup dir'
) ;
2018-04-20 21:55:33 +00:00
const backupAttachmentPattern = path . join ( backupDir , 'attachments/*' ) ;
const backupAttachments = glob . sync ( backupAttachmentPattern ) ;
console . log ( { backupAttachments } ) ;
assert . strictEqual ( ATTACHMENT _COUNT , backupAttachments . length ) ;
console . log ( 'Backup test: Clear all data' ) ;
await clearAllData ( ) ;
console . log ( 'Backup test: Import!' ) ;
2018-12-13 21:41:42 +00:00
await Signal . Backup . importFromDirectory ( backupDir , {
key : staticKeyPair . privKey ,
} ) ;
2018-04-20 21:55:33 +00:00
2018-12-13 21:41:42 +00:00
console . log ( 'Backup test: Check conversations' ) ;
const conversationCollection = await window . Signal . Data . getAllConversations (
{
ConversationCollection : Whisper . ConversationCollection ,
}
) ;
assert . strictEqual ( conversationCollection . length , CONVERSATION _COUNT ) ;
const conversationFromDB = conversationCollection . at ( 0 ) . attributes ;
console . log ( { conversationFromDB , conversation } ) ;
assert . deepEqual (
conversationFromDB ,
_ . omit ( conversation , [ 'profileAvatar' ] )
2018-04-27 21:25:04 +00:00
) ;
2018-04-20 21:55:33 +00:00
console . log ( 'Backup test: Check messages' ) ;
2018-09-21 01:47:19 +00:00
const messageCollection = await window . Signal . Data . getAllMessages ( {
MessageCollection : Whisper . MessageCollection ,
} ) ;
2018-04-20 21:55:33 +00:00
assert . strictEqual ( messageCollection . length , MESSAGE _COUNT ) ;
const messageFromDB = removeId ( messageCollection . at ( 0 ) . attributes ) ;
2018-12-13 21:41:42 +00:00
const expectedMessage = messageFromDB ;
2018-04-25 19:03:04 +00:00
console . log ( { messageFromDB , expectedMessage } ) ;
2018-04-27 21:25:04 +00:00
assert . deepEqual ( messageFromDB , expectedMessage ) ;
2018-04-20 21:55:33 +00:00
2018-12-13 21:41:42 +00:00
console . log ( 'Backup test: ensure that all attachments were imported' ) ;
const recreatedAttachmentFiles = removeDirs (
glob . sync ( attachmentsPattern )
) ;
console . log ( { recreatedAttachmentFiles } ) ;
assert . strictEqual ( ATTACHMENT _COUNT , recreatedAttachmentFiles . length ) ;
assert . deepEqual ( attachmentFiles , recreatedAttachmentFiles ) ;
2018-04-27 21:25:04 +00:00
console . log (
'Backup test: Check that all attachments were successfully imported'
) ;
const messageWithAttachmentsFromDB = await loadAllFilesFromDisk (
messageFromDB
) ;
2018-12-13 21:41:42 +00:00
const expectedMessageWithAttachments = await loadAllFilesFromDisk (
omitUndefinedKeys ( message )
2018-04-27 21:25:04 +00:00
) ;
console . log ( {
messageWithAttachmentsFromDB ,
expectedMessageWithAttachments ,
} ) ;
2018-04-20 21:55:33 +00:00
assert . deepEqual (
2018-12-13 21:41:42 +00:00
messageWithAttachmentsFromDB ,
2018-04-25 19:03:04 +00:00
expectedMessageWithAttachments
2018-04-20 21:55:33 +00:00
) ;
console . log ( 'Backup test: Clear all data' ) ;
await clearAllData ( ) ;
console . log ( 'Backup test: Complete!' ) ;
} finally {
if ( backupDir ) {
console . log ( { backupDir } ) ;
console . log ( 'Deleting' , backupDir ) ;
await fse . remove ( backupDir ) ;
}
}
} ) ;
} ) ;
2017-09-07 01:20:42 +00:00
} ) ;