Skip to content
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

Complete rcl enclave validation API coverage. #751

Merged
merged 2 commits into from
Aug 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion rcl/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ call_for_each_rmw_implementation(test_target)
rcl_add_custom_gtest(test_validate_enclave_name
SRCS rcl/test_validate_enclave_name.cpp
APPEND_LIBRARY_DIRS ${extra_lib_dirs}
LIBRARIES ${PROJECT_NAME}
LIBRARIES ${PROJECT_NAME} mimick
)

rcl_add_custom_gtest(test_domain_id
Expand Down
59 changes: 59 additions & 0 deletions rcl/test/rcl/test_validate_enclave_name.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,17 @@
#include <string>
#include <vector>

#include "rcutils/snprintf.h"

#include "rcl/rcl.h"
#include "rcl/validate_enclave_name.h"

#include "rcl/error_handling.h"

#include "rmw/validate_namespace.h"

#include "../mocking_utils/patch.hpp"

TEST(TestValidateEnclaveName, test_validate) {
int validation_result;
size_t invalid_index;
Expand All @@ -47,6 +53,59 @@ TEST(TestValidateEnclaveName, test_validate) {
RCL_RET_OK,
rcl_validate_enclave_name("/foo/bar", &validation_result, &invalid_index));
EXPECT_EQ(RCL_ENCLAVE_NAME_VALID, validation_result);

{
auto mock = mocking_utils::patch(
Blast545 marked this conversation as resolved.
Show resolved Hide resolved
"lib:rcl", rmw_validate_namespace_with_size,
[&](auto, auto, int * result, size_t * index) {
if (index) {
*index = 0u;
}
*result = RMW_NAMESPACE_INVALID_TOO_LONG;
return RMW_RET_OK;
});

// When applying RMW namespace validation rules, an enclave name may be too
// long for an RMW namespace but not necessarily for an enclave name.
EXPECT_EQ(
RCL_RET_OK,
rcl_validate_enclave_name("/foo/baz", &validation_result, &invalid_index));
EXPECT_EQ(RCL_ENCLAVE_NAME_VALID, validation_result);
Blast545 marked this conversation as resolved.
Show resolved Hide resolved
}
}

TEST(TestValidateEnclaveName, test_validate_on_internal_error) {
int validation_result;
size_t invalid_index;
Blast545 marked this conversation as resolved.
Show resolved Hide resolved

{
auto mock = mocking_utils::patch_to_fail(
"lib:rcl", rmw_validate_namespace_with_size, "internal error", RMW_RET_ERROR);

EXPECT_EQ(
RCL_RET_ERROR,
rcl_validate_enclave_name("/foo", &validation_result, &invalid_index));
EXPECT_TRUE(rcl_error_is_set());
rcl_reset_error();
}

{
auto mock = mocking_utils::patch(
"lib:rcl", rmw_validate_namespace_with_size,
[&](auto, auto, int * result, size_t * index) {
if (index) {
*index = 0u;
}
*result = -1;
return RMW_RET_OK;
});

EXPECT_EQ(
RCL_RET_ERROR,
rcl_validate_enclave_name("/foo", &validation_result, &invalid_index));
EXPECT_TRUE(rcl_error_is_set());
rcl_reset_error();
}
}

TEST(TestValidateEnclaveName, test_validation_string) {
Expand Down