From df5770f083e1f9e8779c6f383956141187d726aa Mon Sep 17 00:00:00 2001 From: Karen Shaw Date: Mon, 12 Aug 2024 18:16:08 +0000 Subject: [PATCH 1/2] Remove english analyzer from hybrid query --- chat/src/helpers/hybrid_query.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/chat/src/helpers/hybrid_query.py b/chat/src/helpers/hybrid_query.py index d0cb8287..5a7119d3 100644 --- a/chat/src/helpers/hybrid_query.py +++ b/chat/src/helpers/hybrid_query.py @@ -21,8 +21,7 @@ def hybrid_query(query: str, model_id: str, vector_field: str = "embedding", k: "query_string": { "default_operator": "AND", "fields": ["title^5", "all_controlled_labels", "all_ids^5"], - "query": query, - "analyzer": "english" + "query": query } }), filter({ From 85aea16ef1e602f6bd0c6ce4f61b8a00809901b4 Mon Sep 17 00:00:00 2001 From: "Michael B. Klein" Date: Mon, 12 Aug 2024 19:31:13 +0000 Subject: [PATCH 2/2] Use netid-derived name & email if directory response succeeds but is empty --- node/src/handlers/get-auth-callback.js | 31 ++++++++++++----- node/src/handlers/post-chat-feedback.js | 1 - .../integration/get-auth-callback.test.js | 34 ++++++++++++++++++- 3 files changed, 56 insertions(+), 10 deletions(-) diff --git a/node/src/handlers/get-auth-callback.js b/node/src/handlers/get-auth-callback.js index 6efb6081..87370f21 100644 --- a/node/src/handlers/get-auth-callback.js +++ b/node/src/handlers/get-auth-callback.js @@ -61,12 +61,12 @@ async function redeemSsoToken(event) { }, } ); - return { ...response.data.results[0], uid: netid }; + return fillInBlanks({ ...response.data.results[0], uid: netid }); } catch (err) { if ( BAD_DIRECTORY_SEARCH_FAULT.test(err?.response?.data?.fault?.faultstring) ) { - return redeemForNetIdOnly(netid); + return fillInBlanks({ uid: netid }); } await Honeybadger.notifyAsync(err, { tags: ["auth", "upstream"] }); console.error(err.response.data); @@ -78,10 +78,25 @@ async function redeemSsoToken(event) { } } -function redeemForNetIdOnly(netid) { - return { - uid: netid, - displayName: [netid], - mail: `${netid}@e.northwestern.edu`, - }; +function fillInBlanks(response) { + const { uid } = response; + response.displayName = ifEmpty(response.displayName, [uid]); + response.mail = ifEmpty(response.mail, `${uid}@e.northwestern.edu`); + return response; +} + +function ifEmpty(val, replacement) { + return isEmpty(val) ? replacement : val; +} + +function isEmpty(val) { + if (val === null || val === undefined) { + return true; + } + + if (Array.isArray(val)) { + return val.every(isEmpty); + } + + return val.length == 0; } diff --git a/node/src/handlers/post-chat-feedback.js b/node/src/handlers/post-chat-feedback.js index 45ee1b87..4ab8a6c4 100644 --- a/node/src/handlers/post-chat-feedback.js +++ b/node/src/handlers/post-chat-feedback.js @@ -118,7 +118,6 @@ const sendNotification = async (snsClient, subject, message) => { Message: message, }); const response = await snsClient.send(command); - console.log(response); return response; }; diff --git a/node/test/integration/get-auth-callback.test.js b/node/test/integration/get-auth-callback.test.js index c4268ed0..92639114 100644 --- a/node/test/integration/get-auth-callback.test.js +++ b/node/test/integration/get-auth-callback.test.js @@ -28,7 +28,9 @@ describe("auth callback", function () { nock(process.env.NUSSO_BASE_URL) .get("/validate-with-directory-search-response") .reply(200, { - results: [{ uid: "uid123", displayName: ["Some User"] }], + results: [ + { displayName: ["Some User"], mail: "some.user@example.com" }, + ], }); const result = await getAuthCallbackHandler.handler(event); @@ -45,6 +47,36 @@ describe("auth callback", function () { expect(apiToken.token.sub).to.eq("uid123"); expect(apiToken.token.name).to.eq("Some User"); + expect(apiToken.token.email).to.eq("some.user@example.com"); + expect(apiToken.isLoggedIn()).to.be.true; + }); + + it("fills in the blanks if the directory search result is incomplete", async () => { + nock(process.env.NUSSO_BASE_URL) + .get("/validate-with-directory-search-response") + .reply(200, { + results: [{ displayName: [], mail: "" }], + }); + + const result = await getAuthCallbackHandler.handler(event); + + expect(result.statusCode).to.eq(302); + expect(result.headers.location).to.eq("https://example.com"); + + expect(result.cookies).to.include( + "redirectUrl=null; Expires=Thu, 01 Jan 1970 00:00:00 GMT" + ); + + const dcApiCookie = helpers.cookieValue( + result.cookies, + process.env.API_TOKEN_NAME + ); + + const apiToken = new ApiToken(dcApiCookie.value); + + expect(apiToken.token.sub).to.eq("uid123"); + expect(apiToken.token.name).to.eq("uid123"); + expect(apiToken.token.email).to.eq("uid123@e.northwestern.edu"); expect(apiToken.isLoggedIn()).to.be.true; });