This repository was archived by the owner on Sep 11, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 823
Device manager - parse user agent for device information #9352
Merged
Merged
Changes from all commits
Commits
Show all changes
37 commits
Select commit
Hold shift + click to select a range
a37682e
record device client inforamtion events on app start
94b027b
matrix-client-information -> matrix_client_information
593465a
fix types
3f616af
Merge branch 'develop' into psg-633/save-device-client-info
c858656
remove another unused export
950f61c
add docs link
fb95964
Merge branch 'develop' into psg-633/save-device-client-info
258d364
display device client information in device details
a3cf263
update snapshots
d316ec6
integration-ish test client information in metadata
f24e983
tests
e79934f
fix tests
9e86e9e
export helper
ad81d2c
DeviceClientInformation type
b97ff34
Merge branch 'develop' into psg-682/display-client-info
d1e3b73
Merge branch 'develop' into psg-682/display-client-info
0e273d9
Device manager - select all devices (#9330)
ae76c77
rename type
295c6d7
use ExtendedDevice type everywhere
b733f61
rename clientName to appName for less collision with UA parser
605019c
fix bad find and replace
0bec4bd
Merge branch 'psg-632/device-man-type-shuffle' into psg-632/device-ma…
b8c3ea1
rename ExtendedDeviceInfo to ExtendedDeviceAppInfo
a01c3ca
Merge branch 'psg-632/device-man-type-shuffle' into psg-632/device-ma…
2569c0c
rename DeviceType comp to DeviceTypeIcon
82dbfb6
update tests for new required property deviceType
b10c197
add stubbed user agent parsing
680fb21
Merge branch 'develop' into psg-682/display-client-info
eef014a
Merge branch 'psg-682/display-client-info' into psg-632/device-man-pa…
a7a878a
setup test cases
7f82b8f
detect device type correctly
f942ab8
80% working ua parser
6766985
Merge branch 'develop' into psg-632/device-man-parse-ua
ebf3da9
Merge branch 'psg-632/device-man-parse-ua' into psg-632/dm-ua-parser-…
83d2f93
parse asera gents for device info
4b5fa8e
combine clientName/Version into one field, remove debug from tests
16c292e
Merge branch 'develop' into psg-632/dm-ua-parser-bowser
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
|
@@ -14,12 +14,132 @@ See the License for the specific language governing permissions and | |
limitations under the License. | ||
*/ | ||
|
||
import { DeviceType, parseUserAgent } from "../../../src/utils/device/parseUserAgent"; | ||
import { DeviceType, ExtendedDeviceInformation, parseUserAgent } from "../../../src/utils/device/parseUserAgent"; | ||
|
||
const makeDeviceExtendedInfo = ( | ||
deviceType: DeviceType, | ||
deviceModel?: string, | ||
deviceOperatingSystem?: string, | ||
clientName?: string, | ||
clientVersion?: string, | ||
): ExtendedDeviceInformation => ({ | ||
deviceType, | ||
deviceModel, | ||
deviceOperatingSystem, | ||
client: clientName && [clientName, clientVersion].filter(Boolean).join(' '), | ||
}); | ||
|
||
/* eslint-disable max-len */ | ||
const ANDROID_UA = [ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. test data taken from android test suite https://github.com/vector-im/element-android/pull/7247/files |
||
// New User Agent Implementation | ||
"Element dbg/1.5.0-dev (Xiaomi Mi 9T; Android 11; RKQ1.200826.002 test-keys; Flavour GooglePlay; MatrixAndroidSdk2 1.5.2)", | ||
"Element/1.5.0 (Samsung SM-G960F; Android 6.0.1; RKQ1.200826.002; Flavour FDroid; MatrixAndroidSdk2 1.5.2)", | ||
"Element/1.5.0 (Google Nexus 5; Android 7.0; RKQ1.200826.002 test test; Flavour FDroid; MatrixAndroidSdk2 1.5.2)", | ||
"Element/1.5.0 (Google (Nexus) 5; Android 7.0; RKQ1.200826.002 test test; Flavour FDroid; MatrixAndroidSdk2 1.5.2)", | ||
"Element/1.5.0 (Google (Nexus) (5); Android 7.0; RKQ1.200826.002 test test; Flavour FDroid; MatrixAndroidSdk2 1.5.2)", | ||
// Legacy User Agent Implementation | ||
"Element/1.0.0 (Linux; U; Android 6.0.1; SM-A510F Build/MMB29; Flavour GPlay; MatrixAndroidSdk2 1.0)", | ||
"Element/1.0.0 (Linux; Android 7.0; SM-G610M Build/NRD90M; Flavour GPlay; MatrixAndroidSdk2 1.0)", | ||
]; | ||
|
||
const ANDROID_EXPECTED_RESULT = [ | ||
makeDeviceExtendedInfo(DeviceType.Mobile, "Xiaomi Mi 9T", "Android 11"), | ||
makeDeviceExtendedInfo(DeviceType.Mobile, "Samsung SM-G960F", "Android 6.0.1"), | ||
makeDeviceExtendedInfo(DeviceType.Mobile, "LG Nexus 5", "Android 7.0"), | ||
makeDeviceExtendedInfo(DeviceType.Mobile, "Google (Nexus) 5", "Android 7.0"), | ||
makeDeviceExtendedInfo(DeviceType.Mobile, "Google (Nexus) (5)", "Android 7.0"), | ||
makeDeviceExtendedInfo(DeviceType.Mobile, "Samsung SM-A510F", "Android 6.0.1"), | ||
makeDeviceExtendedInfo(DeviceType.Mobile, "Samsung SM-G610M", "Android 7.0"), | ||
]; | ||
|
||
const IOS_UA = [ | ||
"Element/1.8.21 (iPhone; iOS 15.2; Scale/3.00)", | ||
"Element/1.8.21 (iPhone XS Max; iOS 15.2; Scale/3.00)", | ||
"Element/1.8.21 (iPad Pro (11-inch); iOS 15.2; Scale/3.00)", | ||
"Element/1.8.21 (iPad Pro (12.9-inch) (3rd generation); iOS 15.2; Scale/3.00)", | ||
]; | ||
const IOS_EXPECTED_RESULT = [ | ||
makeDeviceExtendedInfo(DeviceType.Mobile, "Apple iPhone", "iOS 15.2"), | ||
makeDeviceExtendedInfo(DeviceType.Mobile, "Apple iPhone XS Max", "iOS 15.2"), | ||
makeDeviceExtendedInfo(DeviceType.Mobile, "iPad Pro (11-inch)", "iOS 15.2"), | ||
makeDeviceExtendedInfo(DeviceType.Mobile, "iPad Pro (12.9-inch) (3rd generation)", "iOS 15.2"), | ||
]; | ||
const DESKTOP_UA = [ | ||
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) ElementNightly/2022091301 Chrome/104.0.5112.102" + | ||
" Electron/20.1.1 Safari/537.36", | ||
"Mozilla/5.0 (Windows NT 10.0) AppleWebKit/537.36 (KHTML, like Gecko) ElementNightly/2022091301 Chrome/104.0.5112.102 Electron/20.1.1 Safari/537.36", | ||
]; | ||
const DESKTOP_EXPECTED_RESULT = [ | ||
makeDeviceExtendedInfo(DeviceType.Desktop, undefined, "Mac OS 10.15.7", "Electron", "20"), | ||
makeDeviceExtendedInfo(DeviceType.Desktop, undefined, "Windows 10", "Electron", "20"), | ||
]; | ||
|
||
const WEB_UA = [ | ||
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.5112.102 Safari/537.36", | ||
"Mozilla/5.0 (Windows NT 10.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.5112.102 Safari/537.36", | ||
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:39.0) Gecko/20100101 Firefox/39.0", | ||
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_2) AppleWebKit/600.3.18 (KHTML, like Gecko) Version/8.0.3 Safari/600.3.18", | ||
"Mozilla/5.0 (Windows NT 6.0; rv:40.0) Gecko/20100101 Firefox/40.0", | ||
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36 Edge/12.246", | ||
// using mobile browser | ||
"Mozilla/5.0 (iPad; CPU OS 8_4_1 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Version/8.0 Mobile/12H321 Safari/600.1.4", | ||
"Mozilla/5.0 (iPhone; CPU iPhone OS 8_4_1 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Version/8.0 Mobile/12H321 Safari/600.1.4", | ||
"Mozilla/5.0 (Linux; Android 9; SM-G973U Build/PPR1.180610.011) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Mobile Safari/537.36", | ||
]; | ||
|
||
const WEB_EXPECTED_RESULT = [ | ||
makeDeviceExtendedInfo(DeviceType.Web, undefined, "Mac OS 10.15.7", "Chrome", "104"), | ||
makeDeviceExtendedInfo(DeviceType.Web, undefined, "Windows 10", "Chrome", "104"), | ||
makeDeviceExtendedInfo(DeviceType.Web, undefined, "Mac OS 10.10", "Firefox", "39"), | ||
makeDeviceExtendedInfo(DeviceType.Web, undefined, "Mac OS 10.10.2", "Safari", "8"), | ||
makeDeviceExtendedInfo(DeviceType.Web, undefined, "Windows Vista", "Firefox", "40"), | ||
makeDeviceExtendedInfo(DeviceType.Web, undefined, "Windows 10", "Edge", "12"), | ||
// using mobile browser | ||
makeDeviceExtendedInfo(DeviceType.Web, "Apple iPad", "iOS 8.4.1", "Mobile Safari", "8"), | ||
makeDeviceExtendedInfo(DeviceType.Web, "Apple iPhone", "iOS 8.4.1", "Mobile Safari", "8"), | ||
makeDeviceExtendedInfo(DeviceType.Web, "Samsung SM-G973U", "Android 9", "Chrome", "69"), | ||
|
||
]; | ||
|
||
const MISC_UA = [ | ||
"AppleTV11,1/11.1", | ||
"Curl Client/1.0", | ||
"banana", | ||
"", | ||
]; | ||
|
||
const MISC_EXPECTED_RESULT = [ | ||
makeDeviceExtendedInfo(DeviceType.Unknown, "Apple Apple TV", undefined, undefined, undefined), | ||
makeDeviceExtendedInfo(DeviceType.Unknown, undefined, undefined, undefined, undefined), | ||
makeDeviceExtendedInfo(DeviceType.Unknown, undefined, undefined, undefined, undefined), | ||
makeDeviceExtendedInfo(DeviceType.Unknown, undefined, undefined, undefined, undefined), | ||
]; | ||
/* eslint-disable max-len */ | ||
|
||
describe('parseUserAgent()', () => { | ||
it('returns deviceType unknown when user agent is falsy', () => { | ||
expect(parseUserAgent(undefined)).toEqual({ | ||
deviceType: DeviceType.Unknown, | ||
}); | ||
}); | ||
|
||
type TestCase = [string, ExtendedDeviceInformation]; | ||
|
||
const testPlatform = (platform: string, userAgents: string[], results: ExtendedDeviceInformation[]): void => { | ||
const testCases: TestCase[] = userAgents.map((userAgent, index) => [userAgent, results[index]]); | ||
|
||
describe(platform, () => { | ||
it.each( | ||
testCases, | ||
)('Parses user agent correctly - %s', (userAgent, expectedResult) => { | ||
expect(parseUserAgent(userAgent)).toEqual(expectedResult); | ||
}); | ||
}); | ||
}; | ||
|
||
testPlatform('Android', ANDROID_UA, ANDROID_EXPECTED_RESULT); | ||
testPlatform('iOS', IOS_UA, IOS_EXPECTED_RESULT); | ||
testPlatform('Desktop', DESKTOP_UA, DESKTOP_EXPECTED_RESULT); | ||
testPlatform('Web', WEB_UA, WEB_EXPECTED_RESULT); | ||
testPlatform('Misc', MISC_UA, MISC_EXPECTED_RESULT); | ||
}); |
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.