-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #38 from UFGInsurance/fix/parse-error-messages
Improve XML parsing error messages
- Loading branch information
Showing
11 changed files
with
180 additions
and
199 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,96 +1,87 @@ | ||
const { propertyPlaceholderRegEx } = require("./constants"); | ||
const fs = require("fs"); | ||
const xml2js = require("xml2js"); | ||
const error = require("./error"); | ||
const xmlParser = require("./xmlParser"); | ||
const assert = require("./assert"); | ||
|
||
const expectedTlsContext = "clientTlsContext"; | ||
|
||
const validateGlobal = folderInfo => { | ||
let contents = fs.readFileSync(folderInfo.globalFile); | ||
let parser = new xml2js.Parser(); | ||
let { contents, xml } = xmlParser(folderInfo.globalFile); | ||
|
||
assert.isTrue( | ||
!contents.includes("<db:dynamic-query>"), | ||
"Global: Dynamic query is not permitted - vulnerable to SQL injection" | ||
); | ||
|
||
parser.parseString(contents, (err, result) => { | ||
if (err) { | ||
error.fatal(err); | ||
} | ||
|
||
assert.isTrue( | ||
result.mule["api-platform-gw:api"] && | ||
result.mule["api-platform-gw:api"][0]["$"]["doc:name"] === | ||
"API Autodiscovery", | ||
"Global: API Autodiscovery not configured" | ||
); | ||
|
||
let requestConfigs = result.mule["http:request-config"]; | ||
assert.isTrue( | ||
xml.mule["api-platform-gw:api"] && | ||
xml.mule["api-platform-gw:api"][0]["$"]["doc:name"] === | ||
"API Autodiscovery", | ||
"Global: API Autodiscovery not configured" | ||
); | ||
|
||
if (requestConfigs) { | ||
requestConfigs.forEach(requestConfig => { | ||
let requestConfigAttributes = requestConfig["$"]; | ||
let requestConfigs = xml.mule["http:request-config"]; | ||
|
||
let protocol = requestConfigAttributes.protocol; | ||
let host = requestConfigAttributes["host"]; | ||
let usesMockService = host && host.includes("mock"); | ||
if (requestConfigs) { | ||
requestConfigs.forEach(requestConfig => { | ||
let requestConfigAttributes = requestConfig["$"]; | ||
|
||
if (usesMockService) { | ||
return; // continue forEach, skip remaining checks | ||
} | ||
let protocol = requestConfigAttributes.protocol; | ||
let host = requestConfigAttributes["host"]; | ||
let usesMockService = host && host.includes("mock"); | ||
|
||
if (protocol === "HTTPS") { | ||
let tlsContext = requestConfigAttributes["tlsContext-ref"]; | ||
if (usesMockService) { | ||
return; // continue forEach, skip remaining checks | ||
} | ||
|
||
assert.equals( | ||
expectedTlsContext, | ||
tlsContext, | ||
`Global ${requestConfigAttributes.name} tlsContext` | ||
); | ||
} | ||
if (protocol === "HTTPS") { | ||
let tlsContext = requestConfigAttributes["tlsContext-ref"]; | ||
|
||
assert.matches( | ||
propertyPlaceholderRegEx, | ||
requestConfigAttributes.host, | ||
`Global ${requestConfigAttributes.name} host` | ||
assert.equals( | ||
expectedTlsContext, | ||
tlsContext, | ||
`Global ${requestConfigAttributes.name} tlsContext` | ||
); | ||
|
||
assert.matches( | ||
propertyPlaceholderRegEx, | ||
requestConfigAttributes.port, | ||
`Global ${requestConfigAttributes.name} port` | ||
} | ||
|
||
assert.matches( | ||
propertyPlaceholderRegEx, | ||
requestConfigAttributes.host, | ||
`Global ${requestConfigAttributes.name} host` | ||
); | ||
|
||
assert.matches( | ||
propertyPlaceholderRegEx, | ||
requestConfigAttributes.port, | ||
`Global ${requestConfigAttributes.name} port` | ||
); | ||
}); | ||
} | ||
|
||
let templateQueries = xml.mule["db:template-query"]; | ||
|
||
if (templateQueries) { | ||
templateQueries.forEach(templateQuery => { | ||
let query = templateQuery["db:parameterized-query"]; | ||
|
||
if (query) { | ||
let queryAttributes = query[0]["$"]; | ||
let isFileQuery = queryAttributes && queryAttributes.file; | ||
|
||
assert.isTrue( | ||
isFileQuery, | ||
"Global: Inline SQL should be moved to file" | ||
); | ||
}); | ||
} | ||
|
||
let templateQueries = result.mule["db:template-query"]; | ||
|
||
if (templateQueries) { | ||
templateQueries.forEach(templateQuery => { | ||
let query = templateQuery["db:parameterized-query"]; | ||
|
||
if (query) { | ||
let queryAttributes = query[0]["$"]; | ||
let isFileQuery = queryAttributes && queryAttributes.file; | ||
|
||
assert.isTrue( | ||
isFileQuery, | ||
"Global: Inline SQL should be moved to file" | ||
if (isFileQuery) { | ||
assert.matches( | ||
/^sql\//, | ||
queryAttributes.file, | ||
"Global: Database query file" | ||
); | ||
|
||
if (isFileQuery) { | ||
assert.matches( | ||
/^sql\//, | ||
queryAttributes.file, | ||
"Global: Database query file" | ||
); | ||
} | ||
} | ||
}); | ||
} | ||
}); | ||
} | ||
}); | ||
} | ||
}; | ||
|
||
module.exports = validateGlobal; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.