-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c021ffd
commit 1489694
Showing
3 changed files
with
81 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package com.cflint; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import com.cflint.config.CFLintPluginInfo.PluginInfoRule; | ||
import com.cflint.config.CFLintPluginInfo.PluginInfoRule.PluginMessage; | ||
import com.cflint.config.ConfigRuntime; | ||
import com.cflint.plugins.core.ArgDefChecker; | ||
import com.cflint.plugins.core.QueryParamChecker; | ||
|
||
import cfml.parsing.reporting.ParseException; | ||
|
||
public class TestCFLint2Files { | ||
|
||
private CFLint cfBugs; | ||
|
||
@Before | ||
public void setUp() { | ||
final ConfigRuntime conf = new ConfigRuntime(); | ||
PluginInfoRule pluginRule = new PluginInfoRule(); | ||
pluginRule.setName("ArgDefChecker"); | ||
conf.getRules().add(pluginRule); | ||
PluginMessage pluginMessage = new PluginMessage("ARG_DEFAULT_MISSING"); | ||
pluginMessage.setSeverity("WARNING"); | ||
pluginMessage.setMessageText("Argument ${variable} is not required and does not define a default value."); | ||
pluginRule.getMessages().add(pluginMessage); | ||
|
||
pluginRule = new PluginInfoRule(); | ||
pluginRule.setName("QueryParamChecker"); | ||
conf.getRules().add(pluginRule); | ||
pluginMessage = new PluginMessage("QUERYPARAM_REQ"); | ||
pluginMessage.setSeverity("WARNING"); | ||
pluginMessage.setMessageText("setSql() statement should use .addParam() instead of #'s for security."); | ||
pluginRule.getMessages().add(pluginMessage); | ||
|
||
cfBugs = new CFLint(conf, new ArgDefChecker(),new QueryParamChecker()); | ||
} | ||
|
||
@Test | ||
public void testVarAndArgs_DisabledOther() throws ParseException, IOException { | ||
final String cfcSrc = "<cfcomponent>\r\n" + "<cffunction name=\"test\">\r\n" + " " | ||
+ "<!---CFLINT-DISABLE SOMEOTHER--->" | ||
+ "<cfargument name=\"xyz\">\r\n" | ||
+ "</cffunction>\r\n" + "</cfcomponent>"; | ||
cfBugs.process(cfcSrc, "test"); | ||
final List<BugInfo> result = cfBugs.getBugs().getBugList().values().iterator().next(); | ||
assertEquals(1, result.size()); | ||
assertEquals("ARG_DEFAULT_MISSING", result.get(0).getMessageCode()); | ||
|
||
final String cfcSrc2 = "component {\r\n" + " public string function fooFunction() {\r\n" | ||
+ "local.query = new Query();\r\n" + "local.query.setSql(\"\r\n" | ||
+ " SELECT id from table where id = #arguments.id#\");" + "</cfscript>\r\n" | ||
+ " }\r\n" | ||
+ "}"; | ||
cfBugs.process(cfcSrc2, "test"); | ||
final List<BugInfo> result2 = cfBugs.getBugs().getBugList().get("QUERYPARAM_REQ"); | ||
assertEquals(1, result2.size()); | ||
System.out.println(result2); | ||
assertEquals(4, result2.get(0).getLine()); | ||
} | ||
} |