Skip to content

Commit

Permalink
FAB-10497 NodeSDK blockToLive error
Browse files Browse the repository at this point in the history
Fix the validation of the value.

Change-Id: Iaeaf1c5201623e29cb31854505f4ba6b0178826a
Signed-off-by: Bret Harrison <[email protected]>
  • Loading branch information
harrisob committed May 31, 2018
1 parent 13e3f51 commit acce409
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
13 changes: 11 additions & 2 deletions fabric-client/lib/SideDB.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,18 @@ function checkCollectionConfig(collectionConfig) {
if (!Number.isInteger(requiredPeerCount)) {
throw new Error(format('CollectionConfig Requires Param "requiredPeerCount" of type number, found %j(type: %s)', requiredPeerCount, typeof requiredPeerCount));
}
if (blockToLive == null || Number.isNaN(Number.parseInt(blockToLive)) ||
Long.fromValue(blockToLive, true).isNegative() || Long.fromValue(blockToLive, true) > Long.MAX_UNSIGNED_VALUE) {

if (blockToLive == null ||
Number.isNaN(Number.parseInt(blockToLive)) ||
Long.fromValue(blockToLive, true).isNegative()) {
throw new Error(format('CollectionConfig Requires Param "blockToLive" of type unsigned int64, found %j(type: %s)', blockToLive, typeof blockToLive));
} else {
const test = Long.fromValue(blockToLive, true);
logger.debug('checkCollectionConfig blockToLive parse from %j and parsed to %s)', blockToLive, test);

if(test.toString() !== blockToLive.toString()) {
throw new Error(format('CollectionConfig Requires Param "blockToLive" to be a valid unsigned int64, input is %j and parsed to %s)', blockToLive, test));
}
}
}

Expand Down
15 changes: 14 additions & 1 deletion test/unit/sidedb.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,20 @@ test('Test SideDB.checkCollectionConfig()', async (t) => {
t.throws(()=>{
checkCollectionConfig(config);
},
/CollectionConfig Requires Param "blockToLive" of type unsigned int64, found "28446744073709551615"\(type: string\)/,
/CollectionConfig Requires Param "blockToLive" to be a valid unsigned int64/,
'collectionConfig without valid blockToLive should throw error');

config = {
name: 'test',
policy: policy,
maxPeerCount: 123,
requiredPeerCount: 100,
blockToLive: 18446744073709551615
};
t.throws(()=>{
checkCollectionConfig(config);
},
/CollectionConfig Requires Param "blockToLive" to be a valid unsigned int64/,
'collectionConfig without valid blockToLive should throw error');

config = {
Expand Down

0 comments on commit acce409

Please sign in to comment.