mirror of
https://github.com/Foundry376/Mailspring.git
synced 2024-11-12 12:40:08 +08:00
142 lines
6.3 KiB
CoffeeScript
Executable file
142 lines
6.3 KiB
CoffeeScript
Executable file
{React, ReactDOM, ReactTestUtils, DraftStore, Message} = require 'nylas-exports'
|
|
pgp = require 'kbpgp'
|
|
|
|
EncryptMessageButton = require '../lib/encrypt-button'
|
|
PGPKeyStore = require '../lib/pgp-key-store'
|
|
|
|
describe "EncryptMessageButton", ->
|
|
beforeEach ->
|
|
key = """-----BEGIN PGP PRIVATE KEY BLOCK-----
|
|
Version: GnuPG v1
|
|
|
|
lQOYBFbgdCwBCADP7pEHzySjYHIlQK7T3XlqfFaot7VAgwmBUmXwFNRsYxGFj5sC
|
|
qEvhcw3nGvhVOul9A5S3yDZCtEDMqZSFDXNNIptpbhJgEqae0stfmHzHNUJSz+3w
|
|
ZE8Bvz1D5MU8YsMCUbt/wM/dBsp0EdbCS+zWIfM7Gzhb5vYOYx/wAeUxORCljQ6i
|
|
E80iGKII7EYmpscIOjb6QgaM7wih6GT3GWFYOMRG0uKGDVGWgWQ3EJgdcJq6Dvmx
|
|
GgrEQL7R8chtuLn9iyG3t5ZUfNvoH6PM7L7ei2ceMjxvLOfaHWNVKc+9YPeEOcvB
|
|
uQi5NEqSEZOSqd1jPPaOiSTnIOCeVXXMyZVlABEBAAEAB/0Q2OWLWm8/hYr6FbmU
|
|
lPdHd3eWB/x5k6Rrg/+aajWj6or65V3L41Lym13fAcJpNXLBnE6qbWBoGy685miQ
|
|
NzzGXS12Z2K5wgkaCT5NKo/BnEEZcJt4xMfZ/mK6Y4jPkbj3MSQd/8NXxzsUGHXs
|
|
HDa+StXoThZM6/O3yrRFwAGP8UhMVYOSwZB0u+DZ8EFaImqKJmznRvyNOaaGDrI5
|
|
cNdB4Xkk7L/tDxUxqc60WMQ49BEA9HW7miqymb3MEBA4Gd931pGYRM3hzQDhg+VI
|
|
oGlw2Xl9YjUGWVHMyufKzxTYhWWHDSpfjSVikeKwqbJ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rWSe61zZTuR7kb8/IkGHDTC7tLVZ
|
|
vKzdkRinh+qISpjI5OHSsITBV1uh/iko+K2rKca8gonjQBsxeAPMZwvMfUROGKkS
|
|
eXm/5sLUWlRtGkfVED1rYwUkE720tFUvBACGilgE7ezuoH7ZukyPPw9RziI7/CQp
|
|
u0KhFTGzLMGJWfiGgMC7l1jnS0EJxvs3ZpBme//vsKCjPGVg3/OqOHqCY0p9Uqjt
|
|
7v8o7y62AMzHKEGuMubSzDZZalo0515HQilfwnOGTHN14693icg1W/daB8aGI+Uz
|
|
cH3NziXnu23zc0VMiQEfBBgBAgAJBQJW4HQsAhsMAAoJECYBoapfcqjghFEH/ioJ
|
|
c4jot40O3Xa0K9ZFXol2seUHIf5rLgvcnwAKEiibK81/cZzlL6uXpgxVA4GOgdw5
|
|
nfGVd7b9jB7S6aUKcVoLDmy47qmJkWvZ45cjgv+K+ZoV22IN0J9Hhhdnqe+QJd4A
|
|
vIqb67gb9cw0xUDqcLdYywsXHoF9WkAYpIvBw4klHgd77XTzYz6xv4vVl469CPdk
|
|
+1dlOKpCHTLh7t38StP/rSu4ZrAYGET0e2+Ayqj44VHS9VwEbR/D2xrbjo43URZB
|
|
VsVlQKtXimFLpck1z0BPQ0NmRdEzRHQwP2WNYfxdNCeFAGDL4tpblBzw/vp/CFTO
|
|
217s2OKjpJqtpHPf2vY=
|
|
=UY7Y
|
|
-----END PGP PRIVATE KEY BLOCK-----"""
|
|
|
|
pgp.KeyManager.import_from_armored_pgp {
|
|
armored: key
|
|
}, (err, km) =>
|
|
@km = km
|
|
|
|
waitsFor (=> @km?), "getting a key took too long", 1000
|
|
|
|
@msg = new Message({subject: 'Subject', body: '<p>Body</p>', draft: true})
|
|
@session =
|
|
draft: =>
|
|
return @msg
|
|
changes:
|
|
add: (changes) =>
|
|
@output = changes
|
|
|
|
@output = null
|
|
|
|
add = jasmine.createSpy('add')
|
|
spyOn(DraftStore, 'sessionForClientId').andCallFake((draftClientId) =>
|
|
return Promise.resolve(@session)
|
|
)
|
|
|
|
@component = ReactTestUtils.renderIntoDocument(
|
|
<EncryptMessageButton draft={@msg} session={@session} />
|
|
)
|
|
|
|
it "should render into the page", ->
|
|
expect(@component).toBeDefined()
|
|
|
|
it "should have a displayName", ->
|
|
expect(EncryptMessageButton.displayName).toBe('EncryptMessageButton')
|
|
|
|
it "should have an onClick behavior which encrypts the message", ->
|
|
spyOn(@component, '_onClick')
|
|
buttonNode = ReactDOM.findDOMNode(@component.refs.button)
|
|
ReactTestUtils.Simulate.click(buttonNode)
|
|
expect(@component._onClick).toHaveBeenCalled()
|
|
|
|
it "should store the message body's plaintext on encryption", ->
|
|
spyOn(@component, '_onClick')
|
|
buttonNode = ReactDOM.findDOMNode(@component.refs.button)
|
|
ReactTestUtils.Simulate.click(buttonNode)
|
|
expect(@component.plaintext is @msg.body)
|
|
|
|
it "should mark itself as encrypted", ->
|
|
spyOn(@component, '_onClick')
|
|
buttonNode = ReactDOM.findDOMNode(@component.refs.button)
|
|
ReactTestUtils.Simulate.click(buttonNode)
|
|
expect(@component.currentlyEncrypted is true)
|
|
|
|
xit "should be able to encrypt messages", ->
|
|
# NOTE: this doesn't work.
|
|
# As best I can tell, something is wrong with the pgp.box function -
|
|
# nothing seems to get it to complete. Weird.
|
|
|
|
runs( =>
|
|
console.log @km
|
|
@component._encrypt("test text", [@km])
|
|
|
|
@flag = false
|
|
pgp.box {encrypt_for: [@km], msg: "test text"}, (err, result_string) =>
|
|
expect(not err?)
|
|
@err = err
|
|
@result_string = result_string
|
|
@flag = true
|
|
)
|
|
|
|
waitsFor (=> console.log @flag; @flag), "encryption took too long", 5000
|
|
|
|
runs( =>
|
|
console.log @err
|
|
console.log @result_string
|
|
console.log @output
|
|
|
|
expect(@output is @result_string))
|