app.get('/app_locals_oom', function*() { for (let i = 0; i < 1000; i++) { app.locals = { // 10MB buff: Buffer.alloc(10 * 1024 * 1024).toString() }; } this.body = 'ok'; });
it('should log CookieLimitExceed error when cookie value too long', done => { const ctx = app.mockContext(); const value = Buffer.alloc(4094).fill(49).toString(); ctx.cookies.set('foo', value); setTimeout(() => { const logPath = path.join(utils.getFilepath('apps/secure-app'), 'logs/secure-app/common-error.log'); const content = fs.readFileSync(logPath, 'utf8'); assert(content.match(/CookieLimitExceedError: cookie foo's length\(4094\) exceed the limit\(4093\)/)); done(); }, 100); });
function convertTimestampToBigEndian(timestamp) { const buffer = Buffer.alloc(8); const high = ~~(timestamp / 0xffffffff); const low = timestamp % (0xffffffff + 0x1); buffer.writeUInt32BE(parseInt(high, 10), 0); buffer.writeUInt32BE(parseInt(low, 10), 4); return buffer; }
ensureAvailable(length) { if (this.offset + length > this.buf.length) { const newLength = Encoder.nextPowerOfTwo(this.offset + length) const newBuffer = Buffer.alloc(newLength) this.buf.copy(newBuffer, 0, 0, this.offset) this.buf = newBuffer } }
it("should throw error if packet is too large", () => { let cb = jest.fn(); let buf = Buffer.alloc(513, "0"); parser._write(buf, null, cb); expect(cb).toHaveBeenCalledTimes(1); expect(cb).toHaveBeenCalledWith(jasmine.any(Error)); let err = cb.mock.calls[0][0]; expect(err.message).toBe("Incoming packet is larger than the 'maxPacketSize' limit (513 > 512)!"); expect(parser.buf).toBeNull(); });
static sendSaslMessage(status, payload, callback) { const saslTransport = new thrift.TBufferedTransport(null, callback); const messageHeader = Buffer.alloc(5); messageHeader.writeInt8(status); messageHeader.writeUInt32BE(payload.length, 1); saslTransport.write(messageHeader); saslTransport.write(payload); saslTransport.flush(); }
const sendFrame = (data, seqId, writeCallback) => { const frameBuffer = Buffer.alloc(4 + data.length); frameBuffer.writeUInt32BE(data.length, 0); data.copy(frameBuffer, 4, 0, data.length); writeCallback(frameBuffer, seqId); }
it("should concat previous chunk and throw CRC error", () => { let cb = jest.fn(); // Preload buffer parser.buf = Buffer.alloc(5, "0"); let buf = Buffer.alloc(5, "1"); parser._write(buf, null, cb); expect(cb).toHaveBeenCalledTimes(1); expect(cb).toHaveBeenCalledWith(jasmine.any(Error)); let err = cb.mock.calls[0][0]; expect(err.message).toBe("Invalid packet CRC! 49"); expect(parser.buf).toBeNull(); });
/** * @param {Object} metadata * @param {number} metadata.version * @param {Array<string>} metadata.topics * @param {Buffer} [metadata.userData=Buffer.alloc(0)] * * @returns Buffer */ encode({ version, topics, userData = Buffer.alloc(0) }) { return new Encoder() .writeInt16(version) .writeArray(topics) .writeBytes(userData).buffer }
const encodeGroupProtocols = ({ name, metadata = Buffer.alloc(0) }) => { return new Encoder().writeString(name).writeBytes(metadata) }
/** * Construct a new encoder with the given initial size * * @param {number} [initialSize] initial size */ constructor(initialSize = 511) { this.buf = Buffer.alloc(Encoder.nextPowerOfTwo(initialSize)) this.offset = 0 }
it("should store chunk in buffer if length is smaller than 6 bytes", () => { let cb = jest.fn(); let buf = Buffer.alloc(5, "0"); parser._write(buf, null, cb); expect(cb).toHaveBeenCalledTimes(1); expect(cb).toHaveBeenCalledWith(); expect(parser.buf).toBeInstanceOf(Buffer); expect(parser.buf.toString()).toBe("00000"); });
constructor() { this.buffer = Buffer.alloc(0); }
function convertTimestampToBigEndian(timestamp) { const buffer = Buffer.alloc(8); const high = ~~(timestamp / 0xffffffff); const low = timestamp % (0xffffffff + 0x1); buffer.writeUInt32BE(parseInt(high, 10), 0); buffer.writeUInt32BE(parseInt(low, 10), 4); return buffer; }
const encodeGroupProtocols = ({ name, metadata = Buffer.alloc(0) }) => { return new Encoder().writeString(name).writeBytes(metadata) }