it('should successfully parse encoded info', async () => { await request(getSample().app) .get('/auth/info/googlejwt') .set( 'X-Endpoint-API-UserInfo', Buffer.from(JSON.stringify({id: 'foo'})).toString('base64') ) .expect(200) .expect(response => { assert.deepStrictEqual(response.body, {id: 'foo'}); }); });
it(`stopInstancePubSub: should fail with missing 'label' attribute`, () => { const mocks = getMocks(); const sample = getSample(); const pubsubData = {zone: 'test-zone'}; mocks.event.data = Buffer.from(JSON.stringify(pubsubData)).toString('base64'); sample.program.stopInstancePubSub(mocks.event, mocks.context, mocks.callback); assert.deepStrictEqual( mocks.callback.firstCall.args[0], new Error(`Attribute 'label' missing from payload`) ); });
// [END gae_flex_pubsub_index] // [START gae_flex_pubsub_push] app.post('/pubsub/push', jsonBodyParser, (req, res) => { if (req.query.token !== PUBSUB_VERIFICATION_TOKEN) { res.status(400).send(); return; } // The message is a unicode string encoded in base64. const message = Buffer.from(req.body.message.data, 'base64').toString( 'utf-8' ); messages.push(message); res.status(200).send(); });
it('should return an unaltered buffer if there is less than a packets worth of data in it', () => { let expectedString = 'AJ'; let buffer = new Buffer(expectedString); // Reset the spy if it exists if (_processQualifiedPacketSpy) _processQualifiedPacketSpy.reset(); // Test the function buffer = ourBoard._processDataBuffer(buffer); // Convert the buffer to a string and ensure that it equals the expected string buffer.toString().should.equal(expectedString); // Make sure that the spy was not infact called. _processQualifiedPacketSpy.should.not.have.been.called(); });
it(`should successfully parse encoded info`, async () => { const sample = getSample(); await request(sample.app) .get('/auth/info/googlejwt') .set( 'X-Endpoint-API-UserInfo', Buffer.from(JSON.stringify({id: 'foo'})).toString('base64') ) .expect(200) .expect(response => { assert.deepStrictEqual(response.body, {id: 'foo'}); }); });
/** Tests for startInstancePubSub */ it('startInstancePubSub: should accept JSON-formatted event payload with label', async () => { const mocks = getMocks(); const sample = getSample(); const pubsubData = {zone: 'test-zone', label: 'testkey=value'}; mocks.event.data = Buffer.from(JSON.stringify(pubsubData)).toString('base64'); sample.program.startInstancePubSub( mocks.event, mocks.context, mocks.callback ); const data = await sample.mocks.requestPromise(); // The request was successfully sent. assert.strictEqual(data, 'request sent'); });
/** Tests for stopInstancePubSub */ it('startInstancePubSub: should accept JSON-formatted event payload with label', async () => { const mocks = getMocks(); const sample = getSample(); const pubsubData = {zone: 'test-zone', label: 'testkey=value'}; mocks.event.data = Buffer.from(JSON.stringify(pubsubData)).toString('base64'); sample.program.stopInstancePubSub(mocks.event, mocks.context, mocks.callback); const data = await sample.mocks.requestPromise(); // The request was successfully sent. assert.strictEqual(data, 'request sent'); });
it('should successfully parse encoded info', async () => { await request(getSample().app) .get('/auth/info/googlejwt') .set( 'X-Endpoint-API-UserInfo', Buffer.from(JSON.stringify({id: 'foo'})).toString('base64') ) .expect(200) .expect(response => { assert.deepStrictEqual(response.body, {id: 'foo'}); }); });
it(`stopInstancePubSub: should fail with missing 'label' attribute`, () => { const mocks = getMocks(); const sample = getSample(); const pubsubData = {zone: 'test-zone'}; mocks.event.data = Buffer.from(JSON.stringify(pubsubData)).toString('base64'); sample.program.stopInstancePubSub(mocks.event, mocks.context, mocks.callback); assert.deepStrictEqual( mocks.callback.firstCall.args[0], new Error(`Attribute 'label' missing from payload`) ); });
/** Tests for stopInstancePubSub */ it('startInstancePubSub: should accept JSON-formatted event payload with label', async () => { const mocks = getMocks(); const sample = getSample(); const pubsubData = {zone: 'test-zone', label: 'testkey=value'}; mocks.event.data = Buffer.from(JSON.stringify(pubsubData)).toString('base64'); sample.program.stopInstancePubSub(mocks.event, mocks.context, mocks.callback); const data = await sample.mocks.requestPromise(); // The request was successfully sent. assert.strictEqual(data, 'request sent'); });
it('stopInstancePubSub: should fail with empty event payload', () => { const mocks = getMocks(); const sample = getSample(); const pubsubData = {}; mocks.event.data = Buffer.from(JSON.stringify(pubsubData)).toString('base64'); sample.program.stopInstancePubSub(mocks.event, mocks.context, mocks.callback); assert.deepStrictEqual( mocks.callback.firstCall.args[0], new Error(`Attribute 'zone' missing from payload`) ); });
it(`stopInstancePubSub: should fail with missing 'zone' attribute`, () => { const mocks = getMocks(); const sample = getSample(); const pubsubData = {label: 'testkey=value'}; mocks.event.data = Buffer.from(JSON.stringify(pubsubData)).toString('base64'); sample.program.stopInstancePubSub(mocks.event, mocks.context, mocks.callback); assert.deepStrictEqual( mocks.callback.firstCall.args[0], new Error(`Attribute 'zone' missing from payload`) ); });
it(`stopInstancePubSub: should fail with missing 'zone' attribute`, () => { const mocks = getMocks(); const sample = getSample(); const pubsubData = {label: 'testkey=value'}; mocks.event.data = Buffer.from(JSON.stringify(pubsubData)).toString('base64'); sample.program.stopInstancePubSub(mocks.event, mocks.context, mocks.callback); assert.deepStrictEqual( mocks.callback.firstCall.args[0], new Error(`Attribute 'zone' missing from payload`) ); });
it('stopInstancePubSub: should fail with empty event payload', () => { const mocks = getMocks(); const sample = getSample(); const pubsubData = {}; mocks.event.data = Buffer.from(JSON.stringify(pubsubData)).toString('base64'); sample.program.stopInstancePubSub(mocks.event, mocks.context, mocks.callback); assert.deepStrictEqual( mocks.callback.firstCall.args[0], new Error(`Attribute 'zone' missing from payload`) ); });
it(`should successfully parse encoded info`, async () => { const sample = getSample(); await request(sample.app) .get('/auth/info/googlejwt') .set( 'X-Endpoint-API-UserInfo', Buffer.from(JSON.stringify({id: 'foo'})).toString('base64') ) .expect(200) .expect(response => { assert.deepStrictEqual(response.body, {id: 'foo'}); }); });