Skip to content

Commit

Permalink
update fixtures
Browse files Browse the repository at this point in the history
  • Loading branch information
sanchezzzhak committed Mar 22, 2024
1 parent 417466a commit a91fa12
Show file tree
Hide file tree
Showing 18 changed files with 869 additions and 11,016 deletions.
4 changes: 0 additions & 4 deletions parser/client/browser-short.js
Original file line number Diff line number Diff line change
Expand Up @@ -601,8 +601,4 @@ module.exports = {
'ZV': 'Zvu',
'ZI': 'Zirco Browser',
'ZR': 'Zordo Browser',
// detected browsers in older versions
// 'IA': 'Iceape', => pim
// 'SM': 'SeaMonkey', => pim

};
56 changes: 32 additions & 24 deletions parser/os-abstract-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,20 @@ const CLIENTHINT_MAPPING = {
'Mac': ['MacOS']
};

const FIREOS_VERSION_MAPPING = {
'11': '8',
'10': '8',
'9': '7',
'7': '6',
'5': '5',
'4.4.3': '4.5.1',
'4.4.2': '4',
'4.2.2': '3',
'4.0.3': '3',
'4.0.2': '3',
'4': '2',
'2': '1'
};
const FIRE_OS_VERSION_MAPPING = require('./os/fire-os-version-map');
const LINEAGE_OS_VERSION_MAPPING = require('./os/lineage-os-version-map');


const getVersionForMapping = (version, map) => {
const majorVersion = ~~version.split('.', 1)[0];
if (map[version]) {
return map[version];
}
if (map[majorVersion]) {
return map[majorVersion];
}
return '';
}

const compareOsForClientHints = (brand) => {
for (let mapName in CLIENTHINT_MAPPING) {
Expand Down Expand Up @@ -233,13 +233,8 @@ class OsAbstractParser extends ParserAbstract {
}

if (data && data.name === 'Fire OS') {
let majorVersion = ~~version.split('.', 1)[0];
short = data.short_name;
if (FIREOS_VERSION_MAPPING[version]) {
version = FIREOS_VERSION_MAPPING[version];
} else if (FIREOS_VERSION_MAPPING[majorVersion]) {
version = FIREOS_VERSION_MAPPING[majorVersion];
}
version = getVersionForMapping(version, FIRE_OS_VERSION_MAPPING);
}

if ('GNU/Linux' === name
Expand All @@ -252,19 +247,32 @@ class OsAbstractParser extends ParserAbstract {
}

family = this.parseOsFamily(short);
} else if (data && data.name) {
name = data.name;
version = data.version;
short = data.short_name;
platform = data.platform;
family = data.family;
}

if (clientHints && data && clientHints.app) {
if (ANDROID_APP_LIST.indexOf(clientHints.app) !== -1 && data.name !== 'Android') {
name = 'Android';
short = 'ADR';
family = 'Android';
version = '';
}
if (clientHints.app === 'org.mozilla.tv.firefox' && name !== 'Fire OS') {
name = 'Fire OS';
family = 'Android';
short = 'FIR';
version = getVersionForMapping(version, FIRE_OS_VERSION_MAPPING);
}
if (clientHints.app === 'org.lineageos.jelly' && name !== 'Lineage OS') {
name = 'Lineage OS';
family = 'Android';
short = 'LEN';
version = '';
name = 'Lineage OS';
family = 'Android';
short = 'LEN';
version = getVersionForMapping(data.version, LINEAGE_OS_VERSION_MAPPING);
}
}

Expand Down
16 changes: 16 additions & 0 deletions parser/os/fire-os-version-map.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// prettier-ignore
module.exports = {
'11': '8',
'10': '8',
'9': '7',
'7': '6',
'5': '5',
'4.4.3': '4.5.1',
'4.4.2': '4',
'4.2.2': '3',
'4.0.3': '3',
'4.0.2': '3',
'4': '2',
'2': '1',

};
25 changes: 25 additions & 0 deletions parser/os/lineage-os-version-map.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// prettier-ignore
module.exports = {
'14': '21.0',
'13': '20.0',
'12.1': '19.1',
'12': '19.0',
'11': '18.0',
'10': '17.0',
'9': '16.0',
'8.1.0': '15.1',
'8.0.0': '15.0',
'7.1.2': '14.1',
'7.1.1': '14.1',
'7.0': '14.0',
'6.0.1': '13.0',
'6.0': '13.0',
'5.1.1': '12.1',
'5.0.2': '12.0',
'5.0': '12.0',
'4.4.4': '11.0',
'4.3': '10.2',
'4.2.2': '10.1',
'4.0.4': '9.1.0',

};
2 changes: 1 addition & 1 deletion parser/os/os_families.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ module.exports = {
'LOS', 'DVK', 'ROK', 'OWR', 'OTV', 'KTV', 'PUR', 'PLA', 'FUC', 'PAR',
'FOR', 'MON', 'KAN', 'ZEN', 'LND', 'LNS', 'CHN', 'AMZ', 'TEN', 'CST',
'NOV', 'ROU', 'ZOR', 'RED', 'KAL', 'ORA', 'VID', 'TIV', 'BSN', 'RAS',
'UOS', 'PIO', 'FRI', 'LIR', 'WEB',
'UOS', 'PIO', 'FRI', 'LIR', 'WEB', 'SER', 'ASP',
],
'Mac': ['MAC'],
'Mobile Gaming Console': ['PSP', 'NDS', 'XBX'],
Expand Down
2 changes: 2 additions & 0 deletions parser/os/os_systems.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module.exports = {
'ARM': 'Armadillo OS',
'ATV': 'tvOS',
'ARL': 'Arch Linux',
'ASP': 'ASPLinux',
'BTR': 'BackTrack',
'SBA': 'Bada',
'BEO': 'BeOS',
Expand Down Expand Up @@ -112,6 +113,7 @@ module.exports = {
'SSE': 'SUSE',
'SAF': 'Sailfish OS',
'SEE': 'SeewoOS',
'SER': 'SerenityOS',
'SIR': 'Sirin OS',
'SLW': 'Slackware',
'SOS': 'Solaris',
Expand Down
1 change: 1 addition & 0 deletions regexes/client/hints/browsers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
'phx.hot.browser': 'Anka Browser'
'com.anka.browser': 'Anka Browser'
'org.mozilla.focus': 'Firefox Focus'
'org.mozilla.tv.firefox': 'Firefox Focus'
'com.vivaldi.browser': 'Vivaldi'
'web.browser.dragon': 'Dragon Browser'
'org.easyweb.browser': 'Easy Browser'
Expand Down
41 changes: 32 additions & 9 deletions regexes/oss.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@
# @license http://www.gnu.org/licenses/lgpl.html LGPL v3 or later
###############

##########
# SerenityOS (https://github.com/SerenityOS/serenity)
##########
- regex: 'SerenityOS|Ladybird/'
name: 'SerenityOS'
version: ''

##########
# HELIX OS (https://www.pegasusintelligence.com/communication-security/)
##########
Expand Down Expand Up @@ -380,25 +387,41 @@
name: 'Lineage OS'
versions:
- regex: 'Android 14'
version: '21'
version: '21.0'
- regex: 'Android 13'
version: '20'
version: '20.0'
- regex: 'Android 12\.1'
version: '19.1'
- regex: 'Android 12'
version: '19'
version: '19.0'
- regex: 'Android 11'
version: '18'
version: '18.0'
- regex: 'Android 10'
version: '17'
version: '17.0'
- regex: 'Android 9'
version: '16'
version: '16.0'
- regex: 'Android 8\.1'
version: '15.1'
- regex: 'Android 8'
version: '15.0'
- regex: 'Android 7\.1'
version: '14.1'
- regex: 'Android 7'
version: '14.0'
- regex: 'Android 6'
version: '13'
version: '13.0'
- regex: 'Android 5\.1'
version: '12.1'
- regex: 'Android 5'
version: '12.0'
- regex: 'Android 4\.4'
version: '11.0'
- regex: 'Android 4\.3'
version: '10.2'
- regex: 'Android 4\.2'
version: '10.1'
- regex: 'Android 4'
version: '9.1.0'

#########
# Resurrection Remix OS (https://resurrectionremix.com/)
Expand Down Expand Up @@ -772,7 +795,7 @@
name: 'Deepin'
version: '$1'

- regex: '(Debian|Knoppix|Mint(?! Browser)|Ubuntu|Kubuntu|Xubuntu|Lubuntu|Fedora|Red Hat|Mandriva|Gentoo|Sabayon|Slackware|SUSE|CentOS|BackTrack|Freebox)(?:(?: Enterprise)? Linux)?(?:[ /\-](\d+[\.\d]+))?'
- regex: '(Debian|Knoppix|Mint(?! Browser)|Ubuntu|Kubuntu|Xubuntu|Lubuntu|Fedora|Red Hat|Mandriva|Gentoo|Sabayon|Slackware|SUSE|CentOS|BackTrack|Freebox|ASPLinux)(?:(?: Enterprise)? Linux)?(?:[ /\-](\d+[\.\d]+))?'
name: '$1'
version: '$2'

Expand Down Expand Up @@ -925,7 +948,7 @@
name: 'tvOS'
version: '$1'

- regex: 'tvOS((?:9|1[0-7])\.\d+(?:[_\.]\d+)*);'
- regex: 'tvOS[ /]?((?:9|1[0-7])\.\d+(?:[_\.]\d+)*);?'
name: 'tvOS'
version: '$1'

Expand Down
35 changes: 17 additions & 18 deletions tests/client.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,52 +37,51 @@ describe('tests clients', function () {
it(pos + '/' + total, function () {
let clientHintData = clientHint.parse(fixture.headers || {});
let fixtureClientType = fixture.client.type ?? '';
let cleint = {};
let client = {};

switch (fixtureClientType) {
case CLIENT_TYPE.LIBRARY:
cleint = detector.getParseClient(CLIENT_PARSER.LIBRARY).parse(fixture.user_agent, clientHintData)
client = detector.getParseClient(CLIENT_PARSER.LIBRARY).parse(fixture.user_agent, clientHintData)
break;
case CLIENT_TYPE.BROWSER:
cleint = detector.getParseClient(CLIENT_PARSER.BROWSER).parse(fixture.user_agent, clientHintData)
client = detector.getParseClient(CLIENT_PARSER.BROWSER).parse(fixture.user_agent, clientHintData)
break;
default:
cleint = detector.detect(fixture.user_agent, clientHintData).client;
client = detector.detect(fixture.user_agent, clientHintData).client;
break;
}

let messageError = 'fixture data\n' + perryJSON(fixture);
perryTable(fixture, cleint);

perryTable(fixture, client);

// fix values fixture null
if (cleint.version === '' && fixture.client.version === null) {
cleint.version = fixture.client.version;
if (client.version === '' && fixture.client.version === null) {
client.version = fixture.client.version;
}

if (!cleint.engine_version && fixture.client.engine_version === null) {
cleint.engine_version = fixture.client.engine_version;
if (!client.engine_version && fixture.client.engine_version === null) {
client.engine_version = fixture.client.engine_version;
}

if (!cleint.engine && fixture.client.engine === null) {
cleint.engine = fixture.client.engine;
if (!client.engine && fixture.client.engine === null) {
client.engine = fixture.client.engine;
}

// fix version fixture
if (fixture.client.version !== null && typeof fixture.client.version === 'number') {
fixture.version = String(fixture.client.version);
if (fixture.client.version !== null && Number.isFinite(fixture.client.version)) {
fixture.client.version = '' + fixture.client.version;
}

if (cleint.short_name) {
expect(cleint.short_name, messageError).to.not.equal('UNK');
delete cleint.short_name;
if (client.short_name) {
expect(client.short_name, messageError).to.not.equal('UNK');
delete client.short_name;
}

if (fixture.client && fixture.client.family === null) {
fixture.client.family = '';
}

expect(fixture.client, messageError).to.deep.equal(cleint);
expect(fixture.client, messageError).to.deep.equal(client);
});
});
});
Expand Down
11 changes: 11 additions & 0 deletions tests/fixtures/clients/browser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9023,3 +9023,14 @@
engine: WebKit
engine_version: 605.1.15
family:
-
user_agent: Mozilla/5.0 (Linux; Android 11) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Focus/4.5 Chrome/83.0.4103.120 Safari/537.36
client:
type: browser
name: Firefox Focus
version: "4.5"
engine: Blink
engine_version: 83.0.4103.120
family:
headers:
http-x-requested-with: org.mozilla.tv.firefox
10 changes: 5 additions & 5 deletions tests/fixtures/clients/mediaplayer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -166,19 +166,19 @@
client:
type: mediaplayer
name: SONOS
version: "61.1"
version: 61.1
-
user_agent: Linux UPnP/1.0 Sonos/57.4-83220 (ZP120)
client:
type: mediaplayer
name: SONOS
version: "57.4"
version: 57.4
-
user_agent: Linux UPnP/1.0 Sonos/61.1-83220 (ZPS3)
client:
type: mediaplayer
name: SONOS
version: "61.1"
version: 61.1
-
user_agent: HTC Streaming Player htc / 1.0 / o2_de / 4.2.2
client:
Expand All @@ -202,7 +202,7 @@
client:
type: mediaplayer
name: JHelioviewer
version: "4.4.2.10777"
version: 4.4.2.10777
-
user_agent: com.devcoder.iptvxtreamplayer/111 (Linux; U; Android 12; en; Philips Google TV TA1; Build/STT2.220929.001; Cronet/114.0.5735.33)
client:
Expand All @@ -220,7 +220,7 @@
client:
type: mediaplayer
name: DIGA
version: "1.0.0"
version: 1.0.0
-
user_agent: Mozilla/5.0 (Linux armv7l) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.153 Safari/537.36 OPR/22.0.1481.0 OMI/4.2.12.48.ALSAN3.97 HbbTV/1.1.1 (; Sony; N/A; v1.000; 2015;) sony.hbbtv.tv.2015HE YouView
client:
Expand Down
Loading

0 comments on commit a91fa12

Please sign in to comment.