-
Notifications
You must be signed in to change notification settings - Fork 99
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
bugfix/1247: Don't create an lmdb library if the name is invalid. #1481
Conversation
9b0669d
to
9ae6d49
Compare
8b5fc3f
to
60a1161
Compare
Looks good to me |
def test_invalid_lib_name_windows(lmdb_storage): | ||
ac = lmdb_storage.create_arctic() | ||
|
||
invalid_paths = ["lib?1", "lib:1", "lib|1", "lib.", "lib "] | ||
for lib in invalid_paths: | ||
with pytest.raises(UserInputException) as e: | ||
ac.create_library(lib) | ||
assert ac.list_libraries() == [] | ||
|
||
valid_libs = ["lib#~@,1", "lib{)[.1", "!lib$%^"] | ||
for lib in valid_libs: | ||
ac.create_library(lib) | ||
assert set(ac.list_libraries()) == set(valid_libs) |
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.
I'd split this into two separate test cases because it looks like it's testing two separate things. One is that some strings are valid and the other is that some strings are invalid. The name is confusing as well. Also it looks like the naming is inconsistent, it's paths in one place and libs in the other. I'd also use parametrized test in order to avoid the for lib in invalid_paths
loop. It would look a lot cleaner as the test would have only the asserts in it's body.
@pytest.mark.skipif(sys.platform == "win32", reason="Windows has different file path name restrictions") | ||
def test_valid_lib_name_linux(lmdb_storage): | ||
ac = lmdb_storage.create_arctic() | ||
valid_libs = ["lib?1", "lib:1", "lib|1", "lib ", "lib#~@,1", "lib{)[.1", "!lib$%^"] |
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.
Use parametrized test
bf863a3
to
1504e18
Compare
def is_valid_lmdb_lib_name(lmdb_storage, lib_name): | ||
ac = lmdb_storage.create_arctic() | ||
ac.create_library(lib_name) | ||
|
||
return ac.list_libraries() == [lib_name] |
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.
I'd add this inside the tests instead of separating it in a function. While it helps avoiding code duplication it has the side effect of actually creating a library. I wouldn't expect a function checking if the name is valid to create a library.
@@ -259,6 +259,23 @@ void LmdbStorage::do_iterate_type(KeyType key_type, const IterateTypeVisitor& vi | |||
} | |||
} | |||
|
|||
bool LmdbStorage::do_is_path_valid(const std::string_view pathString) const { | |||
#ifdef _WIN32 | |||
std::string_view invalid_win32_chars = "<>:\"|?*"; |
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.
This list is not exhaustive:
https://stackoverflow.com/questions/1976007/what-characters-are-forbidden-in-windows-and-linux-directory-names
There are also a whole bunch of other reserved filenames that would fail
https://learn.microsoft.com/en-us/windows/win32/fileio/naming-a-file
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.
Note that when we create an lmdb library, it creates a folder with the given name, therefore I allow /
and \
as in this case if you give name1/name2
it will just create a subdir name2
under name1
and everything else (e.g. reads and writes on the lib) will work fine. In fact, this older test expects to be able to create such libraries. The purpose of this fix is to strictly disallow library names that are disallowed by windows, and a library name containing /
or \
would not fail so they should be allowed.
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.
I did look at the list of other reserved filenames while working on the fix. But the docs were strictly saying "reserved names for the name of a file". In fact, I tested this and I was able to create libraries with names such as CON, PRN, COM0
which successfully created folders with these names. These are reserved names but not strictly disallowed and that's why I allowed these names.
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.
Aha OK that makes sense. I think it's worth adding a comment here explaining all this, as it won't be obvious to the next person reading it.
return false; | ||
} | ||
#else | ||
(void) pathString; // suppress -Werror=unused-parameter |
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.
Use ARCTICDB_UNUSED
instead of this
verify_name("library name", library_path, true, UNSUPPORTED_S3_CHARS); | ||
if(!store->is_path_valid(library_path)) { |
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.
You can get rid of this if
using user_input::check
#### Reference Issues/PRs Addresses @alexowens90's comments in #1481 after that PR was merged. #### What does this implement or fix? #### Any other comments? #### Checklist <details> <summary> Checklist for code changes... </summary> - [ ] Have you updated the relevant docstrings, documentation and copyright notice? - [ ] Is this contribution tested against [all ArcticDB's features](../docs/mkdocs/docs/technical/contributing.md)? - [ ] Do all exceptions introduced raise appropriate [error messages](https://docs.arcticdb.io/error_messages/)? - [ ] Are API changes highlighted in the PR description? - [ ] Is the PR labelled as enhancement or bug so it appears in autogenerated release notes? </details> <!-- Thanks for contributing a Pull Request to ArcticDB! Please ensure you have taken a look at: - ArcticDB's Code of Conduct: https://github.com/man-group/ArcticDB/blob/master/CODE_OF_CONDUCT.md - ArcticDB's Contribution Licensing: https://github.com/man-group/ArcticDB/blob/master/docs/mkdocs/docs/technical/contributing.md#contribution-licensing -->
) #### Reference Issues/PRs Fixes #1247 #### What does this implement or fix? #### Any other comments? #### Checklist <details> <summary> Checklist for code changes... </summary> - [ ] Have you updated the relevant docstrings, documentation and copyright notice? - [ ] Is this contribution tested against [all ArcticDB's features](../docs/mkdocs/docs/technical/contributing.md)? - [ ] Do all exceptions introduced raise appropriate [error messages](https://docs.arcticdb.io/error_messages/)? - [ ] Are API changes highlighted in the PR description? - [ ] Is the PR labelled as enhancement or bug so it appears in autogenerated release notes? </details>
#### Reference Issues/PRs Addresses @alexowens90's comments in #1481 after that PR was merged. #### What does this implement or fix? #### Any other comments? #### Checklist <details> <summary> Checklist for code changes... </summary> - [ ] Have you updated the relevant docstrings, documentation and copyright notice? - [ ] Is this contribution tested against [all ArcticDB's features](../docs/mkdocs/docs/technical/contributing.md)? - [ ] Do all exceptions introduced raise appropriate [error messages](https://docs.arcticdb.io/error_messages/)? - [ ] Are API changes highlighted in the PR description? - [ ] Is the PR labelled as enhancement or bug so it appears in autogenerated release notes? </details> <!-- Thanks for contributing a Pull Request to ArcticDB! Please ensure you have taken a look at: - ArcticDB's Code of Conduct: https://github.com/man-group/ArcticDB/blob/master/CODE_OF_CONDUCT.md - ArcticDB's Contribution Licensing: https://github.com/man-group/ArcticDB/blob/master/docs/mkdocs/docs/technical/contributing.md#contribution-licensing -->
Reference Issues/PRs
Fixes #1247
What does this implement or fix?
Any other comments?
Checklist
Checklist for code changes...