fix search by channel for invalid channel

This commit is contained in:
Victor Shyba 2021-03-11 04:04:26 -03:00
parent 21e023f0db
commit c3e426c491
2 changed files with 4 additions and 4 deletions

View file

@ -236,11 +236,10 @@ class SearchIndex:
async def search(self, **kwargs): async def search(self, **kwargs):
if 'channel' in kwargs: if 'channel' in kwargs:
results, _, _ = await self.resolve(kwargs.pop('channel')) channel_id = await self.resolve_url(kwargs.pop('channel'))
if not results or not isinstance(results, Iterable): if not channel_id or not isinstance(channel_id, str):
return [], 0, 0 return [], 0, 0
result = results[0] if results else None kwargs['channel_id'] = channel_id
kwargs['channel_id'] = result['claim_id']
try: try:
result = await self.search_client.search( result = await self.search_client.search(
expand_query(**kwargs), index=self.index, track_total_hits=200 expand_query(**kwargs), index=self.index, track_total_hits=200

View file

@ -150,6 +150,7 @@ class ClaimSearchCommand(ClaimTestCase):
claims = [three, two, signed] claims = [three, two, signed]
await self.assertFindsClaims(claims, channel_ids=[self.channel_id]) await self.assertFindsClaims(claims, channel_ids=[self.channel_id])
await self.assertFindsClaims(claims, channel=f"@abc#{self.channel_id}") await self.assertFindsClaims(claims, channel=f"@abc#{self.channel_id}")
await self.assertFindsClaims([], channel=f"@inexistent")
await self.assertFindsClaims([three, two, signed2, signed], channel_ids=[channel_id2, self.channel_id]) await self.assertFindsClaims([three, two, signed2, signed], channel_ids=[channel_id2, self.channel_id])
await self.channel_abandon(claim_id=self.channel_id) await self.channel_abandon(claim_id=self.channel_id)
await self.assertFindsClaims([], channel=f"@abc#{self.channel_id}", valid_channel_signature=True) await self.assertFindsClaims([], channel=f"@abc#{self.channel_id}", valid_channel_signature=True)