decomposer: generate files for Build source connectors that retrieve content and source permissions from SCM and CMS systems and expose normalized content-change records to downstream ingestion workflows.
This commit is contained in:
29
tests/test_connectors.py
Normal file
29
tests/test_connectors.py
Normal file
@@ -0,0 +1,29 @@
|
||||
from source_connectors import GitHubConnector, SharePointConnector, StaticTokenProvider, Cursor
|
||||
|
||||
class FakeHTTP:
|
||||
def __init__(self, responses): self.responses, self.urls = responses, []
|
||||
def get(self, url, headers):
|
||||
self.urls.append((url, headers)); return self.responses[url]
|
||||
|
||||
def test_github_enumeration_is_scoped_and_authenticated():
|
||||
url = "https://api.github.com/repos/acme/docs/git/trees/main?recursive=1"
|
||||
http = FakeHTTP({url: {"tree": [{"type": "blob", "path": "a.md", "sha": "s", "url": "u"}]}})
|
||||
rows = list(GitHubConnector(StaticTokenProvider("t"), http).enumerate({"owner":"acme","repo":"docs","ref":"main"}))
|
||||
assert rows[0].path == "a.md" and http.urls[0][1]["Authorization"] == "Bearer t"
|
||||
|
||||
def test_github_webhook_normalizes_delete():
|
||||
event = GitHubConnector(StaticTokenProvider("t"), FakeHTTP({})).normalize_webhook({"X-GitHub-Delivery":"d","X-GitHub-Event":"push"}, {"ref":"refs/heads/main","after":"sha","repository":{"owner":{"login":"a"},"name":"r"}})
|
||||
assert event.event_id == "d" and event.cursor_hint.value == "sha"
|
||||
|
||||
def test_sharepoint_delta_and_acl():
|
||||
delta = "https://graph.microsoft.com/v1.0/sites/s/drives/d/root/delta"
|
||||
acl = "https://graph.microsoft.com/v1.0/sites/s/drives/d/root/permissions"
|
||||
http = FakeHTTP({delta: {"value":[{"id":"1","name":"x","file":{},"webUrl":"w"}], "@odata.deltaLink":"next"}, acl:{"value":[{"id":"p","roles":["read"],"grantedToV2":{"user":{"id":"u"}}}]}})
|
||||
c = SharePointConnector(StaticTokenProvider("t"), http)
|
||||
assert list(c.enumerate({"site_id":"s","drive_id":"d"}))[0].id == "1"
|
||||
assert list(c.acl({"site_id":"s","drive_id":"d"}))[0].subject_id == "u"
|
||||
|
||||
def test_scope_rejects_path_injection():
|
||||
try: list(GitHubConnector(StaticTokenProvider("t"), FakeHTTP({})).enumerate({"owner":"a/b","repo":"r"}))
|
||||
except ValueError: pass
|
||||
else: raise AssertionError("unsafe scope accepted")
|
||||
Reference in New Issue
Block a user