Commit 8ae78dc4 authored by Antonin Coulibaly's avatar Antonin Coulibaly Committed by Antonin Coulibaly
Browse files

FIX(protocol): make the tag optionnal for the put

    * Update associated tests
parent 8cedc026
Loading
Loading
Loading
Loading
+12 −7
Original line number Diff line number Diff line
@@ -894,7 +894,6 @@ class PutPDU extends PDU {
                                    InitPDU
 * @param {Buffer} keyArg - key of the item to put.
 * @param {number} chunkSize - size of the chunk to put.
 * @param {Buffer} tagArg - the hash of the value to put.
 * @param {Object} optionsArg - optional :
 *                  {String} [options.synchronization = WRITEBACK] - to
 *                  specify if the data must be written to disk immediately,
@@ -903,21 +902,27 @@ class PutPDU extends PDU {
 *                  true ignores potential version mismatches and carries out
 *                  the operation.
 *                  {string} [options.algorithm] - algorithm used for the tag
 *                  {Buffer} dbVersion - version of the item in the database
 *                  {Buffer} newVersion - new version of the item to put
 *                  {Buffer} [options.dbVersion] - version of the item in the
 *                                                 database
 *                  {Buffer} [options.newVersion] - new version of the item to
 *                                                  put
 *                  {Buffer} [options.tag] - the hash of the value to put.
 * @returns {Kinetic} - message structure following the kinetic protocol
 */
    constructor(sequence, connectionID, clusterVersion, keyArg, chunkSize,
                tagArg, optionsArg) {
                optionsArg) {
        super();

        const options = optionsArg || {};

        let dbVersion = null;
        let newVersion = null;
        let tag = null;

        const key = validateBufferOrStringArgument(keyArg);
        const tag = validateVersionArgument(tagArg);

        if (options.tag)
            tag = validateVersionArgument(options.tag);
        if (options.dbVersion)
            dbVersion = validateVersionArgument(options.dbVersion);
        if (options.newVersion)
@@ -941,8 +946,8 @@ class PutPDU extends PDU {
                    force: typeof options.force === "boolean" ?
                        options.force : null,
                    tag,
                    algorithm: validateAlgo(options.algorithm) ||
                        algorithms.SHA1,
                    algorithm: tag ? validateAlgo(options.algorithm) ||
                        algorithms.SHA1 : null,
                },
            },
        });
+2 −3
Original line number Diff line number Diff line
@@ -49,7 +49,6 @@ const requestsArr = [

function requestsLauncher(request, client, optionsA) {
    let pdu;
    let tag;

    const options = optionsA || {};

@@ -58,11 +57,11 @@ function requestsLauncher(request, client, optionsA) {
        pdu = new kinetic.NoOpPDU(sequence, connectionID, clusterVersion);
        break;
    case 'put':
        tag = crypto
        options.tag = crypto
            .createHmac('sha1', 'asdfasdf').update(chunk).digest();
        pdu = new kinetic.PutPDU(
            sequence, connectionID, clusterVersion, options.key || key,
            chunk.length, tag, options);
            chunk.length,  options);
        break;
    case 'get':
        pdu = new kinetic.GetPDU(
+15 −16
Original line number Diff line number Diff line
@@ -701,14 +701,13 @@ describe('kinetic.PDU encoding()', () => {
        const options = {
            dbVersion: Buffer.from('2', 'utf8'),
            newVersion: Buffer.from('3', 'utf8'),
            tag: crypto
                  .createHmac('sha1', 'asdfasdf').update(chunk).digest(),
        };

        const tag = crypto
                  .createHmac('sha1', 'asdfasdf').update(chunk).digest();

        const k = new kinetic.PutPDU(
            1, connectionID, clusterVersion,
            'string', chunk.length, tag, options);
            'string', chunk.length, options);

        const result = Buffer.concat([k.read(), chunk]);

@@ -731,14 +730,13 @@ describe('kinetic.PDU encoding()', () => {
            dbVersion: Buffer.from('2', 'utf8'),
            newVersion: Buffer.from('3', 'utf8'),
            force: true,
            tag: crypto
                  .createHmac('sha1', 'asdfasdf').update(chunk).digest(),
        };

        const tag = crypto
                  .createHmac('sha1', 'asdfasdf').update(chunk).digest();

        const k = new kinetic.PutPDU(
            1, connectionID, clusterVersion,
            'string', chunk.length, tag, options);
            'string', chunk.length, options);

        const result = Buffer.concat([k.read(), chunk]);

@@ -761,14 +759,13 @@ describe('kinetic.PDU encoding()', () => {
            dbVersion: Buffer.from('2', 'utf8'),
            newVersion: Buffer.from('3', 'utf8'),
            force: false,
            tag: crypto
                  .createHmac('sha1', 'asdfasdf').update(chunk).digest(),
        };

        const tag = crypto
                  .createHmac('sha1', 'asdfasdf').update(chunk).digest();

        const k = new kinetic.PutPDU(
            1, connectionID, clusterVersion,
            'string', chunk.length, tag, options);
            'string', chunk.length, options);

        const result = Buffer.concat([k.read(), chunk]);

@@ -1190,9 +1187,10 @@ describe('kinetic.PutPDU()', () => {
            const tag = crypto
                  .createHmac('sha1', 'asdfasdf').update('HelloWorld').digest();
            const k = new kinetic.PutPDU(
                1, connectionID, clusterVersion, "string", 12, tag,
                1, connectionID, clusterVersion, "string", 12,
                { dbVersion: { a: 1 },
                  newVersion: Buffer.from('3', 'utf8'),
                  tag,
                });
            k;
            done(new Error("constructor accepted object-typed key"));
@@ -1210,7 +1208,7 @@ describe('kinetic.PutPDU()', () => {
                  .createHmac('sha1', 'asdfasdf').update('HelloWorld').digest();
            const k = new kinetic.PutPDU(
                1, connectionID, clusterVersion,
                "string", 12, tag, { newVersion: 346 });
                "string", 12, { newVersion: 346, tag });
            k;
            done();
        } catch (e) {
@@ -1223,9 +1221,10 @@ describe('kinetic.PutPDU()', () => {
            const tag = crypto
                  .createHmac('sha1', 'asdfasdf').update('HelloWorld').digest();
            const k = new kinetic.PutPDU(
                1, connectionID, clusterVersion, 'string', 12, tag,
                1, connectionID, clusterVersion, 'string', 12,
                { dbVersion: Buffer.from('2', 'utf8'),
                  newVersion: { s: 'abc' }
                  newVersion: { s: 'abc' },
                  tag,
                });
            k;
            done(new Error("constructor accepted string-typed key"));