|
|
@ -1,55 +0,0 @@ |
|
|
|
/* eslint-disable no-console */ |
|
|
|
let {describe, it, before, beforeEach} = require('mocha'); |
|
|
|
let chai = require('chai').use(require('chai-as-promised')); |
|
|
|
let expect = require('chai').expect |
|
|
|
let messages = require('../messages.js'); |
|
|
|
let jsmimeMock = { |
|
|
|
headeremitter: { |
|
|
|
emitStructuredHeader: (name, value, empty) => { |
|
|
|
return name + ": " + value + "\r\n"; |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
let MimeEmitter = require('../../chrome/content/modules/MimeEmitter'); |
|
|
|
let controller = require('../../chrome/content/modules/pEp'); |
|
|
|
let emitter = new MimeEmitter(jsmimeMock, require('atob'), 'boundary'); |
|
|
|
|
|
|
|
let expectations = { |
|
|
|
encrypted: 'Message-ID: pEp....@pep.security\r\nSubject: p≡p\r\nX-pEp-Version: 2.1\r\nContent-Type: multipart/encrypted; protocol="application/pgp-encrypted"; boundary="boundary"\r\n\r\nthis message was encrypted with p≡p https://pEp-project.org\r\n\r\n--boundary\r\nContent-Type: application/pgp-encrypted\r\nContent-Description: PGP/MIME version identification\r\n\r\nVersion: 1\r\n\r\n--boundary\r\nContent-Type: application/octet-stream; name="msg.asc"\r\nContent-Description: OpenPGP encrypted message\r\nContent-Disposition: inline; filename="msg.asc"\r\n\r\n1337\r\n--boundary--\r\n\r\n', |
|
|
|
unencrypted: { |
|
|
|
simple: 'Message-ID: No-message-ID\r\nSubject: pep test\r\nContent-Type: text/plain; charset=utf-8\r\nContent-Transfer-Encoding: 7bit\r\n\r\nbody\r\n\r\n', |
|
|
|
withAttachments: 'Message-ID: No-message-ID\r\nSubject: pep attach\r\nContent-Type: multipart/mixed; boundary="boundary"\r\n\r\nThis is a multi-part message in MIME format.\r\n\r\n--boundary\r\nContent-Type: text/plain; charset=utf-8;\r\nContent-Transfer-Encoding: 7bit\r\n\r\nbody\r\n\r\n--boundary\r\nContent-Type: image/x-icon\r\nContent-Transfer-Encoding: base64\r\nContent-Disposition: attachment; filename="favicon.ico"\r\n\r\n1337\r\n--boundary--\r\n\r\n', |
|
|
|
pgpMime: '' |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
describe('the MIME emitter', () => { |
|
|
|
describe('multipart encoding', () => { |
|
|
|
it('emits MIME from raw data', () => { |
|
|
|
let parts = [{ |
|
|
|
headers: [['a', 'b']], |
|
|
|
body: 'body 1' |
|
|
|
}, { |
|
|
|
headers: [['c', 'd'], ['e', 'f']], |
|
|
|
body: 'body 2' |
|
|
|
}]; |
|
|
|
let expected = 'a: b\r\n\r\nbody 1\r\n\r\n--boundary\r\nc: d\r\ne: f\r\n\r\nbody 2\r\n--boundary--\r\n\r\n'; |
|
|
|
expect(emitter.emit(parts)) |
|
|
|
.to.equal(expected); |
|
|
|
}); |
|
|
|
}); |
|
|
|
describe('message serialisation', () => { |
|
|
|
it('ducktypes encrypted messages', () => { |
|
|
|
expect(emitter.fromMessage(controller.cloneMessage(messages.encrypted))) |
|
|
|
.to.equal(expectations.encrypted); |
|
|
|
}); |
|
|
|
it('ducktypes unencrypted messages', () => { |
|
|
|
expect(emitter.fromMessage(controller.cloneMessage(messages.unencrypted.simple))) |
|
|
|
.to.equal(expectations.unencrypted.simple); |
|
|
|
}); |
|
|
|
it('ducktypes multipart unencrypted messages', () => { |
|
|
|
expect(emitter.fromMessage(controller.cloneMessage(messages.unencrypted.withAttachments))) |
|
|
|
.to.equal(expectations.unencrypted.withAttachments); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |