Skip to content

Commit

Permalink
Merge pull request #243 from nulib/deploy/staging
Browse files Browse the repository at this point in the history
Deploy to production
  • Loading branch information
kdid committed Aug 13, 2024
2 parents cccfa98 + bf1cfd0 commit 217d843
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 12 deletions.
3 changes: 1 addition & 2 deletions chat/src/helpers/hybrid_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
31 changes: 23 additions & 8 deletions node/src/handlers/get-auth-callback.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
}
1 change: 0 additions & 1 deletion node/src/handlers/post-chat-feedback.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ const sendNotification = async (snsClient, subject, message) => {
Message: message,
});
const response = await snsClient.send(command);
console.log(response);
return response;
};

Expand Down
34 changes: 33 additions & 1 deletion node/test/integration/get-auth-callback.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
});

Expand Down

0 comments on commit 217d843

Please sign in to comment.