aboutsummaryrefslogtreecommitdiffstats
path: root/packages/main/src/infrastructure/electron/__tests__/UserAgents.test.ts
blob: 0c6dd1ce69dd4d83c5fba86491bb0ba288cbc954 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/*
 * Copyright (C)  2022 Kristóf Marussy <kristof@marussy.com>
 *
 * This file is part of Sophie.
 *
 * Sophie is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, version 3.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 *
 * SPDX-License-Identifier: AGPL-3.0-only
 */

import UserAgents from '../UserAgents.js';

let userAgents: UserAgents;

beforeEach(() => {
  userAgents = new UserAgents(
    'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) sophie/0.1.0 Chrome/102.0.5005.27 Electron/19.0.0-beta.4 Safari/537.36',
  );
});

test('removes Electron from the user agent outside dev mode', () => {
  expect(userAgents.fallbackUserAgent(false)).toBe(
    'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.5005.27 Safari/537.36',
  );
});

test('does not remove Electron from the user agent in dev mode', () => {
  expect(userAgents.fallbackUserAgent(true)).toBe(
    'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) sophie/0.1.0 Chrome/102.0.5005.27 Electron/19.0.0-beta.4 Safari/537.36',
  );
});

test('displays the Chrome version for services', () => {
  expect(userAgents.serviceUserAgent('https://example.org')).toBe(
    'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.5005.27 Safari/537.36',
  );
});

test('does not display the Chrome version when loggin in to Google', () => {
  expect(
    userAgents.serviceUserAgent(
      'https://accounts.google.com/signin/v2/identifier',
    ),
  ).toBe(
    'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Safari/537.36',
  );
});