Skip to content
This repository was archived by the owner on Apr 3, 2024. It is now read-only.

Commit 14fee82

Browse files
authored
improve message for allowExpressions=false (#270)
1 parent e2af535 commit 14fee82

File tree

2 files changed

+39
-36
lines changed

2 files changed

+39
-36
lines changed

src/agent/debuglet.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ var pjson = require('../../package.json');
3939
var assert = require('assert');
4040

4141
var ALLOW_EXPRESSIONS_MESSAGE = 'Expressions and conditions are not allowed' +
42-
' by default. Please set the allowExpressions configuration option to true';
42+
' by default. Please set the allowExpressions configuration option to true.' +
43+
' See the debug agent documentation at https://goo.gl/ShSm6r.';
4344
var NODE_VERSION_MESSAGE = 'Node.js version not supported. Node.js 5.2.0 and ' +
4445
' versions older than 0.12 are not supported.';
4546
var BREAKPOINT_ACTION_MESSAGE = 'The only currently supported breakpoint actions' +
@@ -285,7 +286,7 @@ Debuglet.createDebuggee =
285286
if (!description && process.env.FUNCTION_NAME) {
286287
description = 'Function: ' + process.env.FUNCTION_NAME;
287288
}
288-
289+
289290
if (description) {
290291
desc += ' description:' + description;
291292
}

test/test-debuglet.js

Lines changed: 36 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ var DEBUGGEE_ID = 'bar';
3131
var API = 'https://clouddebugger.googleapis.com';
3232
var REGISTER_PATH = '/v2/controller/debuggees/register';
3333
var BPS_PATH = '/v2/controller/debuggees/' + DEBUGGEE_ID + '/breakpoints';
34+
var EXPRESSIONS_REGEX =
35+
/Expressions and conditions are not allowed.*https:\/\/goo\.gl\/ShSm6r/;
3436

3537
var fakeCredentials = require('./fixtures/gcloud-credentials.json');
3638

@@ -53,6 +55,12 @@ var errorBp = {
5355
location: {path: 'fixtures/foo.js', line: 2}
5456
};
5557

58+
function verifyBreakpointRejection(re, body) {
59+
var status = body.breakpoint.status;
60+
var hasCorrectDescription = status.description.format.match(re);
61+
return status.isError && hasCorrectDescription;
62+
}
63+
5664
describe('Debuglet', function() {
5765
describe('setup', function() {
5866
before(function() { oldGP = process.env.GCLOUD_PROJECT; });
@@ -529,23 +537,20 @@ describe('Debuglet', function() {
529537
debuglet.config_.allowExpressions = false;
530538

531539
var scope = nock(API)
532-
.post(REGISTER_PATH)
533-
.reply(200, {debuggee: {id: DEBUGGEE_ID}})
534-
.get(BPS_PATH + '?success_on_timeout=true')
535-
.reply(200, {breakpoints: [{
536-
id: 'test',
537-
action: 'CAPTURE',
538-
condition: 'x === 5',
539-
location: {path: 'fixtures/foo.js', line: 2}
540-
}]})
541-
.put(BPS_PATH + '/test',
542-
function(body) {
543-
var status = body.breakpoint.status;
544-
var hasCorrectDescription = status.description.format.indexOf(
545-
'Expressions and conditions are not allowed by default.') === 0;
546-
return status.isError && hasCorrectDescription;
547-
})
548-
.reply(200);
540+
.post(REGISTER_PATH)
541+
.reply(200, { debuggee: { id: DEBUGGEE_ID } })
542+
.get(BPS_PATH + '?success_on_timeout=true')
543+
.reply(200, {
544+
breakpoints: [{
545+
id: 'test',
546+
action: 'CAPTURE',
547+
condition: 'x === 5',
548+
location: { path: 'fixtures/foo.js', line: 2 }
549+
}]
550+
})
551+
.put(BPS_PATH + '/test',
552+
verifyBreakpointRejection.bind(null, EXPRESSIONS_REGEX))
553+
.reply(200);
549554

550555
debuglet.once('registered', function reg(id) {
551556
assert.equal(id, DEBUGGEE_ID);
@@ -570,23 +575,20 @@ describe('Debuglet', function() {
570575
debuglet.config_.allowExpressions = false;
571576

572577
var scope = nock(API)
573-
.post(REGISTER_PATH)
574-
.reply(200, {debuggee: {id: DEBUGGEE_ID}})
575-
.get(BPS_PATH + '?success_on_timeout=true')
576-
.reply(200, {breakpoints: [{
577-
id: 'test',
578-
action: 'CAPTURE',
579-
expressions: ['x'],
580-
location: {path: 'fixtures/foo.js', line: 2}
581-
}]})
582-
.put(BPS_PATH + '/test',
583-
function(body) {
584-
var status = body.breakpoint.status;
585-
var hasCorrectDescription = status.description.format.indexOf(
586-
'Expressions and conditions are not allowed by default.') === 0;
587-
return status.isError && hasCorrectDescription;
588-
})
589-
.reply(200);
578+
.post(REGISTER_PATH)
579+
.reply(200, { debuggee: { id: DEBUGGEE_ID } })
580+
.get(BPS_PATH + '?success_on_timeout=true')
581+
.reply(200, {
582+
breakpoints: [{
583+
id: 'test',
584+
action: 'CAPTURE',
585+
expressions: ['x'],
586+
location: { path: 'fixtures/foo.js', line: 2 }
587+
}]
588+
})
589+
.put(BPS_PATH + '/test',
590+
verifyBreakpointRejection.bind(null, EXPRESSIONS_REGEX))
591+
.reply(200);
590592

591593
debuglet.once('registered', function reg(id) {
592594
assert.equal(id, DEBUGGEE_ID);

0 commit comments

Comments
 (0)