Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

test code,

removed debug verify logic.
  • Loading branch information...
commit 19441bb80fc69319357033eda297104fb542b0e0 1 parent ee641df
Bret Thaeler authored
View
4 lib/app/addons/ac/output-adapter.common.js
@@ -51,7 +51,9 @@ YUI.add('mojito-output-adapter-addon', function(Y, NAME) {
contentPath,
viewEngineOptions = (instance.appConfig && instance.appConfig.viewEngine) || {};
- adapter.debug.profClose("dispatch", instance.instanceId, 'done');
+ if (adapter.debug) {
+ adapter.debug.profClose("dispatch", instance.instanceId, 'done');
+ }
if (Y.Lang.isString(meta)) {
// If the meta string is a serializer set it
View
16 lib/app/autoload/debug-api.common.js
@@ -26,6 +26,14 @@ YUI.add('mojito-debug-api', function(Y, NAME) {
store.modules[flag] = {};
});
+ this.flag = function (flag) {
+ if (store.modules[flag]) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+
this.on = function (flag, f) {
if (store.modules[flag]) {
@@ -90,7 +98,7 @@ YUI.add('mojito-debug-api', function(Y, NAME) {
store.modules[flag].data = {};
}
if (!store.modules[flag].events) {
- store.modules[flag].events = []
+ store.modules[flag].events = [];
}
store.modules[flag].data[node] = {
@@ -129,7 +137,7 @@ YUI.add('mojito-debug-api', function(Y, NAME) {
}
if (!store.modules[flag].events) {
- return;
+ store.modules[flag].events = [];
}
store.modules[flag].events.push({
@@ -154,6 +162,10 @@ YUI.add('mojito-debug-api', function(Y, NAME) {
return this.Y.Object.keys(this.store.modules);
},
+ flag: function () {
+ return false;
+ },
+
get: function (key, value) {
return this.store.modules[key] || value;
},
View
12 lib/app/autoload/dispatch.common.js
@@ -81,7 +81,9 @@ YUI.add('mojito-dispatcher', function(Y, NAME) {
null;
if (cc) {
- adapter.debug.profOpen("dispatch", instance.instanceId, (instance.id || '@' + instance.type) + ':' + (command.action ? command.action : (instance.action || 'index')) + ":cached");
+ if (adapter.debug) {
+ adapter.debug.profOpen("dispatch", instance.instanceId, (instance.id || '@' + instance.type) + ':' + (command.action ? command.action : (instance.action || 'index')) + ":cached");
+ }
logger.log('using cached controller context: ' +
instance.instanceId, 'info', NAME);
cc.invoke(command, adapter);
@@ -122,7 +124,9 @@ YUI.add('mojito-dispatcher', function(Y, NAME) {
return;
}
- adapter.debug.profOpen("dispatch", instance.instanceId, (instance.id || '@' + instance.type) + ':' + command.action);
+ if (adapter.debug) {
+ adapter.debug.profOpen("dispatch", instance.instanceId, (instance.id || '@' + instance.type) + ':' + command.action);
+ }
logger.log('mojit instance expansion complete: ' +
instance.instanceId, 'mojito', 'qeperf');
@@ -192,7 +196,9 @@ YUI.add('mojito-dispatcher', function(Y, NAME) {
CACHE.controllerContexts[instance.instanceId] = cc;
}
- adapter.debug.profClose("dispatch", instance.instanceId, 'startup done');
+ if (adapter.debug) {
+ adapter.debug.profClose("dispatch", instance.instanceId, 'startup done');
+ }
cc.invoke(command, adapter);
});
View
76 lib/app/middleware/mojito-debug.js
@@ -25,17 +25,30 @@ Debug.prototype = {
queryParam = null,
debugPath = null,
debugMojit = null,
- appConfig = self._store.getAppConfig(null);
+ debugAllowed = null,
+ debugAllowHandler = null,
+ appConfig = self._store.getAppConfig(null),
+ s;
// see if debugger is turned on
if (appConfig.debug) {
queryParam = appConfig.debug.queryParam;
debugPath = appConfig.debug.debugPath;
debugMojit = appConfig.debug.debugMojit;
+ debugAllowed = appConfig.debug.debugAllowed;
+ if (debugAllowed) {
+ // debugAllowHandler = require(debugAllowed);
+ s = debugAllowed.split(/\./);
+ self.Y.applyConfig({ useSync: true });
+ debugAllowHandler = self.Y.use(s[0]).namespace(s[0])[s[1]];
+ self.Y.applyConfig({ useSync: false });
+ }
}
return function(req, res, next) {
- var debug = new self.Y.mojito.DebugAPI(self.Y, req, queryParam, self.microtime);
+ var debug = new self.Y.mojito.DebugAPI(self.Y, req, queryParam, self.microtime),
+ liburl,
+ call = [];
req.debug = debug;
@@ -51,46 +64,35 @@ Debug.prototype = {
console.warn("Request attempting to access debugger route directly");
} else if (req.url.match(new RegExp("^.*\?(.*&)?" + queryParam + "=.+$"))) {
- try {
- libynet = require('ynetdblib');
- } catch (e1) {
- console.error('ynetdblib is not available on this system');
+ // call application provided function to verify if this request shoudl be allowed or not
+ if (debugAllowHandler && !debugAllowHandler(req)) {
+ next();
+ return;
}
- try {
- // Determine if request comes from Yahoo's internal network.
- // If so, reroute to debug...
- if ((req.headers.yahooremoteip && libynet.isYahooInternalAddress(req.headers.yahooremoteip)) || libynet.isYahooInternalAddress(req.connection.remoteAddress)) {
- var liburl = require('url');
- var call = [];
- call[0] = debugMojit.split('.');
- call[1] = call[0].pop();
- call[0] = call[0].join('.');
+ liburl = require('url');
+ call[0] = debugMojit.split('.');
+ call[1] = call[0].pop();
+ call[0] = call[0].join('.');
- req.url = debugPath + req.url;
+ req.url = debugPath + req.url;
- req.command = {
- instance: {
- },
- action: call[1],
- context: req.context,
- params: {
- route: [],
- url: liburl.parse(req.url, true).query || {},
- body: req.body || {},
- file: {}
- }
- };
- if (call[0][0] === '@') {
- req.command.instance.type = call[0].slice(1);
- } else {
- req.command.instance.base = call[0];
- }
- } else {
- console.warn("Non internal address (" + (req.headers.yahooremoteip || req.connection.remoteAddress) + ") attempting to access debugger");
+ req.command = {
+ instance: {
+ },
+ action: call[1],
+ context: req.context,
+ params: {
+ route: [],
+ url: liburl.parse(req.url, true).query || {},
+ body: req.body || {},
+ file: {}
}
- } catch (e2) {
- console.error('Unable to verify if request address is internal: ' + e2.message);
+ };
+ if (call[0][0] === '@') {
+ req.command.instance.type = call[0].slice(1);
+ } else {
+ req.command.instance.base = call[0];
}
}
next();
View
85 lib/tests/autoload/app/autoload/debug-api-tests.common.js
@@ -29,11 +29,12 @@ YUI.add('mojito-debug-api-tests', function(Y, NAME) {
debug.profEvent("A", "event 1");
// AA.contains(debug.flags(), [], 'correct flags');
- A.areEqual(debug.flags().length, 0, 'no flags');
+ A.areEqual(0, debug.flags().length, 'no flags');
A.isUndefined(debug.get("bar"), "no bar data");
A.isUndefined(debug.get("log"), "no log data");
A.isUndefined(debug.get("log.My"), "no log.My data");
A.isUndefined(debug.get("prof.A"), "cno prof.A");
+ A.isFalse(debug.flag("bar"), "flag not set");
},
'debug on flags off': function() {
@@ -53,12 +54,13 @@ YUI.add('mojito-debug-api-tests', function(Y, NAME) {
debug.profClose("A", "b", "first close");
debug.profEvent("A", "event 1");
- AA.containsItems(debug.flags(), "help".split(/,/), 'correct flags');
+ AA.containsItems("help".split(/,/), debug.flags(), 'correct flags');
// A.areEqual(debug.flags().length, 0, 'no flags');
A.isUndefined(debug.get("bar"), "no bar data");
A.isUndefined(debug.get("log"), "no log data");
A.isUndefined(debug.get("log.My"), "no log.My data");
A.isUndefined(debug.get("prof.A"), "cno prof.A");
+ A.isFalse(debug.flag("bar"), "flag not set");
},
'debug interface on': function() {
@@ -78,26 +80,27 @@ YUI.add('mojito-debug-api-tests', function(Y, NAME) {
debug.profClose("A", "b", "first close");
debug.profEvent("A", "event 1");
- AA.containsItems(debug.flags(), "bar,log,log.My,prof.A".split(/,/), 'correct flags');
- A.areEqual(debug.get("bar").data, "abc", "correct bar data");
- A.areEqual(debug.get("log").data.length, 1, "correct log data count");
- OA.areEqual(debug.get("log").data[0], {content: "here", jsonTreeOptions: undefined}, "correct log data");
- A.areEqual(debug.get("log.My").data.length, 1, "correct log.My data count");
- OA.areEqual(debug.get("log.My").data[0], {content: "there", jsonTreeOptions: undefined}, "correct log.My data");
+ AA.containsItems("bar,log,log.My,prof.A".split(/,/), debug.flags(), 'correct flags');
+ A.areEqual("abc", debug.get("bar").data, "correct bar data");
+ A.areEqual(1, debug.get("log").data.length, "correct log data count");
+ OA.areEqual({content: "here", jsonTreeOptions: undefined}, debug.get("log").data[0], "correct log data");
+ A.areEqual(1, debug.get("log.My").data.length, "correct log.My data count");
+ OA.areEqual({content: "there", jsonTreeOptions: undefined}, debug.get("log.My").data[0], "correct log.My data");
// do prof data
- A.areEqual(Y.Object.keys(debug.get("prof.A").data).length, 1, "correct prof.A data count");
+ A.areEqual(1, Y.Object.keys(debug.get("prof.A").data).length, "correct prof.A data count");
A.isNotUndefined(debug.get("prof.A").data['b'], "correct prof.A node data");
- A.areEqual(debug.get("prof.A").data['b'].desc, 'b desc', "correct prof.A desc");
+ A.areEqual('b desc', debug.get("prof.A").data['b'].desc, "correct prof.A desc");
A.isNumber(debug.get("prof.A").data['b'].start, "correct prof.A start");
- A.areEqual(debug.get("prof.A").data['b'].close.length, 1, "correct prof.A.close data count");
- A.areEqual(debug.get("prof.A").data['b'].close[0].type, 'first close', "correct prof.A.close type");
+ A.areEqual(1, debug.get("prof.A").data['b'].close.length, "correct prof.A.close data count");
+ A.areEqual('first close', debug.get("prof.A").data['b'].close[0].type, "correct prof.A.close type");
A.isNumber(debug.get("prof.A").data['b'].close[0].time, "correct prof.A.close time");
- A.areEqual(debug.get("prof.A").events.length, 1, "correct prof.A.events count");
- A.areEqual(debug.get("prof.A").events[0].type, 'event 1', "correct prof.A.events type");
+ A.areEqual(1, debug.get("prof.A").events.length, "correct prof.A.events count");
+ A.areEqual('event 1', debug.get("prof.A").events[0].type, "correct prof.A.events type");
A.isNumber(debug.get("prof.A").events[0].time, "correct prof.A.events time");
- AA.containsItems(debug.getSpecialLogs(), "My".split(/,/), 'correct flags');
- AA.containsItems(debug.getKnownProf(), "A".split(/,/), 'correct flags');
+ AA.containsItems("My".split(/,/), debug.getSpecialLogs(), 'correct flags');
+ AA.containsItems("A".split(/,/), debug.getKnownProf(), 'correct flags');
+ A.isTrue(debug.flag("bar"), "flag set");
},
'debug interface more data': function() {
@@ -123,41 +126,41 @@ YUI.add('mojito-debug-api-tests', function(Y, NAME) {
debug.profClose("A", "d", "close no open");
- AA.containsItems(debug.flags(), "log,log.My,prof.A".split(/,/), 'correct flags');
- A.areEqual(debug.get("log").data.length, 2, "correct log data count");
- OA.areEqual(debug.get("log").data[0], {content: "here", jsonTreeOptions: undefined}, "correct log data");
- OA.areEqual(debug.get("log").data[1], {content: "here2", jsonTreeOptions: undefined}, "correct log data");
- A.areEqual(debug.get("log.My").data.length, 2, "correct log.My data count");
- OA.areEqual(debug.get("log.My").data[0], {content: "there", jsonTreeOptions: undefined}, "correct log.My data");
- OA.areEqual(debug.get("log.My").data[1], {content: "there2", jsonTreeOptions: undefined}, "correct log.My data");
+ AA.containsItems("log,log.My,prof.A".split(/,/), debug.flags(), 'correct flags');
+ A.areEqual(2, debug.get("log").data.length, "correct log data count");
+ OA.areEqual({content: "here", jsonTreeOptions: undefined}, debug.get("log").data[0], "correct log data");
+ OA.areEqual({content: "here2", jsonTreeOptions: undefined}, debug.get("log").data[1], "correct log data");
+ A.areEqual(2, debug.get("log.My").data.length, "correct log.My data count");
+ OA.areEqual({content: "there", jsonTreeOptions: undefined}, debug.get("log.My").data[0], "correct log.My data");
+ OA.areEqual({content: "there2", jsonTreeOptions: undefined}, debug.get("log.My").data[1], "correct log.My data");
// do prof data
- A.areEqual(Y.Object.keys(debug.get("prof.A").data).length, 2, "correct prof.A data count");
+ A.areEqual(2, Y.Object.keys(debug.get("prof.A").data).length, "correct prof.A data count");
A.isNotUndefined(debug.get("prof.A").data['b'], "correct prof.A node b data");
- A.areEqual(debug.get("prof.A").data['b'].desc, 'b desc', "correct prof.A b desc");
+ A.areEqual('b desc', debug.get("prof.A").data['b'].desc, "correct prof.A b desc");
A.isNumber(debug.get("prof.A").data['b'].start, "correct prof.A b start");
- A.areEqual(debug.get("prof.A").data['b'].close.length, 2, "correct prof.A.close b data count");
- A.areEqual(debug.get("prof.A").data['b'].close[0].type, 'first close', "correct prof.A.close b.0 type");
+ A.areEqual(2, debug.get("prof.A").data['b'].close.length, "correct prof.A.close b data count");
+ A.areEqual('first close', debug.get("prof.A").data['b'].close[0].type, "correct prof.A.close b.0 type");
A.isNumber(debug.get("prof.A").data['b'].close[0].time, "correct prof.A.close b.0 time");
- A.areEqual(debug.get("prof.A").data['b'].close[1].type, 'second close', "correct prof.A.close b.1 type");
+ A.areEqual('second close', debug.get("prof.A").data['b'].close[1].type, "correct prof.A.close b.1 type");
A.isNumber(debug.get("prof.A").data['b'].close[1].time, "correct prof.A.close b.1 time");
- A.areEqual(debug.get("prof.A").events.length, 2, "correct prof.A.events count");
- A.areEqual(debug.get("prof.A").events[0].type, 'event 1', "correct prof.A.events type");
+ A.areEqual(2, debug.get("prof.A").events.length, "correct prof.A.events count");
+ A.areEqual('event 1', debug.get("prof.A").events[0].type, "correct prof.A.events type");
A.isNumber(debug.get("prof.A").events[0].time, "correct prof.A.events time");
- A.areEqual(debug.get("prof.A").events[1].type, 'event 2', "correct prof.A.events type");
+ A.areEqual('event 2', debug.get("prof.A").events[1].type, "correct prof.A.events type");
A.isNumber(debug.get("prof.A").events[1].time, "correct prof.A.events time");
A.isNotUndefined(debug.get("prof.A").data['c'], "correct prof.A node c data");
- A.areEqual(debug.get("prof.A").data['c'].desc, 'c desc', "correct prof.A c desc");
+ A.areEqual('c desc', debug.get("prof.A").data['c'].desc, "correct prof.A c desc");
A.isNumber(debug.get("prof.A").data['c'].start, "correct prof.A c start");
- A.areEqual(debug.get("prof.A").data['c'].close.length, 2, "correct prof.A.close c data count");
- A.areEqual(debug.get("prof.A").data['c'].close[0].type, 'first close', "correct prof.A.c.0 close type");
+ A.areEqual(2, debug.get("prof.A").data['c'].close.length, "correct prof.A.close c data count");
+ A.areEqual('first close', debug.get("prof.A").data['c'].close[0].type, "correct prof.A.c.0 close type");
A.isNumber(debug.get("prof.A").data['c'].close[0].time, "correct prof.A.close c.0 time");
- A.areEqual(debug.get("prof.A").data['c'].close[1].type, 'second close', "correct prof.A.c.1 close type");
+ A.areEqual('second close', debug.get("prof.A").data['c'].close[1].type, "correct prof.A.c.1 close type");
A.isNumber(debug.get("prof.A").data['c'].close[1].time, "correct prof.A.close c.1 time");
- AA.containsItems(debug.getSpecialLogs(), "My".split(/,/), 'correct flags');
- AA.containsItems(debug.getKnownProf(), "A".split(/,/), 'correct flags');
+ AA.containsItems("My".split(/,/), debug.getSpecialLogs(), 'correct flags');
+ AA.containsItems("A".split(/,/), debug.getKnownProf(), 'correct flags');
},
'instrimentatin errors': function() {
@@ -173,11 +176,11 @@ YUI.add('mojito-debug-api-tests', function(Y, NAME) {
});
debug.logOn("My", function () {throw new Error("fail 2");});
- AA.containsItems(debug.flags(), "bar,log.My".split(/,/), 'correct flags');
+ AA.containsItems("bar,log.My".split(/,/), debug.flags(), 'correct flags');
A.isNotUndefined(debug.getInstrumentationErrors(), "error list");
- A.areEqual(debug.getInstrumentationErrors().length, 2, 'number of errors');
- A.areEqual(debug.getInstrumentationErrors()[0].flag, 'bar', 'bar error');
- A.areEqual(debug.getInstrumentationErrors()[1].flag, 'log.My', 'log.My error');
+ A.areEqual(2, debug.getInstrumentationErrors().length, 'number of errors');
+ A.areEqual('bar', debug.getInstrumentationErrors()[0].flag, 'bar error');
+ A.areEqual('log.My', debug.getInstrumentationErrors()[1].flag, 'log.My error');
},
}));
View
76 lib/tests/autoload/app/autoload/dispatch-tests.common.js
@@ -222,6 +222,82 @@ YUI.add('mojito-dispatcher-tests', function(Y, NAME) {
// this is about all we can get at
A.areSame(0, loaderCalled);
+ },
+
+ 'debugger on': function() {
+
+ var store = {
+ getAppConfig: function() {
+ return { yui: { dependencyCalculations: 'precomputed+ondemand' },
+ debug: { queryParam: 'debug', debugPath: '/debug', debugMojit: '@Debug.index' }
+ };
+ },
+ expandInstance: function(instance, context, cb) {
+ cb(null, {
+ type: instance.type,
+ id: 'xyz123',
+ instanceId: 'xyz123',
+ yui: {
+ config: {},
+ langs: [],
+ requires: [],
+ sorted: [],
+ sortedPaths: {}
+ }
+ });
+ }
+ };
+
+ var coreModules = [];
+
+ var logger = {
+ log: function(msg, lvl, src) {
+ // not testing this
+ }
+ };
+
+ var loaderCalled = 0;
+ var loader = {
+ load: function(paths, cb) {
+ loaderCalled++;
+ cb();
+ }
+ };
+
+ var dispatcher = Y.mojito.Dispatcher;
+
+ var res = dispatcher.init(store, coreModules, logger, loader);
+ A.areSame(dispatcher, res);
+
+ var realCC = Y.mojito.ControllerContext;
+ Y.mojito.ControllerContext = function(cfg) {};
+ Y.mojito.ControllerContext.prototype.invoke = function(command, adapter) {};
+
+ var command = {
+ action: 'index',
+ instance: {
+ type: 'M'
+ },
+ context: {
+ lang: 'klingon',
+ langs: 'klingon'
+ }
+ };
+ var adapter = {
+ debug: {
+ profOpen: function() {},
+ profClose: function() {}
+ }
+ };
+ try {
+ dispatcher.dispatch(command, adapter);
+ }
+ finally {
+ Y.mojito.ControllerContext = realCC;
+ }
+
+ // this is about all we can get at
+ A.areSame(0, loaderCalled);
}
}));
View
85 lib/tests/autoload/middleware/debug-tests.js
@@ -129,12 +129,7 @@ YUI.add('mojito-middleware-debug-tests', function(Y, NAME) {
},
handler = debug_interface(config),
req = {
- url: '/foo?debug=help',
- connection: {
- remoteAddress: "10.73.146.27"
- },
- headers: {
- }
+ url: '/foo?debug=help'
};
A.isNotUndefined(handler, 'middleware is null');
@@ -147,24 +142,80 @@ YUI.add('mojito-middleware-debug-tests', function(Y, NAME) {
req.debug.on("foo", function() {A.pass("debugger is on");});
A.isUndefined(req.debug.getInstrumentationErrors(), 'instrumentation error');
A.isNotUndefined(req.command, 'failed to detect query param');
- A.areEqual(req.url, '/debug/foo?debug=help', 'redirect url wrong');
- A.areEqual(req.command.instance.type, 'Debug', 'wrong debug mojit type');
- A.areEqual(req.command.action, 'index', 'wrong mojit action');
+ A.areEqual('/debug/foo?debug=help', req.url, 'redirect url wrong');
+ A.areEqual('Debug', req.command.instance.type, 'wrong debug mojit type');
+ A.areEqual('index', req.command.action, 'wrong mojit action');
req = {
- url: '/foo?debug=help',
- connection: {
- remoteAddress: "10.73.146.27"
- },
- headers: {
- }
+ url: '/foo?debug=help'
};
app_config.debug.debugMojit = 'Debug.index2';
handler = debug_interface(config);
handler(req, {}, function() {A.pass("handle req success");});
A.isNotUndefined(req.command, 'failed to detect query param');
- A.areEqual(req.command.instance.base, 'Debug', 'wrong debug mojit base');
- A.areEqual(req.command.action, 'index2', 'wrong mojit action');
+ A.areEqual('Debug', req.command.instance.base, 'wrong debug mojit base');
+ A.areEqual('index2', req.command.action, 'wrong mojit action');
+ },
+
+ 'create handler with request validator': function() {
+ var app_config = {
+ debug: {
+ queryParam: 'debug',
+ debugPath: '/debug',
+ debugMojit: '@Debug.index',
+ debugAllowed: 'my_validate_module.handler'
+ }
+ },
+ store = {
+ getRoutes: function() {
+ return routes;
+ },
+ getAppConfig: function() {
+ return app_config;
+ }
+ },
+ config = {
+ Y: Y,
+ store: store
+ },
+ handler = debug_interface(config),
+ req = {
+ url: '/foo'
+ };
+
+ Y.add('my_validate_module', function(Y, NAME) {
+ function ValidateRequest(req) {
+ return false;
+ };
+ Y.namespace(NAME).handler = ValidateRequest;
+ });
+
+
+ A.isNotUndefined(handler, 'middleware is null');
+
+ handler(req, {}, function() {A.pass("handle req success");});
+
+ A.isNotUndefined(req.debug, 'api is null');
+
+ A.areEqual('/foo', req.url, 'redirect url wrong');
+
+ Y.add('my_validate_module2', function(Y, NAME) {
+ function ValidateRequest(req) {
+ return true;
+ };
+ Y.namespace(NAME).handler = ValidateRequest;
+ });
+
+ req = {
+ url: '/foo?debug=help'
+ };
+ app_config.debug.debugAllowed = 'my_validate_module2.handler';
+ handler = debug_interface(config);
+ handler(req, {}, function() {A.pass("handle req success");});
+
+ A.isNotUndefined(req.debug, 'api is null');
+
+ A.areEqual('/debug/foo?debug=help', req.url, 'redirect url wrong');
}
}));
Please sign in to comment.
Something went wrong with that request. Please try again.