mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-03-31 17:36:21 +00:00
Reformat everything.
This commit is contained in:
parent
3f2213791a
commit
340ff8586d
1008 changed files with 61301 additions and 58309 deletions
|
|
@ -19,15 +19,13 @@ VALID = {
|
|||
'"public.table"': '"public.table"',
|
||||
'"public"."table"': '"public"."table"',
|
||||
'"schema test"."table test"': '"schema test"."table test"',
|
||||
|
||||
# We quote part
|
||||
'public.table': '"public"."table"',
|
||||
"public.table": '"public"."table"',
|
||||
'"public".table': '"public"."table"',
|
||||
'public."table"': '"public"."table"',
|
||||
'schema test.table test': '"schema test"."table test"',
|
||||
"schema test.table test": '"schema test"."table test"',
|
||||
'"schema test".table test': '"schema test"."table test"',
|
||||
'schema test."table test"': '"schema test"."table test"',
|
||||
|
||||
# Embedded double quotes
|
||||
'table "test"': '"table ""test"""',
|
||||
'public."table ""test"""': '"public"."table ""test"""',
|
||||
|
|
@ -40,7 +38,6 @@ VALID = {
|
|||
'schema."table': '"schema"."""table"',
|
||||
'"schema.table': '"""schema"."table"',
|
||||
'schema."table.something': '"schema"."""table"."something"',
|
||||
|
||||
# Embedded dots
|
||||
'"schema.test"."table.test"': '"schema.test"."table.test"',
|
||||
'"schema.".table': '"schema."."table"',
|
||||
|
|
@ -50,61 +47,61 @@ VALID = {
|
|||
'"schema.".".table"': '"schema.".".table"',
|
||||
# These are valid but maybe not what the user intended
|
||||
'."table"': '".""table"""',
|
||||
'table.': '"table."',
|
||||
"table.": '"table."',
|
||||
}
|
||||
|
||||
INVALID = {
|
||||
('test.too.many.dots', 'table'): 'PostgreSQL does not support table with more than 3 dots',
|
||||
('"test.too".many.dots', 'database'): 'PostgreSQL does not support database with more than 1 dots',
|
||||
('test.too."many.dots"', 'database'): 'PostgreSQL does not support database with more than 1 dots',
|
||||
('"test"."too"."many"."dots"', 'database'): "PostgreSQL does not support database with more than 1 dots",
|
||||
('"test"."too"."many"."dots"', 'schema'): "PostgreSQL does not support schema with more than 2 dots",
|
||||
('"test"."too"."many"."dots"', 'table'): "PostgreSQL does not support table with more than 3 dots",
|
||||
('"test"."too"."many"."dots"."for"."column"', 'column'): "PostgreSQL does not support column with more than 4 dots",
|
||||
('"table "invalid" double quote"', 'table'): 'User escaped identifiers must escape extra quotes',
|
||||
('"schema "invalid"""."table "invalid"', 'table'): 'User escaped identifiers must escape extra quotes',
|
||||
('"schema."table"', 'table'): 'User escaped identifiers must escape extra quotes',
|
||||
('"schema".', 'table'): 'Identifier name unspecified or unquoted trailing dot',
|
||||
("test.too.many.dots", "table"): "PostgreSQL does not support table with more than 3 dots",
|
||||
('"test.too".many.dots', "database"): "PostgreSQL does not support database with more than 1 dots",
|
||||
('test.too."many.dots"', "database"): "PostgreSQL does not support database with more than 1 dots",
|
||||
('"test"."too"."many"."dots"', "database"): "PostgreSQL does not support database with more than 1 dots",
|
||||
('"test"."too"."many"."dots"', "schema"): "PostgreSQL does not support schema with more than 2 dots",
|
||||
('"test"."too"."many"."dots"', "table"): "PostgreSQL does not support table with more than 3 dots",
|
||||
('"test"."too"."many"."dots"."for"."column"', "column"): "PostgreSQL does not support column with more than 4 dots",
|
||||
('"table "invalid" double quote"', "table"): "User escaped identifiers must escape extra quotes",
|
||||
('"schema "invalid"""."table "invalid"', "table"): "User escaped identifiers must escape extra quotes",
|
||||
('"schema."table"', "table"): "User escaped identifiers must escape extra quotes",
|
||||
('"schema".', "table"): "Identifier name unspecified or unquoted trailing dot",
|
||||
}
|
||||
|
||||
HOW_MANY_DOTS = (
|
||||
('role', 'role', '"role"',
|
||||
'PostgreSQL does not support role with more than 1 dots'),
|
||||
('db', 'database', '"db"',
|
||||
'PostgreSQL does not support database with more than 1 dots'),
|
||||
('db.schema', 'schema', '"db"."schema"',
|
||||
'PostgreSQL does not support schema with more than 2 dots'),
|
||||
('db.schema.table', 'table', '"db"."schema"."table"',
|
||||
'PostgreSQL does not support table with more than 3 dots'),
|
||||
('db.schema.table.column', 'column', '"db"."schema"."table"."column"',
|
||||
'PostgreSQL does not support column with more than 4 dots'),
|
||||
("role", "role", '"role"', "PostgreSQL does not support role with more than 1 dots"),
|
||||
("db", "database", '"db"', "PostgreSQL does not support database with more than 1 dots"),
|
||||
("db.schema", "schema", '"db"."schema"', "PostgreSQL does not support schema with more than 2 dots"),
|
||||
("db.schema.table", "table", '"db"."schema"."table"', "PostgreSQL does not support table with more than 3 dots"),
|
||||
(
|
||||
"db.schema.table.column",
|
||||
"column",
|
||||
'"db"."schema"."table"."column"',
|
||||
"PostgreSQL does not support column with more than 4 dots",
|
||||
),
|
||||
)
|
||||
|
||||
VALID_QUOTES = ((test, VALID[test]) for test in sorted(VALID))
|
||||
INVALID_QUOTES = ((test[0], test[1], INVALID[test]) for test in sorted(INVALID))
|
||||
|
||||
IS_STRINGS_DANGEROUS = (
|
||||
('', False),
|
||||
(' ', False),
|
||||
('alternative database', False),
|
||||
('backup of TRUNCATED table', False),
|
||||
('bob.dropper', False),
|
||||
('d\'artagnan', False),
|
||||
('user_with_select_update_truncate_right', False),
|
||||
(';DROP DATABASE fluffy_pets_photos', True),
|
||||
(';drop DATABASE fluffy_pets_photos', True),
|
||||
('; TRUNCATE TABLE his_valuable_table', True),
|
||||
('; truncate TABLE his_valuable_table', True),
|
||||
('\'--', True),
|
||||
("", False),
|
||||
(" ", False),
|
||||
("alternative database", False),
|
||||
("backup of TRUNCATED table", False),
|
||||
("bob.dropper", False),
|
||||
("d'artagnan", False),
|
||||
("user_with_select_update_truncate_right", False),
|
||||
(";DROP DATABASE fluffy_pets_photos", True),
|
||||
(";drop DATABASE fluffy_pets_photos", True),
|
||||
("; TRUNCATE TABLE his_valuable_table", True),
|
||||
("; truncate TABLE his_valuable_table", True),
|
||||
("'--", True),
|
||||
('"--', True),
|
||||
('\' union select username, password from admin_credentials', True),
|
||||
('\' UNION SELECT username, password from admin_credentials', True),
|
||||
('\' intersect select', True),
|
||||
('\' INTERSECT select', True),
|
||||
('\' except select', True),
|
||||
('\' EXCEPT select', True),
|
||||
(';ALTER TABLE prices', True),
|
||||
(';alter table prices', True),
|
||||
("' union select username, password from admin_credentials", True),
|
||||
("' UNION SELECT username, password from admin_credentials", True),
|
||||
("' intersect select", True),
|
||||
("' INTERSECT select", True),
|
||||
("' except select", True),
|
||||
("' EXCEPT select", True),
|
||||
(";ALTER TABLE prices", True),
|
||||
(";alter table prices", True),
|
||||
("; UPDATE products SET price = '0'", True),
|
||||
(";update products SET price = '0'", True),
|
||||
("; DELETE FROM products", True),
|
||||
|
|
@ -116,7 +113,7 @@ IS_STRINGS_DANGEROUS = (
|
|||
|
||||
@pytest.mark.parametrize("identifier, quoted_identifier", VALID_QUOTES)
|
||||
def test_valid_quotes(identifier, quoted_identifier):
|
||||
assert pg_quote_identifier(identifier, 'table') == quoted_identifier
|
||||
assert pg_quote_identifier(identifier, "table") == quoted_identifier
|
||||
|
||||
|
||||
@pytest.mark.parametrize("identifier, id_type, msg", INVALID_QUOTES)
|
||||
|
|
@ -132,7 +129,7 @@ def test_how_many_dots(identifier, id_type, quoted_identifier, msg):
|
|||
assert pg_quote_identifier(identifier, id_type) == quoted_identifier
|
||||
|
||||
with pytest.raises(SQLParseError) as ex:
|
||||
pg_quote_identifier(f'{identifier}.more', id_type)
|
||||
pg_quote_identifier(f"{identifier}.more", id_type)
|
||||
|
||||
ex.match(msg)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue