Exemplo n.º 1
0
 def _validate_filters(self) -> None:
     for param in ("where", "having"):
         clause = self.extras.get(param)
         if clause:
             try:
                 validate_filter_clause(clause)
             except QueryClauseValidationException as ex:
                 raise QueryObjectValidationError(ex.message) from ex
Exemplo n.º 2
0
def test_validate_filter_clause_valid():
    # regular clauses
    assert validate_filter_clause("col = 1") is None
    assert validate_filter_clause("1=\t\n1") is None
    assert validate_filter_clause("(col = 1)") is None
    assert validate_filter_clause("(col1 = 1) AND (col2 = 2)") is None

    # Valid literal values that appear to be invalid
    assert validate_filter_clause("col = 'col1 = 1) AND (col2 = 2'") is None
    assert validate_filter_clause("col = 'select 1; select 2'") is None
    assert validate_filter_clause("col = 'abc -- comment'") is None
Exemplo n.º 3
0
def test_validate_filter_clause_subquery_comment():
    with pytest.raises(QueryClauseValidationException):
        validate_filter_clause("(1 = 1 -- comment\n)")
Exemplo n.º 4
0
def test_validate_filter_clause_multiple():
    with pytest.raises(QueryClauseValidationException):
        validate_filter_clause("TRUE; SELECT 1")
Exemplo n.º 5
0
def test_validate_filter_clause_closing_and_unclosed_nested():
    with pytest.raises(QueryClauseValidationException):
        validate_filter_clause("(col1 = 1)) AND ((col2 = 2)")
Exemplo n.º 6
0
def test_validate_filter_clause_unclosed():
    with pytest.raises(QueryClauseValidationException):
        validate_filter_clause("(col1 = 1) AND (col2 = 2")