Feature/retrieve registered users (#243)

* add GET /Accounts/:sid/RegisteredSipUsers

* fix vulnerabilities
This commit is contained in:
Dave Horton
2023-10-22 17:32:59 +02:00
committed by GitHub
parent a1c302f85c
commit 7b805130bb
7 changed files with 425 additions and 307 deletions

3
app.js
View File

@@ -8,6 +8,7 @@ const rateLimit = require('express-rate-limit');
const cors = require('cors');
const passport = require('passport');
const routes = require('./lib/routes');
const Registrar = require('@jambonz/mw-registrar');
assert.ok(process.env.JAMBONES_MYSQL_HOST &&
process.env.JAMBONES_MYSQL_USER &&
@@ -35,6 +36,7 @@ const {
logger, process.env.JAMBONES_TIME_SERIES_HOST
);
const {
client,
retrieveCall,
deleteCall,
listCalls,
@@ -81,6 +83,7 @@ passport.use(authStrategy);
app.locals = app.locals || {};
app.locals = {
...app.locals,
registrar: new Registrar(logger, client),
logger,
retrieveCall,
deleteCall,

View File

@@ -25,6 +25,7 @@ const JAMBONES_REDIS_SENTINELS = process.env.JAMBONES_REDIS_SENTINELS ? {
} : null;
const {
client,
retrieveCall,
deleteCall,
listCalls,
@@ -42,6 +43,7 @@ const {
}, logger);
module.exports = {
client,
retrieveCall,
deleteCall,
listCalls,

View File

@@ -145,6 +145,21 @@ router.post('/:sid/VoipCarriers', async(req, res) => {
sysError(logger, res, err);
}
});
router.get('/:sid/RegisteredSipUsers', async(req, res) => {
const {logger, registrar} = req.app.locals;
try {
const account_sid = parseAccountSid(req);
await validateRequest(req, account_sid);
const result = await Account.retrieve(account_sid);
if (!result || result.length === 0) {
throw new DbErrorBadRequest(`account not found for sid ${account_sid}`);
}
const users = await registrar.getRegisteredUsersForRealm(result[0].sip_realm);
res.status(200).json(users.map((u) => `${u}@${result[0].sip_realm}`));
} catch (err) {
sysError(logger, res, err);
}
});
function coerceNumbers(callInfo) {
if (Array.isArray(callInfo)) {

View File

@@ -4164,6 +4164,28 @@ paths:
type: string
length:
type: string
/Accounts/{AccountSid}/RegisteredSipUsers:
parameters:
- name: AccountSid
in: path
required: true
schema:
type: string
format: uuid
get:
tags:
- Accounts
summary: retrieve online sip users for an account
operationId: listQueues
responses:
200:
description: retrieve online sip users for an account
content:
application/json:
schema:
type: array
items:
type: string
/Lcrs:
post:
tags:

653
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -19,16 +19,19 @@
"url": "https://github.com/jambonz/jambonz-api-server.git"
},
"dependencies": {
"@aws-sdk/client-transcribe": "^3.363.0",
"@aws-sdk/client-s3": "^3.363.0",
"@aws-sdk/client-transcribe": "^3.363.0",
"@azure/storage-blob": "^12.15.0",
"@deepgram/sdk": "^1.21.0",
"@google-cloud/speech": "^5.2.0",
"@google-cloud/storage": "^6.12.0",
"@jambonz/db-helpers": "^0.9.0",
"@jambonz/realtimedb-helpers": "^0.8.6",
"@jambonz/lamejs": "^1.2.2",
"@jambonz/mw-registrar": "^0.2.5",
"@jambonz/realtimedb-helpers": "^0.8.7",
"@jambonz/speech-utils": "^0.0.15",
"@jambonz/time-series": "^0.2.8",
"@jambonz/verb-specifications": "^0.0.29",
"@jambonz/lamejs": "^1.2.2",
"@soniox/soniox-node": "^1.1.1",
"argon2": "^0.30.3",
"bent": "^7.3.12",
@@ -51,11 +54,9 @@
"stripe": "^8.222.0",
"swagger-ui-express": "^4.4.0",
"uuid": "^8.3.2",
"yamljs": "^0.3.0",
"ws": "^8.12.1",
"wav": "^1.0.2",
"@google-cloud/storage": "^6.12.0",
"@azure/storage-blob": "^12.15.0"
"ws": "^8.12.1",
"yamljs": "^0.3.0"
},
"devDependencies": {
"eslint": "^8.39.0",

View File

@@ -12,6 +12,7 @@ process.on('unhandledRejection', (reason, p) => {
test('client test', async(t) => {
const app = require('../app');
const {registrar} = app.locals;
try {
let result;
@@ -35,6 +36,7 @@ test('client test', async(t) => {
body: {
name: 'sample_account',
service_provider_sid: sp_sid,
sip_realm: 'drachtio.org',
registration_hook: {
url: 'http://example.com/reg',
method: 'get'
@@ -60,6 +62,26 @@ test('client test', async(t) => {
t.ok(result.statusCode === 201, 'successfully created Client');
const sid = result.body.sid;
/* register the client */
const r = await registrar.add(
"dhorton@drachtio.org",
{
contact: "10.10.1.1",
sbcAddress: "192.168.1.1",
protocol: "udp",
},
5
);
t.ok(r, 'successfully registered Client');
/* query all registered clients */
result = await request.get(`/Accounts/${account_sid}/RegisteredSipUsers`, {
auth: authAdmin,
json: true,
});
t.ok(result.length === 1 && result[0] === 'dhorton@drachtio.org',
'successfully queried all registered clients');
/* query all entity */
result = await request.get('/Clients', {
auth: authAdmin,