start of test cases

This commit is contained in:
Dave Horton
2019-08-17 11:53:01 -04:00
parent 6e61fb898c
commit 6cf55f69da
11 changed files with 102 additions and 24 deletions

9
.travis.yml Normal file
View File

@@ -0,0 +1,9 @@
sudo: required
language: node_js
node_js:
- "lts/*"
services:
- docker
script:
- npm test

13
app.js
View File

@@ -11,9 +11,18 @@ if (process.env.NODE_ENV === 'test') {
logger.child = () => {return {info: noop, error: noop, debug: noop};}; 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})); srf.invite(require('./lib/invite')({logger}));
module.exports = {srf}; module.exports = {srf};

View File

@@ -4,7 +4,43 @@
"port": 9060, "port": 9060,
"secret": "cymru" "secret": "cymru"
}, },
"rtpengine": {
"host": "127.0.0.1",
"port": 12222
},
"logging": { "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"]
}
} }
} }

View File

@@ -22,8 +22,7 @@ function handler({logger}) {
throw new Error(`failed allocating rtpengine endpoint: ${JSON.stringify(response)}`); throw new Error(`failed allocating rtpengine endpoint: ${JSON.stringify(response)}`);
} }
const {uas, uac} = await srf.createB2BUA(req, res, { const {uas, uac} = await srf.createB2BUA(req, res, uri, {
proxy: uri,
localSdpB: response.sdp, localSdpB: response.sdp,
localSdpA: (sdp, res) => { localSdpA: (sdp, res) => {
const opts = Object.assign({sdp, 'to-tag': res.getParsedHeader('To').params.tag}, const opts = Object.assign({sdp, 'to-tag': res.getParsedHeader('To').params.tag},

View File

@@ -3,7 +3,9 @@ const config = require('config');
const authenticator = require('drachtio-http-authenticator')(config.get('authCallback')); const authenticator = require('drachtio-http-authenticator')(config.get('authCallback'));
function auth(req, res, next) { function auth(req, res, next) {
if (fromInboundTrunk) return next(); if (fromInboundTrunk) {
return next();
}
authenticator(req, res, next); authenticator(req, res, next);
} }

View File

@@ -15,23 +15,21 @@ function connect(connectable) {
}); });
} }
test('invite handler', (t) => { test('incoming call from carrier', (t) => {
clearModule('../app'); clearModule('../app');
const {srf, disconnectMs} = require('../app'); const {srf} = require('../app');
connect(srf) connect(srf)
.then(() => { .then(() => {
return sippUac('uac-pcap.xml'); return sippUac('uac-pcap-carrier-success.xml', '172.38.0.20');
}) })
.then(() => { .then(() => {
t.pass('successfully connected call'); t.pass('successfully connected incoming call from carrier');
if (srf.locals.lb) srf.locals.lb.disconnect();
srf.disconnect(); srf.disconnect();
t.end(); t.end();
return; return;
}) })
.catch((err) => { .catch((err) => {
if (srf.locals.lb) srf.locals.lb.disconnect();
if (srf) srf.disconnect(); if (srf) srf.disconnect();
console.log(`error received: ${err}`); console.log(`error received: ${err}`);
t.error(err); t.error(err);

View File

@@ -8,25 +8,46 @@ networks:
- subnet: 172.38.0.0/16 - subnet: 172.38.0.0/16
services: services:
drachtio: sbc:
image: drachtio/drachtio-server:latest image: drachtio/drachtio-server:latest
command: drachtio --contact "sip:*;transport=udp" --loglevel debug --sofia-loglevel 9 command: drachtio --contact "sip:*;transport=udp" --loglevel debug --sofia-loglevel 9
container_name: drachtio
ports: ports:
- "9060:9022/tcp" - "9060:9022/tcp"
networks: networks:
sbc-inbound: sbc-inbound:
ipv4_address: 172.38.0.10 ipv4_address: 172.38.0.10
appserver:
sipp-uas:
image: drachtio/sipp:latest image: drachtio/sipp:latest
command: sipp -sf /tmp/uas.xml command: sipp -sf /tmp/uas.xml
container_name: sipp-uas.local
volumes: volumes:
- ./scenarios:/tmp - ./scenarios:/tmp
tty: true 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: networks:
sbc-inbound: sbc-inbound:
ipv4_address: 172.38.0.12 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

2
test/docker.env Normal file
View File

@@ -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"}]}}

View File

@@ -1,3 +1,4 @@
require('./docker_start'); require('./docker_start');
require('./sip-tests'); require('./carrier-origination');
//require('./device-origination');
require('./docker_stop'); require('./docker_stop');

View File

@@ -88,9 +88,8 @@
</action> </action>
</nop> </nop>
<!-- Pause 8 seconds, which is approximately the duration of the --> <!-- Pause briefly -->
<!-- PCAP file --> <pause milliseconds="3000"/>
<pause milliseconds="4000"/>
<!-- The 'crlf' option inserts a blank line in the statistics report. --> <!-- The 'crlf' option inserts a blank line in the statistics report. -->
<send retrans="500"> <send retrans="500">

View File

@@ -24,7 +24,7 @@ obj.output = () => {
return output; return output;
}; };
obj.sippUac = (file) => { obj.sippUac = (file, bindAddress) => {
const cmd = 'docker'; const cmd = 'docker';
const args = [ const args = [
'run', '-ti', '--rm', '--net', `${network}`, 'run', '-ti', '--rm', '--net', `${network}`,
@@ -34,9 +34,11 @@ obj.sippUac = (file) => {
'-sleep', '250ms', '-sleep', '250ms',
'-nostdin', '-nostdin',
'-cid_str', `%u-%p@%s-${idx++}`, '-cid_str', `%u-%p@%s-${idx++}`,
'drachtio' 'sbc'
]; ];
if (bindAddress) args.splice(args.length - 2, 0, '-i', bindAddress);
clearOutput(); clearOutput();
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {