Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: make call token extraction more robust #6253

Merged
merged 1 commit into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/services/talkService.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
logger.debug('Event\'s conference/location is from another host', url)
return
}
const token = url.match(/\/call\/([a-z0-9]*)$/)[1]
const token = extractCallTokenFromUrl(url)

Check warning on line 56 in src/services/talkService.js

View check run for this annotation

Codecov / codecov/patch

src/services/talkService.js#L56

Added line #L56 was not covered by tests
if (!token) {
logger.debug('URL ' + url + ' contains no call token')
return
Expand Down Expand Up @@ -129,3 +129,13 @@
function generateURLForToken(token = '') {
return window.location.protocol + '//' + window.location.host + generateUrl('/call/' + token)
}

/**
* Extract a spreed call token from the given URL
*
* @param {string} callUrl URL of the spreed call
* @return {string|undefined} Matched token or undefined if URL is invalid
*/
export function extractCallTokenFromUrl(callUrl) {
return callUrl.match(/\/call\/([a-z0-9]*)(\/|#.*)?$/)?.[1] ?? undefined
}
21 changes: 21 additions & 0 deletions tests/javascript/unit/services/talkService.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

import { extractCallTokenFromUrl } from '../../../../src/services/talkService'

describe('services/talk test suite', () => {
test.each([
['https://foo.bar/call/123abc456', '123abc456'],
['https://foo.bar/call/123abc456/', '123abc456'],
['https://foo.bar/call/123abc456/baz', undefined],
['https://foo.bar/call/123abc456#', '123abc456'],
['https://foo.bar/call/123abc456#/', '123abc456'],
['https://foo.bar/call/123abc456#message_3074226', '123abc456'],
['https://foo.bar/baz', undefined],
['https://foo.bar/baz/bar', undefined],
])('should extract a token from call url %s', (url, expected) => {
expect(extractCallTokenFromUrl(url)).toBe(expected)
})
})
Loading