szaszm commented on code in PR #1749:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1749#discussion_r1609650194
##########
libminifi/test/libtest/unit/TestUtils.cpp:
##########
@@ -14,59 +14,117 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-#pragma once
-#include <string>
-#include <utility>
-#include <vector>
-#include <memory>
+#include "TestUtils.h"
-#include "rapidjson/document.h"
-#include "asio.hpp"
-#include "asio/ssl.hpp"
-#include "net/Ssl.h"
-#include "utils/IntegrationTestUtils.h"
+#include <type_traits>
-using namespace std::literals::chrono_literals;
+#ifdef WIN32
+#include <windows.h>
+#include <aclapi.h>
+#endif
+
+#include "utils/gsl.h"
+
+#ifdef WIN32
+namespace {
-#undef GetObject // windows.h #defines GetObject = GetObjectA or GetObjectW,
which conflicts with rapidjson
-#include "Connection.h"
-#include "FlowFileQueue.h"
-#include "Catch.h"
+void setAclOnFileOrDirectory(std::string file_name, DWORD perms, ACCESS_MODE
perm_options) {
+ PSECURITY_DESCRIPTOR security_descriptor = nullptr;
+ const auto security_descriptor_deleter = gsl::finally([&security_descriptor]
{ if (security_descriptor) { LocalFree((HLOCAL) security_descriptor); } });
-#define FIELD_ACCESSOR(field) \
- template<typename T> \
- static auto get_##field(T&& instance) ->
decltype((std::forward<T>(instance).field)) { \
- return std::forward<T>(instance).field; \
+ PACL old_acl = nullptr; // GetNamedSecurityInfo will set this to a
non-owning pointer to a field inside security_descriptor: no need to free it
+ if (GetNamedSecurityInfo(file_name.c_str(), SE_FILE_OBJECT,
DACL_SECURITY_INFORMATION, NULL, NULL, &old_acl, NULL, &security_descriptor) !=
ERROR_SUCCESS) {
+ throw std::runtime_error("Could not get security info for file: " +
file_name);
}
-#define METHOD_ACCESSOR(method) \
- template<typename T, typename ...Args> \
- static auto call_##method(T&& instance, Args&& ...args) ->
decltype((std::forward<T>(instance).method(std::forward<Args>(args)...))) { \
- return std::forward<T>(instance).method(std::forward<Args>(args)...); \
+ char trustee_name[] = "Everyone";
+ EXPLICIT_ACCESS explicit_access = {
+ .grfAccessPermissions = perms,
+ .grfAccessMode = perm_options,
+ .grfInheritance = CONTAINER_INHERIT_ACE | OBJECT_INHERIT_ACE,
+ .Trustee = { .TrusteeForm = TRUSTEE_IS_NAME, .ptstrName = trustee_name }
+ };
+
+ PACL new_acl = nullptr;
+ const auto new_acl_deleter = gsl::finally([&new_acl] { if (new_acl) {
LocalFree((HLOCAL) new_acl); } });
+
+ if (SetEntriesInAcl(1, &explicit_access, old_acl, &new_acl) !=
ERROR_SUCCESS) {
+ throw std::runtime_error("Could not create new ACL for file: " +
file_name);
}
+ if (SetNamedSecurityInfo(file_name.data(), SE_FILE_OBJECT,
DACL_SECURITY_INFORMATION, NULL, NULL, new_acl, NULL) != ERROR_SUCCESS) {
+ throw std::runtime_error("Could not set the new ACL for file: " +
file_name);
+ }
+}
+
+} // namespace
+#endif
+
namespace org::apache::nifi::minifi::test::utils {
-namespace internal {
-struct JsonContext {
- const JsonContext *parent{nullptr};
- std::string_view member;
+std::filesystem::path putFileToDir(const std::filesystem::path& dir_path,
const std::filesystem::path& file_name, const std::string& content) {
+ auto file_path = dir_path/file_name;
+ std::ofstream out_file(file_path, std::ios::binary | std::ios::out);
+ if (out_file.is_open()) {
+ out_file << content;
+ }
Review Comment:
Let's not fail silently here.
```suggestion
assert(out_file.is_open());
out_file << content;
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]