1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
|
# fmt: off
import pytest
import subprocess
import sys
from typing import List
from conftest import ShellTest
from tools.shell.tests.conftest import random_filepath
@pytest.mark.parametrize("command", [".sh ls", ".cd ..", ".log file", ".import file.csv tbl", ".open new_file", ".output out", ".once out", ".excel out", ".read myfile.sql"])
def test_safe_mode_command(shell, command):
test = (
ShellTest(shell, ['-safe'])
.statement(command)
)
result = test.run()
result.check_stderr('cannot be used in -safe mode')
@pytest.mark.parametrize("param", [(".sh ls", 'cannot be used in -safe mode'), ("INSTALL extension", "Permission Error")])
def test_safe_mode_dot_command(shell, param):
command = param[0]
expected_error = param[1]
test = (
ShellTest(shell)
.statement('.safe_mode')
.statement(command)
)
result = test.run()
result.check_stderr(expected_error)
def test_safe_mode_database_basic(shell, random_filepath):
test = (
ShellTest(shell, [random_filepath, '-safe'])
.statement('CREATE TABLE integers(i INT)')
.statement('INSERT INTO integers VALUES (1), (2), (3)')
.statement('SELECT SUM(i) FROM integers')
)
result = test.run()
result.check_stdout("6")
@pytest.mark.parametrize("command", [".sh ls", ".cd ..", ".log file", ".import file.csv tbl", ".open new_file", ".output out", ".once out", ".excel out", ".read myfile.sql"])
@pytest.mark.parametrize("persistent", [False, True])
def test_safe_mode_database_commands(shell, random_filepath, command, persistent):
arguments = ['-safe'] if not persistent else [random_filepath, '-safe']
test = (
ShellTest(shell, arguments)
.statement(command)
)
result = test.run()
result.check_stderr('cannot be used in -safe mode')
@pytest.mark.parametrize("sql", ["COPY (SELECT 42) TO 'test.csv'", "LOAD spatial", "INSTALL spatial", "ATTACH 'file.db' AS file"])
@pytest.mark.parametrize("persistent", [False, True])
def test_safe_mode_query(shell, random_filepath, sql, persistent):
arguments = ['-safe'] if not persistent else [random_filepath, '-safe']
test = (
ShellTest(shell, arguments)
.statement(sql)
)
result = test.run()
result.check_stderr('disabled')
def test_lock_config(shell, random_filepath):
arguments = ['-safe']
test = (
ShellTest(shell, arguments)
.statement("SET memory_limit='-1'")
)
result = test.run()
result.check_stderr('locked')
# fmt: on
|