summary refs log tree commit diff stats
path: root/testing
diff options
context:
space:
mode:
authorSoniEx2 <endermoneymod@gmail.com>2024-02-07 20:59:05 -0300
committerSoniEx2 <endermoneymod@gmail.com>2024-02-07 20:59:05 -0300
commit2a344c63c4145c2c96ac2096dcf02d64694a3dc8 (patch)
tree37eac63acfa50e233ea623cd7bfc26a9df4bd3de /testing
parent2f5654e49e2aae96b2a1bc0f5b6a1b784a00ff01 (diff)
Handle untrusted input more better
Diffstat (limited to 'testing')
-rw-r--r--testing/test_data.py51
1 files changed, 51 insertions, 0 deletions
diff --git a/testing/test_data.py b/testing/test_data.py
new file mode 100644
index 0000000..47f4e66
--- /dev/null
+++ b/testing/test_data.py
@@ -0,0 +1,51 @@
+from ganarchy.data import DataProperty, ObjectDataSource, PCTP
+
+def test_basic_project():
+    ods = ObjectDataSource({
+        'projects': {
+            '0123456789012345678901234567890123456789': {
+                'https://example/': {
+                    None: {'active': True}
+                }
+            }
+         }
+    })
+    values = list(ods.get_property_values(DataProperty.VCS_REPOS))
+    assert len(values) == 1
+    assert isinstance(values[0], PCTP)
+    assert values[0].project_commit == '0123456789'*4
+    assert values[0].uri == 'https://example/'
+    assert values[0].branch == None
+    assert values[0].active
+    assert values[0].federate # defaults to True
+    assert not values[0].pinned # defaults to False
+
+def test_nul_in_project_uri():
+    # tests what happens if repo uri is malicious/bogus
+    # should just ignore bad uri
+    ods = ObjectDataSource({
+        'projects': {
+            '0123456789012345678901234567890123456789': {
+                'https://example/\0': {
+                    None: {'active': True}
+                }
+            }
+         }
+    })
+    values = list(ods.get_property_values(DataProperty.VCS_REPOS))
+    assert not len(values)
+
+def test_bad_branch():
+    # tests what happens if repo branch is malicious/bogus
+    # should just ignore bad branch
+    ods = ObjectDataSource({
+        'projects': {
+            '0123456789012345678901234567890123456789': {
+                'https://example/': {
+                    '\0': {'active': True}
+                }
+            }
+         }
+    })
+    values = list(ods.get_property_values(DataProperty.VCS_REPOS))
+    assert not len(values)