|
18 | 18 | var _ = require('lodash'); |
19 | 19 | var assert = require('assert'); |
20 | 20 | var DEFAULT_CONFIG = require('../src/agent/config.js'); |
| 21 | +DEFAULT_CONFIG.allowExpressions = true; |
21 | 22 | var Debuglet = require('../src/agent/debuglet.js'); |
22 | 23 | var extend = require('extend'); |
23 | 24 |
|
@@ -526,6 +527,88 @@ describe('Debuglet', function() { |
526 | 527 | debuglet.start(); |
527 | 528 | }); |
528 | 529 |
|
| 530 | + it('should reject breakpoints with conditions when allowExpressions=false', |
| 531 | + function(done) { |
| 532 | + this.timeout(2000); |
| 533 | + var debug = require('../src/debug.js')( |
| 534 | + {projectId: 'fake-project', credentials: fakeCredentials}); |
| 535 | + var debuglet = new Debuglet(debug, defaultConfig); |
| 536 | + debuglet.config_.allowExpressions = false; |
| 537 | + |
| 538 | + var scope = nock(API) |
| 539 | + .post(REGISTER_PATH) |
| 540 | + .reply(200, {debuggee: {id: DEBUGGEE_ID}}) |
| 541 | + .get(BPS_PATH + '?success_on_timeout=true') |
| 542 | + .reply(200, {breakpoints: [{ |
| 543 | + id: 'test', |
| 544 | + action: 'CAPTURE', |
| 545 | + condition: 'x === 5', |
| 546 | + location: {path: 'fixtures/foo.js', line: 2} |
| 547 | + }]}) |
| 548 | + .put(BPS_PATH + '/test', |
| 549 | + function(body) { |
| 550 | + var status = body.breakpoint.status; |
| 551 | + var hasCorrectDescription = status.description.format.indexOf( |
| 552 | + 'Expressions and conditions are not allowed by default.') === 0; |
| 553 | + return status.isError && hasCorrectDescription; |
| 554 | + }) |
| 555 | + .reply(200); |
| 556 | + |
| 557 | + debuglet.once('registered', function reg(id) { |
| 558 | + assert.equal(id, DEBUGGEE_ID); |
| 559 | + setTimeout(function() { |
| 560 | + assert.ok(!debuglet.activeBreakpointMap_.test); |
| 561 | + debuglet.stop(); |
| 562 | + debuglet.config_.allowExpressions = true; |
| 563 | + scope.done(); |
| 564 | + done(); |
| 565 | + }, 1000); |
| 566 | + }); |
| 567 | + |
| 568 | + debuglet.start(); |
| 569 | + }); |
| 570 | + |
| 571 | + it('should reject breakpoints with expressions when allowExpressions=false', |
| 572 | + function(done) { |
| 573 | + this.timeout(2000); |
| 574 | + var debug = require('../src/debug.js')( |
| 575 | + {projectId: 'fake-project', credentials: fakeCredentials}); |
| 576 | + var debuglet = new Debuglet(debug, defaultConfig); |
| 577 | + debuglet.config_.allowExpressions = false; |
| 578 | + |
| 579 | + var scope = nock(API) |
| 580 | + .post(REGISTER_PATH) |
| 581 | + .reply(200, {debuggee: {id: DEBUGGEE_ID}}) |
| 582 | + .get(BPS_PATH + '?success_on_timeout=true') |
| 583 | + .reply(200, {breakpoints: [{ |
| 584 | + id: 'test', |
| 585 | + action: 'CAPTURE', |
| 586 | + expressions: ['x'], |
| 587 | + location: {path: 'fixtures/foo.js', line: 2} |
| 588 | + }]}) |
| 589 | + .put(BPS_PATH + '/test', |
| 590 | + function(body) { |
| 591 | + var status = body.breakpoint.status; |
| 592 | + var hasCorrectDescription = status.description.format.indexOf( |
| 593 | + 'Expressions and conditions are not allowed by default.') === 0; |
| 594 | + return status.isError && hasCorrectDescription; |
| 595 | + }) |
| 596 | + .reply(200); |
| 597 | + |
| 598 | + debuglet.once('registered', function reg(id) { |
| 599 | + assert.equal(id, DEBUGGEE_ID); |
| 600 | + setTimeout(function() { |
| 601 | + assert.ok(!debuglet.activeBreakpointMap_.test); |
| 602 | + debuglet.stop(); |
| 603 | + debuglet.config_.allowExpressions = true; |
| 604 | + scope.done(); |
| 605 | + done(); |
| 606 | + }, 1000); |
| 607 | + }); |
| 608 | + |
| 609 | + debuglet.start(); |
| 610 | + }); |
| 611 | + |
529 | 612 | it('should re-fetch breakpoints on error', function(done) { |
530 | 613 | this.timeout(6000); |
531 | 614 |
|
|
0 commit comments