Skip to content

Commit

Permalink
Merge pull request #189 from Patrik-Stas/fix/scanning-buildernet
Browse files Browse the repository at this point in the history
Fix endpoint attrib processing, fix daemon hanging on regex
  • Loading branch information
Patrik-Stas authored Sep 10, 2022
2 parents 1dc74fd + dd5adc0 commit dceb941
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 13 deletions.
16 changes: 3 additions & 13 deletions indyscan-daemon/src/transformers/expansion/domain/nym-attrib.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,6 @@ function roleIdToRoleAction (id) {
return ROLE_ACTIONS[id.trim()] || UNKNOWN_ROLE_ACTION
}

function validURL(str) { // https://stackoverflow.com/a/5717133
var pattern = new RegExp('^(https?:\\/\\/)?'+ // protocol
'((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|'+ // domain name
'((\\d{1,3}\\.){3}\\d{1,3}))'+ // OR ip (v4) address
'(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*'+ // port and path
'(\\?[;&a-z\\d%_.~+=-]*)?'+ // query string
'(\\#[-a-z\\d_]*)?$','i'); // fragment locator
return !!pattern.test(str);
}

function tryParseRawData (rawData) {
let parsed
let endpoint
Expand All @@ -38,7 +28,7 @@ function tryParseRawData (rawData) {
if (parsed.endpoint.endpoint) {
if (parsed.endpoint.endpoint.endpoint) { // fix for bad txn
endpoint = parsed.endpoint.endpoint.endpoint
}
}
else {
endpoint = parsed.endpoint.endpoint
}
Expand All @@ -58,8 +48,8 @@ function tryParseRawData (rawData) {
if (parsed.last_updated) {
lastUpdated = parsed.last_updated
}
} catch (err) {}
if (!validURL(endpoint)){
} catch (err) { }
if (typeof endpoint !== 'string'){
endpoint = undefined // sanitize input
}
return { endpoint, lastUpdated }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const txAttribRoleSteward = require('indyscan-storage/test/resource/sample-txs/t
const txAttribRoleNetworkMonitor = require('indyscan-storage/test/resource/sample-txs/tx-domain-attrib-role-network-monitor')
const txAttribRoleEndorser = require('indyscan-storage/test/resource/sample-txs/tx-domain-attrib-role-endorser')
const txAttribRoleTrustee = require('indyscan-storage/test/resource/sample-txs/tx-domain-attrib-role-trustee')
const txAttribBuildernet55175 = require('indyscan-storage/test/resource/sample-txs/tx-domain-attrib-endpoint-buildernet-55175.json')
const txAttribRoleRemove = require('indyscan-storage/test/resource/sample-txs/tx-domain-attrib-role-remove')
const txAttribRoleUnrecognized = require('indyscan-storage/test/resource/sample-txs/tx-domain-attrib-role-unrecognized')
const txAttribRoleRemoveWithSpace = require('indyscan-storage/test/resource/sample-txs/tx-domain-attrib-role-remove-with-spaces')
Expand Down Expand Up @@ -37,6 +38,13 @@ describe('domain/attrib transaction transformations', () => {
expect(processedTx.txn.data.roleAction).toBe('SET_STEWARD')
})

it('should process ATTRIB transaction with endpoint (sovrin buildernet tx 55175)', async () => {
const tx = _.cloneDeep(txAttribBuildernet55175)
const { processedTx } = await processor.processTx(tx, 'DOMAIN')
expect(JSON.stringify(tx)).toBe(JSON.stringify(txAttribBuildernet55175))
expect(processedTx.txn.data.endpoint).toBe('http://localhost:8000/')
})

it('should process ATTRIB transaction with SET_NETWORK_MONITOR role', async () => {
const tx = _.cloneDeep(txAttribRoleNetworkMonitor)
const { processedTx } = await processor.processTx(tx, 'DOMAIN')
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"auditPath": [
"5Q1wj1D8TZhRAjDKobezLFEvJJCNEUE88aSRjAHPc62H",
"8U1Pw3dz2cCYLFJ6kW3jjPQ3dS3RkPV6VByrdXEPYjnj",
"BBkdmQxAMvdFPqPoAB9tzkxufzMbHkRAbkggUg2mfhaJ",
"9CtmYsKB4rLDDPSH7keZpwUAvPU9T3CTq8CVfs7ssqEA",
"HwvnHTCqaZeZeg4tgt33TJd5vWK3A3u7ed5FGtxfJ85R",
"GMjz4Ln1iUinEZSyYWXHGGQFbi1WzdKnA5T4bavmWak9",
"8MwjdEetR7UonGMak2u6upmKFBUAZzsiUm3BQdaVb6Da",
"DoibS3EaSp5RM4ThA4sX2ZW3k49CheMC2AWp1ewiKdVy",
"DsA2vn5WqfL4ZJqzwVtW3YzkQ1imYrgG8S2UfQfXtV2E"
],
"ledgerSize": 55175,
"reqSignature": {
"type": "ED25519",
"values": [
{
"from": "JEMWktUsL4YVuDgcPeTf9",
"value": "3crGVsSS3CQmpXGunTeyx8VHYdoFHmz12zgx35NXeusKQ8cNMLy9nfTyQ4ugVLEoydkzQ6c3nhB8anCdu7Vipz5t"
}
]
},
"rootHash": "Guwn2dgaeYfyeuUNA5upM5B87Y5FbPfrrWdwVYvqh84x",
"txn": {
"data": {
"dest": "JEMWktUsL4YVuDgcPeTf9",
"raw": "{\"endpoint\":{\"endpoint\":{\"endpoint\":\"http://localhost:8000/\",\"routingKeys\":[]}}}"
},
"metadata": {
"digest": "599fb98cb08014d56ed50b26dd4586fec4dd05829a6d1784b670851efe54fa31",
"from": "JEMWktUsL4YVuDgcPeTf9",
"payloadDigest": "15c97bcda96f97898c90ec031a25b5aa4057bd512571e3571ec19a9bc9358287",
"reqId": 1662491513671581200,
"taaAcceptance": {
"mechanism": "wallet_agreement",
"taaDigest": "8cee5d7a573e4893b08ff53a0761a22a1607df3b3fcd7e75b98696c92879641f",
"time": 1662422400
}
},
"protocolVersion": 2,
"type": "100"
},
"txnMetadata": {
"seqNo": 55175,
"txnId": "JEMWktUsL4YVuDgcPeTf9:1:b6bf7bc8d96f3ea9d132c83b3da8e7760e420138485657372db4d6a981d3fd9e",
"txnTime": 1662491517
},
"ver": "1"
}

0 comments on commit dceb941

Please sign in to comment.