File: test_clientconfig.py

package info (click to toggle)
python-proton-vpn-api-core 0.39.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 892 kB
  • sloc: python: 6,582; makefile: 8
file content (92 lines) | stat: -rw-r--r-- 3,151 bytes parent folder | download
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
"""
Copyright (c) 2023 Proton AG

This file is part of Proton VPN.

Proton VPN is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

Proton VPN 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 General Public License for more details.

You should have received a copy of the GNU General Public License
along with ProtonVPN.  If not, see <https://www.gnu.org/licenses/>.
"""
import pytest

from proton.vpn.session.exceptions import ClientConfigDecodeError
from proton.vpn.session.session import ClientConfig
import time

EXPIRATION_TIME = time.time()

@pytest.fixture
def apidata():
    return {
        "Code": 1000,
        "DefaultPorts": {
            "OpenVPN": {
                "UDP": [80, 51820, 4569, 1194, 5060],
                "TCP": [443, 7770, 8443]
            },
            "WireGuard": {
                "UDP": [443, 88, 1224, 51820, 500, 4500],
                "TCP": [443],
            }
        },
        "HolesIPs": ["62.112.9.168", "104.245.144.186"],
        "ServerRefreshInterval": 10,
        "FeatureFlags": {
            "NetShield": True,
            "GuestHoles": False,
            "ServerRefresh": True,
            "StreamingServicesLogos": True,
            "PortForwarding": True,
            "ModerateNAT": True,
            "SafeMode": False,
            "StartConnectOnBoot": True,
            "PollNotificationAPI": True,
            "VpnAccelerator": True,
            "SmartReconnect": True,
            "PromoCode": False,
            "WireGuardTls": True,
            "Telemetry": True,
            "NetShieldStats": True
        },
        "SmartProtocol": {
            "OpenVPN": True,
            "IKEv2": True,
            "WireGuard": True,
            "WireGuardTCP": True,
            "WireGuardTLS": True
        },
        "RatingSettings": {
            "EligiblePlans": [],
            "SuccessConnections": 3,
            "DaysLastReviewPassed": 100,
            "DaysConnected": 3,
            "DaysFromFirstConnection": 14
        },
        "ExpirationTime": EXPIRATION_TIME
    }


def test_from_dict(apidata):
    client_config = ClientConfig.from_dict(apidata)

    assert client_config.openvpn_ports.udp == apidata["DefaultPorts"]["OpenVPN"]["UDP"]
    assert client_config.openvpn_ports.tcp == apidata["DefaultPorts"]["OpenVPN"]["TCP"]
    assert client_config.wireguard_ports.udp == apidata["DefaultPorts"]["WireGuard"]["UDP"]
    assert client_config.wireguard_ports.tcp == apidata["DefaultPorts"]["WireGuard"]["TCP"]
    assert client_config.holes_ips == apidata["HolesIPs"]
    assert client_config.server_refresh_interval == apidata["ServerRefreshInterval"]
    assert client_config.expiration_time == EXPIRATION_TIME


def test_from_dict_raises_error_when_dict_does_not_have_expected_keys():
    with pytest.raises(ClientConfigDecodeError):
        ClientConfig.from_dict({})