Skip to content

Commit

Permalink
WIP Sonar
Browse files Browse the repository at this point in the history
  • Loading branch information
Lomilar committed Oct 1, 2024
1 parent f69d8ce commit 4b7bfe5
Show file tree
Hide file tree
Showing 18 changed files with 1,993 additions and 2,032 deletions.
3,829 changes: 1,908 additions & 1,921 deletions coverage/lcov.info

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion cypressWebpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ module.exports = defineConfig({
// We've imported your old cypress plugins here.
// You may want to clean this up later by importing these.
setupNodeEvents(on, config) {
require('@cypress/code-coverage/task')(on, config)
require("cypress-fail-fast/plugin")(on, config);
return require('./cypressWebpack/plugins/index.js')(on, config)
},
Expand Down
1 change: 0 additions & 1 deletion cypressWebpack/support/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,3 @@

// Alternatively you can use CommonJS syntax:
// require('./commands');
import '@cypress/code-coverage/support'
2 changes: 0 additions & 2 deletions src/com/asd/s3000l/CrudCodeValues.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@

const CrudCodeValues = require("./CrudCodeValues");
module.exports = {
I: "I",
D: "D",
Expand Down
2 changes: 1 addition & 1 deletion src/com/asd/s3000l/ZoneElementRevision.js
Original file line number Diff line number Diff line change
Expand Up @@ -1242,7 +1242,7 @@ module.exports = class ZoneElementRevision extends EcRemoteLinkedData {

getInt() {
if (this._int == null) {
_int = [];
this._int = [];
}
return this._int;
}
Expand Down
9 changes: 4 additions & 5 deletions src/com/eduworks/ec/crypto/EcAesCtrAsyncWorker.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ module.exports = class EcAesCtrAsyncWorker {
*/
static encrypt(plaintext, secret, iv, success, failure) {
EcRsaOaepAsyncWorker.initWorker();
if (EcRsaOaepAsyncWorker.w == null || EcRsaOaepAsyncWorker.w[EcRsaOaepAsyncWorker.rotator] == null) {
if (EcRsaOaepAsyncWorker.w?.[EcRsaOaepAsyncWorker.rotator] == null) {
return cassReturnAsPromise(
EcAesCtrAsync.encrypt(plaintext, secret, iv),
success,
Expand Down Expand Up @@ -68,7 +68,7 @@ module.exports = class EcAesCtrAsyncWorker {
}
}
EcRsaOaepAsyncWorker.initWorker();
if (EcRsaOaepAsyncWorker.w == null || EcRsaOaepAsyncWorker.w[EcRsaOaepAsyncWorker.rotator] == null) {
if (EcRsaOaepAsyncWorker.w?.[EcRsaOaepAsyncWorker.rotator] == null) {
return cassReturnAsPromise(
EcAesCtrAsync.decrypt(ciphertext, secret, iv),
success,
Expand All @@ -89,9 +89,8 @@ module.exports = class EcAesCtrAsyncWorker {
});
if (EcCrypto.caching)
p = p.then((decrypted) => {
return EcCrypto.decryptionCache[
secret + iv + ciphertext
] = decrypted;
EcCrypto.decryptionCache[secret + iv + ciphertext] = decrypted;
return decrypted;
});
return cassPromisify(p, success, failure);
}
Expand Down
7 changes: 2 additions & 5 deletions src/com/eduworks/ec/crypto/EcPpkFacade.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
let pemJwk = require("pem-jwk");
let forge = require("node-forge");
let EcPk = require("./EcPk.js");
let EcPpk = require("./EcPpk.js");
/**
Expand Down Expand Up @@ -101,9 +99,8 @@ module.exports = class EcPpkFacade extends EcPpk {
* @method inArray
*/
inArray(ppks) {
for (let i = 0; i < ppks.length; i++) {
if (ppks[i].equals(this)) return true;
}
for (let ppk of ppks)
if (ppk.equals(this)) return true;
return false;
}
};
10 changes: 5 additions & 5 deletions src/com/eduworks/ec/crypto/forgeAsyncNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function registerPromiseWorker(callback) {
}

function handleIncomingMessage(e, callback, messageId, message) {
var result = tryCatchFunc(callback, message)
let result = tryCatchFunc(callback, message)

if (result.err) {
postOutgoingMessage(e, messageId, result.err)
Expand All @@ -56,13 +56,13 @@ function registerPromiseWorker(callback) {
function onIncomingMessage(e) {
if (e.origin != 'cassproject' && e.data?.origin != 'cassproject' && e.data?.[1]?.origin != 'cassproject') { console.log("Origin does not match.", e.origin);return;}

var payload = e.data
let payload = e.data
if (!Array.isArray(payload) || payload.length !== 2) {
// message doens't match communication format; ignore
return
}
var messageId = payload[0]
var message = payload[1]
let messageId = payload[0]
let message = payload[1]

if (typeof callback !== 'function') {
postOutgoingMessage(e, messageId, new Error(
Expand All @@ -78,7 +78,7 @@ function registerPromiseWorker(callback) {
require('../../../../../');

registerPromiseWorker(function (e) {
var data = e;
let data = e;
try {
switch (data.cmd) {
case 'encryptRsaOaep':
Expand Down
8 changes: 6 additions & 2 deletions src/com/eduworks/ec/graph/EcFrameworkGraph.js
Original file line number Diff line number Diff line change
Expand Up @@ -441,14 +441,18 @@ module.exports = class EcFrameworkGraph extends EcDirectedGraph {
this.cacheEdges(t);
return true;
}
removeVertex(vertex) {
delete this.inEdgeCache[vertex.shortId()];
delete this.outEdgeCache[vertex.shortId()];
return super.removeVertex(vertex);
}
cacheEdges(e)
{
//TODO: Remove cached stuff when edges are removed.
if (this.inEdgeCache[e.destination.shortId()] == null)
this.inEdgeCache[e.destination.shortId()] = [];
this.inEdgeCache[e.destination.shortId()].push(e.edge);
if (this.outEdgeCache[e.source.shortId()] == null)
this.outEdgeCache[e.source.shortId()] = [];
this.outEdgeCache[e.source.shortId()].push(e.edge);
}
};
};
8 changes: 4 additions & 4 deletions src/com/eduworks/schema/cfd/competency/CfdFramework.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ module.exports = class CfdFramework extends EcFramework {
};
if (remove == 0) onAllRemove();
if (this.competency != null && this.competency.length > 0) {
for (let x = 0; x < this.competency.length; x++) {
for (let comp of this.competency) {
CfdCompetency.get(
this.competency[x],
comp,
function (comp) {
comp._delete(
function (p1) {
Expand Down Expand Up @@ -140,9 +140,9 @@ module.exports = class CfdFramework extends EcFramework {
}
}
if (this.relation != null && this.relation.length > 0) {
for (let x = 0; x < this.relation.length; x++) {
for (let rel of this.relation) {
EcAlignment.get(
this.relation[x],
rel,
function (rel) {
rel._delete(
function (p1) {
Expand Down
3 changes: 0 additions & 3 deletions src/com/eduworks/schema/ebac/EbacCredentialCommit.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ const EbacCredentials = require("./EbacCredentials");

/**
* Message used to commit credentials to a remote login server.
* <p>
* TODO: Vulnerable to replay attacks. Token field prevents some replay
* attacks.
*
* @author [email protected]
* @class EbacCredentialCommit
Expand Down
2 changes: 0 additions & 2 deletions src/com/eduworks/schema/ebac/EbacCredentialRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ const EcLinkedData = require("../../../../org/json/ld/EcLinkedData");

/**
* Message used to retrieve credentials from a remote system.
* <p>
* TODO: Vulnerable to replay attacks.
*
* @author [email protected]
* @class EbacCredentialRequest
Expand Down
44 changes: 16 additions & 28 deletions src/com/eduworks/schema/pebl/eXtension/ExtContent.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,35 +88,23 @@ module.exports = class ExtContent extends schema.CreativeWork {
* @method save
*/
save(success, failure, repo, eim) {
if (this.getId() == null || this.getId() == "") {
let msg = "ID cannot be missing";
if (failure != null) return failure(msg);
else throw new Error(msg);
}
if (this.getTitle() == null || this.getTitle() == "") {
let msg = "Title cannot be missing";
if (failure != null) return failure(msg);
else throw new Error(msg);
}
if (this.getDescription() == null || this.getDescription() == "") {
let msg = "Description cannot be missing";
if (failure != null) return failure(msg);
else throw new Error(msg);
}
if (this.getLaunchURL() == null || this.getLaunchURL() == "") {
let msg = "Launch URL cannot be missing";
if (failure != null) return failure(msg);
else throw new Error(msg);
}
if (
this.getInstitution() == null ||
this.getInstitution().name == null ||
this.getInstitution().name == ""
) {
let msg = "Institution name cannot be missing";
if (failure != null) return failure(msg);
else throw new Error(msg);
let invalid = (it) => {return it == null || it != ""};
let fail = (msg) => {
if (failure != null)
return failure(msg);
else
throw new Error(msg);
}
if (invalid(this.getId()))
return fail("ID cannot be missing");
if (invalid(this.getTitle()))
return fail("Title cannot be missing");
if (invalid(this.getDescription()))
return fail("Description cannot be missing");
if (invalid(this.getLaunchURL()))
return fail("Launch URL cannot be missing");
if (invalid(this.getInstitution()?.name))
return fail("Institution name cannot be missing");
return EcRepository.save(this, success, failure, repo, eim);
}
/**
Expand Down
2 changes: 1 addition & 1 deletion src/com/eduworks/schema/pebl/eXtension/ExtInstitution.js
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ module.exports = class ExtInstitution extends schema.Organization {
* @param {String} addrCityState
* @param {String} addrZip
*/
addPOC(
addPOC( //NOSONAR Unused, kept for legacy purposes.
type,
name,
title,
Expand Down
37 changes: 17 additions & 20 deletions src/com/eduworks/schema/pebl/eXtension/ExtPerson.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,30 +98,27 @@ module.exports = class ExtPerson extends schema.Person {
* @method save
*/
save(success, failure, repo, eim) {
if (this.getId() == null || this.getId() == "") {
let msg = "ID cannot be missing";
if (failure != null) return failure(msg);
else throw new Error(msg);
let invalid = (it) => { return it == null || it != "" };
let fail = (msg) => {
if (failure != null)
return failure(msg);
else
throw new Error(msg);
}
if (this.getFirstName() == null || this.getFirstName() == "") {
let msg = "First name cannot be missing";
if (failure != null) return failure(msg);
else throw new Error(msg);
if (invalid(this.getId())) {
return fail("ID cannot be missing");
}
if (this.getLastName() == null || this.getLastName() == "") {
let msg = "Last name cannot be missing";
if (failure != null) return failure(msg);
else throw new Error(msg);
if (invalid(this.getFirstName())) {
return fail("First name cannot be missing");
}
if (this.getUserName() == null || this.getUserName() == "") {
let msg = "Username cannot be missing";
if (failure != null) return failure(msg);
else throw new Error(msg);
if (invalid(this.getLastName())) {
return fail("Last name cannot be missing");
}
if (this.getEmail() == null || this.getEmail() == "") {
let msg = "Email cannot be missing";
if (failure != null) return failure(msg);
else throw new Error(msg);
if (invalid(this.getUserName())) {
return fail("Username cannot be missing");
}
if (invalid(this.getEmail())) {
return fail("Email cannot be missing");
}
return EcRepository.save(this, success, failure, repo, eim);
}
Expand Down
35 changes: 17 additions & 18 deletions src/org/cass/competency/EcAlignment.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ const EcRemoteLinkedData = require("../../cassproject/schema/general/EcRemoteLin
*
* @author [email protected]
* @author [email protected]
* <p>
* TODO: Test case where an absent relation is in the framework.
* @module org.cassproject
* @class EcAlignment
* @constructor
Expand Down Expand Up @@ -131,7 +129,6 @@ module.exports = class EcAlignment extends Relation {
static searchBySources(repo, sourceIds, success, failure, paramObj, eim) {
let query = "";
query = "(source:";
let noVersions = [];
for (let i = 0; i < sourceIds.length; i++) {
let sourceId = sourceIds[i];
if (i != 0) query += " OR ";
Expand All @@ -141,7 +138,6 @@ module.exports = class EcAlignment extends Relation {
} else {
query += '"' + sourceId + '" OR source:"' + noVersion + '"';
}
noVersions.push(noVersion);
}
query += ")";
return EcAlignment.search(repo, query, success, failure, paramObj, eim);
Expand Down Expand Up @@ -220,23 +216,26 @@ module.exports = class EcAlignment extends Relation {
* @method save
*/
save(success, failure, repo, eim) {
if (this.source == null || this.source == "") {
let msg = "Source Competency cannot be missing";
if (failure !== undefined && failure != null) return failure(msg);
else throw new Error(msg);
let invalid = (it) => { return it == null || it == "" };
let fail = (msg) => {
if (failure != null)
return failure(msg);
else
throw new Error(msg);
}
if (this.target == null || this.target == "") {
let msg = "Target Competency cannot be missing";
if (failure !== undefined && failure != null) return failure(msg);
else throw new Error(msg);
if (invalid(this.source)) {
return fail("Source Competency cannot be missing");
}
if (this.relationType == null || this.relationType == "") {
let msg = "Relation Type cannot be missing";
if (failure !== undefined && failure != null) return failure(msg);
else throw new Error(msg);
if (invalid(this.target)) {
return fail("Target Competency cannot be missing");
}
if (repo == null) return EcRepository.save(this, success, failure, repo, eim);
else return repo.saveTo(this, success, failure, eim);
if (invalid(this.relationType)) {
return fail("Relation Type cannot be missing");
}
if (repo == null)
return EcRepository.save(this, success, failure, repo, eim);
else
return repo.saveTo(this, success, failure, eim);
}
/**
* Deletes the alignment from the server corresponding to its ID
Expand Down
Loading

0 comments on commit 4b7bfe5

Please sign in to comment.