Skip to content

Commit

Permalink
test: node rpc validateresource
Browse files Browse the repository at this point in the history
Test the success cases and the failure cases.
  • Loading branch information
tynes committed Apr 16, 2020
1 parent de9d018 commit 39df65f
Showing 1 changed file with 84 additions and 0 deletions.
84 changes: 84 additions & 0 deletions test/node-rpc-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,5 +130,89 @@ describe('RPC', function() {
const info = await nclient.execute('getblock', [hash]);
assert.deepEqual(info.confirmations, -1);
});

it('should validateresource (valid)', async () => {
const records = [
[{type: 'NS', ns: 'ns1.handshake.org.'}],
[{type: 'DS', keyTag: 0xffff, algorithm: 0xff, digestType: 0xff, digest: '00'.repeat(32)}],
[{type: 'TXT', txt: ['i like turtles', 'then who phone']}],
[{type: 'GLUE4', ns: 'ns1.nam.ek.', address: '192.168.0.1'}],
[{type: 'GLUE6', ns: 'ns2.nam.ek.', address: '::'}],
[{type: 'SYNTH4', address: '192.168.0.1'}],
[{type: 'SYNTH6', address: '::'}]
];

for (const record of records) {
const data = {records: record};
const info = await nclient.execute('validateresource', [data]);
assert.deepEqual(info, data);
}
});

it('should validateresource (invalid)', async () => {
const records = [
// No trailing dot
[[{type: 'NS', ns: 'ns1.handshake.org'}], 'Invalid NS record. Property "ns" must be a valid name.'],
[[{type: 'DS', keyTag: 0xffffff}], 'Invalid DS record. Property "keyTag" must be a u16.'],
[
[{type: 'DS', keyTag: 0xffff, algorithm: 0xffff}],
'Invalid DS record. Property "algorithm" must be a u8.'
],
[
[{type: 'DS', keyTag: 0xffff, algorithm: 0xff, digestType: 0xffff}],
'Invalid DS record. Property "digestType" must be a u8.'
],
[
[{type: 'DS', keyTag: 0xffff, algorithm: 0xff, digestType: 0xff, digest: Buffer.alloc(0)}],
'Invalid DS record. Property "digest" must be a String.'
],
[
[{type: 'DS', keyTag: 0xffff, algorithm: 0xff, digestType: 0xff, digest: '00'.repeat(256)}],
'Invalid DS record. Property "digest" is too large.'
],
[
[{type: 'TXT', txt: 'foobar'}],
'Invalid TXT record. Property "txt" must be an Array.'
],
[
[{type: 'TXT', txt: ['0'.repeat(256)]}],
'Invalid TXT record. Entries in "txt" Array must be <= 255 in length.'
],
[
[{type: 'GLUE4', ns: 'ns1.nam.ek', address: '192.168.0.1'}],
'Invalid GLUE4 record. Property "ns" must be a valid name.'
],
[
[{type: 'GLUE4', ns: 'ns1.nam.ek.', address: '::'}],
'Invalid GLUE4 record. Property "address" must be a IPv4 address.'
],
[
[{type: 'GLUE6', ns: 'ns1.nam.ek', address: '::'}],
'Invalid GLUE6 record. Property "ns" must be a valid name.'
],
[
[{type: 'GLUE6', ns: 'ns1.nam.ek.', address: '0.0.0.0'}],
'Invalid GLUE6 record. Property "address" must be a IPv6 address.'
],
[
[{type: 'SYNTH4', address: '::'}],
'Invalid SYNTH4 record. Property "address" must be a IPv4 address.'
],
[
[{type: 'SYNTH6', address: '127.0.0.1'}],
'Invalid SYNTH6 record. Property "address" must be a IPv6 address.'
]
];

for (const [record, reason] of records) {
try {
const data = {records: record};
await nclient.execute('validateresource', [data]);
assert.fail();
} catch (e) {
assert.equal(e.message, reason);
}
}
});
});
});

0 comments on commit 39df65f

Please sign in to comment.