Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
var fluid = require("infusion"),
kettle = fluid.require("kettle");
// Ensure this happens first, to catch errors during code loading.
kettle.loadTestingSupport();
// Pass the current `require` to `fluid.require`, as nyc's instrumentation is hooked into it.
fluid.require("%gpii-universal", require);
var testIncludes = [
"./CloudStatusProductionTests.js",
"./SettingsGetProductionTests.js",
"./SettingsPutProductionTests.js"
];
fluid.each(testIncludes, function (path) {
require(path);
});
fluid.each(settingsDefs, function (settingsDef) {
var isValid = gpii.tests.universal.solutionsRegistry.validateSinglePayload(
preferencePayload,
settingsDef.schema,
"settings file " + settingsFilePath + " -> " + preferenceKey
);
if (!isValid) {
fileErrors++;
}
});
}
// "SR" preferences, which are "deep", i.e. multiple key:value pairs per solution.
else {
fluid.each(preferencePayload, function (prefValue, prefKey) {
var solutionKey = preferenceKey.replace("http://registry.gpii.net/applications/", "");
var settingsLabel = "settings file " + settingsFilePath + " -> " + solutionKey + " -> " + prefKey;
var settingsDefs = fluid.get(settingsIndex, [solutionKey, prefKey]);
if (!settingsDefs || settingsDefs.length === 0) {
fluid.log("WARNING, setting found that does not correspond to a known setting: " + settingsLabel);
}
fluid.each(settingsDefs, function (settingsDef) {
if (settingsDef.schema) {
var isValid = gpii.tests.universal.solutionsRegistry.validateSinglePayload(
prefValue,
settingsDef.schema,
settingsLabel
);
if (!isValid) {
gpii.pcpInterface.sendUserMessage = function (socket, text, messageType, extras) {
console.log("User message sent: " + text);
fluid.each(gpii.pcpInterface.sockets, function (s) {
if ((s === null) || (s.disconnected === true)) {
fluid.log("No PCP connected on this socket, so discarding message: " + text);
} else {
// Default to 'infoMessage'
var message = {
type: (messageType === undefined) ? "infoMessage" : messageType,
message: text
};
if (extras) {
message = $.extend(true, {}, message, extras);
}
s.emit("message", message, fluid.log);
}
});
};
gpii.migration.GPII4014.verifyDocsData = function (responseString, options) {
var allDocs = JSON.parse(responseString);
var totalNumOfDocs = allDocs.total_rows;
var numOfVerified = 0;
var numOfErrorDocs = 0;
var togo = fluid.promise();
fluid.each(allDocs.rows, function (aRow) {
var hasError = false;
var aDoc = aRow.doc;
// To filter out the "_design/views" doc that doesn't have the "schemaVersion" field
if (aDoc.schemaVersion) {
numOfVerified++;
if (aDoc.schemaVersion !== gpii.migration.GPII4014.newSchemaVersion) {
console.log("Error with the document _id \"" + aDoc._id + "\": schema version is ", aDoc.schemaVersion, ", not ", gpii.migration.GPII4014.newSchemaVersion);
hasError = true;
}
if (aDoc.timestampUpdated === null) {
console.log("Error with the document _id \"" + aDoc._id + "\": the value of timestampUpdated is empty");
hasError = true;
}
if (aDoc.type === "clientCredential") {
var docFields = {
allowedIPBlocks: aDoc.allowedIPBlocks,
gpii.metrics.logonStateChanged = function (that, lifecycleManager, oldValue, newValue) {
if (oldValue && oldValue.type === "login" && (newValue.type === "logout" || !newValue.inProgress)) {
var session = lifecycleManager.getSession(oldValue.gpiiKey);
// The reason for this null checker is that the lifecyclaManager's "session" may be null after
// having logged on with a bogus token which terminated the request in error before the
// "session" could be created.
if (session) {
// Log the solution IDs that hadn't been applied.
var expectedSolutions = fluid.keys(session.model.activeConfiguration.lifecycleInstructions);
fluid.each(expectedSolutions, function (id) {
if (!session.model.appliedSolutions[id]) {
that.logMetric("solution-failed", {
solutionID: id
});
}
});
}
}
};
gpii.tests.universal.solutionsRegistry.indexSrEntries = function (indexObject, srData) {
fluid.each(srData, function (solutionDef, solutionKey) {
fluid.each(solutionDef.settingsHandlers, function (settingsHandler) {
fluid.each(settingsHandler.supportedSettings, function (settingDef, settingKey) {
gpii.tests.universal.solutionsRegistry.indexSingleSolution(indexObject, [solutionKey, settingKey], settingDef);
});
});
});
};
gpii.source.finalInit = function (that) {
fluid.each(that.options.invokers, function (invoker, name) {
that.server[name](that.options.path, that[name]);
});
};
fluid.each(handlerResponse, function (handler, idx) {
if (handler[solutionId] !== null && handler[solutionId] !== undefined) {
var settings = handler[solutionId].settings;
fluid.each(settings, function (setting, key) {
returnSettings[key] = setting.oldValue;
});
}
});
return returnSettings;
gpii.ontologyHandler.collectPaths = function (obj, search, target, pathArray) {
if (!(pathArray instanceof Array)) {
pathArray = [];
}
fluid.each(obj, function (entry, key) {
pathArray.push(key);
if (entry === search) {
var path = fluid.pathUtil.composeSegments.apply(null, pathArray);
target.push(path);
pathArray.pop(key);
return;
}
if (!fluid.isPrimitive(entry)) {
gpii.ontologyHandler.collectPaths(entry, search, target, pathArray);
}
pathArray.pop(key);
});
};
gpii.accessTokens.filterExpiredAccessTokens = function (responseString, options) {
if (options.deleteAll) {
fluid.log("Deleting all access tokens...");
} else {
fluid.log("Filtering for expired access tokens...");
}
var tokens = JSON.parse(responseString);
var expiredTokens = [];
options.totalTokens = 0;
if (tokens.rows) {
fluid.each(tokens.rows, function (aRow) {
var aToken = aRow.value.authorization;
if (options.deleteAll || Date.now() > Date.parse(aToken.timestampExpires)) {
expiredTokens.push(aToken);
}
options.totalTokens++;
});
options.accessTokens = expiredTokens;
}
return expiredTokens;
};