use of org.opensearch.common.breaker.CircuitBreakingException in project OpenSearch by opensearch-project.
the class LimitedCharSequenceTests method testCharAtAboveLimit.
public void testCharAtAboveLimit() {
String str = "abc";
String patternStr = "a.*bc";
Pattern p = Pattern.compile(patternStr);
final CharSequence seq = new LimitedCharSequence(str, p, 2);
for (int i = 0; i < 6; i++) {
seq.charAt(0);
}
CircuitBreakingException circuitBreakingException = expectThrows(CircuitBreakingException.class, () -> seq.charAt(0));
assertEquals("[scripting] Regular expression considered too many characters, " + "pattern: [a.*bc], " + "limit factor: [2], " + "char limit: [6], " + "count: [7], " + "wrapped: [abc], " + "this limit can be changed by changed by the [script.painless.regex.limit-factor] setting", circuitBreakingException.getMessage());
final CharSequence seqNullPattern = new LimitedCharSequence(str, null, 2);
for (int i = 0; i < 6; i++) {
seqNullPattern.charAt(0);
}
circuitBreakingException = expectThrows(CircuitBreakingException.class, () -> seqNullPattern.charAt(0));
assertEquals("[scripting] Regular expression considered too many characters, " + "limit factor: [2], " + "char limit: [6], " + "count: [7], " + "wrapped: [abc], " + "this limit can be changed by changed by the [script.painless.regex.limit-factor] setting", circuitBreakingException.getMessage());
}
use of org.opensearch.common.breaker.CircuitBreakingException in project OpenSearch by opensearch-project.
the class RegexLimitTests method testRegexInject_Ref_SplitAsStream.
public void testRegexInject_Ref_SplitAsStream() {
String script = "Stream splitStream(Function func) { func.apply(" + SPLIT_CHAR_SEQUENCE + "); } " + "Pattern pattern = " + PATTERN + ";" + "splitStream(pattern::splitAsStream).toArray(String[]::new)";
CircuitBreakingException cbe = expectScriptThrows(CircuitBreakingException.class, () -> exec(script));
assertTrue(cbe.getMessage().contains(REGEX_CIRCUIT_MESSAGE));
}
use of org.opensearch.common.breaker.CircuitBreakingException in project OpenSearch by opensearch-project.
the class RegexLimitTests method testRegexInject_Split.
public void testRegexInject_Split() {
String[] scripts = new String[] { PATTERN + ".split(" + SPLIT_CHAR_SEQUENCE + ")", "Pattern p = " + PATTERN + "; p.split(" + SPLIT_CHAR_SEQUENCE + ")" };
for (String script : scripts) {
CircuitBreakingException cbe = expectScriptThrows(CircuitBreakingException.class, () -> exec(script));
assertTrue(cbe.getMessage().contains(REGEX_CIRCUIT_MESSAGE));
}
}
use of org.opensearch.common.breaker.CircuitBreakingException in project OpenSearch by opensearch-project.
the class RegexLimitTests method testRegexInjectFindOperator.
public void testRegexInjectFindOperator() {
String script = "if (" + CHAR_SEQUENCE + " =~ " + PATTERN + ") { return 100; } return 200";
CircuitBreakingException cbe = expectScriptThrows(CircuitBreakingException.class, () -> exec(script));
assertTrue(cbe.getMessage().contains(REGEX_CIRCUIT_MESSAGE));
}
use of org.opensearch.common.breaker.CircuitBreakingException in project OpenSearch by opensearch-project.
the class RegexLimitTests method testRegexInject_SplitAsStream.
public void testRegexInject_SplitAsStream() {
String[] scripts = new String[] { PATTERN + ".splitAsStream(" + SPLIT_CHAR_SEQUENCE + ").toArray(String[]::new)", "Pattern p = " + PATTERN + "; p.splitAsStream(" + SPLIT_CHAR_SEQUENCE + ").toArray(String[]::new)" };
for (String script : scripts) {
CircuitBreakingException cbe = expectScriptThrows(CircuitBreakingException.class, () -> exec(script));
assertTrue(cbe.getMessage().contains(REGEX_CIRCUIT_MESSAGE));
}
}
Aggregations