Compare commits

...

18 Commits

Author SHA1 Message Date
khang
81def62a03 fix tests 2022-08-17 18:33:53 -04:00
khang
b60fd4bbc4 Fix application /:sid return 2022-08-17 16:33:37 -04:00
Hans Krutzer
08163a31d0 Add missing fields to PhoneNumbers POST request Swagger spec (#53) 2022-08-17 15:55:25 +02:00
Dave Horton
1898ba501d upgrade should a FK to new column 2022-08-09 15:27:26 +02:00
Dave Horton
6f52202deb bugfix: FK was wrong 2022-08-03 17:22:30 +01:00
Dave Horton
0ceb79b568 add siprec_hook_sid to accounts model 2022-08-03 14:56:07 +01:00
Dave Horton
1e396266a0 upgrade-jambonz-db.js now handles schema upgrades 2022-07-29 09:48:28 +01:00
Dave Horton
69f36f5a51 Feature/siprec server (#49)
* upgrade schema to 0.7.6 if necessary

* db upgrade

* db upgrade
2022-07-28 16:17:39 +01:00
Dave Horton
f83cc25098 Dockerfile: update base image 2022-07-28 12:59:05 +01:00
Dave Horton
1473c30d7b update passport 2022-07-07 16:15:54 +02:00
Dave Horton
6088b99acf fix Dockerfile for db-create image 2022-07-07 16:10:18 +02:00
Guilherme Rauen
9aab716dc9 Snyk Security Issues (#46)
* improve dockerfile and fix snyk security issues

* enable build in arm64 machine

Co-authored-by: Guilherme Rauen <g.rauen@cognigy.com>
2022-06-29 08:33:08 -04:00
Dave Horton
56b646b6db Feature/siprec client (#45)
* updateCall now supports record action to start, stop, pause, or resume siprec

* update Dockerfile
2022-06-23 16:25:11 -04:00
Dave Horton
eeb23109dc update to azure 1.22.0 2022-06-11 16:18:26 -04:00
Dave Horton
17d1be4605 update deps 2022-06-11 12:23:54 -04:00
Dave Horton
2324890b72 add ability to create service_provider level apikeys 2022-05-06 20:30:38 -04:00
Dave Horton
4097ca2125 bugfix: createCall accepts call_hook that is a ws(s) url 2022-05-02 08:21:03 -04:00
Dave Horton
9a126f396e remove orphaned webhooks when deleting accounts and applications 2022-04-30 12:17:37 -04:00
18 changed files with 1957 additions and 2611 deletions

View File

@@ -1,10 +1,23 @@
FROM node:17
FROM --platform=linux/amd64 node:18.6.0-alpine as base
RUN apk --update --no-cache add --virtual .builds-deps build-base python3
WORKDIR /opt/app/
COPY package.json ./
RUN npm install
RUN npm prune
COPY . /opt/app
FROM base as build
COPY package.json package-lock.json ./
RUN npm ci
COPY . .
FROM base
COPY --from=build /opt/app /opt/app/
ARG NODE_ENV
ENV NODE_ENV $NODE_ENV
CMD [ "npm", "start" ]
CMD [ "node", "app.js" ]

View File

@@ -1,10 +1,23 @@
FROM node:17
FROM --platform=linux/amd64 node:18.6.0-alpine as base
RUN apk --update --no-cache add --virtual .builds-deps build-base python3
WORKDIR /opt/app/
COPY package.json ./
RUN npm install
RUN npm prune
COPY . /opt/app
FROM base as build
COPY package.json package-lock.json ./
RUN npm ci
COPY . .
FROM base
COPY --from=build /opt/app /opt/app/
ARG NODE_ENV
ENV NODE_ENV $NODE_ENV
CMD [ "npm", "run", "upgrade-db" ]

View File

@@ -365,7 +365,7 @@ CREATE TABLE webhooks
(
webhook_sid CHAR(36) NOT NULL UNIQUE ,
url VARCHAR(1024) NOT NULL,
method ENUM("GET","POST","WS") NOT NULL DEFAULT 'POST',
method ENUM("GET","POST") NOT NULL DEFAULT 'POST',
username VARCHAR(255),
password VARCHAR(255),
PRIMARY KEY (webhook_sid)
@@ -422,6 +422,7 @@ subspace_client_id VARCHAR(255),
subspace_client_secret VARCHAR(255),
subspace_sip_teleport_id VARCHAR(255),
subspace_sip_teleport_destinations VARCHAR(255),
siprec_hook_sid CHAR(36),
PRIMARY KEY (account_sid)
) COMMENT='An enterprise that uses the platform for comm services';
@@ -576,4 +577,6 @@ ALTER TABLE accounts ADD FOREIGN KEY queue_event_hook_sid_idxfk (queue_event_hoo
ALTER TABLE accounts ADD FOREIGN KEY device_calling_application_sid_idxfk (device_calling_application_sid) REFERENCES applications (application_sid);
SET FOREIGN_KEY_CHECKS=0;
ALTER TABLE accounts ADD FOREIGN KEY siprec_hook_sid_idxfk (siprec_hook_sid) REFERENCES applications (application_sid);
SET FOREIGN_KEY_CHECKS=1;

View File

@@ -1412,7 +1412,7 @@
</location>
<size>
<width>318.00</width>
<height>420.00</height>
<height>440.00</height>
</size>
<zorder>4</zorder>
<SQLField>
@@ -1577,6 +1577,19 @@
<type><![CDATA[VARCHAR(255)]]></type>
<uid><![CDATA[2A70CC94-123D-4AF1-9881-F876051D8CB5]]></uid>
</SQLField>
<SQLField>
<name><![CDATA[siprec_hook_sid]]></name>
<type><![CDATA[CHAR(36)]]></type>
<referencesField>application_sid</referencesField>
<referencesTable>applications</referencesTable>
<referencesField><![CDATA[application_sid]]></referencesField>
<referencesTable><![CDATA[applications]]></referencesTable>
<sourceCardinality>4</sourceCardinality>
<destinationCardinality>1</destinationCardinality>
<referencesFieldUID><![CDATA[EF943D13-DCB0-43C1-B03F-550612E20F9D]]></referencesFieldUID>
<referencesTableUID><![CDATA[E97EE4F0-7ED7-4E8C-862E-D98192D6EAE0]]></referencesTableUID>
<uid><![CDATA[4B8283B4-5E16-4846-A79D-12C6B2E73C86]]></uid>
</SQLField>
<labelWindowIndex><![CDATA[25]]></labelWindowIndex>
<objectComment><![CDATA[An enterprise that uses the platform for comm services]]></objectComment>
<ui.treeExpanded><![CDATA[1]]></ui.treeExpanded>
@@ -1855,7 +1868,7 @@
<objectComment><![CDATA[if not null, this number is a test number for the associated service provider]]></objectComment>
<uid><![CDATA[D2D46B75-F9C7-42A5-8D8C-4A8412C75ECA]]></uid>
</SQLField>
<labelWindowIndex><![CDATA[25]]></labelWindowIndex>
<labelWindowIndex><![CDATA[26]]></labelWindowIndex>
<objectComment><![CDATA[A phone number that has been assigned to an account]]></objectComment>
<ui.treeExpanded><![CDATA[1]]></ui.treeExpanded>
<uid><![CDATA[BA650DDC-AC7B-4DFE-A5E5-828C75607807]]></uid>
@@ -2433,17 +2446,17 @@
<overviewPanelHidden><![CDATA[0]]></overviewPanelHidden>
<pageBoundariesVisible><![CDATA[0]]></pageBoundariesVisible>
<PageGridVisible><![CDATA[0]]></PageGridVisible>
<RightSidebarWidth><![CDATA[2154.000000]]></RightSidebarWidth>
<RightSidebarWidth><![CDATA[1235.000000]]></RightSidebarWidth>
<sidebarIndex><![CDATA[2]]></sidebarIndex>
<snapToGrid><![CDATA[0]]></snapToGrid>
<SourceSidebarWidth><![CDATA[0.000000]]></SourceSidebarWidth>
<SQLEditorFileFormatVersion><![CDATA[4]]></SQLEditorFileFormatVersion>
<uid><![CDATA[58C99A00-06C9-478C-A667-C63842E088F3]]></uid>
<windowHeight><![CDATA[977.000000]]></windowHeight>
<windowLocationX><![CDATA[1230.000000]]></windowLocationX>
<windowLocationY><![CDATA[80.000000]]></windowLocationY>
<windowScrollOrigin><![CDATA[{0, 0}]]></windowScrollOrigin>
<windowWidth><![CDATA[2431.000000]]></windowWidth>
<windowHeight><![CDATA[833.000000]]></windowHeight>
<windowLocationX><![CDATA[0.000000]]></windowLocationX>
<windowLocationY><![CDATA[111.000000]]></windowLocationY>
<windowScrollOrigin><![CDATA[{172, 109}]]></windowScrollOrigin>
<windowWidth><![CDATA[1512.000000]]></windowWidth>
</SQLDocumentInfo>
<AllowsIndexRenamingOnInsert><![CDATA[1]]></AllowsIndexRenamingOnInsert>
<defaultLabelExpanded><![CDATA[1]]></defaultLabelExpanded>

View File

@@ -1,6 +1,8 @@
SET FOREIGN_KEY_CHECKS=0;
-- create one service provider
insert into service_providers (service_provider_sid, name, description, root_domain)
values ('2708b1b3-2736-40ea-b502-c53d8396247f', 'sip.jambonz.us', 'jambonz.us service provider', 'sip.jambonz.us');
values ('2708b1b3-2736-40ea-b502-c53d8396247f', 'sip.jambonz.xyz', 'jambonz.xyz service provider', 'sip.jambonz.xyz');
insert into api_keys (api_key_sid, token)
values ('3f35518f-5a0d-4c2e-90a5-2407bb3b36f0', '38700987-c7a4-4685-a5bb-af378f9734de');
@@ -16,9 +18,9 @@ insert into predefined_carriers (predefined_carrier_sid, name, requires_static_i
requires_register, register_username, register_password,
register_sip_realm, tech_prefix, inbound_auth_username, inbound_auth_password, diversion)
VALUES
('17479288-bb9f-421a-89d1-f4ac57af1dca', 'TelecomsXChange', 0, 0, 0, NULL, NULL, NULL, 'your-tech-prefix', NULL, NULL, NULL),
('7d509a18-bbff-4c5d-b21e-b99bf8f8c49a', 'Twilio', 0, 1, 0, '<your-twilio-credential-username>', '<your-twilio-credential-password>', NULL, NULL, NULL, NULL, NULL),
('032d90d5-39e8-41c0-b807-9c88cffba65c', 'Voxbone', 0, 1, 0, '<your-voxbone-outbound-username>', '<your-voxbone-outbound-password>', NULL, NULL, NULL, NULL, '<your-voxbone-DID>'),
('17479288-bb9f-421a-89d1-f4ac57af1dca', 'TelecomsXChange', 0, 0, 0, NULL, NULL, NULL, 'your-tech-prefix', NULL, NULL, NULL),
('e6fb301a-1af0-4fb8-a1f6-f65530c6e1c6', 'Simwood', 0, 1, 0, '<your-simwood-auth-trunk-username>', '<your-simwood-auth-trunk-password>', NULL, NULL, NULL, NULL, NULL);
-- TelecomXchange gateways
@@ -69,3 +71,4 @@ VALUES
('e7447e7e-2c7d-4738-ab53-097c187236ff', 'e6fb301a-1af0-4fb8-a1f6-f65530c6e1c6', '178.22.143.66', 32, 5060, 1, 0),
('5f431d42-48e4-44ce-a311-d946f0b475b6', 'e6fb301a-1af0-4fb8-a1f6-f65530c6e1c6', 'out.simwood.com', 32, 5060, 0, 1);
SET FOREIGN_KEY_CHECKS=1;

View File

@@ -22,6 +22,14 @@ const opts = {
multipleStatements: true
};
const sql = {
'7006': [
'ALTER TABLE `accounts` ADD COLUMN `siprec_hook_sid` CHAR(36)',
// eslint-disable-next-line max-len
'ALTER TABLE accounts ADD FOREIGN KEY siprec_hook_sid_idxfk (siprec_hook_sid) REFERENCES applications (application_sid)'
]
};
const doIt = async() => {
let connection;
try {
@@ -35,10 +43,32 @@ const doIt = async() => {
try {
/* does the schema exist at all ? */
const [r] = await connection.execute('SELECT version from schema_version');
let errors = 0;
if (r.length) {
//TODO: check against desired version and perform upgrades
logger.info(`current version is ${r[0].version}, no upgrade will be performed`);
const {version} = r[0];
const arr = /v?(\d+)\.(\d+)\.(\d+)/.exec(version);
if (arr) {
const upgrades = [];
logger.info(`performing schema migration: ${version} => ${desiredVersion}`);
const val = (1000 * arr[1]) + (100 * arr[2]) + arr[3];
logger.info(`current schema value: ${val}`);
if (val < 7006) upgrades.push(...sql['7006']);
// perform all upgrades
logger.info({upgrades}, 'applying schema upgrades..');
for (const upgrade of upgrades) {
try {
await connection.execute(upgrade);
} catch (err) {
errors++;
logger.info({statement:upgrade, err}, 'Error applying statement');
}
}
}
if (errors === 0) await connection.execute(`UPDATE schema_version SET version = '${desiredVersion}'`);
await connection.end();
logger.info(`schema migration to ${desiredVersion} completed with ${errors} errors`);
return;
}
} catch (err) {
@@ -70,5 +100,6 @@ const seedDatabase = async(connection) => {
await connection.query(sql);
};
doIt();

View File

@@ -314,6 +314,10 @@ Account.fields = [
name: 'subspace_sip_teleport_destinations',
type: 'string',
},
{
name: 'siprec_hook_sid',
type: 'string',
},
];
module.exports = Account;

View File

@@ -27,6 +27,25 @@ class ApiKey extends Model {
});
}
/**
* list all api keys for a service provider
*/
static retrieveAllForSP(service_provider_sid) {
const sql = 'SELECT * from api_keys WHERE service_provider_sid = ?';
const args = [service_provider_sid];
return new Promise((resolve, reject) => {
getMysqlConnection((err, conn) => {
if (err) return reject(err);
conn.query(sql, args, (err, results) => {
conn.release();
if (err) return reject(err);
resolve(results);
});
});
});
}
/**
* update last_used api key for an account
*/

View File

@@ -117,7 +117,8 @@ function validateUpdateCall(opts) {
'conf_hold_status',
'conf_mute_status',
'mute_status',
'sip_request'
'sip_request',
'record'
]
.reduce((acc, prop) => (opts[prop] ? ++acc : acc), 0);
@@ -156,6 +157,12 @@ function validateUpdateCall(opts) {
(!opts.sip_request.method && !opts.sip_request.content_type || !opts.sip_request.content_type)) {
throw new DbErrorBadRequest('sip_request requires content_type and content properties');
}
if (opts.record && !opts.record.action) {
throw new DbErrorBadRequest('record requires action property');
}
if ('startCallRecording' === opts.record?.action && !opts.record.siprecServerURL) {
throw new DbErrorBadRequest('record requires siprecServerURL property when starting recording');
}
}
function validateTo(to) {
@@ -240,10 +247,10 @@ async function validateCreateCall(logger, sid, req) {
if (typeof obj.call_status_hook === 'object' && typeof obj.call_status_hook.url != 'string') {
throw new DbErrorBadRequest('call_status_hook must be string or an object containing a url property');
}
if (obj.call_hook && !/^https?:/.test(obj.call_hook.url)) {
if (obj.call_hook && !/^https?:/.test(obj.call_hook.url) && !/^wss?:/.test(obj.call_hook.url)) {
throw new DbErrorBadRequest('call_hook url be an absolute url');
}
if (obj.call_status_hook && !/^https?:/.test(obj.call_status_hook.url)) {
if (obj.call_status_hook && !/^https?:/.test(obj.call_status_hook.url) && !/^wss?:/.test(obj.call_status_hook.url)) {
throw new DbErrorBadRequest('call_status_hook url be an absolute url');
}
}
@@ -519,7 +526,7 @@ router.delete('/:sid', async(req, res) => {
await validateDelete(req, sid);
const [account] = await promisePool.query('SELECT * FROM accounts WHERE account_sid = ?', sid);
const {sip_realm, stripe_customer_id} = account[0];
const {sip_realm, stripe_customer_id, registration_hook_sid} = account[0];
/* remove dns records */
if (process.env.NODE_ENV !== 'test' || process.env.DME_API_KEY) {
@@ -560,6 +567,15 @@ account_subscriptions WHERE account_sid = ?)
await promisePool.execute('DELETE from applications where account_sid = ?', [sid]);
await promisePool.execute('DELETE from accounts where account_sid = ?', [sid]);
if (registration_hook_sid) {
/* remove registration hook if only used by this account */
const sql = 'SELECT COUNT(*) as count FROM accounts WHERE registration_hook_sid = ?';
const [r] = await promisePool.query(sql, registration_hook_sid);
if (r[0]?.count === 0) {
await promisePool.execute('DELETE from webhooks where webhook_sid = ?', [registration_hook_sid]);
}
}
if (stripe_customer_id) {
const response = await deleteCustomer(logger, stripe_customer_id);
logger.info({response}, `deleted stripe customer_id ${stripe_customer_id} for account_si ${sid}`);

View File

@@ -3,12 +3,12 @@ const {DbErrorBadRequest, DbErrorUnprocessableRequest} = require('../../utils/er
const Application = require('../../models/application');
const Account = require('../../models/account');
const Webhook = require('../../models/webhook');
const {promisePool} = require('../../db');
const decorate = require('./decorate');
const sysError = require('../error');
const preconditions = {
'add': validateAdd,
'update': validateUpdate,
'delete': validateDelete
'update': validateUpdate
};
/* only user-level tokens can add applications */
@@ -59,7 +59,7 @@ async function validateDelete(req, sid) {
if (assignedPhoneNumbers > 0) throw new DbErrorUnprocessableRequest('cannot delete application with phone numbers');
}
decorate(router, Application, ['delete'], preconditions);
decorate(router, Application, [], preconditions);
/* add */
router.post('/', async(req, res) => {
@@ -104,13 +104,54 @@ router.get('/:sid', async(req, res) => {
const account_sid = req.user.hasAccountAuth ? req.user.account_sid : null;
const results = await Application.retrieve(req.params.sid, service_provider_sid, account_sid);
if (results.length === 0) return res.status(404).end();
return res.status(200).json(results);
return res.status(200).json(results[0]);
}
catch (err) {
sysError(logger, res, err);
}
});
/* delete */
router.delete('/:sid', async(req, res) => {
const sid = req.params.sid;
const logger = req.app.locals.logger;
try {
await validateDelete(req, sid);
const [application] = await promisePool.query('SELECT * FROM applications WHERE application_sid = ?', sid);
const {call_hook_sid, call_status_hook_sid, messaging_hook_sid} = application[0];
logger.info({call_hook_sid, call_status_hook_sid, messaging_hook_sid, sid}, 'deleting application');
await promisePool.execute('DELETE from applications where application_sid = ?', [sid]);
if (call_hook_sid) {
/* remove call hook if only used by this app */
const sql = 'SELECT COUNT(*) as count FROM applications WHERE call_hook_sid = ?';
const [r] = await promisePool.query(sql, call_hook_sid);
if (r[0]?.count === 0) {
await promisePool.execute('DELETE from webhooks where webhook_sid = ?', [call_hook_sid]);
}
}
if (call_status_hook_sid) {
const sql = 'SELECT COUNT(*) as count FROM applications WHERE call_status_hook_sid = ?';
const [r] = await promisePool.query(sql, call_status_hook_sid);
if (r[0]?.count === 0) {
await promisePool.execute('DELETE from webhooks where webhook_sid = ?', [call_status_hook_sid]);
}
}
if (messaging_hook_sid) {
const sql = 'SELECT COUNT(*) as count FROM applications WHERE messaging_hook_sid = ?';
const [r] = await promisePool.query(sql, messaging_hook_sid);
if (r[0]?.count === 0) {
await promisePool.execute('DELETE from webhooks where webhook_sid = ?', [messaging_hook_sid]);
}
}
res.status(204).end();
} catch (err) {
sysError(logger, res, err);
}
});
/* update */
router.put('/:sid', async(req, res) => {
const sid = req.params.sid;

View File

@@ -7,9 +7,16 @@ const isAdminScope = (req, res, next) => {
message: 'insufficient privileges'
});
};
const isAdminOrSPScope = (req, res, next) => {
if (req.user.hasScope('admin') || req.user.hasScope('service_provider')) return next();
res.status(403).json({
status: 'fail',
message: 'insufficient privileges'
});
};
api.use('/BetaInviteCodes', isAdminScope, require('./beta-invite-codes'));
api.use('/ServiceProviders', isAdminScope, require('./service-providers'));
api.use('/ServiceProviders', isAdminOrSPScope, require('./service-providers'));
api.use('/VoipCarriers', require('./voip-carriers'));
api.use('/Webhooks', require('./webhooks'));
api.use('/SipGateways', require('./sip-gateways'));

View File

@@ -7,6 +7,7 @@ const Account = require('../../models/account');
const VoipCarrier = require('../../models/voip-carrier');
const Application = require('../../models/application');
const PhoneNumber = require('../../models/phone-number');
const ApiKey = require('../../models/api-key');
const {hasServiceProviderPermissions, parseServiceProviderSid} = require('./utils');
const sysError = require('../error');
const decorate = require('./decorate');
@@ -114,6 +115,18 @@ router.get(':sid/Acccounts', async(req, res) => {
sysError(logger, res, err);
}
});
router.get('/:sid/ApiKeys', async(req, res) => {
const logger = req.app.locals.logger;
const {sid} = req.params;
try {
const results = await ApiKey.retrieveAllForSP(sid);
res.status(200).json(results);
await ApiKey.updateLastUsed(sid);
} catch (err) {
sysError(logger, res, err);
}
});
/* add */
router.post('/', async(req, res) => {

View File

@@ -1346,6 +1346,12 @@ paths:
schema:
type: object
properties:
account_sid:
type: string
format: uuid
application_sid:
type: string
format: uuid
number:
type: string
description: telephone number
@@ -3135,6 +3141,20 @@ paths:
type: string
headers:
type: object
record:
type: object
properties:
action:
type: string
enum:
- startCallRecording
- stopCallRecording
- pauseCallRecording
- resumeCallRecording
recordingID:
type: string
siprecServerURL:
type: string
responses:
200:
description: Accepted

4236
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,6 +1,6 @@
{
"name": "jambonz-api-server",
"version": "v0.7.5",
"version": "v0.7.6",
"description": "",
"main": "app.js",
"scripts": {
@@ -18,42 +18,39 @@
"url": "https://github.com/jambonz/jambonz-api-server.git"
},
"dependencies": {
"@google-cloud/speech": "^4.10.0",
"@google-cloud/speech": "^4.10.2",
"@google-cloud/text-to-speech": "^3.4.0",
"@jambonz/db-helpers": "^0.6.16",
"@jambonz/realtimedb-helpers": "^0.4.24",
"@jambonz/time-series": "^0.1.6",
"@jambonz/db-helpers": "^0.6.18",
"@jambonz/realtimedb-helpers": "^0.4.29",
"@jambonz/time-series": "^0.1.9",
"argon2-ffi": "^2.0.0",
"aws-sdk": "^2.1073.0",
"aws-sdk": "^2.1152.0",
"bent": "^7.3.12",
"cors": "^2.8.5",
"debug": "^4.3.3",
"express": "^4.17.2",
"express-rate-limit": "^6.3.0",
"debug": "^4.3.4",
"express": "^4.18.1",
"express-rate-limit": "^6.4.0",
"form-data": "^2.5.1",
"form-urlencoded": "^6.0.5",
"helmet": "^5.0.2",
"helmet": "^5.1.0",
"jsonwebtoken": "^8.5.1",
"mailgun.js": "^3.7.3",
"microsoft-cognitiveservices-speech-sdk": "^1.19.0",
"mysql2": "^2.3.3",
"passport": "^0.5.2",
"passport": "^0.6.0",
"passport-http-bearer": "^1.0.1",
"pino": "^5.17.0",
"request-debug": "^0.2.0",
"short-uuid": "^4.1.0",
"stripe": "^8.196.0",
"swagger-ui-express": "^4.3.0",
"stripe": "^8.222.0",
"swagger-ui-express": "^4.4.0",
"uuid": "^8.3.2",
"yamljs": "^0.3.0"
},
"devDependencies": {
"eslint": "^7.17.0",
"eslint": "^7.32.0",
"eslint-plugin-promise": "^4.2.1",
"husky": "7.0.4",
"nyc": "^15.1.0",
"request": "^2.88.2",
"request-promise-native": "^1.0.9",
"tape": "^5.2.2"
"tape": "^5.5.3"
}
}

View File

@@ -60,8 +60,8 @@ test('application tests', async(t) => {
auth: authAdmin,
json: true,
});
t.ok(result[0].name === 'daveh' , 'successfully retrieved application by sid');
t.ok(result[0].messaging_hook.url === 'http://example.com/sms' , 'successfully retrieved messaging_hook from application');
t.ok(result.name === 'daveh' , 'successfully retrieved application by sid');
t.ok(result.messaging_hook.url === 'http://example.com/sms' , 'successfully retrieved messaging_hook from application');
/* update applications */
result = await request.put(`/Applications/${sid}`, {
@@ -84,7 +84,7 @@ test('application tests', async(t) => {
auth: authAdmin,
json: true,
});
t.ok(result[0].messaging_hook.url === 'http://example2.com/mms' , 'successfully updated messaging_hook');
t.ok(result.messaging_hook.url === 'http://example2.com/mms' , 'successfully updated messaging_hook');
/* assign phone number to application */
result = await request.put(`/PhoneNumbers/${phone_number_sid}`, {

View File

@@ -318,7 +318,7 @@ test('authentication tests', async(t) => {
json: true
});
//console.log(`result: ${JSON.stringify(result)}`);
t.ok(result.length === 1, 'using account token A1 we are able to retrieve application A1');
t.ok(result.name === "A1-app", 'using account token A1 we are able to retrieve application A1');
/* cannot see app under another account using account token */
result = await request.get(`/Applications/${appA2}`, {

View File

@@ -106,6 +106,33 @@ test('service provider tests', async(t) => {
});
t.ok(result.statusCode === 204, 'successfully updated service provider');
/* add an api key for a service provider */
result = await request.post(`/ApiKeys`, {
auth: authAdmin,
json: true,
resolveWithFullResponse: true,
body: {
service_provider_sid: sid
}
});
t.ok(result.statusCode === 201, 'successfully added an api_key for a service provider');
const apiKeySid = result.body.sid;
/* query all api keys for a service provider */
result = await request.get(`/ServiceProviders/${sid}/ApiKeys`, {
auth: authAdmin,
json: true,
});
t.ok(result.length === 1 , 'successfully queried all service provider keys');
/* delete an api key */
result = await request.delete(`/ApiKeys/${apiKeySid}`, {
auth: authAdmin,
json: true,
resolveWithFullResponse: true,
});
t.ok(result.statusCode === 204, 'successfully deleted an api_key for a service provider');
/* add a predefined carrier for a service provider */
result = await request.post(`/ServiceProviders/${sid}/PredefinedCarriers/7d509a18-bbff-4c5d-b21e-b99bf8f8c49a`, {
auth: authAdmin,