Marco Ricci commited on 2025-01-11 19:04:57
              Zeige 1 geänderte Dateien mit 49 Einfügungen und 9 Löschungen.
            
For each test calling an export handler directly, also perform the test when calling the export handler dispatcher.
| ... | ... | 
                      @@ -267,11 +267,19 @@ class TestStoreroom:  | 
                  
| 267 | 267 | 
                        ),  | 
                    
| 268 | 268 | 
                        ],  | 
                    
| 269 | 269 | 
                        )  | 
                    
| 270 | 
                        + @pytest.mark.parametrize(  | 
                    |
| 271 | 
                        + 'handler',  | 
                    |
| 272 | 
                        + [  | 
                    |
| 273 | 
                        + pytest.param(storeroom.export_storeroom_data, id='handler'),  | 
                    |
| 274 | 
                        + pytest.param(exporter.export_vault_config_data, id='dispatcher'),  | 
                    |
| 275 | 
                        + ],  | 
                    |
| 276 | 
                        + )  | 
                    |
| 270 | 277 | 
                        def test_200_export_data_path_and_keys_type(  | 
                    
| 271 | 278 | 
                        self,  | 
                    
| 272 | 279 | 
                        monkeypatch: pytest.MonkeyPatch,  | 
                    
| 273 | 280 | 
                        path: str | None,  | 
                    
| 274 | 281 | 
                        key: str | Buffer | None,  | 
                    
| 282 | 
                        + handler: exporter.ExportVaultConfigDataFunction,  | 
                    |
| 275 | 283 | 
                        ) -> None:  | 
                    
| 276 | 284 | 
                        runner = click.testing.CliRunner(mix_stderr=False)  | 
                    
| 277 | 285 | 
                        with tests.isolated_vault_exporter_config(  | 
                    
| ... | ... | 
                      @@ -281,7 +289,7 @@ class TestStoreroom:  | 
                  
| 281 | 289 | 
                        vault_key=tests.VAULT_MASTER_KEY,  | 
                    
| 282 | 290 | 
                        ):  | 
                    
| 283 | 291 | 
                        assert (  | 
                    
| 284 | 
                        - storeroom.export_storeroom_data(path, key)  | 
                    |
| 292 | 
                        + handler(path, key, format='storeroom')  | 
                    |
| 285 | 293 | 
                        == tests.VAULT_STOREROOM_CONFIG_DATA  | 
                    
| 286 | 294 | 
                        )  | 
                    
| 287 | 295 | 
                         | 
                    
| ... | ... | 
                      @@ -327,11 +335,19 @@ class TestStoreroom:  | 
                  
| 327 | 335 | 
                                     ('{"version": 1}\nAAAA', 'cannot handle version 0 encrypted keys'),
                       | 
                    
| 328 | 336 | 
                        ],  | 
                    
| 329 | 337 | 
                        )  | 
                    
| 338 | 
                        + @pytest.mark.parametrize(  | 
                    |
| 339 | 
                        + 'handler',  | 
                    |
| 340 | 
                        + [  | 
                    |
| 341 | 
                        + pytest.param(storeroom.export_storeroom_data, id='handler'),  | 
                    |
| 342 | 
                        + pytest.param(exporter.export_vault_config_data, id='dispatcher'),  | 
                    |
| 343 | 
                        + ],  | 
                    |
| 344 | 
                        + )  | 
                    |
| 330 | 345 | 
                        def test_402_export_storeroom_data_bad_master_keys_file(  | 
                    
| 331 | 346 | 
                        self,  | 
                    
| 332 | 347 | 
                        monkeypatch: pytest.MonkeyPatch,  | 
                    
| 333 | 348 | 
                        data: str,  | 
                    
| 334 | 349 | 
                        err_msg: str,  | 
                    
| 350 | 
                        + handler: exporter.ExportVaultConfigDataFunction,  | 
                    |
| 335 | 351 | 
                        ) -> None:  | 
                    
| 336 | 352 | 
                        runner = click.testing.CliRunner(mix_stderr=False)  | 
                    
| 337 | 353 | 
                        with tests.isolated_vault_exporter_config(  | 
                    
| ... | ... | 
                      @@ -343,7 +359,7 @@ class TestStoreroom:  | 
                  
| 343 | 359 | 
                                     with open('.vault/.keys', 'w', encoding='UTF-8') as outfile:
                       | 
                    
| 344 | 360 | 
                        print(data, file=outfile)  | 
                    
| 345 | 361 | 
                        with pytest.raises(RuntimeError, match=err_msg):  | 
                    
| 346 | 
                        - storeroom.export_storeroom_data()  | 
                    |
| 362 | 
                        + handler(format='storeroom')  | 
                    |
| 347 | 363 | 
                         | 
                    
| 348 | 364 | 
                        @pytest.mark.parametrize(  | 
                    
| 349 | 365 | 
                        ['zipped_config', 'error_text'],  | 
                    
| ... | ... | 
                      @@ -370,11 +386,19 @@ class TestStoreroom:  | 
                  
| 370 | 386 | 
                        ),  | 
                    
| 371 | 387 | 
                        ],  | 
                    
| 372 | 388 | 
                        )  | 
                    
| 389 | 
                        + @pytest.mark.parametrize(  | 
                    |
| 390 | 
                        + 'handler',  | 
                    |
| 391 | 
                        + [  | 
                    |
| 392 | 
                        + pytest.param(storeroom.export_storeroom_data, id='handler'),  | 
                    |
| 393 | 
                        + pytest.param(exporter.export_vault_config_data, id='dispatcher'),  | 
                    |
| 394 | 
                        + ],  | 
                    |
| 395 | 
                        + )  | 
                    |
| 373 | 396 | 
                        def test_403_export_storeroom_data_bad_directory_listing(  | 
                    
| 374 | 397 | 
                        self,  | 
                    
| 375 | 398 | 
                        monkeypatch: pytest.MonkeyPatch,  | 
                    
| 376 | 399 | 
                        zipped_config: bytes,  | 
                    
| 377 | 400 | 
                        error_text: str,  | 
                    
| 401 | 
                        + handler: exporter.ExportVaultConfigDataFunction,  | 
                    |
| 378 | 402 | 
                        ) -> None:  | 
                    
| 379 | 403 | 
                        runner = click.testing.CliRunner(mix_stderr=False)  | 
                    
| 380 | 404 | 
                        # Use parenthesized context manager expressions once Python 3.9  | 
                    
| ... | ... | 
                      @@ -389,7 +413,7 @@ class TestStoreroom:  | 
                  
| 389 | 413 | 
                        )  | 
                    
| 390 | 414 | 
                        )  | 
                    
| 391 | 415 | 
                        stack.enter_context(pytest.raises(RuntimeError, match=error_text))  | 
                    
| 392 | 
                        - storeroom.export_storeroom_data()  | 
                    |
| 416 | 
                        + handler(format='storeroom')  | 
                    |
| 393 | 417 | 
                         | 
                    
| 394 | 418 | 
                        def test_404_decrypt_keys_wrong_data_length(self) -> None:  | 
                    
| 395 | 419 | 
                        payload = (  | 
                    
| ... | ... | 
                      @@ -506,12 +530,20 @@ class TestVaultNativeConfig:  | 
                  
| 506 | 530 | 
                        ),  | 
                    
| 507 | 531 | 
                        ],  | 
                    
| 508 | 532 | 
                        )  | 
                    
| 533 | 
                        + @pytest.mark.parametrize(  | 
                    |
| 534 | 
                        + 'handler',  | 
                    |
| 535 | 
                        + [  | 
                    |
| 536 | 
                        + pytest.param(vault_native.export_vault_native_data, id='handler'),  | 
                    |
| 537 | 
                        + pytest.param(exporter.export_vault_config_data, id='dispatcher'),  | 
                    |
| 538 | 
                        + ],  | 
                    |
| 539 | 
                        + )  | 
                    |
| 509 | 540 | 
                        def test_201_export_vault_native_data_no_arguments(  | 
                    
| 510 | 541 | 
                        self,  | 
                    
| 511 | 542 | 
                        monkeypatch: pytest.MonkeyPatch,  | 
                    
| 512 | 543 | 
                        config: str,  | 
                    
| 513 | 544 | 
                        format: Literal['v0.2', 'v0.3'],  | 
                    
| 514 | 545 | 
                        result: _types.VaultConfig | type[Exception],  | 
                    
| 546 | 
                        + handler: exporter.ExportVaultConfigDataFunction,  | 
                    |
| 515 | 547 | 
                        ) -> None:  | 
                    
| 516 | 548 | 
                        runner = click.testing.CliRunner(mix_stderr=False)  | 
                    
| 517 | 549 | 
                        with tests.isolated_vault_exporter_config(  | 
                    
| ... | ... | 
                      @@ -522,11 +554,9 @@ class TestVaultNativeConfig:  | 
                  
| 522 | 554 | 
                        ):  | 
                    
| 523 | 555 | 
                        if isinstance(result, type):  | 
                    
| 524 | 556 | 
                        with pytest.raises(result):  | 
                    
| 525 | 
                        - vault_native.export_vault_native_data(None, format=format)  | 
                    |
| 557 | 
                        + handler(None, format=format)  | 
                    |
| 526 | 558 | 
                        else:  | 
                    
| 527 | 
                        - parsed_config = vault_native.export_vault_native_data(  | 
                    |
| 528 | 
                        - None, format=format  | 
                    |
| 529 | 
                        - )  | 
                    |
| 559 | 
                        + parsed_config = handler(None, format=format)  | 
                    |
| 530 | 560 | 
                        assert parsed_config == result  | 
                    
| 531 | 561 | 
                         | 
                    
| 532 | 562 | 
                             @pytest.mark.parametrize('path', ['.vault', None])
                       | 
                    
| ... | ... | 
                      @@ -546,11 +576,19 @@ class TestVaultNativeConfig:  | 
                  
| 546 | 576 | 
                        ),  | 
                    
| 547 | 577 | 
                        ],  | 
                    
| 548 | 578 | 
                        )  | 
                    
| 579 | 
                        + @pytest.mark.parametrize(  | 
                    |
| 580 | 
                        + 'handler',  | 
                    |
| 581 | 
                        + [  | 
                    |
| 582 | 
                        + pytest.param(vault_native.export_vault_native_data, id='handler'),  | 
                    |
| 583 | 
                        + pytest.param(exporter.export_vault_config_data, id='dispatcher'),  | 
                    |
| 584 | 
                        + ],  | 
                    |
| 585 | 
                        + )  | 
                    |
| 549 | 586 | 
                        def test_202_export_data_path_and_keys_type(  | 
                    
| 550 | 587 | 
                        self,  | 
                    
| 551 | 588 | 
                        monkeypatch: pytest.MonkeyPatch,  | 
                    
| 552 | 589 | 
                        path: str | None,  | 
                    
| 553 | 590 | 
                        key: str | Buffer | None,  | 
                    
| 591 | 
                        + handler: exporter.ExportVaultConfigDataFunction,  | 
                    |
| 554 | 592 | 
                        ) -> None:  | 
                    
| 555 | 593 | 
                        runner = click.testing.CliRunner(mix_stderr=False)  | 
                    
| 556 | 594 | 
                        with tests.isolated_vault_exporter_config(  | 
                    
| ... | ... | 
                      @@ -559,8 +597,10 @@ class TestVaultNativeConfig:  | 
                  
| 559 | 597 | 
                        vault_config=tests.VAULT_V03_CONFIG,  | 
                    
| 560 | 598 | 
                        vault_key=tests.VAULT_MASTER_KEY,  | 
                    
| 561 | 599 | 
                        ):  | 
                    
| 562 | 
                        - parsed_config = vault_native.export_vault_native_data(None)  | 
                    |
| 563 | 
                        - assert parsed_config == tests.VAULT_V03_CONFIG_DATA  | 
                    |
| 600 | 
                        + assert (  | 
                    |
| 601 | 
                        + handler(path, key, format='v0.3')  | 
                    |
| 602 | 
                        + == tests.VAULT_V03_CONFIG_DATA  | 
                    |
| 603 | 
                        + )  | 
                    |
| 564 | 604 | 
                         | 
                    
| 565 | 605 | 
                        @pytest.mark.parametrize(  | 
                    
| 566 | 606 | 
                        ['parser_class', 'config', 'result'],  | 
                    
| 567 | 607 |