}
@Test
public void shouldSecureSome() throws Exception {
GroovyInterceptor.getApplicableInterceptors().forEach(GroovyInterceptor::unregister);
final SecurityCustomizerProvider provider = new SecurityCustomizerProvider(new AllowSome());
final GremlinGroovyScriptEngine scriptEngine = new GremlinGroovyScriptEngine(
new DefaultImportCustomizerProvider(), provider);
try {
scriptEngine.eval("g = 'new java.awt.Color(255, 255, 255)'");
fail("Should have failed security");
} catch (ScriptException se) {
assertEquals(SecurityException.class, se.getCause().getCause().getClass());
}
try {
assertNotNull(g);
final java.awt.Color c = (java.awt.Color) scriptEngine.eval("c = new java.awt.Color(255, 255, 255)");
assertEquals(java.awt.Color.class, c.getClass());
} catch (Exception ex) {
fail("Should not have tossed an exception");
} finally {
provider.unregisterInterceptors();
}
}