-
Notifications
You must be signed in to change notification settings - Fork 168
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
156 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,7 +23,6 @@ var badWebsocketUri = 'service.com/ws-endpoint'; | |
var goodSipUri = 'sip:[email protected]'; | ||
var badSipUri = '[email protected]'; | ||
var defaultApiUrl = 'https://api.opentok.com'; | ||
var defaultTimeoutLength = 20000; // 20 seconds | ||
var recording = false; | ||
|
||
// Helpers | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
const expect = require('chai').expect; | ||
const nock = require('nock'); | ||
const jwt = require('jsonwebtoken'); | ||
const OpenTok = require('../lib/opentok.js'); | ||
|
||
// This is a test key and is not assigned to a real account | ||
// However it can be used to generate JWT tokens | ||
const testPrivateKey = `-----BEGIN PRIVATE KEY----- | ||
MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQCuR/FU8YCqMYj/ | ||
UH/yhAJcu56T7RvN/DqGmR8pnp6AS5LqsUcGW8TB/0at2zxvEVlZ/ubr6X1fAUjm | ||
R2tZcOsigCkw//unWBrS7Ygh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BDULSyUVbJZGytx3zOFGgxA8hKpM0E/sd1VZ5PHyp1z+t | ||
fUqgcWMo0a9MfIl5/NDM99k+iIn12S7KwugBFPWW6eWxMMOmFMEyYPDXAoGAW3Z+ | ||
EPvUWS/YJlKRJs/Xlc8fTXSLIL4cjGHhpqSfla+fif15OxSECDC9tPiMsbGFvPMZ | ||
ssMCL6+1cFQe0/XdZmUosVV3uC2a7T+Ik2bw/7QjdD/ANVKTjyWtGTpgBJiWS1ra | ||
n9HceB9HNbHoGPCeDDOvp7vckcBwd1CGQ18dPkkCgYBwm8eIPoW92dOBvnZrh4WT | ||
UBEEJoSmV7iom93Wt6m6u0Ow54JrhJeDpRH301OMU0V0UD4cQ7S4SxvVsFEjyGiO | ||
thaTVNUBxf1N62zIzUL7t6ItA4+PZVu6ehXyZ/rax7DfhmINjQ3fRGPPLHGd0L1O | ||
8B7ZcGqNJg+6nRv+fTwCjw== | ||
-----END PRIVATE KEY----- | ||
`; | ||
|
||
const validReply = JSON.stringify([ | ||
{ | ||
session_id: 'SESSIONID', | ||
create_dt: 'Fri Nov 18 15:50:36 PST 2016', | ||
media_server_url: '' | ||
} | ||
]); | ||
|
||
describe('when initialized with an applicationId and privatekey', function () { | ||
afterEach(function () { | ||
nock.cleanAll(); | ||
}); | ||
|
||
it('sends its requests to the vonage', (done) => { | ||
const apiKey = '00000000-0000-0000-0000-000000000000'; | ||
const opentok = new OpenTok(apiKey, testPrivateKey); | ||
|
||
const scope = nock('https://video.api.vonage.com') | ||
.matchHeader('authorization', ([value]) => { | ||
const token = `${value}`.replace('Bearer: ', '') | ||
try { | ||
const claims = jwt.verify(token, testPrivateKey) | ||
return claims.iss === apiKey; | ||
} catch (_) { | ||
|
||
} | ||
return false; | ||
}) | ||
.post('/session/create', 'archiveMode=manual&p2p.preference=enabled') | ||
.reply( | ||
200, | ||
validReply, | ||
{ | ||
'content-type': 'application/json', | ||
} | ||
); | ||
|
||
opentok.createSession((err, session) => { | ||
expect(err).to.be.null | ||
scope.done(); | ||
done(err); | ||
}); | ||
}); | ||
|
||
it('uses a custom proxy', function (done) { | ||
const apiKey = '00000000-0000-0000-0000-000000000000'; | ||
const opentok = new OpenTok(apiKey, testPrivateKey, 'https://example.com'); | ||
|
||
const scope = nock('https://example.com') | ||
.matchHeader('authorization', ([value]) => { | ||
const token = `${value}`.replace('Bearer: ', '') | ||
try { | ||
const claims = jwt.verify(token, testPrivateKey) | ||
return claims.iss === apiKey; | ||
} catch (_) { | ||
|
||
} | ||
return false; | ||
}) | ||
.post('/session/create', 'archiveMode=manual&p2p.preference=enabled') | ||
.reply( | ||
200, | ||
validReply, | ||
{ | ||
'content-type': 'application/json', | ||
} | ||
); | ||
|
||
opentok.createSession((err, session) => { | ||
expect(err).to.be.null | ||
scope.done(); | ||
done(err); | ||
}); | ||
}); | ||
}); |