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

Use test fixtures to create SROS artifacts (backport #522) #524

Merged
merged 2 commits into from Aug 8, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
47 changes: 26 additions & 21 deletions test_security/CMakeLists.txt
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.5)
cmake_minimum_required(VERSION 3.7)

project(test_security)

Expand Down Expand Up @@ -67,6 +67,7 @@ if(BUILD_TESTING)
set_tests_properties(
${target}${target_suffix}
PROPERTIES REQUIRED_FILES "$<TARGET_FILE:${target}${target_suffix}>"
FIXTURES_REQUIRED "sros_artifacts"
)
endif()
endfunction()
Expand Down Expand Up @@ -144,6 +145,7 @@ if(BUILD_TESTING)
set_tests_properties(
test_secure_publisher_subscriber${test_suffix}
PROPERTIES DEPENDS "test_secure_publisher_cpp__${rmw_implementation};test_secure_subscriber_cpp__${rmw_implementation}"
FIXTURES_REQUIRED "sros_artifacts"
)
endif()
endwhile()
Expand Down Expand Up @@ -184,6 +186,7 @@ if(BUILD_TESTING)
set_tests_properties(
test_secure_publisher_subscriber${test_suffix}
PROPERTIES DEPENDS "test_secure_publisher_cpp__${rmw_implementation};test_secure_subscriber_cpp__${rmw_implementation}"
FIXTURES_REQUIRED "sros_artifacts"
)
endif()
endwhile()
Expand Down Expand Up @@ -224,6 +227,7 @@ if(BUILD_TESTING)
set_tests_properties(
test_secure_publisher_subscriber${test_suffix}
PROPERTIES DEPENDS "test_secure_publisher_cpp__${rmw_implementation};test_secure_subscriber_cpp__${rmw_implementation}"
FIXTURES_REQUIRED "sros_artifacts"
)
endif()
endwhile()
Expand Down Expand Up @@ -308,28 +312,29 @@ if(BUILD_TESTING)
set(KEYSTORE_DIRECTORY_NATIVE_PATH "${KEYSTORE_DIRECTORY}")
endif()

# generate security artifacts using sros2
find_program(PROGRAM ros2)

set(node_names_list "/publisher;/subscriber;/publisher_missing_key;/publisher_invalid_cert")
file(REMOVE_RECURSE "${KEYSTORE_DIRECTORY}/enclaves/publisher_invalid_cert")
set(generate_artifacts_command ${PROGRAM} security generate_artifacts -k ${KEYSTORE_DIRECTORY_NATIVE_PATH} -e ${node_names_list})
execute_process(
COMMAND ${generate_artifacts_command}
RESULT_VARIABLE GENERATE_ARTIFACTS_RESULT
ERROR_VARIABLE GENERATE_ARTIFACTS_ERROR
#
# CTest Fixtures
#
# These fixtures are set up as needed at the beginning of the test run to
# support any selected tests which require them.
#
# * sros_artifacts: This fixture generates SROS2 security artifacts needed
# for the tests in this package.
#

find_program(ROS2_EXECUTABLE ros2)

add_test(NAME sros_artifacts
COMMAND ${CMAKE_COMMAND}
"-DROS2_EXECUTABLE=${ROS2_EXECUTABLE}"
"-DKEYSTORE_DIRECTORY=${KEYSTORE_DIRECTORY}"
"-DKEYSTORE_DIRECTORY_NATIVE_PATH=${KEYSTORE_DIRECTORY_NATIVE_PATH}"
"-P${CMAKE_CURRENT_SOURCE_DIR}/test/sros_artifacts.cmake"
)
if(NOT ${GENERATE_ARTIFACTS_RESULT} EQUAL 0)
message(FATAL_ERROR "Failed to generate security artifacts: ${GENERATE_ARTIFACTS_ERROR}")
endif()

# deleting key of /publisher_missing_key
file(REMOVE "${KEYSTORE_DIRECTORY}/enclaves/publisher_missing_key/key.pem")

# copy invalid certificate from source tree
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/test/test_security_files/publisher_invalid_cert/cert.pem
DESTINATION ${KEYSTORE_DIRECTORY}/enclaves/publisher_invalid_cert/
set_tests_properties(sros_artifacts PROPERTIES
FIXTURES_SETUP sros_artifacts
)

call_for_each_rmw_implementation(targets)
endif()
endif() # BUILD_TESTING
Expand Down
35 changes: 35 additions & 0 deletions test_security/test/sros_artifacts.cmake
@@ -0,0 +1,35 @@
# Copyright 2023 Open Source Robotics Foundation, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

cmake_minimum_required(VERSION 3.7)

set(node_names_list "/publisher;/subscriber;/publisher_missing_key;/publisher_invalid_cert")
file(REMOVE_RECURSE "${KEYSTORE_DIRECTORY}/enclaves")
set(generate_artifacts_command ${ROS2_EXECUTABLE} security generate_artifacts -k ${KEYSTORE_DIRECTORY_NATIVE_PATH} -e ${node_names_list})
execute_process(
COMMAND ${generate_artifacts_command}
RESULT_VARIABLE GENERATE_ARTIFACTS_RESULT
ERROR_VARIABLE GENERATE_ARTIFACTS_ERROR
)
if(NOT ${GENERATE_ARTIFACTS_RESULT} EQUAL 0)
message(FATAL_ERROR "Failed to generate security artifacts: ${GENERATE_ARTIFACTS_ERROR}")
endif()

# deleting key of /publisher_missing_key
file(REMOVE "${KEYSTORE_DIRECTORY}/enclaves/publisher_missing_key/key.pem")

# copy invalid certificate from source tree
file(COPY ${CMAKE_CURRENT_LIST_DIR}/test_security_files/publisher_invalid_cert/cert.pem
DESTINATION ${KEYSTORE_DIRECTORY}/enclaves/publisher_invalid_cert/
)