mirror of
https://github.com/jambonz/sbc-sip-sidecar.git
synced 2026-01-24 22:27:52 +00:00
feat: merge sip-registra and sip-options-handler
This commit is contained in:
78
test/sip-options-tests.js
Normal file
78
test/sip-options-tests.js
Normal file
@@ -0,0 +1,78 @@
|
|||||||
|
const test = require('tape');
|
||||||
|
const { sippUac } = require('./sipp')('test_sbc-sip-sidecar');
|
||||||
|
const clearModule = require('clear-module');
|
||||||
|
|
||||||
|
process.on('unhandledRejection', (reason, p) => {
|
||||||
|
console.log('Unhandled Rejection at: Promise', p, 'reason:', reason);
|
||||||
|
});
|
||||||
|
|
||||||
|
function connect(connectable) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
connectable.on('connect', () => {
|
||||||
|
return resolve();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function waitFor(ms) {
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
setTimeout(resolve, ms * 1000);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
test('sip options tests', async(t) => {
|
||||||
|
clearModule.all();
|
||||||
|
const {srf} = require('../app');
|
||||||
|
|
||||||
|
t.teardown(() => {
|
||||||
|
srf.disconnect();
|
||||||
|
});
|
||||||
|
|
||||||
|
try {
|
||||||
|
await connect(srf);
|
||||||
|
|
||||||
|
await sippUac('uac-add-fs-1.xml', null, '172.39.0.20');
|
||||||
|
t.pass('added a feature server');
|
||||||
|
|
||||||
|
await sippUac('uac-add-rtp-1.xml', null, '172.39.0.20');
|
||||||
|
t.pass('added an RTP server');
|
||||||
|
|
||||||
|
await sippUac('uac-add-fs-2.xml', null, '172.39.0.21');
|
||||||
|
t.pass('added a second feature server');
|
||||||
|
|
||||||
|
await sippUac('uac-add-fs-2.xml', null, '172.39.0.21');
|
||||||
|
t.pass('second feature server checks in again');
|
||||||
|
|
||||||
|
await sippUac('uac-add-rtp-2.xml', null, '172.39.0.21');
|
||||||
|
t.pass('added a second RTP server');
|
||||||
|
|
||||||
|
await sippUac('uac-remove-fs-1.xml', null, '172.39.0.20');
|
||||||
|
t.pass('remove feature server 1');
|
||||||
|
|
||||||
|
await sippUac('uac-remove-rtp-1.xml', null, '172.39.0.20');
|
||||||
|
t.pass('remove rtp server 1');
|
||||||
|
|
||||||
|
await sippUac('uac-remove-fs-2.xml', null, '172.39.0.21');
|
||||||
|
t.pass('removed second feature server');
|
||||||
|
|
||||||
|
await sippUac('uac-remove-rtp-2.xml', null, '172.39.0.21');
|
||||||
|
t.pass('removed second rtp server');
|
||||||
|
|
||||||
|
await sippUac('uac-external-options-ping.xml', null, '172.39.0.22');
|
||||||
|
t.pass('handled external options ping');
|
||||||
|
|
||||||
|
await sippUac('uac-add-fs-1.xml', null, '172.39.0.20');
|
||||||
|
t.pass('added a feature server');
|
||||||
|
|
||||||
|
await waitFor(16);
|
||||||
|
|
||||||
|
await sippUac('uac-add-fs-1.xml', null, '172.39.0.20');
|
||||||
|
t.pass('feature server expired due to lack of check-in');
|
||||||
|
|
||||||
|
t.end();
|
||||||
|
} catch (err) {
|
||||||
|
console.log(`error received: ${err}`);
|
||||||
|
t.end(err);
|
||||||
|
}
|
||||||
|
});
|
||||||
54
test/sip-register-tests.js
Normal file
54
test/sip-register-tests.js
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
const test = require('tape');
|
||||||
|
const { output, sippUac } = require('./sipp')('test_sbc-sip-sidecar');
|
||||||
|
const debug = require('debug')('drachtio:sbc-sip-sidecar');
|
||||||
|
const clearModule = require('clear-module');
|
||||||
|
|
||||||
|
process.on('unhandledRejection', (reason, p) => {
|
||||||
|
console.log('Unhandled Rejection at: Promise', p, 'reason:', reason);
|
||||||
|
});
|
||||||
|
|
||||||
|
function connect(connectable) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
connectable.on('connect', () => {
|
||||||
|
return resolve();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
test('register tests', (t) => {
|
||||||
|
clearModule.all();
|
||||||
|
const {srf} = require('../app');
|
||||||
|
|
||||||
|
const sippRegObj = {
|
||||||
|
remote_host: '172.38.0.10:5060'
|
||||||
|
};
|
||||||
|
|
||||||
|
connect(srf)
|
||||||
|
.then(() => {
|
||||||
|
sippRegObj.data_file = 'bad_realm.csv';
|
||||||
|
return sippUac('uac-reject-ipv4-realm.xml', sippRegObj);
|
||||||
|
})
|
||||||
|
.then(() => {
|
||||||
|
t.pass('received immediate 403 Forbidden when using ipv4 dot decimal for sip realm');
|
||||||
|
sippRegObj.data_file = 'bad_password.csv';
|
||||||
|
return sippUac('uac-register-auth-failure-expect-403.xml', sippRegObj);
|
||||||
|
})
|
||||||
|
.then(() => {
|
||||||
|
t.pass('received 403 Forbidden after challenge when using invalid credentials');
|
||||||
|
sippRegObj.data_file = 'good_user.csv';
|
||||||
|
return sippUac('uac-register-auth-success.xml', sippRegObj);
|
||||||
|
})
|
||||||
|
.then(() => {
|
||||||
|
t.pass('successfully registered when using valid credentials (service provider level auth hook)');
|
||||||
|
if (srf.locals.lb) srf.locals.lb.disconnect();
|
||||||
|
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);
|
||||||
|
});
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user