test_kms_server 5.24.0

Run a test KMS server for testing purposes
Documentation
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
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
use std::{
    collections::HashMap,
    path::{Path, PathBuf},
};

use cosmian_kms_client::{
    KmsClient, KmsClientConfig, KmsClientError,
    cosmian_kmip::{
        kmip_2_1::extra::tagging::VENDOR_ID_COSMIAN,
        ttlv::{KmipFlavor, TTLV, enum_lookup::lookup_enum_code},
    },
    reexport::cosmian_kms_access::access::Access,
};
use serde::Deserialize;
use tokio::sync::OnceCell;

use crate::TestsContext;

/// Singleton server for vector tests on the `SQLite` backend.
static ONCE_VECTOR_SQLITE: OnceCell<TestsContext> = OnceCell::const_new();
/// Singleton server for vector tests on the `PostgreSQL` backend.
static ONCE_VECTOR_POSTGRESQL: OnceCell<TestsContext> = OnceCell::const_new();
/// Singleton server for vector tests on the `MySQL` backend.
static ONCE_VECTOR_MYSQL: OnceCell<TestsContext> = OnceCell::const_new();
/// Singleton server for vector tests on the `Redis-findex` backend.
static ONCE_VECTOR_REDIS_FINDEX: OnceCell<TestsContext> = OnceCell::const_new();
/// Singleton server for vector tests requiring mTLS cert-auth (`cert_auth.toml`).
static ONCE_VECTOR_CERT_AUTH: OnceCell<TestsContext> = OnceCell::const_new();
/// Singleton server for vector tests requiring server-only TLS (`auth_https.toml`).
static ONCE_VECTOR_AUTH_HTTPS: OnceCell<TestsContext> = OnceCell::const_new();
/// Singleton server for vector tests requiring `SoftHSM2` + KEK.
static ONCE_VECTOR_HSM_KEK: OnceCell<TestsContext> = OnceCell::const_new();

/// A test vector manifest loaded from a TOML file.
///
/// Each test vector directory contains a `manifest.toml` and one or more
/// step JSON files (TTLV-JSON request payloads).
///
/// # Example
///
/// ```toml
/// name = "AES Create, Encrypt, Decrypt"
/// description = "Full lifecycle of an AES-256 symmetric key"
/// server_config = "test_data/configs/server/test/auth_plain.toml"
///
/// [[steps]]
/// operation = "Create"
/// request = "step1_request.json"
/// assert_success = true
///
/// [steps.assert_fields]
/// ObjectType = "SymmetricKey"
///
/// [steps.capture]
/// key_id = "UniqueIdentifier"
///
/// [[steps]]
/// operation = "Encrypt"
/// request = "step2_request.json"
/// assert_success = true
///
/// [steps.capture]
/// ciphertext = "Data"
/// ```
#[derive(Debug, Deserialize)]
pub struct TestManifest {
    /// Human-readable name for the test vector
    pub name: String,
    /// Optional description
    pub description: Option<String>,
    /// Path to a TOML server config file (relative to the repo root).
    /// If omitted, defaults to `test_data/configs/server/test/auth_plain.toml`.
    pub server_config: Option<String>,
    /// Server type to use for this vector.
    ///
    /// Controls which singleton server is started:
    /// - `"hsm_kek"` — `SoftHSM2` with a Key Encryption Key (uses `ONCE_VECTOR_HSM_KEK`)
    /// - anything else or omitted — standard backend-driven servers
    pub server_type: Option<String>,
    /// Environment variables required to run this vector.
    ///
    /// If any variable in this list is not set, the vector is skipped gracefully.
    /// Used for HSM tests that require `HSM_SLOT_ID` to be set by the CI script.
    #[serde(default)]
    pub requires_env: Vec<String>,
    /// Database backends this vector should be tested against.
    ///
    /// Defaults to `["sqlite"]`. When `KMS_TEST_BACKENDS` env var is set
    /// (comma-separated list), the runner intersects it with this list and
    /// runs the vector once per matching backend.
    ///
    /// Supported values: `"sqlite"`, `"postgresql"`, `"mysql"`, `"redis-findex"`.
    ///
    /// Each backend maps to a config TOML override:
    /// - `sqlite` → default (`auth_plain.toml` or `server_config`)
    /// - `postgresql` → `test_data/configs/server/test/postgres.toml`
    /// - `mysql` → `test_data/configs/server/test/mysql.toml`
    /// - `redis-findex` → `test_data/configs/server/test/redis_findex.toml`
    #[serde(default = "default_backends")]
    pub backends: Vec<String>,
    /// Wire format: `"json"` (default) or `"binary"`.
    /// When `"binary"`, requests are serialized as TTLV binary bytes, wrapped in a
    /// `RequestMessage` envelope, and sent to `/kmip` with `application/octet-stream`.
    /// Responses are parsed from TTLV binary back to JSON for assertions.
    #[serde(default = "default_json")]
    pub wire_format: String,
    /// KMIP protocol version for binary wire format: `[major, minor]`.
    /// Default is `[2, 1]`. Use `[1, 4]` for KMIP 1.4 integration tests.
    #[serde(default = "default_kmip_version")]
    pub kmip_version: [i32; 2],
    /// Named client identities for multi-user tests.
    ///
    /// Keys are identity names (e.g. "owner", "user"); values contain cert/key paths
    /// relative to the repo root.  Steps reference identities via their `identity` field.
    /// If a step's identity is not found here, the default owner client is used.
    ///
    /// Example:
    /// ```toml
    /// [identities.owner]
    /// client_cert = "test_data/certificates/client_server/owner/owner.client.acme.com.crt"
    /// client_key  = "test_data/certificates/client_server/owner/owner.client.acme.com.key"
    ///
    /// [identities.user]
    /// client_cert = "test_data/certificates/client_server/user/user.client.acme.com.crt"
    /// client_key  = "test_data/certificates/client_server/user/user.client.acme.com.key"
    /// ```
    #[serde(default)]
    pub identities: HashMap<String, IdentityConfig>,
    /// Ordered list of KMIP request steps to execute
    pub steps: Vec<TestStep>,
}

/// TLS client-certificate identity for a specific user in a test vector.
///
/// Paths are relative to the repository root.
/// On macOS (native-tls / Security.framework), PEM identity loading is not
/// supported. The runner auto-detects a `.p12` file next to the `.crt` and
/// uses it with password `"password"` (standard test infrastructure convention).
#[derive(Debug, Deserialize, Clone)]
pub struct IdentityConfig {
    /// Path to the PEM client certificate
    pub client_cert: String,
    /// Path to the PEM client private key
    pub client_key: String,
}

/// A single request–response step in a test vector.
#[derive(Debug, Deserialize)]
pub struct TestStep {
    /// KMIP operation name (informational; included in error messages).
    ///
    /// Use `"GrantAccess"` or `"RevokeAccess"` for the Cosmian access-control
    /// REST endpoints (`POST /access/grant` and `POST /access/revoke`).  These
    /// are not KMIP operations; the request file should be a JSON object with
    /// fields `user_id`, `unique_identifier`, and `operation_types`.
    pub operation: String,
    /// Filename of the TTLV-JSON request payload (relative to the vector directory).
    /// For `GrantAccess`/`RevokeAccess` steps the file must contain a JSON object
    /// matching the `Access` struct (`user_id`, `unique_identifier`, `operation_types`).
    pub request: String,
    /// When `true`, assert that `ResultStatus` == "Success" (KMIP) or HTTP 2xx (REST).
    #[serde(default = "default_true")]
    pub assert_success: bool,
    /// Field assertions on the response TTLV.
    /// Keys are TTLV tag names; values are the expected string representations.
    /// The assertion walks the response tree looking for a matching tag and checks
    /// that the leaf value matches the expected string.
    #[serde(default)]
    pub assert_fields: HashMap<String, String>,
    /// Like `assert_fields`, but checks that the expected value is present in **any**
    /// occurrence of the tag in the response (useful for `Locate` responses that
    /// return multiple `UniqueIdentifier` items — only one of them needs to match).
    #[serde(default)]
    pub assert_any_field: HashMap<String, String>,
    /// Opposite of `assert_any_field`: asserts that **no** occurrence of the tag has
    /// the given value. Useful to verify that a specific object is NOT returned by
    /// Locate (e.g. a key not granted to the requesting user).
    /// Supports `{{captured}}` and `{{$ENV}}` variable substitution.
    #[serde(default)]
    pub assert_none_field: HashMap<String, String>,
    /// Assert that these TTLV tags are **absent** from the response.
    /// Useful to verify fields have been properly removed (e.g. Veeam compatibility).
    #[serde(default)]
    pub assert_fields_absent: Vec<String>,
    /// Assert the number of occurrences of a given TTLV tag in the response.
    /// Keys are TTLV tag names; values are the expected count.
    /// Useful for `Locate` responses to verify exactly how many objects are returned.
    ///
    /// Example: `assert_count = { UniqueIdentifier = 2 }` checks that the response
    /// contains exactly 2 `UniqueIdentifier` tags.
    #[serde(default)]
    pub assert_count: HashMap<String, usize>,
    /// When `assert_success` is `false`, optionally assert that the error response
    /// contains a specific `ResultReason` value (e.g. `"Item_Not_Found"`).
    pub assert_error_reason: Option<String>,
    /// When `assert_success` is `false`, optionally assert that `ResultMessage`
    /// contains this substring.
    pub assert_error_contains: Option<String>,
    /// Values to capture from the response for use in subsequent steps.
    /// Keys are capture variable names (used as `{{name}}` in later request files);
    /// values are the TTLV tag name whose leaf value should be captured.
    #[serde(default)]
    pub capture: HashMap<String, String>,
    /// When `true`, the request JSON file contains a complete `RequestMessage` envelope
    /// (with `RequestHeader`, `BatchItem`(s), etc.) and should be sent as-is without
    /// wrapping. Use this for batched requests (`BatchCount` > 1) or when the request
    /// needs custom header fields (e.g. `Authentication`, `BatchOrderOption`).
    /// Placeholder `{{variable}}` substitution still applies.
    #[serde(default)]
    pub raw_request: bool,
    /// Named identity to use for this step (must match a key in `[identities]`).
    ///
    /// When absent, defaults to `"owner"` (the default client from `TestsContext`).
    /// Set to `"user"` (or any other name defined in `[identities]`) to send this
    /// request using a different client certificate.
    ///
    /// Example in manifest:
    /// ```toml
    /// [[steps]]
    /// operation = "Get"
    /// request   = "step_get.json"
    /// identity  = "user"
    /// ```
    pub identity: Option<String>,
    /// When `true`, the step outcome (success or failure) is ignored.
    /// Useful for cleanup/setup steps that may or may not succeed (e.g. destroying
    /// a key that may not exist from a prior run).
    #[serde(default)]
    pub allow_failure: bool,
}

const fn default_true() -> bool {
    true
}

fn default_json() -> String {
    "json".to_owned()
}

fn default_backends() -> Vec<String> {
    vec![
        "sqlite".to_owned(),
        "postgresql".to_owned(),
        "mysql".to_owned(),
        "redis-findex".to_owned(),
    ]
}

const fn default_kmip_version() -> [i32; 2] {
    [2, 1]
}

/// Wrap a bare KMIP operation TTLV-JSON in a `RequestMessage` envelope.
///
/// Transforms `{ "tag": "Create", "value": [...] }` into a full
/// `RequestMessage` with `RequestHeader` (protocol version, batch count)
/// and a single `BatchItem` (operation enum + request payload).
fn wrap_in_request_message(
    bare_op_json: &serde_json::Value,
    major: i32,
    minor: i32,
) -> serde_json::Value {
    let tag = bare_op_json
        .get("tag")
        .and_then(|t| t.as_str())
        .unwrap_or("Unknown");
    // Map TTLV tag names to OperationEnumeration variant names
    // (TTLV tags use PascalCase, but some enum variants differ)
    let w = match tag {
        "Mac" => "MAC",
        "MacVerify" => "MACVerify",
        _ => tag,
    };
    let children = bare_op_json
        .get("value")
        .cloned()
        .unwrap_or(serde_json::json!([]));

    serde_json::json!({
        "tag": "RequestMessage",
        "value": [
            {
                "tag": "RequestHeader",
                "value": [
                    {
                        "tag": "ProtocolVersion",
                        "value": [
                            { "tag": "ProtocolVersionMajor", "type": "Integer", "value": major },
                            { "tag": "ProtocolVersionMinor", "type": "Integer", "value": minor }
                        ]
                    },
                    { "tag": "BatchCount", "type": "Integer", "value": 1 }
                ]
            },
            {
                "tag": "BatchItem",
                "value": [
                    { "tag": "Operation", "type": "Enumeration", "value": w },
                    {
                        "tag": "RequestPayload",
                        "value": children
                    }
                ]
            }
        ]
    })
}

/// Send a binary TTLV request and return the response as JSON.
///
/// Converts TTLV-JSON → TTLV struct → binary bytes, POSTs to `/kmip`
/// with `application/octet-stream`, then parses the response binary
/// back to TTLV → JSON for assertion.
///
/// When `raw_request` is `true`, `request_json` is already a complete
/// `RequestMessage` and will not be wrapped in an envelope.
async fn send_binary_request(
    client: &cosmian_kms_client::KmsClient,
    binary_url: &str,
    request_json: &serde_json::Value,
    kmip_version: [i32; 2],
    step_index: usize,
    step_operation: &str,
    raw_request: bool,
) -> Result<serde_json::Value, KmsClientError> {
    let kmip_flavor = if kmip_version[0] == 1 {
        KmipFlavor::Kmip1
    } else {
        KmipFlavor::Kmip2
    };

    // Wrap bare operation in RequestMessage envelope, or use as-is for raw requests
    let request_message = if raw_request {
        request_json.clone()
    } else {
        wrap_in_request_message(request_json, kmip_version[0], kmip_version[1])
    };

    // JSON → TTLV struct
    let mut request_ttlv: TTLV = serde_json::from_value(request_message).map_err(|e| {
        KmsClientError::UnexpectedError(format!(
            "Step {step_index} '{step_operation}': failed to parse TTLV JSON: {e}"
        ))
    })?;

    // Resolve enum names (e.g. "Create", "AES") to their numeric KMIP codes.
    // JSON deserialization sets enum `value` to 0 with only the `name` populated;
    // the binary serializer requires the numeric `value`.
    request_ttlv.resolve_enumeration_values();

    // TTLV struct → binary bytes
    let request_bytes = request_ttlv.to_bytes(kmip_flavor).map_err(|e| {
        KmsClientError::UnexpectedError(format!(
            "Step {step_index} '{step_operation}': failed to serialize TTLV to binary: {e}"
        ))
    })?;

    // POST binary
    let response = client
        .client
        .post_bytes(binary_url, request_bytes, "application/octet-stream")
        .await
        .map_err(|e| {
            KmsClientError::UnexpectedError(format!(
                "Step {step_index} '{step_operation}': HTTP request failed: {e}"
            ))
        })?;

    let response_bytes = response.bytes();

    // binary bytes → TTLV struct → JSON
    if response_bytes.is_empty() {
        return Err(KmsClientError::UnexpectedError(format!(
            "Step {step_index} '{step_operation}': empty binary response"
        )));
    }

    let response_ttlv = TTLV::from_bytes(response_bytes, kmip_flavor).map_err(|e| {
        KmsClientError::UnexpectedError(format!(
            "Step {step_index} '{step_operation}': failed to parse binary TTLV response: {e}"
        ))
    })?;

    let response_json = serde_json::to_value(&response_ttlv).map_err(|e| {
        KmsClientError::UnexpectedError(format!(
            "Step {step_index} '{step_operation}': failed to convert TTLV response to JSON: {e}"
        ))
    })?;

    Ok(response_json)
}

/// Load a test vector manifest from a TOML file.
pub fn load_manifest(manifest_path: &Path) -> Result<TestManifest, KmsClientError> {
    let content = std::fs::read_to_string(manifest_path).map_err(|e| {
        KmsClientError::UnexpectedError(format!(
            "Cannot read test vector manifest at {}: {e}",
            manifest_path.display()
        ))
    })?;
    toml::from_str(&content).map_err(|e| {
        KmsClientError::UnexpectedError(format!(
            "Cannot parse test vector manifest at {}: {e}",
            manifest_path.display()
        ))
    })
}

/// Load a TTLV-JSON request payload, substituting `{{variable}}` placeholders
/// with captured values from previous steps, and `{{$ENV_VAR}}` placeholders
/// with environment variable values.
fn load_request_json(
    path: &Path,
    captures: &HashMap<String, String>,
) -> Result<serde_json::Value, KmsClientError> {
    let mut content = std::fs::read_to_string(path).map_err(|e| {
        KmsClientError::UnexpectedError(format!(
            "Cannot read request JSON at {}: {e}",
            path.display()
        ))
    })?;

    // Substitute environment variable placeholders {{$VAR_NAME}} first
    while let Some(start) = content.find("{{$") {
        let rest = &content[start + 3..];
        let end = rest.find("}}").ok_or_else(|| {
            KmsClientError::UnexpectedError(format!(
                "Unclosed env-var placeholder in {}: found '{{{{$' without matching '}}}}'",
                path.display()
            ))
        })?;
        let var_name = &rest[..end];
        let var_value = std::env::var(var_name).map_err(|_e| {
            KmsClientError::UnexpectedError(format!(
                "Environment variable '{var_name}' referenced in {} is not set",
                path.display()
            ))
        })?;
        content = format!(
            "{}{var_value}{}",
            &content[..start],
            &content[start + 3 + end + 2..]
        );
    }

    // Substitute all {{variable}} placeholders (captured values)
    for (name, value) in captures {
        content = content.replace(&format!("{{{{{name}}}}}"), value);
    }

    serde_json::from_str(&content).map_err(|e| {
        KmsClientError::UnexpectedError(format!(
            "Cannot parse request JSON at {} (after placeholder substitution): {e}",
            path.display()
        ))
    })
}

/// Resolve `{{$ENV_VAR}}` and `{{captured}}` placeholders in an assertion value.
///
/// Returns an error if a referenced environment variable is not set or a captured
/// placeholder was never populated. This ensures test vectors never silently
/// pass with empty/default values.
fn resolve_assertion_value(
    template: &str,
    captures: &HashMap<String, String>,
) -> Result<String, KmsClientError> {
    let mut result = template.to_owned();
    // Substitute environment variable placeholders {{$VAR_NAME}}
    while let Some(start) = result.find("{{$") {
        let rest = &result[start + 3..];
        if let Some(end) = rest.find("}}") {
            let var_name = &rest[..end];
            let var_value = std::env::var(var_name).map_err(|_err| {
                KmsClientError::UnexpectedError(format!(
                    "resolve_assertion_value: environment variable '{var_name}' \
                     referenced in assertion template '{template}' is not set — \
                     refusing to silently use an empty string"
                ))
            })?;
            result = format!("{}{}{}", &result[..start], var_value, &rest[end + 2..]);
        } else {
            break;
        }
    }
    // Substitute captured variable placeholders {{name}}
    for (name, value) in captures {
        result = result.replace(&format!("{{{{{name}}}}}"), value);
    }
    // Fail loudly if any unresolved placeholder remains (typo in capture name)
    if let Some(pos) = result.find("{{") {
        if result[pos..].contains("}}") {
            return Err(KmsClientError::UnexpectedError(format!(
                "resolve_assertion_value: unresolved placeholder in assertion \
                 template '{template}' — result after substitution: '{result}'. \
                 Check for typos in capture variable names."
            )));
        }
    }
    Ok(result)
}

/// Collect ALL leaf values for a given tag name in the TTLV JSON tree.
fn find_all_fields_in_json(value: &serde_json::Value, tag: &str) -> Vec<String> {
    let mut results = Vec::new();
    find_all_fields_impl(value, tag, &mut results);
    results
}

fn find_all_fields_impl(value: &serde_json::Value, tag: &str, out: &mut Vec<String>) {
    match value {
        serde_json::Value::Object(map) => {
            if let Some(serde_json::Value::String(t)) = map.get("tag") {
                if t == tag {
                    if let Some(v) = map.get("value") {
                        let s = match v {
                            serde_json::Value::String(s) => Some(s.clone()),
                            serde_json::Value::Number(n) => Some(n.to_string()),
                            serde_json::Value::Bool(b) => Some(b.to_string()),
                            serde_json::Value::Array(_) => None,
                            _ => Some(v.to_string()),
                        };
                        if let Some(s) = s {
                            out.push(s);
                        }
                    }
                }
            }
            if let Some(serde_json::Value::Array(children)) = map.get("value") {
                for child in children {
                    find_all_fields_impl(child, tag, out);
                }
            }
        }
        serde_json::Value::Array(arr) => {
            for item in arr {
                find_all_fields_impl(item, tag, out);
            }
        }
        _ => {}
    }
}

/// Find the first leaf value in a TTLV JSON tree matching the given tag name.
fn find_field_in_json(value: &serde_json::Value, tag: &str) -> Option<String> {
    find_all_fields_in_json(value, tag).into_iter().next()
}

/// Assert that a response TTLV JSON contains the expected field values.
fn assert_response_fields(
    response: &serde_json::Value,
    assertions: &HashMap<String, String>,
    step_operation: &str,
) -> Result<(), KmsClientError> {
    for (tag, expected) in assertions {
        let actual = find_field_in_json(response, tag).ok_or_else(|| {
            KmsClientError::UnexpectedError(format!(
                "Step '{step_operation}': expected field '{tag}' not found in response"
            ))
        })?;
        if actual != *expected {
            // Binary TTLV responses encode enumerations as hex (e.g. "0x00000002").
            // If the expected value is a known enum name, resolve it and compare
            // against the hex form.
            let matches_via_enum = actual.starts_with("0x")
                && lookup_enum_code(expected)
                    .is_some_and(|(code, _)| actual == format!("0x{code:08X}"));
            if !matches_via_enum {
                return Err(KmsClientError::UnexpectedError(format!(
                    "Step '{step_operation}': field '{tag}' expected '{expected}', got '{actual}'"
                )));
            }
        }
    }
    Ok(())
}

/// Assert that the response indicates success.
///
/// For `ResponseMessage` envelopes, checks `ResultStatus` == "Success".
/// For bare operation responses (e.g. `CreateResponse`), HTTP 200 is sufficient
/// — this function is a no-op when `ResultStatus` is absent (the HTTP check
/// is handled by the caller).
fn assert_success(
    response: &serde_json::Value,
    step_operation: &str,
) -> Result<(), KmsClientError> {
    // If there is a ResultStatus field, verify it is "Success".
    // If not (bare operation response), the HTTP 200 status already confirms success.
    let result_status = find_field_in_json(response, "ResultStatus");
    match result_status.as_deref() {
        Some("Success" | "0x00000000") | None => Ok(()),
        Some(other) => {
            // Also extract ResultMessage if available
            let msg = find_field_in_json(response, "ResultMessage")
                .unwrap_or_else(|| "(no message)".to_owned());
            Err(KmsClientError::UnexpectedError(format!(
                "Step '{step_operation}': expected success, got ResultStatus='{other}', \
                 ResultMessage='{msg}'"
            )))
        }
    }
}

/// Assert that ALL `ResultStatus` fields in a batched response indicate success.
fn assert_all_success(
    response: &serde_json::Value,
    step_operation: &str,
) -> Result<(), KmsClientError> {
    for (idx, status) in find_all_fields_in_json(response, "ResultStatus")
        .iter()
        .enumerate()
    {
        if status != "Success" && status != "0x00000000" {
            return Err(KmsClientError::UnexpectedError(format!(
                "Step '{step_operation}': batch item {idx} expected success, \
                 got ResultStatus='{status}'"
            )));
        }
    }
    Ok(())
}

/// Capture values from a response TTLV JSON for use in subsequent steps.
fn capture_values(
    response: &serde_json::Value,
    capture_rules: &HashMap<String, String>,
    captures: &mut HashMap<String, String>,
    step_operation: &str,
) -> Result<(), KmsClientError> {
    for (var_name, tag) in capture_rules {
        let value = find_field_in_json(response, tag).ok_or_else(|| {
            KmsClientError::UnexpectedError(format!(
                "Step '{step_operation}': cannot capture '{var_name}': \
                 tag '{tag}' not found in response"
            ))
        })?;
        captures.insert(var_name.clone(), value);
    }
    Ok(())
}

/// Resolve a path relative to the repository root (two levels up from `CARGO_MANIFEST_DIR`).
fn repo_root() -> Result<PathBuf, KmsClientError> {
    PathBuf::from(env!("CARGO_MANIFEST_DIR"))
        .parent()
        .and_then(|p| p.parent())
        .map(Path::to_path_buf)
        .ok_or_else(|| {
            KmsClientError::UnexpectedError(
                "cannot resolve repo root from CARGO_MANIFEST_DIR".to_owned(),
            )
        })
}

/// Parse the `KMS_TEST_BACKENDS` environment variable into a list of backend names.
///
/// Format: comma-separated, e.g. `"sqlite,postgresql,mysql"`.
/// Falls back to `KMS_TEST_DB` (single value, used by CI scripts).
/// Defaults to `["sqlite"]` when neither variable is set.
///
/// Returns `(backends, explicitly_requested)` where `explicitly_requested` is
/// `true` when the caller set `KMS_TEST_BACKENDS` or `KMS_TEST_DB` — in that
/// case a missing connection env var is a hard error, not a graceful skip.
fn requested_backends() -> (Vec<String>, bool) {
    if let Ok(v) = std::env::var("KMS_TEST_BACKENDS") {
        let backends = v.split(',').map(|s| s.trim().to_owned()).collect();
        return (backends, true);
    }
    if let Ok(db) = std::env::var("KMS_TEST_DB") {
        let backend = match db.as_str() {
            "redis" => "redis-findex".to_owned(),
            other => other.to_owned(),
        };
        return (vec![backend], true);
    }
    (vec!["sqlite".to_owned()], false)
}

/// Check whether a backend is available to test.
///
/// Returns `true` when any of the following hold:
/// - The backend is `sqlite` (always available)
/// - `KMS_TEST_DB` explicitly names this backend (user asserts it is reachable;
///   the connection URL is provided by the server config TOML)
/// - `KMS_TEST_BACKENDS` lists this backend (same assertion)
/// - The legacy per-backend connection env var is set (`KMS_POSTGRES_URL`, etc.)
fn backend_available(backend: &str) -> bool {
    // If the user explicitly requested this specific backend, treat it as available.
    // The KMS server will use its own config TOML (which contains the URL), so
    // no separate connection env var is needed.
    if std::env::var("KMS_TEST_DB")
        .ok()
        .as_deref()
        .map(|v| if v == "redis" { "redis-findex" } else { v })
        == Some(backend)
    {
        return true;
    }
    if let Ok(v) = std::env::var("KMS_TEST_BACKENDS") {
        if v.split(',').any(|b| b.trim() == backend) {
            return true;
        }
    }
    // Fall back to checking the legacy per-backend connection env var.
    match backend {
        "postgresql" => std::env::var("KMS_POSTGRES_URL").is_ok(),
        "mysql" => std::env::var("KMS_MYSQL_URL").is_ok(),
        "redis-findex" => {
            std::env::var("KMS_REDIS_URL").is_ok() || std::env::var("REDIS_HOST").is_ok()
        }
        _ => true, // sqlite is always available
    }
}

/// Get or initialize a singleton test server for the given backend.
async fn get_or_init_vector_server(backend: &str) -> Result<&'static TestsContext, KmsClientError> {
    let root = repo_root()?;
    let (cell, toml, env_var) = match backend {
        "postgresql" => (&ONCE_VECTOR_POSTGRESQL, "postgres.toml", "KMS_POSTGRES_URL"),
        "mysql" => (&ONCE_VECTOR_MYSQL, "mysql.toml", "KMS_MYSQL_URL"),
        "redis-findex" => (
            &ONCE_VECTOR_REDIS_FINDEX,
            "redis_findex.toml",
            "KMS_REDIS_URL",
        ),
        _ => (&ONCE_VECTOR_SQLITE, "auth_plain.toml", ""),
    };
    let p = root.join("test_data/configs/server/test").join(toml);
    // Override the database URL from the environment when set (e.g. MariaDB on
    // port 3308 or Percona on port 3307 reuse the "mysql" backend with a
    // different connection URL).
    let url_override = if env_var.is_empty() {
        None
    } else {
        std::env::var(env_var).ok()
    };
    cell.get_or_try_init(|| async move {
        crate::start_test_server_with_patch(
            &p,
            |config| {
                if let Some(url) = &url_override {
                    config.db.database_url = Some(url.clone());
                }
            },
            crate::TestClientOptions::default(),
        )
        .await
    })
    .await
}

/// Run a test vector from a directory containing `manifest.toml` and step JSON files.
///
/// This is the main entry point for vector-based regression tests. It:
/// 1. Loads the manifest
/// 2. Determines which backends to test (intersection of manifest `backends`
///    field and `KMS_TEST_BACKENDS` env var)
/// 3. For each backend: uses a singleton shared server, executes steps
///
/// # Multi-backend support
///
/// Set `KMS_TEST_BACKENDS=sqlite,postgresql,mysql` to run vectors against multiple
/// database backends. The connection URL for each backend is taken from the server
/// config TOML; no separate env var is required when the backend is explicitly
/// requested. Backends not listed are skipped gracefully.
///
/// # Arguments
/// * `vector_dir` — Path to the test vector directory (relative to the repo root),
///   e.g. `test_data/vectors/fips/symmetric/aes_create_encrypt_decrypt`
///
/// # Errors
/// Returns an error on any failure (assertion, network, parse error).
pub async fn run_test_vector(vector_dir: &str) -> Result<(), KmsClientError> {
    let root = repo_root()?;
    let vector_path = root.join(vector_dir);

    // Load manifest
    let manifest_path = vector_path.join("manifest.toml");
    let manifest = load_manifest(&manifest_path)?;

    // Check required environment variables; skip gracefully if any is missing
    for env_var in &manifest.requires_env {
        if std::env::var(env_var).is_err() {
            eprintln!(
                "SKIP vector '{}': required env var '{env_var}' is not set",
                manifest.name
            );
            return Ok(());
        }
    }

    // If server_type is set, use a dedicated server instead of the backend-driven ones
    if let Some(server_type) = &manifest.server_type {
        match server_type.as_str() {
            "hsm_kek" => {
                let context = ONCE_VECTOR_HSM_KEK
                    .get_or_try_init(|| async {
                        crate::start_default_test_kms_server_with_softhsm2_and_kek_for_vectors()
                            .await
                    })
                    .await?;
                eprintln!(
                    "▶ Running vector '{}' on server_type 'hsm_kek'",
                    manifest.name
                );
                return execute_steps(context, &manifest, &vector_path).await;
            }
            other => {
                return Err(KmsClientError::UnexpectedError(format!(
                    "Unknown server_type '{other}' in manifest for vector '{}'",
                    manifest.name
                )));
            }
        }
    }

    // Determine which backends to test
    let (requested, explicit) = requested_backends();
    let backends_to_run: Vec<&String> = manifest
        .backends
        .iter()
        .filter(|b| requested.iter().any(|r| r == *b))
        .collect();

    if backends_to_run.is_empty() {
        // Vector does not target any of the requested backends — skip gracefully.
        eprintln!(
            "SKIP vector '{}': its backends {:?} are not in the current run set {:?}",
            manifest.name, manifest.backends, requested
        );
        return Ok(());
    }

    for backend in &backends_to_run {
        if !backend_available(backend) {
            if explicit {
                return Err(KmsClientError::UnexpectedError(format!(
                    "Backend '{backend}' was explicitly requested but its connection \
                     env var is not set (postgresql→KMS_POSTGRES_URL, \
                     mysql→KMS_MYSQL_URL, redis-findex→KMS_REDIS_URL/REDIS_HOST)"
                )));
            }
            eprintln!(
                "SKIP vector '{}' on backend '{backend}': connection env var not set",
                manifest.name
            );
            continue;
        }

        eprintln!(
            "▶ Running vector '{}' on backend '{backend}'",
            manifest.name
        );

        // Manifests with a custom server_config use a per-config singleton server.
        // Each config file gets its own OnceCell to prevent race conditions where a
        // different config (e.g. auth_https.toml without mTLS) could poison the
        // ONCE_VECTOR_CERT_AUTH cell and cause all cert-auth tests to run against
        // the wrong server (reproduces non-deterministically on slower runners like ARM).
        if let Some(server_config) = &manifest.server_config {
            let config_path = root.join(server_config);
            let context = match server_config.as_str() {
                "test_data/configs/server/test/auth_https.toml" => {
                    ONCE_VECTOR_AUTH_HTTPS
                        .get_or_try_init(|| crate::start_test_server_from_toml(&config_path))
                        .await?
                }
                _ => {
                    // Default: cert_auth.toml and any future mTLS configs
                    ONCE_VECTOR_CERT_AUTH
                        .get_or_try_init(|| crate::start_test_server_from_toml(&config_path))
                        .await?
                }
            };
            execute_steps(context, &manifest, &vector_path).await?;
        } else {
            let context = get_or_init_vector_server(backend).await?;
            execute_steps(context, &manifest, &vector_path).await?;
        }
    }

    Ok(())
}

/// Run a test vector against a pre-existing (shared) server context.
///
/// Same as [`run_test_vector`] but reuses an already-running server, which is
/// useful for tests that share a `OnceCell<TestsContext>` server instance.
///
/// # Errors
/// Returns an error on any failure (assertion, network, parse error).
pub async fn run_test_vector_with_context(
    vector_dir: &str,
    context: &TestsContext,
) -> Result<(), KmsClientError> {
    let root = repo_root()?;
    let vector_path = root.join(vector_dir);

    let manifest_path = vector_path.join("manifest.toml");
    let manifest = load_manifest(&manifest_path)?;

    execute_steps(context, &manifest, &vector_path).await
}

/// Execute a `GrantAccess` or `RevokeAccess` step via the Cosmian REST API.
async fn execute_access_step(
    client: &KmsClient,
    request_json: &serde_json::Value,
    step: &TestStep,
    i: usize,
) -> Result<(), KmsClientError> {
    let access: Access = serde_json::from_value(request_json.clone()).map_err(|e| {
        KmsClientError::UnexpectedError(format!(
            "Step {} '{}': cannot parse Access request: {e}",
            i, step.operation
        ))
    })?;
    let result = if step.operation == "GrantAccess" {
        client.grant_access(access).await
    } else {
        client.revoke_access(access).await
    };
    match result {
        Ok(_) => {
            if !step.assert_success && !step.allow_failure {
                return Err(KmsClientError::UnexpectedError(format!(
                    "Step {} '{}': expected failure but got success",
                    i, step.operation
                )));
            }
        }
        Err(e) => {
            if step.allow_failure {
                // Best-effort step — ignore the error
            } else if step.assert_success {
                return Err(KmsClientError::UnexpectedError(format!(
                    "Step {} '{}': expected success, got error: {e}",
                    i, step.operation
                )));
            } else if let Some(substr) = &step.assert_error_contains {
                let msg = e.to_string();
                if !msg.contains(substr.as_str()) {
                    return Err(KmsClientError::UnexpectedError(format!(
                        "Step {} '{}': expected error containing '{}', got: {e}",
                        i, step.operation, substr
                    )));
                }
            }
        }
    }
    Ok(())
}

/// Build one `KmsClient` per named identity declared in `manifest.identities`.
///
/// Always uses PEM (`.crt` + `.key`) so the runner works in both FIPS and
/// non-FIPS builds (PKCS12KDF is not available in FIPS mode).
fn build_identity_clients(
    context: &TestsContext,
    manifest: &TestManifest,
    root: &Path,
) -> Result<HashMap<String, KmsClient>, KmsClientError> {
    let mut identity_clients: HashMap<String, KmsClient> = HashMap::new();
    for (name, id_cfg) in &manifest.identities {
        let cert_path = root.join(&id_cfg.client_cert);
        let key_path = root.join(&id_cfg.client_key);
        let mut http_cfg = context.owner_client_config.http_config.clone();
        http_cfg.tls_client_pem_cert_path = Some(cert_path.to_string_lossy().into_owned());
        http_cfg.tls_client_pem_key_path = Some(key_path.to_string_lossy().into_owned());
        http_cfg.tls_client_pkcs12_path = None;
        http_cfg.tls_client_pkcs12_password = None;
        let cfg = KmsClientConfig {
            http_config: http_cfg,
            vendor_id: VENDOR_ID_COSMIAN.to_owned(),
            ..KmsClientConfig::default()
        };
        let client = KmsClient::new_with_config(cfg).map_err(|e| {
            KmsClientError::UnexpectedError(format!(
                "Failed to build client for identity '{name}': {e}"
            ))
        })?;
        identity_clients.insert(name.clone(), client);
    }
    Ok(identity_clients)
}

/// Execute the steps of a test vector against a running server.
async fn execute_steps(
    context: &TestsContext,
    manifest: &TestManifest,
    vector_path: &Path,
) -> Result<(), KmsClientError> {
    let base_url = context
        .owner_client_config
        .http_config
        .server_url
        .trim_end_matches('/')
        .to_owned();

    // Build per-identity KmsClients from the manifest's `[identities.*]` section.
    let root = repo_root()?;
    let identity_clients = build_identity_clients(context, manifest, &root)?;

    let is_binary = manifest.wire_format == "binary";
    let json_url = format!("{base_url}/kmip/2_1");
    let binary_url = format!("{base_url}/kmip");

    let mut captures: HashMap<String, String> = HashMap::new();

    for (i, step) in manifest.steps.iter().enumerate() {
        // Resolve which client to use for this step
        let step_identity = step.identity.as_deref().unwrap_or("owner");
        let client = identity_clients
            .get(step_identity)
            .map_or_else(|| context.get_owner_client(), Clone::clone);

        let request_path = vector_path.join(&step.request);
        let request_json = load_request_json(&request_path, &captures)?;

        // GrantAccess and RevokeAccess use the Cosmian REST API rather than TTLV.
        if matches!(step.operation.as_str(), "GrantAccess" | "RevokeAccess") {
            execute_access_step(&client, &request_json, step, i).await?;
            continue;
        }

        // Send the request via JSON or binary wire format.
        // When `raw_request` is true, the JSON is already a complete RequestMessage;
        // otherwise, wrap the bare operation in a standard KMIP RequestMessage envelope.
        let (http_success, response_json) = if is_binary {
            // Binary: always HTTP 200; success/failure is in ResultStatus
            let json = send_binary_request(
                &client,
                &binary_url,
                &request_json,
                manifest.kmip_version,
                i,
                &step.operation,
                step.raw_request,
            )
            .await?;
            (true, json)
        } else {
            // JSON wire format: wrap or use as-is depending on raw_request
            let request_message = if step.raw_request {
                request_json.clone()
            } else {
                wrap_in_request_message(
                    &request_json,
                    manifest.kmip_version[0],
                    manifest.kmip_version[1],
                )
            };

            // POST the wrapped JSON TTLV to the KMIP /kmip/2_1 endpoint
            let send_result = client.client.post_json(&json_url, &request_message).await;

            match send_result {
                Ok(response) => {
                    let status = response.status;
                    let response_text = response.text().map_err(|e| {
                        KmsClientError::UnexpectedError(format!(
                            "Step {i} '{}': cannot read response body: {e}",
                            step.operation
                        ))
                    })?;

                    // Try to parse as JSON; for non-JSON error responses, create
                    // a synthetic JSON
                    let response_json: serde_json::Value =
                        serde_json::from_str(&response_text).unwrap_or_else(|_| {
                            serde_json::json!({
                                "tag": "ErrorResponse",
                                "value": [
                                    { "tag": "ResultStatus", "type": "Enumeration", "value": "OperationFailed" },
                                    { "tag": "ResultMessage", "type": "TextString", "value": response_text }
                                ]
                            })
                        });

                    (status.is_success(), response_json)
                }
                Err(e) => {
                    // Transport-level failure (server crash, connection reset,
                    // etc.). When assert_success is false or allow_failure is set,
                    // treat it as an expected failure and continue.
                    if !step.assert_success || step.allow_failure {
                        eprintln!(
                            "Step {i} '{}': transport error (expected failure): {e}",
                            step.operation
                        );
                        continue;
                    }
                    return Err(KmsClientError::UnexpectedError(format!(
                        "Step {i} '{}': HTTP request failed: {e}",
                        step.operation
                    )));
                }
            }
        };

        // Optionally record the response for debugging / capture mode
        if std::env::var("RECORD_VECTORS").is_ok() {
            let response_path = vector_path.join(format!("step{}_response.json", i + 1));
            if let Ok(pretty) = serde_json::to_string_pretty(&response_json) {
                drop(std::fs::write(&response_path, pretty));
            }
        }

        if step.assert_success {
            // When allow_failure is set, skip all assertions — the step is best-effort
            if step.allow_failure {
                continue;
            }
            // Expect success: HTTP 2xx and ResultStatus == Success
            if !http_success {
                return Err(KmsClientError::UnexpectedError(format!(
                    "Step {i} '{}': HTTP error — body: {}",
                    step.operation,
                    serde_json::to_string_pretty(&response_json).unwrap_or_default()
                )));
            }
            // For raw (batched) requests, verify ALL ResultStatus fields succeed
            if step.raw_request {
                assert_all_success(&response_json, &step.operation)?;
            } else {
                assert_success(&response_json, &step.operation)?;
            }
        } else {
            // Expect failure: HTTP non-2xx or ResultStatus != Success
            if http_success {
                let result_status = find_field_in_json(&response_json, "ResultStatus");
                if result_status.as_deref() == Some("Success")
                    || result_status.as_deref() == Some("0x00000000")
                {
                    return Err(KmsClientError::UnexpectedError(format!(
                        "Step {i} '{}': expected failure but got success",
                        step.operation
                    )));
                }
            }

            // Optionally check the specific error reason
            if let Some(expected_reason) = &step.assert_error_reason {
                let actual_reason =
                    find_field_in_json(&response_json, "ResultReason").unwrap_or_default();
                if actual_reason != *expected_reason {
                    return Err(KmsClientError::UnexpectedError(format!(
                        "Step {i} '{}': expected ResultReason='{expected_reason}', \
                         got '{actual_reason}'",
                        step.operation
                    )));
                }
            }

            // Optionally check that the error message contains a substring
            if let Some(expected_substr) = &step.assert_error_contains {
                let actual_msg =
                    find_field_in_json(&response_json, "ResultMessage").unwrap_or_default();
                if !actual_msg.contains(expected_substr.as_str()) {
                    return Err(KmsClientError::UnexpectedError(format!(
                        "Step {i} '{}': expected ResultMessage to contain \
                         '{expected_substr}', got '{actual_msg}'",
                        step.operation
                    )));
                }
            }

            // Require at least one error assertion when assert_success=false.
            // Without this guard, any failure would silently pass the test.
            if step.assert_error_reason.is_none() && step.assert_error_contains.is_none() {
                return Err(KmsClientError::UnexpectedError(format!(
                    "Step {i} '{}': assert_success=false but neither \
                     'assert_error_reason' nor 'assert_error_contains' is set — \
                     refusing to accept any arbitrary error as expected. \
                     Add an error assertion to the manifest.",
                    step.operation
                )));
            }

            // Expected failure — skip further assertions and captures
            continue;
        }

        // Assert specific fields (substitute env vars and captured variables in expected values)
        if !step.assert_fields.is_empty() {
            let mut resolved: HashMap<String, String> = HashMap::new();
            for (k, v) in &step.assert_fields {
                resolved.insert(k.clone(), resolve_assertion_value(v, &captures)?);
            }
            assert_response_fields(&response_json, &resolved, &step.operation)?;
        }

        // Assert that the expected value appears in ANY occurrence of the field
        // (used for Locate responses that return multiple UniqueIdentifiers)
        if !step.assert_any_field.is_empty() {
            for (tag, expected_template) in &step.assert_any_field {
                let expected = resolve_assertion_value(expected_template, &captures)?;
                let all_values = find_all_fields_in_json(&response_json, tag);
                if !all_values.contains(&expected) {
                    return Err(KmsClientError::UnexpectedError(format!(
                        "Step '{}': field '{tag}' expected to contain '{expected}', \
                         but got: [{}]",
                        step.operation,
                        all_values.join(", ")
                    )));
                }
            }
        }

        // Assert that the expected value does NOT appear in any occurrence of the field
        // (used to verify a specific object is not returned by Locate)
        if !step.assert_none_field.is_empty() {
            for (tag, forbidden_template) in &step.assert_none_field {
                let forbidden = resolve_assertion_value(forbidden_template, &captures)?;
                let all_values = find_all_fields_in_json(&response_json, tag);
                if all_values.contains(&forbidden) {
                    return Err(KmsClientError::UnexpectedError(format!(
                        "Step '{}': field '{tag}' must NOT contain '{forbidden}', \
                         but it was found in: [{}]",
                        step.operation,
                        all_values.join(", ")
                    )));
                }
            }
        }

        // Assert that certain fields are absent
        for absent_tag in &step.assert_fields_absent {
            if find_field_in_json(&response_json, absent_tag).is_some() {
                return Err(KmsClientError::UnexpectedError(format!(
                    "Step {i} '{}': field '{absent_tag}' should be absent but was found \
                     in response",
                    step.operation
                )));
            }
        }

        // Assert occurrence counts
        for (tag, expected_count) in &step.assert_count {
            let actual_count = find_all_fields_in_json(&response_json, tag).len();
            if actual_count != *expected_count {
                return Err(KmsClientError::UnexpectedError(format!(
                    "Step {i} '{}': expected {expected_count} occurrence(s) of '{tag}', \
                     got {actual_count}",
                    step.operation
                )));
            }
        }

        // Capture values for subsequent steps
        if !step.capture.is_empty() {
            capture_values(
                &response_json,
                &step.capture,
                &mut captures,
                &step.operation,
            )?;
        }
    }

    Ok(())
}

#[cfg(test)]
#[allow(
    clippy::unwrap_used,
    clippy::indexing_slicing,
    clippy::assertions_on_result_states
)]
mod tests {
    use super::*;

    #[test]
    fn test_find_field_in_json() {
        let json = serde_json::json!({
            "tag": "ResponseMessage",
            "value": [
                {
                    "tag": "ResponseHeader",
                    "value": [
                        {
                            "tag": "ProtocolVersion",
                            "value": [
                                { "tag": "ProtocolVersionMajor", "type": "Integer", "value": 2 },
                                { "tag": "ProtocolVersionMinor", "type": "Integer", "value": 1 }
                            ]
                        },
                        { "tag": "BatchCount", "type": "Integer", "value": 1 }
                    ]
                },
                {
                    "tag": "BatchItem",
                    "value": [
                        { "tag": "Operation", "type": "Enumeration", "value": "Create" },
                        { "tag": "ResultStatus", "type": "Enumeration", "value": "Success" },
                        { "tag": "UniqueIdentifier", "type": "TextString", "value": "abc-123" }
                    ]
                }
            ]
        });

        assert_eq!(
            find_field_in_json(&json, "UniqueIdentifier"),
            Some("abc-123".to_owned())
        );
        assert_eq!(
            find_field_in_json(&json, "ResultStatus"),
            Some("Success".to_owned())
        );
        assert_eq!(
            find_field_in_json(&json, "BatchCount"),
            Some("1".to_owned())
        );
        assert_eq!(find_field_in_json(&json, "NonExistent"), None);
    }

    #[test]
    fn test_substitute_placeholders() {
        let dir = std::env::temp_dir().join("test_vector_placeholder");
        std::fs::create_dir_all(&dir).unwrap();

        let request_content = r#"{
            "tag": "RequestMessage",
            "value": [
                {
                    "tag": "UniqueIdentifier",
                    "type": "TextString",
                    "value": "{{key_id}}"
                }
            ]
        }"#;
        let request_path = dir.join("request.json");
        std::fs::write(&request_path, request_content).unwrap();

        let mut captures = HashMap::new();
        captures.insert("key_id".to_owned(), "my-unique-id-123".to_owned());

        let json = load_request_json(&request_path, &captures).unwrap();
        assert_eq!(json["value"][0]["value"].as_str(), Some("my-unique-id-123"));

        // Cleanup
        drop(std::fs::remove_dir_all(&dir));
    }

    #[test]
    fn test_assert_success_ok() {
        let response = serde_json::json!({
            "tag": "ResponseMessage",
            "value": [{
                "tag": "BatchItem",
                "value": [
                    { "tag": "ResultStatus", "type": "Enumeration", "value": "Success" }
                ]
            }]
        });
        assert!(assert_success(&response, "test_op").is_ok());
    }

    #[test]
    fn test_assert_success_fail() {
        let response = serde_json::json!({
            "tag": "ResponseMessage",
            "value": [{
                "tag": "BatchItem",
                "value": [
                    { "tag": "ResultStatus", "type": "Enumeration", "value": "OperationFailed" },
                    { "tag": "ResultMessage", "type": "TextString", "value": "Key not found" }
                ]
            }]
        });
        let err = assert_success(&response, "test_op").unwrap_err();
        let msg = err.to_string();
        assert!(msg.contains("OperationFailed"), "Error: {msg}");
        assert!(msg.contains("Key not found"), "Error: {msg}");
    }

    #[test]
    fn test_capture_values() {
        let response = serde_json::json!({
            "tag": "ResponseMessage",
            "value": [{
                "tag": "BatchItem",
                "value": [
                    { "tag": "ResultStatus", "type": "Enumeration", "value": "Success" },
                    { "tag": "UniqueIdentifier", "type": "TextString", "value": "id-456" }
                ]
            }]
        });

        let mut capture_rules = HashMap::new();
        capture_rules.insert("key_id".to_owned(), "UniqueIdentifier".to_owned());

        let mut captures = HashMap::new();
        capture_values(&response, &capture_rules, &mut captures, "Create").unwrap();

        assert_eq!(captures.get("key_id"), Some(&"id-456".to_owned()));
    }

    #[test]
    fn test_load_manifest() {
        let dir = std::env::temp_dir().join("test_vector_manifest");
        std::fs::create_dir_all(&dir).unwrap();

        let manifest_content = r#"
name = "Test Vector Example"
description = "A simple test"

[[steps]]
operation = "Create"
request = "step1_request.json"
assert_success = true

[steps.capture]
key_id = "UniqueIdentifier"

[[steps]]
operation = "Get"
request = "step2_request.json"

[steps.assert_fields]
ObjectType = "SymmetricKey"
"#;
        let manifest_path = dir.join("manifest.toml");
        std::fs::write(&manifest_path, manifest_content).unwrap();

        let manifest = load_manifest(&manifest_path).unwrap();
        assert_eq!(manifest.name, "Test Vector Example");
        assert_eq!(manifest.steps.len(), 2);
        assert_eq!(manifest.steps[0].operation, "Create");
        assert!(manifest.steps[0].assert_success);
        assert_eq!(
            manifest.steps[0].capture.get("key_id"),
            Some(&"UniqueIdentifier".to_owned())
        );
        assert_eq!(manifest.steps[1].operation, "Get");
        assert_eq!(
            manifest.steps[1].assert_fields.get("ObjectType"),
            Some(&"SymmetricKey".to_owned())
        );
        // assert_success defaults to true
        assert!(manifest.steps[1].assert_success);
        assert!(manifest.server_config.is_none());

        // Cleanup
        drop(std::fs::remove_dir_all(&dir));
    }

    #[cfg(feature = "non-fips")]
    #[tokio::test]
    async fn test_vec_aes_create_get() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/symmetric/aes_create_get").await
    }

    #[cfg(feature = "non-fips")]
    #[tokio::test]
    async fn test_vec_aes_encrypt_decrypt() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/symmetric/aes_encrypt_decrypt").await
    }

    #[cfg(feature = "non-fips")]
    #[tokio::test]
    async fn test_vec_rsa_create_encrypt_decrypt() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/asymmetric/rsa_create_encrypt_decrypt").await
    }

    #[cfg(feature = "non-fips")]
    #[tokio::test]
    async fn test_vec_ec_p256_sign_verify() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/asymmetric/ec_p256_sign_verify").await
    }

    #[cfg(feature = "non-fips")]
    #[tokio::test]
    async fn test_vec_derive_key_pbkdf2() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/kmip_operations/derive_key_pbkdf2").await
    }

    #[cfg(feature = "non-fips")]
    #[tokio::test]
    async fn test_vec_destroy_lifecycle() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/kmip_operations/destroy").await
    }

    #[cfg(feature = "non-fips")]
    #[tokio::test]
    async fn test_vec_locate() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/kmip_operations/locate").await
    }

    // ── New: Parametric key-size variants ─────────────────────────────────

    #[cfg(feature = "non-fips")]
    #[tokio::test]
    async fn test_vec_aes128_encrypt_decrypt() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/symmetric/aes128_encrypt_decrypt").await
    }

    #[cfg(feature = "non-fips")]
    #[tokio::test]
    async fn test_vec_rsa4096_encrypt_decrypt() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/asymmetric/rsa4096_encrypt_decrypt").await
    }

    #[cfg(feature = "non-fips")]
    #[tokio::test]
    async fn test_vec_ec_p384_sign_verify() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/asymmetric/ec_p384_sign_verify").await
    }

    // ── New: KMIP operations coverage ─────────────────────────────────────

    #[cfg(feature = "non-fips")]
    #[tokio::test]
    async fn test_vec_mac_and_verify() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/kmip_operations/mac_and_verify").await
    }

    #[cfg(feature = "non-fips")]
    #[tokio::test]
    async fn test_vec_hash_sha256() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/kmip_operations/hash_sha256").await
    }

    #[cfg(feature = "non-fips")]
    #[tokio::test]
    async fn test_vec_rng_retrieve() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/kmip_operations/rng_retrieve").await
    }

    #[cfg(feature = "non-fips")]
    #[tokio::test]
    async fn test_vec_check() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/kmip_operations/check").await
    }

    #[cfg(feature = "non-fips")]
    #[tokio::test]
    async fn test_vec_activate_lifecycle() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/kmip_operations/activate").await
    }

    #[cfg(feature = "non-fips")]
    #[tokio::test]
    async fn test_vec_query() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/kmip_operations/query").await
    }

    #[tokio::test]
    async fn test_vec_rekey() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/kmip_operations/rekey").await
    }

    #[tokio::test]
    async fn test_vec_rekey_locate_by_name() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/kmip_operations/rekey_locate_by_name").await
    }

    #[tokio::test]
    async fn test_vec_rekey_deactivated_fails() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/kmip_operations/rekey_deactivated_fails").await
    }

    #[tokio::test]
    async fn test_vec_rekey_with_links() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/kmip_operations/rekey_with_links").await
    }

    #[tokio::test]
    async fn test_vec_rekey_with_offset() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/kmip_operations/rekey_with_offset").await
    }

    #[tokio::test]
    async fn test_vec_rekey_double_chain() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/kmip_operations/rekey_double_chain").await
    }

    #[tokio::test]
    async fn test_vec_rekey_name_removed_from_old() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/kmip_operations/rekey_name_removed_from_old").await
    }

    #[tokio::test]
    async fn test_vec_rekey_old_key_still_decrypts() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/kmip_operations/rekey_old_key_still_decrypts").await
    }

    #[tokio::test]
    async fn test_vec_rekey_kmip14() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/kmip_operations/rekey_kmip14").await
    }

    #[cfg(feature = "non-fips")]
    #[tokio::test]
    async fn test_vec_rekey_keypair_kmip14() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/kmip_operations/rekey_keypair_kmip14").await
    }

    #[cfg(feature = "non-fips")]
    #[tokio::test]
    async fn test_vec_rekey_keypair_kmip14_binary() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/kmip_operations/rekey_keypair_kmip14_binary").await
    }

    #[cfg(feature = "non-fips")]
    #[tokio::test]
    async fn test_vec_attribute_management() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/kmip_operations/attribute_management").await
    }

    #[cfg(feature = "non-fips")]
    #[tokio::test]
    async fn test_vec_register_export() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/kmip_operations/register_export").await
    }

    // ── Integration vectors ───────────────────────────────────────────────

    #[cfg(feature = "non-fips")]
    #[tokio::test]
    async fn test_vec_synology_dsm() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/integrations/synology_dsm").await
    }

    #[cfg(feature = "non-fips")]
    #[tokio::test]
    async fn test_vec_veeam() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/integrations/veeam").await
    }

    #[cfg(feature = "non-fips")]
    #[tokio::test]
    async fn test_vec_vmware_vcenter() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/integrations/vmware_vcenter").await
    }

    // ── New KMIP operation vectors ────────────────────────────────────────

    #[cfg(feature = "non-fips")]
    #[tokio::test]
    async fn test_vec_discover_versions() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/kmip_operations/discover_versions").await
    }

    #[cfg(feature = "non-fips")]
    #[tokio::test]
    async fn test_vec_get_attributes() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/kmip_operations/get_attributes").await
    }

    #[cfg(feature = "non-fips")]
    #[tokio::test]
    async fn test_vec_get_attribute_list() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/kmip_operations/get_attribute_list").await
    }

    #[cfg(feature = "non-fips")]
    #[tokio::test]
    async fn test_vec_import_key() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/kmip_operations/import_key").await
    }

    #[cfg(feature = "non-fips")]
    #[tokio::test]
    async fn test_vec_rng_seed() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/kmip_operations/rng_seed").await
    }

    #[cfg(feature = "non-fips")]
    #[tokio::test]
    async fn test_vec_certify_validate() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/kmip_operations/certify_validate").await
    }

    #[cfg(feature = "non-fips")]
    #[tokio::test]
    async fn test_vec_secret_data() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/kmip_operations/secret_data").await
    }

    #[cfg(feature = "non-fips")]
    #[tokio::test]
    async fn test_vec_opaque_data() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/kmip_operations/opaque_data").await
    }

    // ── Encryption coverage: symmetric modes ──────────────────────────────

    #[cfg(feature = "non-fips")]
    #[tokio::test]
    async fn test_vec_aes256_cbc_encrypt_decrypt() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/symmetric/aes256_cbc_encrypt_decrypt").await
    }

    #[cfg(feature = "non-fips")]
    #[tokio::test]
    async fn test_vec_aes128_cbc_encrypt_decrypt() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/symmetric/aes128_cbc_encrypt_decrypt").await
    }

    #[cfg(feature = "non-fips")]
    #[tokio::test]
    async fn test_vec_aes256_gcm_siv_encrypt_decrypt() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/symmetric/aes256_gcm_siv_encrypt_decrypt").await
    }

    #[cfg(feature = "non-fips")]
    #[tokio::test]
    async fn test_vec_chacha20_poly1305_encrypt_decrypt() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/symmetric/chacha20_poly1305_encrypt_decrypt").await
    }

    // ── Signature coverage: curves and padding schemes ────────────────────

    #[cfg(feature = "non-fips")]
    #[tokio::test]
    async fn test_vec_ec_p521_sign_verify() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/asymmetric/ec_p521_sign_verify").await
    }

    #[cfg(feature = "non-fips")]
    #[tokio::test]
    async fn test_vec_rsa2048_pkcs1v15_sha256_sign() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/asymmetric/rsa2048_pkcs1v15_sha256_sign").await
    }

    #[cfg(feature = "non-fips")]
    #[tokio::test]
    async fn test_vec_rsa2048_pss_sha256_sign() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/asymmetric/rsa2048_pss_sha256_sign").await
    }

    #[cfg(feature = "non-fips")]
    #[tokio::test]
    async fn test_vec_rsa2048_pss_sha384_sign() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/asymmetric/rsa2048_pss_sha384_sign").await
    }

    #[cfg(feature = "non-fips")]
    #[tokio::test]
    async fn test_vec_rsa2048_pss_sha512_sign() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/asymmetric/rsa2048_pss_sha512_sign").await
    }

    #[cfg(feature = "non-fips")]
    #[tokio::test]
    async fn test_vec_eddsa_ed25519_sign() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/asymmetric/eddsa_ed25519_sign").await
    }

    // ── Encrypt coverage: key sizes ───────────────────────────────────────

    #[cfg(feature = "non-fips")]
    #[tokio::test]
    async fn test_vec_aes192_gcm_encrypt_decrypt() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/symmetric/aes192_gcm_encrypt_decrypt").await
    }

    #[cfg(feature = "non-fips")]
    #[tokio::test]
    async fn test_vec_aes192_cbc_encrypt_decrypt() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/symmetric/aes192_cbc_encrypt_decrypt").await
    }

    // ── Encrypt coverage: ECB mode (no nonce, no tag) ─────────────────────

    #[cfg(feature = "non-fips")]
    #[tokio::test]
    async fn test_vec_aes128_ecb_encrypt_decrypt() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/symmetric/aes128_ecb_encrypt_decrypt").await
    }

    #[cfg(feature = "non-fips")]
    #[tokio::test]
    async fn test_vec_aes256_ecb_encrypt_decrypt() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/symmetric/aes256_ecb_encrypt_decrypt").await
    }

    // ── Encrypt coverage: AAD and non-FIPS SIV ───────────────────────────

    #[cfg(feature = "non-fips")]
    #[tokio::test]
    async fn test_vec_aes256_gcm_aad_encrypt_decrypt() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/symmetric/aes256_gcm_aad_encrypt_decrypt").await
    }

    #[cfg(feature = "non-fips")]
    #[tokio::test]
    async fn test_vec_aes128_gcm_siv_encrypt_decrypt() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/symmetric/aes128_gcm_siv_encrypt_decrypt").await
    }

    // ── Encrypt coverage: RSA OAEP hash variants and PKCS#1v15 ──────────

    #[cfg(feature = "non-fips")]
    #[tokio::test]
    async fn test_vec_rsa2048_oaep_sha384_encrypt_decrypt() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/asymmetric/rsa2048_oaep_sha384_encrypt_decrypt")
            .await
    }

    #[cfg(feature = "non-fips")]
    #[tokio::test]
    async fn test_vec_rsa2048_oaep_sha512_encrypt_decrypt() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/asymmetric/rsa2048_oaep_sha512_encrypt_decrypt")
            .await
    }

    #[cfg(feature = "non-fips")]
    #[tokio::test]
    async fn test_vec_rsa2048_pkcs1v15_encrypt_decrypt() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/asymmetric/rsa2048_pkcs1v15_encrypt_decrypt").await
    }

    // ── Dynamic vectors: KMIP operations (hash, MAC, derive key) ──────────

    #[tokio::test]
    async fn test_vec_hash_sha384() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/kmip_operations/hash_sha384").await
    }

    #[tokio::test]
    async fn test_vec_hash_sha512() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/kmip_operations/hash_sha512").await
    }

    #[tokio::test]
    async fn test_vec_hash_sha3_256() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/kmip_operations/hash_sha3_256").await
    }

    #[tokio::test]
    async fn test_vec_hash_sha3_384() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/kmip_operations/hash_sha3_384").await
    }

    #[tokio::test]
    async fn test_vec_hash_sha3_512() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/kmip_operations/hash_sha3_512").await
    }

    #[tokio::test]
    async fn test_vec_mac_hmac_sha384() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/kmip_operations/mac_hmac_sha384").await
    }

    #[tokio::test]
    async fn test_vec_mac_hmac_sha512() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/kmip_operations/mac_hmac_sha512").await
    }

    #[tokio::test]
    async fn test_vec_mac_hmac_sha3_256() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/kmip_operations/mac_hmac_sha3_256").await
    }

    #[tokio::test]
    async fn test_vec_derive_key_pbkdf2_sha512() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/kmip_operations/derive_key_pbkdf2_sha512").await
    }

    #[tokio::test]
    async fn test_vec_derive_key_hkdf() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/kmip_operations/derive_key_hkdf").await
    }

    // ── Dynamic vectors: symmetric ────────────────────────────────────────

    #[tokio::test]
    async fn test_vec_aes192_ecb_encrypt_decrypt() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/symmetric/aes192_ecb_encrypt_decrypt").await
    }

    #[tokio::test]
    async fn test_vec_aes256_cbc_no_padding_encrypt_decrypt() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/symmetric/aes256_cbc_no_padding_encrypt_decrypt")
            .await
    }

    #[cfg(feature = "non-fips")]
    #[tokio::test]
    async fn test_vec_aes128_xts_encrypt_decrypt() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/symmetric/aes128_xts_encrypt_decrypt").await
    }

    #[cfg(feature = "non-fips")]
    #[tokio::test]
    async fn test_vec_aes256_xts_encrypt_decrypt() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/symmetric/aes256_xts_encrypt_decrypt").await
    }

    #[cfg(feature = "non-fips")]
    #[tokio::test]
    async fn test_vec_chacha20_encrypt_decrypt() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/symmetric/chacha20_encrypt_decrypt").await
    }

    // ── Dynamic vectors: asymmetric ───────────────────────────────────────

    #[cfg(feature = "non-fips")]
    #[tokio::test]
    async fn test_vec_eddsa_ed448_sign() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/asymmetric/eddsa_ed448_sign").await
    }

    #[cfg(feature = "non-fips")]
    #[tokio::test]
    async fn test_vec_ec_k256_sign_verify() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/asymmetric/ec_k256_sign_verify").await
    }

    #[tokio::test]
    async fn test_vec_rsa4096_pss_sha256_sign() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/asymmetric/rsa4096_pss_sha256_sign").await
    }

    #[cfg(feature = "non-fips")]
    #[tokio::test]
    async fn test_vec_rsa2048_pss_sha1_sign() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/asymmetric/rsa2048_pss_sha1_sign").await
    }

    #[cfg(feature = "non-fips")]
    #[tokio::test]
    async fn test_vec_ec_p256_ecies_encrypt_decrypt() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/asymmetric/ec_p256_ecies_encrypt_decrypt").await
    }

    #[cfg(feature = "non-fips")]
    #[tokio::test]
    async fn test_vec_rsa2048_aes_key_wrap() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/asymmetric/rsa2048_aes_key_wrap").await
    }

    // ── Dynamic vectors: PQC ──────────────────────────────────────────────

    #[cfg(feature = "non-fips")]
    #[tokio::test]
    async fn test_vec_ml_dsa_44_sign_verify() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/asymmetric/ml_dsa_44_sign_verify").await
    }

    #[cfg(feature = "non-fips")]
    #[tokio::test]
    async fn test_vec_ml_dsa_65_sign_verify() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/asymmetric/ml_dsa_65_sign_verify").await
    }

    #[cfg(feature = "non-fips")]
    #[tokio::test]
    async fn test_vec_ml_dsa_87_sign_verify() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/asymmetric/ml_dsa_87_sign_verify").await
    }

    #[cfg(feature = "non-fips")]
    #[tokio::test]
    async fn test_vec_ml_kem_512_encap_decap() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/asymmetric/ml_kem_512_encap_decap").await
    }

    #[cfg(feature = "non-fips")]
    #[tokio::test]
    async fn test_vec_ml_kem_768_encap_decap() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/asymmetric/ml_kem_768_encap_decap").await
    }

    #[cfg(feature = "non-fips")]
    #[tokio::test]
    async fn test_vec_ml_kem_1024_encap_decap() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/asymmetric/ml_kem_1024_encap_decap").await
    }

    #[cfg(feature = "non-fips")]
    #[tokio::test]
    async fn test_vec_slh_dsa_sha2_128s_sign_verify() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/asymmetric/slh_dsa_sha2_128s_sign_verify").await
    }

    #[cfg(feature = "non-fips")]
    #[tokio::test]
    async fn test_vec_slh_dsa_sha2_128f_sign_verify() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/asymmetric/slh_dsa_sha2_128f_sign_verify").await
    }

    #[cfg(feature = "non-fips")]
    #[tokio::test]
    async fn test_vec_slh_dsa_sha2_192s_sign_verify() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/asymmetric/slh_dsa_sha2_192s_sign_verify").await
    }

    #[cfg(feature = "non-fips")]
    #[tokio::test]
    async fn test_vec_slh_dsa_sha2_192f_sign_verify() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/asymmetric/slh_dsa_sha2_192f_sign_verify").await
    }

    #[cfg(feature = "non-fips")]
    #[tokio::test]
    async fn test_vec_slh_dsa_sha2_256s_sign_verify() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/asymmetric/slh_dsa_sha2_256s_sign_verify").await
    }

    #[cfg(feature = "non-fips")]
    #[tokio::test]
    async fn test_vec_slh_dsa_sha2_256f_sign_verify() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/asymmetric/slh_dsa_sha2_256f_sign_verify").await
    }

    #[cfg(feature = "non-fips")]
    #[tokio::test]
    async fn test_vec_slh_dsa_shake_128s_sign_verify() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/asymmetric/slh_dsa_shake_128s_sign_verify").await
    }

    #[cfg(feature = "non-fips")]
    #[tokio::test]
    async fn test_vec_slh_dsa_shake_128f_sign_verify() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/asymmetric/slh_dsa_shake_128f_sign_verify").await
    }

    #[cfg(feature = "non-fips")]
    #[tokio::test]
    async fn test_vec_slh_dsa_shake_192s_sign_verify() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/asymmetric/slh_dsa_shake_192s_sign_verify").await
    }

    #[cfg(feature = "non-fips")]
    #[tokio::test]
    async fn test_vec_slh_dsa_shake_192f_sign_verify() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/asymmetric/slh_dsa_shake_192f_sign_verify").await
    }

    #[cfg(feature = "non-fips")]
    #[tokio::test]
    async fn test_vec_slh_dsa_shake_256s_sign_verify() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/asymmetric/slh_dsa_shake_256s_sign_verify").await
    }

    #[cfg(feature = "non-fips")]
    #[tokio::test]
    async fn test_vec_slh_dsa_shake_256f_sign_verify() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/asymmetric/slh_dsa_shake_256f_sign_verify").await
    }

    // ── KAT vectors: hash ─────────────────────────────────────────────────

    #[tokio::test]
    async fn test_kat_hash_sha256() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/kat/hash/sha256").await
    }

    #[tokio::test]
    async fn test_kat_hash_sha384() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/kat/hash/sha384").await
    }

    #[tokio::test]
    async fn test_kat_hash_sha512() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/kat/hash/sha512").await
    }

    #[tokio::test]
    async fn test_kat_hash_sha3_256() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/kat/hash/sha3_256").await
    }

    #[tokio::test]
    async fn test_kat_hash_sha3_384() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/kat/hash/sha3_384").await
    }

    #[tokio::test]
    async fn test_kat_hash_sha3_512() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/kat/hash/sha3_512").await
    }

    // ── KAT vectors: MAC ──────────────────────────────────────────────────

    #[tokio::test]
    async fn test_kat_mac_hmac_sha256() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/kat/mac/hmac_sha256").await
    }

    #[tokio::test]
    async fn test_kat_mac_hmac_sha384() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/kat/mac/hmac_sha384").await
    }

    #[tokio::test]
    async fn test_kat_mac_hmac_sha512() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/kat/mac/hmac_sha512").await
    }

    #[tokio::test]
    async fn test_kat_mac_hmac_sha3_256() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/kat/mac/hmac_sha3_256").await
    }

    // ── KAT vectors: symmetric encryption ────────────────────────────────

    #[tokio::test]
    async fn test_kat_sym_aes128_ecb() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/kat/symmetric/aes128_ecb").await
    }

    #[tokio::test]
    async fn test_kat_sym_aes192_ecb() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/kat/symmetric/aes192_ecb").await
    }

    #[tokio::test]
    async fn test_kat_sym_aes256_ecb() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/kat/symmetric/aes256_ecb").await
    }

    #[tokio::test]
    async fn test_kat_sym_aes128_cbc() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/kat/symmetric/aes128_cbc").await
    }

    #[tokio::test]
    async fn test_kat_sym_aes192_cbc() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/kat/symmetric/aes192_cbc").await
    }

    #[tokio::test]
    async fn test_kat_sym_aes256_cbc() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/kat/symmetric/aes256_cbc").await
    }

    #[tokio::test]
    async fn test_kat_sym_aes128_gcm() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/kat/symmetric/aes128_gcm").await
    }

    #[tokio::test]
    async fn test_kat_sym_aes256_gcm() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/kat/symmetric/aes256_gcm").await
    }

    #[cfg(feature = "non-fips")]
    #[tokio::test]
    async fn test_kat_sym_chacha20_poly1305() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/kat/symmetric/chacha20_poly1305").await
    }

    #[cfg(feature = "non-fips")]
    #[tokio::test]
    async fn test_kat_sym_chacha20_pure() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/kat/symmetric/chacha20_pure").await
    }

    #[cfg(feature = "non-fips")]
    #[tokio::test]
    async fn test_kat_sym_aes128_xts() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/kat/symmetric/aes128_xts").await
    }

    #[cfg(feature = "non-fips")]
    #[tokio::test]
    async fn test_kat_sym_aes256_xts() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/kat/symmetric/aes256_xts").await
    }

    // ── KAT vectors: key derivation ───────────────────────────────────────

    #[tokio::test]
    async fn test_kat_derive_key_hkdf_sha256() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/kat/derive_key/hkdf_sha256").await
    }

    #[tokio::test]
    async fn test_kat_derive_key_pbkdf2_sha256() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/kat/derive_key/pbkdf2_sha256").await
    }

    // ── KAT vectors: MAC (new) ────────────────────────────────────────────

    #[tokio::test]
    async fn test_kat_mac_hmac_sha3_384() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/kat/mac/hmac_sha3_384").await
    }

    #[tokio::test]
    async fn test_kat_mac_hmac_sha3_512() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/kat/mac/hmac_sha3_512").await
    }

    #[tokio::test]
    async fn test_kat_mac_hmac_sha1() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/kat/mac/hmac_sha1").await
    }

    // ── KAT vectors: symmetric (new) ─────────────────────────────────────

    #[tokio::test]
    async fn test_kat_sym_aes192_gcm() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/kat/symmetric/aes192_gcm").await
    }

    #[tokio::test]
    async fn test_kat_sym_rfc3394_aes128_kek() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/kat/symmetric/rfc3394_aes128_kek").await
    }

    #[tokio::test]
    async fn test_kat_sym_rfc3394_aes192_kek() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/kat/symmetric/rfc3394_aes192_kek").await
    }

    #[tokio::test]
    async fn test_kat_sym_rfc3394_aes256_kek() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/kat/symmetric/rfc3394_aes256_kek").await
    }

    #[tokio::test]
    async fn test_kat_sym_rfc5649_aes128_kek() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/kat/symmetric/rfc5649_aes128_kek").await
    }

    #[tokio::test]
    async fn test_kat_sym_rfc5649_aes192_kek() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/kat/symmetric/rfc5649_aes192_kek").await
    }

    #[tokio::test]
    async fn test_kat_sym_rfc5649_aes256_kek() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/kat/symmetric/rfc5649_aes256_kek").await
    }

    // ── KAT vectors: key derivation (new) ────────────────────────────────

    #[tokio::test]
    async fn test_kat_derive_key_hkdf_sha384() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/kat/derive_key/hkdf_sha384").await
    }

    #[tokio::test]
    async fn test_kat_derive_key_hkdf_sha512() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/kat/derive_key/hkdf_sha512").await
    }

    #[tokio::test]
    async fn test_kat_derive_key_pbkdf2_sha384() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/kat/derive_key/pbkdf2_sha384").await
    }

    #[tokio::test]
    async fn test_kat_derive_key_pbkdf2_sha512() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/kat/derive_key/pbkdf2_sha512").await
    }

    // ── KAT vectors: asymmetric (new) ────────────────────────────────────

    #[tokio::test]
    async fn test_kat_asym_ed25519_eddsa_sign() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/kat/asymmetric/ed25519_eddsa_sign").await
    }

    #[tokio::test]
    async fn test_kat_asym_rsa2048_oaep_sha256_decrypt() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/kat/asymmetric/rsa2048_oaep_sha256_decrypt").await
    }

    // ── TLS transport vectors ─────────────────────────────────────────────

    #[tokio::test]
    async fn test_tls_server_tls() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/tls/server_tls").await
    }

    #[tokio::test]
    async fn test_tls_mtls() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/tls/mtls").await
    }

    // ── Integration vectors: FIPS ─────────────────────────────────────────

    #[tokio::test]
    async fn test_integration_mysql() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/integrations/mysql").await
    }

    #[tokio::test]
    async fn test_integration_percona() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/integrations/percona").await
    }

    #[tokio::test]
    async fn test_integration_fortigate() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/integrations/fortigate").await
    }

    #[tokio::test]
    async fn test_integration_fortigate_credential_type() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/integrations/fortigate_credential_type").await
    }

    #[tokio::test]
    async fn test_integration_fortigate_locate_filter() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/integrations/fortigate_locate_filter").await
    }

    #[tokio::test]
    async fn test_integration_fortigate_locate_get() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/integrations/fortigate_locate_get").await
    }

    #[tokio::test]
    async fn test_integration_fortigate_locate_many_similar_names() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/integrations/fortigate_locate_many_similar_names")
            .await
    }

    #[tokio::test]
    async fn test_integration_fortigate_locate_multi_tunnel() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/integrations/fortigate_locate_multi_tunnel").await
    }

    #[tokio::test]
    async fn test_integration_fortigate_locate_no_match() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/integrations/fortigate_locate_no_match").await
    }

    #[tokio::test]
    async fn test_integration_synology_dsm() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/integrations/synology_dsm").await
    }

    #[tokio::test]
    async fn test_integration_veeam() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/integrations/veeam").await
    }

    #[tokio::test]
    async fn test_integration_vast_data() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/integrations/vast_data").await
    }

    #[tokio::test]
    async fn test_integration_vmware_vcenter() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/integrations/vmware_vcenter").await
    }

    #[tokio::test]
    async fn test_integration_kmip_1_3_symmetric() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/integrations/kmip_1_3_symmetric").await
    }

    #[tokio::test]
    async fn test_integration_kmip_1_3_asymmetric() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/integrations/kmip_1_3_asymmetric").await
    }

    // ── Integration vectors: non-FIPS ─────────────────────────────────────

    #[cfg(feature = "non-fips")]
    #[tokio::test]
    async fn test_integration_mongodb() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/non-fips/integrations/mongodb").await
    }

    #[cfg(feature = "non-fips")]
    #[tokio::test]
    async fn test_integration_pykmip() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/non-fips/integrations/pykmip").await
    }

    #[cfg(feature = "non-fips")]
    #[tokio::test]
    async fn test_integration_edb_tde_pykmip_variant() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/non-fips/integrations/edb_tde_pykmip_variant").await
    }

    #[cfg(feature = "non-fips")]
    #[tokio::test]
    async fn test_integration_edb_tde_thales_variant() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/non-fips/integrations/edb_tde_thales_variant").await
    }

    #[cfg(feature = "non-fips")]
    #[tokio::test]
    async fn test_integration_edb_tde_key_rotation() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/non-fips/integrations/edb_tde_key_rotation").await
    }

    // ── KAT vectors: non-FIPS symmetric ──────────────────────────────────

    #[cfg(feature = "non-fips")]
    #[tokio::test]
    async fn test_kat_sym_aes128_gcm_siv() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/kat/symmetric/aes128_gcm_siv").await
    }

    #[cfg(feature = "non-fips")]
    #[tokio::test]
    async fn test_kat_sym_aes256_gcm_siv() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/kat/symmetric/aes256_gcm_siv").await
    }

    // ── KAT vectors: non-FIPS asymmetric ─────────────────────────────────

    #[cfg(feature = "non-fips")]
    #[tokio::test]
    async fn test_kat_asym_ed448_eddsa_sign() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/kat/asymmetric/ed448_eddsa_sign").await
    }

    #[cfg(feature = "non-fips")]
    #[tokio::test]
    async fn test_kat_asym_secp256k1_ecdsa_sign() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/kat/asymmetric/secp256k1_ecdsa_sign").await
    }

    // ── KAT vectors: non-FIPS Covercrypt ─────────────────────────────────

    #[cfg(feature = "non-fips")]
    #[tokio::test]
    async fn test_kat_covercrypt_decrypt() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/kat/covercrypt_decrypt").await
    }

    // ── non-FIPS: CryptographicParameters coverage ───────────────────────

    #[cfg(feature = "non-fips")]
    #[tokio::test]
    async fn test_non_fips_cp_aes128_gcm_siv_with_explicit_nonce() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/non-fips/aes128_gcm_siv_with_explicit_nonce").await
    }

    #[cfg(feature = "non-fips")]
    #[tokio::test]
    async fn test_non_fips_cp_aes256_gcm_siv_with_explicit_nonce() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/non-fips/aes256_gcm_siv_with_explicit_nonce").await
    }

    #[cfg(feature = "non-fips")]
    #[tokio::test]
    async fn test_non_fips_cp_aes128_gcm_siv_with_aad() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/non-fips/aes128_gcm_siv_with_aad").await
    }

    #[cfg(feature = "non-fips")]
    #[tokio::test]
    async fn test_non_fips_cp_aes256_gcm_siv_with_aad() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/non-fips/aes256_gcm_siv_with_aad").await
    }

    #[cfg(feature = "non-fips")]
    #[tokio::test]
    async fn test_non_fips_cp_chacha20_server_generated_nonce() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/non-fips/chacha20_server_generated_nonce").await
    }

    #[cfg(feature = "non-fips")]
    #[tokio::test]
    async fn test_non_fips_cp_chacha20_with_explicit_cryptographic_params()
    -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/non-fips/chacha20_with_explicit_cryptographic_params")
            .await
    }

    #[cfg(feature = "non-fips")]
    #[tokio::test]
    async fn test_non_fips_cp_chacha20_poly1305_with_explicit_nonce() -> Result<(), KmsClientError>
    {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/non-fips/chacha20_poly1305_with_explicit_nonce").await
    }

    #[cfg(feature = "non-fips")]
    #[tokio::test]
    async fn test_non_fips_cp_chacha20_poly1305_with_aad() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/non-fips/chacha20_poly1305_with_aad").await
    }

    // ── Negative tests: protocol-level ───────────────────────────────────

    #[tokio::test]
    async fn test_neg_empty_request() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/negative/empty_request").await
    }

    #[tokio::test]
    async fn test_neg_missing_data_encrypt() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/negative/missing_data_encrypt").await
    }

    #[tokio::test]
    async fn test_neg_missing_data_decrypt() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/negative/missing_data_decrypt").await
    }

    #[tokio::test]
    async fn test_neg_missing_uid_encrypt() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/negative/missing_uid_encrypt").await
    }

    #[tokio::test]
    async fn test_neg_nonexistent_key_encrypt() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/negative/nonexistent_key_encrypt").await
    }

    #[tokio::test]
    async fn test_neg_nonexistent_key_decrypt() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/negative/nonexistent_key_decrypt").await
    }

    #[tokio::test]
    async fn test_neg_wrong_key_type_encrypt() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/negative/wrong_key_type_encrypt").await
    }

    #[tokio::test]
    async fn test_neg_destroy_then_encrypt() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/negative/destroy_then_encrypt").await
    }

    #[tokio::test]
    async fn test_neg_empty_data_encrypt() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/negative/empty_data_encrypt").await
    }

    #[tokio::test]
    async fn test_neg_invalid_iv_length() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/negative/invalid_iv_length").await
    }

    #[tokio::test]
    async fn test_neg_sign_with_encrypt_key() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/negative/sign_with_encrypt_key").await
    }

    // ── Negative tests: CryptographicParameters ─────────────────────────

    #[tokio::test]
    async fn test_neg_cp_encrypt_unsupported_mode() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/negative/crypto_params/encrypt_unsupported_mode").await
    }

    #[tokio::test]
    async fn test_neg_cp_encrypt_unsupported_padding() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/negative/crypto_params/encrypt_unsupported_padding")
            .await
    }

    #[cfg(feature = "non-fips")]
    #[tokio::test]
    async fn test_neg_cp_encrypt_mode_algo_mismatch() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/negative/crypto_params/encrypt_mode_algo_mismatch").await
    }

    #[tokio::test]
    async fn test_neg_cp_encrypt_gcm_invalid_tag_length() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/negative/crypto_params/encrypt_gcm_invalid_tag_length")
            .await
    }

    // MD5 is not FIPS-approved; this test documents that RSA-PSS/MD5 succeeds
    // only when the legacy OpenSSL provider is active (non-FIPS mode).
    #[cfg(feature = "non-fips")]
    #[tokio::test]
    async fn test_neg_cp_sign_invalid_hash() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/negative/crypto_params/sign_invalid_hash").await
    }

    #[tokio::test]
    async fn test_neg_cp_sign_rsa_with_ecdsa_algo() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/negative/crypto_params/sign_rsa_with_ecdsa_algo").await
    }

    #[tokio::test]
    async fn test_neg_cp_decrypt_wrong_mode() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/negative/crypto_params/decrypt_wrong_mode").await
    }

    #[cfg(feature = "non-fips")]
    #[tokio::test]
    async fn test_neg_cp_encrypt_chacha20_with_gcm_mode() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/negative/crypto_params/encrypt_chacha20_with_gcm_mode")
            .await
    }

    #[tokio::test]
    async fn test_neg_cp_hash_unsupported_algo() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/negative/crypto_params/hash_unsupported_algo").await
    }

    #[tokio::test]
    async fn test_neg_cp_mac_unsupported_algo() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/negative/crypto_params/mac_unsupported_algo").await
    }

    // ── Negative tests: decrypt edge cases ──────────────────────────────

    #[tokio::test]
    async fn test_neg_decrypt_missing_iv_cbc() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/negative/decrypt/decrypt_missing_iv_cbc").await
    }

    #[tokio::test]
    async fn test_neg_decrypt_empty_tag_gcm() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/negative/decrypt/decrypt_empty_tag_gcm").await
    }

    #[tokio::test]
    async fn test_neg_decrypt_truncated_ciphertext() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/negative/decrypt/decrypt_truncated_ciphertext").await
    }

    #[tokio::test]
    async fn test_neg_decrypt_wrong_key() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/negative/decrypt/decrypt_wrong_key").await
    }

    #[tokio::test]
    async fn test_neg_decrypt_corrupted_ciphertext() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/negative/decrypt/decrypt_corrupted_ciphertext").await
    }

    // ── Negative tests: RSA edge cases ──────────────────────────────────

    #[tokio::test]
    async fn test_neg_rsa_encrypt_oversized_data() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/negative/rsa/rsa_encrypt_oversized_data").await
    }

    #[tokio::test]
    async fn test_neg_rsa_decrypt_with_public_key() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/negative/rsa/rsa_decrypt_with_public_key").await
    }

    #[tokio::test]
    async fn test_neg_rsa_decrypt_garbage() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/negative/rsa/rsa_decrypt_garbage").await
    }

    // ── Negative tests: sign/verify edge cases ──────────────────────────

    #[tokio::test]
    async fn test_neg_verify_corrupted_signature() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/negative/sign_verify/verify_corrupted_signature").await
    }

    #[tokio::test]
    async fn test_neg_verify_wrong_key() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/negative/sign_verify/verify_wrong_key").await
    }

    #[tokio::test]
    async fn test_neg_sign_with_public_key() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/negative/sign_verify/sign_with_public_key").await
    }

    // ── Negative tests: MAC edge cases ──────────────────────────────────

    #[tokio::test]
    async fn test_neg_mac_with_non_hmac_key() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/negative/mac/mac_with_non_hmac_key").await
    }

    #[tokio::test]
    async fn test_neg_mac_verify_wrong_data() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/negative/mac/mac_verify_wrong_data").await
    }

    // ── Negative tests: hash edge cases ─────────────────────────────────

    #[tokio::test]
    async fn test_neg_hash_missing_algorithm() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/negative/hash/hash_missing_algorithm").await
    }

    #[tokio::test]
    async fn test_neg_hash_init_and_final_both_true() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/negative/hash/hash_init_and_final_both_true").await
    }

    // ── Negative tests: derive key edge cases ───────────────────────────

    #[tokio::test]
    async fn test_neg_derive_key_pbkdf2_no_salt() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/negative/derive_key/derive_key_pbkdf2_no_salt").await
    }

    #[tokio::test]
    async fn test_neg_derive_key_negative_iterations() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/negative/derive_key/derive_key_negative_iterations")
            .await
    }

    // ── Negative tests: lifecycle edge cases ────────────────────────────

    #[tokio::test]
    async fn test_neg_encrypt_pre_active_key() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/negative/lifecycle/encrypt_pre_active_key").await
    }

    #[tokio::test]
    async fn test_neg_create_invalid_algorithm() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/negative/lifecycle/create_invalid_algorithm").await
    }

    #[tokio::test]
    async fn test_neg_create_zero_length_key() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/negative/lifecycle/create_zero_length_key").await
    }

    #[tokio::test]
    async fn test_neg_create_hsm_key_without_hsm() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/negative/lifecycle/create_hsm_key_without_hsm").await
    }

    // ── Negative tests: type mismatch ───────────────────────────────────

    #[tokio::test]
    async fn test_neg_import_malformed_key() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/negative/type_mismatch/import_malformed_key").await
    }

    #[tokio::test]
    async fn test_neg_encrypt_with_secret_data() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/negative/type_mismatch/encrypt_with_secret_data").await
    }

    #[tokio::test]
    async fn test_neg_revoke_already_destroyed() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/negative/type_mismatch/revoke_already_destroyed").await
    }

    // ── Negative tests: state machine violations ────────────────────────

    #[tokio::test]
    async fn test_neg_double_activate() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/negative/lifecycle/double_activate").await
    }

    #[tokio::test]
    async fn test_neg_activate_destroyed() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/negative/lifecycle/deactivate_pre_active").await
    }

    #[tokio::test]
    async fn test_neg_reactivate_deactivated() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/negative/lifecycle/reactivate_deactivated").await
    }

    // ── Negative tests: duplicate tags (ambiguous key selection) ─────────

    #[tokio::test]
    async fn test_neg_duplicate_tags_encrypt() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/negative/duplicate_tags_encrypt").await
    }

    // ── Negative tests: KMIP spec error coverage ──────────────────────

    #[tokio::test]
    async fn test_neg_spec_activate_item_not_found() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/negative/activate/item_not_found").await
    }

    #[tokio::test]
    async fn test_neg_spec_activate_wrong_key_lifecycle_state() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/negative/activate/wrong_key_lifecycle_state").await
    }

    #[tokio::test]
    async fn test_neg_spec_add_attribute_item_not_found() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/negative/add_attribute/item_not_found").await
    }

    #[tokio::test]
    async fn test_neg_spec_add_attribute_read_only_attribute() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/negative/add_attribute/read_only_attribute").await
    }

    #[tokio::test]
    async fn test_neg_spec_certify_invalid_object_type() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/negative/certify/invalid_object_type").await
    }

    #[tokio::test]
    async fn test_neg_spec_certify_item_not_found() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/negative/certify/item_not_found").await
    }

    #[tokio::test]
    async fn test_neg_spec_check_item_not_found() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/negative/check/item_not_found").await
    }

    #[tokio::test]
    async fn test_neg_spec_create_invalid_attribute() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/negative/create/invalid_attribute").await
    }

    #[tokio::test]
    async fn test_neg_spec_create_invalid_attribute_value() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/negative/create/invalid_attribute_value").await
    }

    #[tokio::test]
    async fn test_neg_spec_create_invalid_field() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/negative/create/invalid_field").await
    }

    #[tokio::test]
    async fn test_neg_spec_create_invalid_message() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/negative/create/invalid_message").await
    }

    #[tokio::test]
    async fn test_neg_spec_create_read_only_attribute() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/negative/create/read_only_attribute").await
    }

    #[tokio::test]
    async fn test_neg_spec_create_key_pair_invalid_attribute() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/negative/create_key_pair/invalid_attribute").await
    }

    #[tokio::test]
    async fn test_neg_spec_create_key_pair_invalid_attribute_value() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/negative/create_key_pair/invalid_attribute_value").await
    }

    #[tokio::test]
    async fn test_neg_spec_create_key_pair_invalid_message() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/negative/create_key_pair/invalid_message").await
    }

    #[tokio::test]
    async fn test_neg_spec_decrypt_invalid_message() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/negative/decrypt/invalid_message").await
    }

    #[tokio::test]
    async fn test_neg_spec_decrypt_wrong_key_lifecycle_state() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/negative/decrypt/wrong_key_lifecycle_state").await
    }

    #[tokio::test]
    async fn test_neg_spec_delete_attribute_item_not_found() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/negative/delete_attribute/item_not_found").await
    }

    #[tokio::test]
    async fn test_neg_spec_destroy_item_not_found() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/negative/destroy/item_not_found").await
    }

    #[tokio::test]
    async fn test_neg_spec_destroy_wrong_key_lifecycle_state() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/negative/destroy/wrong_key_lifecycle_state").await
    }

    #[tokio::test]
    async fn test_neg_spec_encrypt_bad_cryptographic_parameters() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/negative/encrypt/bad_cryptographic_parameters").await
    }

    #[tokio::test]
    async fn test_neg_spec_encrypt_incompatible_cryptographic_usage_mask()
    -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/negative/encrypt/incompatible_cryptographic_usage_mask")
            .await
    }

    #[tokio::test]
    async fn test_neg_spec_encrypt_invalid_field() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/negative/encrypt/invalid_field").await
    }

    #[tokio::test]
    async fn test_neg_spec_encrypt_invalid_message() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/negative/encrypt/invalid_message").await
    }

    #[tokio::test]
    async fn test_neg_spec_encrypt_invalid_object_type() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/negative/encrypt/invalid_object_type").await
    }

    #[tokio::test]
    async fn test_neg_spec_encrypt_unsupported_cryptographic_parameters()
    -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/negative/encrypt/unsupported_cryptographic_parameters")
            .await
    }

    #[tokio::test]
    async fn test_neg_spec_encrypt_wrong_key_lifecycle_state() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/negative/encrypt/wrong_key_lifecycle_state").await
    }

    #[tokio::test]
    async fn test_neg_spec_export_item_not_found() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/negative/export/item_not_found").await
    }

    #[tokio::test]
    async fn test_neg_spec_export_key_format_type_not_supported() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/negative/export/key_format_type_not_supported").await
    }

    #[tokio::test]
    async fn test_neg_spec_get_item_not_found() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/negative/get/item_not_found").await
    }

    #[tokio::test]
    async fn test_neg_spec_get_key_format_type_not_supported() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/negative/get/key_format_type_not_supported").await
    }

    #[tokio::test]
    async fn test_neg_spec_get_attribute_list_item_not_found() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/negative/get_attribute_list/item_not_found").await
    }

    #[tokio::test]
    async fn test_neg_spec_get_attributes_item_not_found() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/negative/get_attributes/item_not_found").await
    }

    #[tokio::test]
    async fn test_neg_spec_import_invalid_message() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/negative/import/invalid_message").await
    }

    #[tokio::test]
    async fn test_neg_spec_mac_item_not_found() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/negative/mac/item_not_found").await
    }

    #[tokio::test]
    async fn test_neg_spec_mac_wrong_key_lifecycle_state() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/negative/mac/wrong_key_lifecycle_state").await
    }

    #[tokio::test]
    async fn test_neg_spec_mac_verify_item_not_found() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/negative/mac_verify/item_not_found").await
    }

    #[tokio::test]
    async fn test_neg_spec_mac_verify_wrong_key_lifecycle_state() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/negative/mac_verify/wrong_key_lifecycle_state").await
    }

    #[tokio::test]
    async fn test_neg_spec_modify_attribute_item_not_found() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/negative/modify_attribute/item_not_found").await
    }

    #[tokio::test]
    async fn test_neg_spec_modify_attribute_read_only_attribute() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/negative/modify_attribute/read_only_attribute").await
    }

    #[tokio::test]
    async fn test_neg_spec_register_invalid_attribute() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/negative/register/invalid_attribute").await
    }

    #[tokio::test]
    async fn test_neg_spec_register_invalid_attribute_value() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/negative/register/invalid_attribute_value").await
    }

    #[tokio::test]
    async fn test_neg_spec_register_invalid_message() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/negative/register/invalid_message").await
    }

    #[tokio::test]
    async fn test_neg_spec_revoke_item_not_found() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/negative/revoke/item_not_found").await
    }

    #[tokio::test]
    async fn test_neg_spec_set_attribute_item_not_found() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/negative/set_attribute/item_not_found").await
    }

    #[tokio::test]
    async fn test_neg_spec_set_attribute_read_only_attribute() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/negative/set_attribute/read_only_attribute").await
    }

    #[tokio::test]
    async fn test_neg_spec_sign_invalid_message() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/negative/sign/invalid_message").await
    }

    #[tokio::test]
    async fn test_neg_spec_sign_item_not_found() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/negative/sign/item_not_found").await
    }

    #[tokio::test]
    async fn test_neg_spec_sign_wrong_key_lifecycle_state() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/negative/sign/wrong_key_lifecycle_state").await
    }

    #[tokio::test]
    async fn test_neg_spec_signature_verify_item_not_found() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/negative/signature_verify/item_not_found").await
    }

    #[tokio::test]
    async fn test_neg_spec_signature_verify_wrong_key_lifecycle_state() -> Result<(), KmsClientError>
    {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/negative/signature_verify/wrong_key_lifecycle_state")
            .await
    }

    #[tokio::test]
    async fn test_neg_spec_validate_item_not_found() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/negative/validate/item_not_found").await
    }

    // ── Negative tests: ReCertify ───────────────────────────────────────
    // ReCertify is not yet implemented (KMIP 1.4 only); these tests verify the
    // server correctly rejects the operation. Enable positive recertify tests
    // above once the operation is dispatched.

    #[tokio::test]
    async fn test_neg_recertify_missing_uid() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/negative/recertify_missing_uid").await
    }

    #[tokio::test]
    async fn test_neg_recertify_nonexistent() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/negative/recertify_nonexistent").await
    }

    #[tokio::test]
    async fn test_neg_recertify_not_a_certificate() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/negative/recertify_not_a_certificate").await
    }

    // ── KMIP operations: Batch requests ─────────────────────────────────

    #[tokio::test]
    async fn test_vec_batch_create_get() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/kmip_operations/batch_create_get").await
    }

    #[tokio::test]
    async fn test_vec_batch_hash_query() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/kmip_operations/batch_hash_query").await
    }

    // ── KMIP operations: ReCertify ──────────────────────────────────────

    // #[tokio::test]
    // async fn test_vec_recertify_chain() -> Result<(), KmsClientError> {
    //     crate::init_test_logging();
    //     run_test_vector("test_data/vectors/fips/kmip_operations/recertify_chain").await
    // }

    // #[tokio::test]
    // async fn test_vec_recertify_self_signed() -> Result<(), KmsClientError> {
    //     crate::init_test_logging();
    //     run_test_vector("test_data/vectors/fips/kmip_operations/recertify_self_signed").await
    // }

    // #[tokio::test]
    // async fn test_vec_recertify_with_links() -> Result<(), KmsClientError> {
    //     crate::init_test_logging();
    //     run_test_vector("test_data/vectors/fips/kmip_operations/recertify_with_links").await
    // }

    // #[tokio::test]
    // async fn test_vec_recertify_with_offset() -> Result<(), KmsClientError> {
    //     crate::init_test_logging();
    //     run_test_vector("test_data/vectors/fips/kmip_operations/recertify_with_offset").await
    // }

    // ── KMIP operations: ReKey with offset/state ─────────────────────────

    #[cfg(feature = "non-fips")]
    #[tokio::test]
    async fn test_vec_rekey_keypair_with_offset_state() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/kmip_operations/rekey_keypair_with_offset_state")
            .await
    }

    #[cfg(feature = "non-fips")]
    #[tokio::test]
    async fn test_vec_rekey_with_offset_state() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/kmip_operations/rekey_with_offset_state").await
    }

    // ── KMIP operations: ReKeyKeyPair (non-FIPS only) ────────────────────
    // These vectors do not supply PrivateKeyAttributes/PublicKeyAttributes with
    // FIPS-compliant CryptographicUsageMask values, and some use PQC algorithms
    // only available in non-FIPS mode.

    #[cfg(feature = "non-fips")]
    #[tokio::test]
    async fn test_vec_rekey_keypair_rsa() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/kmip_operations/rekey_keypair_rsa").await
    }

    #[cfg(feature = "non-fips")]
    #[tokio::test]
    async fn test_vec_rekey_keypair_ec() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/kmip_operations/rekey_keypair_ec").await
    }

    #[cfg(feature = "non-fips")]
    #[tokio::test]
    async fn test_vec_rekey_keypair_ec_with_links() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/kmip_operations/rekey_keypair_ec_with_links").await
    }

    #[cfg(feature = "non-fips")]
    #[tokio::test]
    async fn test_vec_rekey_keypair_rsa_with_links() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/kmip_operations/rekey_keypair_rsa_with_links").await
    }

    #[cfg(feature = "non-fips")]
    #[tokio::test]
    async fn test_vec_rekey_keypair_ec_locate_by_name() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/kmip_operations/rekey_keypair_ec_locate_by_name")
            .await
    }

    #[cfg(feature = "non-fips")]
    #[tokio::test]
    async fn test_vec_rekey_keypair_ec_sign_verify() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/kmip_operations/rekey_keypair_ec_sign_verify").await
    }

    #[cfg(feature = "non-fips")]
    #[tokio::test]
    async fn test_vec_rekey_keypair_rsa_encrypt_decrypt() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/kmip_operations/rekey_keypair_rsa_encrypt_decrypt")
            .await
    }

    #[cfg(feature = "non-fips")]
    #[tokio::test]
    async fn test_vec_rekey_keypair_p384() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/kmip_operations/rekey_keypair_p384").await
    }

    #[cfg(feature = "non-fips")]
    #[tokio::test]
    async fn test_vec_rekey_keypair_p521() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/kmip_operations/rekey_keypair_p521").await
    }

    #[cfg(feature = "non-fips")]
    #[tokio::test]
    async fn test_vec_rekey_keypair_rsa4096() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/kmip_operations/rekey_keypair_rsa4096").await
    }

    #[cfg(feature = "non-fips")]
    #[tokio::test]
    async fn test_vec_rekey_keypair_ml_kem_768() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/kmip_operations/rekey_keypair_ml_kem_768").await
    }

    #[cfg(feature = "non-fips")]
    #[tokio::test]
    async fn test_vec_rekey_keypair_ml_kem_1024() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/kmip_operations/rekey_keypair_ml_kem_1024").await
    }

    #[cfg(feature = "non-fips")]
    #[tokio::test]
    async fn test_vec_rekey_keypair_ml_dsa_65() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/kmip_operations/rekey_keypair_ml_dsa_65").await
    }

    #[cfg(feature = "non-fips")]
    #[tokio::test]
    async fn test_vec_rekey_keypair_ml_dsa_87() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/kmip_operations/rekey_keypair_ml_dsa_87").await
    }

    #[cfg(feature = "non-fips")]
    #[tokio::test]
    async fn test_vec_rekey_keypair_slh_dsa_sha2_128f() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/kmip_operations/rekey_keypair_slh_dsa_sha2_128f")
            .await
    }

    #[cfg(feature = "non-fips")]
    #[tokio::test]
    async fn test_vec_rekey_keypair_with_offset() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/kmip_operations/rekey_keypair_with_offset").await
    }

    #[cfg(feature = "non-fips")]
    #[tokio::test]
    async fn test_vec_rekey_keypair_double_chain() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/kmip_operations/rekey_keypair_double_chain").await
    }

    #[cfg(feature = "non-fips")]
    #[tokio::test]
    async fn test_vec_rekey_keypair_deactivated_fails() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/kmip_operations/rekey_keypair_deactivated_fails")
            .await
    }

    #[cfg(feature = "non-fips")]
    #[tokio::test]
    async fn test_vec_rekey_keypair_no_public_link_fails() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/kmip_operations/rekey_keypair_no_public_link_fails")
            .await
    }

    #[cfg(feature = "non-fips")]
    #[tokio::test]
    async fn test_vec_rekey_keypair_change_algo_fails() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/kmip_operations/rekey_keypair_change_algo_fails")
            .await
    }

    #[cfg(feature = "non-fips")]
    #[tokio::test]
    async fn test_vec_rekey_keypair_old_key_still_active() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/kmip_operations/rekey_keypair_old_key_still_active")
            .await
    }

    #[cfg(feature = "non-fips")]
    #[tokio::test]
    async fn test_vec_rekey_keypair_name_removed_from_old() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector(
            "test_data/vectors/fips/kmip_operations/rekey_keypair_name_removed_from_old",
        )
        .await
    }

    // ── Non-FIPS ReKeyKeyPair vectors ───────────────────────────────────

    #[cfg(feature = "non-fips")]
    #[tokio::test]
    async fn test_vec_rekey_keypair_ed25519() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/non-fips/rekey_keypair_ed25519").await
    }

    #[cfg(feature = "non-fips")]
    #[tokio::test]
    async fn test_vec_rekey_keypair_x25519() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/non-fips/rekey_keypair_x25519").await
    }

    #[cfg(feature = "non-fips")]
    #[tokio::test]
    async fn test_vec_rekey_keypair_secp256k1() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/non-fips/rekey_keypair_secp256k1").await
    }

    #[cfg(feature = "non-fips")]
    #[tokio::test]
    async fn test_vec_rekey_keypair_covercrypt() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/non-fips/rekey_keypair_covercrypt").await
    }

    // ── KMIP operations: certificate chain and revoke ───────────────────

    #[cfg(feature = "non-fips")]
    #[tokio::test]
    async fn test_vec_certify_chain() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/kmip_operations/certify_chain").await
    }

    #[cfg(feature = "non-fips")]
    #[tokio::test]
    async fn test_vec_certify_revoke_validate() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/kmip_operations/certify_revoke_validate").await
    }

    // ── KMIP operations: Locate filters ─────────────────────────────────

    #[tokio::test]
    async fn test_vec_locate_by_state() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/kmip_operations/locate_by_state").await
    }

    #[tokio::test]
    async fn test_vec_locate_by_usage_mask() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/kmip_operations/locate_by_usage_mask").await
    }

    #[tokio::test]
    async fn test_vec_locate_by_tag() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/kmip_operations/locate_by_tag").await
    }

    // ── Access control: owner/user certificate identities ───────────────

    #[tokio::test]
    async fn test_vec_access_grant_aes() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/access_control/grant_access_aes").await
    }

    #[tokio::test]
    async fn test_vec_access_revoke() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/access_control/revoke_access").await
    }

    #[tokio::test]
    async fn test_vec_access_unauthorized() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/access_control/unauthorized_access").await
    }

    #[tokio::test]
    async fn test_vec_access_owner_full() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/access_control/owner_full_permissions").await
    }

    #[tokio::test]
    async fn test_vec_access_grant_partial() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/access_control/grant_partial_permissions").await
    }

    #[tokio::test]
    async fn test_vec_access_revoke_key_lifecycle() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/access_control/revoke_key_lifecycle").await
    }

    #[tokio::test]
    async fn test_vec_access_privilege_escalation_self_grant() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/access_control/privilege_escalation_self_grant").await
    }

    #[tokio::test]
    async fn test_vec_access_privilege_escalation_non_owner_grant() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/access_control/privilege_escalation_non_owner_grant")
            .await
    }

    #[tokio::test]
    async fn test_vec_access_privilege_escalation_destroy() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector(
            "test_data/vectors/access_control/privilege_escalation_destroy_without_permission",
        )
        .await
    }

    #[tokio::test]
    async fn test_vec_access_privilege_escalation_rekey() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector(
            "test_data/vectors/access_control/privilege_escalation_rekey_without_permission",
        )
        .await
    }

    #[tokio::test]
    async fn test_vec_access_privilege_escalation_activate() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector(
            "test_data/vectors/access_control/privilege_escalation_activate_without_permission",
        )
        .await
    }

    // ── HSM + KEK vectors ─────────────────────────────────────────────────

    #[tokio::test]
    async fn test_vec_hsm_kek_encrypt_decrypt() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/hsm/kek_encrypt_decrypt").await
    }

    #[tokio::test]
    async fn test_vec_hsm_kek_sign_verify() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/hsm/kek_sign_verify").await
    }

    #[tokio::test]
    async fn test_vec_hsm_kek_aes256_create_encrypt() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/hsm/kek_aes256_create_encrypt").await
    }

    #[tokio::test]
    async fn test_vec_hsm_kek_rsa2048_create_sign() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/hsm/kek_rsa2048_create_sign").await
    }

    #[tokio::test]
    async fn test_vec_hsm_kek_ec_p256_create_sign() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/hsm/kek_ec_p256_create_sign").await
    }

    #[tokio::test]
    async fn test_vec_hsm_kek_ed25519_create_sign() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/hsm/kek_ed25519_create_sign").await
    }

    #[tokio::test]
    #[cfg(not(feature = "non-fips"))]
    async fn test_vec_hsm_kek_rsa1024_rejected() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/hsm/kek_rsa1024_rejected").await
    }

    // ── HSM Resident: Key Creation ───────────────────────────────────────

    #[tokio::test]
    async fn test_vec_hsm_resident_aes128_create_encrypt() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/hsm/resident_aes128_create_encrypt").await
    }

    #[tokio::test]
    async fn test_vec_hsm_resident_aes256_create_encrypt() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/hsm/resident_aes256_create_encrypt").await
    }

    #[tokio::test]
    async fn test_vec_hsm_resident_rsa4096_create_sign() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/hsm/resident_rsa4096_create_sign").await
    }

    // ── HSM Resident: Encryption ─────────────────────────────────────────

    #[tokio::test]
    async fn test_vec_hsm_resident_aes256_encrypt_cbc() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/hsm/resident_aes256_encrypt_cbc").await
    }

    #[tokio::test]
    async fn test_vec_hsm_resident_rsa2048_encrypt_oaep_sha256() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/hsm/resident_rsa2048_encrypt_oaep_sha256").await
    }

    #[tokio::test]
    async fn test_vec_hsm_resident_rsa2048_encrypt_oaep_sha1() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/hsm/resident_rsa2048_encrypt_oaep_sha1").await
    }

    #[tokio::test]
    async fn test_vec_hsm_resident_rsa2048_encrypt_pkcs1v15() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/hsm/resident_rsa2048_encrypt_pkcs1v15").await
    }

    // ── HSM Resident: Signing ────────────────────────────────────────────

    #[tokio::test]
    async fn test_vec_hsm_resident_rsa2048_sign_pkcs1v15() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/hsm/resident_rsa2048_sign_pkcs1v15").await
    }

    #[tokio::test]
    async fn test_vec_hsm_resident_rsa2048_sign_sha1() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/hsm/resident_rsa2048_sign_sha1").await
    }

    #[tokio::test]
    async fn test_vec_hsm_resident_rsa2048_sign_sha256() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/hsm/resident_rsa2048_sign_sha256").await
    }

    #[tokio::test]
    async fn test_vec_hsm_resident_rsa2048_sign_sha384() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/hsm/resident_rsa2048_sign_sha384").await
    }

    #[tokio::test]
    async fn test_vec_hsm_resident_rsa2048_sign_sha512() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/hsm/resident_rsa2048_sign_sha512").await
    }

    // ── HSM Resident: Negative tests ─────────────────────────────────────

    #[tokio::test]
    #[cfg(not(feature = "non-fips"))]
    async fn test_vec_hsm_resident_rsa1024_rejected() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/hsm/resident_rsa1024_rejected").await
    }

    #[tokio::test]
    async fn test_vec_hsm_resident_ec_p256_rejected() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/hsm/resident_ec_p256_rejected").await
    }

    #[tokio::test]
    async fn test_vec_hsm_resident_ec_p384_rejected() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/hsm/resident_ec_p384_rejected").await
    }

    #[tokio::test]
    async fn test_vec_hsm_resident_ed25519_rejected() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/hsm/resident_ed25519_rejected").await
    }

    #[tokio::test]
    async fn test_vec_hsm_resident_non_aes_rejected() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/hsm/resident_non_aes_rejected").await
    }

    #[tokio::test]
    async fn test_vec_hsm_resident_aes256_encrypt_ecb_rejected() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/hsm/resident_aes256_encrypt_ecb_rejected").await
    }

    #[tokio::test]
    async fn test_vec_hsm_resident_rsa2048_sign_ecdsa_rejected() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/hsm/resident_rsa2048_sign_ecdsa_rejected").await
    }

    #[tokio::test]
    async fn test_vec_hsm_resident_rsa2048_sign_dsa_rejected() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/hsm/resident_rsa2048_sign_dsa_rejected").await
    }

    #[tokio::test]
    async fn test_vec_hsm_wrong_prefix() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/hsm/wrong_prefix").await
    }

    #[tokio::test]
    async fn test_vec_hsm_no_kek_baseline() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/hsm/no_kek_baseline").await
    }

    #[tokio::test]
    async fn test_vec_hsm_resident_encrypt_all() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/hsm/hsm_resident_encrypt").await
    }

    #[tokio::test]
    async fn test_vec_hsm_resident_sign_all() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/hsm/hsm_resident_sign").await
    }

    // ── HSM permission vectors ────────────────────────────────────────────

    #[tokio::test]
    async fn test_vec_hsm_perm_admin_create_encrypt_destroy() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/hsm/permissions/admin_create_encrypt_destroy").await
    }

    #[tokio::test]
    async fn test_vec_hsm_perm_admin_grant_encrypt_decrypt() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/hsm/permissions/admin_grant_encrypt_decrypt").await
    }

    #[tokio::test]
    async fn test_vec_hsm_perm_get_not_wildcard() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/hsm/permissions/get_not_wildcard").await
    }

    #[tokio::test]
    async fn test_vec_hsm_perm_admin_grant_revoke() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/hsm/permissions/admin_grant_revoke").await
    }

    #[tokio::test]
    async fn test_vec_hsm_perm_user_cannot_create() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/hsm/permissions/user_cannot_create").await
    }

    #[tokio::test]
    async fn test_vec_hsm_perm_user_cannot_destroy() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/hsm/permissions/user_cannot_destroy").await
    }

    #[tokio::test]
    async fn test_vec_hsm_perm_user_cannot_encrypt() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/hsm/permissions/user_cannot_encrypt").await
    }

    #[tokio::test]
    async fn test_vec_hsm_perm_user_cannot_grant() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/hsm/permissions/user_cannot_grant").await
    }

    #[tokio::test]
    async fn test_vec_hsm_perm_cannot_grant_destroy() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/hsm/permissions/cannot_grant_destroy").await
    }

    #[tokio::test]
    async fn test_vec_hsm_perm_locate_visibility() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/hsm/permissions/locate_visibility").await
    }

    // ── Serialization round-trip vectors ────────────────────────────────────────
    // Verify that objects and attributes survive the KMIP 3.0 DB serialization
    // (KMIP3: prefix for objects, raw 3.0 JSON for attributes).

    #[tokio::test]
    async fn test_vec_serial_create_locate_roundtrip() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/serialization/create_locate_roundtrip").await
    }

    #[tokio::test]
    async fn test_vec_serial_create_encrypt_decrypt() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/serialization/create_encrypt_decrypt_roundtrip")
            .await
    }

    // #[tokio::test]
    // async fn test_vec_serial_rsa_sign_verify() -> Result<(), KmsClientError> {
    //     crate::init_test_logging();
    //     run_test_vector("test_data/vectors/fips/serialization/rsa_sign_verify_roundtrip").await
    // }

    #[tokio::test]
    async fn test_vec_serial_attributes_preservation() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/serialization/attributes_preservation").await
    }

    #[tokio::test]
    async fn test_vec_serial_import_destroy_reimport() -> Result<(), KmsClientError> {
        crate::init_test_logging();
        run_test_vector("test_data/vectors/fips/serialization/import_destroy_reimport").await
    }
}