[TEST] Unknown scripting annotations raise error (#50343) (#50346)

Ensure that unknown annotations, such as typo'd `@nondeterministic`, 
will raise an exception.
This commit is contained in:
Stuart Tettemer 2019-12-19 16:22:22 -07:00 committed by GitHub
parent 70ac23ee01
commit f212994c16
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 31 additions and 0 deletions

View File

@ -31,6 +31,26 @@ import java.util.HashMap;
import java.util.Map;
public class WhitelistLoaderTests extends ScriptTestCase {
public void testUnknownAnnotations() {
Map<String, WhitelistAnnotationParser> parsers = new HashMap<>(WhitelistAnnotationParser.BASE_ANNOTATION_PARSERS);
RuntimeException expected = expectThrows(RuntimeException.class, () -> {
WhitelistLoader.loadFromResourceFiles(Whitelist.class, parsers, "org.elasticsearch.painless.annotation.unknown");
});
assertEquals(
"invalid annotation: parser not found for [unknownAnnotation] [@unknownAnnotation]", expected.getCause().getMessage()
);
assertEquals(IllegalArgumentException.class, expected.getCause().getClass());
expected = expectThrows(RuntimeException.class, () -> {
WhitelistLoader.loadFromResourceFiles(Whitelist.class, parsers, "org.elasticsearch.painless.annotation.unknown_with_options");
});
assertEquals(
"invalid annotation: parser not found for [unknownAnootationWithMessage] [@unknownAnootationWithMessage[arg=\"arg value\"]]",
expected.getCause().getMessage()
);
assertEquals(IllegalArgumentException.class, expected.getCause().getClass());
}
public void testAnnotations() {
Map<String, WhitelistAnnotationParser> parsers = new HashMap<>(WhitelistAnnotationParser.BASE_ANNOTATION_PARSERS);

View File

@ -0,0 +1,6 @@
# whitelist for annotation tests with unknown annotation
class org.elasticsearch.painless.AnnotationTestObject @no_import {
void unknownAnnotationMethod() @unknownAnnotation
void unknownAnnotationMethod() @unknownAnootationWithMessage[message="use another method"]
}

View File

@ -0,0 +1,5 @@
# whitelist for annotation tests with unknown annotation containing options
class org.elasticsearch.painless.AnnotationTestObject @no_import {
void unknownAnnotationMethod() @unknownAnootationWithMessage[arg="arg value"]
}