Skip to content

Commit

Permalink
Test that Node can verify a signature produced by the Java SDK.
Browse files Browse the repository at this point in the history
  • Loading branch information
Justin Bailey committed May 7, 2018
1 parent 0b5676a commit 2c009e0
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
12 changes: 12 additions & 0 deletions DEVELOPMENT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Testing

Define the following environment variables:

* REGISTRATION_TOKEN - Should be a mobile registration token (from the Innovault Console).
* API_URL - The environment to test against. For example, 'https://api.e3db.com'.

To run tests, from this directory:

```bash
> npm test
```
14 changes: 14 additions & 0 deletions lib/__tests__/client.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,20 @@ describe('Client', () => {
expect(verify).toBe(true)
})

it('can verify a signature from another SDK', async () => {
// e3db-java SDK produced this document.
let document = `{"doc":{"data":{"a":"yZI0kCHXHtgN2O-9gMdH6OnJDZKn3s8dpRQrZL_NWG2gSWDt4qomAG4abyTby-or.HOBwIJHQC4fm62dRMkM3fASsgDgA8slj.bHpBXShz1xahRiWgMRo6og.YNk6zU7NdxF1nyjj2yxSqw9WLUI6oqKT"},"meta":{"plain":{"client_pub_sig_key":"DW4lugZbPA5AsXyUBWMpRW6pH4UJhi9t1RV7wDWkl4c"},"type":"3835f34f-e667-4fc6-a227-d606cdb2e0a8","user_id":"169f8c64-6f9d-4de7-9e0e-29ec6c53336f","writer_id":"169f8c64-6f9d-4de7-9e0e-29ec6c53336f"},"rec_sig":"xlaTFff9js4_TkW32j74ufXJRmF_mSq0DbrN9qdk6lTXv6yyDkz0VhRtpyyeVUJju5RJVW-EGUEn_BNAoGKUDA"},"sig":"SXQR4zNiaeItbrqIEOO8Kl1HcIFKH_pxLCTTQwyx0gvuJUS052rrLSXbGPX4wLoOeknVQrD6EJJXODv8Wt3GDA"}`

let client = new Client(config)
let parsed = JSON.parse(document)
let encrypted = await Record.decode(parsed.doc)
let doc = new SignedDocument(encrypted, parsed.sig)
let publicKey = encrypted.meta.plain.client_pub_sig_key

let verify = await client.verify(doc, publicKey)
expect(verify).toBe(true)
})

it('rejects invalid signatures', async () => {
let serverPublicKey = 'dGhpc2lzbm90YXJlYWxwdWJsaWNrZXkxMjM0NTc4OTA' //thisisnotarealpublickey123457890

Expand Down

0 comments on commit 2c009e0

Please sign in to comment.