4ea247a8c0739e114d44fae84f6baa09ad4ebb5c
Marco Ricci Change the author e-mail ad...

Marco Ricci authored 2 months ago

1) # SPDX-FileCopyrightText: 2024 Marco Ricci <software@the13thletter.info>
Marco Ricci Import initial project files

Marco Ricci authored 6 months ago

2) #
3) # SPDX-License-Identifier: MIT
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

4) 
5) from __future__ import annotations
6) 
7) import base64
8) import contextlib
Marco Ricci Test exporter data loading...

Marco Ricci authored 2 months ago

9) import importlib.util
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

10) import json
11) import os
Marco Ricci Add missing tests for rewor...

Marco Ricci authored 2 months ago

12) import stat
Marco Ricci Add preliminary tests for t...

Marco Ricci authored 2 months ago

13) import tempfile
14) import zipfile
Marco Ricci Support Python 3.10 and PyP...

Marco Ricci authored 3 months ago

15) from typing import TYPE_CHECKING
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

16) 
Marco Ricci Fix style issues with ruff...

Marco Ricci authored 3 months ago

17) import pytest
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

18) from typing_extensions import NamedTuple, Self, assert_never
Marco Ricci Fix style issues with ruff...

Marco Ricci authored 3 months ago

19) 
Marco Ricci Consolidate `types` submodu...

Marco Ricci authored 3 months ago

20) from derivepassphrase import _types, cli
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

21) 
22) __all__ = ()
23) 
24) if TYPE_CHECKING:
Marco Ricci Fix style issues with ruff...

Marco Ricci authored 3 months ago

25)     from collections.abc import Iterator, Mapping
26) 
27)     import click.testing
28)     from typing_extensions import Any, TypedDict
29) 
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

30)     class SSHTestKey(TypedDict):
31)         private_key: bytes
32)         public_key: bytes | str
33)         public_key_data: bytes
34)         expected_signature: bytes | None
35)         derived_passphrase: bytes | str | None
36) 
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

37) 
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

38) SUPPORTED_KEYS: Mapping[str, SSHTestKey] = {
39)     'ed25519': {
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

40)         'private_key': rb"""-----BEGIN OPENSSH PRIVATE KEY-----
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

41) b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAMwAAAAtzc2gtZW
42) QyNTUxOQAAACCBeIFoJtYCSF8P/zJIb+TBMIncHGpFBgnpCQ/7whJpdgAAAKDweO7H8Hju
43) xwAAAAtzc2gtZWQyNTUxOQAAACCBeIFoJtYCSF8P/zJIb+TBMIncHGpFBgnpCQ/7whJpdg
44) AAAEAbM/A869nkWZbe2tp3Dm/L6gitvmpH/aRZt8sBII3ExYF4gWgm1gJIXw//Mkhv5MEw
45) idwcakUGCekJD/vCEml2AAAAG3Rlc3Qga2V5IHdpdGhvdXQgcGFzc3BocmFzZQEC
46) -----END OPENSSH PRIVATE KEY-----
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

47) """,
48)         'public_key': rb"""ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIIF4gWgm1gJIXw//Mkhv5MEwidwcakUGCekJD/vCEml2 test key without passphrase
49) """,  # noqa: E501
50)         'public_key_data': bytes.fromhex("""
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

51)             00 00 00 0b 73 73 68 2d 65 64 32 35 35 31 39
52)             00 00 00 20
53)             81 78 81 68 26 d6 02 48 5f 0f ff 32 48 6f e4 c1
54)             30 89 dc 1c 6a 45 06 09 e9 09 0f fb c2 12 69 76
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

55) """),
56)         'expected_signature': bytes.fromhex("""
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

57)             00 00 00 0b 73 73 68 2d 65 64 32 35 35 31 39
58)             00 00 00 40
59)             f0 98 19 80 6c 1a 97 d5 26 03 6e cc e3 65 8f 86
60)             66 07 13 19 13 09 21 33 33 f9 e4 36 53 1d af fd
61)             0d 08 1f ec f8 73 9b 8c 5f 55 39 16 7c 53 54 2c
62)             1e 52 bb 30 ed 7f 89 e2 2f 69 51 55 d8 9e a6 02
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

63)         """),
Marco Ricci Fix style issues with ruff...

Marco Ricci authored 3 months ago

64)         'derived_passphrase': rb'8JgZgGwal9UmA27M42WPhmYHExkTCSEzM/nkNlMdr/0NCB/s+HObjF9VORZ8U1QsHlK7MO1/ieIvaVFV2J6mAg==',  # noqa: E501
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

65)     },
66)     # Currently only supported by PuTTY (which is deficient in other
67)     # niceties of the SSH agent and the agent's client).
68)     'ed448': {
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

69)         'private_key': rb"""-----BEGIN OPENSSH PRIVATE KEY-----
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

70) b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAASgAAAAlz
71) c2gtZWQ0NDgAAAA54vZy009Wu8wExjvEb3hqtLz1GO/+d5vmGUbErWQ4AUO9mYLT
72) zHJHc2m4s+yWzP29Cc3EcxizLG8AAAAA8BdhfCcXYXwnAAAACXNzaC1lZDQ0OAAA
73) ADni9nLTT1a7zATGO8RveGq0vPUY7/53m+YZRsStZDgBQ72ZgtPMckdzabiz7JbM
74) /b0JzcRzGLMsbwAAAAByM7GIMRvWJB3YD6SIpAF2uudX4ozZe0X917wPwiBrs373
75) 9TM1n94Nib6hrxGNmCk2iBQDe2KALPgA4vZy009Wu8wExjvEb3hqtLz1GO/+d5vm
76) GUbErWQ4AUO9mYLTzHJHc2m4s+yWzP29Cc3EcxizLG8AAAAAG3Rlc3Qga2V5IHdp
77) dGhvdXQgcGFzc3BocmFzZQECAwQFBgcICQ==
78) -----END OPENSSH PRIVATE KEY-----
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

79) """,
80)         'public_key': rb"""ssh-ed448 AAAACXNzaC1lZDQ0OAAAADni9nLTT1a7zATGO8RveGq0vPUY7/53m+YZRsStZDgBQ72ZgtPMckdzabiz7JbM/b0JzcRzGLMsbwA= test key without passphrase
81) """,  # noqa: E501
82)         'public_key_data': bytes.fromhex("""
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

83)             00 00 00 09 73 73 68 2d 65 64 34 34 38
84)             00 00 00 39
85)             e2 f6 72 d3 4f 56 bb cc 04 c6 3b c4 6f 78 6a b4
86)             bc f5 18 ef fe 77 9b e6 19 46 c4 ad 64 38 01 43
87)             bd 99 82 d3 cc 72 47 73 69 b8 b3 ec 96 cc fd bd
88)             09 cd c4 73 18 b3 2c 6f 00
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

89)         """),
90)         'expected_signature': bytes.fromhex("""
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

91)             00 00 00 09 73 73 68 2d 65 64 34 34 38
92)             00 00 00 72 06 86
93)             f4 64 a4 a6 ba d9 c3 22 c4 93 49 99 fc 11 de 67
94)             97 08 f2 d8 b7 3c 2c 13 e7 c5 1c 1e 92 a6 0e d8
95)             2f 6d 81 03 82 00 e3 72 e4 32 6d 72 d2 6d 32 84
96)             3f cc a9 1e 57 2c 00 9a b3 99 de 45 da ce 2e d1
97)             db e5 89 f3 35 be 24 58 90 c6 ca 04 f0 db 88 80
98)             db bd 77 7c 80 20 7f 3a 48 61 f6 1f ae a9 5e 53
99)             7b e0 9d 93 1e ea dc eb b5 cd 56 4c ea 8f 08 00
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

100)         """),
Marco Ricci Fix style issues with ruff...

Marco Ricci authored 3 months ago

101)         'derived_passphrase': rb'Bob0ZKSmutnDIsSTSZn8Ed5nlwjy2Lc8LBPnxRwekqYO2C9tgQOCAONy5DJtctJtMoQ/zKkeVywAmrOZ3kXazi7R2+WJ8zW+JFiQxsoE8NuIgNu9d3yAIH86SGH2H66pXlN74J2THurc67XNVkzqjwgA',  # noqa: E501
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

102)     },
103)     'rsa': {
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

104)         'private_key': rb"""-----BEGIN OPENSSH PRIVATE KEY-----
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

105) b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAABlwAAAAdzc2gtcn
106) NhAAAAAwEAAQAAAYEAsaHu6Xs4cVsuDSNJlMCqoPVgmDgEviI8TfXmHKqX3JkIqI3LsvV7
107) Ijf8WCdTveEq7CkuZhImtsR52AOEVAoU8mDXDNr+nJ5wUPzf1UIaRjDe0lcXW4SlF01hQs
108) G4wYDuqxshwelraB/L3e0zhD7fjYHF8IbFsqGlFHWEwOtlfhhfbxJsTGguLm4A8/gdEJD5
109) 2rkqDcZpIXCHtJbCzW9aQpWcs/PDw5ylwl/3dB7jfxyfrGz4O3QrzsqhWEsip97mOmwl6q
110) CHbq8V8x9zu89D/H+bG5ijqxhijbjcVUW3lZfw/97gy9J6rG31HNar5H8GycLTFwuCFepD
111) mTEpNgQLKoe8ePIEPq4WHhFUovBdwlrOByUKKqxreyvWt5gkpTARz+9Lt8OjBO3rpqK8sZ
112) VKH3sE3de2RJM3V9PJdmZSs2b8EFK3PsUGdlMPM9pn1uk4uIItKWBmooOynuD8Ll6aPwuW
113) AFn3l8nLLyWdrmmEYzHWXiRjQJxy1Bi5AbHMOWiPAAAFkDPkuBkz5LgZAAAAB3NzaC1yc2
114) EAAAGBALGh7ul7OHFbLg0jSZTAqqD1YJg4BL4iPE315hyql9yZCKiNy7L1eyI3/FgnU73h
115) KuwpLmYSJrbEedgDhFQKFPJg1wza/pyecFD839VCGkYw3tJXF1uEpRdNYULBuMGA7qsbIc
116) Hpa2gfy93tM4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Ca1N58l7f
131) srzwbi9pFUuUp9dShXNffmlUCjDRsVLbK5C6+iaIQyCWFYK8mc6dpNkIoPKf+Xg+EJCIFQ
132) oITqeu30Gc1+M+fdZc2ghq0b6XLthh/uHEry8b68M5KglMAAAAwQDw1i+IdcvPV/3u/q9O
133) /kzLpKO3tbT89sc1zhjZsDNjDAGluNr6n38iq/XYRZu7UTL9BG+EgFVfIUV7XsYT5e+BPf
134) 13VS94rzZ7maCsOlULX+VdMO2zBucHIoec9RUlRZrfB21B2W7YGMhbpoa5lN3lKJQ7afHo
135) dXZUMp0cTFbOmbzJgSzO2/NE7BhVwmvcUzTDJGMMKuxBO6w99YKDKRKm0PNLFDz26rWm9L
136) dNS2MVfVuPMTpzT26HQG4pFageq9cAAADBALzRBXdZF8kbSBa5MTUBVTTzgKQm1C772gJ8
137) T01DJEXZsVtOv7mUC1/m/by6Hk4tPyvDBuGj9hHq4N7dPqGutHb1q5n0ADuoQjRW7BXw5Q
138) vC2EAD91xexdorIA5BgXU+qltBqzzBVzVtF7+jOZOjfzOlaTX9I5I5veyeTaTxZj1XXUzi
139) btBNdMEJJp7ifucYmoYAAwE7K+VlWagDEK2y8Mte9y9E+N0uO2j+h85sQt/UIb2iE/vhcg
140) Bgp6142WnSCQAAABt0ZXN0IGtleSB3aXRob3V0IHBhc3NwaHJhc2UB
141) -----END OPENSSH PRIVATE KEY-----
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

142) """,
143)         'public_key': rb"""ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQCxoe7pezhxWy4NI0mUwKqg9WCYOAS+IjxN9eYcqpfcmQiojcuy9XsiN/xYJ1O94SrsKS5mEia2xHnYA4RUChTyYNcM2v6cnnBQ/N/VQhpGMN7SVxdbhKUXTWFCwbjBgO6rGyHB6WtoH8vd7TOEPt+NgcXwhsWyoaUUdYTA62V+GF9vEmxMaC4ubgDz+B0QkPnauSoNxmkhcIe0lsLNb1pClZyz88PDnKXCX/d0HuN/HJ+sbPg7dCvOyqFYSyKn3uY6bCXqoIdurxXzH3O7z0P8f5sbmKOrGGKNuNxVRbeVl/D/3uDL0nqsbfUc1qvkfwbJwtMXC4IV6kOZMSk2BAsqh7x48gQ+rhYeEVSi8F3CWs4HJQoqrGt7K9a3mCSlMBHP70u3w6ME7eumoryxlUofewTd17ZEkzdX08l2ZlKzZvwQUrc+xQZ2Uw8z2mfW6Ti4gi0pYGaig7Ke4PwuXpo/C5YAWfeXycsvJZ2uaYRjMdZeJGNAnHLUGLkBscw5aI8= test key without passphrase
144) """,  # noqa: E501
145)         'public_key_data': bytes.fromhex("""
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

146)             00 00 00 07 73 73 68 2d 72 73 61
147)             00 00 00 03 01 00 01
148)             00 00 01 81 00
149)             b1 a1 ee e9 7b 38 71 5b 2e 0d 23 49 94 c0 aa a0
150)             f5 60 98 38 04 be 22 3c 4d f5 e6 1c aa 97 dc 99
151)             08 a8 8d cb b2 f5 7b 22 37 fc 58 27 53 bd e1 2a
152)             ec 29 2e 66 12 26 b6 c4 79 d8 03 84 54 0a 14 f2
153)             60 d7 0c da fe 9c 9e 70 50 fc df d5 42 1a 46 30
154)             de d2 57 17 5b 84 a5 17 4d 61 42 c1 b8 c1 80 ee
155)             ab 1b 21 c1 e9 6b 68 1f cb dd ed 33 84 3e df 8d
156)             81 c5 f0 86 c5 b2 a1 a5 14 75 84 c0 eb 65 7e 18
157)             5f 6f 12 6c 4c 68 2e 2e 6e 00 f3 f8 1d 10 90 f9
158)             da b9 2a 0d c6 69 21 70 87 b4 96 c2 cd 6f 5a 42
159)             95 9c b3 f3 c3 c3 9c a5 c2 5f f7 74 1e e3 7f 1c
160)             9f ac 6c f8 3b 74 2b ce ca a1 58 4b 22 a7 de e6
161)             3a 6c 25 ea a0 87 6e af 15 f3 1f 73 bb cf 43 fc
162)             7f 9b 1b 98 a3 ab 18 62 8d b8 dc 55 45 b7 95 97
163)             f0 ff de e0 cb d2 7a ac 6d f5 1c d6 ab e4 7f 06
164)             c9 c2 d3 17 0b 82 15 ea 43 99 31 29 36 04 0b 2a
165)             87 bc 78 f2 04 3e ae 16 1e 11 54 a2 f0 5d c2 5a
166)             ce 07 25 0a 2a ac 6b 7b 2b d6 b7 98 24 a5 30 11
167)             cf ef 4b b7 c3 a3 04 ed eb a6 a2 bc b1 95 4a 1f
168)             7b 04 dd d7 b6 44 93 37 57 d3 c9 76 66 52 b3 66
169)             fc 10 52 b7 3e c5 06 76 53 0f 33 da 67 d6 e9 38
170)             b8 82 2d 29 60 66 a2 83 b2 9e e0 fc 2e 5e 9a 3f
171)             0b 96 00 59 f7 97 c9 cb 2f 25 9d ae 69 84 63 31
172)             d6 5e 24 63 40 9c 72 d4 18 b9 01 b1 cc 39 68 8f
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

173) """),
174)         'expected_signature': bytes.fromhex("""
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

175)             00 00 00 07 73 73 68 2d 72 73 61
176)             00 00 01 80
177)             a2 10 7c 2e f6 bb 53 a8 74 2a a1 19 99 ad 81 be
178)             79 9c ed d6 9d 09 4e 6e c5 18 48 33 90 77 99 68
179)             f7 9e 03 5a cd 4e 18 eb 89 7d 85 a2 ee ae 4a 92
180)             f6 6f ce b9 fe 86 7f 2a 6b 31 da 6e 1a fe a2 a5
181)             88 b8 44 7f a1 76 73 b3 ec 75 b5 d0 a6 b9 15 97
182)             65 09 13 7d 94 21 d1 fb 5d 0f 8b 23 04 77 c2 c3
183)             55 22 b1 a0 09 8a f5 38 2a d6 7f 1b 87 29 a0 25
184)             d3 25 6f cb 64 61 07 98 dc 14 c5 84 f8 92 24 5e
185)             50 11 6b 49 e5 f0 cc 29 cb 29 a9 19 d8 a7 71 1f
186)             91 0b 05 b1 01 4b c2 5f 00 a5 b6 21 bf f8 2c 9d
187)             67 9b 47 3b 0a 49 6b 79 2d fc 1d ec 0c b0 e5 27
188)             22 d5 a9 f8 d3 c3 f9 df 48 68 e9 fb ef 3c dc 26
189)             bf cf ea 29 43 01 a6 e3 c5 51 95 f4 66 6d 8a 55
190)             e2 47 ec e8 30 45 4c ae 47 e7 c9 a4 21 8b 64 ba
191)             b6 88 f6 21 f8 73 b9 cb 11 a1 78 75 92 c6 5a e5
192)             64 fe ed 42 d9 95 99 e6 2b 6f 3c 16 3c 28 74 a4
193)             72 2f 0d 3f 2c 33 67 aa 35 19 8e e7 b5 11 2f b3
194)             f7 6a c5 02 e2 6f a3 42 e3 62 19 99 03 ea a5 20
195)             e7 a1 e3 bc c8 06 a3 b5 7c d6 76 5d df 6f 60 46
196)             83 2a 08 00 d6 d3 d9 a4 c1 41 8c f8 60 56 45 81
197)             da 3b a2 16 1f 9e 4e 75 83 17 da c3 53 c3 3e 19
198)             a4 1b bc d2 29 b8 78 61 2b 78 e6 b1 52 b0 d5 ec
199)             de 69 2c 48 62 d9 fd d1 9b 6b b0 49 db d3 ff 38
200)             e7 10 d9 2d ce 9f 0d 5e 09 7b 37 d2 7b c3 bf ce
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

201) """),
Marco Ricci Fix style issues with ruff...

Marco Ricci authored 3 months ago

202)         'derived_passphrase': rb'ohB8Lva7U6h0KqEZma2Bvnmc7dadCU5uxRhIM5B3mWj3ngNazU4Y64l9haLurkqS9m/Ouf6GfyprMdpuGv6ipYi4RH+hdnOz7HW10Ka5FZdlCRN9lCHR+10PiyMEd8LDVSKxoAmK9Tgq1n8bhymgJdMlb8tkYQeY3BTFhPiSJF5QEWtJ5fDMKcspqRnYp3EfkQsFsQFLwl8ApbYhv/gsnWebRzsKSWt5Lfwd7Ayw5Sci1an408P530ho6fvvPNwmv8/qKUMBpuPFUZX0Zm2KVeJH7OgwRUyuR+fJpCGLZLq2iPYh+HO5yxGheHWSxlrlZP7tQtmVmeYrbzwWPCh0pHIvDT8sM2eqNRmO57URL7P3asUC4m+jQuNiGZkD6qUg56HjvMgGo7V81nZd329gRoMqCADW09mkwUGM+GBWRYHaO6IWH55OdYMX2sNTwz4ZpBu80im4eGEreOaxUrDV7N5pLEhi2f3Rm2uwSdvT/zjnENktzp8NXgl7N9J7w7/O',  # noqa: E501
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

203)     },
204) }
205) 
206) UNSUITABLE_KEYS: Mapping[str, SSHTestKey] = {
207)     'dsa1024': {
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

208)         'private_key': rb"""-----BEGIN OPENSSH PRIVATE KEY-----
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

209) b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAABsQAAAAdzc2gtZH
210) NzAAAAgQC7KAZXqBGNVLBQPrcMYAoNW54BhD8aIhe7BDWYzJcsaMt72VKSkguZ8+XR7nRa
211) 0C/ZsBi+uJp0dpxy9ZMTOWX4u5YPMeQcXEdGExZIfimGqSOAsy6fCld2IfJZJZExcCmhe9
212) Ssjsd3YSAPJRluOXFQc95MZoR5hMwlIDD8QzrE7QAAABUA99nOZOgd7aHMVGoXpUEBcn7H
213) ossAAACALr2Ag3hxM3rKdxzVUw8fX0VVPXO+3+Kr8hGe0Kc/7NwVaBVL1GQ8fenBuWynpA
214) UbH0wo3h1wkB/8hX6p+S8cnu5rIBlUuVNwLw/bIYohK98LfqTYK/V+g6KD+8m34wvEiXZm
215) qywY54n2bksch1Nqvj/tNpLzExSx/XS0kSM1aigAAACAbQNRPcVEuGDrEcf+xg5tgAejPX
216) BPXr/Jss+Chk64km3mirMYjAWyWYtVcgT+7hOYxtYRin8LyMLqKRmqa0Q5UrvDfChgLhvs
217) G9YSb/Mpw5qm8PiHSafwhkaz/te3+8hKogqoe7sd+tCF06IpJr5k70ACiNtRGqssNF8Elr
218) l1efYAAAH4swlfVrMJX1YAAAAHc3NoLWRzcwAAAIEAuygGV6gRjVSwUD63DGAKDVueAYQ/
219) GiIXuwQ1mMyXLGjLe9lSkpILmfPl0e50WtAv2bAYvriadHaccvWTEzll+LuWDzHkHFxHRh
220) MWSH4phqkjgLMunwpXdiHyWSWRMXApoXvUrI7Hd2EgDyUZbjlxUHPeTGaEeYTMJSAw/EM6
221) xO0AAAAVAPfZzmToHe2hzFRqF6VBAXJ+x6LLAAAAgC69gIN4cTN6yncc1VMPH19FVT1zvt
222) /iq/IRntCnP+zcFWgVS9RkPH3pwblsp6QFGx9MKN4dcJAf/IV+qfkvHJ7uayAZVLlTcC8P
223) 2yGKISvfC36k2Cv1foOig/vJt+MLxIl2ZqssGOeJ9m5LHIdTar4/7TaS8xMUsf10tJEjNW
224) ooAAAAgG0DUT3FRLhg6xHH/sYObYAHoz1wT16/ybLPgoZOuJJt5oqzGIwFslmLVXIE/u4T
225) mMbWEYp/C8jC6ikZqmtEOVK7w3woYC4b7BvWEm/zKcOapvD4h0mn8IZGs/7Xt/vISqIKqH
226) u7HfrQhdOiKSa+ZO9AAojbURqrLDRfBJa5dXn2AAAAFQDJHfenj4EJ9WkehpdJatPBlqCW
227) 0gAAABt0ZXN0IGtleSB3aXRob3V0IHBhc3NwaHJhc2UBAgMEBQYH
228) -----END OPENSSH PRIVATE KEY-----
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

229) """,
230)         'public_key': rb"""ssh-dss AAAAB3NzaC1kc3MAAACBALsoBleoEY1UsFA+twxgCg1bngGEPxoiF7sENZjMlyxoy3vZUpKSC5nz5dHudFrQL9mwGL64mnR2nHL1kxM5Zfi7lg8x5BxcR0YTFkh+KYapI4CzLp8KV3Yh8lklkTFwKaF71KyOx3dhIA8lGW45cVBz3kxmhHmEzCUgMPxDOsTtAAAAFQD32c5k6B3tocxUahelQQFyfseiywAAAIAuvYCDeHEzesp3HNVTDx9fRVU9c77f4qvyEZ7Qpz/s3BVoFUvUZDx96cG5bKekBRsfTCjeHXCQH/yFfqn5Lxye7msgGVS5U3AvD9shiiEr3wt+pNgr9X6DooP7ybfjC8SJdmarLBjnifZuSxyHU2q+P+02kvMTFLH9dLSRIzVqKAAAAIBtA1E9xUS4YOsRx/7GDm2AB6M9cE9ev8myz4KGTriSbeaKsxiMBbJZi1VyBP7uE5jG1hGKfwvIwuopGaprRDlSu8N8KGAuG+wb1hJv8ynDmqbw+IdJp/CGRrP+17f7yEqiCqh7ux360IXToikmvmTvQAKI21Eaqyw0XwSWuXV59g== test key without passphrase
231) """,  # noqa: E501
232)         'public_key_data': bytes.fromhex("""
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

233)             00 00 00 07 73 73 68 2d 64 73 73
234)             00 00 00 81 00
235)             bb 28 06 57 a8 11 8d 54 b0 50 3e b7 0c 60 0a 0d
236)             5b 9e 01 84 3f 1a 22 17 bb 04 35 98 cc 97 2c 68
237)             cb 7b d9 52 92 92 0b 99 f3 e5 d1 ee 74 5a d0 2f
238)             d9 b0 18 be b8 9a 74 76 9c 72 f5 93 13 39 65 f8
239)             bb 96 0f 31 e4 1c 5c 47 46 13 16 48 7e 29 86 a9
240)             23 80 b3 2e 9f 0a 57 76 21 f2 59 25 91 31 70 29
241)             a1 7b d4 ac 8e c7 77 61 20 0f 25 19 6e 39 71 50
242)             73 de 4c 66 84 79 84 cc 25 20 30 fc 43 3a c4 ed
243)             00 00 00 15 00 f7 d9 ce 64
244)             e8 1d ed a1 cc 54 6a 17 a5 41 01 72 7e c7 a2 cb
245)             00 00 00 80
246)             2e bd 80 83 78 71 33 7a ca 77 1c d5 53 0f 1f 5f
247)             45 55 3d 73 be df e2 ab f2 11 9e d0 a7 3f ec dc
248)             15 68 15 4b d4 64 3c 7d e9 c1 b9 6c a7 a4 05 1b
249)             1f 4c 28 de 1d 70 90 1f fc 85 7e a9 f9 2f 1c 9e
250)             ee 6b 20 19 54 b9 53 70 2f 0f db 21 8a 21 2b df
251)             0b 7e a4 d8 2b f5 7e 83 a2 83 fb c9 b7 e3 0b c4
252)             89 76 66 ab 2c 18 e7 89 f6 6e 4b 1c 87 53 6a be
253)             3f ed 36 92 f3 13 14 b1 fd 74 b4 91 23 35 6a 28
254)             00 00 00 80
255)             6d 03 51 3d c5 44 b8 60 eb 11 c7 fe c6 0e 6d 80
256)             07 a3 3d 70 4f 5e bf c9 b2 cf 82 86 4e b8 92 6d
257)             e6 8a b3 18 8c 05 b2 59 8b 55 72 04 fe ee 13 98
258)             c6 d6 11 8a 7f 0b c8 c2 ea 29 19 aa 6b 44 39 52
259)             bb c3 7c 28 60 2e 1b ec 1b d6 12 6f f3 29 c3 9a
260)             a6 f0 f8 87 49 a7 f0 86 46 b3 fe d7 b7 fb c8 4a
261)             a2 0a a8 7b bb 1d fa d0 85 d3 a2 29 26 be 64 ef
262)             40 02 88 db 51 1a ab 2c 34 5f 04 96 b9 75 79 f6
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

263) """),
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

264)         'expected_signature': None,
265)         'derived_passphrase': None,
266)     },
267)     'ecdsa256': {
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

268)         'private_key': rb"""-----BEGIN OPENSSH PRIVATE KEY-----
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

269) b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAaAAAABNlY2RzYS
270) 1zaGEyLW5pc3RwMjU2AAAACG5pc3RwMjU2AAAAQQTLbU0zDwsk2Dvp+VYIrsNVf5gWwz2S
271) 3SZ8TbxiQRkpnGSVqyIoHJOJc+NQItAa7xlJ/8Z6gfz57Z3apUkaMJm6AAAAuKeY+YinmP
272) mIAAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBMttTTMPCyTYO+n5
273) Vgiuw1V/mBbDPZLdJnxNvGJBGSmcZJWrIigck4lz41Ai0BrvGUn/xnqB/PntndqlSRowmb
274) oAAAAhAKIl/3n0pKVIxpZkXTGtii782Qr4yIcvHdpxjO/QsIqKAAAAG3Rlc3Qga2V5IHdp
275) dGhvdXQgcGFzc3BocmFzZQECAwQ=
276) -----END OPENSSH PRIVATE KEY-----
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

277) """,
278)         'public_key': rb"""ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBMttTTMPCyTYO+n5Vgiuw1V/mBbDPZLdJnxNvGJBGSmcZJWrIigck4lz41Ai0BrvGUn/xnqB/PntndqlSRowmbo= test key without passphrase
279) """,  # noqa: E501
280)         'public_key_data': bytes.fromhex("""
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

281)             00 00 00 13 65 63 64 73 61 2d 73 68 61 32 2d 6e
282)             69 73 74 70 32 35 36
283)             00 00 00 08 6e 69 73 74 70 32 35 36
284)             00 00 00 41 04
285)             cb 6d 4d 33 0f 0b 24 d8 3b e9 f9 56 08 ae c3 55
286)             7f 98 16 c3 3d 92 dd 26 7c 4d bc 62 41 19 29 9c
287)             64 95 ab 22 28 1c 93 89 73 e3 50 22 d0 1a ef 19
288)             49 ff c6 7a 81 fc f9 ed 9d da a5 49 1a 30 99 ba
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

289) """),
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

290)         'expected_signature': None,
291)         'derived_passphrase': None,
292)     },
293)     'ecdsa384': {
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

294)         'private_key': rb"""-----BEGIN OPENSSH PRIVATE KEY-----
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

295) b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAiAAAABNlY2RzYS
296) 1zaGEyLW5pc3RwMzg0AAAACG5pc3RwMzg0AAAAYQSgkOjkAvq7v5vHuj3KBL4/EAWcn5hZ
297) DyKcbyV0eBMGFq7hKXQlZqIahLVqeMR0QqmkxNJ2rly2VHcXneq3vZ+9fIsWCOdYk5WP3N
298) ZPzv911Xn7wbEkC7QndD5zKlm4pBUAAADomhj+IZoY/iEAAAATZWNkc2Etc2hhMi1uaXN0
299) cDM4NAAAAAhuaXN0cDM4NAAAAGEEoJDo5AL6u7+bx7o9ygS+PxAFnJ+YWQ8inG8ldHgTBh
300) au4Sl0JWaiGoS1anjEdEKppMTSdq5ctlR3F53qt72fvXyLFgjnWJOVj9zWT87/ddV5+8Gx
301) JAu0J3Q+cypZuKQVAAAAMQD5sTy8p+B1cn/DhOmXquui1BcxvASqzzevkBlbQoBa73y04B
302) 2OdqVOVRkwZWRROz0AAAAbdGVzdCBrZXkgd2l0aG91dCBwYXNzcGhyYXNlAQIDBA==
303) -----END OPENSSH PRIVATE KEY-----
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

304) """,
305)         'public_key': rb"""ecdsa-sha2-nistp384 AAAAE2VjZHNhLXNoYTItbmlzdHAzODQAAAAIbmlzdHAzODQAAABhBKCQ6OQC+ru/m8e6PcoEvj8QBZyfmFkPIpxvJXR4EwYWruEpdCVmohqEtWp4xHRCqaTE0nauXLZUdxed6re9n718ixYI51iTlY/c1k/O/3XVefvBsSQLtCd0PnMqWbikFQ== test key without passphrase
306) """,  # noqa: E501
307)         'public_key_data': bytes.fromhex("""
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

308)             00 00 00 13
309)             65 63 64 73 61 2d 73 68 61 32 2d 6e 69 73 74 70
310)             33 38 34
311)             00 00 00 08 6e 69 73 74 70 33 38 34
312)             00 00 00 61 04
313)             a0 90 e8 e4 02 fa bb bf 9b c7 ba 3d ca 04 be 3f
314)             10 05 9c 9f 98 59 0f 22 9c 6f 25 74 78 13 06 16
315)             ae e1 29 74 25 66 a2 1a 84 b5 6a 78 c4 74 42 a9
316)             a4 c4 d2 76 ae 5c b6 54 77 17 9d ea b7 bd 9f bd
317)             7c 8b 16 08 e7 58 93 95 8f dc d6 4f ce ff 75 d5
318)             79 fb c1 b1 24 0b b4 27 74 3e 73 2a 59 b8 a4 15
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

319) """),
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

320)         'expected_signature': None,
321)         'derived_passphrase': None,
322)     },
323) }
324) 
325) DUMMY_SERVICE = 'service1'
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

326) DUMMY_PASSPHRASE = 'my secret passphrase'
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

327) DUMMY_KEY1 = SUPPORTED_KEYS['ed25519']['public_key_data']
328) DUMMY_KEY1_B64 = base64.standard_b64encode(DUMMY_KEY1).decode('ASCII')
329) DUMMY_KEY2 = SUPPORTED_KEYS['rsa']['public_key_data']
330) DUMMY_KEY2_B64 = base64.standard_b64encode(DUMMY_KEY2).decode('ASCII')
Marco Ricci Avoid crashing when overrid...

Marco Ricci authored 3 months ago

331) DUMMY_KEY3 = SUPPORTED_KEYS['ed448']['public_key_data']
332) DUMMY_KEY3_B64 = base64.standard_b64encode(DUMMY_KEY3).decode('ASCII')
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

333) DUMMY_CONFIG_SETTINGS = {
334)     'length': 10,
335)     'upper': 1,
336)     'lower': 1,
337)     'repeat': 5,
338)     'number': 1,
339)     'space': 1,
340)     'dash': 1,
341)     'symbol': 1,
342) }
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

343) DUMMY_RESULT_PASSPHRASE = b'.2V_QJkd o'
344) DUMMY_RESULT_KEY1 = b'E<b<{ -7iG'
345) DUMMY_PHRASE_FROM_KEY1_RAW = (
346)     b'\x00\x00\x00\x0bssh-ed25519'
347)     b'\x00\x00\x00@\xf0\x98\x19\x80l\x1a\x97\xd5&\x03n'
348)     b'\xcc\xe3e\x8f\x86f\x07\x13\x19\x13\t!33\xf9\xe46S'
349)     b'\x1d\xaf\xfd\r\x08\x1f\xec\xf8s\x9b\x8c_U9\x16|ST,'
350)     b'\x1eR\xbb0\xed\x7f\x89\xe2/iQU\xd8\x9e\xa6\x02'
351) )
Marco Ricci Fix style issues with ruff...

Marco Ricci authored 3 months ago

352) DUMMY_PHRASE_FROM_KEY1 = b'8JgZgGwal9UmA27M42WPhmYHExkTCSEzM/nkNlMdr/0NCB/s+HObjF9VORZ8U1QsHlK7MO1/ieIvaVFV2J6mAg=='  # noqa: E501
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

353) 
Marco Ricci Move exporter command-line...

Marco Ricci authored 2 months ago

354) VAULT_MASTER_KEY = 'vault key'
355) VAULT_V02_CONFIG = 'P7xeh5y4jmjpJ2pFq4KUcTVoaE9ZOEkwWmpVTURSSWQxbGt6emN4aFE4eFM3anVPbDRNTGpOLzY3eDF5aE1YTm5LNWh5Q1BwWTMwM3M5S083MWRWRFlmOXNqSFJNcStGMWFOS3c2emhiOUNNenZYTmNNMnZxaUErdlRoOGF2ZHdGT1ZLNTNLOVJQcU9jWmJrR3g5N09VcVBRZ0ZnSFNUQy9HdFVWWnFteVhRVkY3MHNBdnF2ZWFEbFBseWRGelE1c3BFTnVUckRQdWJSL29wNjFxd2Y2ZVpob3VyVzRod3FKTElTenJ1WTZacTJFOFBtK3BnVzh0QWVxcWtyWFdXOXYyenNQeFNZbWt1MDU2Vm1kVGtISWIxWTBpcWRFbyswUVJudVVhZkVlNVpGWDA4WUQ2Q2JTWW81SnlhQ2Zxa3cxNmZoQjJES0Uyd29rNXpSck5iWVBrVmEwOXFya1NpMi9saU5LL3F0M3N3MjZKekNCem9ER2svWkZ0SUJLdmlHRno0VlQzQ3pqZTBWcTM3YmRiNmJjTkhqUHZoQ0NxMW1ldW1XOFVVK3pQMEtUMkRMVGNvNHFlOG40ck5KcGhsYXg1b1VzZ1NYU1B2T3RXdEkwYzg4NWE3YWUzOWI1MDI0MThhMWZjODQ3MDA2OTJmNDQ0MDkxNGFiNmRlMGQ2YjZiNjI5NGMwN2IwMmI4MGZi'  # noqa: E501
356) VAULT_V02_CONFIG_DATA = {
357)     'global': {
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

358)         'phrase': DUMMY_PASSPHRASE.rstrip('\n'),
Marco Ricci Move exporter command-line...

Marco Ricci authored 2 months ago

359)     },
360)     'services': {
361)         '(meta)': {
362)             'notes': 'This config was originally in v0.2 format.',
363)         },
364)         DUMMY_SERVICE: DUMMY_CONFIG_SETTINGS.copy(),
365)     },
366) }
367) VAULT_V03_CONFIG = 'sBPBrr8BFHPxSJkV/A53zk9zwDQHFxLe6UIusCVvzFQre103pcj5xxmE11lMTA0U2QTYjkhRXKkH5WegSmYpAnzReuRsYZlWWp6N4kkubf+twZ9C3EeggPm7as2Af4TICHVbX4uXpIHeQJf9y1OtqrO+SRBrgPBzgItoxsIxebxVKgyvh1CZQOSkn7BIzt9xKhDng3ubS4hQ91fB0QCumlldTbUl8tj4Xs5JbvsSlUMxRlVzZ0OgAOrSsoWELXmsp6zXFa9K6wIuZa4wQuMLQFHiA64JO1CR3I+rviWCeMlbTOuJNx6vMB5zotKJqA2hIUpN467TQ9vI4g/QTo40m5LT2EQKbIdTvBQAzcV4lOcpr5Lqt4LHED5mKvm/4YfpuuT3I3XCdWfdG5SB7ciiB4Go+xQdddy3zZMiwm1fEwIB8XjFf2cxoJdccLQ2yxf+9diedBP04EsMHrvxKDhQ7/vHl7xF2MMFTDKl3WFd23vvcjpR1JgNAKYprG/e1p/7'  # noqa: E501
368) VAULT_V03_CONFIG_DATA = {
369)     'global': {
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

370)         'phrase': DUMMY_PASSPHRASE.rstrip('\n'),
Marco Ricci Move exporter command-line...

Marco Ricci authored 2 months ago

371)     },
372)     'services': {
373)         '(meta)': {
374)             'notes': 'This config was originally in v0.3 format.',
375)         },
376)         DUMMY_SERVICE: DUMMY_CONFIG_SETTINGS.copy(),
377)     },
378) }
379) VAULT_STOREROOM_CONFIG_ZIPPED = b"""
380) UEsDBBQAAAAIAJ1WGVnTVFGT0gAAAOYAAAAFAAAALm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5gqDxAGQRZF
408) QZZbDIFG2YwIga7593nv93sm9N0M/fcf4d+XcUlVE+kvustz3BU7FjHOaW+u6TRsfNKzLh74mO1w
409) IXUlM/2sGKKuY5sYrW5N+oGqit2zLBYv57mFvH/S8pWGYDGzUnU1CdTL3B4Yix+Hk8E/+m0cSi2E
410) dnAibw1brWVXM++8iYcUg84TMbJXntFYCyrNw1NF+008I02PeH4C8oDID6fIoKvsw3p7WJJ/I9Yp
411) a6oJzlJiP5JGxRxZPj50N6EMtzNB+tZoIGxgtOFVpiJ05yMQFztY6I6LKIgvXW/s919GIjGshqdM
412) XVPFxaKG4p9Iux/xazf48FY8O7SMmbQC1VsXIYo+7eSpIY67VzrCoh41wXPklOWS6CV8RR/JBSqq
413) 8lHkcz8L21lMCOrVR1Cs0ls4HLIhUkqr9YegTJ67VM7xevUsgOI7BkPDldiulRgX+sdPheCyCacu
414) e7/b/nk0SXWF7ZBxsR1awYqwkFKz41/1bZDsETsmd8n1DHycGIvRULv3yYhKcvWQ4asAMhP1ks5k
415) AgOcrM+JFvpYA86Ja8HCqCg8LihEI1e7+m8F71Lpavv/UEsDBBQAAAAIAJ1WGVnKO2Ji+AEAAGsC
416) AAACAAAAMWENx7dyo0AAANDen+GWAonMzbggLsJakgGBOhBLlGBZsjz373eve7+fKyJTM/Sff85/
417) P5QMwMFfAWipfXwvFPWU582cd3t7JVV5pBV0Y1clL4eKUd0w1m1M5JrkgW5PlfpOVedgABSe4zPY
418) LnSIZVuen5Eua9QY8lQ7rxW7YIqeajhgLfL54BIcY90fd8ANixlcM8V23Z03U35Txba0BbSguc0f
419) NRF83cWp+7rOYgNO9wWLs915oQmWAqAtqRYCiWlgAtxYFg0MnNS4/G80FvFmQTh0cjwcF1xEVPeW
420) l72ky84PEA0QMgRtQW+HXWtE0/vQTtNKzvNqPfrGZCldL5nk9PWhhPEQ/azyW11bz2eB+aM0g0r7
421) 0/5YkO9er10YonsBT1rEn0lfBXDHwtwbxG2bdqELTuEtX2+OEih7K43rN2EvpXX47azaNpe/drIz
422) wgAdhpfZ/mZwaGFX0c7r5HCTnroNRi5Bx/vu7m1A7Nt1dix4Gl/aPLCWQzpwmdIMJDiqD1RGpc5v
423) +pDLrpfhZOVhLjAPSQ0V7mm/XNSca8oIsDjwdvR438RQCU56mrlypklS4/tJAe0JZNZIgBmJszjG
424) AFbsmNYTJ9GmULB9lXmTWmrME592S285iWU5SsJcE1s+3oQw9QrvWB+e3bGAd9e+VFmFqr6+/gFQ
425) SwECHgMUAAAACACdVhlZ01RRk9IAAADmAAAABQAAAAAAAAABAAAApIEAAAAALmtleXNQSwECHgMU
426) AAAACACdVhlZ3Wlf4QUDAADUAwAAAgAAAAAAAAABAAAApIH1AAAAMDBQSwECHgMUAAAACACdVhlZ
427) /aaiwcoBAAArAgAAAgAAAAAAAAABAAAApIEaBAAAMDNQSwECHgMUAAAACACdVhlZs14oCcgBAAAr
428) AgAAAgAAAAAAAAABAAAApIEEBgAAMDlQSwECHgMUAAAACACdVhlZyjtiYvgBAABrAgAAAgAAAAAA
429) AAABAAAApIHsBwAAMWFQSwUGAAAAAAUABQDzAAAABAoAAAAA
430) """
431) VAULT_STOREROOM_CONFIG_DATA = {
432)     'global': {
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

433)         'phrase': DUMMY_PASSPHRASE.rstrip('\n'),
Marco Ricci Move exporter command-line...

Marco Ricci authored 2 months ago

434)     },
435)     'services': {
436)         '(meta)': {
437)             'notes': 'This config was originally in storeroom format.',
438)         },
439)         DUMMY_SERVICE: DUMMY_CONFIG_SETTINGS.copy(),
440)     },
441) }
442) 
Marco Ricci Add more tests of the store...

Marco Ricci authored 2 months ago

443) _VAULT_STOREROOM_BROKEN_DIR_CONFIG_ZIPPED_JAVASCRIPT_SOURCE = """
444) // Executed in the top-level directory of the vault project code, in Node.js.
445) const storeroom = require('storeroom')
446) const Store = require('./lib/store.js')
447) let store = new Store(storeroom.createFileAdapter('./broken-dir', 'vault key'))
448) await store._storeroom.put('/services/array/', ['entry1','entry2'])
449) // The resulting "broken-dir" was then zipped manually.
450) """
451) VAULT_STOREROOM_BROKEN_DIR_CONFIG_ZIPPED = b"""
452) UEsDBBQAAgAIAHijH1kjc0ql0gAAAOYAAAAFAAAALmtleXMFwclygjAAANB7P8Mrh7LIYmd6oGxC
453) HKwTJJgbNpBKCpGAhNTpv/e952ZpxHTjw+bN+HuJJABEikvHecD0pLgpgYKWjue0CZGk19mKF+4f
454) 0AoLrXKh+ckk13nmxVk/KFE28eEHkBgJTISvRUVMQ0N5aRapLgWs/M7NSXV7qs0s2aIEstUG5FHv
455) fo/HKjpdUJMGK86vs2rOJFGyrx9ZK4iWW+LefwSTYxhYOlWpb0PpgXsV4dHNTz5skcJqpPUudZf9
456) jCFD0vxChL6ajm0P0prY+z9QSwMEFAACAAgAeKMfWX4L7vDYAQAAPwIAAAIAAAAwNQXByZKiMAAA
457) 0Ht/Rl85sIR1qvqAouxbJAG8kWYxgCKICEzNv897f7+XanrR4fH9h//3pVdF8qmVeWjW+STwSbak
458) 4e3CS00h2AcrQIcghm0lOcrLdJfuaOFqg5zEsW9lTbJMtIId5ezNGM9jPKaxeriXXm45pGuHCwFP
459) /gmcXKWGeU3sHfj93iIf6p0xrfQIGGJOvayKjzypUqb99Bllo9IwNP2FZjxmBWDw0NRzJrxr/4Qj
460) qp4ted4f91ZaR8+64C0BJBzDngElJEFLdA2WBcip2R/VZIG219WT3JlkbFrYSjhHWeb47igytTpo
461) USPjEJWVol0cVpD6iX1/mGM2BpHAFa+fLx3trXgbXaVmjyZVzUKDh/XqnovnLs529UGYCAdj8Xnx
462) vWwfWclm5uIB8cHbElx6G82Zs8RQnkDsyGVDbNaMOO7lMQF7o1Uy7Q9GuSWcFMK4KBAbcwm4l8RY
463) +2ema46H3/S31IW1LOFpoZxjwyBS69dWS7/ulVxJfbuydMvZMeWpmerjUHnKaQdumibSeSOXh+zg
464) XU6w6SsKAjHWXCTjRehWmyNnI7z3+epr1RzUlnDcUMiYQ/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nCx3RRFgttiJTydfkB9MeZ9pvxP9jUm/fndQfJI83CsBxcEWhbjzlEparc3VS2s4LjR
479) 3Xafw3HLSlPqylHOWK2vc2ZJoObwqrCaFRg7kz1+z08SGu8pe0EHaII6FSxL7VM+rfVgpc1045Ut
480) 6ayCQ0TwRL5m4oMYkZbFnivCBTY3Cdji2SQ+gh8m3A6YkFxXUH0Vz9Is8JZaLFyi24GjyZZ9rGuk
481) Y6w53oLyTF/fSzG24ghCDZ6pOgB5qyfk4z2mUmH7pwxNCoHZ1oaxeTSn039QSwECHgMUAAIACAB4
482) ox9ZI3NKpdIAAADmAAAABQAAAAAAAAABAAAApIEAAAAALmtleXNQSwECHgMUAAIACAB4ox9Zfgvu
483) 8NgBAAA/AgAAAgAAAAAAAAABAAAApIH1AAAAMDVQSwECHgMUAAIACAB4ox9ZRdFTaLsBAAAXAgAA
484) AgAAAAAAAAABAAAApIHtAgAAMWFQSwECHgMUAAIACAB4ox9ZGgj3mrkBAAAXAgAAAgAAAAAAAAAB
485) AAAApIHIBAAAMWVQSwUGAAAAAAQABADDAAAAoQYAAAAA
486) """
487) 
Marco Ricci Move exporter command-line...

Marco Ricci authored 2 months ago

488) CANNOT_LOAD_CRYPTOGRAPHY = (
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

489)     'Cannot load the required Python module "cryptography".'
Marco Ricci Move exporter command-line...

Marco Ricci authored 2 months ago

490) )
491) 
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

492) skip_if_no_agent = pytest.mark.skipif(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

493)     not os.environ.get('SSH_AUTH_SOCK'), reason='running SSH agent required'
494) )
Marco Ricci Test exporter data loading...

Marco Ricci authored 2 months ago

495) skip_if_cryptography_support = pytest.mark.skipif(
496)     importlib.util.find_spec('cryptography') is not None,
497)     reason='cryptography support available; cannot test "no support" scenario',
498) )
499) skip_if_no_cryptography_support = pytest.mark.skipif(
500)     importlib.util.find_spec('cryptography') is None,
501)     reason='no "cryptography" support',
502) )
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

503) 
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

504) 
Marco Ricci Consolidate `types` submodu...

Marco Ricci authored 3 months ago

505) def list_keys(self: Any = None) -> list[_types.KeyCommentPair]:
Marco Ricci Fix style issues with ruff...

Marco Ricci authored 3 months ago

506)     del self  # Unused.
Marco Ricci Consolidate `types` submodu...

Marco Ricci authored 3 months ago

507)     Pair = _types.KeyCommentPair  # noqa: N806
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

508)     list1 = [
509)         Pair(value['public_key_data'], f'{key} test key'.encode('ASCII'))
510)         for key, value in SUPPORTED_KEYS.items()
511)     ]
512)     list2 = [
513)         Pair(value['public_key_data'], f'{key} test key'.encode('ASCII'))
514)         for key, value in UNSUITABLE_KEYS.items()
515)     ]
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

516)     return list1 + list2
517) 
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

518) 
Marco Ricci Consolidate `types` submodu...

Marco Ricci authored 3 months ago

519) def list_keys_singleton(self: Any = None) -> list[_types.KeyCommentPair]:
Marco Ricci Fix style issues with ruff...

Marco Ricci authored 3 months ago

520)     del self  # Unused.
Marco Ricci Consolidate `types` submodu...

Marco Ricci authored 3 months ago

521)     Pair = _types.KeyCommentPair  # noqa: N806
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

522)     list1 = [
523)         Pair(value['public_key_data'], f'{key} test key'.encode('ASCII'))
524)         for key, value in SUPPORTED_KEYS.items()
525)     ]
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

526)     return list1[:1]
527) 
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

528) 
Marco Ricci Consolidate `types` submodu...

Marco Ricci authored 3 months ago

529) def suitable_ssh_keys(conn: Any) -> Iterator[_types.KeyCommentPair]:
Marco Ricci Fix style issues with ruff...

Marco Ricci authored 3 months ago

530)     del conn  # Unused.
Marco Ricci Consolidate `types` submodu...

Marco Ricci authored 3 months ago

531)     Pair = _types.KeyCommentPair  # noqa: N806
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

532)     yield from [
Marco Ricci Move `sequin` and `ssh_agen...

Marco Ricci authored 3 months ago

533)         Pair(DUMMY_KEY1, b'no comment'),
534)         Pair(DUMMY_KEY2, b'a comment'),
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

535)     ]
536) 
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

537) 
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

538) def phrase_from_key(key: bytes) -> bytes:
539)     if key == DUMMY_KEY1:  # pragma: no branch
540)         return DUMMY_PHRASE_FROM_KEY1
541)     raise KeyError(key)  # pragma: no cover
542) 
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

543) 
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

544) @contextlib.contextmanager
545) def isolated_config(
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

546)     monkeypatch: pytest.MonkeyPatch,
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

547)     runner: click.testing.CliRunner,
Marco Ricci Fix typing issues in mypy s...

Marco Ricci authored 3 months ago

548) ) -> Iterator[None]:
Marco Ricci Consolidate `types` submodu...

Marco Ricci authored 3 months ago

549)     prog_name = cli.PROG_NAME
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

550)     env_name = prog_name.replace(' ', '_').upper() + '_PATH'
551)     with runner.isolated_filesystem():
552)         monkeypatch.setenv('HOME', os.getcwd())
553)         monkeypatch.setenv('USERPROFILE', os.getcwd())
554)         monkeypatch.delenv(env_name, raising=False)
Marco Ricci Rename the configuration fi...

Marco Ricci authored 2 months ago

555)         config_dir = cli._config_filename(subsystem=None)
556)         os.makedirs(config_dir, exist_ok=True)
Marco Ricci Modularize test helpers to...

Marco Ricci authored 2 months ago

557)         yield
558) 
559) 
560) @contextlib.contextmanager
561) def isolated_vault_config(
562)     monkeypatch: pytest.MonkeyPatch,
563)     runner: click.testing.CliRunner,
564)     config: Any,
565) ) -> Iterator[None]:
566)     with isolated_config(monkeypatch=monkeypatch, runner=runner):
Marco Ricci Rename the configuration fi...

Marco Ricci authored 2 months ago

567)         config_filename = cli._config_filename(subsystem='vault')
568)         with open(config_filename, 'w', encoding='UTF-8') as outfile:
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

569)             json.dump(config, outfile)
570)         yield
571) 
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

572) 
Marco Ricci Add preliminary tests for t...

Marco Ricci authored 2 months ago

573) @contextlib.contextmanager
574) def isolated_vault_exporter_config(
575)     monkeypatch: pytest.MonkeyPatch,
576)     runner: click.testing.CliRunner,
577)     vault_config: str | bytes | None = None,
578)     vault_key: str | None = None,
579) ) -> Iterator[None]:
580)     if TYPE_CHECKING:
581)         chdir = contextlib.chdir
582)     else:
583)         try:
584)             chdir = contextlib.chdir
585)         except AttributeError:
586) 
587)             @contextlib.contextmanager
Marco Ricci Move exporter command-line...

Marco Ricci authored 2 months ago

588)             def chdir(newpath: str) -> Iterator[None]:  # pragma: no branch
Marco Ricci Add preliminary tests for t...

Marco Ricci authored 2 months ago

589)                 oldpath = os.getcwd()
590)                 os.chdir(newpath)
591)                 yield
592)                 os.chdir(oldpath)
593) 
594)     with runner.isolated_filesystem():
595)         monkeypatch.setenv('HOME', os.getcwd())
596)         monkeypatch.setenv('USERPROFILE', os.getcwd())
597)         monkeypatch.delenv('VAULT_PATH', raising=False)
598)         monkeypatch.delenv('VAULT_KEY', raising=False)
599)         monkeypatch.delenv('LOGNAME', raising=False)
600)         monkeypatch.delenv('USER', raising=False)
601)         monkeypatch.delenv('USERNAME', raising=False)
602)         if vault_key is not None:
603)             monkeypatch.setenv('VAULT_KEY', vault_key)
604)         match vault_config:
605)             case str():
606)                 with open('.vault', 'w', encoding='UTF-8') as outfile:
607)                     print(vault_config, file=outfile)
608)             case bytes():
609)                 os.makedirs('.vault', mode=0o700, exist_ok=True)
610)                 with (
611)                     chdir('.vault'),
612)                     tempfile.NamedTemporaryFile(suffix='.zip') as tmpzipfile,
613)                 ):
614)                     for line in vault_config.splitlines():
615)                         tmpzipfile.write(base64.standard_b64decode(line))
616)                     tmpzipfile.flush()
617)                     tmpzipfile.seek(0, 0)
618)                     with zipfile.ZipFile(tmpzipfile.file) as zipfileobj:
619)                         zipfileobj.extractall()
620)             case None:
621)                 pass
622)             case _:  # pragma: no cover
623)                 assert_never(vault_config)
624)         yield
625) 
626) 
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

627) def auto_prompt(*args: Any, **kwargs: Any) -> str:
Marco Ricci Fix style issues with ruff...

Marco Ricci authored 3 months ago

628)     del args, kwargs  # Unused.
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

629)     return DUMMY_PASSPHRASE
Marco Ricci Add missing tests for rewor...

Marco Ricci authored 2 months ago

630) 
631) 
632) def make_file_readonly(
633)     pathname: str | bytes | os.PathLike[str],
634)     /,
635)     *,
636)     try_race_free_implementation: bool = True,
637) ) -> None:
638)     """Mark a file as read-only.
639) 
640)     On POSIX, this entails removing the write permission bits for user,
641)     group and other, and ensuring the read permission bit for user is
642)     set.
643) 
644)     Unfortunately, Windows has its own rules: Set exactly(?) the read
645)     permission bit for user to make the file read-only, and set
646)     exactly(?) the write permission bit for user to make the file
647)     read/write; all other permission bit settings are ignored.
648) 
649)     The cross-platform procedure therefore is:
650) 
651)     1. Call `os.stat` on the file, noting the permission bits.
652)     2. Calculate the new permission bits POSIX-style.
653)     3. Call `os.chmod` with permission bit `stat.S_IREAD`.
654)     4. Call `os.chmod` with the correct POSIX-style permissions.
655) 
656)     If the platform supports it, we use a file descriptor instead of
657)     a path name.  Otherwise, we use the same path name multiple times,
658)     and are susceptible to race conditions.
659) 
660)     """
661)     fname: int | str | bytes | os.PathLike[str]
662)     if try_race_free_implementation and {os.stat, os.chmod} <= os.supports_fd:
663)         fname = os.open(
664)             pathname,
665)             os.O_RDONLY
666)             | getattr(os, 'O_CLOEXEC', 0)
667)             | getattr(os, 'O_NOCTTY', 0),
668)         )
669)     else:
670)         fname = pathname
671)     try:
672)         orig_mode = os.stat(fname).st_mode
673)         new_mode = (
674)             orig_mode & ~stat.S_IWUSR & ~stat.S_IWGRP & ~stat.S_IWOTH
675)             | stat.S_IREAD
676)         )
677)         os.chmod(fname, stat.S_IREAD)
678)         os.chmod(fname, new_mode)
679)     finally:
680)         if isinstance(fname, int):
681)             os.close(fname)