From fc1cba6a832a12c12693f532595b2fe32d788139 Mon Sep 17 00:00:00 2001 From: Andres Junge Date: Fri, 12 Apr 2019 00:29:53 -0400 Subject: [PATCH 1/2] fix chasqui endpoint (#51) * fix chasqui endpoint * fix chasqui url inside hard coded jwt used by tests --- src/transport/messageServer.js | 2 +- test/transport/chasqui.js | 70 +++++++++++++++++----------------- test/transport/poll.js | 2 +- 3 files changed, 38 insertions(+), 36 deletions(-) diff --git a/src/transport/messageServer.js b/src/transport/messageServer.js index d2557a5..4387a0d 100644 --- a/src/transport/messageServer.js +++ b/src/transport/messageServer.js @@ -3,7 +3,7 @@ import { randomString } from './../crypto.js' import generalPoll from './poll.js' import { decodeJWT } from 'did-jwt' import nets from 'nets' -const CHASQUI_URL = 'https://api.uport.space/chasqui/' +const CHASQUI_URL = 'https://api.uport.me/chasqui/' const POLLING_INTERVAL = 2000 // TODO can the name of URIHandler be changed diff --git a/test/transport/chasqui.js b/test/transport/chasqui.js index 5a6e7b6..bf402f1 100644 --- a/test/transport/chasqui.js +++ b/test/transport/chasqui.js @@ -2,40 +2,40 @@ // import * as chasqui from './../../src/transport/messageServer.js' const sinon = require('sinon') const proxyquire = require('proxyquire') -var chai = require('chai'); +var chai = require('chai') const expect = chai.expect chai.use(require('sinon-chai')) let chasqui = require('./../../src/transport/messageServer.js') -const CHASQUI_URL = 'https://api.uport.space/chasqui/topic/' +const CHASQUI_URL = 'https://api.uport.me/chasqui/topic/' const ranStr = 'aVKcEd5jznmWslj3' // TODO stub nets everywhere // Cleanup imports and redundancy -describe('transport.chasqui', function () { - - describe('URIHandlerSend()', function () { +describe('transport.chasqui', function() { + describe('URIHandlerSend()', function() { it('Requires a uriHandler', () => { expect(chasqui.URIHandlerSend).to.throw(/required/) - expect(() => chasqui.URIHandlerSend(()=>{})).to.not.throw() + expect(() => chasqui.URIHandlerSend(() => {})).to.not.throw() }) }) - describe('URIHandlerSend() Configured', function () { + describe('URIHandlerSend() Configured', function() { const uriHandler = sinon.spy() const pollGeneral = sinon.stub().resolves('ResponseString') const randomString = sinon.stub().returns(ranStr) - const requestMessage = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJFUzI1NkstUiJ9.eyJpYXQiOjE1Mjk5NTQxMjcsImV4cCI6MTUyOTk1NDcyNywicmVxdWVzdGVkIjpbIm5hbWUiLCJwaG9uZSIsImNvdW50cnkiXSwicGVybWlzc2lvbnMiOlsibm90aWZpY2F0aW9ucyJdLCJjYWxsYmFjayI6Imh0dHBzOi8vYXBpLnVwb3J0LnNwYWNlL2NoYXNxdWkvdG9waWMvYVZLY0VkNWp6bm1Xc2xqMyIsInR5cGUiOiJzaGFyZVJlcSIsImlzcyI6ImRpZDpldGhyOjB4NDFjOTkxZjczZjBjN2E3Y2M5NWI5ZGY5MDk0NmUxYTdiMDE3NGVlNiJ9.hjkP5-yoAACebORa29-iO_VXCm3_81KwaHzrD3xHI94PbJzaT50x3uSr9MwQSl9sO1Lmdzkg1VMkuHyHFt9ClAE' + const requestMessage = + 'eyJ0eXAiOiJKV1QiLCJhbGciOiJFUzI1NksifQ.eyJpYXQiOjE1Mjk5NTQxMjcsImV4cCI6MTUyOTk1NDcyNywicmVxdWVzdGVkIjpbIm5hbWUiLCJwaG9uZSIsImNvdW50cnkiXSwicGVybWlzc2lvbnMiOlsibm90aWZpY2F0aW9ucyJdLCJjYWxsYmFjayI6Imh0dHBzOi8vYXBpLnVwb3J0Lm1lL2NoYXNxdWkvdG9waWMvYVZLY0VkNWp6bm1Xc2xqMyIsInR5cGUiOiJzaGFyZVJlcSIsImlzcyI6ImRpZDpldGhyOjB4NDFjOTkxZjczZjBjN2E3Y2M5NWI5ZGY5MDk0NmUxYTdiMDE3NGVlNiJ9.Xe7KOQrMGM8PRwXBWY4_7i8VR79o_dJ7DC2eabzf65HPra2zZ8JyhWLBQgIcN33DmmbZgeyy8b5t8dBVZXpaIQ' const uri = `https://id.uport.me/req/${requestMessage}` let URIHandlerSend before(() => { - chasqui = proxyquire( './../../src/transport/messageServer.js', { - './poll.js': {default: pollGeneral}, - '../crypto.js': { randomString } + chasqui = proxyquire('./../../src/transport/messageServer.js', { + './poll.js': { default: pollGeneral }, + '../crypto.js': { randomString }, }) URIHandlerSend = chasqui.URIHandlerSend(uriHandler) - }); + }) it('Uses uPort chasqui as default messaging server', () => { return URIHandlerSend(requestMessage).then(res => { @@ -56,17 +56,17 @@ describe('transport.chasqui', function () { }) }) - describe('poll()', function () { - const res = { message: { access_token: 'token'}} - const resError = { message: {error: 'error'}} + describe('poll()', function() { + const res = { message: { access_token: 'token' } } + const resError = { message: { error: 'error' } } it('Creates poll arg function to parse message', () => { const pollGeneral = sinon.stub().callsFake((url, messageParse, errorParse, pollingInterval, cancelled) => { expect(messageParse(res)).to.equal('token') return Promise.resolve('ResponseString') }) - chasqui = proxyquire( './../../src/transport/messageServer.js', { - './poll.js': {default: pollGeneral} + chasqui = proxyquire('./../../src/transport/messageServer.js', { + './poll.js': { default: pollGeneral }, }) return chasqui.poll(CHASQUI_URL + ranStr) }) @@ -76,16 +76,16 @@ describe('transport.chasqui', function () { expect(errorParse(resError)).to.equal('error') return Promise.resolve('ResponseString') }) - chasqui = proxyquire( './../../src/transport/messageServer.js', { - './poll.js': {default: pollGeneral} + chasqui = proxyquire('./../../src/transport/messageServer.js', { + './poll.js': { default: pollGeneral }, }) return chasqui.poll(CHASQUI_URL + ranStr) }) it('Clears response on chasqui once response received ', () => { const pollGeneral = sinon.stub().resolves('ResponseString') - chasqui = proxyquire( './../../src/transport/messageServer.js', { - './poll.js': {default: pollGeneral} + chasqui = proxyquire('./../../src/transport/messageServer.js', { + './poll.js': { default: pollGeneral }, }) return chasqui.poll(CHASQUI_URL + ranStr) // TODO Spy on nets call with delete uponr response @@ -93,8 +93,8 @@ describe('transport.chasqui', function () { it('It resolves with response from polling if response', () => { const pollGeneral = sinon.stub().resolves('ResponseString') - chasqui = proxyquire( './../../src/transport/messageServer.js', { - './poll.js': {default: pollGeneral} + chasqui = proxyquire('./../../src/transport/messageServer.js', { + './poll.js': { default: pollGeneral }, }) return chasqui.poll(CHASQUI_URL + ranStr).then(res => { expect(res).to.equal('ResponseString') @@ -103,25 +103,27 @@ describe('transport.chasqui', function () { it('It rejects with error from polling if error', () => { const pollGeneral = sinon.stub().rejects('Error') - chasqui = proxyquire( './../../src/transport/messageServer.js', { - './poll.js': {default: pollGeneral} - }) - return chasqui.poll(CHASQUI_URL + ranStr).then(res => { - throw new Error('transport.chasqui.poll Promise resolved, expected it to reject') - }, err => { - expect(err).to.be.an('error'); + chasqui = proxyquire('./../../src/transport/messageServer.js', { + './poll.js': { default: pollGeneral }, }) + return chasqui.poll(CHASQUI_URL + ranStr).then( + res => { + throw new Error('transport.chasqui.poll Promise resolved, expected it to reject') + }, + err => { + expect(err).to.be.an('error') + }, + ) }) - }) - describe('clearResponse()', function () { + describe('clearResponse()', function() { it('Creates DELETE HTTP request to given url', () => { const nets = sinon.stub().callsFake((obj, cb) => { expect(obj.method).to.equal('DELETE') }) - chasqui = proxyquire( './../../src/transport/messageServer.js', { - 'nets': nets + chasqui = proxyquire('./../../src/transport/messageServer.js', { + nets: nets, }) return chasqui.clearResponse(CHASQUI_URL + ranStr) }) diff --git a/test/transport/poll.js b/test/transport/poll.js index 184c5f4..60851fc 100644 --- a/test/transport/poll.js +++ b/test/transport/poll.js @@ -3,7 +3,7 @@ const proxyquire = require('proxyquire') var chai = require('chai'); const expect = chai.expect chai.use(require('sinon-chai')) -const CHASQUI_URL = 'https://api.uport.space/chasqui/topic/' +const CHASQUI_URL = 'https://api.uport.me/chasqui/topic/' const ranStr = '4242' describe('transport.poll', function () { From 93053b021c528aadf6166db9225dbd705dea6868 Mon Sep 17 00:00:00 2001 From: Mike Xu Date: Fri, 12 Apr 2019 09:54:12 -0400 Subject: [PATCH 2/2] bump version to 0.2.6 --- package-lock.json | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index 7766e19..c8323ec 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "uport-transports", - "version": "0.2.5", + "version": "0.2.6", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 370d271..0b74ba0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "uport-transports", - "version": "0.2.5", + "version": "0.2.6", "description": "Set up communication channels between your app and a uPort client to handle requests and responses", "main": "lib/index.js", "scripts": {