Skip to content

Commit

Permalink
Fix POST_Links incorrectly returning all links
Browse files Browse the repository at this point in the history
  • Loading branch information
mattjala committed Feb 9, 2024
1 parent c1184b7 commit 5a15989
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 2 deletions.
9 changes: 8 additions & 1 deletion hsds/link_sn.py
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,8 @@ async def POST_Links(request):
msg = f"Invalid group id: {group_id}"
log.warn(msg)

titles = items[group_id]
if (group_ids is not None) and isinstance(group_ids, dict):
titles = items[group_id]

if titles is None:
log.debug(f"getting all links for {group_id}")
Expand Down Expand Up @@ -698,6 +699,12 @@ async def POST_Links(request):
kwargs["limit"] = limit
if pattern:
kwargs["pattern"] = pattern

# If retrieving same link names from multiple groups, map each UUID to all links provided
if isinstance(group_ids, list) and titles:
for i in items:
items[i] = titles

crawler = DomainCrawler(app, items, **kwargs)
# will raise exception on NotFound, etc.
await crawler.crawl()
Expand Down
75 changes: 74 additions & 1 deletion tests/integ/link_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1229,7 +1229,7 @@ def testPostLinkSingle(self):

def testPostLinkMultiple(self):
domain = helper.getTestDomain("tall.h5")
print("testPostLinkSingle", domain)
print("testPostLinkMultiple", domain)
headers = helper.getRequestHeaders(domain=domain)
headers["Origin"] = "https://www.hdfgroup.org" # test CORS

Expand Down Expand Up @@ -1354,6 +1354,79 @@ def testPostLinkMultiple(self):
else:
self.assertTrue(False) # unexpected

def testPostLinksGroupList(self):
domain = self.base_domain + "/testPostLinksGroupList.h5"
helper.setupDomain(domain)
print("testPostLinksGroupList", domain)
headers = helper.getRequestHeaders(domain=domain)

req = helper.getEndpoint() + "/"
rsp = self.session.get(req, headers=headers)
self.assertEqual(rsp.status_code, 200)
rspJson = json.loads(rsp.text)
root_id = rspJson["root"]

# create group "g1" in root group
req = helper.getEndpoint() + "/groups"
body = {"link": {"id": root_id, "name": "g1"}}
rsp = self.session.post(req, data=json.dumps(body), headers=headers)
self.assertEqual(rsp.status_code, 201)
rspJson = json.loads(rsp.text)
group_id = rspJson["id"]

path = "/dummy_target"
# create link "link1" in root group
req = helper.getEndpoint() + "/groups/" + root_id + "/links/link1"
body = {"h5path": path}
rsp = self.session.put(req, data=json.dumps(body), headers=headers)
self.assertEqual(rsp.status_code, 201)

# create link "link1" in g1
req = helper.getEndpoint() + "/groups/" + group_id + "/links/link1"
body = {"h5path": path}
rsp = self.session.put(req, data=json.dumps(body), headers=headers)
self.assertEqual(rsp.status_code, 201)

# create link "link2" in root group
req = helper.getEndpoint() + "/groups/" + root_id + "/links/link2"
body = {"h5path": path}
rsp = self.session.put(req, data=json.dumps(body), headers=headers)
self.assertEqual(rsp.status_code, 201)

# make POST_Links request to retrieve only /link1 and /g1/link1
req = helper.getEndpoint() + "/groups/" + root_id + "/links"
group_ids = [root_id, group_id]
titles = ["link1"]
body = {"group_ids": group_ids, "titles": titles}
rsp = self.session.post(req, data=json.dumps(body), headers=headers)
self.assertEqual(rsp.status_code, 200)
rspJson = json.loads(rsp.text)

# verify that only the two "link1"s are returned
self.assertTrue("links" in rspJson)
links = rspJson["links"]
self.assertEqual(len(links), 2)

self.assertTrue(root_id in links)
root_links = links[root_id]
self.assertEqual(len(root_links), 1)
self.assertTrue("h5path" in root_links[0])
root_link = root_links[0]
self.assertTrue("h5path" in root_link)
self.assertEqual(root_link["h5path"], path)
self.assertTrue("title" in root_link)
self.assertEqual(root_link["title"], "link1")

self.assertTrue(group_id in links)
group_links = links[group_id]
self.assertEqual(len(group_links), 1)
self.assertTrue("h5path" in group_links[0])
group_link = group_links[0]
self.assertTrue("h5path" in group_link)
self.assertEqual(group_link["h5path"], path)
self.assertTrue("title" in group_link)
self.assertEqual(group_link["title"], "link1")

def testPutLinkMultiple(self):
domain = self.base_domain + "/testPutLinkMultiple.h5"
helper.setupDomain(domain)
Expand Down

0 comments on commit 5a15989

Please sign in to comment.