-
Notifications
You must be signed in to change notification settings - Fork 463
Fix PostgreSQL product creation with special characters in DB name #4830
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
bruntib
merged 3 commits into
Ericsson:master
from
bishara74:fix/postgres-db-name-special-chars
Apr 27, 2026
+116
−2
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -13,6 +13,7 @@ | |
|
|
||
| from codechecker_server.routing import split_client_GET_request | ||
| from codechecker_server.routing import split_client_POST_request | ||
| from codechecker_server.routing import is_valid_postgresql_db_name | ||
|
|
||
|
|
||
| def get(path, host="http://localhost:8001/"): | ||
|
|
@@ -61,3 +62,64 @@ def test_post(self): | |
|
|
||
| self.assertEqual(post('/DummyProduct/v6.0/FoobarService'), | ||
| ('DummyProduct', '6.0', 'FoobarService')) | ||
|
|
||
|
|
||
| class PostgresqlDbNameValidationTest(unittest.TestCase): | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, I've just noticed that this test is also among the tests of the routing module. Could you place this to a new test file? Thank you! |
||
| """ | ||
| Tests for is_valid_postgresql_db_name, which guards against dangerous | ||
| or unusable PostgreSQL database names before CodeChecker issues a | ||
| CREATE DATABASE statement. | ||
| """ | ||
|
|
||
| def test_accepts_plain_names(self): | ||
| """Names that are legal even as unquoted identifiers are allowed.""" | ||
| self.assertTrue(is_valid_postgresql_db_name('myapp')) | ||
| self.assertTrue(is_valid_postgresql_db_name('codechecker_test')) | ||
| self.assertTrue(is_valid_postgresql_db_name('db2')) | ||
| self.assertTrue(is_valid_postgresql_db_name('_internal')) | ||
|
|
||
| def test_accepts_names_needing_quoting(self): | ||
| """ | ||
| Names that are legal only as quoted identifiers are allowed, since | ||
| CodeChecker always quotes the identifier when creating the database. | ||
| These are the cases reported in the bug ticket. | ||
| """ | ||
| self.assertTrue(is_valid_postgresql_db_name('test-product')) | ||
| self.assertTrue(is_valid_postgresql_db_name('1team')) | ||
| self.assertTrue(is_valid_postgresql_db_name('my-app-prod')) | ||
| # "user" is a PostgreSQL reserved word but valid when quoted. | ||
| self.assertTrue(is_valid_postgresql_db_name('user')) | ||
|
|
||
| def test_rejects_empty_or_none(self): | ||
| """Empty string and non-string inputs are rejected.""" | ||
| self.assertFalse(is_valid_postgresql_db_name('')) | ||
| self.assertFalse(is_valid_postgresql_db_name(None)) | ||
| self.assertFalse(is_valid_postgresql_db_name(123)) | ||
|
|
||
| def test_rejects_dangerous_characters(self): | ||
| """ | ||
| Characters that could break out of a quoted identifier or embed | ||
| an SQL statement are rejected. | ||
| """ | ||
| self.assertFalse(is_valid_postgresql_db_name('foo"bar')) | ||
| self.assertFalse(is_valid_postgresql_db_name("foo'bar")) | ||
| self.assertFalse(is_valid_postgresql_db_name('foo;bar')) | ||
| self.assertFalse(is_valid_postgresql_db_name('foo\\bar')) | ||
| self.assertFalse(is_valid_postgresql_db_name('foo\x00bar')) | ||
|
|
||
| def test_rejects_whitespace(self): | ||
| """Names containing any whitespace are rejected.""" | ||
| self.assertFalse(is_valid_postgresql_db_name('foo bar')) | ||
| self.assertFalse(is_valid_postgresql_db_name('foo\tbar')) | ||
| self.assertFalse(is_valid_postgresql_db_name('foo\nbar')) | ||
| self.assertFalse(is_valid_postgresql_db_name('foo\rbar')) | ||
|
|
||
| def test_rejects_overlong_names(self): | ||
| """ | ||
| PostgreSQL silently truncates identifiers longer than 63 bytes, | ||
| which would produce a database CodeChecker cannot reconnect to. | ||
| """ | ||
| self.assertTrue(is_valid_postgresql_db_name('a' * 63)) | ||
| self.assertFalse(is_valid_postgresql_db_name('a' * 64)) | ||
| # 63 characters but more than 63 bytes due to multi-byte encoding. | ||
| self.assertFalse(is_valid_postgresql_db_name('é' * 32)) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please, replace this function to
codechecker_common.utilmodule. Thisrouting.pyis for other purposes.