Skip to content

Commit 45ef841

Browse files
author
timmydoza
authored
Merge pull request #12 from twilio-labs/validate-identity-parameter
Add verification for user_identity parameter
2 parents 4202885 + 848aaa5 commit 45ef841

File tree

4 files changed

+53
-6
lines changed

4 files changed

+53
-6
lines changed

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# @twilio-labs/plugin-rtc
22

3+
![npm](https://img.shields.io/npm/v/@twilio-labs/plugin-rtc)
34
[![CircleCI](https://circleci.com/gh/twilio-labs/plugin-rtc.svg?style=svg)](https://circleci.com/gh/twilio-labs/plugin-rtc)
45

56
This plugin adds functionality to the [Twilio CLI](https://github.com/twilio/twilio-cli) which supports developing and deploying real-time communication apps.
@@ -113,6 +114,22 @@ POST /token
113114
<td> <b>Status</b> </td> <td> <b>Response</b> </td>
114115
</tr>
115116

117+
<tr>
118+
<td> 400 </td>
119+
<td>
120+
121+
```json
122+
{
123+
"error": {
124+
"message": "missing user_identity",
125+
"explanation": "The user_identity parameter is missing."
126+
}
127+
}
128+
```
129+
130+
</td>
131+
</tr>
132+
116133
<tr>
117134
<td> 401 </td>
118135
<td>

package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,15 @@
66
"publishConfig": {
77
"access": "public"
88
},
9-
"repository": "twilio-labs/plugin-rtc",
9+
"repository": "https://github.com/twilio-labs/plugin-rtc",
1010
"scripts": {
1111
"test": "TZ=utc jest",
1212
"postpack": "rm -f oclif.manifest.json",
1313
"prepack": "oclif-dev manifest && oclif-dev readme",
14-
"version": "oclif-dev readme && git add README.md",
1514
"lint": "eslint .",
1615
"posttest": "npm run lint"
1716
},
18-
"author": "",
17+
"author": "Twilio",
1918
"license": "Apache-2.0",
2019
"dependencies": {
2120
"@oclif/command": "^1.5.19",

src/video-token-server.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,18 @@ module.exports.handler = (context, event, callback) => {
4646
return;
4747
}
4848

49+
if (!user_identity) {
50+
response.setStatusCode(400);
51+
response.setBody({
52+
error: {
53+
message: 'missing user_identity',
54+
explanation: 'The user_identity parameter is missing.',
55+
},
56+
});
57+
callback(null, response);
58+
return;
59+
}
60+
4961
const token = new AccessToken(TWILIO_ACCOUNT_SID, TWILIO_API_KEY_SID, TWILIO_API_KEY_SECRET, {
5062
ttl: MAX_ALLOWED_SESSION_DURATION,
5163
});

test/video-token-server.test.js

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ describe('the video-token-server', () => {
1616
it('should return an "unauthorized" error when the passcode is incorrect', () => {
1717
Date.now = () => 5;
1818

19-
handler(mockContext, { passcode: '9876543210' }, callback);
19+
handler(mockContext, { passcode: '9876543210', user_identity: 'test identity' }, callback);
2020

2121
expect(callback).toHaveBeenCalledWith(null, {
2222
body: {
@@ -33,7 +33,7 @@ describe('the video-token-server', () => {
3333
it('should return an "expired" error when the current time is past the API_PASSCODE_EXPIRY time', () => {
3434
Date.now = () => 15;
3535

36-
handler(mockContext, { passcode: '1234566789' }, callback);
36+
handler(mockContext, { passcode: '1234566789', user_identity: 'test identity'}, callback);
3737

3838
expect(callback).toHaveBeenCalledWith(null, {
3939
body: {
@@ -48,11 +48,29 @@ describe('the video-token-server', () => {
4848
});
4949
});
5050

51-
it('should return a token when only the passcode is supplied', () => {
51+
it('should return a "missing user_identity" error when the "user_identity" parameter is not supplied', () => {
5252
Date.now = () => 5;
5353

5454
handler(mockContext, { passcode: '1234566789' }, callback);
5555

56+
expect(callback).toHaveBeenCalledWith(null, {
57+
body: {
58+
error: {
59+
message: 'missing user_identity',
60+
explanation:
61+
'The user_identity parameter is missing.',
62+
},
63+
},
64+
headers: { 'Content-Type': 'application/json' },
65+
statusCode: 400,
66+
});
67+
});
68+
69+
it('should return a token when no room_name is supplied', () => {
70+
Date.now = () => 5;
71+
72+
handler(mockContext, { passcode: '1234566789', user_identity: 'test identity' }, callback);
73+
5674
expect(callback).toHaveBeenCalledWith(null, {
5775
body: { token: expect.any(String) },
5876
headers: { 'Content-Type': 'application/json' },
@@ -62,6 +80,7 @@ describe('the video-token-server', () => {
6280
expect(jwt.decode(callback.mock.calls[0][1].body.token)).toEqual({
6381
exp: 14400,
6482
grants: {
83+
identity: "test identity",
6584
video: {},
6685
},
6786
iat: 0,

0 commit comments

Comments
 (0)