~aleteoryx/muditaos

ref: 266c2085296f7369f7a4c4571e544e31258b4c7b muditaos/test/pytest/service-desktop/test_security.py -rw-r--r-- 4.2 KiB
266c2085 — Wojtek Rzepecki [EGD-6790] Fix cellular sleep mode 4 years ago
                                                                                
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
# For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

import pytest
import time

from harness.interface.defs import status


@pytest.mark.service_desktop_test
@pytest.mark.usefixtures("phone_unlocked")
def test_security_phone_unlocked(harness):
    body = {}

    ret = harness.endpoint_request("deviceInfo", "get", body)
    assert ret["status"] == status["OK"]


@pytest.mark.service_desktop_test
@pytest.mark.usefixtures("phone_locked")
def test_security_phone_locked_with_code(harness):
    body = {}

    ret = harness.endpoint_request("usbSecurity", "get", body)
    assert ret["status"] == status["Forbidden"]


@pytest.mark.service_desktop_test
@pytest.mark.usefixtures("phone_locked")
def test_all_other_endpoints_phone_locked_with_code(harness):
    body = {}
    endpoints_list = ["deviceInfo",
                      "update",
                      "filesystemUpload",
                      "backup",
                      "restore",
                      "factory",
                      "contacts",
                      "messages",
                      "calllog",
                      "events",
                      "bluetooth"]
    for endpoint_name in endpoints_list:
        print(endpoint_name)
        ret = harness.endpoint_request(endpoint_name, "get", body)
        assert ret["status"] == status["Forbidden"]

        ret = harness.endpoint_request(endpoint_name, "post", body)
        assert ret["status"] == status["Forbidden"]

        ret = harness.endpoint_request(endpoint_name, "put", body)
        assert ret["status"] == status["Forbidden"]

        ret = harness.endpoint_request(endpoint_name, "del", body)
        assert ret["status"] == status["Forbidden"]

    body = {"getInfo": "simState"}
    ret = harness.endpoint_request("developerMode", "get", body)
    assert ret["status"] == status["OK"]


@pytest.mark.service_desktop_test
@pytest.mark.usefixtures("phone_locked")
def test_security_phone_locked_without_code(harness):

    body = {"phoneLockCodeEnabled": False}
    ret = harness.endpoint_request("developerMode", "put", body)
    assert ret["status"] == status["OK"]

    time.sleep(.1)

    body = {}
    ret = harness.endpoint_request("usbSecurity", "get", body)
    assert ret["status"] == status["OK"]

    body = {"phoneLockCodeEnabled": True}
    ret = harness.endpoint_request("developerMode", "put", body)
    assert ret["status"] == status["OK"]

    harness.lock_phone()
    time.sleep(.1)

    body = {}
    ret = harness.endpoint_request("usbSecurity", "get", body)
    assert ret["status"] == status["Forbidden"]


@pytest.mark.service_desktop_test
@pytest.mark.usefixtures("phone_locked")
def test_security_unlock_phone(harness):

    """
    Attempt unlocking with wrong passcode: 1111
    Assuming 1111 is not the actual passcode :-)
    """
    body = {"phoneLockCode": [1, 1, 1, 1]}
    ret = harness.endpoint_request("usbSecurity", "put", body)
    assert ret["status"] == status["OK"]

    time.sleep(.1)

    body = {}
    ret = harness.endpoint_request("usbSecurity", "get", body)
    assert ret["status"] == status["Forbidden"]

    time.sleep(.1)

    body = {"phoneLockCode": ['a', 'a', 'a', 'a']}
    ret = harness.endpoint_request("usbSecurity", "put", body)
    assert ret["status"] == status["BadRequest"]

    time.sleep(.1)

    body = {}
    ret = harness.endpoint_request("usbSecurity", "get", body)
    assert ret["status"] == status["Forbidden"]

    time.sleep(.1)

    """
    Attempt unlocking with too short passcode: 1
    """
    body = {"phoneLockCode": [1]}
    ret = harness.endpoint_request("usbSecurity", "put", body)
    assert ret["status"] == status["BadRequest"]

    time.sleep(.1)

    body = {}
    ret = harness.endpoint_request("usbSecurity", "get", body)
    assert ret["status"] == status["Forbidden"]

    time.sleep(.1)

    """
    Attempt unlocking with correct passcode: 3333
    Assuming 3333 is the actual passcode :-)
    """
    body = {"phoneLockCode": [3, 3, 3, 3]}
    ret = harness.endpoint_request("usbSecurity", "put", body)
    assert ret["status"] == status["OK"]

    time.sleep(.1)

    body = {}
    ret = harness.endpoint_request("deviceInfo", "get", body)
    assert ret["status"] == status["OK"]