@ -1,18 +1,18 @@
/* eslint-disable no-console */
const {
describe , it , before , after ,
} = require ( 'mocha' ) ;
const chai = require ( 'chai' ) . use ( require ( 'chai-as-promised' ) ) ;
describe , it , before , after ,
} = require ( "mocha" ) ;
const chai = require ( "chai" ) . use ( require ( "chai-as-promised" ) ) ;
chai . should ( ) ;
const pEp = require ( '../../addon/content/modules/pEp' ) ;
const { getQueue } = require ( '../mock' ) ;
const { getController } = require ( '../boilerplate' ) ;
const pEp = require ( "../../addon/content/modules/pEp" ) ;
const { getQueue } = require ( "../mock" ) ;
const { getController } = require ( "../boilerplate" ) ;
const ENC_FORMAT_PEP = 4 ;
const DIR_OUTGOING = 1 ;
// Restored from https://pep-security.lu/dev/repos/pEp_for_Thunderbird/diff/2770741ed46e/chrome/content/modules/pEp.js
function encryptMail ( controller , subject = '' , body = '' , htmlBody = '' , from = '' , to = [ ] , cc = [ ] , bcc = [ ] , encodingFormat = ENC_FORMAT_PEP ) {
function encryptMail ( controller , subject = "" , body = "" , htmlBody = "" , from = "" , to = [ ] , cc = [ ] , bcc = [ ] , encodingFormat = ENC_FORMAT_PEP ) {
body = quoted_printable_decode ( body ) ;
const msgId = "testID@pep.security" ;
const message = new pEp . Message ( msgId , subject , body , from , to , DIR_OUTGOING , encodingFormat , [ ] , [ ] , htmlBody ) ;
@ -46,412 +46,524 @@ function quoted_printable_decode(str) {
// the RFC states against decoding lower case encodings, but following apparent PHP behavior
// RFC2045Decode2IN = /=([0-9A-F]{2})/gm,
const RFC2045Decode2OUT = function ( sMatch , sHex ) {
return String . fromCharCode ( parseInt ( sHex , 16 ) ) ;
return String . fromCharCode ( parseInt ( sHex , 16 ) ) ;
} ;
return str . replace ( RFC2045Decode1 , '' )
. replace ( RFC2045Decode2IN , RFC2045Decode2OUT ) ;
return str . replace ( RFC2045Decode1 , "" )
. replace ( RFC2045Decode2IN , RFC2045Decode2OUT ) ;
}
describe ( 'pEp Encrypt Feature' , ( ) => {
let b ;
let queue ;
let pEpController ;
describe ( 'Without having public key' , ( ) => {
let result ;
let message ;
const from = 'cfg@pep.security' ;
const to = 'to@test.com' ;
const subject = 'subject' ;
const body = 'Not Encrypted Message' ;
before ( ( ) => {
queue = getQueue ( ) ;
pEpController = getController ( queue ) ;
queue . respondWith ( {
jsonrpc : '2.0' ,
id : 1 ,
result : {
outParams : [ null , {
dir : 1 ,
id : 'pEp-0' ,
shortmsg : subject ,
longmsg : body ,
longmsg_formatted : "" ,
attachments : [ ] ,
from : { address : 'cfg@pep.security' , fpr : '' , user_id : '' , username : '' } ,
to : [ { address : to , fpr : '' , user_id : '' , username : '' } ] ,
enc_format : 3 ,
} ] ,
return : { status : 1024 , hex : '0x400 "PEP_UNENCRYPTED"' } ,
errorstack : [ '(1 elements cleared)' ] ,
} ,
} ) ;
result = encryptMail ( pEpController , subject , body , '' , from , to ) ;
} ) ;
after ( ( ) => {
queue . after ( ) ;
pEpController . after ( ) ;
} ) ;
it ( 'returns an unencrypted message' , ( ) => {
queue . expectSent (
{ "security_token" : "0847cqi9WqqE5ZcVtA8_mDIgEmYMv14xlNAvSZW" , "method" : "cache_encrypt_message" , "params" : [ { "dir" : 1 , "id" : "testID@pep.security" , "shortmsg" : "subject" , "longmsg" : "Not Encrypted Message" , "longmsg_formatted" : "" , "attachments" : [ ] , "rawmsg_ref" : "" , "rawmsg_size" : "" , "from" : { "user_id" : "" , "username" : "" , "address" : "cfg@pep.security" , "fpr" : "" } , "to" : [ { "user_id" : "" , "username" : "" , "address" : "to@test.com" , "fpr" : "" } ] , "in_reply_to" : [ ] , "opt_fields" : [ ] , "enc_format" : 4 , "cc" : [ ] } , [ ] , [ "OP" ] , 4 , 0 ] , "id" : 1 , "jsonrpc" : "2.0" }
) ;
result . should . eventually . have . property ( 'enc_format' , 0 ) ;
message = new pEp . Message ( 'pEp-0' , subject , body , from , to ) ;
message . longmsg_formatted = '' ;
message . setCc ( [ ] ) ;
message . setBcc ( [ ] ) ;
message . enc_format = 0 ;
return result . should . become ( message ) ;
} ) ;
describe ( "pEp Encrypt Feature" , ( ) => {
let b ;
let queue ;
let pEpController ;
describe ( "Without having public key" , ( ) => {
let result ;
let message ;
const from = "cfg@pep.security" ;
const to = "to@test.com" ;
const subject = "subject" ;
const body = "Not Encrypted Message" ;
before ( ( ) => {
queue = getQueue ( ) ;
pEpController = getController ( queue ) ;
queue . respondWith ( {
jsonrpc : "2.0" ,
id : 1 ,
result : {
outParams : [ null , {
dir : 1 ,
id : "pEp-0" ,
shortmsg : subject ,
longmsg : body ,
longmsg_formatted : "" ,
attachments : [ ] ,
from : {
address : "cfg@pep.security" , fpr : "" , user_id : "" , username : "" ,
} ,
to : [ {
address : to , fpr : "" , user_id : "" , username : "" ,
} ] ,
enc_format : 3 ,
} ] ,
return : { status : 1024 , hex : "0x400 \"PEP_UNENCRYPTED\"" } ,
errorstack : [ "(1 elements cleared)" ] ,
} ,
} ) ;
result = encryptMail ( pEpController , subject , body , "" , from , to ) ;
} ) ;
after ( ( ) => {
queue . after ( ) ;
pEpController . after ( ) ;
} ) ;
describe ( 'Perfect scenario' , ( ) => {
let from ;
let to ;
let subject ;
let body ;
let message ;
let result ;
before ( ( ) => {
queue = getQueue ( ) ;
pEpController = getController ( queue ) ;
queue . respondWith ( {
jsonrpc : '2.0' ,
id : 2 ,
result : {
outParams : [ {
dir : 1 ,
id : 'pEp.PXRZLM.16E95EA7JPDTS.BEFBAEC0-94DC-4AA2-A239-FE24BAA73911@pep.security' ,
shortmsg : 'p≡p' ,
longmsg : 'this message was encrypted with p≡p https://pEp-project.org' ,
attachments : [ {
value : 'VmVyc2lvbjogMQ==' ,
size : 10 ,
mime_type : 'application/pgp-encrypted' ,
} , {
value : 'mockvalue' ,
size : 3681 ,
mime_type : 'application/octet-stream' ,
filename : 'file://msg.asc' ,
} ] ,
from : {
address : 'cfg@pep.security' ,
fpr : 'B5313A3FBF6720F2A421F8B3B8C7ED6CD7FF61B5' ,
user_id : 'pEp_own_userId' ,
username : 'anonymous' ,
comm_type : 255 ,
} ,
to : [ {
address : 'cfg@pep.security' ,
fpr : 'B5313A3FBF6720F2A421F8B3B8C7ED6CD7FF61B5' ,
user_id : 'pEp_own_userId' ,
username : 'anonymous' ,
comm_type : 255 ,
} ] ,
opt_fields : [ { key : 'X-pEp-Version' , value : '2.1' } ] ,
enc_format : 3 ,
} ] ,
return : { status : 0 , hex : '0 "PEP_STATUS_OK"' } ,
errorstack : [ '(1 elements cleared)' ] ,
} ,
} ) ;
from = 'cfg@pep.security' ;
to = 'cfg@pep.security' ;
subject = 'subject' ;
body = 'Not Encrypted Message' ;
result = encryptMail ( pEpController , subject , body , '' , from , to ) ;
} ) ;
after ( ( ) => {
queue . after ( ) ;
pEpController . after ( ) ;
} ) ;
it ( 'sends as expected' , ( ) => {
queue . expectSent (
{ "security_token" : "0847cqi9WqqE5ZcVtA8_mDIgEmYMv14xlNAvSZW" , "method" : "cache_encrypt_message" , "params" : [ { "dir" : 1 , "id" : "testID@pep.security" , "shortmsg" : "subject" , "longmsg" : "Not Encrypted Message" , "longmsg_formatted" : "" , "attachments" : [ ] , "rawmsg_ref" : "" , "rawmsg_size" : "" , "from" : { "user_id" : "" , "username" : "" , "address" : "cfg@pep.security" , "fpr" : "" } , "to" : [ { "user_id" : "" , "username" : "" , "address" : "cfg@pep.security" , "fpr" : "" } ] , "in_reply_to" : [ ] , "opt_fields" : [ ] , "enc_format" : 4 , "cc" : [ ] } , [ ] , [ "OP" ] , 4 , 0 ] , "id" : 1 , "jsonrpc" : "2.0" }
) ;
} ) ;
it ( 'should resolve into an encrypted mail' , ( ) => result . should . be . fulfilled ) ;
it ( 'should return an outgoing message' , ( ) => result . should . eventually . have . property ( 'dir' ) . then ( ( dir ) => {
dir . should . be . equal ( 1 ) ;
} ) ) ;
it ( 'should return formated with enc_format default' , ( ) => result . should . eventually . have . property ( 'enc_format' ) . then ( ( enc_format ) => {
enc_format . should . be . equal ( 3 ) ;
} ) ) ;
it ( 'should return sender fingerprints' , ( ) => result . should . eventually . have . property ( 'from' ) . then ( ( sender ) => {
sender . address . should . be . equal ( from ) ;
sender . comm_type . should . be . equal ( 255 ) ;
sender . fpr . should . be . equal ( 'B5313A3FBF6720F2A421F8B3B8C7ED6CD7FF61B5' ) ;
sender . user_id . should . be . equal ( 'pEp_own_userId' ) ;
sender . username . should . be . equal ( 'anonymous' ) ;
} ) ) ;
it ( 'should return receiver fingerprints' , ( ) => result . should . eventually . have . property ( 'to' ) . then ( ( receivers ) => {
receivers . length . should . be . gte ( 1 ) ;
receivers [ 0 ] . address . should . be . equal ( to ) ;
receivers [ 0 ] . comm_type . should . be . equal ( 255 ) ;
receivers [ 0 ] . fpr . should . be . equal ( 'B5313A3FBF6720F2A421F8B3B8C7ED6CD7FF61B5' ) ;
receivers [ 0 ] . user_id . should . be . equal ( 'pEp_own_userId' ) ;
receivers [ 0 ] . username . should . be . equal ( 'anonymous' ) ;
} ) ) ;
it ( 'should have at least 2 attachments' , ( ) => result . should . eventually . have . property ( 'attachments' ) . then ( ( attachments ) => {
attachments . length . should . be . gte ( 2 ) ;
attachments [ 0 ] . mime_type . should . be . equal ( 'application/pgp-encrypted' ) ;
attachments [ 1 ] . mime_type . should . be . equal ( 'application/octet-stream' ) ;
attachments [ 1 ] . filename . should . be . equal ( 'file://msg.asc' ) ;
} ) ) ;
it ( 'should have x-pEp-version header' , ( ) => result . should . eventually . have . property ( 'opt_fields' ) . then ( ( opt_fields ) => {
opt_fields [ 0 ] . key . should . be . equal ( 'X-pEp-Version' ) ;
} ) ) ;
it ( 'should have pEp subject' , ( ) => result . should . eventually . have . property ( 'shortmsg' ) . then ( ( shortmsg ) => {
shortmsg . should . be . equal ( 'p≡p' ) ;
} ) ) ;
it ( 'should have encrypted body' , ( ) => result . should . eventually . have . property ( 'longmsg' ) . then ( ( longmsg ) => {
longmsg . should . be . equal ( 'this message was encrypted with p≡p https://pEp-project.org' ) ;
} ) ) ;
it ( "returns an unencrypted message" , ( ) => {
queue . expectSent (
{
security_token : "0847cqi9WqqE5ZcVtA8_mDIgEmYMv14xlNAvSZW" ,
method : "cache_encrypt_message" ,
params : [ {
dir : 1 ,
id : "testID@pep.security" ,
shortmsg : "subject" ,
longmsg : "Not Encrypted Message" ,
longmsg_formatted : "" ,
attachments : [ ] ,
rawmsg_ref : "" ,
rawmsg_size : "" ,
from : {
user_id : "" , username : "" , address : "cfg@pep.security" , fpr : "" ,
} ,
to : [ {
user_id : "" , username : "" , address : "to@test.com" , fpr : "" ,
} ] ,
in_reply_to : [ ] ,
opt_fields : [ ] ,
enc_format : 4 ,
cc : [ ] ,
} , [ ] , [ "OP" ] , 4 , 0 ] ,
id : 1 ,
jsonrpc : "2.0" ,
} ,
) ;
result . should . eventually . have . property ( "enc_format" , 0 ) ;
message = new pEp . Message ( "pEp-0" , subject , body , from , to ) ;
message . longmsg_formatted = "" ;
message . setCc ( [ ] ) ;
message . setBcc ( [ ] ) ;
message . enc_format = 0 ;
return result . should . become ( message ) ;
} ) ;
} ) ;
describe ( "Perfect scenario" , ( ) => {
let from ;
let to ;
let subject ;
let body ;
let message ;
let result ;
before ( ( ) => {
queue = getQueue ( ) ;
pEpController = getController ( queue ) ;
queue . respondWith ( {
jsonrpc : "2.0" ,
id : 2 ,
result : {
outParams : [ {
dir : 1 ,
id : "pEp.PXRZLM.16E95EA7JPDTS.BEFBAEC0-94DC-4AA2-A239-FE24BAA73911@pep.security" ,
shortmsg : "p≡p" ,
longmsg : "this message was encrypted with p≡p https://pEp-project.org" ,
attachments : [ {
value : "VmVyc2lvbjogMQ==" ,
size : 10 ,
mime_type : "application/pgp-encrypted" ,
} , {
value : "mockvalue" ,
size : 3681 ,
mime_type : "application/octet-stream" ,
filename : "file://msg.asc" ,
} ] ,
from : {
address : "cfg@pep.security" ,
fpr : "B5313A3FBF6720F2A421F8B3B8C7ED6CD7FF61B5" ,
user_id : "pEp_own_userId" ,
username : "anonymous" ,
comm_type : 255 ,
} ,
to : [ {
address : "cfg@pep.security" ,
fpr : "B5313A3FBF6720F2A421F8B3B8C7ED6CD7FF61B5" ,
user_id : "pEp_own_userId" ,
username : "anonymous" ,
comm_type : 255 ,
} ] ,
opt_fields : [ { key : "X-pEp-Version" , value : "2.1" } ] ,
enc_format : 3 ,
} ] ,
return : { status : 0 , hex : "0 \"PEP_STATUS_OK\"" } ,
errorstack : [ "(1 elements cleared)" ] ,
} ,
} ) ;
from = "cfg@pep.security" ;
to = "cfg@pep.security" ;
subject = "subject" ;
body = "Not Encrypted Message" ;
result = encryptMail ( pEpController , subject , body , "" , from , to ) ;
} ) ;
after ( ( ) => {
queue . after ( ) ;
pEpController . after ( ) ;
} ) ;
describe ( 'Multiple recivers' , ( ) => {
let from ;
let to ;
let subject ;
let body ;
let cc ;
let
bcc ;
before ( ( ) => {
queue = getQueue ( ) ;
pEpController = getController ( queue ) ;
queue . respondWith ( {
jsonrpc : '2.0' ,
id : 1 ,
result : {
outParams : [ {
dir : 1 ,
id : 'pEp-0' ,
shortmsg : 'p≡p' ,
longmsg : 'this message was encrypted with p≡p https://pEp-project.org' ,
attachments : [ {
value : 'VmVyc2lvbjogMQ==' ,
size : 10 ,
mime_type : 'application/pgp-encrypted' ,
} , {
value : 'mocked value' ,
size : 5071 ,
mime_type : 'application/octet-stream' ,
filename : 'file://msg.asc' ,
} ] ,
from : {
address : 'fo@pep.security' ,
fpr : 'B0E03850E2033BCBBF22F7087D45E0D0A78160AC' ,
user_id : 'pEp_own_userId' ,
username : 'anonymous' ,
comm_type : 255 ,
} ,
to : [ {
address : 'cfg@pep.security' ,
fpr : 'B5313A3FBF6720F2A421F8B3B8C7ED6CD7FF61B5' ,
user_id : 'pEp_own_userId' ,
username : 'anonymous' ,
comm_type : 255 ,
} , {
address : 'rg@pep.security' ,
fpr : '14120CA823EA419E6A297EEDE37AADE4CCFDFBAD' ,
user_id : 'TOFU_rg@pep.security' ,
username : 'anonymous' ,
comm_type : 56 ,
} ] ,
cc : [ {
address : 'kinga@pep-security.net' ,
fpr : 'B49167205B22B4891CD69580A1D55C3A106407CF' ,
user_id : 'TOFU_kinga@pep-security.net' ,
username : 'anonymous' ,
comm_type : 56 ,
} ] ,
opt_fields : [ { key : 'X-pEp-Version' , value : '2.1' } ] ,
enc_format : 3 ,
} ] ,
return : { status : 0 , hex : '0 "PEP_STATUS_OK"' } ,
errorstack : [ '(1 elements cleared)' ] ,
} ,
} ) ;
from = 'fo@pep.security' ;
to = [ 'cfg@pep.security' , 'rg@pep.security' ] ;
cc = [ 'kinga@pep-security.net' ] ;
bcc = [ 'cfg@pep.security' ] ;
subject = 'subject' ;
body = 'Not Encrypted Message' ;
result = encryptMail ( pEpController , subject , body , '' , from , to , cc ) ;
} ) ;
after ( ( ) => {
queue . after ( ) ;
pEpController . after ( ) ;
} ) ;
it ( 'sends as expected' , ( ) => {
queue . expectSent (
{ "security_token" : "0847cqi9WqqE5ZcVtA8_mDIgEmYMv14xlNAvSZW" , "method" : "cache_encrypt_message" , "params" : [ { "dir" : 1 , "id" : "testID@pep.security" , "shortmsg" : "subject" , "longmsg" : "Not Encrypted Message" , "longmsg_formatted" : "" , "attachments" : [ ] , "rawmsg_ref" : "" , "rawmsg_size" : "" , "from" : { "user_id" : "" , "username" : "" , "address" : "fo@pep.security" , "fpr" : "" } , "to" : [ { "user_id" : "" , "username" : "" , "address" : "cfg@pep.security" , "fpr" : "" } , { "user_id" : "" , "username" : "" , "address" : "rg@pep.security" , "fpr" : "" } ] , "in_reply_to" : [ ] , "opt_fields" : [ ] , "enc_format" : 4 , "cc" : [ { "user_id" : "" , "username" : "" , "address" : "kinga@pep-security.net" , "fpr" : "" } ] } , [ ] , [ "OP" ] , 4 , 0 ] , "id" : 1 , "jsonrpc" : "2.0" }
) ;
} ) ;
it ( 'should resolve into an encrypted mail' , ( ) => result . should . be . fulfilled ) ;
it ( 'should return an outgoing message' , ( ) => result . should . eventually . have . property ( 'dir' ) . then ( ( dir ) => {
dir . should . be . equal ( 1 ) ;
} ) ) ;
it ( 'should return formated with enc_format default' , ( ) => result . should . eventually . have . property ( 'enc_format' ) . then ( ( enc_format ) => {
enc_format . should . be . equal ( 3 ) ;
} ) ) ;
it ( 'should return original sender info' , ( ) => result . should . eventually . have . property ( 'from' ) . then ( ( sender ) => {
sender . should . be . deep . equal ( {
address : 'fo@pep.security' ,
comm_type : 255 ,
fpr : 'B0E03850E2033BCBBF22F7087D45E0D0A78160AC' ,
user_id : 'pEp_own_userId' ,
username : 'anonymous' ,
} ) ;
} ) ) ;
it ( 'should return original receivers info' , ( ) => result . should . eventually . have . property ( 'to' ) . then ( ( receivers ) => receivers . should . be . deep . equal ( [ {
address : 'cfg@pep.security' ,
comm_type : 255 ,
fpr : 'B5313A3FBF6720F2A421F8B3B8C7ED6CD7FF61B5' ,
user_id : 'pEp_own_userId' ,
username : 'anonymous' ,
} , {
address : 'rg@pep.security' ,
comm_type : 56 ,
fpr : '14120CA823EA419E6A297EEDE37AADE4CCFDFBAD' ,
user_id : 'TOFU_rg@pep.security' ,
username : 'anonymous' ,
} ] ) ) ) ;
it ( 'should return cc fingerprints' , ( ) => result . should . eventually . have . property ( 'cc' ) . then ( ( receivers ) => receivers . should . be . deep . equal ( [ {
address : 'kinga@pep-security.net' ,
comm_type : 56 ,
fpr : 'B49167205B22B4891CD69580A1D55C3A106407CF' ,
user_id : 'TOFU_kinga@pep-security.net' ,
username : 'anonymous' ,
} ] ) ) ) ;
it ( 'should have at least 2 attachments' , ( ) => result . should . eventually . have . property ( 'attachments' ) . then ( ( attachments ) => {
attachments . length . should . be . gte ( 2 ) ;
attachments [ 0 ] . mime_type . should . be . equal ( 'application/pgp-encrypted' ) ;
attachments [ 1 ] . mime_type . should . be . equal ( 'application/octet-stream' ) ;
attachments [ 1 ] . filename . should . be . equal ( 'file://msg.asc' ) ;
} ) ) ;
it ( 'should have x-pEp-version header' , ( ) => result . should . eventually . have . property ( 'opt_fields' ) . then ( ( opt_fields ) => {
opt_fields [ 0 ] . key . should . be . equal ( 'X-pEp-Version' ) ;
} ) ) ;
it ( 'should have pEp subject' , ( ) => result . should . eventually . have . property ( 'shortmsg' ) . then ( ( shortmsg ) => {
shortmsg . should . be . equal ( 'p≡p' ) ;
} ) ) ;
it ( 'should have encrypted body' , ( ) => result . should . eventually . have . property ( 'longmsg' ) . then ( ( longmsg ) => {
longmsg . should . be . equal ( 'this message was encrypted with p≡p https://pEp-project.org' ) ;
} ) ) ;
it ( "sends as expected" , ( ) => {
queue . expectSent (
{
security_token : "0847cqi9WqqE5ZcVtA8_mDIgEmYMv14xlNAvSZW" ,
method : "cache_encrypt_message" ,
params : [ {
dir : 1 ,
id : "testID@pep.security" ,
shortmsg : "subject" ,
longmsg : "Not Encrypted Message" ,
longmsg_formatted : "" ,
attachments : [ ] ,
rawmsg_ref : "" ,
rawmsg_size : "" ,
from : {
user_id : "" , username : "" , address : "cfg@pep.security" , fpr : "" ,
} ,
to : [ {
user_id : "" , username : "" , address : "cfg@pep.security" , fpr : "" ,
} ] ,
in_reply_to : [ ] ,
opt_fields : [ ] ,
enc_format : 4 ,
cc : [ ] ,
} , [ ] , [ "OP" ] , 4 , 0 ] ,
id : 1 ,
jsonrpc : "2.0" ,
} ,
) ;
} ) ;
it ( "should resolve into an encrypted mail" , ( ) => result . should . be . fulfilled ) ;
it ( "should return an outgoing message" , ( ) => result . should . eventually . have . property ( "dir" ) . then ( ( dir ) => {
dir . should . be . equal ( 1 ) ;
} ) ) ;
it ( "should return formated with enc_format default" , ( ) => result . should . eventually . have . property ( "enc_format" ) . then ( ( enc_format ) => {
enc_format . should . be . equal ( 3 ) ;
} ) ) ;
it ( "should return sender fingerprints" , ( ) => result . should . eventually . have . property ( "from" ) . then ( ( sender ) => {
sender . address . should . be . equal ( from ) ;
sender . comm_type . should . be . equal ( 255 ) ;
sender . fpr . should . be . equal ( "B5313A3FBF6720F2A421F8B3B8C7ED6CD7FF61B5" ) ;
sender . user_id . should . be . equal ( "pEp_own_userId" ) ;
sender . username . should . be . equal ( "anonymous" ) ;
} ) ) ;
it ( "should return receiver fingerprints" , ( ) => result . should . eventually . have . property ( "to" ) . then ( ( receivers ) => {
receivers . length . should . be . gte ( 1 ) ;
receivers [ 0 ] . address . should . be . equal ( to ) ;
receivers [ 0 ] . comm_type . should . be . equal ( 255 ) ;
receivers [ 0 ] . fpr . should . be . equal ( "B5313A3FBF6720F2A421F8B3B8C7ED6CD7FF61B5" ) ;
receivers [ 0 ] . user_id . should . be . equal ( "pEp_own_userId" ) ;
receivers [ 0 ] . username . should . be . equal ( "anonymous" ) ;
} ) ) ;
it ( "should have at least 2 attachments" , ( ) => result . should . eventually . have . property ( "attachments" ) . then ( ( attachments ) => {
attachments . length . should . be . gte ( 2 ) ;
attachments [ 0 ] . mime_type . should . be . equal ( "application/pgp-encrypted" ) ;
attachments [ 1 ] . mime_type . should . be . equal ( "application/octet-stream" ) ;
attachments [ 1 ] . filename . should . be . equal ( "file://msg.asc" ) ;
} ) ) ;
it ( "should have x-pEp-version header" , ( ) => result . should . eventually . have . property ( "opt_fields" ) . then ( ( opt_fields ) => {
opt_fields [ 0 ] . key . should . be . equal ( "X-pEp-Version" ) ;
} ) ) ;
it ( "should have pEp subject" , ( ) => result . should . eventually . have . property ( "shortmsg" ) . then ( ( shortmsg ) => {
shortmsg . should . be . equal ( "p≡p" ) ;
} ) ) ;
it ( "should have encrypted body" , ( ) => result . should . eventually . have . property ( "longmsg" ) . then ( ( longmsg ) => {
longmsg . should . be . equal ( "this message was encrypted with p≡p https://pEp-project.org" ) ;
} ) ) ;
} ) ;
describe ( "Multiple recivers" , ( ) => {
let from ;
let to ;
let subject ;
let body ;
let cc ;
let
bcc ;
before ( ( ) => {
queue = getQueue ( ) ;
pEpController = getController ( queue ) ;
queue . respondWith ( {
jsonrpc : "2.0" ,
id : 1 ,
result : {
outParams : [ {
dir : 1 ,
id : "pEp-0" ,
shortmsg : "p≡p" ,
longmsg : "this message was encrypted with p≡p https://pEp-project.org" ,
attachments : [ {
value : "VmVyc2lvbjogMQ==" ,
size : 10 ,
mime_type : "application/pgp-encrypted" ,
} , {
value : "mocked value" ,
size : 5071 ,
mime_type : "application/octet-stream" ,
filename : "file://msg.asc" ,
} ] ,
from : {
address : "fo@pep.security" ,
fpr : "B0E03850E2033BCBBF22F7087D45E0D0A78160AC" ,
user_id : "pEp_own_userId" ,
username : "anonymous" ,
comm_type : 255 ,
} ,
to : [ {
address : "cfg@pep.security" ,
fpr : "B5313A3FBF6720F2A421F8B3B8C7ED6CD7FF61B5" ,
user_id : "pEp_own_userId" ,
username : "anonymous" ,
comm_type : 255 ,
} , {
address : "rg@pep.security" ,
fpr : "14120CA823EA419E6A297EEDE37AADE4CCFDFBAD" ,
user_id : "TOFU_rg@pep.security" ,
username : "anonymous" ,
comm_type : 56 ,
} ] ,
cc : [ {
address : "kinga@pep-security.net" ,
fpr : "B49167205B22B4891CD69580A1D55C3A106407CF" ,
user_id : "TOFU_kinga@pep-security.net" ,
username : "anonymous" ,
comm_type : 56 ,
} ] ,
opt_fields : [ { key : "X-pEp-Version" , value : "2.1" } ] ,
enc_format : 3 ,
} ] ,
return : { status : 0 , hex : "0 \"PEP_STATUS_OK\"" } ,
errorstack : [ "(1 elements cleared)" ] ,
} ,
} ) ;
from = "fo@pep.security" ;
to = [ "cfg@pep.security" , "rg@pep.security" ] ;
cc = [ "kinga@pep-security.net" ] ;
bcc = [ "cfg@pep.security" ] ;
subject = "subject" ;
body = "Not Encrypted Message" ;
result = encryptMail ( pEpController , subject , body , "" , from , to , cc ) ;
} ) ;
after ( ( ) => {
queue . after ( ) ;
pEpController . after ( ) ;
} ) ;
describe ( 'Encryption None scenario' , ( ) => {
let from ;
let to ;
let subject ;
let body ;
let message ;
before ( ( ) => {
queue = getQueue ( ) ;
pEpController = getController ( queue ) ;
from = 'cfg@pep.security' ;
to = 'cfg@pep.security' ;
subject = 'subject' ;
body = 'Not Encrypted Message' ;
queue . respondWith ( {
jsonrpc : '2.0' ,
id : 2 ,
result : {
outParams : [ null , {
dir : 1 ,
id : 'pEp-0' ,
shortmsg : subject ,
longmsg : body ,
longmsg_formatted : "" ,
attachments : [ ] ,
from : { address : 'cfg@pep.security' , fpr : '' , user_id : '' , username : '' } ,
to : [ { address : to , fpr : '' , user_id : '' , username : '' } ] ,
enc_format : 3 ,
} ] ,
return : { status : 1024 , hex : '0x400 "PEP_UNENCRYPTED"' } ,
errorstack : [ '(1 elements cleared)' ] ,
} ,
} ) ;
result = encryptMail ( pEpController , subject , body , '' , from , to , undefined , undefined , 0 ) ;
} ) ;
after ( ( ) => {
queue . after ( ) ;
pEpController . after ( ) ;
} ) ;
it ( 'sends as expected' , ( ) => {
queue . expectSent (
{ "security_token" : "0847cqi9WqqE5ZcVtA8_mDIgEmYMv14xlNAvSZW" , "method" : "cache_encrypt_message" , "params" : [ { "dir" : 1 , "id" : "testID@pep.security" , "shortmsg" : "subject" , "longmsg" : "Not Encrypted Message" , "longmsg_formatted" : "" , "attachments" : [ ] , "rawmsg_ref" : "" , "rawmsg_size" : "" , "from" : { "user_id" : "" , "username" : "" , "address" : "cfg@pep.security" , "fpr" : "" } , "to" : [ { "user_id" : "" , "username" : "" , "address" : "cfg@pep.security" , "fpr" : "" } ] , "in_reply_to" : [ ] , "opt_fields" : [ ] , "enc_format" : 0 , "cc" : [ ] } , [ ] , [ "OP" ] , 0 , 0 ] , "id" : 1 , "jsonrpc" : "2.0" }
) ;
} ) ;
it ( 'should resolve into an encrypted mail' , ( ) => result . should . be . fulfilled ) ;
it ( 'should return an outgoing message' , ( ) => result . should . eventually . have . property ( 'dir' ) . then ( ( dir ) => {
dir . should . be . equal ( 1 ) ;
} ) ) ;
it ( 'should return formated with enc_format default' , ( ) => result . should . eventually . have . property ( 'enc_format' ) . then ( ( enc_format ) => {
enc_format . should . be . equal ( 0 ) ;
} ) ) ;
it ( 'should return sender fingerprints' , ( ) => result . should . eventually . have . property ( 'from' ) . then ( ( sender ) => {
sender . address . should . be . equal ( from ) ;
sender . fpr . should . be . equal ( '' ) ;
sender . user_id . should . be . equal ( '' ) ;
sender . username . should . be . equal ( '' ) ;
} ) ) ;
it ( 'should return receiver fingerprints' , ( ) => result . should . eventually . have . property ( 'to' ) . then ( ( receivers ) => {
receivers . length . should . be . gte ( 1 ) ;
receivers [ 0 ] . address . should . be . equal ( to ) ;
receivers [ 0 ] . fpr . should . be . equal ( '' ) ;
receivers [ 0 ] . user_id . should . be . equal ( '' ) ;
receivers [ 0 ] . username . should . be . equal ( '' ) ;
} ) ) ;
it ( 'should have original subject' , ( ) => result . should . eventually . have . property ( 'shortmsg' ) . then ( ( shortmsg ) => {
shortmsg . should . be . equal ( 'subject' ) ;
} ) ) ;
it ( 'should have original body' , ( ) => result . should . eventually . have . property ( 'longmsg' ) . then ( ( longmsg ) => {
longmsg . should . be . equal ( 'Not Encrypted Message' ) ;
} ) ) ;
it ( "sends as expected" , ( ) => {
queue . expectSent (
{
security_token : "0847cqi9WqqE5ZcVtA8_mDIgEmYMv14xlNAvSZW" ,
method : "cache_encrypt_message" ,
params : [ {
dir : 1 ,
id : "testID@pep.security" ,
shortmsg : "subject" ,
longmsg : "Not Encrypted Message" ,
longmsg_formatted : "" ,
attachments : [ ] ,
rawmsg_ref : "" ,
rawmsg_size : "" ,
from : {
user_id : "" , username : "" , address : "fo@pep.security" , fpr : "" ,
} ,
to : [ {
user_id : "" , username : "" , address : "cfg@pep.security" , fpr : "" ,
} , {
user_id : "" , username : "" , address : "rg@pep.security" , fpr : "" ,
} ] ,
in_reply_to : [ ] ,
opt_fields : [ ] ,
enc_format : 4 ,
cc : [ {
user_id : "" , username : "" , address : "kinga@pep-security.net" , fpr : "" ,
} ] ,
} , [ ] , [ "OP" ] , 4 , 0 ] ,
id : 1 ,
jsonrpc : "2.0" ,
} ,
) ;
} ) ;
it ( "should resolve into an encrypted mail" , ( ) => result . should . be . fulfilled ) ;
it ( "should return an outgoing message" , ( ) => result . should . eventually . have . property ( "dir" ) . then ( ( dir ) => {
dir . should . be . equal ( 1 ) ;
} ) ) ;
it ( "should return formated with enc_format default" , ( ) => result . should . eventually . have . property ( "enc_format" ) . then ( ( enc_format ) => {
enc_format . should . be . equal ( 3 ) ;
} ) ) ;
it ( "should return original sender info" , ( ) => result . should . eventually . have . property ( "from" ) . then ( ( sender ) => {
sender . should . be . deep . equal ( {
address : "fo@pep.security" ,
comm_type : 255 ,
fpr : "B0E03850E2033BCBBF22F7087D45E0D0A78160AC" ,
user_id : "pEp_own_userId" ,
username : "anonymous" ,
} ) ;
} ) ) ;
it ( "should return original receivers info" , ( ) => result . should . eventually . have . property ( "to" ) . then ( ( receivers ) => receivers . should . be . deep . equal ( [ {
address : "cfg@pep.security" ,
comm_type : 255 ,
fpr : "B5313A3FBF6720F2A421F8B3B8C7ED6CD7FF61B5" ,
user_id : "pEp_own_userId" ,
username : "anonymous" ,
} , {
address : "rg@pep.security" ,
comm_type : 56 ,
fpr : "14120CA823EA419E6A297EEDE37AADE4CCFDFBAD" ,
user_id : "TOFU_rg@pep.security" ,
username : "anonymous" ,
} ] ) ) ) ;
it ( "should return cc fingerprints" , ( ) => result . should . eventually . have . property ( "cc" ) . then ( ( receivers ) => receivers . should . be . deep . equal ( [ {
address : "kinga@pep-security.net" ,
comm_type : 56 ,
fpr : "B49167205B22B4891CD69580A1D55C3A106407CF" ,
user_id : "TOFU_kinga@pep-security.net" ,
username : "anonymous" ,
} ] ) ) ) ;
it ( "should have at least 2 attachments" , ( ) => result . should . eventually . have . property ( "attachments" ) . then ( ( attachments ) => {
attachments . length . should . be . gte ( 2 ) ;
attachments [ 0 ] . mime_type . should . be . equal ( "application/pgp-encrypted" ) ;
attachments [ 1 ] . mime_type . should . be . equal ( "application/octet-stream" ) ;
attachments [ 1 ] . filename . should . be . equal ( "file://msg.asc" ) ;
} ) ) ;
it ( "should have x-pEp-version header" , ( ) => result . should . eventually . have . property ( "opt_fields" ) . then ( ( opt_fields ) => {
opt_fields [ 0 ] . key . should . be . equal ( "X-pEp-Version" ) ;
} ) ) ;
it ( "should have pEp subject" , ( ) => result . should . eventually . have . property ( "shortmsg" ) . then ( ( shortmsg ) => {
shortmsg . should . be . equal ( "p≡p" ) ;
} ) ) ;
it ( "should have encrypted body" , ( ) => result . should . eventually . have . property ( "longmsg" ) . then ( ( longmsg ) => {
longmsg . should . be . equal ( "this message was encrypted with p≡p https://pEp-project.org" ) ;
} ) ) ;
} ) ;
describe ( "Encryption None scenario" , ( ) => {
let from ;
let to ;
let subject ;
let body ;
let message ;
before ( ( ) => {
queue = getQueue ( ) ;
pEpController = getController ( queue ) ;
from = "cfg@pep.security" ;
to = "cfg@pep.security" ;
subject = "subject" ;
body = "Not Encrypted Message" ;
queue . respondWith ( {
jsonrpc : "2.0" ,
id : 2 ,
result : {
outParams : [ null , {
dir : 1 ,
id : "pEp-0" ,
shortmsg : subject ,
longmsg : body ,
longmsg_formatted : "" ,
attachments : [ ] ,
from : {
address : "cfg@pep.security" , fpr : "" , user_id : "" , username : "" ,
} ,
to : [ {
address : to , fpr : "" , user_id : "" , username : "" ,
} ] ,
enc_format : 3 ,
} ] ,
return : { status : 1024 , hex : "0x400 \"PEP_UNENCRYPTED\"" } ,
errorstack : [ "(1 elements cleared)" ] ,
} ,
} ) ;
result = encryptMail ( pEpController , subject , body , "" , from , to , undefined , undefined , 0 ) ;
} ) ;
after ( ( ) => {
queue . after ( ) ;
pEpController . after ( ) ;
} ) ;
it ( "sends as expected" , ( ) => {
queue . expectSent (
{
security_token : "0847cqi9WqqE5ZcVtA8_mDIgEmYMv14xlNAvSZW" ,
method : "cache_encrypt_message" ,
params : [ {
dir : 1 ,
id : "testID@pep.security" ,
shortmsg : "subject" ,
longmsg : "Not Encrypted Message" ,
longmsg_formatted : "" ,
attachments : [ ] ,
rawmsg_ref : "" ,
rawmsg_size : "" ,
from : {
user_id : "" , username : "" , address : "cfg@pep.security" , fpr : "" ,
} ,
to : [ {
user_id : "" , username : "" , address : "cfg@pep.security" , fpr : "" ,
} ] ,
in_reply_to : [ ] ,
opt_fields : [ ] ,
enc_format : 0 ,
cc : [ ] ,
} , [ ] , [ "OP" ] , 0 , 0 ] ,
id : 1 ,
jsonrpc : "2.0" ,
} ,
) ;
} ) ;
it ( "should resolve into an encrypted mail" , ( ) => result . should . be . fulfilled ) ;
it ( "should return an outgoing message" , ( ) => result . should . eventually . have . property ( "dir" ) . then ( ( dir ) => {
dir . should . be . equal ( 1 ) ;
} ) ) ;
it ( "should return formated with enc_format default" , ( ) => result . should . eventually . have . property ( "enc_format" ) . then ( ( enc_format ) => {
enc_format . should . be . equal ( 0 ) ;
} ) ) ;
it ( "should return sender fingerprints" , ( ) => result . should . eventually . have . property ( "from" ) . then ( ( sender ) => {
sender . address . should . be . equal ( from ) ;
sender . fpr . should . be . equal ( "" ) ;
sender . user_id . should . be . equal ( "" ) ;
sender . username . should . be . equal ( "" ) ;
} ) ) ;
it ( "should return receiver fingerprints" , ( ) => result . should . eventually . have . property ( "to" ) . then ( ( receivers ) => {
receivers . length . should . be . gte ( 1 ) ;
receivers [ 0 ] . address . should . be . equal ( to ) ;
receivers [ 0 ] . fpr . should . be . equal ( "" ) ;
receivers [ 0 ] . user_id . should . be . equal ( "" ) ;
receivers [ 0 ] . username . should . be . equal ( "" ) ;
} ) ) ;
it ( "should have original subject" , ( ) => result . should . eventually . have . property ( "shortmsg" ) . then ( ( shortmsg ) => {
shortmsg . should . be . equal ( "subject" ) ;
} ) ) ;
it ( "should have original body" , ( ) => result . should . eventually . have . property ( "longmsg" ) . then ( ( longmsg ) => {
longmsg . should . be . equal ( "Not Encrypted Message" ) ;
} ) ) ;
} ) ;
} ) ;