aboutsummaryrefslogtreecommitdiffstats
path: root/packages/main/src/infrastructure/electron/__tests__/UserAgents.test.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/main/src/infrastructure/electron/__tests__/UserAgents.test.ts')
-rw-r--r--packages/main/src/infrastructure/electron/__tests__/UserAgents.test.ts57
1 files changed, 57 insertions, 0 deletions
diff --git a/packages/main/src/infrastructure/electron/__tests__/UserAgents.test.ts b/packages/main/src/infrastructure/electron/__tests__/UserAgents.test.ts
new file mode 100644
index 0000000..0c6dd1c
--- /dev/null
+++ b/packages/main/src/infrastructure/electron/__tests__/UserAgents.test.ts
@@ -0,0 +1,57 @@
1/*
2 * Copyright (C) 2022 Kristóf Marussy <kristof@marussy.com>
3 *
4 * This file is part of Sophie.
5 *
6 * Sophie is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Affero General Public License as
8 * published by the Free Software Foundation, version 3.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Affero General Public License for more details.
14 *
15 * You should have received a copy of the GNU Affero General Public License
16 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17 *
18 * SPDX-License-Identifier: AGPL-3.0-only
19 */
20
21import UserAgents from '../UserAgents.js';
22
23let userAgents: UserAgents;
24
25beforeEach(() => {
26 userAgents = new UserAgents(
27 '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',
28 );
29});
30
31test('removes Electron from the user agent outside dev mode', () => {
32 expect(userAgents.fallbackUserAgent(false)).toBe(
33 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.5005.27 Safari/537.36',
34 );
35});
36
37test('does not remove Electron from the user agent in dev mode', () => {
38 expect(userAgents.fallbackUserAgent(true)).toBe(
39 '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',
40 );
41});
42
43test('displays the Chrome version for services', () => {
44 expect(userAgents.serviceUserAgent('https://example.org')).toBe(
45 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.5005.27 Safari/537.36',
46 );
47});
48
49test('does not display the Chrome version when loggin in to Google', () => {
50 expect(
51 userAgents.serviceUserAgent(
52 'https://accounts.google.com/signin/v2/identifier',
53 ),
54 ).toBe(
55 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Safari/537.36',
56 );
57});