import { expect } from 'chai'; import { stringToUint8Array } from '../../../../session/utils/String'; import { from_hex, to_hex } from 'libsodium-wrappers-sumo'; import { concatUInt8Array } from '../../../../session/crypto'; import * as SessionUtilWrapper from 'session_util_wrapper'; // tslint:disable: chai-vague-errors no-unused-expression no-http-string no-octal-literal whitespace describe('libsession_wrapper', () => { it('[config][user_profile][c]', () => { // Note: To run this test, you need to compile the libsession wrapper for node (and not for electron). // To do this, you can cd to the node_module/libsession_wrapper folder and do // yarn configure && yarn build // once that is done, you can rename this file and remove the _skip suffix so that test is run. // We have to disable it by filename as nodejs tries to load the module during the import step above, and fails as it is not compiled for nodejs but for electron. const edSecretKey = from_hex( '0123456789abcdef0123456789abcdef000000000000000000000000000000004cb76fdc6d32278e3f83dbf608360ecc6b65727934b85d2fb86862ff98c46ab7' ); // Initialize a brand new, empty config because we have no dump data to deal with. const conf = new SessionUtilWrapper.UserConfigWrapper(edSecretKey, null); // We don't need to push anything, since this is an empty config expect(conf.needsPush()).to.be.eql(false); expect(conf.needsDump()).to.be.eql(false); // Since it's empty there shouldn't be a name. expect(conf.getName()).to.be.null; let pushResult = conf.push(); expect(pushResult.seqno).to.be.eq(0); expect(pushResult.data.length).to.be.eq(256); expect(conf.encryptionDomain()).to.be.eq('UserProfile'); expect(conf.storageNamespace()).to.be.eq(2); expect(to_hex(pushResult.data)).to.be.deep.eq( '9ffb5347e061ac40d937ae4f1a890031475bdc11653f94c8ae1d516ffda71d9ee9cdaf9fbaeb15d835cdc7b3b6ecc120361f004ff172dd5e757c80ede10e88945536e6841255a7bca73664ab8a0607fcfe2579c05bb3d9d4b34ac1de2921e703783ce39e317a512cb9d4e3b59176cbde47b5ba24a03065bf8fefe3e8ca2609e0ad10c7c9c3f81dc6d3a399bda0c190e8a228d0acb22863ab84c2d0c411be74dac4de1f8bc18539635db01ea1ef7f28e505703d67786cb419690edd4bd8c92926fc1d6449eaccc31d7d9639e1b36222e5672b87d1e34b7860308c3f40b3997f39fecf6ceb889323826fa69e001816307799fc9fed302a90faa1e43f7cd7367c3c' ); // This should also be unset: const picResult = conf.getProfilePic(); expect(picResult.url).to.be.null; expect(picResult.key).to.be.null; // Now let's go set a profile name and picture: conf.setProfilePic('http://example.org/omg-pic-123.bmp', stringToUint8Array('secret')); conf.setName('Kallie'); // Retrieve them just to make sure they set properly: const name = conf.getName(); expect(name).to.be.not.null; expect(name).to.be.eq('Kallie'); const picture = conf.getProfilePic(); expect(picture.url).to.be.eq('http://example.org/omg-pic-123.bmp'); expect(picture.key).to.be.deep.eq(stringToUint8Array('secret')); // Since we've made changes, we should need to push new config to the swarm, *and* should need // to dump the updated state: expect(conf.needsDump()).to.be.true; expect(conf.needsPush()).to.be.true; // incremented since we made changes (this only increments once between // dumps; even though we changed two fields here). pushResult = conf.push(); expect(pushResult.seqno).to.be.eq(1); const expHash0 = from_hex('ea173b57beca8af18c3519a7bbf69c3e7a05d1c049fa9558341d8ebb48b0c965'); const expPush1Start = 'd1:#i1e1:&d1:n6:Kallie1:p34:http://example.org/omg-pic-123.bmp1:q6:secrete1: