diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..5f5c34e --- /dev/null +++ b/.travis.yml @@ -0,0 +1,9 @@ +sudo: required +language: node_js +node_js: + - "lts/*" +services: + - docker +script: + - npm test + \ No newline at end of file diff --git a/app.js b/app.js index 0cff83a..7669bcd 100644 --- a/app.js +++ b/app.js @@ -11,9 +11,18 @@ if (process.env.NODE_ENV === 'test') { logger.child = () => {return {info: noop, error: noop, debug: noop};}; } -srf.listen(config.get('drachtio')); +// config dictates whether to use outbound or inbound connections +if (config.has('drachtio.host')) { + srf.connect(config.get('drachtio')); + srf.on('connect', (err, hp) => { + logger.info(`connected to drachtio listening on ${hp}`); + }); +} +else { + srf.listen(config.get('drachtio')); +} -srf.request('invite', auth); +srf.use('invite', auth); srf.invite(require('./lib/invite')({logger})); module.exports = {srf}; diff --git a/config/local-test.json b/config/local-test.json index d3e2f26..0420037 100644 --- a/config/local-test.json +++ b/config/local-test.json @@ -4,7 +4,43 @@ "port": 9060, "secret": "cymru" }, + "rtpengine": { + "host": "127.0.0.1", + "port": 12222 + }, "logging": { - "level": "info" + "level": "debug" + }, + "authCallback": { + "uri": "http://example.com/auth", + "auth": { + "username": "foo", + "password": "bar" + } + }, + "trunks": { + "inbound": [ + { + "name": "carrier1", + "host": ["172.38.0.20"] + } + ], + "appserver": ["sip:172.38.0.11"] + }, + "transcoding": { + "rtpCharacteristics" : { + "transport protocol": "RTP/AVP", + "DTLS": "off", + "SDES": "off", + "ICE": "remove", + "rtcp-mux": ["demux"] + }, + "srtpCharacteristics": { + "transport-protocol": "UDP/TLS/RTP/SAVPF", + "ICE": "force", + "SDES": "off", + "flags": ["generate mid", "SDES-no"], + "rtcp-mux": ["require"] + } } } \ No newline at end of file diff --git a/lib/invite.js b/lib/invite.js index 271078f..2547389 100644 --- a/lib/invite.js +++ b/lib/invite.js @@ -22,8 +22,7 @@ function handler({logger}) { throw new Error(`failed allocating rtpengine endpoint: ${JSON.stringify(response)}`); } - const {uas, uac} = await srf.createB2BUA(req, res, { - proxy: uri, + const {uas, uac} = await srf.createB2BUA(req, res, uri, { localSdpB: response.sdp, localSdpA: (sdp, res) => { const opts = Object.assign({sdp, 'to-tag': res.getParsedHeader('To').params.tag}, diff --git a/lib/middleware.js b/lib/middleware.js index dba3175..9696c93 100644 --- a/lib/middleware.js +++ b/lib/middleware.js @@ -3,7 +3,9 @@ const config = require('config'); const authenticator = require('drachtio-http-authenticator')(config.get('authCallback')); function auth(req, res, next) { - if (fromInboundTrunk) return next(); + if (fromInboundTrunk) { + return next(); + } authenticator(req, res, next); } diff --git a/test/sip-tests.js b/test/carrier-origination.js similarity index 73% rename from test/sip-tests.js rename to test/carrier-origination.js index 5e2d075..99ac74a 100644 --- a/test/sip-tests.js +++ b/test/carrier-origination.js @@ -15,23 +15,21 @@ function connect(connectable) { }); } -test('invite handler', (t) => { +test('incoming call from carrier', (t) => { clearModule('../app'); - const {srf, disconnectMs} = require('../app'); + const {srf} = require('../app'); connect(srf) .then(() => { - return sippUac('uac-pcap.xml'); + return sippUac('uac-pcap-carrier-success.xml', '172.38.0.20'); }) .then(() => { - t.pass('successfully connected call'); - if (srf.locals.lb) srf.locals.lb.disconnect(); + t.pass('successfully connected incoming call from carrier'); srf.disconnect(); t.end(); return; }) .catch((err) => { - if (srf.locals.lb) srf.locals.lb.disconnect(); if (srf) srf.disconnect(); console.log(`error received: ${err}`); t.error(err); diff --git a/test/docker-compose-testbed.yaml b/test/docker-compose-testbed.yaml index 3e9d94f..2e38a60 100644 --- a/test/docker-compose-testbed.yaml +++ b/test/docker-compose-testbed.yaml @@ -8,25 +8,46 @@ networks: - subnet: 172.38.0.0/16 services: - drachtio: + sbc: image: drachtio/drachtio-server:latest command: drachtio --contact "sip:*;transport=udp" --loglevel debug --sofia-loglevel 9 - container_name: drachtio ports: - "9060:9022/tcp" networks: sbc-inbound: ipv4_address: 172.38.0.10 - - - sipp-uas: + appserver: image: drachtio/sipp:latest command: sipp -sf /tmp/uas.xml - container_name: sipp-uas.local volumes: - ./scenarios:/tmp tty: true + networks: + sbc-inbound: + ipv4_address: 172.38.0.11 + + auth-server: + image: jambonz/customer-auth-server:latest + command: npm start + env_file: docker.env networks: sbc-inbound: ipv4_address: 172.38.0.12 + + redis: + image: redis:5-alpine + ports: + - "16379:6379/tcp" + networks: + sbc-inbound: + ipv4_address: 172.38.0.13 + + rtpengine: + image: drachtio/rtpengine:latest + ports: + - "12222:22222/udp" + networks: + sbc-inbound: + ipv4_address: 172.38.0.14 + diff --git a/test/docker.env b/test/docker.env new file mode 100644 index 0000000..19112b9 --- /dev/null +++ b/test/docker.env @@ -0,0 +1,2 @@ +# tip: to minify json into a single string as below, see https://codebeautify.org/jsonminifier +NODE_CONFIG={"server":{"port":4000,"path":"/auth","auth":{"users":{"foo":"bar"}}},"credentials":{"jambonz.org":[{"username":"john","password":"1234"},{"username":"jane","password":"5678"}]}} \ No newline at end of file diff --git a/test/index.js b/test/index.js index 4b44985..7fd06e5 100644 --- a/test/index.js +++ b/test/index.js @@ -1,3 +1,4 @@ require('./docker_start'); -require('./sip-tests'); +require('./carrier-origination'); +//require('./device-origination'); require('./docker_stop'); diff --git a/test/scenarios/uac-pcap.xml b/test/scenarios/uac-pcap-carrier-success.xml similarity index 96% rename from test/scenarios/uac-pcap.xml rename to test/scenarios/uac-pcap-carrier-success.xml index bdc2efc..5e0a502 100644 --- a/test/scenarios/uac-pcap.xml +++ b/test/scenarios/uac-pcap-carrier-success.xml @@ -88,9 +88,8 @@ - - - + + diff --git a/test/sipp.js b/test/sipp.js index 2f580ec..9392af1 100644 --- a/test/sipp.js +++ b/test/sipp.js @@ -24,7 +24,7 @@ obj.output = () => { return output; }; -obj.sippUac = (file) => { +obj.sippUac = (file, bindAddress) => { const cmd = 'docker'; const args = [ 'run', '-ti', '--rm', '--net', `${network}`, @@ -34,9 +34,11 @@ obj.sippUac = (file) => { '-sleep', '250ms', '-nostdin', '-cid_str', `%u-%p@%s-${idx++}`, - 'drachtio' + 'sbc' ]; + if (bindAddress) args.splice(args.length - 2, 0, '-i', bindAddress); + clearOutput(); return new Promise((resolve, reject) => {