From d59bac0978af18e47c0179b96d9af31dacfffe89 Mon Sep 17 00:00:00 2001 From: Mike Gerwitz Date: Fri, 13 May 2011 21:27:53 -0400 Subject: [PATCH] Added test to ensure users can't be tricky and try to break static property encapsulation --- test/test-class_builder-static.js | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/test/test-class_builder-static.js b/test/test-class_builder-static.js index 647d210..92a1c83 100644 --- a/test/test-class_builder-static.js +++ b/test/test-class_builder-static.js @@ -733,3 +733,32 @@ var common = require( './common' ), ); } )(); + + +/** + * This tests very closely to the implementation, which is not good. However, + * it's important to protecting the data. The accessor method works off of + * context, so it's important to ensure that the data will remain encapsulated + * if the user attempts to be tricky and bind to a supertype. + */ +( function testCannotExploitAccessorMethodToGainAccessToParentPrivateProps() +{ + var Foo = builder.build( + { + 'private static foo': 'bar', + } ), + + SubFoo = builder.build( Foo, + { + 'public static getParentPrivate': function() + { + return this.$.call( Foo, 'foo' ); + } + } ) + ; + + assert.equal( SubFoo.getParentPrivate(), undefined, + "Cannot exploit accses modifier to gain access to parent private props" + ); +} )(); +