Generate and/or verify the hashcode for sys_update_xml payloads in vanilla javascript.
npm install @devendor/sn-payload-hashcodeshell
npm install @devendor/sn-payload-hashcode --save-dev
`
Exports
strHashCode and polyfill
strHashCode is a pure-js implimentation of the java String.hashCode Method
`shell
rferguson@mendota:~/code/sn-payload-hashcode$ nodejs
> require('.').strHashCode('Helo World');
840137394
> require('.').polyfill();
undefined
> 'Helo World'.hashCode();
840137394`Compare to Java
`shell
rferguson@mendota:~/code/sn-payload-hashcode/test$ cat Main.java
public class Main {
public static void main(String[] args) {
String myStr = "Helo World";
System.out.println(myStr.hashCode());
}
}
rferguson@mendota:~/code/sn-payload-hashcode/test$ javac Main.java
rferguson@mendota:~/code/sn-payload-hashcode/test$ java Main
840137394
`payloadHashCode
The payloadHashCode replicates the hashcode algorythem servicenow uses
for sys_update_xml records. The portion of these records
also makes up the xml files the Studio app checks into git. The method will work on either an isolated payload like the ones in git or the sys_update_xml files.
Note: This relies on consistent formatting which appears to include four space indentation, "\n"
line delimeters, no trailing line feed, and scrubbing of volatile metadata like sys_updated_on etc.
`shell
rferguson@mendota:~/code/sn-payload-hashcode$ nodejs passed
``js
{
let sys_update_version_xml = [ '',
' ',
' 10 ',
' d3c89
ea5db07330098cbde82ca9619ee ',
' sys_embedded_help_role ',
' ray.ferguson ',
' 2019-08-03 20:56:39 ',
' 446952e1db07330098cbde82ca9619fb ',
' 0 ',
' d3c89ea5db07330098cbde82ca9619ee ',
' 1b951ea1db07330098cbde82ca9619
ac ',
' ',
' 1b951ea1db07330098cbde82ca9619ac ',
' sys_embedded_help_role_446952e1db07330098cbde82ca9619fb ',
' ray.ferguson ',
' 2019-08-03 20:56:39 ',
' ',
' '].join("\n");
let hashCode = require('.').calculatePayloadHashCode(sys_update_version_xml);
if (hashCode == 2078306678){ // sys_update_xml.payload_hash from system.
console.log('passed');
} else {
console.log(failed);
}}
`
running with the cli utility
help
`shellNote: ./cli.js gets install into ./node_modules/.bin/sn-payload-hashcode
rferguson@mendota:~/code/sn-payload-hashcode$ ./cli.js -h
Reading from STDIN
cli.js@1.0.0CLI OPTIONS:
-f, --file Input file(s) (Pass '-' for stdin)
-h, --help Show this help
-v, --version Show package version
`STDIN
`shellrferguson@mendota:~/code/sn-payload-hashcode$ ./cli.js <../x_dete_emb/xml/sys_app_1b951ea1db07330098cbde82ca9
619ac.xml
Reading from STDIN
{
"-": 1902278309
}
`
explicit
`shellrferguson@mendota:~/code/sn-payload-hashcode$ ./cli.js -f ../x_dete_emb/xml/sys_app_1b951ea1db07330098cbde82
ca9619ac.xml
{
"/home/rferguson/code/x_dete_emb/xml/sys_app_1b951ea1db07330098cbde82ca9619ac.xml": 1902278309
}
`Using shell globbing when glob param is not quoted. (unixes)
`shell
rferguson@mendota:~/code/sn-payload-hashcode$ ./cli.js -f ../x_dete_emb/xml/update/content_css_*
{
"/home/rferguson/code/x_dete_emb/xml/update/content_css_7f5aa2d9db1ff7009c1a622dca961926.xml": -1709665871
,
"/home/rferguson/code/x_dete_emb/xml/update/content_css_9befee5ddb1ff7009c1a622dca961916.xml": -268430420,
"/home/rferguson/code/x_dete_emb/xml/update/content_css_f838463cdb57b7009c1a622dca9619bd.xml": 1226607513
}
`Using nodejs glob module when quoted glob pattern.
`
rferguson@mendota:~/code/sn-payload-hashcode$ ./cli.js -f '../x_dete_emb/xml/update/sys_{user_role,ui_view}_
*.xml'
{
"/home/rferguson/code/x_dete_emb/xml/update/sys_ui_view_d4ad467cdb38a010862db298f496194a.xml": -24878458,
"/home/rferguson/code/x_dete_emb/xml/update/sys_user_role_a0a99ea5db07330098cbde82ca9619f2.xml": 565386732
,
"/home/rferguson/code/x_dete_emb/xml/update/sys_user_role_contains_be6a56e5db07330098cbde82ca96199f.xml":
-1785291525,
"/home/rferguson/code/x_dete_emb/xml/update/sys_user_role_d3c89ea5db07330098cbde82ca9619ee.xml": -20548678
}
`
Debug logging
`
rferguson@mendota:~/code/sn-payload-hashcode$ DEBUG_SN_PAYLOAD_HASH=1 ./cli.js -f '../x_dete_emb/xml/update/
sys_{user_role,ui_view}_*.xml'
isTTY: true
checkFile-param /home/rferguson/code/x_dete_emb/xml/update/sys_{user_role,ui_view}_*.xml
using glob
{
"/home/rferguson/code/x_dete_emb/xml/update/sys_ui_view_d4ad467cdb38a010862db298f496194a.xml": -24878458,
"/home/rferguson/code/x_dete_emb/xml/update/sys_user_role_a0a99ea5db07330098cbde82ca9619f2.xml": 565386732
,
"/home/rferguson/code/x_dete_emb/xml/update/sys_user_role_contains_be6a56e5db07330098cbde82ca96199f.xml":
-1785291525,
"/home/rferguson/code/x_dete_emb/xml/update/sys_user_role_d3c89ea5db07330098cbde82ca9619ee.xml": -20548678
}
``