|
21 | 21 | import subprocess
|
22 | 22 | import tempfile
|
23 | 23 | import unittest
|
| 24 | +from os.path import exists |
24 | 25 |
|
25 | 26 | TOOLS_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
|
26 | 27 |
|
|
120 | 121 | 0xde, 0x3d, 0xc0, 0x14, 0x3a, 0x97, 0xe1, 0x35, 0x38, 0xf7, 0xff, 0x76,
|
121 | 122 | 0x05, 0x5e, 0xbf, 0x27, 0x90, 0x6f, 0x50, 0x0f])
|
122 | 123 |
|
| 124 | +TEST_MANUAL_CODE = "Manualcode : 35442608082" |
| 125 | + |
| 126 | +TEST_QR_CODE = "QRCode : MT:KAYA3EYF15ND8B1OA00" |
| 127 | + |
123 | 128 |
|
124 | 129 | def write_file(path: str, content: bytes) -> None:
|
125 | 130 | with open(path, 'wb') as f:
|
@@ -258,6 +263,50 @@ def test_generate_spake2p_verifier_default(self):
|
258 | 263 | '--raw'
|
259 | 264 | ])
|
260 | 265 |
|
| 266 | + def test_generate_onboarding_codes(self): |
| 267 | + with tempfile.TemporaryDirectory() as outdir: |
| 268 | + write_file(os.path.join(outdir, 'DAC_key.der'), DAC_DER_KEY) |
| 269 | + write_file(os.path.join(outdir, 'DAC_cert.der'), DAC_DER_CERT) |
| 270 | + write_file(os.path.join(outdir, 'PAI_cert.der'), PAI_DER_CERT) |
| 271 | + |
| 272 | + subprocess.check_call(['python3', os.path.join(TOOLS_DIR, 'generate_nrfconnect_chip_factory_data.py'), |
| 273 | + '-s', os.path.join(TOOLS_DIR, 'nrfconnect_factory_data.schema'), |
| 274 | + '--include_passcode', |
| 275 | + '--sn', 'SN:12345678', |
| 276 | + '--vendor_id', '0x127F', |
| 277 | + '--product_id', '0xABCD', |
| 278 | + '--vendor_name', 'Nordic Semiconductor ASA', |
| 279 | + '--product_name', 'Lock Gen2', |
| 280 | + '--part_number', 'PCA10056', |
| 281 | + '--product_url', 'https://example.com/lock', |
| 282 | + '--product_label', 'Lock', |
| 283 | + '--date', '2022-07-20', |
| 284 | + '--hw_ver', '101', |
| 285 | + '--hw_ver_str', 'v1.1', |
| 286 | + '--dac_key', os.path.join(outdir, 'DAC_key.der'), |
| 287 | + '--dac_cert', os.path.join(outdir, 'DAC_cert.der'), |
| 288 | + '--pai_cert', os.path.join(outdir, 'PAI_cert.der'), |
| 289 | + '--spake2_it', '2000', |
| 290 | + '--spake2_salt', 'U1BBS0UyUCBLZXkgU2FsdA==', |
| 291 | + '--passcode', '13243546', |
| 292 | + '--spake2_verifier', ('WN0SgEXLfUN19BbJqp6qn4pS69EtdNLReIMZwv/CIM0ECMP7ytiAJ7txIYJ0Ovlha/' |
| 293 | + 'rQ3E+88mj3qaqqnviMaZzG+OyXEdSocDIT9ZhmkTCgWwERaHz4Vdh3G37RT6kqbw=='), |
| 294 | + '--discriminator', '0xFED', |
| 295 | + '--rd_uid', '91a9c12a7c80700a31ddcfa7fce63e44', |
| 296 | + '--enable_key', '00112233445566778899aabbccddeeff', |
| 297 | + '--user', '{"name": "product_name", "version": 123, "revision": "0x123"}', |
| 298 | + '-o', os.path.join(outdir, 'fd.json'), |
| 299 | + '--generate_onboarding' |
| 300 | + ]) |
| 301 | + |
| 302 | + self.assertTrue(exists(os.path.join(outdir, 'fd.txt'))) |
| 303 | + self.assertTrue(exists(os.path.join(outdir, 'fd.png'))) |
| 304 | + |
| 305 | + with open(os.path.join(outdir, 'fd.txt'), 'r') as onboarding_code_file: |
| 306 | + onboarding = onboarding_code_file.readlines() |
| 307 | + self.assertEqual(onboarding[0][:-1], TEST_MANUAL_CODE) |
| 308 | + self.assertEqual(onboarding[1], TEST_QR_CODE) |
| 309 | + |
261 | 310 |
|
262 | 311 | if __name__ == '__main__':
|
263 | 312 | unittest.main()
|
0 commit comments