Skip to content

Commit

Permalink
Merge pull request #53 from bu-ist/improvements
Browse files Browse the repository at this point in the history
Improvements
  • Loading branch information
jdub233 authored Feb 7, 2024
2 parents 70cdb13 + 175ee2c commit 8c1580c
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 15 deletions.
6 changes: 2 additions & 4 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
{
"env": {
"node": true,
"commonjs": true,
"es2021": true,
"jest": true
"node": true
},
"extends": ["airbnb-base"],
"overrides": [
Expand All @@ -14,5 +11,6 @@
"rules": {
"import/prefer-default-export": "off",
"import/extensions": ["error", "ignorePackages"],
"import/no-extraneous-dependencies": ["error", {"packageDir": ["./", "./src"]}]
}
}
2 changes: 1 addition & 1 deletion src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,4 @@ export async function handler(event) {

// Exit the Lambda function.
return { statusCode: 200 };
};
}
2 changes: 1 addition & 1 deletion src/app.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { DynamoDBDocumentClient, GetCommand } from '@aws-sdk/lib-dynamodb';
import { GetParameterCommand, SSMClient } from '@aws-sdk/client-ssm';

// Import the function to test.
import { handler } from './app';
import { handler } from './app.js';

const ddbMock = mockClient(DynamoDBDocumentClient);
const ssmMock = mockClient(SSMClient);
Expand Down
17 changes: 13 additions & 4 deletions src/authorizeRequest/authorizeRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,22 @@ async function authorizeRequest(userRequest, siteRule, networkRanges) {
// Get the rules for the group.
// Need to skip this for the entire-bu-community group, since it is not in the database.
// to avoid INFO Failed to find the group in DynamoDB for group: entire-bu-community
const { Item } = await dynamoDb.get({
TableName: tableName,
Key: { PK: siteAndGroupKey },
});
let response;
try {
response = await dynamoDb.get({
TableName: tableName,
Key: { PK: siteAndGroupKey },
});
} catch (error) {
// eslint-disable-next-line no-console
console.error(error);
}

const { Item } = response;

if (Item == null) {
// If the group rules are not found, log the error then deny access.
// eslint-disable-next-line no-console
console.log('Failed to find the group in DynamoDB for group: ', groupName);
return false;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, it, expect } from 'vitest';
import { checkNetworkAccess } from './checkNetworkAccess';
import { checkNetworkAccess } from './checkNetworkAccess.js';

const testRanges = {
campus1: [
Expand Down
4 changes: 3 additions & 1 deletion src/authorizeRequest/checkUserAccess.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ function checkUserAccess(rules, headers) {
const userName = eppn.split('@')[0];

// Unpack the rules, with defaults.
const { users = [], states: affiliations = [], entitlements = [], admins = [] } = rules;
const {
users = [], states: affiliations = [], entitlements = [], admins = [],
} = rules;

// Merge the users and admins arrays.
const allowedUsers = [...users, ...admins];
Expand Down
2 changes: 1 addition & 1 deletion src/authorizeRequest/checkUserAccess.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, it, expect } from 'vitest';
import { checkUserAccess } from './checkUserAccess';
import { checkUserAccess } from './checkUserAccess.js';

// Setup an example rules object.
const exampleUserRules = {
Expand Down
13 changes: 12 additions & 1 deletion src/getOrCreateObject/getOrCreateObject.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { GetObjectCommand, S3Client } from '@aws-sdk/client-s3';
import { DynamoDBDocumentClient, GetCommand } from '@aws-sdk/lib-dynamodb';

// Import the function to test.
import { getOrCreateObject } from './getOrCreateObject';
import { getOrCreateObject } from './getOrCreateObject.js';

process.env.DYNAMODB_TABLE = 'test-table';

Expand Down Expand Up @@ -45,4 +45,15 @@ describe('getOrCreateObject', () => {
);
expect(result.Body).toBeDefined();
});

it('should correctly handle unicode characters', async () => {
const result = await getOrCreateObject(
{
url: 'https://example-1111.s3-object-lambda.us-east-1.amazonaws.com/site/files/01/file-with-ñ.jpg',
headers: { },
},
'www.bu.edu',
);
expect(result.Body).toBeDefined();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { DynamoDBDocumentClient, GetCommand } from '@aws-sdk/lib-dynamodb';

const ddbMock = mockClient(DynamoDBDocumentClient);

import { lookupCustomCrop } from './lookupCustomCrop';
import { lookupCustomCrop } from './lookupCustomCrop.js';

// Table name is not relevant for these tests, but has to exist for the mocked ddb client.
process.env.DYNAMODB_TABLE = 'test-table';
Expand Down

0 comments on commit 8c1580c

Please sign in to comment.