tests in progress

This commit is contained in:
Dave Horton
2019-08-17 14:34:34 -04:00
parent 785e992107
commit 537d6a9eaf
7 changed files with 36 additions and 13 deletions

View File

@@ -100,9 +100,16 @@ Inbound sip trunks are configured by specifing name and associated ip addresses.
}
}
```
## Forwarding behavior
This application acts as a back-to-back user agent and media proxy. When sending INVITEs on to the jambonz application servers, it adds the following headers onto the INVITE:
- `X-Forwarded-For`: the IP address of the client that sent the INVITE
- `X-Forwarded-Proto`: the transport protocol used by the client
- `X-Forwarded-Carrier`: the name of the inbound carrier, if applicable
## Tests
The automated test suite requires a docker installation.
```
npm test
```

2
app.js
View File

@@ -23,6 +23,6 @@ else {
}
srf.use('invite', auth);
srf.invite(require('./lib/invite')({logger}));
srf.invite(require('./lib/invite')({log: logger}));
module.exports = {srf};

View File

@@ -8,8 +8,9 @@ const {getAppserver, isWSS} = require('./utils');
module.exports = handler;
function handler({logger}) {
function handler({log}) {
return async(req, res) => {
const logger = log.child({callId: req.get('Call-ID')});
const srf = req.srf;
const rtpEngineOpts = makeRtpEngineOpts(req, isWSS(req), false);
const rtpEngineResource = {destroy: del.bind(rtpengine, rtpEngineOpts.common)};
@@ -23,8 +24,14 @@ function handler({logger}) {
}
const {uas, uac} = await srf.createB2BUA(req, res, uri, {
headers: {
'X-Forwarded-For': req.source_address,
'X-Forwarded-Proto': req.getParsedHeader('Via')[0].protocol.toLowerCase(),
'X-Forwarded-Carrier': req.carrier_name
},
proxyRequestHeaders: ['User-Agent', 'Subject'],
localSdpB: response.sdp,
localSdpA: (sdp, res) => {
localSdpA: (sdp, res) => {
const opts = Object.assign({sdp, 'to-tag': res.getParsedHeader('To').params.tag},
rtpEngineOpts.answer);
return answer(opts)
@@ -35,12 +42,8 @@ function handler({logger}) {
}
});
logger.info('call connected');
setHandlers(logger, uas, uac, rtpEngineResource);
[uas, uac].forEach((dlg) => dlg.on('destroy', () => {
logger.info('call ended');
dlg.other.destroy();
rtpEngineResource.destroy();
}));
} catch (err) {
logger.error(err, 'Error connecting call');
rtpEngineResource.destroy();
@@ -48,6 +51,16 @@ function handler({logger}) {
};
}
function setHandlers(logger, uas, uac, rtpEngineResource) {
[uas, uac].forEach((dlg) => dlg.on('destroy', () => {
logger.info('call ended');
dlg.other.destroy();
rtpEngineResource.destroy();
}));
//TODO: handle re-INVITEs, REFER, INFO
}
function makeRtpEngineOpts(req, srcIsUsingSrtp, dstIsUsingSrtp) {
const from = req.getParsedHeader('from');
const common = {'call-id': req.get('Call-ID'), 'from-tag': from.params.tag};

View File

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

View File

@@ -5,7 +5,10 @@ function fromInboundTrunk(req) {
const trunks = config.has('trunks.inbound') ?
config.get('trunks.inbound') : [];
if (isWSS(req)) return false;
return trunks.find((trunk) => trunk.host.includes(req.source_address));
const trunk = trunks.find((t) => t.host.includes(req.source_address));
if (!trunk) return false;
req.carrier_name = trunk.name;
return true;
}
function isWSS(req) {

View File

@@ -19,7 +19,7 @@
},
"dependencies": {
"config": "^3.2.2",
"drachtio-http-authenticator": "0.0.2",
"drachtio-http-authenticator": "0.0.3",
"drachtio-srf": "^4.4.14",
"pino": "^5.13.2",
"rtpengine-client": "0.0.8"

View File

@@ -37,7 +37,7 @@ obj.sippUac = (file, bindAddress) => {
'sbc'
];
if (bindAddress) args.splice(args.length - 2, 0, '-i', bindAddress);
if (bindAddress) args.splice(5, 0, '--ip', bindAddress);
clearOutput();