Skip to content

Commit 0b4175b

Browse files
author
Tim Mendoza
committed
Update tokenserver to ignore spaces in passcode
1 parent a9953d3 commit 0b4175b

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/video-token-server.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ module.exports.handler = (context, event, callback) => {
3434
return;
3535
}
3636

37-
if (API_PASSCODE + appID + serverlessID !== passcode) {
37+
if (API_PASSCODE + appID + serverlessID !== passcode.replace(/\s+/g, '')) {
3838
response.setStatusCode(401);
3939
response.setBody({
4040
error: {

test/video-token-server.test.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,23 @@ describe('the video-token-server', () => {
114114
});
115115
});
116116

117+
it('should ignore spaces in the passcode', () => {
118+
Date.now = () => 5;
119+
handler(
120+
mockContext,
121+
{ passcode: '123 456 1234 5678', room_name: 'test-room', user_identity: 'test-user' },
122+
callback
123+
);
124+
125+
expect(callback).toHaveBeenCalledWith(null, {
126+
body: { token: expect.any(String) },
127+
headers: { 'Content-Type': 'application/json' },
128+
statusCode: 200,
129+
});
130+
131+
expect(jwt.verify(callback.mock.calls[0][1].body.token, 'api_secret')).toBeTruthy();
132+
});
133+
117134
describe('when using an old form URL "video-app-XXXX-dev.twil.io', () => {
118135
it('should return a valid token when passcode, room_name, and user_identity parameters are supplied', () => {
119136
Date.now = () => 5;

0 commit comments

Comments
 (0)