Skip to content
Permalink
Browse files

Merge pull request #127 from abayer/jenkins-42360

[JENKINS-42360] Improve validation on object method calls
  • Loading branch information
abayer committed Mar 1, 2017
2 parents faa4b12 + 2750f57 commit 5c215ff0cdbf81bb517d34451aeb5d6a32fe7044
@@ -882,7 +882,12 @@ class ModelParser implements Parser {
protected String parseMethodName(MethodCallExpression exp) {
def s = matchMethodName(exp)
if (s==null) {
errorCollector.error(ModelASTValue.fromConstant(null, exp), Messages.ModelParser_ExpectedSymbol())
if (exp.objectExpression instanceof VariableExpression &&
!((VariableExpression)exp.objectExpression).isThisExpression()) {
errorCollector.error(ModelASTValue.fromConstant(null, exp), Messages.ModelParser_ObjectMethodCall())
} else {
errorCollector.error(ModelASTValue.fromConstant(null, exp), Messages.ModelParser_ExpectedSymbol())
}
s = "error";
}
return s;
@@ -62,6 +62,7 @@ ModelParser.NoArgForAgent=No argument for agent
ModelParser.NoArgForAgentKey=No argument for agent key "{0}"
ModelParser.NoArgForMapMethodKey=No argument for map key "{0}"
ModelParser.NoArgForTool=No argument for tool "{0}"
ModelParser.ObjectMethodCall=Method calls on objects not allowed outside "script" blocks.
ModelParser.OneAgentMax=Only one agent type is allowed per agent section
ModelParser.PipelineBlockNotAtTop={0} block must be at the top-level, not within another block.
ModelParser.PipelineStepWithoutBlock=Expected a block with the "{0}" step
@@ -534,7 +534,7 @@ public void libraryObjectInScript() throws Exception {

@Issue("JENKINS-40657")
@Test
public void libraryObjectOutsideScript() throws Exception {
public void libraryObjectDefinedOutsidePipeline() throws Exception {
otherRepo.init();
otherRepo.write("src/org/foo/Zot.groovy", "package org.foo;\n" +
"\n" +
@@ -553,7 +553,7 @@ public void libraryObjectOutsideScript() throws Exception {
new LibraryConfiguration("zot-stuff",
new SCMSourceRetriever(new GitSCMSource(null, otherRepo.toString(), "", "*", "", true)))));

expect("libraryObjectOutsideScript")
expect("libraryObjectDefinedOutsidePipeline")
.logContains("hello");
}

@@ -410,7 +410,7 @@ public void globalLibraryObjectMethodCall() throws Exception {
// Test the case of calling a method on an object, i.e., foo.bar(1). This will fail.
expectError("globalLibraryObjectMethodCall")
.logContains("MultipleCompilationErrorsException: startup failed:",
Messages.ModelParser_ExpectedSymbol())
Messages.ModelParser_ObjectMethodCall())
.go();
}

0 comments on commit 5c215ff

Please sign in to comment.
You can’t perform that action at this time.