forked from LedgerHQ/app-openpgp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_menus.py
More file actions
266 lines (238 loc) · 10.4 KB
/
Copy pathtest_menus.py
File metadata and controls
266 lines (238 loc) · 10.4 KB
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
from typing import Sequence
import pytest
from ledgered.devices import Device, DeviceType
from ragger.backend import BackendInterface
from ragger.navigator import Navigator, NavInsID, NavIns
from ragger.navigator.navigator import InstructionType
from application_client.command_sender import CommandSender
from application_client.app_def import PassWord
from utils import check_pincode
from utils import ROOT_SCREENSHOT_PATH
# In this test we check the behavior of the Slot menu
# The Navigations go and check:
# - Select slot / Slot 2 / (next page) / Set default
def test_menu_slot(device: Device, backend: BackendInterface, navigator: Navigator, test_name: str) -> None:
# Use the app interface instead of raw interface
client = CommandSender(backend)
# Check slots availability
nb_slots, def_slot = client.get_slot_config()
print("Slots configuration:")
print(f" Nb: {nb_slots}")
print(f" default: {def_slot}")
if nb_slots == 1:
pytest.skip("single slot configuration")
# Navigate in the main menu
instructions: Sequence[InstructionType]
if device.is_nano:
initial_instructions = [
NavInsID.RIGHT_CLICK,
NavInsID.BOTH_CLICK, # Select slot
]
instructions = [
NavInsID.RIGHT_CLICK,
NavInsID.BOTH_CLICK, # Slot 2
NavInsID.RIGHT_CLICK,
NavInsID.RIGHT_CLICK,
NavInsID.BOTH_CLICK, # (Set as default)
NavInsID.RIGHT_CLICK,
NavInsID.RIGHT_CLICK,
NavInsID.RIGHT_CLICK,
NavInsID.BOTH_CLICK, # (Back)
]
else:
initial_instructions = [
NavInsID.USE_CASE_CHOICE_CONFIRM, # Slots
]
instructions = [
NavIns(NavInsID.TOUCH, (350, 220)), # Slot 2
NavInsID.CENTERED_FOOTER_TAP, # Set default
]
# Navigate to settings menu to avoid 1st screen with random serial no
navigator.navigate(initial_instructions,
screen_change_before_first_instruction=False,
screen_change_after_last_instruction=True)
navigator.navigate_and_compare(ROOT_SCREENSHOT_PATH, test_name, instructions,
screen_change_before_first_instruction=False,
screen_change_after_last_instruction=False)
# In this test we check the behavior of the Setting menus
# The Navigations go and check:
# - Settings / Key Template / Decryption / SECP 256K1 / Confirm
# Seed mode
# (back)
# PIN mode / On Screen / (next page) / Set default
# UIF / Enable UIF for Signature
# (back)
# Reset / Long press 'Yes'
def test_menu_settings(device: Device, backend: BackendInterface, navigator: Navigator, test_name: str) -> None:
# Navigate in the main menu
instructions: Sequence[InstructionType]
if device.type == DeviceType.NANOS:
# Use the app interface instead of raw interface
client = CommandSender(backend)
# Check slots availability
nb_slots, _ = client.get_slot_config()
initial_instructions = []
if nb_slots > 1:
initial_instructions.append(NavInsID.RIGHT_CLICK)
initial_instructions.append(NavInsID.RIGHT_CLICK)
initial_instructions.append(NavInsID.BOTH_CLICK) # Settings
instructions = [
NavInsID.BOTH_CLICK, # Key Template
NavInsID.BOTH_CLICK, # Choose Key
NavInsID.RIGHT_CLICK,
NavInsID.BOTH_CLICK, # Decryption
NavInsID.RIGHT_CLICK,
NavInsID.BOTH_CLICK, # Choose Type
NavInsID.RIGHT_CLICK,
NavInsID.RIGHT_CLICK,
NavInsID.BOTH_CLICK, # NIST P256
NavInsID.RIGHT_CLICK,
NavInsID.BOTH_CLICK, # Set Template
NavInsID.BOTH_CLICK, # OK
NavInsID.RIGHT_CLICK,
NavInsID.RIGHT_CLICK,
NavInsID.RIGHT_CLICK,
NavInsID.BOTH_CLICK, # (Back to settings)
NavInsID.RIGHT_CLICK,
NavInsID.BOTH_CLICK, # Seed mode ON
NavInsID.RIGHT_CLICK,
NavInsID.RIGHT_CLICK,
NavInsID.RIGHT_CLICK,
NavInsID.BOTH_CLICK, # (Back to settings)
NavInsID.RIGHT_CLICK,
NavInsID.RIGHT_CLICK,
NavInsID.BOTH_CLICK, # PIN mode
NavInsID.RIGHT_CLICK,
NavInsID.BOTH_CLICK, # On Screen
NavInsID.RIGHT_CLICK,
NavInsID.RIGHT_CLICK,
NavInsID.RIGHT_CLICK,
NavInsID.BOTH_CLICK, # Set as default
NavInsID.RIGHT_CLICK,
NavInsID.RIGHT_CLICK,
NavInsID.RIGHT_CLICK,
NavInsID.RIGHT_CLICK,
NavInsID.BOTH_CLICK, # (Back to settings)
NavInsID.RIGHT_CLICK,
NavInsID.RIGHT_CLICK,
NavInsID.RIGHT_CLICK,
NavInsID.BOTH_CLICK, # UIF
NavInsID.RIGHT_CLICK,
NavInsID.BOTH_CLICK, # UIF for Signature
NavInsID.RIGHT_CLICK,
NavInsID.RIGHT_CLICK,
NavInsID.RIGHT_CLICK,
NavInsID.BOTH_CLICK, # (Back to settings)
NavInsID.RIGHT_CLICK,
NavInsID.RIGHT_CLICK,
NavInsID.RIGHT_CLICK,
NavInsID.RIGHT_CLICK,
NavInsID.BOTH_CLICK, # Reset
NavInsID.RIGHT_CLICK,
NavInsID.RIGHT_CLICK,
NavInsID.BOTH_CLICK, # Validate
]
elif device.is_nano:
initial_instructions = [
NavInsID.RIGHT_CLICK,
NavInsID.RIGHT_CLICK,
NavInsID.BOTH_CLICK, # Settings
]
instructions = [
NavInsID.BOTH_CLICK, # Key Template
NavInsID.BOTH_CLICK, # Choose Key
NavInsID.RIGHT_CLICK, # Decryption
NavInsID.RIGHT_CLICK, # Authentication
NavInsID.BOTH_CLICK, # Key Authentication
NavInsID.RIGHT_CLICK, # Choose Type
NavInsID.BOTH_CLICK, # (Select)
NavInsID.RIGHT_CLICK,
NavInsID.RIGHT_CLICK,
NavInsID.RIGHT_CLICK,
NavInsID.BOTH_CLICK, # SECP 256R1
NavInsID.RIGHT_CLICK, # Type SECP 256R1
NavInsID.BOTH_CLICK, # Set Template
NavInsID.RIGHT_CLICK,
NavInsID.RIGHT_CLICK,
NavInsID.RIGHT_CLICK,
NavInsID.BOTH_CLICK, # (Back)
NavInsID.RIGHT_CLICK,
NavInsID.BOTH_CLICK, # Seed mode ON
NavInsID.RIGHT_CLICK,
NavInsID.BOTH_CLICK, # (Back to settings)
NavInsID.RIGHT_CLICK,
NavInsID.BOTH_CLICK, # PIN mode
NavInsID.BOTH_CLICK, # On Screen
NavInsID.RIGHT_CLICK,
NavInsID.RIGHT_CLICK,
NavInsID.RIGHT_CLICK,
NavInsID.BOTH_CLICK, # Set as default
NavInsID.RIGHT_CLICK,
NavInsID.RIGHT_CLICK,
NavInsID.RIGHT_CLICK,
NavInsID.RIGHT_CLICK,
NavInsID.BOTH_CLICK, # (Back to settings)
NavInsID.RIGHT_CLICK,
NavInsID.BOTH_CLICK, # UIF
NavInsID.BOTH_CLICK, # UIF for Signature
NavInsID.RIGHT_CLICK,
NavInsID.RIGHT_CLICK,
NavInsID.RIGHT_CLICK,
NavInsID.BOTH_CLICK, # (Back to settings)
NavInsID.RIGHT_CLICK,
NavInsID.BOTH_CLICK, # Reset
NavInsID.RIGHT_CLICK,
NavInsID.BOTH_CLICK, # Validate
]
else:
initial_instructions = [
NavInsID.USE_CASE_HOME_SETTINGS, # Settings
]
if device.type == DeviceType.STAX:
instructions = [
NavIns(NavInsID.TOUCH, (350, 130)), # Key Template
NavIns(NavInsID.TOUCH, (350, 330)), # Authentication
NavIns(NavInsID.TOUCH, (350, 420)), # SECP 256K1
NavInsID.NAVIGATION_HEADER_TAP, # (Back)
NavIns(NavInsID.TOUCH, (350, 220)), # Seed mode
NavInsID.NAVIGATION_HEADER_TAP, # (Back)
NavIns(NavInsID.TOUCH, (350, 320)), # PIN mode
NavIns(NavInsID.TOUCH, (350, 140)), # On Screen
NavInsID.CENTERED_FOOTER_TAP, # Set default
NavInsID.NAVIGATION_HEADER_TAP, # (Back)
NavIns(NavInsID.TOUCH, (350, 420)), # UIF
NavIns(NavInsID.TOUCH, (350, 130)), # UIF for Signature
NavInsID.NAVIGATION_HEADER_TAP, # (Back)
NavIns(NavInsID.TOUCH, (350, 510)), # Reset
NavInsID.USE_CASE_CHOICE_CONFIRM, # Press 'Reset'
]
else:
instructions = [
NavIns(NavInsID.TOUCH, (430, 130)), # Key Template
NavIns(NavInsID.TOUCH, (430, 320)), # Authentication
NavIns(NavInsID.TOUCH, (430, 410)), # SECP 256K1
NavInsID.NAVIGATION_HEADER_TAP, # (Back)
NavIns(NavInsID.TOUCH, (430, 230)), # Seed mode
NavInsID.NAVIGATION_HEADER_TAP, # (Back)
NavIns(NavInsID.TOUCH, (430, 325)), # PIN mode
NavIns(NavInsID.TOUCH, (430, 140)), # On Screen
NavInsID.EXIT_FOOTER_TAP, # Set default
NavInsID.NAVIGATION_HEADER_TAP, # (Back)
NavIns(NavInsID.TOUCH, (430, 420)), # UIF
NavIns(NavInsID.TOUCH, (430, 140)), # UIF for Signature
NavInsID.NAVIGATION_HEADER_TAP, # (Back)
NavInsID.USE_CASE_SETTINGS_NEXT, # Next page
NavIns(NavInsID.TOUCH, (430, 130)), # Reset
NavInsID.USE_CASE_CHOICE_CONFIRM, # Press 'Reset'
]
# Use the app interface instead of raw interface
client = CommandSender(backend)
# Verify PW2 (User)
check_pincode(client, PassWord.PW2)
# Navigate to settings menu to avoid 1st screen with random serial no
navigator.navigate(initial_instructions,
screen_change_before_first_instruction=False,
screen_change_after_last_instruction=True)
navigator.navigate_and_compare(ROOT_SCREENSHOT_PATH, test_name, instructions,
screen_change_before_first_instruction=False,
screen_change_after_last_instruction=False)