From 32f39685a126674822720080fecc7c1ca346a5a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A2u=20Cao?= Date: Wed, 23 Oct 2024 22:38:30 +0200 Subject: [PATCH] Fix search timing out on non-existing nostrKey fixes #1 --- ldap.ts | 11 +++++++++-- tests/feeds_test.ts | 2 +- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/ldap.ts b/ldap.ts index 07867b9..d021572 100644 --- a/ldap.ts +++ b/ldap.ts @@ -19,7 +19,12 @@ export async function lookupPubkeyByUsername(username: string) { attributes: ["nostrKey"], }); - pubkey = searchEntries[0]?.nostrKey as string; + if ( + searchEntries.length > 0 && + typeof searchEntries[0].nostrKey === "string" + ) { + pubkey = searchEntries[0].nostrKey; + } } catch (e) { console.error(e); } finally { @@ -40,7 +45,9 @@ export async function lookupUsernameByPubkey(pubkey: string) { attributes: ["cn"], }); - username = searchEntries[0]?.cn; + if (searchEntries.length > 0) { + username = searchEntries[0].cn; + } } catch (e) { console.error(e); } finally { diff --git a/tests/feeds_test.ts b/tests/feeds_test.ts index b629d92..2e21231 100644 --- a/tests/feeds_test.ts +++ b/tests/feeds_test.ts @@ -4,7 +4,7 @@ import { cleanContentHtml } from "../feeds.ts"; describe("Feeds", () => { describe("#cleanContentHtml", () => { - let articleHtml = Deno.readTextFileSync( + const articleHtml = Deno.readTextFileSync( "tests/fixtures/gfm-content-1.html", );