-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_validation_errors.py
More file actions
169 lines (148 loc) · 5.24 KB
/
test_validation_errors.py
File metadata and controls
169 lines (148 loc) · 5.24 KB
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
#!/usr/bin/env python3
"""
Test script to demonstrate validation error scenarios.
This script creates sample data with intentional issues to show
how the validation script reports problems.
"""
import json
import tempfile
import os
from pathlib import Path
from validate_bitwarden_export import BitwardenValidator
def create_problematic_data():
"""Create sample data with intentional validation issues."""
# Sample input data (original export)
input_data = {
"encrypted": False,
"folders": [],
"items": [
{
"id": "1",
"name": "GitHub",
"type": 1,
"login": {
"username": "user1",
"password": "pass123",
"uris": [{"uri": "https://github.com"}]
},
"notes": "GitHub account",
"creationDate": "2024-01-01T00:00:00.000Z",
"revisionDate": "2024-01-01T00:00:00.000Z"
},
{
"id": "2",
"name": "Gmail",
"type": 1,
"login": {
"username": "user2@gmail.com",
"password": "pass456",
"uris": [{"uri": "https://gmail.com"}]
},
"notes": "Personal email",
"creationDate": "2024-01-01T00:00:00.000Z",
"revisionDate": "2024-01-01T00:00:00.000Z"
},
{
"id": "3",
"name": "Bank Account",
"type": 1,
"login": {
"username": "user3",
"password": "pass789",
"uris": [{"uri": "https://mybank.com"}]
},
"notes": "Online banking",
"creationDate": "2024-01-01T00:00:00.000Z",
"revisionDate": "2024-01-01T00:00:00.000Z"
}
]
}
# Sample output data with PROBLEMS (missing item, modified data, lost notes)
output_data = {
"encrypted": False,
"folders": [
{
"id": "folder1",
"name": "Developer",
"revisionDate": "2024-01-01T00:00:00.000Z"
},
{
"id": "folder2",
"name": "Email",
"revisionDate": "2024-01-01T00:00:00.000Z"
}
],
"items": [
{
"id": "1",
"name": "GitHub - Development Platform",
"type": 1,
"folderId": "folder1",
"login": {
"username": "user1",
"password": "pass123",
"uris": [{"uri": "https://github.com"}]
},
"notes": "GitHub account\n\nCategory: Developer\nTags: dev, code\nProcessed: 2024-01-01T00:00:00",
"tags": ["dev", "code"],
"creationDate": "2024-01-01T00:00:00.000Z",
"revisionDate": "2024-01-01T00:00:00.000Z"
},
{
"id": "2",
"name": "Gmail - Personal Email",
"type": 1,
"folderId": "folder2",
"login": {
"username": "user2@gmail.com",
"password": "pass456",
"uris": [{"uri": "https://gmail.com"}]
},
# NOTE: Notes were lost here!
"tags": ["email", "personal"],
"creationDate": "2024-01-01T00:00:00.000Z",
"revisionDate": "2024-01-01T00:00:00.000Z"
}
# NOTE: Bank Account item is missing!
]
}
return input_data, output_data
def test_validation_errors():
"""Test the validation functionality with problematic data."""
print("🧪 Testing Bitwarden validation script with ERROR scenarios...")
print()
# Create problematic data
input_data, output_data = create_problematic_data()
# Create temporary files
with tempfile.NamedTemporaryFile(mode='w', suffix='.json', delete=False) as f:
json.dump(input_data, f, indent=2)
input_file = f.name
with tempfile.NamedTemporaryFile(mode='w', suffix='.json', delete=False) as f:
json.dump(output_data, f, indent=2)
output_file = f.name
try:
print(f"📁 Created temporary files:")
print(f" Input: {input_file}")
print(f" Output: {output_file}")
print()
print("⚠️ This test data has INTENTIONAL problems:")
print(" - Missing 1 item (Bank Account)")
print(" - Lost notes for Gmail item")
print(" - Item count mismatch (3 → 2)")
print()
# Run validation
validator = BitwardenValidator(input_file, output_file, verbose=True)
success = validator.run_validation()
print()
print(f"🎯 Validation result: {'✅ PASSED' if success else '❌ FAILED'}")
return success
finally:
# Clean up temporary files
try:
os.unlink(input_file)
os.unlink(output_file)
print(f"\n🧹 Cleaned up temporary files")
except:
pass
if __name__ == "__main__":
test_validation_errors()