-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Implement DTLSSocket and fix non-blocking connections on TLSSocket #8659
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
d22adbd
Implement DTLSSocketWrapper and fix non-blocking connections on TLSSo…
2ca1fe6
Implement DTLSSocket helper
392bccf
Add unit tests for TLSSocket and TLSSocketWrapper
michalpasztamobica 695db63
Decrease verbosity of the TLSSocketWrapper
46c4601
Refactor DTLSSocket to use Socket::getpeername()
2229a2f
Need to protect members with MBEDTLS_PK_C and X509_CRT_PARSE flags.
6192ed1
Compare the intermediate timestamps as well
5d170f2
Clarify that TLSSocket should not be reopened.
bdc355f
Astyle fixes
0f5cec3
Include TLSSocket and DTLSSocket in Doxygen
8e41cac
Add license headers into TLSSocket unittests
5459a7b
Add license headers into TLSSocket files
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
24 changes: 24 additions & 0 deletions
24
UNITTESTS/features/netsocket/DTLSSocket/dtls_test_config.h
This file contains 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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* Copyright (c) 2018, Arm Limited and affiliates | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* 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. | ||
*/ | ||
|
||
#ifndef UNITTESTS_FEATURES_NETSOCKET_DTLSSOCKET_DTLS_TEST_CONFIG_H_ | ||
#define UNITTESTS_FEATURES_NETSOCKET_DTLSSOCKET_DTLS_TEST_CONFIG_H_ | ||
|
||
#define MBEDTLS_SSL_CLI_C | ||
|
||
|
||
#endif /* UNITTESTS_FEATURES_NETSOCKET_DTLSSOCKET_DTLS_TEST_CONFIG_H_ */ |
73 changes: 73 additions & 0 deletions
73
UNITTESTS/features/netsocket/DTLSSocket/test_DTLSSocket.cpp
This file contains 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 |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
* Copyright (c) 2018, Arm Limited and affiliates | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* 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. | ||
*/ | ||
|
||
#include "gtest/gtest.h" | ||
#include "features/netsocket/DTLSSocket.h" | ||
#include "NetworkStack_stub.h" | ||
|
||
#include "mbed_error.h" | ||
mbed_error_status_t mbed_error(mbed_error_status_t error_status, const char *error_msg, unsigned int error_value, const char *filename, int line_number) | ||
{ | ||
return 0; | ||
} | ||
|
||
// Control the rtos EventFlags stub. See EventFlags_stub.cpp | ||
extern std::list<uint32_t> eventFlagsStubNextRetval; | ||
|
||
class TestDTLSSocket : public testing::Test { | ||
public: | ||
unsigned int dataSize = 10; | ||
char dataBuf[10]; | ||
protected: | ||
DTLSSocket *socket; | ||
NetworkStackstub stack; | ||
|
||
virtual void SetUp() | ||
{ | ||
socket = new DTLSSocket(); | ||
} | ||
|
||
virtual void TearDown() | ||
{ | ||
stack.return_values.clear(); | ||
eventFlagsStubNextRetval.clear(); | ||
delete socket; | ||
} | ||
}; | ||
|
||
TEST_F(TestDTLSSocket, constructor) | ||
{ | ||
EXPECT_TRUE(socket); | ||
} | ||
|
||
/* connect */ | ||
|
||
TEST_F(TestDTLSSocket, connect) | ||
{ | ||
socket->open((NetworkStack *)&stack); | ||
|
||
stack.return_value = NSAPI_ERROR_OK; | ||
EXPECT_EQ(socket->connect("127.0.0.1", 1024), NSAPI_ERROR_OK); | ||
} | ||
|
||
TEST_F(TestDTLSSocket, connect_error) | ||
{ | ||
socket->open((NetworkStack *)&stack); | ||
|
||
stack.return_value = NSAPI_ERROR_DNS_FAILURE; | ||
EXPECT_EQ(socket->connect("127.0.0.1", 1024), NSAPI_ERROR_DNS_FAILURE); | ||
} |
This file contains 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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
|
||
#################### | ||
# UNIT TESTS | ||
#################### | ||
|
||
set(unittest-sources | ||
../features/netsocket/SocketAddress.cpp | ||
../features/netsocket/NetworkStack.cpp | ||
../features/netsocket/InternetSocket.cpp | ||
../features/netsocket/UDPSocket.cpp | ||
../features/netsocket/DTLSSocket.cpp | ||
../features/netsocket/DTLSSocketWrapper.cpp | ||
../features/netsocket/TLSSocketWrapper.cpp | ||
../features/frameworks/nanostack-libservice/source/libip4string/ip4tos.c | ||
../features/frameworks/nanostack-libservice/source/libip6string/ip6tos.c | ||
../features/frameworks/nanostack-libservice/source/libip4string/stoip4.c | ||
../features/frameworks/nanostack-libservice/source/libip6string/stoip6.c | ||
../features/frameworks/nanostack-libservice/source/libBits/common_functions.c | ||
) | ||
|
||
set(unittest-test-sources | ||
features/netsocket/DTLSSocket/test_DTLSSocket.cpp | ||
stubs/Mutex_stub.cpp | ||
stubs/mbed_assert_stub.c | ||
stubs/equeue_stub.c | ||
../features/nanostack/coap-service/test/coap-service/unittest/stub/mbedtls_stub.c | ||
stubs/EventQueue_stub.cpp | ||
stubs/mbed_shared_queues_stub.cpp | ||
stubs/nsapi_dns_stub.cpp | ||
stubs/EventFlags_stub.cpp | ||
stubs/stoip4_stub.c | ||
stubs/ip4tos_stub.c | ||
stubs/Kernel_stub.cpp | ||
) | ||
|
||
set(MBEDTLS_USER_CONFIG_FILE_PATH "\"../UNITTESTS/features/netsocket/DTLSSocket/dtls_test_config.h\"") | ||
set_source_files_properties(features/netsocket/DTLSSocket/test_DTLSSocket.cpp PROPERTIES COMPILE_DEFINITIONS MBEDTLS_USER_CONFIG_FILE=${MBEDTLS_USER_CONFIG_FILE_PATH}) | ||
set_source_files_properties(../features/netsocket/DTLSSocket.cpp PROPERTIES COMPILE_DEFINITIONS MBEDTLS_USER_CONFIG_FILE=${MBEDTLS_USER_CONFIG_FILE_PATH}) | ||
set_source_files_properties(../features/netsocket/DTLSSocketWrapper.cpp PROPERTIES COMPILE_DEFINITIONS MBEDTLS_USER_CONFIG_FILE=${MBEDTLS_USER_CONFIG_FILE_PATH}) | ||
|
24 changes: 24 additions & 0 deletions
24
UNITTESTS/features/netsocket/DTLSSocketWrapper/dtls_test_config.h
This file contains 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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* Copyright (c) 2018, Arm Limited and affiliates | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* 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. | ||
*/ | ||
|
||
#ifndef UNITTESTS_FEATURES_NETSOCKET_DTLSSOCKETWRAPPER_TLS_TEST_CONFIG_H_ | ||
#define UNITTESTS_FEATURES_NETSOCKET_DTLSSOCKETWRAPPER_TLS_TEST_CONFIG_H_ | ||
|
||
#define MBEDTLS_SSL_CLI_C | ||
|
||
|
||
#endif /* UNITTESTS_FEATURES_NETSOCKET_DTLSSOCKETWRAPPER_TLS_TEST_CONFIG_H_ */ |
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.
Some configs in this PR do not contain the license, please add