Skip to content

Commit

Permalink
Merge pull request #1687 from ilios/dependabot/npm_and_yarn/eslint-9.0.0
Browse files Browse the repository at this point in the history
Bump eslint from 8.57.0 to 9.0.0
  • Loading branch information
jrjohnson authored Jul 10, 2024
2 parents 94a558f + 460f6b0 commit 07112b9
Show file tree
Hide file tree
Showing 12 changed files with 801 additions and 1,431 deletions.
17 changes: 0 additions & 17 deletions .eslintrc.yaml

This file was deleted.

33 changes: 33 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import globals from 'globals';
import js from '@eslint/js';
import stylisticJs from '@stylistic/eslint-plugin-js';
import nodePlugin from 'eslint-plugin-n';
import mochaPlugin from 'eslint-plugin-mocha';

export default [
js.configs.recommended,
mochaPlugin.configs.flat.recommended,
{
languageOptions: {
ecmaVersion: 2020,
sourceType: 'module',
globals: {
...globals.node,
},
},
plugins: {
n: nodePlugin,
s: stylisticJs,
},
rules: {
'no-console': 'off',
'prefer-const': 'error',
's/comma-dangle': ['error', 'only-multiline'],
's/comma-spacing': 'error',
's/indent': ['error', 2],
's/quotes': ['error', 'single', { avoidEscape: true }],
's/semi': 'error',
'strict': ['error', 'global']
},
},
];
2,049 changes: 686 additions & 1,363 deletions package-lock.json

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@
"author": "The Ilios Team",
"license": "MIT",
"devDependencies": {
"eslint": "^8.37.0",
"@stylistic/eslint-plugin-js": "^1.7.2",
"eslint": "^9.0.0",
"eslint-plugin-mocha": "^10.4.3",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-n": "^17.2.1",
"mocha": "^10.6.0",
"moment": "^2.30.1",
"serverless": "^3.39.0",
Expand Down
11 changes: 0 additions & 11 deletions test/.eslintrc.yaml

This file was deleted.

15 changes: 12 additions & 3 deletions test/createJWTTest.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

import createJWT from '../lib/createJWT.js';
import jwt from 'jsonwebtoken';

Expand All @@ -9,10 +10,15 @@ describe('Generates a JWT from provided data', function () {
const apiHost = 'https://example.com';
const apiNameSpace = '/api/v3';
const secret = 'secret';
const token = createJWT(userId, apiHost, apiNameSpace, secret);
let token;
let obj;

beforeEach(function () {
token = createJWT(userId, apiHost, apiNameSpace, secret);
assert.ok(token.length > 200);
obj = jwt.decode(token);
});

assert.ok(token.length > 200);
const obj = jwt.decode(token);
it('has the right passed values', function () {
assert.strictEqual(obj.iss, 'ilios-lti-server');
assert.strictEqual(obj.aud, 'ilios-lti-app');
Expand All @@ -22,17 +28,20 @@ describe('Generates a JWT from provided data', function () {
const diff = expiresAt.diff(now, 's');
assert.ok(diff < 61);
});

it('has the right default values', function () {
assert.strictEqual(obj.user_id, userId);
assert.strictEqual(obj.apiHost, apiHost);
assert.strictEqual(obj.apiNameSpace, apiNameSpace);
});

it('expires in less than 60 seconds', function () {
const expiresAt = moment(obj.exp, 'X');
const now = moment();
const diff = expiresAt.diff(now, 's');
assert.ok(diff < 61);
});

it('is valid', function () {
const isValid = jwt.verify(token, 'ilios.jwt.key.' + secret);
assert.ok(isValid);
Expand Down
11 changes: 8 additions & 3 deletions test/eventToRequestTest.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import eventToRequest from '../lib/eventToRequest.js';
import assert from 'assert';
//https://nodejs.org/api/http.html#http_http_request_options_callback
describe('Parses a lambda event into a node request', function() {
describe('Parses a lambda event into a node request', function () {
const protocol = 'https';
const host = 'localhost';
const path = '/dev/lti';
Expand All @@ -18,8 +18,13 @@ describe('Parses a lambda event into a node request', function() {
},
body
};
const request = eventToRequest(testEvent);
it('returns a correctly structured response', function() {
let request;

beforeEach(function () {
request = eventToRequest(testEvent);
});

it('returns a correctly structured response', function () {
assert.ok('method' in request);
assert.ok('url' in request);
assert.ok('protocol' in request);
Expand Down
14 changes: 10 additions & 4 deletions test/findIliosUserTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,15 @@ describe('Get the ID for a user', function () {
iliosMatchField: 'authentication-username'
};
const searchString = 'test-username';

const createJWT = (id) => `TOKEN${id}`;
const key = `${config.apiServer}:${config.apiNameSpace}:${config.ltiPostField}:${config.iliosMatchField}:userId:${searchString}`;
const keyHash = sha256(key);
process.env.USERID_SIMPLEDB_DOMAIN = 'test-domain';
let key;
let keyHash;

beforeEach(function () {
key = `${config.apiServer}:${config.apiNameSpace}:${config.ltiPostField}:${config.iliosMatchField}:userId:${searchString}`;
keyHash = sha256(key);
process.env.USERID_SIMPLEDB_DOMAIN = 'test-domain';
});

it('calls the api and returns a userId when there is no data in the cache', async function () {
const SimpleDB = function () {
Expand Down Expand Up @@ -58,6 +62,7 @@ describe('Get the ID for a user', function () {
const result = await findIliosUser({ fetch, createJWT, config, searchString, aws });
assert.strictEqual(result, 24);
});

it('Users the id in the cache when it exists', async function () {
const SimpleDB = function () {
this.getAttributes = ({ DomainName, ItemName }) => {
Expand All @@ -82,6 +87,7 @@ describe('Get the ID for a user', function () {
const result = await findIliosUser({ fetch, createJWT, config, searchString, aws });
assert.strictEqual(result, 11);
});

it('dies well when a bad search is performed', async function () {
const SimpleDB = function () {
this.getAttributes = ({ DomainName, ItemName }) => {
Expand Down
2 changes: 1 addition & 1 deletion test/launchCourseManagerTest.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import launchCourseManager from '../lib/launchCourseManager.js';
import assert from 'assert';
describe('Course Response handler works', async function() {
describe('Course Response handler works', function() {
it('sends a redirect with all the right data', async function () {
const ltiRequestValidator = () => true;
const eventToRequest = () => {
Expand Down
2 changes: 1 addition & 1 deletion test/launchDashboardTest.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import launchDashboard from '../lib/launchDashboard.js';
import assert from 'assert';
describe('Dashboard Response handler works', async function() {
describe('Dashboard Response handler works', function() {
it('sends a redirect with all the right data', async function () {
const ltiRequestValidator = () => true;
const eventToRequest = () => {
Expand Down
42 changes: 27 additions & 15 deletions test/ltiRequestValidatorTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,52 +25,64 @@ describe('Validate LTI Request', function () {
first: 'some data',
second: '--some*data',
};
let encodedParts;
let encodedString;
let encodedUrl;
let hash;

beforeEach(function () {
encodedParts = Object.entries(data).map(([key, value]) => {
const encodedValue = encodeRFC5987ValueChars(value);
return `${key}=${encodedValue}`;
}).sort();
encodedString = encodeRFC5987ValueChars(encodedParts.join('&'));
encodedUrl = encodeRFC5987ValueChars(url);
hash = hmac(`${secret}&${token}`, `POST&${encodedUrl}&${encodedString}`);
});

const encodedParts = Object.entries(data).map(([key, value]) => {
const encodedValue = encodeRFC5987ValueChars(value);
return `${key}=${encodedValue}`;
}).sort();
const encodedString = encodeRFC5987ValueChars(encodedParts.join('&'));
const encodedUrl = encodeRFC5987ValueChars(url);
const hash = hmac(`${secret}&${token}`, `POST&${encodedUrl}&${encodedString}`);

it('validate the signature and the data', async function () {
const body = Object.assign({'oauth_signature': hash}, data);
const body = Object.assign({ 'oauth_signature': hash }, data);
const request = createRequest(body);
request.url = url;

const result = ltiRequestValidator(secret, token, request);
assert.strictEqual(result, true);
});
it('returns false when the secret is different', async function() {
const body = Object.assign({'oauth_signature': hash}, data);

it('returns false when the secret is different', async function () {
const body = Object.assign({ 'oauth_signature': hash }, data);
const request = createRequest(body);

const result = ltiRequestValidator('wrong secret', token, request);
assert.strictEqual(result, false);
});
it('returns false when the token is different', async function() {
const body = Object.assign({'oauth_signature': hash}, data);

it('returns false when the token is different', async function () {
const body = Object.assign({ 'oauth_signature': hash }, data);
const request = createRequest(body);

const result = ltiRequestValidator(secret, 'wrong token', request);
assert.strictEqual(result, false);
});
it('returns false when signature is wrong', async function() {
const body = Object.assign({'oauth_signature': 'bad signature'}, data);

it('returns false when signature is wrong', async function () {
const body = Object.assign({ 'oauth_signature': 'bad signature' }, data);
const request = createRequest(body);

const result = ltiRequestValidator(secret, token, request);
assert.strictEqual(result, false);
});
it('returns false when the data does not match the signature', async function() {

it('returns false when the data does not match the signature', async function () {
const body = Object.assign({ 'oauth_signature': hash }, data);
delete body.first;
const request = createRequest(body);

const result = ltiRequestValidator(secret, token, request);
assert.strictEqual(result, false);
});

it('validates test data', async function () {
//data from http://lti.tools/oauth/
const body = {
Expand Down
31 changes: 20 additions & 11 deletions test/readSchoolConfigTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,26 @@ import fs from 'fs';
import assert from 'assert';

describe('Read the configuration for a school', function () {
const json = fs.readFileSync(new URL('sample-config.json', import.meta.url));
const S3 = function () {
this.getObject = () => {
return {
async promise() {
return {
Body: json
};
}
let json;
let S3;
let aws;

beforeEach(function () {
json = fs.readFileSync(new URL('sample-config.json', import.meta.url));
S3 = function () {
this.getObject = () => {
return {
async promise() {
return {
Body: json
};
}
};
};
};
};
const aws = { S3 };
aws = { S3 };
});

it('reads the first school correctly', async function () {
const result = await readSchoolConfig('demo-school-config', aws);
assert.ok('apiServer' in result, 'result contains apiServer');
Expand All @@ -33,6 +40,7 @@ describe('Read the configuration for a school', function () {
assert.ok('iliosMatchField' in result, 'result contains iliosMatchField');
assert.strictEqual(result.iliosMatchField, 'authentication-username', 'iliosMatchField is correct');
});

it('reads the second school correctly', async function () {
const result = await readSchoolConfig('second-school-config', aws);
assert.ok('apiServer' in result, 'result contains apiServer');
Expand All @@ -50,6 +58,7 @@ describe('Read the configuration for a school', function () {
assert.ok('iliosMatchField' in result, 'result contains iliosMatchField');
assert.strictEqual(result.iliosMatchField, 'authentication-username', 'iliosMatchField is correct');
});

it('dies well when a bad config is requested', async function () {
try {
await readSchoolConfig('bad-school-config', aws);
Expand Down

0 comments on commit 07112b9

Please sign in to comment.