@abaplint/core
Version:
abaplint - Core API
96 lines • 4.38 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ModifyOnlyOwnDBTables = exports.ModifyOnlyOwnDBTablesConf = void 0;
const Statements = require("../abap/2_statements/statements");
const Expressions = require("../abap/2_statements/expressions");
const issue_1 = require("../issue");
const _basic_rule_config_1 = require("./_basic_rule_config");
const _irule_1 = require("./_irule");
const _abap_object_1 = require("../objects/_abap_object");
const syntax_1 = require("../abap/5_syntax/syntax");
class ModifyOnlyOwnDBTablesConf extends _basic_rule_config_1.BasicRuleConfig {
constructor() {
super(...arguments);
this.reportDynamic = true;
/** Case insensitve regex for own tables */
this.ownTables = "^[yz]";
}
}
exports.ModifyOnlyOwnDBTablesConf = ModifyOnlyOwnDBTablesConf;
class ModifyOnlyOwnDBTables {
constructor() {
this.conf = new ModifyOnlyOwnDBTablesConf();
}
getMetadata() {
return {
key: "modify_only_own_db_tables",
title: "Modify only own DB tables",
shortDescription: `Modify only own DB tables`,
extendedInformation: `https://docs.abapopenchecks.org/checks/26/`,
tags: [_irule_1.RuleTag.Security],
};
}
getConfig() {
return this.conf;
}
setConfig(conf) {
this.conf = conf;
}
initialize(reg) {
this.reg = reg;
return this;
}
run(obj) {
var _a;
if (!(obj instanceof _abap_object_1.ABAPObject)) {
return [];
}
let spaghetti = undefined;
const output = [];
for (const file of obj.getABAPFiles()) {
const struc = file.getStructure();
if (struc === undefined) {
return [];
}
const regExp = new RegExp(this.getConfig().ownTables, "i");
for (const s of file.getStatements()) {
const g = s.get();
if (g instanceof Statements.DeleteDatabase
|| g instanceof Statements.UpdateDatabase
|| g instanceof Statements.InsertDatabase
|| g instanceof Statements.ModifyDatabase) {
const databaseTable = s.findFirstExpression(Expressions.DatabaseTable);
if (databaseTable === undefined) {
continue;
}
if (((_a = databaseTable.getFirstChild()) === null || _a === void 0 ? void 0 : _a.get()) instanceof Expressions.Dynamic) {
if (this.getConfig().reportDynamic === true) {
output.push(issue_1.Issue.atStatement(file, s, this.getMetadata().title, this.getMetadata().key, this.getConfig().severity));
}
continue;
}
const concat = databaseTable.concatTokens().toUpperCase();
if (regExp.test(concat) === false) {
// must contain a ReferenceType.TableVoidReference or a ReferenceType.TableReference if its a dependency
if (spaghetti === undefined) {
spaghetti = new syntax_1.SyntaxLogic(this.reg, obj).run().spaghetti;
}
const start = databaseTable.getFirstToken().getStart();
const scope = spaghetti.lookupPosition(start, file.getFilename());
const found1 = scope === null || scope === void 0 ? void 0 : scope.findTableVoidReference(start);
if (found1) {
output.push(issue_1.Issue.atStatement(file, s, this.getMetadata().title, this.getMetadata().key, this.getConfig().severity));
}
const found2 = scope === null || scope === void 0 ? void 0 : scope.findTableReference(start);
if (found2) {
output.push(issue_1.Issue.atStatement(file, s, this.getMetadata().title, this.getMetadata().key, this.getConfig().severity));
}
}
}
}
}
return output;
}
}
exports.ModifyOnlyOwnDBTables = ModifyOnlyOwnDBTables;
//# sourceMappingURL=modify_only_own_db_tables.js.map