Skip to content

Commit 4c02daf

Browse files
committed
Updates to profile calculation
1 parent 0797212 commit 4c02daf

File tree

3 files changed

+58
-34
lines changed

3 files changed

+58
-34
lines changed

src/main/server/profile/calculator.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ module.exports = class ProfileCalculator {
118118

119119
if (this.frameworkId != null)
120120
if (this.framework == null)
121-
this.framework = await EcFramework.get(this.frameworkId);
121+
this.framework = await EcFramework.get(this.frameworkId,null,null,repo,eim);
122122

123123
let profileKey = null;
124124
let storedProfile = null;

src/main/server/profile/coprocessors/default.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@ let fetchAssertions = async function(){
1414
let prevCount = assertions.length;
1515
assertions = await Promise.all(assertions.map(async(a)=>{
1616
let subjectPk = await a.getSubject();
17+
if (subjectPk == null) return null;
1718
if (subjectPk.toPem() == this.pem)
1819
return a;
1920
return null;
2021
}));
21-
global.auditLogger.report(global.auditLogger.LogCategory.PROFILE, global.auditLogger.Severity.INFO, "DefaultFetchAssertions", `Relevant assertion count: (${prevCount} -> ${assertions.length})`);
2222
assertions = assertions.filter((x)=>(x));
23+
global.auditLogger.report(global.auditLogger.LogCategory.PROFILE, global.auditLogger.Severity.INFO, "DefaultFetchAssertions", `Relevant assertion count: (${prevCount} -> ${assertions.length})`);
2324
assertions.sort((a, b)=>{
2425
return b.id.localeCompare(a.id);
2526
});

src/main/server/profile/util.js

+55-32
Original file line numberDiff line numberDiff line change
@@ -1,88 +1,111 @@
1-
const EcPerson = require("cassproject/src/org/schema/EcPerson");
1+
const EcPerson = require('cassproject/src/org/schema/EcPerson');
22

33
/** Will NOT return null, but may throw errors. */
4-
let anythingToPem = global.anythingToPem = async(subject) => {
5-
if (typeof subject === "string" && subject.startsWith("-----BEGIN")) {
4+
let anythingToPem = global.anythingToPem = async (subject) => {
5+
if (typeof subject === 'string' && subject.startsWith('-----BEGIN')) {
66
return subject;
77
}
88

9-
return anythingToPerson(subject).then(person => {
10-
if (person == null) throw new Error("No Person found for " + subject);
11-
if (EcArray.isArray(person))
9+
return anythingToPerson(subject).then((person) => {
10+
if (person == null) throw new Error('No Person found for ' + subject);
11+
if (EcArray.isArray(person)) {
1212
return person.map((p)=>p.owner[0]);
13+
}
1314
return person.owner[0];
14-
}).catch(e => {
15+
}).catch((e) => {
1516
throw e;
1617
});
1718
};
1819

19-
let anythingToPerson = global.anythingToPerson = async(subject) => {
20+
let unknownPerson = new EcPerson();
21+
unknownPerson.generateId(global.repo.selectedServer);
22+
unknownPerson.name = 'Unknown Person';
23+
let anythingToPersonIsTolerant = true;
24+
let anythingToPerson = global.anythingToPerson = async (subject) => {
2025
// No/Invalid subject?
21-
if (subject == null) throw new Error("Parse Error");
26+
if (subject == null) throw new Error('Parse Error');
2227

2328
let result;
24-
if (EcArray.isArray(subject))
29+
if (EcArray.isArray(subject)) {
2530
result = await Promise.all(subject.map(anythingToPerson));
31+
}
2632
// Subject is URL?
27-
else if (typeof subject === "string" && subject.startsWith("http")) {
33+
else if (typeof subject === 'string' && subject.startsWith('http')) {
2834
const url = subject;
2935
let person;
3036
try {
3137
person = await EcPerson.get(url);
3238
} catch (e) {
33-
error(e,500);
39+
if (anythingToPersonIsTolerant) return unknownPerson;
40+
error(e, 500);
3441
}
3542

36-
if (person == null)
37-
error("Person not found.",400);
43+
if (person == null) {
44+
if (anythingToPersonIsTolerant) return unknownPerson;
45+
error('Person not found.', 400);
46+
}
3847

3948
result = person;
40-
} else if (typeof subject === "string" && subject.startsWith("-----BEGIN")) {
49+
} else if (typeof subject === 'string' && subject.startsWith('-----BEGIN')) {
4150
// Subject is PEM
4251
subject = EcPk.fromPem(subject).toPem();
4352
let person;
4453
try {
4554
person = await EcPerson.getByPk(repo, EcPk.fromPem(subject)).catch(() => {});
4655
if (person == null) {
47-
people = await EcPerson.search(repo,`owner:"${subject}"`);
56+
people = await EcPerson.search(repo, `owner:"${subject}"`);
4857
people = people.filter((p) => p.owner[0] == subject);
4958
if (people.length > 0) person = people[0];
50-
if (people.length > 1) global.auditLogger.report(global.auditLogger.LogCategory.PROFILE, global.auditLogger.Severity.INFO, "AnythingToPerson", `Looking for person, found people! ${people.length}`);
59+
if (people.length > 1) global.auditLogger.report(global.auditLogger.LogCategory.PROFILE, global.auditLogger.Severity.INFO, 'AnythingToPerson', `Looking for person, found people! ${people.length}`);
5160
}
5261
} catch (e) {
53-
global.auditLogger.report(global.auditLogger.LogCategory.PROFILE, global.auditLogger.Severity.ERROR, "AnythingToPerson", e);
62+
global.auditLogger.report(global.auditLogger.LogCategory.PROFILE, global.auditLogger.Severity.ERROR, 'AnythingToPerson', e);
5463
if (e instanceof TypeError) {
55-
throw new Error("Parse Error");
56-
} else throw new Error(e.message);
64+
if (anythingToPersonIsTolerant) return unknownPerson;
65+
throw new Error('Parse Error');
66+
} else {
67+
if (anythingToPersonIsTolerant) return unknownPerson;
68+
throw new Error(e.message);
69+
}
5770
}
5871

59-
if (person == null) throw new Error("Could not find " + subject);
72+
if (person == null) {
73+
if (anythingToPersonIsTolerant) return unknownPerson;
74+
throw new Error('Could not find ' + subject);
75+
}
6076

6177
result = person;
62-
} else if (typeof subject === "string") {
78+
} else if (typeof subject === 'string') {
6379
// Subject is an Email or Username
6480
let people;
6581
try {
66-
people = await EcPerson.search(repo,`email:"${subject}" OR username:"${subject}"`);
82+
people = await EcPerson.search(repo, `email:"${subject}" OR username:"${subject}"`);
6783
} catch (e) {
68-
global.auditLogger.report(global.auditLogger.LogCategory.PROFILE, global.auditLogger.Severity.ERROR, "AnythingToPerson", e);
84+
if (anythingToPersonIsTolerant) return unknownPerson;
85+
global.auditLogger.report(global.auditLogger.LogCategory.PROFILE, global.auditLogger.Severity.ERROR, 'AnythingToPerson', e);
6986
throw new Error(e.message);
7087
}
71-
if (people == null || people.length === 0) Error("No Person found for " + subject);
88+
if (people == null || people.length === 0) {
89+
if (anythingToPersonIsTolerant) return unknownPerson;
90+
throw new Error('No Person found for ' + subject);
91+
}
7292

7393
result = people[0];
7494
}
7595

7696
if (result != null) {
77-
if (result.personType != null && result.personType !== "Person")
78-
throw Error("No Person found for " + subject);
97+
if (result.personType != null && result.personType !== 'Person') {
98+
if (anythingToPersonIsTolerant) return unknownPerson;
99+
throw Error('No Person found for ' + subject);
100+
}
79101
return result;
80102
}
81103

82-
throw new Error("Parse Error");
83-
}
104+
if (anythingToPersonIsTolerant) return unknownPerson;
105+
throw new Error('Parse Error');
106+
};
84107
module.exports = {
85108
/** Will NOT return null, but may throw errors. */
86-
anythingToPem: anythingToPem,
87-
anythingToPerson: anythingToPerson
88-
}
109+
anythingToPem: anythingToPem,
110+
anythingToPerson: anythingToPerson,
111+
};

0 commit comments

Comments
 (0)