mirror of
https://github.com/jambonz/jambonz-api-server.git
synced 2025-12-19 05:47:46 +00:00
* initial changes for jwt auth * return permissions as an array of string * Add JWT expiration environment variable (#74) * allow fromHost in createCall REST API * add JWT_EXPIRES_IN=<mins> env variable, 60 mins by default * add jwt expiration in register.js and signin.js * fix tests - add permissions and scope to encoded obj in jwt Co-authored-by: Dave Horton <daveh@beachdognet.com> Co-authored-by: eglehelms <e.helms@cognigy.com> * return only the jwt-token in the api response Co-authored-by: EgleH <egle.helms@gmail.com> Co-authored-by: eglehelms <e.helms@cognigy.com>
86 lines
3.3 KiB
JavaScript
86 lines
3.3 KiB
JavaScript
const test = require('tape');
|
|
const jwt = require('jsonwebtoken');
|
|
const request = require('request-promise-native').defaults({
|
|
baseUrl: 'http://127.0.0.1:3000/v1'
|
|
});
|
|
const consoleLogger = { debug: console.log, info: console.log, error: console.error }
|
|
const {
|
|
createServiceProvider,
|
|
createAccount,
|
|
createGoogleSpeechCredentials,
|
|
getLastRequestFromFeatureServer
|
|
} = require('./utils');
|
|
|
|
test('Create Call Success With Synthesizer in Payload', async (t) => {
|
|
// GIVEN
|
|
const app = require('../app');
|
|
let result;
|
|
const service_provider_sid = await createServiceProvider(request, 'account_has_synthesizer');
|
|
const account_sid = await createAccount(request, service_provider_sid, 'account_has_synthesizer');
|
|
const token = jwt.sign({
|
|
account_sid,
|
|
scope: "account",
|
|
permissions: ["PROVISION_USERS", "PROVISION_SERVICES", "VIEW_ONLY"]
|
|
}, process.env.JWT_SECRET, { expiresIn: '1h' });
|
|
const authUser = { bearer: token };
|
|
const speech_sid = await createGoogleSpeechCredentials(request, account_sid, null, authUser, true, true)
|
|
|
|
// WHEN
|
|
result = await request.post(`/Accounts/${account_sid}/Calls`, {
|
|
resolveWithFullResponse: true,
|
|
auth: authUser,
|
|
json: true,
|
|
body: {
|
|
call_hook: "https://public-apps.jambonz.us/hello-world",
|
|
call_status_hook: "https://public-apps.jambonz.us/call-status",
|
|
from: "15083778299",
|
|
to: {
|
|
type: "phone",
|
|
number: "15089084809"
|
|
},
|
|
speech_synthesis_vendor: "google",
|
|
speech_synthesis_language: "en-US",
|
|
speech_synthesis_voice: "en-US-Standard-C",
|
|
speech_recognizer_vendor: "google",
|
|
speech_recognizer_language: "en-US"
|
|
}
|
|
});
|
|
// THEN
|
|
t.ok(result.statusCode === 201, 'successfully created Call without Synthesizer && application_sid');
|
|
const fs_request = await getLastRequestFromFeatureServer('15083778299_createCall');
|
|
const obj = JSON.parse(fs_request);
|
|
t.ok(obj.body.speech_synthesis_vendor == 'google', 'speech synthesizer successfully added')
|
|
t.ok(obj.body.speech_recognizer_vendor == 'google', 'speech recognizer successfully added')
|
|
});
|
|
|
|
test('Create Call Success Without Synthesizer in Payload', async (t) => {
|
|
// GIVEN
|
|
const app = require('../app');
|
|
let result;
|
|
const service_provider_sid = await createServiceProvider(request, 'account2_has_synthesizer');
|
|
const account_sid = await createAccount(request, service_provider_sid, 'account2_has_synthesizer');
|
|
const token = jwt.sign({
|
|
account_sid,
|
|
scope: "account",
|
|
permissions: ["PROVISION_USERS", "PROVISION_SERVICES", "VIEW_ONLY"]
|
|
}, process.env.JWT_SECRET, { expiresIn: '1h' });
|
|
const authUser = { bearer: token };
|
|
const speech_sid = await createGoogleSpeechCredentials(request, account_sid, null, authUser, true, true)
|
|
|
|
// WHEN
|
|
result = await request.post(`/Accounts/${account_sid}/Calls`, {
|
|
resolveWithFullResponse: true,
|
|
auth: authUser,
|
|
json: true,
|
|
body: {
|
|
call_hook: "https://public-apps.jambonz.us/hello-world",
|
|
call_status_hook: "https://public-apps.jambonz.us/call-status",
|
|
from: "15083778299",
|
|
to: {
|
|
type: "phone",
|
|
number: "15089084809"
|
|
}
|
|
}
|
|
}).then(data => { t.ok(false, 'Create Call should not be success') })
|
|
.catch(error => { t.ok(error.response.statusCode === 400, 'Call failed for no synthesizer') });
|
|
}); |