Skip to content

Commit ed87839

Browse files
committed
Extract 'temp_credentials_file' fixture
1 parent b66294e commit ed87839

File tree

5 files changed

+63
-113
lines changed

5 files changed

+63
-113
lines changed

tests/integration/conftest.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
"""
2+
Shared fixtures and utilities for integration tests.
3+
"""
4+
5+
import json
6+
import tempfile
7+
from pathlib import Path
8+
9+
import pytest
10+
11+
12+
@pytest.fixture(scope="session")
13+
def temp_credentials_file():
14+
"""Create a temporary credentials file for testing."""
15+
with tempfile.TemporaryDirectory() as temp_dir:
16+
creds_file = Path(temp_dir) / "creds.json"
17+
creds_data = {"clientId": "opentdf", "clientSecret": "secret"}
18+
with open(creds_file, "w") as f:
19+
json.dump(creds_data, f)
20+
yield creds_file

tests/integration/test_cli_comparison.py

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import pytest
66
import subprocess
77
import tempfile
8-
import json
98
from pathlib import Path
109
from tests.config_pydantic import CONFIG_TDF
1110

@@ -16,19 +15,13 @@
1615

1716

1817
@pytest.mark.integration
19-
def test_otdfctl_encrypt_python_decrypt(collect_server_logs):
18+
def test_otdfctl_encrypt_python_decrypt(collect_server_logs, temp_credentials_file):
2019
"""Integration test that uses otdfctl for encryption and the Python CLI for decryption"""
2120

2221
# Create temporary directory for work
2322
with tempfile.TemporaryDirectory() as temp_dir:
2423
temp_path = Path(temp_dir)
2524

26-
# Create credentials file
27-
creds_file = temp_path / "creds.json"
28-
creds_data = {"clientId": "opentdf", "clientSecret": "secret"}
29-
with open(creds_file, "w") as f:
30-
json.dump(creds_data, f)
31-
3225
# Create input file
3326
input_file = temp_path / "input.txt"
3427
input_content = "Hello, World! This is a test for otdfctl decrypt comparison."
@@ -49,7 +42,7 @@ def test_otdfctl_encrypt_python_decrypt(collect_server_logs):
4942
"--host",
5043
platform_url,
5144
"--with-client-creds-file",
52-
str(creds_file),
45+
str(temp_credentials_file),
5346
"--tls-no-verify",
5447
"--mime-type",
5548
"text/plain",
@@ -77,7 +70,7 @@ def test_otdfctl_encrypt_python_decrypt(collect_server_logs):
7770
"--host",
7871
platform_url,
7972
"--with-client-creds-file",
80-
str(creds_file),
73+
str(temp_credentials_file),
8174
"--tls-no-verify",
8275
str(otdfctl_tdf_output),
8376
"-o",
@@ -118,7 +111,7 @@ def test_otdfctl_encrypt_python_decrypt(collect_server_logs):
118111
"--platform-url",
119112
platform_url,
120113
"--with-client-creds-file",
121-
str(creds_file),
114+
str(temp_credentials_file),
122115
"--insecure", # equivalent to --tls-no-verify
123116
"decrypt",
124117
str(otdfctl_tdf_output),
@@ -191,19 +184,13 @@ def test_otdfctl_encrypt_python_decrypt(collect_server_logs):
191184

192185

193186
@pytest.mark.integration
194-
def test_otdfctl_encrypt_otdfctl_decrypt(collect_server_logs):
187+
def test_otdfctl_encrypt_otdfctl_decrypt(collect_server_logs, temp_credentials_file):
195188
"""Integration test that uses otdfctl for both encryption and decryption to verify roundtrip functionality"""
196189

197190
# Create temporary directory for work
198191
with tempfile.TemporaryDirectory() as temp_dir:
199192
temp_path = Path(temp_dir)
200193

201-
# Create credentials file
202-
creds_file = temp_path / "creds.json"
203-
creds_data = {"clientId": "opentdf", "clientSecret": "secret"}
204-
with open(creds_file, "w") as f:
205-
json.dump(creds_data, f)
206-
207194
# Create input file
208195
input_file = temp_path / "input.txt"
209196
input_content = (
@@ -223,7 +210,7 @@ def test_otdfctl_encrypt_otdfctl_decrypt(collect_server_logs):
223210
"--host",
224211
platform_url,
225212
"--with-client-creds-file",
226-
str(creds_file),
213+
str(temp_credentials_file),
227214
"--tls-no-verify",
228215
"--mime-type",
229216
"text/plain",
@@ -272,7 +259,7 @@ def test_otdfctl_encrypt_otdfctl_decrypt(collect_server_logs):
272259
"--host",
273260
platform_url,
274261
"--with-client-creds-file",
275-
str(creds_file),
262+
str(temp_credentials_file),
276263
"--tls-no-verify",
277264
str(otdfctl_tdf_output),
278265
"-o",

tests/integration/test_cli_encrypt_only.py

Lines changed: 17 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,6 @@
3333
otdfctl_flags = ["--tls-no-verify"]
3434

3535

36-
def _create_test_credentials(temp_path: Path) -> Path:
37-
"""Create a test credentials file in the given temporary directory."""
38-
creds_file = temp_path / "test-creds.json"
39-
creds_data = {"clientId": "opentdf", "clientSecret": "secret"}
40-
with open(creds_file, "w") as f:
41-
json.dump(creds_data, f)
42-
return creds_file
43-
44-
4536
def _create_test_input_file(temp_path: Path, content: str) -> Path:
4637
"""Create a test input file with the given content."""
4738
input_file = temp_path / "input.txt"
@@ -381,15 +372,14 @@ def _run_python_cli_decrypt(
381372

382373

383374
@pytest.mark.integration
384-
def test_otdfctl_encrypt_with_validation(collect_server_logs):
375+
def test_otdfctl_encrypt_with_validation(collect_server_logs, temp_credentials_file):
385376
"""Integration test that uses otdfctl for encryption and validates the TDF thoroughly."""
386377

387378
# Create temporary directory for work
388379
with tempfile.TemporaryDirectory() as temp_dir:
389380
temp_path = Path(temp_dir)
390381

391382
# Create test files
392-
creds_file = _create_test_credentials(temp_path)
393383
input_content = "Hello, World! This is test content for otdfctl encryption."
394384
input_file = _create_test_input_file(temp_path, input_content)
395385

@@ -403,7 +393,7 @@ def test_otdfctl_encrypt_with_validation(collect_server_logs):
403393
"--host",
404394
platform_url,
405395
"--with-client-creds-file",
406-
str(creds_file),
396+
str(temp_credentials_file),
407397
*otdfctl_flags,
408398
"--mime-type",
409399
"text/plain",
@@ -433,7 +423,7 @@ def test_otdfctl_encrypt_with_validation(collect_server_logs):
433423
_run_otdfctl_decrypt(
434424
otdfctl_tdf_output,
435425
platform_url,
436-
creds_file,
426+
temp_credentials_file,
437427
temp_path,
438428
collect_server_logs,
439429
input_content,
@@ -444,15 +434,14 @@ def test_otdfctl_encrypt_with_validation(collect_server_logs):
444434

445435

446436
@pytest.mark.integration
447-
def test_python_encrypt(collect_server_logs):
437+
def test_python_encrypt(collect_server_logs, temp_credentials_file):
448438
"""Integration test that uses Python CLI for encryption only and verifies the TDF can be inspected"""
449439

450440
# Create temporary directory for work
451441
with tempfile.TemporaryDirectory() as temp_dir:
452442
temp_path = Path(temp_dir)
453443

454444
# Create test files
455-
creds_file = _create_test_credentials(temp_path)
456445
input_content = "Hello, World! This is test content for Python CLI encryption."
457446
input_file = _create_test_input_file(temp_path, input_content)
458447

@@ -469,7 +458,7 @@ def test_python_encrypt(collect_server_logs):
469458
"--platform-url",
470459
platform_url,
471460
"--with-client-creds-file",
472-
str(creds_file),
461+
str(temp_credentials_file),
473462
*cli_flags,
474463
"encrypt",
475464
"--mime-type",
@@ -500,7 +489,7 @@ def test_python_encrypt(collect_server_logs):
500489
_run_otdfctl_decrypt(
501490
python_tdf_output,
502491
platform_url,
503-
creds_file,
492+
temp_credentials_file,
504493
temp_path,
505494
collect_server_logs,
506495
input_content,
@@ -513,15 +502,14 @@ def test_python_encrypt(collect_server_logs):
513502

514503

515504
@pytest.mark.integration
516-
def test_cross_tool_compatibility(collect_server_logs):
505+
def test_cross_tool_compatibility(collect_server_logs, temp_credentials_file):
517506
"""Test that TDFs created by one tool can be decrypted by the other."""
518507

519508
# Create temporary directory for work
520509
with tempfile.TemporaryDirectory() as temp_dir:
521510
temp_path = Path(temp_dir)
522511

523512
# Create test files
524-
creds_file = _create_test_credentials(temp_path)
525513
input_content = "Cross-tool compatibility test content. Testing 123!"
526514
input_file = _create_test_input_file(temp_path, input_content)
527515

@@ -535,7 +523,7 @@ def test_cross_tool_compatibility(collect_server_logs):
535523
"--host",
536524
platform_url,
537525
"--with-client-creds-file",
538-
str(creds_file),
526+
str(temp_credentials_file),
539527
*otdfctl_flags,
540528
"--mime-type",
541529
"text/plain",
@@ -562,7 +550,7 @@ def test_cross_tool_compatibility(collect_server_logs):
562550
_run_python_cli_decrypt(
563551
otdfctl_tdf_output,
564552
platform_url,
565-
creds_file,
553+
temp_credentials_file,
566554
temp_path,
567555
collect_server_logs,
568556
input_content,
@@ -581,7 +569,7 @@ def test_cross_tool_compatibility(collect_server_logs):
581569
"--platform-url",
582570
platform_url,
583571
"--with-client-creds-file",
584-
str(creds_file),
572+
str(temp_credentials_file),
585573
*cli_flags,
586574
"encrypt",
587575
"--mime-type",
@@ -609,7 +597,7 @@ def test_cross_tool_compatibility(collect_server_logs):
609597
_run_otdfctl_decrypt(
610598
python_tdf_output,
611599
platform_url,
612-
creds_file,
600+
temp_credentials_file,
613601
temp_path,
614602
collect_server_logs,
615603
input_content,
@@ -621,7 +609,7 @@ def test_cross_tool_compatibility(collect_server_logs):
621609

622610

623611
@pytest.mark.integration
624-
def test_different_content_types(collect_server_logs):
612+
def test_different_content_types(collect_server_logs, temp_credentials_file):
625613
"""Test encryption/decryption with different types of content."""
626614

627615
test_cases = [
@@ -634,7 +622,6 @@ def test_different_content_types(collect_server_logs):
634622
# Create temporary directory for work
635623
with tempfile.TemporaryDirectory() as temp_dir:
636624
temp_path = Path(temp_dir)
637-
creds_file = _create_test_credentials(temp_path)
638625

639626
for filename, content in test_cases:
640627
print(f"\n--- Testing {filename} (content length: {len(content)}) ---")
@@ -657,7 +644,7 @@ def test_different_content_types(collect_server_logs):
657644
"--platform-url",
658645
platform_url,
659646
"--with-client-creds-file",
660-
str(creds_file),
647+
str(temp_credentials_file),
661648
*cli_flags,
662649
"encrypt",
663650
"--mime-type",
@@ -688,7 +675,7 @@ def test_different_content_types(collect_server_logs):
688675
_run_otdfctl_decrypt(
689676
python_tdf_output,
690677
platform_url,
691-
creds_file,
678+
temp_credentials_file,
692679
temp_path,
693680
collect_server_logs,
694681
content,
@@ -701,7 +688,7 @@ def test_different_content_types(collect_server_logs):
701688

702689
@pytest.mark.skip("Skipping test for now due to known issues with empty content")
703690
@pytest.mark.integration
704-
def test_different_content_types_empty(collect_server_logs):
691+
def test_different_content_types_empty(collect_server_logs, temp_credentials_file):
705692
"""Test encryption/decryption with different types of content."""
706693

707694
test_cases = [
@@ -711,7 +698,6 @@ def test_different_content_types_empty(collect_server_logs):
711698
# Create temporary directory for work
712699
with tempfile.TemporaryDirectory() as temp_dir:
713700
temp_path = Path(temp_dir)
714-
creds_file = _create_test_credentials(temp_path)
715701

716702
for filename, content in test_cases:
717703
print(f"\n--- Testing {filename} (content length: {len(content)}) ---")
@@ -734,7 +720,7 @@ def test_different_content_types_empty(collect_server_logs):
734720
"--platform-url",
735721
platform_url,
736722
"--with-client-creds-file",
737-
str(creds_file),
723+
str(temp_credentials_file),
738724
*cli_flags,
739725
"encrypt",
740726
"--mime-type",
@@ -765,7 +751,7 @@ def test_different_content_types_empty(collect_server_logs):
765751
_run_otdfctl_decrypt(
766752
python_tdf_output,
767753
platform_url,
768-
creds_file,
754+
temp_credentials_file,
769755
temp_path,
770756
collect_server_logs,
771757
content,

0 commit comments

Comments
 (0)