mirror of
https://github.com/outbackdingo/parodus.git
synced 2026-01-27 18:20:04 +00:00
Compare commits
138 Commits
boot_time_
...
1.0.1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8d7cc47e62 | ||
|
|
326e83c177 | ||
|
|
3df3876553 | ||
|
|
77f16d65db | ||
|
|
6e4f8e92d1 | ||
|
|
7b106585cd | ||
|
|
cb3da5a343 | ||
|
|
6e1a0fccf4 | ||
|
|
b7e5d47f65 | ||
|
|
7e9d3c80c5 | ||
|
|
50d9271e90 | ||
|
|
982cf14f55 | ||
|
|
91a9d4d679 | ||
|
|
6bcae50f0e | ||
|
|
e5ac5c0712 | ||
|
|
3e23aeb451 | ||
|
|
a61de51dfe | ||
|
|
dc099a553c | ||
|
|
0b3b31fc6f | ||
|
|
bebaf9efa0 | ||
|
|
a8ecc96cdb | ||
|
|
8f77883a11 | ||
|
|
602ba21a8d | ||
|
|
32dc7b4b93 | ||
|
|
de0eefbaa6 | ||
|
|
d636cfffe9 | ||
|
|
2af5845e76 | ||
|
|
a2079aabf1 | ||
|
|
880e4a8765 | ||
|
|
3d3c965807 | ||
|
|
2a4fa2ffc4 | ||
|
|
d0535521c7 | ||
|
|
5663981ac0 | ||
|
|
844ee1c240 | ||
|
|
dc81484779 | ||
|
|
e0c69f5e29 | ||
|
|
3768ef17f1 | ||
|
|
fbe267ee82 | ||
|
|
a619b59e23 | ||
|
|
1ceedbf772 | ||
|
|
d22f497e4e | ||
|
|
dd77f874b5 | ||
|
|
280166b4ca | ||
|
|
1012afeebf | ||
|
|
d13daec5b1 | ||
|
|
f57caffb2e | ||
|
|
b15a2cd638 | ||
|
|
d2853fe742 | ||
|
|
3986da3885 | ||
|
|
38f855f1a3 | ||
|
|
bb16704bed | ||
|
|
ac74889b9a | ||
|
|
cbeeb44702 | ||
|
|
d6a6bf8549 | ||
|
|
b5633ba8db | ||
|
|
05d24b6b57 | ||
|
|
375e3ef79a | ||
|
|
3fd1b5ce38 | ||
|
|
a9d9c6a538 | ||
|
|
4ea905e491 | ||
|
|
6a2db59bbe | ||
|
|
89ab46499a | ||
|
|
6b6b943ef0 | ||
|
|
7eec176414 | ||
|
|
7a7e7acb19 | ||
|
|
7328a559f8 | ||
|
|
a279ee71c9 | ||
|
|
facae2e9f4 | ||
|
|
f3e506e943 | ||
|
|
38e5c0b5b5 | ||
|
|
e01ae80307 | ||
|
|
12a034f451 | ||
|
|
a1e63ca251 | ||
|
|
355b7d7bd3 | ||
|
|
bbf5fc263c | ||
|
|
45c1865cb1 | ||
|
|
06f96abe41 | ||
|
|
ee9d7684c6 | ||
|
|
951be13bc0 | ||
|
|
c5819e4cb1 | ||
|
|
38d2596458 | ||
|
|
8c79a7712d | ||
|
|
15d9b14e31 | ||
|
|
c3d66f7a45 | ||
|
|
659bb28ce7 | ||
|
|
0725e9f3ae | ||
|
|
3e264707e7 | ||
|
|
e6c41ee386 | ||
|
|
6b5f24f81b | ||
|
|
4dd693d2b5 | ||
|
|
8eb6ff8fa8 | ||
|
|
c067faa65a | ||
|
|
e0ecd1bbd7 | ||
|
|
a06d507422 | ||
|
|
a1b676e5fe | ||
|
|
4276e2dd24 | ||
|
|
dc8f9f49f0 | ||
|
|
0618690bf4 | ||
|
|
7b1ef043ef | ||
|
|
1da5978eac | ||
|
|
df96235321 | ||
|
|
9421a3d01a | ||
|
|
c277ef4587 | ||
|
|
472b769874 | ||
|
|
4e1f77c1df | ||
|
|
b07ff93fd8 | ||
|
|
9aacf1cbb3 | ||
|
|
5545dbc84f | ||
|
|
755e15fd6c | ||
|
|
492688e6e7 | ||
|
|
9c98105e35 | ||
|
|
0a4ef718f6 | ||
|
|
7eba72b2af | ||
|
|
5af33bec8c | ||
|
|
0f71f45ca6 | ||
|
|
89da01fad0 | ||
|
|
0e927c0f26 | ||
|
|
6bcc88c55a | ||
|
|
9cd80c1237 | ||
|
|
20fc1bb8a0 | ||
|
|
46767bf392 | ||
|
|
deec73c5a5 | ||
|
|
b6f315bbb7 | ||
|
|
202b5deb68 | ||
|
|
a69acfeabb | ||
|
|
36dc370ef8 | ||
|
|
587027ce78 | ||
|
|
a254fc17d7 | ||
|
|
f3abee1a04 | ||
|
|
d85f790407 | ||
|
|
12565db6e9 | ||
|
|
6a396c2197 | ||
|
|
633cfe1636 | ||
|
|
7e74d05196 | ||
|
|
fc72633519 | ||
|
|
62aea40eb4 | ||
|
|
c693a34a15 | ||
|
|
d6fb9073ed |
@@ -13,7 +13,7 @@ addons:
|
||||
notification_email: weston_schmidt@alumni.purdue.edu
|
||||
build_command_prepend: "mkdir coverity_build && cd coverity_build && cmake .."
|
||||
build_command: "make"
|
||||
branch_pattern: master
|
||||
branch_pattern: ignore
|
||||
|
||||
before_install:
|
||||
- sudo pip install codecov
|
||||
|
||||
44
CHANGELOG.md
Normal file
44
CHANGELOG.md
Normal file
@@ -0,0 +1,44 @@
|
||||
# Changelog
|
||||
All notable changes to this project will be documented in this file.
|
||||
|
||||
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
|
||||
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
|
||||
|
||||
## [Unreleased]
|
||||
- Refactor of connection code (simplification).
|
||||
- Additional `/cloud-status` and `/cloud-disconnect` fields.
|
||||
|
||||
## [1.0.1] - 2018-07-18
|
||||
### Added
|
||||
- Added command line arguments for secure token read and acquire.
|
||||
- DNS check for <device-id>.<URL> to allow custom device handling logic (like test boxes, refurbishing, etc).
|
||||
- Add check for matching `partner-id` for incoming WRP messages based on command line argument passed.
|
||||
- CRUD operations to local namespace is now supported.
|
||||
- Via CRUD calls, the custom metadata tag values are now supported.
|
||||
|
||||
### Changed
|
||||
- Configurable security flag and port.
|
||||
- Default HTTP port to 80 and HTTPS port to 443.
|
||||
- Updates to how `nopoll` is called have been implemented.
|
||||
|
||||
### Fixed
|
||||
- 64 bit pointer fixes (#144, #145).
|
||||
- Handle `403` error from talaria (#147).
|
||||
- Several additional NULL pointer checks & recovery logic blocks added.
|
||||
- A scenario where ping requests are not responded to was fixed.
|
||||
|
||||
### Security
|
||||
- Added command line arguments for secure token read and acquire. Token presented to cloud for authentication verification.
|
||||
|
||||
## [1.0.0] - 2017-11-17
|
||||
### Added
|
||||
- Added the basic implementation.
|
||||
|
||||
## [0.0.1] - 2016-08-15
|
||||
### Added
|
||||
- Initial creation
|
||||
|
||||
[Unreleased]: https://github.com/Comcast/parodus/compare/1.0.1...HEAD
|
||||
[1.0.1]: https://github.com/Comcast/parodus/compare/1.0.0...1.0.1
|
||||
[1.0.0]: https://github.com/Comcast/parodus/compare/79fa7438de2b14ae64f869d52f5c127497bf9c3f...1.0.0
|
||||
|
||||
@@ -71,7 +71,7 @@ if (NOT BUILD_YOCTO)
|
||||
ExternalProject_Add(trower-base64
|
||||
PREFIX ${CMAKE_CURRENT_BINARY_DIR}/_prefix/trower-base64
|
||||
GIT_REPOSITORY https://github.com/Comcast/trower-base64.git
|
||||
GIT_TAG "master"
|
||||
GIT_TAG "fbb9440ae2bc1118866baefcea7ff814f16613dd"
|
||||
CMAKE_ARGS += -DCMAKE_INSTALL_PREFIX=${INSTALL_DIR} -DBUILD_TESTING=OFF
|
||||
)
|
||||
add_library(libtrower-base64 STATIC SHARED IMPORTED)
|
||||
@@ -83,7 +83,7 @@ add_dependencies(libtrower-base64 trower-base64)
|
||||
ExternalProject_Add(nopoll
|
||||
PREFIX ${PREFIX_DIR}/nopoll
|
||||
GIT_REPOSITORY https://github.com/Comcast/nopoll.git
|
||||
GIT_TAG "nopoll_yocto"
|
||||
GIT_TAG "739b740683b0615e5999bdeea756cbd593b7f1cc"
|
||||
CONFIGURE_COMMAND COMMAND <SOURCE_DIR>/autogen.sh --prefix=${PREFIX}
|
||||
--includedir=${INCLUDE_DIR}
|
||||
--libdir=${LIBRARY_DIR}
|
||||
@@ -99,7 +99,7 @@ add_dependencies(libnopoll nopoll)
|
||||
ExternalProject_Add(nanomsg
|
||||
PREFIX ${CMAKE_CURRENT_BINARY_DIR}/_prefix/nanomsg
|
||||
GIT_REPOSITORY https://github.com/nanomsg/nanomsg.git
|
||||
#GIT_TAG "096998834451219ee7813d8977f6a4027b0ccb43"
|
||||
GIT_TAG "0c1aa2b288f6b167dbafe7e29c20e6fc7e71c000"
|
||||
CMAKE_ARGS += -DCMAKE_INSTALL_PREFIX=${INSTALL_DIR}
|
||||
)
|
||||
add_library(libnanomsg STATIC SHARED IMPORTED)
|
||||
@@ -138,7 +138,7 @@ add_dependencies(libmsgpack msgpack)
|
||||
ExternalProject_Add(cimplog
|
||||
PREFIX ${CMAKE_CURRENT_BINARY_DIR}/_prefix/cimplog
|
||||
GIT_REPOSITORY https://github.com/Comcast/cimplog.git
|
||||
GIT_TAG "master"
|
||||
GIT_TAG "8a5fb3c2f182241d17f5342bea5b7688c28cd1fd"
|
||||
CMAKE_ARGS += -DCMAKE_INSTALL_PREFIX=${INSTALL_DIR} -DBUILD_TESTING=OFF
|
||||
)
|
||||
add_library(libcimplog STATIC SHARED IMPORTED)
|
||||
@@ -151,7 +151,7 @@ ExternalProject_Add(wrp-c
|
||||
DEPENDS trower-base64 msgpack cimplog
|
||||
PREFIX ${CMAKE_CURRENT_BINARY_DIR}/_prefix/wrp-c
|
||||
GIT_REPOSITORY https://github.com/Comcast/wrp-c.git
|
||||
GIT_TAG "master"
|
||||
GIT_TAG "d42ac3a63b8d6e723995b63e23aa1969e622faa5"
|
||||
CMAKE_ARGS += -DCMAKE_INSTALL_PREFIX=${INSTALL_DIR}
|
||||
-DMSGPACK_ENABLE_CXX=OFF
|
||||
-DMSGPACK_BUILD_EXAMPLES=OFF
|
||||
@@ -169,7 +169,7 @@ ExternalProject_Add(libparodus
|
||||
DEPENDS trower-base64 msgpack nanomsg wrp-c
|
||||
PREFIX ${CMAKE_CURRENT_BINARY_DIR}/_prefix/libparodus
|
||||
GIT_REPOSITORY https://github.com/Comcast/libparodus.git
|
||||
GIT_TAG "master"
|
||||
GIT_TAG "a7615d69bd5859e337f467fb7e33182da970a5de"
|
||||
CMAKE_ARGS += -DCMAKE_INSTALL_PREFIX=${INSTALL_DIR} -DBUILD_TESTING=OFF
|
||||
-DMAIN_PROJ_BUILD=ON
|
||||
-DMAIN_PROJ_LIB_PATH=${LIBRARY_DIR}
|
||||
@@ -187,6 +187,7 @@ ExternalProject_Add(libseshat
|
||||
DEPENDS cJSON trower-base64 msgpack nanomsg wrp-c
|
||||
PREFIX ${CMAKE_CURRENT_BINARY_DIR}/_prefix/libseshat
|
||||
GIT_REPOSITORY https://github.com/comcast/seshat.git
|
||||
GIT_TAG "470f8d5e9457755028aae6da65d3df9b62a53942"
|
||||
CMAKE_ARGS += -DCMAKE_INSTALL_PREFIX=${INSTALL_DIR} -DBUILD_TESTING=OFF
|
||||
-DMAIN_PROJ_BUILD=ON
|
||||
-DMAIN_PROJ_LIB_PATH=${LIBRARY_DIR}
|
||||
@@ -205,8 +206,7 @@ endif (ENABLE_SESHAT)
|
||||
ExternalProject_Add(cjwt
|
||||
PREFIX ${CMAKE_CURRENT_BINARY_DIR}/_prefix/cjwt
|
||||
GIT_REPOSITORY https://github.com/Comcast/cjwt.git
|
||||
GIT_TAG "master"
|
||||
#GIT_TAG "abd4376ff56212d16f69e850a64f6e095857ca39"
|
||||
GIT_TAG "ddd077f0f00407f9657934492b252ee5cfcde535"
|
||||
CMAKE_ARGS += -DCMAKE_INSTALL_PREFIX=${INSTALL_DIR} -DBUILD_TESTING=OFF
|
||||
)
|
||||
add_library(libcjwt STATIC SHARED IMPORTED)
|
||||
@@ -218,7 +218,7 @@ if (FEATURE_DNS_QUERY)
|
||||
ExternalProject_Add(ucresolv
|
||||
PREFIX ${CMAKE_CURRENT_BINARY_DIR}/_prefix/ucresolv
|
||||
GIT_REPOSITORY https://github.com/Comcast/libucresolv.git
|
||||
GIT_TAG "master"
|
||||
GIT_TAG "b58d49e165208791f84b44e3c079b1b4ef6d5c9d"
|
||||
CMAKE_ARGS += -DCMAKE_INSTALL_PREFIX=${INSTALL_DIR}
|
||||
)
|
||||
add_library(libucresolv STATIC SHARED IMPORTED)
|
||||
@@ -235,7 +235,7 @@ if (BUILD_TESTING)
|
||||
ExternalProject_Add(cmocka
|
||||
PREFIX ${CMAKE_CURRENT_BINARY_DIR}/_prefix/cmocka
|
||||
GIT_REPOSITORY https://github.com/elventear/cmocka.git
|
||||
GIT_TAG "master"
|
||||
GIT_TAG "b71a3060699bc1a5b00e958be353772f42545ac2"
|
||||
CMAKE_ARGS += -DCMAKE_INSTALL_PREFIX=${INSTALL_DIR}
|
||||
)
|
||||
add_library(libcmocka STATIC SHARED IMPORTED)
|
||||
|
||||
19
README.md
19
README.md
@@ -1,11 +1,16 @@
|
||||
# parodus
|
||||
|
||||
C implementation of the WebPA client coordinator
|
||||
|
||||
[](https://travis-ci.org/Comcast/parodus)
|
||||
[](http://codecov.io/github/Comcast/parodus?branch=master)
|
||||
[](https://scan.coverity.com/projects/comcast-parodus)
|
||||
[](https://github.com/Comcast/parodus/blob/master/LICENSE)
|
||||
[](CHANGELOG.md)
|
||||
|
||||
|
||||
C implementation of the XMiDT client coordinator
|
||||
|
||||
XMiDT is a highly scalable, highly available, generic message routing system.
|
||||
|
||||
# Building and Testing Instructions
|
||||
|
||||
```
|
||||
@@ -50,10 +55,12 @@ make test
|
||||
|
||||
- /force-ipv6 -Forcefully connect parodus to ipv6 address (optional argument)
|
||||
|
||||
- /token-read-script -Script to get webpa auth token for establishing secure connection (absolute path where that script is present) -optional argument
|
||||
- /token-read-script -Script to get auth token for establishing secure connection (absolute path where that script is present) -optional argument
|
||||
|
||||
- /token-acquisition-script -Script to create new auth token for establishing secure connection (absolute path where that script is present) -optional argument
|
||||
|
||||
- /crud-config-file -Config json file to store objects during create, retrieve, update and delete (CRUD) operations -optional argument
|
||||
|
||||
|
||||
# if ENABLE_SESHAT is enabled
|
||||
- /seshat-url - The seshat server url
|
||||
@@ -75,17 +82,17 @@ make test
|
||||
```
|
||||
# Seshat & FEATURE_DNS_QUERY Enabled
|
||||
|
||||
./parodus --hw-model=TGXXX --hw-serial-number=E8GBUEXXXXXXXXX --hw-manufacturer=ARRIS --hw-mac=14cfexxxxxxx --hw-last-reboot-reason=unknown --fw-name=TG1682_DEV_master_20170512115046sdy --boot-time=1494590301 --webpa-ping-timeout=180 --webpa-interface-used=eth0 --webpa-url=somebody.net:8080 --webpa-backoff-max=9 --parodus-local-url=tcp://127.0.0.1:6666 --partner-id=comcast --ssl-cert-path=/etc/ssl/certs/ca-certificates.crt --acquire-jwt=1 --dns-txt-url=somebody.net --jwt-public-key-file=webpa-rs256.pem --jwt-algo=RS256 --seshat-url=tcp://127.0.0.1:7777 --token-read-script=/usr/ccsp/parodus/parodus_token1.sh --token-acquisition-script=/usr/ccsp/parodus/parodus_token2.sh --force-ipv4
|
||||
./parodus --hw-model=TGXXX --hw-serial-number=E8GBUEXXXXXXXXX --hw-manufacturer=ARRIS --hw-mac=14cfexxxxxxx --hw-last-reboot-reason=unknown --fw-name=TG1682_DEV_master_20170512115046sdy --boot-time=1494590301 --webpa-ping-timeout=180 --webpa-interface-used=eth0 --webpa-url=somebody.net:8080 --webpa-backoff-max=9 --parodus-local-url=tcp://127.0.0.1:6666 --partner-id=comcast --ssl-cert-path=/etc/ssl/certs/ca-certificates.crt --acquire-jwt=1 --dns-txt-url=somebody.net --jwt-public-key-file=webpa-rs256.pem --jwt-algo=RS256 --seshat-url=tcp://127.0.0.1:7777 --token-read-script=/usr/ccsp/parodus/parodus_token1.sh --token-acquisition-script=/usr/ccsp/parodus/parodus_token2.sh --force-ipv4 --crud-config-file=/tmp/parodus_cfg.json
|
||||
|
||||
|
||||
# Seshat is not enabled
|
||||
|
||||
./parodus --hw-model=TGXXX --hw-serial-number=E8GBUEXXXXXXXXX --hw-manufacturer=ARRIS --hw-mac=14cfexxxxxxx --hw-last-reboot-reason=unknown --fw-name=TG1682_DEV_master_20170512115046sdy --boot-time=1494590301 --webpa-ping-timeout=180 --webpa-interface-used=eth0 --webpa-url=somebody.net:8080 --webpa-backoff-max=9 --parodus-local-url=tcp://127.0.0.1:6666 --partner-id=comcast --ssl-cert-path=/etc/ssl/certs/ca-certificates.crt --acquire-jwt=1 --dns-txt-url=somebody.net --jwt-public-key-file=webpa-rs256.pem --jwt-algo=RS256 --token-read-script=/usr/ccsp/parodus/parodus_token1.sh --token-acquisition-script=/usr/ccsp/parodus/parodus_token2.sh --force-ipv4
|
||||
./parodus --hw-model=TGXXX --hw-serial-number=E8GBUEXXXXXXXXX --hw-manufacturer=ARRIS --hw-mac=14cfexxxxxxx --hw-last-reboot-reason=unknown --fw-name=TG1682_DEV_master_20170512115046sdy --boot-time=1494590301 --webpa-ping-timeout=180 --webpa-interface-used=eth0 --webpa-url=somebody.net:8080 --webpa-backoff-max=9 --parodus-local-url=tcp://127.0.0.1:6666 --partner-id=comcast --ssl-cert-path=/etc/ssl/certs/ca-certificates.crt --acquire-jwt=1 --dns-txt-url=somebody.net --jwt-public-key-file=webpa-rs256.pem --jwt-algo=RS256 --token-read-script=/usr/ccsp/parodus/parodus_token1.sh --token-acquisition-script=/usr/ccsp/parodus/parodus_token2.sh --force-ipv4 --crud-config-file=/tmp/parodus_cfg.json
|
||||
|
||||
|
||||
# When both Seshat & FEATURE_DNS_QUERY not Enabled
|
||||
|
||||
./parodus --hw-model=TGXXX --hw-serial-number=E8GBUEXXXXXXXXX --hw-manufacturer=ARRIS --hw-mac=14cfexxxxxxx --hw-last-reboot-reason=unknown --fw-name=TG1682_DEV_master_20170512115046sdy --boot-time=1494590301 --webpa-ping-timeout=180 --webpa-interface-used=eth0 --webpa-url=somebody.net:8080 --webpa-backoff-max=9 --parodus-local-url=tcp://127.0.0.1:6666 --partner-id=comcast --ssl-cert-path=/etc/ssl/certs/ca-certificates.crt --token-read-script=/usr/ccsp/parodus/parodus_token1.sh --token-acquisition-script=/usr/ccsp/parodus/parodus_token2.sh --force-ipv4
|
||||
./parodus --hw-model=TGXXX --hw-serial-number=E8GBUEXXXXXXXXX --hw-manufacturer=ARRIS --hw-mac=14cfexxxxxxx --hw-last-reboot-reason=unknown --fw-name=TG1682_DEV_master_20170512115046sdy --boot-time=1494590301 --webpa-ping-timeout=180 --webpa-interface-used=eth0 --webpa-url=somebody.net:8080 --webpa-backoff-max=9 --parodus-local-url=tcp://127.0.0.1:6666 --partner-id=comcast --ssl-cert-path=/etc/ssl/certs/ca-certificates.crt --token-read-script=/usr/ccsp/parodus/parodus_token1.sh --token-acquisition-script=/usr/ccsp/parodus/parodus_token2.sh --force-ipv4 --crud-config-file=/tmp/parodus_cfg.json
|
||||
|
||||
```
|
||||
|
||||
|
||||
@@ -11,10 +11,11 @@
|
||||
# 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.
|
||||
set(SOURCES main.c mutex.c networking.c nopoll_helpers.c nopoll_handlers.c
|
||||
set(SOURCES main.c mutex.c networking.c nopoll_helpers.c heartBeat.c nopoll_handlers.c
|
||||
ParodusInternal.c string_helpers.c time.c config.c conn_interface.c
|
||||
connection.c spin_thread.c client_list.c service_alive.c
|
||||
upstream.c downstream.c thread_tasks.c partners_check.c token.c)
|
||||
upstream.c downstream.c thread_tasks.c partners_check.c token.c
|
||||
crud_interface.c crud_tasks.c crud_internal.c)
|
||||
|
||||
if (ENABLE_SESHAT)
|
||||
set(SOURCES ${SOURCES} seshat_interface.c)
|
||||
|
||||
@@ -121,3 +121,17 @@ char* getWebpaConveyHeader()
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void timespec_diff(struct timespec *start, struct timespec *stop,
|
||||
struct timespec *diff)
|
||||
{
|
||||
if ((stop->tv_nsec - start->tv_nsec) < 0) {
|
||||
diff->tv_sec = stop->tv_sec - start->tv_sec - 1;
|
||||
diff->tv_nsec = stop->tv_nsec - start->tv_nsec + 1000000000UL;
|
||||
} else {
|
||||
diff->tv_sec = stop->tv_sec - start->tv_sec;
|
||||
diff->tv_nsec = stop->tv_nsec - start->tv_nsec;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -80,7 +80,6 @@ typedef struct {
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* File Scoped Variables */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
extern bool LastReasonStatus;
|
||||
extern ParodusMsg *ParodusMsgQ;
|
||||
int numLoops;
|
||||
/*----------------------------------------------------------------------------*/
|
||||
@@ -97,6 +96,12 @@ void parStrncpy(char *destStr, const char *srcStr, size_t destSize);
|
||||
|
||||
char* getWebpaConveyHeader();
|
||||
|
||||
void *CRUDHandlerTask();
|
||||
void addCRUDmsgToQueue(wrp_msg_t *crudMsg);
|
||||
|
||||
void timespec_diff(struct timespec *start, struct timespec *stop,
|
||||
struct timespec *result);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
26
src/config.c
26
src/config.c
@@ -230,6 +230,12 @@ int parse_webpa_url(const char *full_url,
|
||||
parStrncpy (port_buf, "80", port_buflen);
|
||||
else
|
||||
parStrncpy (port_buf, "443", port_buflen);
|
||||
|
||||
end_port = strchr (server_addr, '/');
|
||||
if (NULL != end_port) {
|
||||
*end_port = '\0'; // terminate server address with null
|
||||
}
|
||||
|
||||
} else {
|
||||
*port_val = '\0'; // terminate server address with null
|
||||
port_val++;
|
||||
@@ -293,6 +299,7 @@ int parseCommandLine(int argc,char **argv,ParodusCfg * cfg)
|
||||
{"force-ipv6", no_argument, 0, '6'},
|
||||
{"token-read-script", required_argument, 0, 'T'},
|
||||
{"token-acquisition-script", required_argument, 0, 'J'},
|
||||
{"crud-config-file", required_argument, 0, 'C'},
|
||||
{0, 0, 0, 0}
|
||||
};
|
||||
int c;
|
||||
@@ -307,13 +314,14 @@ int parseCommandLine(int argc,char **argv,ParodusCfg * cfg)
|
||||
cfg->acquire_jwt = 0;
|
||||
cfg->jwt_algo = 0;
|
||||
parStrncpy (cfg->jwt_key, "", sizeof(cfg->jwt_key));
|
||||
cfg->crud_config_file = NULL;
|
||||
optind = 1; /* We need this if parseCommandLine is called again */
|
||||
while (1)
|
||||
{
|
||||
|
||||
/* getopt_long stores the option index here. */
|
||||
int option_index = 0;
|
||||
c = getopt_long (argc, argv, "m:s:f:d:r:n:b:u:t:o:i:l:p:e:D:j:a:k:c:T:J:46",
|
||||
c = getopt_long (argc, argv, "m:s:f:d:r:n:b:u:t:o:i:l:p:e:D:j:a:k:c:T:J:46:C",
|
||||
long_options, &option_index);
|
||||
|
||||
/* Detect the end of the options. */
|
||||
@@ -456,6 +464,11 @@ int parseCommandLine(int argc,char **argv,ParodusCfg * cfg)
|
||||
parStrncpy(cfg->token_read_script, optarg,sizeof(cfg->token_read_script));
|
||||
break;
|
||||
|
||||
case 'C':
|
||||
cfg->crud_config_file = strdup(optarg);
|
||||
ParodusInfo("crud_config_file is %s\n", cfg->crud_config_file);
|
||||
break;
|
||||
|
||||
case '?':
|
||||
/* getopt_long already printed an error message. */
|
||||
break;
|
||||
@@ -585,7 +598,8 @@ void setDefaultValuesToCfg(ParodusCfg *cfg)
|
||||
|
||||
parStrncpy(cfg->webpa_uuid, "1234567-345456546",sizeof(cfg->webpa_uuid));
|
||||
ParodusPrint("cfg->webpa_uuid is :%s\n", cfg->webpa_uuid);
|
||||
|
||||
cfg->crud_config_file = strdup("parodus_cfg.json");
|
||||
ParodusPrint("Default crud_config_file is %s\n", cfg->crud_config_file);
|
||||
}
|
||||
|
||||
void loadParodusCfg(ParodusCfg * config,ParodusCfg *cfg)
|
||||
@@ -750,6 +764,14 @@ void loadParodusCfg(ParodusCfg * config,ParodusCfg *cfg)
|
||||
parStrncpy(cfg->webpa_uuid, "1234567-345456546",sizeof(cfg->webpa_uuid));
|
||||
ParodusPrint("cfg->webpa_uuid is :%s\n", cfg->webpa_uuid);
|
||||
|
||||
if(config->crud_config_file != NULL)
|
||||
{
|
||||
cfg->crud_config_file = strdup(config->crud_config_file);
|
||||
}
|
||||
else
|
||||
{
|
||||
ParodusPrint("crud_config_file is NULL. set to empty\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -93,10 +93,12 @@ typedef struct
|
||||
char webpa_auth_token[4096];
|
||||
char token_acquisition_script[64];
|
||||
char token_read_script[64];
|
||||
char *crud_config_file;
|
||||
} ParodusCfg;
|
||||
|
||||
#define FLAGS_IPV6_ONLY (1 << 0)
|
||||
#define FLAGS_IPV4_ONLY (1 << 1)
|
||||
#define FLAGS_IPV6_IPV4 (FLAGS_IPV6_ONLY | FLAGS_IPV4_ONLY)
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Function Prototypes */
|
||||
|
||||
@@ -33,9 +33,12 @@
|
||||
#include "spin_thread.h"
|
||||
#include "service_alive.h"
|
||||
#include "seshat_interface.h"
|
||||
#include "crud_interface.h"
|
||||
#include "heartBeat.h"
|
||||
#ifdef FEATURE_DNS_QUERY
|
||||
#include <ucresolv_log.h>
|
||||
#endif
|
||||
#include <time.h>
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Macros */
|
||||
@@ -48,24 +51,24 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
bool close_retry = false;
|
||||
bool LastReasonStatus = false;
|
||||
volatile unsigned int heartBeatTimer = 0;
|
||||
pthread_mutex_t close_mut=PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Function Prototypes */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
void timespec_diff(struct timespec *start, struct timespec *stop,
|
||||
struct timespec *result);
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* External Functions */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
void createSocketConnection(void (* initKeypress)())
|
||||
{
|
||||
int intTimer=0;
|
||||
//ParodusCfg *tmpCfg = (ParodusCfg*)config_in;
|
||||
noPollCtx *ctx;
|
||||
bool seshat_registered = false;
|
||||
unsigned int webpa_ping_timeout_ms = 1000 * get_parodus_cfg()->webpa_ping_timeout;
|
||||
unsigned int heartBeatTimer = 0;
|
||||
|
||||
//loadParodusCfg(tmpCfg,get_parodus_cfg());
|
||||
#ifdef FEATURE_DNS_QUERY
|
||||
@@ -92,6 +95,7 @@ void createSocketConnection(void (* initKeypress)())
|
||||
ParodusMsgQ = NULL;
|
||||
StartThread(messageHandlerTask);
|
||||
StartThread(serviceAliveTask);
|
||||
StartThread(CRUDHandlerTask);
|
||||
|
||||
if (NULL != initKeypress)
|
||||
{
|
||||
@@ -102,17 +106,27 @@ void createSocketConnection(void (* initKeypress)())
|
||||
|
||||
do
|
||||
{
|
||||
nopoll_loop_wait(ctx, 5000000);
|
||||
intTimer = intTimer + 5;
|
||||
struct timespec start, stop, diff;
|
||||
int time_taken_ms;
|
||||
|
||||
if(heartBeatTimer >= get_parodus_cfg()->webpa_ping_timeout)
|
||||
clock_gettime(CLOCK_REALTIME, &start);
|
||||
nopoll_loop_wait(ctx, 5000000);
|
||||
clock_gettime(CLOCK_REALTIME, &stop);
|
||||
|
||||
timespec_diff(&start, &stop, &diff);
|
||||
time_taken_ms = diff.tv_sec * 1000 + (diff.tv_nsec / 1000000);
|
||||
|
||||
// ParodusInfo("nopoll_loop_wait() time %d msec\n", time_taken_ms);
|
||||
heartBeatTimer = get_heartBeatTimer();
|
||||
if(heartBeatTimer >= webpa_ping_timeout_ms)
|
||||
{
|
||||
ParodusInfo("heartBeatTimer %d webpa_ping_timeout_ms %d\n", heartBeatTimer, webpa_ping_timeout_ms);
|
||||
if(!close_retry)
|
||||
{
|
||||
ParodusError("ping wait time > %d. Terminating the connection with WebPA server and retrying\n", get_parodus_cfg()->webpa_ping_timeout);
|
||||
ParodusError("ping wait time > %d . Terminating the connection with WebPA server and retrying\n", webpa_ping_timeout_ms / 1000);
|
||||
ParodusInfo("Reconnect detected, setting Ping_Miss reason for Reconnect\n");
|
||||
set_global_reconnect_reason("Ping_Miss");
|
||||
LastReasonStatus = true;
|
||||
set_global_reconnect_status(true);
|
||||
pthread_mutex_lock (&close_mut);
|
||||
close_retry = true;
|
||||
pthread_mutex_unlock (&close_mut);
|
||||
@@ -121,13 +135,10 @@ void createSocketConnection(void (* initKeypress)())
|
||||
{
|
||||
ParodusPrint("heartBeatHandler - close_retry set to %d, hence resetting the heartBeatTimer\n",close_retry);
|
||||
}
|
||||
heartBeatTimer = 0;
|
||||
reset_heartBeatTimer();
|
||||
}
|
||||
else if(intTimer >= 30)
|
||||
{
|
||||
ParodusPrint("heartBeatTimer %d\n",heartBeatTimer);
|
||||
heartBeatTimer += HEARTBEAT_RETRY_SEC;
|
||||
intTimer = 0;
|
||||
else {
|
||||
increment_heartBeatTimer(time_taken_ms);
|
||||
}
|
||||
|
||||
if( false == seshat_registered ) {
|
||||
|
||||
257
src/connection.c
257
src/connection.c
@@ -28,12 +28,14 @@
|
||||
#include "nopoll_helpers.h"
|
||||
#include "mutex.h"
|
||||
#include "spin_thread.h"
|
||||
#include "heartBeat.h"
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Macros */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#define HTTP_CUSTOM_HEADER_COUNT 5
|
||||
#define INITIAL_CJWT_RETRY -2
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* File Scoped Variables */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
@@ -41,10 +43,13 @@
|
||||
char deviceMAC[32]={'\0'};
|
||||
static char *reconnect_reason = "webpa_process_starts";
|
||||
static noPollConn *g_conn = NULL;
|
||||
static bool LastReasonStatus = false;
|
||||
static noPollConnOpts * createConnOpts (char * extra_headers, bool secure);
|
||||
static noPollConn * nopoll_tls_common_conn (noPollCtx * ctx,char * serverAddr,char *serverPort,char * extra_headers);
|
||||
static noPollConn * nopoll_tls_common_conn (noPollCtx * ctx,char * serverAddr,char *serverPort,char * extra_headers,unsigned int *fallback);
|
||||
static char* build_extra_headers( const char *auth, const char *device_id,
|
||||
const char *user_agent, const char *convey );
|
||||
static void toggleIPFlag (unsigned int *ptrFallback);
|
||||
static noPollConn * __internal_fallbackConn(noPollCtx * ctx,noPollConnOpts * opts,char * serverAddr,char *serverPort,char * extra_headers,unsigned int *fallback);
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* External Functions */
|
||||
@@ -69,6 +74,25 @@ void set_global_reconnect_reason(char *reason)
|
||||
reconnect_reason = reason;
|
||||
}
|
||||
|
||||
bool get_global_reconnect_status()
|
||||
{
|
||||
return LastReasonStatus;
|
||||
}
|
||||
|
||||
void set_global_reconnect_status(bool status)
|
||||
{
|
||||
LastReasonStatus = status;
|
||||
}
|
||||
|
||||
// If IPv6 conn failed to connect then fallback to IPv4 conn or vice-versa
|
||||
static void toggleIPFlag (unsigned int *ptrFallback)
|
||||
{
|
||||
if(FLAGS_IPV6_ONLY == (FLAGS_IPV6_IPV4 & *ptrFallback))
|
||||
*ptrFallback = FLAGS_IPV4_ONLY;
|
||||
else
|
||||
*ptrFallback = FLAGS_IPV6_ONLY;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief createNopollConnection interface to create WebSocket client connections.
|
||||
*Loads the WebPA config file and creates the intial connection and manages the connection wait, close mechanisms.
|
||||
@@ -80,9 +104,11 @@ int createNopollConnection(noPollCtx *ctx)
|
||||
int max_retry_sleep;
|
||||
char port[8];
|
||||
char server_Address[256];
|
||||
char redirectURL[128]={'\0'};
|
||||
char *jwt_server_url= NULL;
|
||||
char *redirectURL = NULL;
|
||||
int status=0;
|
||||
int allow_insecure;
|
||||
int allow_insecure = -1;
|
||||
int jwt_status = INITIAL_CJWT_RETRY;
|
||||
int connErr=0;
|
||||
struct timespec connErr_start,connErr_end,*connErr_startPtr,*connErr_endPtr;
|
||||
connErr_startPtr = &connErr_start;
|
||||
@@ -90,9 +116,10 @@ int createNopollConnection(noPollCtx *ctx)
|
||||
//Retry Backoff count shall start at c=2 & calculate 2^c - 1.
|
||||
int c=2;
|
||||
char *conveyHeader = NULL;
|
||||
char device_id[32]={'\0'};
|
||||
char device_id[36]={'\0'};
|
||||
char user_agent[512]={'\0'};
|
||||
char * extra_headers = NULL;
|
||||
unsigned int fallback = FLAGS_IPV6_ONLY;
|
||||
|
||||
if(ctx == NULL) {
|
||||
return nopoll_false;
|
||||
@@ -101,23 +128,6 @@ int createNopollConnection(noPollCtx *ctx)
|
||||
ParodusPrint("BootTime In sec: %d\n", get_parodus_cfg()->boot_time);
|
||||
ParodusInfo("Received reboot_reason as:%s\n", get_parodus_cfg()->hw_last_reboot_reason);
|
||||
ParodusInfo("Received reconnect_reason as:%s\n", reconnect_reason);
|
||||
allow_insecure = parse_webpa_url (get_parodus_cfg()->webpa_url,
|
||||
server_Address, (int) sizeof(server_Address),
|
||||
port, (int) sizeof(port));
|
||||
if (allow_insecure < 0)
|
||||
return nopoll_false; // must have valid default url
|
||||
#ifdef FEATURE_DNS_QUERY
|
||||
if (get_parodus_cfg()->acquire_jwt) {
|
||||
//query dns and validate JWT
|
||||
int jwt_insecure = allow_insecure_conn(
|
||||
server_Address, (int) sizeof(server_Address),
|
||||
port, (int) sizeof(port));
|
||||
if (jwt_insecure >= 0)
|
||||
allow_insecure = jwt_insecure;
|
||||
}
|
||||
#endif
|
||||
ParodusInfo("server_Address %s\n",server_Address);
|
||||
ParodusInfo("port %s\n", port);
|
||||
|
||||
max_retry_sleep = (int) get_parodus_cfg()->webpa_backoff_max;
|
||||
ParodusPrint("max_retry_sleep is %d\n", max_retry_sleep );
|
||||
@@ -147,10 +157,44 @@ int createNopollConnection(noPollCtx *ctx)
|
||||
}
|
||||
ParodusPrint("New backoffRetryTime value calculated as %d seconds\n", backoffRetryTime);
|
||||
noPollConn *connection;
|
||||
//retry jwt validation on query dns failure
|
||||
if((jwt_status == INITIAL_CJWT_RETRY) || (jwt_status == TOKEN_ERR_QUERY_DNS_FAIL))
|
||||
{
|
||||
allow_insecure = parse_webpa_url (get_parodus_cfg()->webpa_url,
|
||||
server_Address, (int) sizeof(server_Address),
|
||||
port, (int) sizeof(port));
|
||||
if (allow_insecure < 0)
|
||||
return nopoll_false; // must have valid default url
|
||||
#ifdef FEATURE_DNS_QUERY
|
||||
if (get_parodus_cfg()->acquire_jwt) {
|
||||
//query dns and validate JWT
|
||||
jwt_status = allow_insecure_conn(
|
||||
server_Address, (int) sizeof(server_Address),
|
||||
port, (int) sizeof(port));
|
||||
|
||||
//store server_Address as jwt_server_url to use it for JWT retry scenarios
|
||||
jwt_server_url = strdup(server_Address);
|
||||
if (jwt_server_url !=NULL)
|
||||
ParodusInfo("JWT ON: jwt_server_url stored as %s\n", jwt_server_url);
|
||||
|
||||
if (jwt_status >= 0)
|
||||
allow_insecure = jwt_status;
|
||||
}
|
||||
else
|
||||
{
|
||||
ParodusInfo("JWT validation is disabled\n");
|
||||
jwt_status = 1;
|
||||
}
|
||||
#else
|
||||
jwt_status = 1;
|
||||
#endif
|
||||
ParodusInfo("server_Address %s\n",server_Address);
|
||||
ParodusInfo("port %s\n", port);
|
||||
}
|
||||
if(allow_insecure <= 0)
|
||||
{
|
||||
ParodusPrint("secure true\n");
|
||||
connection = nopoll_tls_common_conn(ctx,server_Address, port, extra_headers);
|
||||
connection = nopoll_tls_common_conn(ctx,server_Address, port, extra_headers,&fallback);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -168,13 +212,32 @@ int createNopollConnection(noPollCtx *ctx)
|
||||
ParodusError("Error connecting to server\n");
|
||||
ParodusError("RDK-10037 - WebPA Connection Lost\n");
|
||||
// Copy the server address from config to avoid retrying to the same failing talaria redirected node
|
||||
allow_insecure = parse_webpa_url (get_parodus_cfg()->webpa_url,
|
||||
if (get_parodus_cfg()->acquire_jwt == 0)
|
||||
{
|
||||
ParodusInfo("acquire_jwt is 0, retrying with config server address\n");
|
||||
allow_insecure = parse_webpa_url (get_parodus_cfg()->webpa_url,
|
||||
server_Address, (int) sizeof(server_Address),
|
||||
port, (int) sizeof(port));
|
||||
}
|
||||
else
|
||||
{
|
||||
if( (jwt_server_url != NULL) && strlen(jwt_server_url) != 0 )
|
||||
{
|
||||
ParodusInfo("acquire_jwt is 1, retrying with jwt_server_url\n");
|
||||
parStrncpy(server_Address, jwt_server_url, sizeof(server_Address));
|
||||
}
|
||||
else
|
||||
{
|
||||
ParodusError("acquire_jwt is 1 & unable to get jwt_server_url, retrying with config server address\n");
|
||||
allow_insecure = parse_webpa_url (get_parodus_cfg()->webpa_url, server_Address, (int) sizeof(server_Address), port, (int) sizeof(port));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
close_and_unref_connection(get_global_conn());
|
||||
set_global_conn(NULL);
|
||||
initial_retry = true;
|
||||
|
||||
toggleIPFlag(&fallback);
|
||||
ParodusInfo("Waiting with backoffRetryTime %d seconds\n", backoffRetryTime);
|
||||
sleep(backoffRetryTime);
|
||||
continue;
|
||||
@@ -188,24 +251,41 @@ int createNopollConnection(noPollCtx *ctx)
|
||||
backoffRetryTime = (int) pow(2, c) -1;
|
||||
}
|
||||
|
||||
if(!nopoll_conn_wait_until_connection_ready(get_global_conn(), 10, &status, redirectURL))
|
||||
if(!nopoll_conn_wait_for_status_until_connection_ready(get_global_conn(), 10, &status, &redirectURL))
|
||||
{
|
||||
|
||||
if(status == 307 || status == 302 || status == 303) // only when there is a http redirect
|
||||
{
|
||||
char *redirect_ptr = redirectURL;
|
||||
ParodusError("Received temporary redirection response message %s\n", redirectURL);
|
||||
// Extract server Address and port from the redirectURL
|
||||
if (strncmp (redirect_ptr, "Redirect:", 9) == 0)
|
||||
redirect_ptr += 9;
|
||||
allow_insecure = parse_webpa_url (redirect_ptr,
|
||||
if (strncmp (redirectURL, "Redirect:", 9) == 0)
|
||||
redirectURL += 9;
|
||||
allow_insecure = parse_webpa_url (redirectURL,
|
||||
server_Address, (int) sizeof(server_Address),
|
||||
port, (int) sizeof(port));
|
||||
if (allow_insecure < 0) {
|
||||
ParodusError ("Invalid redirectURL\n");
|
||||
allow_insecure = parse_webpa_url (get_parodus_cfg()->webpa_url,
|
||||
server_Address, (int) sizeof(server_Address),
|
||||
port, (int) sizeof(port));
|
||||
|
||||
if (get_parodus_cfg()->acquire_jwt == 0)
|
||||
{
|
||||
ParodusInfo("acquire_jwt is 0, retrying with config server address\n");
|
||||
allow_insecure = parse_webpa_url (get_parodus_cfg()->webpa_url, server_Address, (int) sizeof(server_Address), port, (int) sizeof(port));
|
||||
}
|
||||
else
|
||||
{
|
||||
if( (jwt_server_url != NULL) && strlen(jwt_server_url) != 0 )
|
||||
{
|
||||
ParodusInfo("acquire_jwt is 1, retrying with jwt_server_url\n");
|
||||
parStrncpy(server_Address, jwt_server_url, sizeof(server_Address));
|
||||
}
|
||||
else
|
||||
{
|
||||
ParodusError("acquire_jwt is 1 & unable to get jwt_server_url, retrying with config server address\n");
|
||||
allow_insecure = parse_webpa_url (get_parodus_cfg()->webpa_url, server_Address, (int) sizeof(server_Address), port, (int) sizeof(port));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
} else
|
||||
ParodusInfo("Trying to Connect to new Redirected server : %s with port : %s\n", server_Address, port);
|
||||
//reset c=2 to start backoffRetryTime as retrying using new redirect server
|
||||
@@ -231,11 +311,30 @@ int createNopollConnection(noPollCtx *ctx)
|
||||
ParodusError("Client connection timeout\n");
|
||||
ParodusError("RDK-10037 - WebPA Connection Lost\n");
|
||||
// Copy the server address and port from config to avoid retrying to the same failing talaria redirected node
|
||||
allow_insecure = parse_webpa_url (get_parodus_cfg()->webpa_url,
|
||||
server_Address, (int) sizeof(server_Address),
|
||||
port, (int) sizeof(port));
|
||||
|
||||
if (get_parodus_cfg()->acquire_jwt == 0)
|
||||
{
|
||||
ParodusInfo("acquire_jwt is 0, retrying with config server address\n");
|
||||
allow_insecure = parse_webpa_url (get_parodus_cfg()->webpa_url, server_Address, (int) sizeof(server_Address), port, (int) sizeof(port));
|
||||
}
|
||||
else
|
||||
{
|
||||
if( (jwt_server_url != NULL) && strlen(jwt_server_url) != 0 )
|
||||
{
|
||||
ParodusInfo("acquire_jwt is 1, retrying with jwt_server_url\n");
|
||||
parStrncpy(server_Address, jwt_server_url, sizeof(server_Address));
|
||||
}
|
||||
else
|
||||
{
|
||||
ParodusError("acquire_jwt is 1 & unable to get jwt_server_url, retrying with config server address\n");
|
||||
allow_insecure = parse_webpa_url (get_parodus_cfg()->webpa_url, server_Address, (int) sizeof(server_Address), port, (int) sizeof(port));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
ParodusInfo("Waiting with backoffRetryTime %d seconds\n", backoffRetryTime);
|
||||
sleep(backoffRetryTime);
|
||||
toggleIPFlag(&fallback);
|
||||
c++;
|
||||
}
|
||||
//reset httpStatus before next retry
|
||||
@@ -273,21 +372,39 @@ int createNopollConnection(noPollCtx *ctx)
|
||||
if(timeValDiff(connErr_startPtr, connErr_endPtr) >= (15*60*1000))
|
||||
{
|
||||
ParodusError("WebPA unable to connect due to DNS resolving to 10.0.0.1 for over 15 minutes; crashing service.\n");
|
||||
reconnect_reason = "Dns_Res_webpa_reconnect";
|
||||
LastReasonStatus = true;
|
||||
set_global_reconnect_reason("Dns_Res_webpa_reconnect");
|
||||
set_global_reconnect_status(true);
|
||||
|
||||
kill(getpid(),SIGTERM);
|
||||
}
|
||||
}
|
||||
}
|
||||
initial_retry = true;
|
||||
toggleIPFlag(&fallback);
|
||||
ParodusInfo("Waiting with backoffRetryTime %d seconds\n", backoffRetryTime);
|
||||
sleep(backoffRetryTime);
|
||||
c++;
|
||||
// Copy the server address and port from config to avoid retrying to the same failing talaria redirected node
|
||||
allow_insecure = parse_webpa_url (get_parodus_cfg()->webpa_url,
|
||||
server_Address, (int) sizeof(server_Address),
|
||||
port, (int) sizeof(port));
|
||||
|
||||
if (get_parodus_cfg()->acquire_jwt == 0)
|
||||
{
|
||||
ParodusInfo("acquire_jwt is 0, retrying with config server address\n");
|
||||
allow_insecure = parse_webpa_url (get_parodus_cfg()->webpa_url, server_Address, (int) sizeof(server_Address), port, (int) sizeof(port));
|
||||
}
|
||||
else
|
||||
{
|
||||
if( (jwt_server_url != NULL) && strlen(jwt_server_url) != 0 )
|
||||
{
|
||||
ParodusInfo("acquire_jwt is 1, retrying with jwt_server_url\n");
|
||||
parStrncpy(server_Address, jwt_server_url, sizeof(server_Address));
|
||||
}
|
||||
else
|
||||
{
|
||||
ParodusError("acquire_jwt is 1 & unable to get jwt_server_url, retrying with config server address\n");
|
||||
allow_insecure = parse_webpa_url (get_parodus_cfg()->webpa_url, server_Address, (int) sizeof(server_Address), port, (int) sizeof(port));
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}while(initial_retry);
|
||||
@@ -301,17 +418,35 @@ int createNopollConnection(noPollCtx *ctx)
|
||||
ParodusInfo("Connected to server\n");
|
||||
}
|
||||
|
||||
|
||||
if (NULL != jwt_server_url)
|
||||
{
|
||||
free (jwt_server_url);
|
||||
}
|
||||
|
||||
if(redirectURL != NULL)
|
||||
{
|
||||
free(redirectURL);
|
||||
redirectURL = NULL;
|
||||
}
|
||||
|
||||
if (NULL != extra_headers)
|
||||
{
|
||||
free (extra_headers);
|
||||
extra_headers = NULL;
|
||||
}
|
||||
|
||||
// Reset close_retry flag and heartbeatTimer once the connection retry is successful
|
||||
ParodusPrint("createNopollConnection(): close_mut lock\n");
|
||||
pthread_mutex_lock (&close_mut);
|
||||
close_retry = false;
|
||||
pthread_mutex_unlock (&close_mut);
|
||||
ParodusPrint("createNopollConnection(): close_mut unlock\n");
|
||||
heartBeatTimer = 0;
|
||||
reset_heartBeatTimer();
|
||||
// Reset connErr flag on successful connection
|
||||
connErr = 0;
|
||||
reconnect_reason = "webpa_process_starts";
|
||||
LastReasonStatus =false;
|
||||
set_global_reconnect_reason("webpa_process_starts");
|
||||
set_global_reconnect_status(false);
|
||||
ParodusPrint("LastReasonStatus reset after successful connection\n");
|
||||
setMessageHandlers();
|
||||
|
||||
@@ -337,7 +472,7 @@ static char* build_extra_headers( const char *auth, const char *device_id,
|
||||
(NULL != convey) ? convey : "" );
|
||||
}
|
||||
|
||||
static noPollConn * nopoll_tls_common_conn (noPollCtx * ctx,char * serverAddr,char *serverPort,char * extra_headers)
|
||||
static noPollConn * nopoll_tls_common_conn (noPollCtx * ctx,char * serverAddr,char *serverPort,char * extra_headers,unsigned int *fallback)
|
||||
{
|
||||
unsigned int flags = 0;
|
||||
noPollConnOpts * opts;
|
||||
@@ -353,18 +488,36 @@ static noPollConn * nopoll_tls_common_conn (noPollCtx * ctx,char * serverAddr,c
|
||||
ParodusInfo("Connecting in Ipv6 mode\n");
|
||||
connection = nopoll_conn_tls_new6 (ctx, opts,serverAddr,serverPort,NULL,get_parodus_cfg()->webpa_path_url,NULL,NULL);
|
||||
} else {
|
||||
ParodusInfo("Try connecting with Ipv6 mode\n");
|
||||
connection = nopoll_conn_tls_new6 (ctx, opts,serverAddr,serverPort,NULL,get_parodus_cfg()->webpa_path_url,NULL,NULL);
|
||||
if(connection == NULL)
|
||||
{
|
||||
ParodusInfo("Ipv6 connection failed. Try connecting with Ipv4 mode \n");
|
||||
opts = createConnOpts(extra_headers, true);
|
||||
connection = nopoll_conn_tls_new (ctx, opts,serverAddr,serverPort,NULL,get_parodus_cfg()->webpa_path_url,NULL,NULL);
|
||||
}
|
||||
|
||||
connection = __internal_fallbackConn(ctx,opts,serverAddr,serverPort,extra_headers,fallback);
|
||||
}
|
||||
return connection;
|
||||
}
|
||||
|
||||
static noPollConn * __internal_fallbackConn(noPollCtx * ctx,noPollConnOpts * opts,char * serverAddr,char *serverPort,char * extra_headers,unsigned int *fallback)
|
||||
{
|
||||
noPollConn *connection = NULL;
|
||||
|
||||
if(FLAGS_IPV6_ONLY == (FLAGS_IPV6_IPV4 & *fallback))
|
||||
{
|
||||
ParodusInfo("Try connecting with Ipv6 mode\n");
|
||||
connection = nopoll_conn_tls_new6 (ctx, opts,serverAddr,serverPort,NULL,get_parodus_cfg()->webpa_path_url,NULL,NULL);
|
||||
}
|
||||
if(FLAGS_IPV4_ONLY == (FLAGS_IPV6_IPV4 & *fallback) || !nopoll_conn_is_ok (connection) )
|
||||
{
|
||||
ParodusInfo("Ipv6 connection failed. Try connecting with Ipv4 mode \n");
|
||||
|
||||
// fallback is to detect the current connection mode either IPv6/IPv4. if the fallback flag is true for IPv6 connection, then change it here to IPv4. or if the fallback flag is already in IPv4 mode, then skip it.
|
||||
if(!nopoll_conn_is_ok (connection) && FLAGS_IPV6_ONLY == (FLAGS_IPV6_IPV4 & *fallback))
|
||||
toggleIPFlag(fallback);
|
||||
|
||||
opts = createConnOpts(extra_headers, true);
|
||||
connection = nopoll_conn_tls_new (ctx, opts,serverAddr,serverPort,NULL,get_parodus_cfg()->webpa_path_url,NULL,NULL);
|
||||
}
|
||||
|
||||
return connection;
|
||||
}
|
||||
|
||||
static noPollConnOpts * createConnOpts (char * extra_headers, bool secure)
|
||||
{
|
||||
noPollConnOpts * opts;
|
||||
|
||||
@@ -35,7 +35,6 @@ extern "C" {
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
extern bool close_retry;
|
||||
extern volatile unsigned int heartBeatTimer;
|
||||
extern pthread_mutex_t close_mut;
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
@@ -55,6 +54,9 @@ void set_global_conn(noPollConn *);
|
||||
char *get_global_reconnect_reason();
|
||||
void set_global_reconnect_reason(char *reason);
|
||||
|
||||
bool get_global_reconnect_status();
|
||||
void set_global_reconnect_status(bool status);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
173
src/crud_interface.c
Normal file
173
src/crud_interface.c
Normal file
@@ -0,0 +1,173 @@
|
||||
/**
|
||||
* Copyright 2015 Comcast Cable Communications Management, LLC
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
/**
|
||||
* @file crud_interface.c
|
||||
*
|
||||
* @description This file is used to manage incoming and outgoing CRUD messages.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "ParodusInternal.h"
|
||||
#include "crud_tasks.h"
|
||||
#include "crud_interface.h"
|
||||
#include "upstream.h"
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Macros */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
pthread_mutex_t crud_mut=PTHREAD_MUTEX_INITIALIZER;
|
||||
pthread_cond_t crud_con=PTHREAD_COND_INITIALIZER;
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Internal variables */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
CrudMsg *crudMsgQ = NULL;
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* External functions */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
void addCRUDmsgToQueue(wrp_msg_t *crudMsg)
|
||||
{
|
||||
CrudMsg * crudMessage;
|
||||
crudMessage = (CrudMsg *)malloc(sizeof(CrudMsg));
|
||||
if(crudMessage && crudMsg!=NULL)
|
||||
{
|
||||
crudMessage->msg = crudMsg;
|
||||
crudMessage->next = NULL;
|
||||
ParodusPrint("Inside addCRUDmsgToQueue : mutex lock in producer \n");
|
||||
pthread_mutex_lock(&crud_mut);
|
||||
if(crudMsgQ ==NULL)
|
||||
{
|
||||
crudMsgQ = crudMessage;
|
||||
ParodusPrint("Producer added message\n");
|
||||
pthread_cond_signal(&crud_con);
|
||||
pthread_mutex_unlock(&crud_mut);
|
||||
ParodusPrint("Inside addCRUDmsgToQueue : mutex unlock in producer \n");
|
||||
}
|
||||
else
|
||||
{
|
||||
CrudMsg *temp = crudMsgQ;
|
||||
while(temp->next)
|
||||
{
|
||||
temp = temp->next;
|
||||
}
|
||||
temp->next = crudMessage;
|
||||
pthread_mutex_unlock(&crud_mut);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ParodusError("Memory allocation failed for CRUD\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void *CRUDHandlerTask()
|
||||
{
|
||||
int ret = 0;
|
||||
ssize_t resp_size = 0;
|
||||
void *resp_bytes;
|
||||
wrp_msg_t *crud_response = NULL;
|
||||
|
||||
while(FOREVER())
|
||||
{
|
||||
pthread_mutex_lock(&crud_mut);
|
||||
ParodusPrint("Mutex lock in CRUD consumer thread\n");
|
||||
|
||||
if(crudMsgQ !=NULL)
|
||||
{
|
||||
CrudMsg *message = crudMsgQ;
|
||||
crudMsgQ = crudMsgQ->next;
|
||||
pthread_mutex_unlock(&crud_mut);
|
||||
ParodusPrint("Mutex unlock in CRUD consumer thread\n");
|
||||
|
||||
ret = processCrudRequest(message->msg, &crud_response);
|
||||
wrp_free_struct(message->msg);
|
||||
free(message);
|
||||
message = NULL;
|
||||
|
||||
if(ret == 0)
|
||||
{
|
||||
ParodusInfo("CRUD processed successfully\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
ParodusError("Failure in CRUD request processing !!\n");
|
||||
}
|
||||
ParodusPrint("msgpack encode to send to upstream\n");
|
||||
resp_size = wrp_struct_to( crud_response, WRP_BYTES, &resp_bytes );
|
||||
ParodusPrint("Encoded CRUD resp_size :%lu\n", resp_size);
|
||||
|
||||
ParodusPrint("Adding CRUD response to upstreamQ\n");
|
||||
addCRUDresponseToUpstreamQ(resp_bytes, resp_size);
|
||||
wrp_free_struct(crud_response);
|
||||
}
|
||||
else
|
||||
{
|
||||
pthread_cond_wait(&crud_con, &crud_mut);
|
||||
pthread_mutex_unlock (&crud_mut);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
//CRUD Producer adds the response into common UpStreamQ
|
||||
void addCRUDresponseToUpstreamQ(void *response_bytes, ssize_t response_size)
|
||||
{
|
||||
UpStreamMsg *response;
|
||||
|
||||
response = (UpStreamMsg *)malloc(sizeof(UpStreamMsg));
|
||||
if(response)
|
||||
{
|
||||
response->msg =(void *)response_bytes;
|
||||
response->len =(int)response_size;
|
||||
response->next=NULL;
|
||||
pthread_mutex_lock (get_global_nano_mut());
|
||||
ParodusPrint("Mutex lock in CRUD response producer\n");
|
||||
|
||||
if(get_global_UpStreamMsgQ() == NULL)
|
||||
{
|
||||
set_global_UpStreamMsgQ(response);
|
||||
ParodusPrint("Producer added CRUD response to UpStreamQ\n");
|
||||
pthread_cond_signal(get_global_nano_con());
|
||||
pthread_mutex_unlock (get_global_nano_mut());
|
||||
ParodusPrint("mutex unlock in CRUD response producer\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
ParodusPrint("Producer adding CRUD response to UpStreamQ\n");
|
||||
UpStreamMsg *temp = get_global_UpStreamMsgQ();
|
||||
while(temp->next)
|
||||
{
|
||||
temp = temp->next;
|
||||
}
|
||||
temp->next = response;
|
||||
pthread_mutex_unlock (get_global_nano_mut());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ParodusError("failure in allocation for CRUD response\n");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
55
src/crud_interface.h
Normal file
55
src/crud_interface.h
Normal file
@@ -0,0 +1,55 @@
|
||||
/**
|
||||
* Copyright 2015 Comcast Cable Communications Management, LLC
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
/**
|
||||
* @file crud_interface.h
|
||||
*
|
||||
* @description This header defines functions required to manage CRUD messages.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _CRUD_INTERFACE_H_
|
||||
#define _CRUD_INTERFACE_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Data Structures */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
typedef struct CrudMsg__
|
||||
{
|
||||
wrp_msg_t *msg;
|
||||
struct CrudMsg__ *next;
|
||||
} CrudMsg;
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Function Prototypes */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
//void *CRUDHandlerTask();
|
||||
//void addCRUDmsgToQueue(wrp_msg_t *crudMsg);
|
||||
void addCRUDresponseToUpstreamQ(void *response_bytes, ssize_t response_size);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* _CRUD_INTERFACE_H_ */
|
||||
|
||||
1452
src/crud_internal.c
Normal file
1452
src/crud_internal.c
Normal file
File diff suppressed because it is too large
Load Diff
27
src/crud_internal.h
Normal file
27
src/crud_internal.h
Normal file
@@ -0,0 +1,27 @@
|
||||
/**
|
||||
* Copyright 2016 Comcast Cable Communications Management, LLC
|
||||
*
|
||||
* 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 <wrp-c.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int createObject( wrp_msg_t *reqMsg, wrp_msg_t **response );
|
||||
int retrieveObject( wrp_msg_t *reqMsg, wrp_msg_t **response);
|
||||
int updateObject( wrp_msg_t *reqMsg, wrp_msg_t **response);
|
||||
int deleteObject(wrp_msg_t *reqMsg, wrp_msg_t **response);
|
||||
|
||||
int writeToJSON(char *data);
|
||||
int readFromJSON(char **data);
|
||||
int retrieveFromMemory(char *keyName, cJSON **jsonresponse);
|
||||
109
src/crud_tasks.c
Normal file
109
src/crud_tasks.c
Normal file
@@ -0,0 +1,109 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <cJSON.h>
|
||||
#include <wrp-c.h>
|
||||
#include "crud_tasks.h"
|
||||
#include "crud_internal.h"
|
||||
|
||||
|
||||
int processCrudRequest( wrp_msg_t *reqMsg, wrp_msg_t **responseMsg)
|
||||
{
|
||||
wrp_msg_t *resp_msg = NULL;
|
||||
int ret = -1;
|
||||
|
||||
resp_msg = ( wrp_msg_t *)malloc( sizeof( wrp_msg_t ) );
|
||||
memset(resp_msg, 0, sizeof(wrp_msg_t));
|
||||
|
||||
resp_msg->msg_type = reqMsg->msg_type;
|
||||
resp_msg->u.crud.transaction_uuid = strdup(reqMsg->u.crud.transaction_uuid);
|
||||
resp_msg->u.crud.source = strdup(reqMsg->u.crud.dest);
|
||||
resp_msg->u.crud.dest = strdup(reqMsg->u.crud.source);
|
||||
|
||||
switch( reqMsg->msg_type )
|
||||
{
|
||||
|
||||
case WRP_MSG_TYPE__CREATE:
|
||||
ParodusInfo( "CREATE request\n" );
|
||||
|
||||
ret = createObject( reqMsg, &resp_msg );
|
||||
|
||||
if(ret != 0)
|
||||
{
|
||||
ParodusError("Failed to create object in config JSON\n");
|
||||
|
||||
//WRP payload is NULL for failure cases
|
||||
resp_msg ->u.crud.payload = NULL;
|
||||
resp_msg ->u.crud.payload_size = 0;
|
||||
*responseMsg = resp_msg;
|
||||
return -1;
|
||||
}
|
||||
|
||||
*responseMsg = resp_msg;
|
||||
break;
|
||||
|
||||
case WRP_MSG_TYPE__RETREIVE:
|
||||
ParodusInfo( "RETREIVE request\n" );
|
||||
|
||||
ret = retrieveObject( reqMsg, &resp_msg );
|
||||
if(ret != 0)
|
||||
{
|
||||
ParodusError("Failed to retrieve object \n");
|
||||
|
||||
//WRP payload is NULL for failure cases
|
||||
resp_msg ->u.crud.payload = NULL;
|
||||
resp_msg ->u.crud.payload_size = 0;
|
||||
*responseMsg = resp_msg;
|
||||
return -1;
|
||||
}
|
||||
|
||||
*responseMsg = resp_msg;
|
||||
break;
|
||||
|
||||
case WRP_MSG_TYPE__UPDATE:
|
||||
ParodusInfo( "UPDATE request\n" );
|
||||
|
||||
ret = updateObject( reqMsg, &resp_msg );
|
||||
if(ret ==0)
|
||||
{
|
||||
//WRP payload is NULL for update requests
|
||||
resp_msg ->u.crud.payload = NULL;
|
||||
resp_msg ->u.crud.payload_size = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
ParodusError("Failed to update object \n");
|
||||
*responseMsg = resp_msg;
|
||||
return -1;
|
||||
}
|
||||
*responseMsg = resp_msg;
|
||||
break;
|
||||
|
||||
case WRP_MSG_TYPE__DELETE:
|
||||
ParodusInfo( "DELETE request\n" );
|
||||
|
||||
ret = deleteObject(reqMsg, &resp_msg );
|
||||
if(ret == 0)
|
||||
{
|
||||
//WRP payload is NULL for delete requests
|
||||
resp_msg ->u.crud.payload = NULL;
|
||||
resp_msg ->u.crud.payload_size = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
ParodusError("Failed to delete object \n");
|
||||
*responseMsg = resp_msg;
|
||||
return -1;
|
||||
}
|
||||
*responseMsg = resp_msg;
|
||||
break;
|
||||
|
||||
default:
|
||||
ParodusInfo( "Unknown msgType for CRUD request\n" );
|
||||
*responseMsg = resp_msg;
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
31
src/crud_tasks.h
Normal file
31
src/crud_tasks.h
Normal file
@@ -0,0 +1,31 @@
|
||||
/**
|
||||
* Copyright 2016 Comcast Cable Communications Management, LLC
|
||||
*
|
||||
* 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 <wrp-c.h>
|
||||
#include "ParodusInternal.h"
|
||||
|
||||
/**
|
||||
* @brief processCrudRequest function to process CRUD operations.
|
||||
*
|
||||
* @note processCrudRequest function allocates memory for response,
|
||||
* caller needs to free the response (resMsg) in both success and failure case.
|
||||
* @param[in] decoded request in wrp_msg_t structure format
|
||||
* @param[out] resulting wrp_msg_t structure as a response
|
||||
* @return 0 in success case and -1 in error case
|
||||
*/
|
||||
int processCrudRequest(wrp_msg_t * reqMsg, wrp_msg_t **resMsg);
|
||||
@@ -26,6 +26,7 @@
|
||||
#include "connection.h"
|
||||
#include "partners_check.h"
|
||||
#include "ParodusInternal.h"
|
||||
#include "crud_interface.h"
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* External Functions */
|
||||
@@ -93,16 +94,32 @@ void listenerOnMessage(void * msg, size_t msgSize)
|
||||
cJSON_AddStringToObject(response, "message", "Invalid partner_id");
|
||||
}
|
||||
|
||||
destVal = ((WRP_MSG_TYPE__EVENT == msgType) ? message->u.event.dest :
|
||||
((WRP_MSG_TYPE__REQ == msgType) ? message->u.req.dest : message->u.crud.dest));
|
||||
|
||||
destVal = strdup(((WRP_MSG_TYPE__EVENT == msgType) ? message->u.event.dest :
|
||||
((WRP_MSG_TYPE__REQ == msgType) ? message->u.req.dest : message->u.crud.dest)));
|
||||
|
||||
if( (destVal != NULL) && (ret >= 0) )
|
||||
{
|
||||
strtok(destVal , "/");
|
||||
parStrncpy(dest,strtok(NULL , "/"), sizeof(dest));
|
||||
char *newDest = NULL;
|
||||
char *tempDest = strtok(destVal , "/");
|
||||
if(tempDest != NULL)
|
||||
{
|
||||
newDest = strtok(NULL , "/");
|
||||
}
|
||||
if(newDest != NULL)
|
||||
{
|
||||
parStrncpy(dest,newDest, sizeof(dest));
|
||||
}
|
||||
else
|
||||
{
|
||||
parStrncpy(dest,destVal, sizeof(dest));
|
||||
}
|
||||
ParodusInfo("Received downstream dest as :%s and transaction_uuid :%s\n", dest,
|
||||
((WRP_MSG_TYPE__REQ == msgType) ? message->u.req.transaction_uuid :
|
||||
((WRP_MSG_TYPE__EVENT == msgType) ? "NA" : message->u.crud.transaction_uuid)));
|
||||
temp = get_global_node();
|
||||
|
||||
free(destVal);
|
||||
temp = get_global_node();
|
||||
//Checking for individual clients & Sending to each client
|
||||
|
||||
while (NULL != temp)
|
||||
@@ -122,7 +139,25 @@ void listenerOnMessage(void * msg, size_t msgSize)
|
||||
temp= temp->next;
|
||||
}
|
||||
|
||||
//if any unknown dest received sending error response to server
|
||||
/* check Downstream dest for CRUD requests */
|
||||
if(destFlag ==0 && strcmp("parodus", dest)==0)
|
||||
{
|
||||
ParodusPrint("Received CRUD request : dest : %s\n", dest);
|
||||
if ((message->u.crud.source == NULL) || (message->u.crud.transaction_uuid == NULL))
|
||||
{
|
||||
ParodusError("Invalid request\n");
|
||||
response = cJSON_CreateObject();
|
||||
cJSON_AddNumberToObject(response, "statusCode", 400);
|
||||
cJSON_AddStringToObject(response, "message", "Invalid Request");
|
||||
ret = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
addCRUDmsgToQueue(message);
|
||||
}
|
||||
destFlag =1;
|
||||
}
|
||||
//if any unknown dest received sending error response to server
|
||||
if(destFlag ==0)
|
||||
{
|
||||
ParodusError("Unknown dest:%s\n", dest);
|
||||
@@ -147,8 +182,15 @@ void listenerOnMessage(void * msg, size_t msgSize)
|
||||
}
|
||||
else
|
||||
{
|
||||
resp_msg ->u.crud.source = message->u.crud.dest;
|
||||
resp_msg ->u.crud.dest = message->u.crud.source;
|
||||
resp_msg ->u.crud.source = message->u.crud.dest;
|
||||
if(message->u.crud.source !=NULL)
|
||||
{
|
||||
resp_msg ->u.crud.dest = message->u.crud.source;
|
||||
}
|
||||
else
|
||||
{
|
||||
resp_msg ->u.crud.dest = "unknown";
|
||||
}
|
||||
resp_msg ->u.crud.transaction_uuid = message->u.crud.transaction_uuid;
|
||||
resp_msg ->u.crud.path = message->u.crud.path;
|
||||
}
|
||||
@@ -192,6 +234,7 @@ void listenerOnMessage(void * msg, size_t msgSize)
|
||||
case WRP_MSG_TYPE__SVC_ALIVE:
|
||||
case WRP_MSG_TYPE__UNKNOWN:
|
||||
default:
|
||||
wrp_free_struct(message);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
56
src/heartBeat.c
Normal file
56
src/heartBeat.c
Normal file
@@ -0,0 +1,56 @@
|
||||
/**
|
||||
* Copyright 2018 Comcast Cable Communications Management, LLC
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
/**
|
||||
* @file heartBeat.c
|
||||
*
|
||||
* @description This decribes functions required to manage heartBeatTimer.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "heartBeat.h"
|
||||
|
||||
volatile unsigned int heartBeatTimer = 0;
|
||||
|
||||
pthread_mutex_t heartBeat_mut=PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
// Get value of heartBeatTimer
|
||||
unsigned int get_heartBeatTimer()
|
||||
{
|
||||
unsigned int tmp = 0;
|
||||
pthread_mutex_lock (&heartBeat_mut);
|
||||
tmp = heartBeatTimer;
|
||||
pthread_mutex_unlock (&heartBeat_mut);
|
||||
return tmp;
|
||||
}
|
||||
|
||||
// Reset value of heartBeatTimer to 0
|
||||
void reset_heartBeatTimer()
|
||||
{
|
||||
pthread_mutex_lock (&heartBeat_mut);
|
||||
heartBeatTimer = 0;
|
||||
pthread_mutex_unlock (&heartBeat_mut);
|
||||
}
|
||||
|
||||
// Increment value of heartBeatTimer to desired value
|
||||
void increment_heartBeatTimer(unsigned int inc_time_ms)
|
||||
{
|
||||
pthread_mutex_lock (&heartBeat_mut);
|
||||
heartBeatTimer += inc_time_ms;
|
||||
pthread_mutex_unlock (&heartBeat_mut);
|
||||
}
|
||||
|
||||
|
||||
46
src/heartBeat.h
Normal file
46
src/heartBeat.h
Normal file
@@ -0,0 +1,46 @@
|
||||
/**
|
||||
* Copyright 2018 Comcast Cable Communications Management, LLC
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
/**
|
||||
* @file heartBeat.h
|
||||
*
|
||||
* @description This decribes functions required to manage heartBeatTimer.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _HEARBEAT_H_
|
||||
#define _HEARBEAT_H_
|
||||
|
||||
#include <pthread.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// Get value of heartBeatTimer
|
||||
unsigned int get_heartBeatTimer();
|
||||
|
||||
// Reset value of heartBeatTimer to 0
|
||||
void reset_heartBeatTimer();
|
||||
|
||||
// Increment value of heartBeatTimer to desired value
|
||||
void increment_heartBeatTimer(unsigned int inc_time_ms);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -24,6 +24,7 @@
|
||||
#include "ParodusInternal.h"
|
||||
#include "nopoll_handlers.h"
|
||||
#include "connection.h"
|
||||
#include "heartBeat.h"
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Macros */
|
||||
@@ -36,6 +37,7 @@
|
||||
pthread_mutex_t g_mutex=PTHREAD_MUTEX_INITIALIZER;
|
||||
pthread_cond_t g_cond=PTHREAD_COND_INITIALIZER;
|
||||
ParodusMsg *ParodusMsgQ = NULL;
|
||||
noPollMsg * previous_msg = NULL;
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* External Functions */
|
||||
@@ -54,18 +56,43 @@ void listenerOnMessage_queue(noPollCtx * ctx, noPollConn * conn, noPollMsg * msg
|
||||
UNUSED(ctx);
|
||||
UNUSED(conn);
|
||||
UNUSED(user_data);
|
||||
noPollMsg * aux;
|
||||
|
||||
if (nopoll_msg_is_fragment (msg))
|
||||
{
|
||||
ParodusInfo("Found fragment, FIN = %d \n", nopoll_msg_is_final (msg));
|
||||
aux = previous_msg;
|
||||
previous_msg = nopoll_msg_join (previous_msg, msg);
|
||||
nopoll_msg_unref (aux);
|
||||
|
||||
if (! nopoll_msg_is_final (msg)) {
|
||||
ParodusInfo ("Found fragment that is not final..\n");
|
||||
return;
|
||||
}
|
||||
ParodusInfo("Found final fragment *** \n");
|
||||
}
|
||||
|
||||
ParodusMsg *message;
|
||||
message = (ParodusMsg *)malloc(sizeof(ParodusMsg));
|
||||
|
||||
if(message)
|
||||
{
|
||||
message->msg = msg;
|
||||
message->payload = (void *)nopoll_msg_get_payload (msg);
|
||||
message->len = nopoll_msg_get_payload_size (msg);
|
||||
message->next = NULL;
|
||||
if(previous_msg)
|
||||
{
|
||||
message->msg = previous_msg;
|
||||
message->payload = (void *)nopoll_msg_get_payload (previous_msg);
|
||||
message->len = nopoll_msg_get_payload_size (previous_msg);
|
||||
message->next = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
message->msg = msg;
|
||||
message->payload = (void *)nopoll_msg_get_payload (msg);
|
||||
message->len = nopoll_msg_get_payload_size (msg);
|
||||
message->next = NULL;
|
||||
|
||||
nopoll_msg_ref(msg);
|
||||
}
|
||||
|
||||
pthread_mutex_lock (&g_mutex);
|
||||
ParodusPrint("mutex lock in producer thread\n");
|
||||
@@ -94,6 +121,7 @@ void listenerOnMessage_queue(noPollCtx * ctx, noPollConn * conn, noPollMsg * msg
|
||||
//Memory allocation failed
|
||||
ParodusError("Memory allocation is failed\n");
|
||||
}
|
||||
previous_msg = NULL;
|
||||
ParodusPrint("*****Returned from listenerOnMessage_queue*****\n");
|
||||
}
|
||||
|
||||
@@ -109,6 +137,7 @@ void listenerOnPingMessage (noPollCtx * ctx, noPollConn * conn, noPollMsg * msg,
|
||||
{
|
||||
UNUSED(ctx);
|
||||
UNUSED(user_data);
|
||||
UNUSED(conn);
|
||||
|
||||
noPollPtr payload = NULL;
|
||||
payload = (noPollPtr ) nopoll_msg_get_payload(msg);
|
||||
@@ -118,9 +147,7 @@ void listenerOnPingMessage (noPollCtx * ctx, noPollConn * conn, noPollMsg * msg,
|
||||
ParodusInfo("Ping received with payload %s, opcode %d\n",(char *)payload, nopoll_msg_opcode(msg));
|
||||
if (nopoll_msg_opcode(msg) == NOPOLL_PING_FRAME)
|
||||
{
|
||||
nopoll_conn_send_frame (conn, nopoll_true, nopoll_true, NOPOLL_PONG_FRAME, strlen(payload), payload, 0);
|
||||
heartBeatTimer = 0;
|
||||
ParodusPrint("Sent Pong frame and reset HeartBeat Timer\n");
|
||||
reset_heartBeatTimer();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -129,16 +156,20 @@ void listenerOnCloseMessage (noPollCtx * ctx, noPollConn * conn, noPollPtr user_
|
||||
{
|
||||
UNUSED(ctx);
|
||||
UNUSED(conn);
|
||||
UNUSED(user_data);
|
||||
int closeStatus;
|
||||
char * defaultReason = "SSL_Socket_Close";
|
||||
|
||||
ParodusPrint("listenerOnCloseMessage(): mutex lock in producer thread\n");
|
||||
|
||||
if((user_data != NULL) && (strstr(user_data, "SSL_Socket_Close") != NULL) && !LastReasonStatus)
|
||||
closeStatus = nopoll_conn_get_close_status (conn);
|
||||
if( closeStatus == 1006 && !get_global_reconnect_status())
|
||||
{
|
||||
ParodusInfo("Reconnect detected, setting Reconnect reason as Server close\n");
|
||||
set_global_reconnect_reason("Server_closed_connection");
|
||||
LastReasonStatus = true;
|
||||
ParodusInfo("Reconnect detected, setting default Reconnect reason %s\n",defaultReason);
|
||||
set_global_reconnect_reason(defaultReason);
|
||||
set_global_reconnect_status(true);
|
||||
}
|
||||
else if ((user_data == NULL) && !LastReasonStatus)
|
||||
else if(!get_global_reconnect_status())
|
||||
{
|
||||
ParodusInfo("Reconnect detected, setting Reconnect reason as Unknown\n");
|
||||
set_global_reconnect_reason("Unknown");
|
||||
|
||||
@@ -37,7 +37,6 @@ extern "C" {
|
||||
extern pthread_mutex_t g_mutex;
|
||||
extern pthread_cond_t g_cond;
|
||||
extern pthread_mutex_t close_mut;
|
||||
extern volatile unsigned int heartBeatTimer;
|
||||
extern bool close_retry;
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
#include "connection.h"
|
||||
#include "nopoll_helpers.h"
|
||||
#include "nopoll_handlers.h"
|
||||
#include "time.h"
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Macros */
|
||||
@@ -33,6 +34,10 @@
|
||||
#define MAX_SEND_SIZE (60 * 1024)
|
||||
#define FLUSH_WAIT_TIME (2000000LL)
|
||||
|
||||
struct timespec connStuck_start,connStuck_end;
|
||||
struct timespec *connStuck_startPtr = &connStuck_start;
|
||||
struct timespec *connStuck_endPtr = &connStuck_end;
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* External functions */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
@@ -49,8 +54,11 @@ void setMessageHandlers()
|
||||
void sendMessage(noPollConn *conn, void *msg, size_t len)
|
||||
{
|
||||
int bytesWritten = 0;
|
||||
static int connErr=0;
|
||||
long timeDiff = 0;
|
||||
|
||||
ParodusInfo("sendMessage length %zu\n", len);
|
||||
|
||||
if(nopoll_conn_is_ok(conn) && nopoll_conn_is_ready(conn))
|
||||
{
|
||||
//bytesWritten = nopoll_conn_send_binary(conn, msg, len);
|
||||
@@ -60,10 +68,30 @@ void sendMessage(noPollConn *conn, void *msg, size_t len)
|
||||
{
|
||||
ParodusError("Failed to send bytes %zu, bytes written were=%d (errno=%d, %s)..\n", len, bytesWritten, errno, strerror(errno));
|
||||
}
|
||||
connErr = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
ParodusError("Failed to send msg upstream as connection is not OK\n");
|
||||
ParodusError("Failed to send msg upstream as connection is not OK\n");
|
||||
if (connErr == 0)
|
||||
{
|
||||
getCurrentTime(connStuck_startPtr);
|
||||
ParodusInfo("Conn got stuck, initialized the first timer\n");
|
||||
connErr = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
getCurrentTime(connStuck_endPtr);
|
||||
timeDiff = timeValDiff(connStuck_startPtr, connStuck_endPtr);
|
||||
ParodusPrint("checking timeout difference:%ld\n", timeDiff);
|
||||
|
||||
if( timeDiff >= (10*60*1000))
|
||||
{
|
||||
ParodusError("conn got stuck for over 10 minutes; crashing service.\n");
|
||||
kill(getpid(),SIGTERM);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -68,7 +68,7 @@ int validate_partner_id(wrp_msg_t *msg, partners_t **partnerIds)
|
||||
|
||||
if(matchFlag != 1)
|
||||
{
|
||||
(*partnerIds) = (partners_t *) malloc(sizeof(partners_t));
|
||||
(*partnerIds) = (partners_t *) malloc(sizeof(partners_t) + (sizeof(char *) * (count+1)));
|
||||
(*partnerIds)->count = count+1;
|
||||
for(i = 0; i < count; i++)
|
||||
{
|
||||
@@ -83,7 +83,7 @@ int validate_partner_id(wrp_msg_t *msg, partners_t **partnerIds)
|
||||
else
|
||||
{
|
||||
ParodusPrint("partner_ids list is NULL\n");
|
||||
(*partnerIds) = (partners_t *) malloc(sizeof(partners_t));
|
||||
(*partnerIds) = (partners_t *) malloc(sizeof(partners_t) + (sizeof(char *) * 1));
|
||||
(*partnerIds)->count = 1;
|
||||
(*partnerIds)->partner_ids[0] = (char *) malloc(sizeof(char) * 64);
|
||||
parStrncpy((*partnerIds)->partner_ids[0], partnerId, 64);
|
||||
|
||||
17
src/token.c
17
src/token.c
@@ -185,7 +185,7 @@ int nquery(const char* dns_txt_record_id, u_char *nsbuf)
|
||||
ParodusError ("nquery: nsbuf is NULL\n");
|
||||
return (-1);
|
||||
}
|
||||
statp.options |= RES_DEBUG;
|
||||
statp.options = RES_DEBUG;
|
||||
if (__res_ninit(&statp) < 0) {
|
||||
ParodusError ("res_ninit error: can't initialize statp.\n");
|
||||
return (-1);
|
||||
@@ -233,11 +233,10 @@ static bool is_digit (char c)
|
||||
// strip quotes and newlines from rr rec
|
||||
const char *strip_rr_data (const char *rr_ptr, int *rrlen)
|
||||
{
|
||||
int len;
|
||||
int len = *rrlen;
|
||||
const char *optr = rr_ptr;
|
||||
char c;
|
||||
|
||||
len = strlen (optr);
|
||||
if (len > 0) {
|
||||
c = optr[0];
|
||||
if (!is_digit(c)) {
|
||||
@@ -338,6 +337,7 @@ int get_rr_seq_table (ns_msg *msg_handle, int num_rr_recs, rr_rec_t *seq_table)
|
||||
continue;
|
||||
++num_txt_recs;
|
||||
rr_ptr = (const char *)ns_rr_rdata(rr);
|
||||
rrlen = ns_rr_rdlen(rr);
|
||||
ParodusPrint ("Found rr rec type %d: %s\n", ns_t_txt, rr_ptr);
|
||||
rr_ptr = strip_rr_data (rr_ptr, &rrlen);
|
||||
seq_pos = find_seq_num (rr_ptr, rrlen);
|
||||
@@ -429,8 +429,10 @@ int query_dns(const char* dns_txt_record_id,char *jwt_ans)
|
||||
ParodusError ("Unable to allocate nsbuf in query_dns\n");
|
||||
return TOKEN_ERR_MEMORY_FAIL;
|
||||
}
|
||||
|
||||
l = nquery(dns_txt_record_id,nsbuf);
|
||||
if (l < 0) {
|
||||
ParodusError("nquery returns error: l value is %d\n", l);
|
||||
free (nsbuf);
|
||||
return l;
|
||||
}
|
||||
@@ -491,15 +493,18 @@ int allow_insecure_conn(char *url_buf, int url_buflen,
|
||||
get_dns_txt_record_id (dns_txt_record_id);
|
||||
|
||||
ret = query_dns(dns_txt_record_id, jwt_token);
|
||||
ParodusPrint("query_dns returns %d\n", ret);
|
||||
|
||||
if(ret){
|
||||
if (ret == TOKEN_ERR_MEMORY_FAIL) {
|
||||
ParodusError("Failed in DNS query\n");
|
||||
if (ret == TOKEN_ERR_MEMORY_FAIL){
|
||||
insecure = ret;
|
||||
} else {
|
||||
}
|
||||
else{
|
||||
insecure = TOKEN_ERR_QUERY_DNS_FAIL;
|
||||
}
|
||||
goto end;
|
||||
}
|
||||
|
||||
//Decoding the jwt token
|
||||
key = get_parodus_cfg()->jwt_key;
|
||||
ret = cjwt_decode( jwt_token, 0, &jwt, ( const uint8_t * )key,strlen(key) );
|
||||
|
||||
@@ -48,6 +48,26 @@ pthread_mutex_t nano_mut=PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
pthread_cond_t nano_con=PTHREAD_COND_INITIALIZER;
|
||||
|
||||
UpStreamMsg * get_global_UpStreamMsgQ(void)
|
||||
{
|
||||
return UpStreamMsgQ;
|
||||
}
|
||||
|
||||
void set_global_UpStreamMsgQ(UpStreamMsg * UpStreamQ)
|
||||
{
|
||||
UpStreamMsgQ = UpStreamQ;
|
||||
}
|
||||
|
||||
pthread_cond_t *get_global_nano_con(void)
|
||||
{
|
||||
return &nano_con;
|
||||
}
|
||||
|
||||
pthread_mutex_t *get_global_nano_mut(void)
|
||||
{
|
||||
return &nano_mut;
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Internal Functions */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
@@ -314,16 +334,26 @@ void *processUpstreamMessage()
|
||||
{
|
||||
ParodusError("Error in msgpack decoding for upstream\n");
|
||||
}
|
||||
ParodusPrint("Free for upstream decoded msg\n");
|
||||
wrp_free_struct(msg);
|
||||
msg = NULL;
|
||||
|
||||
if(nn_freemsg (message->msg) < 0)
|
||||
{
|
||||
ParodusError ("Failed to free msg\n");
|
||||
//nn_freemsg should not be done for parodus/tags/ CRUD requests as it is not received through nanomsg.
|
||||
if ((msg && (msg->u.crud.source !=NULL) && strstr(msg->u.crud.source, "parodus") != NULL))
|
||||
{
|
||||
free(message->msg);
|
||||
}
|
||||
else
|
||||
{
|
||||
if(nn_freemsg (message->msg) < 0)
|
||||
{
|
||||
ParodusError ("Failed to free msg\n");
|
||||
}
|
||||
}
|
||||
ParodusPrint("Free for upstream decoded msg\n");
|
||||
if (msg) {
|
||||
wrp_free_struct(msg);
|
||||
}
|
||||
free(message);
|
||||
message = NULL;
|
||||
msg = NULL;
|
||||
free(message);
|
||||
message = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -340,7 +370,6 @@ void sendUpstreamMsgToServer(void **resp_bytes, size_t resp_size)
|
||||
{
|
||||
void *appendData;
|
||||
size_t encodedSize;
|
||||
|
||||
//appending response with metadata
|
||||
if(metaPackSize > 0)
|
||||
{
|
||||
|
||||
@@ -24,10 +24,12 @@
|
||||
#ifndef _UPSTREAM_H_
|
||||
#define _UPSTREAM_H_
|
||||
|
||||
#include <pthread.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Data Structures */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
@@ -47,6 +49,10 @@ void *handle_upstream();
|
||||
void *processUpstreamMessage();
|
||||
|
||||
void sendUpstreamMsgToServer(void **resp_bytes, size_t resp_size);
|
||||
void set_global_UpStreamMsgQ(UpStreamMsg * UpStreamQ);
|
||||
UpStreamMsg * get_global_UpStreamMsgQ(void);
|
||||
pthread_cond_t *get_global_nano_con(void);
|
||||
pthread_mutex_t *get_global_nano_mut(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -109,17 +109,25 @@ target_link_libraries (test_string_helpers ${PARODUS_COMMON_LIBS} )
|
||||
# test_nopoll_handlers
|
||||
#-------------------------------------------------------------------------------
|
||||
add_test(NAME test_nopoll_handlers COMMAND ${MEMORY_CHECK} ./test_nopoll_handlers)
|
||||
add_executable(test_nopoll_handlers test_nopoll_handlers.c ../src/nopoll_handlers.c)
|
||||
add_executable(test_nopoll_handlers test_nopoll_handlers.c ../src/nopoll_handlers.c ../src/heartBeat.c)
|
||||
target_link_libraries (test_nopoll_handlers -lnopoll -lcunit -lcimplog -Wl,--no-as-needed -lrt -lpthread -lm)
|
||||
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# test_nopoll_handlers_fragment
|
||||
#-------------------------------------------------------------------------------
|
||||
add_test(NAME test_nopoll_handlers_fragment COMMAND ${MEMORY_CHECK} ./test_nopoll_handlers_fragment)
|
||||
add_executable(test_nopoll_handlers_fragment test_nopoll_handlers_fragment.c ../src/nopoll_handlers.c ../src/heartBeat.c)
|
||||
target_link_libraries (test_nopoll_handlers_fragment -lnopoll -lcunit -lcimplog -Wl,--no-as-needed -lrt -lpthread -lm -lcmocka)
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# test_connection
|
||||
#-------------------------------------------------------------------------------
|
||||
add_test(NAME test_connection COMMAND ${MEMORY_CHECK} ./test_connection)
|
||||
#add_executable(test_connection test_connection.c ../src/connection.c ${PARODUS_COMMON_SRC})
|
||||
#target_link_libraries (test_connection ${PARODUS_COMMON_LIBS} -lcmocka)
|
||||
set(SOURCES test_connection.c ../src/connection.c ${PARODUS_COMMON_SRC})
|
||||
add_executable(test_connection ${SOURCES})
|
||||
set(CONN_SRC test_connection.c ../src/connection.c ../src/heartBeat.c ${PARODUS_COMMON_SRC})
|
||||
add_executable(test_connection ${CONN_SRC})
|
||||
#target_link_libraries (test_connection ${PARODUS_CONN_LIBS} ${PARODUS_COMMON_LIBS} -lcmocka)
|
||||
target_link_libraries (test_connection ${PARODUS_COMMON_LIBS} -lcmocka)
|
||||
|
||||
@@ -129,7 +137,7 @@ target_link_libraries (test_connection ${PARODUS_COMMON_LIBS} -lcmocka)
|
||||
add_test(NAME test_createConnection COMMAND ${MEMORY_CHECK} ./test_createConnection)
|
||||
#add_executable(test_createConnection test_createConnection.c ../src/connection.c ../src/string_helpers.c ../src/config.c)
|
||||
#target_link_libraries (test_createConnection ${PARODUS_COMMON_LIBS} -lcmocka)
|
||||
add_executable(test_createConnection test_createConnection.c ../src/connection.c ../src/string_helpers.c ../src/config.c)
|
||||
add_executable(test_createConnection test_createConnection.c ../src/connection.c ../src/string_helpers.c ../src/config.c ../src/heartBeat.c)
|
||||
#target_link_libraries (test_createConnection ${PARODUS_CONN_LIBS} ${PARODUS_COMMON_LIBS} -lcmocka )
|
||||
target_link_libraries (test_createConnection ${PARODUS_COMMON_LIBS} -lcmocka )
|
||||
|
||||
@@ -139,19 +147,19 @@ target_link_libraries (test_createConnection ${PARODUS_COMMON_LIBS} -lcmocka )
|
||||
add_test(NAME test_client_list COMMAND ${MEMORY_CHECK} ./test_client_list)
|
||||
#add_executable(test_client_list test_client_list.c ../src/client_list.c ../src/service_alive.c ../src/upstream.c ../src/networking.c ../src/nopoll_helpers.c ../src/downstream.c ../src/connection.c ../src/nopoll_handlers.c ../src/ParodusInternal.c ../src/thread_tasks.c ../src/conn_interface.c ../src/partners_check.c ${PARODUS_COMMON_SRC})
|
||||
#target_link_libraries (test_client_list ${PARODUS_COMMON_LIBS})
|
||||
set(SOURCES test_client_list.c ../src/client_list.c
|
||||
set(CLIST_SRC test_client_list.c ../src/client_list.c
|
||||
../src/service_alive.c ../src/upstream.c ../src/networking.c ../src/nopoll_helpers.c
|
||||
../src/downstream.c ../src/connection.c ../src/nopoll_handlers.c
|
||||
../src/downstream.c ../src/connection.c ../src/nopoll_handlers.c ../src/heartBeat.c
|
||||
../src/ParodusInternal.c ../src/thread_tasks.c ../src/conn_interface.c
|
||||
../src/partners_check.c ${PARODUS_COMMON_SRC})
|
||||
../src/partners_check.c ../src/crud_interface.c ../src/crud_tasks.c ../src/crud_internal.c ${PARODUS_COMMON_SRC})
|
||||
|
||||
if (ENABLE_SESHAT)
|
||||
set(SOURCES ${SOURCES} ../src/seshat_interface.c)
|
||||
set(CLIST_SRC ${CLIST_SRC} ../src/seshat_interface.c)
|
||||
else()
|
||||
set(SOURCES ${SOURCES} ../src/seshat_interface_stub.c)
|
||||
set(CLIST_SRC ${CLIST_SRC} ../src/seshat_interface_stub.c)
|
||||
endif (ENABLE_SESHAT)
|
||||
|
||||
add_executable(test_client_list ${SOURCES})
|
||||
add_executable(test_client_list ${CLIST_SRC})
|
||||
#target_link_libraries (test_client_list ${PARODUS_CONN_LIBS} ${PARODUS_COMMON_LIBS})
|
||||
target_link_libraries (test_client_list ${PARODUS_COMMON_LIBS})
|
||||
|
||||
@@ -161,14 +169,14 @@ target_link_libraries (test_client_list ${PARODUS_COMMON_LIBS})
|
||||
add_test(NAME test_service_alive COMMAND ${MEMORY_CHECK} ./test_service_alive)
|
||||
#add_executable(test_service_alive test_service_alive.c ../src/client_list.c ../src/service_alive.c ../src/upstream.c ../src/networking.c ../src/nopoll_helpers.c ../src/nopoll_handlers.c ../src/config.c ../src/connection.c ../src/ParodusInternal.c ../src/downstream.c ../src/thread_tasks.c ../src/conn_interface.c ../src/partners_check.c ${PARODUS_COMMON_SRC})
|
||||
#target_link_libraries (test_service_alive ${PARODUS_COMMON_LIBS})
|
||||
set(SOURCES test_service_alive.c ../src/client_list.c ../src/service_alive.c ../src/upstream.c ../src/networking.c ../src/nopoll_helpers.c ../src/nopoll_handlers.c ../src/config.c ../src/connection.c ../src/ParodusInternal.c ../src/downstream.c ../src/thread_tasks.c ../src/conn_interface.c ../src/partners_check.c ${PARODUS_COMMON_SRC})
|
||||
set(SVA_SRC test_service_alive.c ../src/client_list.c ../src/service_alive.c ../src/upstream.c ../src/networking.c ../src/nopoll_helpers.c ../src/nopoll_handlers.c ../src/config.c ../src/connection.c ../src/ParodusInternal.c ../src/downstream.c ../src/thread_tasks.c ../src/conn_interface.c ../src/partners_check.c ../src/heartBeat.c ${PARODUS_COMMON_SRC})
|
||||
if (ENABLE_SESHAT)
|
||||
set(SOURCES ${SOURCES} ../src/seshat_interface.c)
|
||||
set(SVA_SRC ${SVA_SRC} ../src/seshat_interface.c)
|
||||
else()
|
||||
set(SOURCES ${SOURCES} ../src/seshat_interface_stub.c)
|
||||
set(SVA_SRC ${SVA_SRC} ../src/seshat_interface_stub.c)
|
||||
endif (ENABLE_SESHAT)
|
||||
|
||||
add_executable(test_service_alive ${SOURCES})
|
||||
add_executable(test_service_alive ${SVA_SRC})
|
||||
#target_link_libraries (test_service_alive ${PARODUS_CONN_LIBS} ${PARODUS_COMMON_LIBS})
|
||||
target_link_libraries (test_service_alive ${PARODUS_COMMON_LIBS})
|
||||
|
||||
@@ -182,6 +190,27 @@ target_link_libraries (test_config -lcmocka
|
||||
-lcjson -lcjwt -ltrower-base64 -lssl -lcrypto -lrt -lm
|
||||
)
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# test_crud_interface
|
||||
#-------------------------------------------------------------------------------
|
||||
add_test(NAME test_crud_interface COMMAND ${MEMORY_CHECK} ./test_crud_interface)
|
||||
add_executable(test_crud_interface test_crud_interface.c ../src/crud_interface.c ../src/ParodusInternal.c)
|
||||
target_link_libraries (test_crud_interface -lcmocka ${PARODUS_COMMON_LIBS} )
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# test_crud_tasks
|
||||
#-------------------------------------------------------------------------------
|
||||
add_test(NAME test_crud_tasks COMMAND ${MEMORY_CHECK} ./test_crud_tasks)
|
||||
add_executable(test_crud_tasks test_crud_tasks.c ../src/crud_tasks.c )
|
||||
target_link_libraries (test_crud_tasks -lcmocka ${PARODUS_COMMON_LIBS} )
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# test_crud_internal
|
||||
#-------------------------------------------------------------------------------
|
||||
add_test(NAME test_crud_internal COMMAND ${MEMORY_CHECK} ./test_crud_internal)
|
||||
add_executable(test_crud_internal test_crud_internal.c ../src/config.c ../src/string_helpers.c ../src/crud_internal.c )
|
||||
target_link_libraries (test_crud_internal -lcmocka ${PARODUS_COMMON_LIBS} )
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# test_upstream
|
||||
#-------------------------------------------------------------------------------
|
||||
@@ -214,13 +243,21 @@ target_link_libraries (test_thread_tasks -lcmocka ${PARODUS_COMMON_LIBS} )
|
||||
# test_conn_interface
|
||||
#-------------------------------------------------------------------------------
|
||||
add_test(NAME test_conn_interface COMMAND ${MEMORY_CHECK} ./test_conn_interface)
|
||||
set(SOURCES test_conn_interface.c ../src/conn_interface.c ../src/config.c ../src/string_helpers.c ../src/mutex.c)
|
||||
set(CONIFC_SRC test_conn_interface.c
|
||||
../src/crud_interface.c ../src/crud_tasks.c ../src/crud_internal.c
|
||||
../src/conn_interface.c
|
||||
../src/config.c
|
||||
../src/token.c
|
||||
../src/string_helpers.c
|
||||
../src/mutex.c
|
||||
../src/heartBeat.c
|
||||
)
|
||||
if (ENABLE_SESHAT)
|
||||
set(SOURCES ${SOURCES} ../src/seshat_interface.c)
|
||||
set(CONIFC_SRC ${CONIFC_SRC} ../src/seshat_interface.c)
|
||||
else()
|
||||
set(SOURCES ${SOURCES} ../src/seshat_interface_stub.c)
|
||||
set(CONIFC_SRC ${CONIFC_SRC} ../src/seshat_interface_stub.c)
|
||||
endif (ENABLE_SESHAT)
|
||||
add_executable(test_conn_interface ${SOURCES})
|
||||
add_executable(test_conn_interface ${CONIFC_SRC})
|
||||
target_link_libraries (test_conn_interface -lcmocka ${PARODUS_COMMON_LIBS} )
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
@@ -241,7 +278,31 @@ target_link_libraries (test_partners_check -lcmocka ${PARODUS_COMMON_LIBS} -lwrp
|
||||
# test_token - token.c tests
|
||||
#-------------------------------------------------------------------------------
|
||||
add_test(NAME test_token COMMAND ${MEMORY_CHECK} ./test_token)
|
||||
add_executable(test_token ${SOURCES} )
|
||||
set(TOKEN_SRC ../src/conn_interface.c ../src/config.c
|
||||
../src/connection.c ../src/spin_thread.c
|
||||
../src/service_alive.c ../src/client_list.c
|
||||
../src/nopoll_handlers.c ../src/nopoll_helpers.c
|
||||
../src/partners_check.c ../src/ParodusInternal.c
|
||||
../src/upstream.c ../src/downstream.c
|
||||
../src/networking.c
|
||||
../src/thread_tasks.c ../src/time.c
|
||||
../src/string_helpers.c ../src/mutex.c
|
||||
../src/token.c ../src/heartBeat.c
|
||||
)
|
||||
|
||||
if (ENABLE_SESHAT)
|
||||
set(TOKEN_SRC ${TOKEN_SRC} ../src/seshat_interface.c)
|
||||
else()
|
||||
set(TOKEN_SRC ${TOKEN_SRC} ../src/seshat_interface_stub.c)
|
||||
endif (ENABLE_SESHAT)
|
||||
|
||||
if (FEATURE_DNS_QUERY)
|
||||
set(TOKEN_SRC test_token.c ${TOKEN_SRC})
|
||||
else()
|
||||
set(TOKEN_SRC test_token_stub.c ${TOKEN_SRC})
|
||||
endif (FEATURE_DNS_QUERY)
|
||||
|
||||
add_executable(test_token ${TOKEN_SRC} )
|
||||
#target_link_libraries (test_token ${PARODUS_COMMON_LIBS} ${PARODUS_JWT_LIBS} -lcmocka )
|
||||
target_link_libraries (test_token ${PARODUS_COMMON_LIBS} -lcmocka )
|
||||
|
||||
@@ -250,11 +311,11 @@ target_link_libraries (test_token ${PARODUS_COMMON_LIBS} -lcmocka )
|
||||
#-------------------------------------------------------------------------------
|
||||
add_test(NAME test_seshat_interface COMMAND ${MEMORY_CHECK} ./test_seshat_interface)
|
||||
if (ENABLE_SESHAT)
|
||||
set(SOURCES test_seshat_interface.c ../src/seshat_interface.c ../src/string_helpers.c)
|
||||
set(SESHIFC_SRC test_seshat_interface.c ../src/seshat_interface.c ../src/string_helpers.c)
|
||||
else()
|
||||
set(SOURCES test_seshat_interface_stub.c ../src/seshat_interface_stub.c)
|
||||
set(SESHIFC_SRC test_seshat_interface_stub.c ../src/seshat_interface_stub.c)
|
||||
endif (ENABLE_SESHAT)
|
||||
add_executable(test_seshat_interface ${SOURCES})
|
||||
add_executable(test_seshat_interface ${SESHIFC_SRC})
|
||||
target_link_libraries (test_seshat_interface -lcmocka ${PARODUS_COMMON_LIBS} -lwrp-c)
|
||||
|
||||
if (INTEGRATION_TESTING)
|
||||
@@ -262,28 +323,28 @@ if (INTEGRATION_TESTING)
|
||||
# simple_connection test
|
||||
#-------------------------------------------------------------------------------
|
||||
add_test(NAME simple_connection COMMAND ${MEMORY_CHECK} ./simple_connection)
|
||||
set(SOURCES simple_connection.c ${PARODUS_COMMON_SRC} ../src/upstream.c ../src/conn_interface.c
|
||||
set(SIMCON_SRC simple_connection.c ${PARODUS_COMMON_SRC} ../src/upstream.c ../src/conn_interface.c
|
||||
../src/thread_tasks.c ../src/downstream.c ../src/networking.c ../src/nopoll_helpers.c ../src/nopoll_handlers.c ../src/connection.c ../src/ParodusInternal.c ../src/client_list.c ../src/partners_check.c ../src/service_alive.c)
|
||||
if (ENABLE_SESHAT)
|
||||
set(SOURCES ${SOURCES} ../src/seshat_interface.c)
|
||||
set(SIMCON_SRC ${SIMCON_SRC} ../src/seshat_interface.c)
|
||||
else()
|
||||
set(SOURCES ${SOURCES} ../src/seshat_interface_stub.c)
|
||||
set(SIMCON_SRC ${SIMCON_SRC} ../src/seshat_interface_stub.c)
|
||||
endif (ENABLE_SESHAT)
|
||||
add_executable(simple_connection ${SOURCES})
|
||||
add_executable(simple_connection ${SIMCON_SRC})
|
||||
target_link_libraries (simple_connection ${PARODUS_CONN_LIBS} ${PARODUS_COMMON_LIBS} )
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# simple test
|
||||
#-------------------------------------------------------------------------------
|
||||
add_test(NAME simple COMMAND ${MEMORY_CHECK} ./simple)
|
||||
set(SOURCES simple.c ../src/upstream.c ../src/conn_interface.c ../src/downstream.c ../src/thread_tasks.c ../src/networking.c ../src/nopoll_helpers.c ../src/nopoll_handlers.c ../src/string_helpers.c ../src/mutex.c ../src/time.c
|
||||
set(SIMPLE_SRC simple.c ../src/upstream.c ../src/conn_interface.c ../src/downstream.c ../src/thread_tasks.c ../src/networking.c ../src/nopoll_helpers.c ../src/nopoll_handlers.c ../src/string_helpers.c ../src/mutex.c ../src/time.c
|
||||
../src/config.c ../src/connection.c ../src/ParodusInternal.c ../src/spin_thread.c ../src/client_list.c ../src/partners_check.c ../src/service_alive.c)
|
||||
if (ENABLE_SESHAT)
|
||||
set(SOURCES ${SOURCES} ../src/seshat_interface.c)
|
||||
set(SIMPLE_SRC ${SIMPLE_SRC} ../src/seshat_interface.c)
|
||||
else()
|
||||
set(SOURCES ${SOURCES} ../src/seshat_interface_stub.c)
|
||||
set(SIMPLE_SRC ${SIMPLE_SRC} ../src/seshat_interface_stub.c)
|
||||
endif (ENABLE_SESHAT)
|
||||
add_executable(simple ${SOURCES})
|
||||
add_executable(simple ${SIMPLE_SRC})
|
||||
|
||||
target_link_libraries (simple ${PARODUS_CONN_LIBS} ${PARODUS_COMMON_LIBS} gcov -lnopoll -lnanomsg )
|
||||
endif (INTEGRATION_TESTING)
|
||||
|
||||
28
tests/key4.pem
Normal file
28
tests/key4.pem
Normal file
@@ -0,0 +1,28 @@
|
||||
-----BEGIN PRIVATE KEY-----
|
||||
MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDsLxH6GZFxU64v
|
||||
GL9CNz3hLSoCb7TckabgbVp6PIRy9cKEwfqnQ/2ohqrdolMA6Peru2+DgBs1iJ3u
|
||||
JNSc+8XFphUj0Jm2gVumVfclSZTEkM4xI4D3ABXn0Pj6/Ps5Skx9pXk3KI988ksB
|
||||
secD+FNqBPgmKWG0Gp+JSrPEwAtA4ZBP/4vtCGxEFzRCSOSBkTh27n1f08M4PjsY
|
||||
+vMvyTVF67y4Zb3nWJHpa1yOBlHid0xI138KPEBl+9Vai1AwRWbhlq52I9+IVjCo
|
||||
N7Ui9KbRgfd21SJFLh3hDw6xSrNqtcU+mvv5GuLAxHF5tCcGpAgKvKhvjQU4v+fh
|
||||
lGW77zkVAgMBAAECggEBAI8DoZsTyGIbDaovDgEGek3Tj1CSW64D9EyJavQBmSIT
|
||||
don0+9Y08XAOu4AhPqmaZ/5xLQEvnUo5Q4hkfOnh+svH2Z0qPymoAtshytmlSJQO
|
||||
KwzONtVaE+mfPGSes3DpcI/UlyWzRc+e15RbKUvaHohgIfLZs/Pe+yOjPF+y+h16
|
||||
Tpvklvk9GuS5/njOm0N8iRZw0+mKMLjwKCf0Q9WpF5OXW7hYccG9aTpmiUDnpixP
|
||||
nMyEdZMhmfFDLl+t6Txj3KhNX8jixDmfkuiPuoADWZuYk3GjS499nb3Y5Tmm8TLq
|
||||
jf0St48y1bObNnkceSqODnUK2hUZzzWcgTLwIC1E0DECgYEA+QoVuCA5i3eAiyE7
|
||||
PUsKpT0qVH/rWVWl0HYykUI7MSv0KJH7uPS+m2GzScxpCZoA4wtu6iK5IePNf645
|
||||
yJAleglx+1vuBGCWQrr206gOPWrkthfVHd+pDCr/fnIG+RdNr9SgwUx1youpovQ4
|
||||
x64RQuEyBXENt+xx2+fFI28GxEcCgYEA8skAisNqPgREewZ+hM2OkhIyU7GaKWgt
|
||||
HfjPYHHYWVO/sSfOdcyzcCUZJkseBhIVEmIeiXM4NCO0spmieHa6bo8oLr1nPMtm
|
||||
J4UkyVRPtO99V5mIBYOS3cWAEwEt7lWZ+4JiIyEBO/tMVjIrB8YkOE4LqV40Vvpu
|
||||
XGJbtw3JEcMCgYEA15xnmXYs3Bamb85hn3tsyArgry/g7wM7//OVbDXPUY8gYE+j
|
||||
hEpBC/3WX7pd5jYzNl8btBJD/pdfv39z/7Ts/W9YA6tfsuJ8tWFxeWYyjfIR+aVA
|
||||
mhCeJy7C7RKD/vyyAd0xIKm2AZpRUAfpcNe/kguuZw+uNOK84QsUnsztKtkCgYAE
|
||||
KBDMT2AoQ6ZwfMH5wBMqyQj3idjb0J7FHpdeTVSo4tgrTkUomyKPTvNJRovzCqg1
|
||||
slxXehOCQQI89Ihli5LRhb3oXvG/hrPvBUaF892ReXAp6cT8Yy5GgbUZnjGNHQYP
|
||||
2kGX3F7LChhaeW1nKqtAE4X7llNLEeqFxmFPlvrURQKBgA0c5s3WPeX5OfSRsLaF
|
||||
iXaQNQ88QORNJ4hp/L7/o3ZNy7elH/R3GM1fs8Yf711CDxy4qI7icRYyrkl0P/Py
|
||||
WyRbNnvw0JMa5xkzRgKlnvspfEfve7gzcZhE9yEw173MIyyoxIn43G9aGNSN3QIR
|
||||
51ZlCYyuIAgR7p+9lKvM74HR
|
||||
-----END PRIVATE KEY-----
|
||||
@@ -244,13 +244,19 @@ void delay_ms(unsigned int secs, unsigned int msecs)
|
||||
|
||||
void dbg_log_err (const char *fmt, ...)
|
||||
{
|
||||
char errbuf[100];
|
||||
char errbuf[100];
|
||||
|
||||
va_list arg_ptr;
|
||||
|
||||
va_start(arg_ptr, fmt);
|
||||
vprintf(fmt, arg_ptr);
|
||||
va_end(arg_ptr);
|
||||
printf ("LIBPD_TEST: %s\n", strerror_r (errno, errbuf, 100));
|
||||
|
||||
if( 0 == strerror_r (errno, errbuf, 100) ) {
|
||||
printf("LIBPD_TEST: %s\n", errbuf);
|
||||
} else {
|
||||
printf("LIBPD_TEST: strerror_r returned failure!\n");
|
||||
}
|
||||
}
|
||||
|
||||
void wait_auth_received (void)
|
||||
|
||||
9
tests/pubkey4.pem
Normal file
9
tests/pubkey4.pem
Normal file
@@ -0,0 +1,9 @@
|
||||
-----BEGIN PUBLIC KEY-----
|
||||
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA7C8R+hmRcVOuLxi/Qjc9
|
||||
4S0qAm+03JGm4G1aejyEcvXChMH6p0P9qIaq3aJTAOj3q7tvg4AbNYid7iTUnPvF
|
||||
xaYVI9CZtoFbplX3JUmUxJDOMSOA9wAV59D4+vz7OUpMfaV5NyiPfPJLAbHnA/hT
|
||||
agT4JilhtBqfiUqzxMALQOGQT/+L7QhsRBc0QkjkgZE4du59X9PDOD47GPrzL8k1
|
||||
Reu8uGW951iR6WtcjgZR4ndMSNd/CjxAZfvVWotQMEVm4ZaudiPfiFYwqDe1IvSm
|
||||
0YH3dtUiRS4d4Q8OsUqzarXFPpr7+RriwMRxebQnBqQICryob40FOL/n4ZRlu+85
|
||||
FQIDAQAB
|
||||
-----END PUBLIC KEY-----
|
||||
@@ -95,6 +95,38 @@ void err_getWebpaConveyHeader()
|
||||
getWebpaConveyHeader();
|
||||
}
|
||||
|
||||
/*
|
||||
* Test function to verify timespec_diff function
|
||||
* Verifys when the time diff is positive ie stop time > start time
|
||||
*/
|
||||
void test_timespec_diff()
|
||||
{
|
||||
struct timespec start, stop, diff;
|
||||
int time_taken_ms;
|
||||
clock_gettime(CLOCK_REALTIME, &start);
|
||||
sleep(1);
|
||||
clock_gettime(CLOCK_REALTIME, &stop);
|
||||
timespec_diff(&start, &stop, &diff);
|
||||
time_taken_ms = diff.tv_sec * 1000 + (diff.tv_nsec / 1000000);
|
||||
assert_int_equal(time_taken_ms, 1000);
|
||||
}
|
||||
|
||||
/*
|
||||
* Test function to verify timespec_diff function
|
||||
* Verifys when the time diff is negative ie stop time < start time
|
||||
*/
|
||||
void test_timespec_diff1()
|
||||
{
|
||||
struct timespec start, stop, diff;
|
||||
int time_taken_ms;
|
||||
clock_gettime(CLOCK_REALTIME, &start);
|
||||
sleep(1);
|
||||
clock_gettime(CLOCK_REALTIME, &stop);
|
||||
timespec_diff(&stop, &start, &diff);
|
||||
time_taken_ms = diff.tv_sec * 1000 + (diff.tv_nsec / 1000000);
|
||||
assert_int_equal(time_taken_ms, -1001);
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* External Functions */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
@@ -103,6 +135,8 @@ int main(void)
|
||||
const struct CMUnitTest tests[] = {
|
||||
cmocka_unit_test(test_getWebpaConveyHeader),
|
||||
cmocka_unit_test(err_getWebpaConveyHeader),
|
||||
cmocka_unit_test(test_timespec_diff),
|
||||
cmocka_unit_test(test_timespec_diff1),
|
||||
};
|
||||
|
||||
return cmocka_run_group_tests(tests, NULL, NULL);
|
||||
|
||||
@@ -69,7 +69,7 @@ void test_setParodusConfig()
|
||||
parStrncpy(cfg.webpa_interface_used , "eth0", sizeof(cfg.webpa_interface_used));
|
||||
parStrncpy(cfg.webpa_protocol , "WebPA-1.6", sizeof(cfg.webpa_protocol));
|
||||
parStrncpy(cfg.webpa_uuid , "1234567-345456546", sizeof(cfg.webpa_uuid));
|
||||
parStrncpy(cfg.partner_id , "comcast", sizeof(cfg.partner_id));
|
||||
parStrncpy(cfg.partner_id , "mycom", sizeof(cfg.partner_id));
|
||||
#ifdef ENABLE_SESHAT
|
||||
parStrncpy(cfg.seshat_url, "ipc://tmp/seshat_service.url", sizeof(cfg.seshat_url));
|
||||
#endif
|
||||
@@ -82,10 +82,10 @@ void test_setParodusConfig()
|
||||
parStrncpy(cfg.dns_txt_url, "test",sizeof(cfg.dns_txt_url));
|
||||
cfg.jwt_algo = 1025;
|
||||
parStrncpy(cfg.jwt_key, "key.txt",sizeof(cfg.jwt_key));
|
||||
#endif
|
||||
set_parodus_cfg(&cfg);
|
||||
|
||||
ParodusCfg *temp = get_parodus_cfg();
|
||||
#endif
|
||||
cfg.crud_config_file = strdup("parodus_cfg.json");
|
||||
set_parodus_cfg(&cfg);
|
||||
ParodusCfg *temp = get_parodus_cfg();
|
||||
|
||||
assert_string_equal(cfg.hw_model, temp->hw_model);
|
||||
assert_string_equal(cfg.hw_serial_number, temp->hw_serial_number);
|
||||
@@ -111,6 +111,7 @@ void test_setParodusConfig()
|
||||
assert_int_equal( (int) cfg.jwt_algo, (int) temp->jwt_algo);
|
||||
assert_string_equal(cfg.jwt_key, temp->jwt_key);
|
||||
#endif
|
||||
assert_string_equal(cfg.crud_config_file, temp->crud_config_file);
|
||||
}
|
||||
|
||||
void test_getParodusConfig()
|
||||
@@ -184,10 +185,11 @@ void test_parseCommandLine()
|
||||
"--ssl-cert-path=/etc/ssl/certs/ca-certificates.crt",
|
||||
#ifdef FEATURE_DNS_QUERY
|
||||
"--acquire-jwt=1",
|
||||
"--dns-txt-url=fabric.comcast.net",
|
||||
"--dns-txt-url=mydns.mycom.net",
|
||||
"--jwt-public-key-file=../../tests/jwt_key.tst",
|
||||
"--jwt-algo=RS256",
|
||||
#endif
|
||||
"--crud-config-file=parodus_cfg.json",
|
||||
NULL
|
||||
};
|
||||
int argc = (sizeof (command) / sizeof (char *)) - 1;
|
||||
@@ -226,11 +228,11 @@ void test_parseCommandLine()
|
||||
assert_string_equal( parodusCfg.cert_path,"/etc/ssl/certs/ca-certificates.crt");
|
||||
#ifdef FEATURE_DNS_QUERY
|
||||
assert_int_equal( (int) parodusCfg.acquire_jwt, 1);
|
||||
assert_string_equal(parodusCfg.dns_txt_url, "fabric.comcast.net");
|
||||
assert_string_equal(parodusCfg.dns_txt_url, "mydns.mycom.net");
|
||||
assert_int_equal( (int) parodusCfg.jwt_algo, 1024);
|
||||
assert_string_equal ( get_parodus_cfg()->jwt_key, jwt_key);
|
||||
#endif
|
||||
|
||||
assert_string_equal(parodusCfg.crud_config_file, "parodus_cfg.json");
|
||||
}
|
||||
|
||||
void test_parseCommandLineNull()
|
||||
@@ -272,7 +274,7 @@ void err_parseCommandLine()
|
||||
#ifdef FEATURE_DNS_QUERY
|
||||
command[5] = "--webpa-url=https://127.0.0.1";
|
||||
command[3] = "--acquire-jwt=1";
|
||||
command[4] = "--dns-txt-url=fabric.comcast.net";
|
||||
command[4] = "--dns-txt-url=mydns.mycom.net";
|
||||
// missing algo
|
||||
assert_int_equal (parseCommandLine(argc,command,&parodusCfg), -1);
|
||||
command[4] = "--jwt-algo=none:RS256";
|
||||
@@ -307,7 +309,7 @@ void test_loadParodusCfg()
|
||||
parStrncpy(Cfg->partner_id , "shaw", sizeof(Cfg->partner_id));
|
||||
#ifdef FEATURE_DNS_QUERY
|
||||
Cfg->acquire_jwt = 1;
|
||||
parStrncpy(Cfg->dns_txt_url, "fabric",sizeof(Cfg->dns_txt_url));
|
||||
parStrncpy(Cfg->dns_txt_url, "mydns",sizeof(Cfg->dns_txt_url));
|
||||
Cfg->jwt_algo = 1025;
|
||||
parStrncpy(Cfg->jwt_key, "AGdyuwyhwl2ow2ydsoioiygkshwdthuwd",sizeof(Cfg->jwt_key));
|
||||
#endif
|
||||
@@ -317,6 +319,7 @@ void test_loadParodusCfg()
|
||||
#ifdef ENABLE_SESHAT
|
||||
parStrncpy(Cfg->seshat_url, "ipc://tmp/seshat_service.url", sizeof(Cfg->seshat_url));
|
||||
#endif
|
||||
Cfg->crud_config_file = strdup("parodus_cfg.json");
|
||||
memset(&tmpcfg,0,sizeof(ParodusCfg));
|
||||
loadParodusCfg(Cfg,&tmpcfg);
|
||||
|
||||
@@ -329,7 +332,7 @@ void test_loadParodusCfg()
|
||||
assert_string_equal( tmpcfg.webpa_protocol, protocol);
|
||||
#ifdef FEATURE_DNS_QUERY
|
||||
assert_int_equal( (int) tmpcfg.acquire_jwt, 1);
|
||||
assert_string_equal(tmpcfg.dns_txt_url, "fabric");
|
||||
assert_string_equal(tmpcfg.dns_txt_url, "mydns");
|
||||
assert_int_equal( (int) tmpcfg.jwt_algo, 1025);
|
||||
assert_string_equal(tmpcfg.jwt_key, "AGdyuwyhwl2ow2ydsoioiygkshwdthuwd");
|
||||
#endif
|
||||
@@ -339,6 +342,7 @@ void test_loadParodusCfg()
|
||||
#ifdef ENABLE_SESHAT
|
||||
assert_string_equal(tmpcfg.seshat_url, "ipc://tmp/seshat_service.url");
|
||||
#endif
|
||||
assert_string_equal(tmpcfg.crud_config_file, "parodus_cfg.json");
|
||||
free(Cfg);
|
||||
}
|
||||
|
||||
@@ -359,7 +363,7 @@ void test_loadParodusCfgNull()
|
||||
assert_string_equal( temp.webpa_path_url, WEBPA_PATH_URL);
|
||||
assert_string_equal( temp.webpa_uuid,"1234567-345456546");
|
||||
assert_string_equal( temp.local_url, PARODUS_UPSTREAM);
|
||||
|
||||
assert_null(temp.crud_config_file);
|
||||
free(cfg);
|
||||
}
|
||||
|
||||
@@ -453,23 +457,27 @@ void test_parse_webpa_url ()
|
||||
{
|
||||
char addr_buf[80];
|
||||
char port_buf[8];
|
||||
assert_int_equal (parse_webpa_url ("fabric.webpa.comcast.net:8080",
|
||||
assert_int_equal (parse_webpa_url ("mydns.mycom.net:8080",
|
||||
addr_buf, 80, port_buf, 8), -1);
|
||||
assert_int_equal (parse_webpa_url ("https://fabric.webpa.comcast.net:8080",
|
||||
assert_int_equal (parse_webpa_url ("https://mydns.mycom.net:8080",
|
||||
addr_buf, 80, port_buf, 8), 0);
|
||||
assert_string_equal (addr_buf, "fabric.webpa.comcast.net");
|
||||
assert_string_equal (addr_buf, "mydns.mycom.net");
|
||||
assert_string_equal (port_buf, "8080");
|
||||
assert_int_equal (parse_webpa_url ("https://fabric.webpa.comcast.net/",
|
||||
assert_int_equal (parse_webpa_url ("https://mydns.mycom.net/",
|
||||
addr_buf, 80, port_buf, 8), 0);
|
||||
assert_string_equal (addr_buf, "fabric.webpa.comcast.net");
|
||||
assert_string_equal (addr_buf, "mydns.mycom.net");
|
||||
assert_string_equal (port_buf, "443");
|
||||
assert_int_equal (parse_webpa_url ("http://fabric.webpa.comcast.net:8080",
|
||||
assert_int_equal (parse_webpa_url ("https://mydns.mycom.net/api/v2/",
|
||||
addr_buf, 80, port_buf, 8), 0);
|
||||
assert_string_equal (addr_buf, "mydns.mycom.net");
|
||||
assert_string_equal (port_buf, "443");
|
||||
assert_int_equal (parse_webpa_url ("http://mydns.mycom.net:8080",
|
||||
addr_buf, 80, port_buf, 8), 1);
|
||||
assert_string_equal (addr_buf, "fabric.webpa.comcast.net");
|
||||
assert_string_equal (addr_buf, "mydns.mycom.net");
|
||||
assert_string_equal (port_buf, "8080");
|
||||
assert_int_equal (parse_webpa_url ("http://fabric.webpa.comcast.net",
|
||||
assert_int_equal (parse_webpa_url ("http://mydns.mycom.net",
|
||||
addr_buf, 80, port_buf, 8), 1);
|
||||
assert_string_equal (addr_buf, "fabric.webpa.comcast.net");
|
||||
assert_string_equal (addr_buf, "mydns.mycom.net");
|
||||
assert_string_equal (port_buf, "80");
|
||||
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
#include "../src/conn_interface.h"
|
||||
#include "../src/connection.h"
|
||||
#include "../src/config.h"
|
||||
#include "../src/heartBeat.h"
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* File Scoped Variables */
|
||||
@@ -35,7 +36,10 @@ UpStreamMsg *UpStreamMsgQ;
|
||||
ParodusMsg *ParodusMsgQ;
|
||||
extern bool close_retry;
|
||||
extern pthread_mutex_t close_mut;
|
||||
extern volatile unsigned int heartBeatTimer;
|
||||
pthread_mutex_t nano_mut;
|
||||
pthread_cond_t nano_con;
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Mocks */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
@@ -107,6 +111,12 @@ void set_global_reconnect_reason(char *reason)
|
||||
function_called();
|
||||
}
|
||||
|
||||
void set_global_reconnect_status(bool status)
|
||||
{
|
||||
(void)status;
|
||||
function_called();
|
||||
}
|
||||
|
||||
void close_and_unref_connection(noPollConn *conn)
|
||||
{
|
||||
UNUSED(conn);
|
||||
@@ -151,6 +161,40 @@ void initKeypress()
|
||||
{
|
||||
function_called();
|
||||
}
|
||||
|
||||
UpStreamMsg * get_global_UpStreamMsgQ(void)
|
||||
{
|
||||
return UpStreamMsgQ;
|
||||
}
|
||||
|
||||
void set_global_UpStreamMsgQ(UpStreamMsg * UpStreamQ)
|
||||
{
|
||||
UpStreamMsgQ = UpStreamQ;
|
||||
}
|
||||
|
||||
pthread_cond_t *get_global_nano_con(void)
|
||||
{
|
||||
return &nano_con;
|
||||
}
|
||||
|
||||
pthread_mutex_t *get_global_nano_mut(void)
|
||||
{
|
||||
return &nano_mut;
|
||||
}
|
||||
|
||||
/*
|
||||
* Mock func to calculate time diff between start and stop time
|
||||
* This timespec_diff retuns 1 sec as diff time
|
||||
*/
|
||||
void timespec_diff(struct timespec *start, struct timespec *stop,
|
||||
struct timespec *diff)
|
||||
{
|
||||
UNUSED(start);
|
||||
UNUSED(stop);
|
||||
diff->tv_sec = 1;
|
||||
diff->tv_nsec = 1000;
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Tests */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
@@ -173,13 +217,14 @@ void test_createSocketConnection()
|
||||
expect_function_call(createNopollConnection);
|
||||
expect_function_call(packMetaData);
|
||||
|
||||
expect_function_calls(StartThread, 4);
|
||||
expect_function_calls(StartThread, 5);
|
||||
expect_function_call(initKeypress);
|
||||
will_return(nopoll_loop_wait, 1);
|
||||
expect_function_call(nopoll_loop_wait);
|
||||
|
||||
expect_function_call(set_global_reconnect_reason);
|
||||
will_return(get_global_conn, (intptr_t)NULL);
|
||||
expect_function_call(set_global_reconnect_status);
|
||||
expect_function_call(get_global_conn);
|
||||
expect_function_call(close_and_unref_connection);
|
||||
expect_function_call(set_global_conn);
|
||||
@@ -210,7 +255,7 @@ void test_createSocketConnection1()
|
||||
expect_function_call(createNopollConnection);
|
||||
expect_function_call(packMetaData);
|
||||
|
||||
expect_function_calls(StartThread, 4);
|
||||
expect_function_calls(StartThread, 5);
|
||||
will_return(nopoll_loop_wait, 1);
|
||||
expect_function_call(nopoll_loop_wait);
|
||||
|
||||
@@ -229,7 +274,7 @@ void test_createSocketConnection1()
|
||||
|
||||
}
|
||||
|
||||
void test_createSocketConnection2()
|
||||
void test_PingMissIntervalTime()
|
||||
{
|
||||
noPollCtx *ctx;
|
||||
ParodusCfg cfg;
|
||||
@@ -245,7 +290,8 @@ void test_createSocketConnection2()
|
||||
parStrncpy(cfg.webpa_interface_used , "eth0", sizeof(cfg.webpa_interface_used));
|
||||
parStrncpy(cfg.webpa_protocol , "WebPA-1.6", sizeof(cfg.webpa_protocol));
|
||||
parStrncpy(cfg.webpa_uuid , "1234567-345456546", sizeof(cfg.webpa_uuid));
|
||||
cfg.webpa_ping_timeout = 1;
|
||||
//Max ping timeout is 6 sec
|
||||
cfg.webpa_ping_timeout = 6;
|
||||
set_parodus_cfg(&cfg);
|
||||
|
||||
pthread_mutex_lock (&close_mut);
|
||||
@@ -260,7 +306,8 @@ void test_createSocketConnection2()
|
||||
expect_function_call(createNopollConnection);
|
||||
expect_function_call(packMetaData);
|
||||
|
||||
expect_function_calls(StartThread, 4);
|
||||
expect_function_calls(StartThread, 5);
|
||||
//Increment ping interval time to 1 sec for each nopoll_loop_wait call
|
||||
will_return(nopoll_loop_wait, 1);
|
||||
will_return(nopoll_loop_wait, 1);
|
||||
will_return(nopoll_loop_wait, 1);
|
||||
@@ -269,9 +316,10 @@ void test_createSocketConnection2()
|
||||
will_return(nopoll_loop_wait, 1);
|
||||
will_return(nopoll_loop_wait, 1);
|
||||
expect_function_calls(nopoll_loop_wait, 7);
|
||||
|
||||
//Expecting Ping miss after 6 sec
|
||||
expect_function_call(set_global_reconnect_reason);
|
||||
will_return(get_global_conn, (intptr_t)NULL);
|
||||
expect_function_call(set_global_reconnect_status);
|
||||
expect_function_call(get_global_conn);
|
||||
expect_function_call(close_and_unref_connection);
|
||||
expect_function_call(set_global_conn);
|
||||
@@ -283,6 +331,7 @@ void test_createSocketConnection2()
|
||||
expect_function_call(nopoll_ctx_unref);
|
||||
expect_function_call(nopoll_cleanup_library);
|
||||
createSocketConnection(NULL);
|
||||
|
||||
}
|
||||
|
||||
void err_createSocketConnection()
|
||||
@@ -290,7 +339,7 @@ void err_createSocketConnection()
|
||||
pthread_mutex_lock (&close_mut);
|
||||
close_retry = true;
|
||||
pthread_mutex_unlock (&close_mut);
|
||||
heartBeatTimer = 0;
|
||||
reset_heartBeatTimer();
|
||||
expect_function_call(nopoll_thread_handlers);
|
||||
|
||||
will_return(nopoll_ctx_new, (intptr_t)NULL);
|
||||
@@ -300,7 +349,7 @@ void err_createSocketConnection()
|
||||
expect_function_call(createNopollConnection);
|
||||
expect_function_call(packMetaData);
|
||||
|
||||
expect_function_calls(StartThread, 4);
|
||||
expect_function_calls(StartThread, 5);
|
||||
will_return(nopoll_loop_wait, 1);
|
||||
expect_function_call(nopoll_loop_wait);
|
||||
|
||||
@@ -327,7 +376,7 @@ int main(void)
|
||||
const struct CMUnitTest tests[] = {
|
||||
cmocka_unit_test(test_createSocketConnection),
|
||||
cmocka_unit_test(test_createSocketConnection1),
|
||||
cmocka_unit_test(test_createSocketConnection2),
|
||||
cmocka_unit_test(test_PingMissIntervalTime),
|
||||
cmocka_unit_test(err_createSocketConnection),
|
||||
};
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
395
tests/test_crud_interface.c
Normal file
395
tests/test_crud_interface.c
Normal file
@@ -0,0 +1,395 @@
|
||||
/**
|
||||
* Copyright 2010-2016 Comcast Cable Communications Management, LLC
|
||||
*
|
||||
* 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 <assert.h>
|
||||
#include <errno.h>
|
||||
#include <pthread.h>
|
||||
#include <malloc.h>
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
#include <setjmp.h>
|
||||
#include <cmocka.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <wrp-c.h>
|
||||
#include "../src/crud_interface.h"
|
||||
#include "../src/config.h"
|
||||
#include "../src/client_list.h"
|
||||
#include "../src/ParodusInternal.h"
|
||||
#include "../src/partners_check.h"
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* File Scoped Variables */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
extern CrudMsg *crudMsgQ;
|
||||
int numLoops = 1;
|
||||
wrp_msg_t *temp = NULL;
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Mocks */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
char * get_global_UpStreamMsgQ(void)
|
||||
{
|
||||
function_called();
|
||||
return (char *)mock();
|
||||
}
|
||||
|
||||
int set_global_UpStreamMsgQ(void)
|
||||
{
|
||||
function_called();
|
||||
return (int)mock();
|
||||
}
|
||||
|
||||
int get_global_nano_con(void)
|
||||
{
|
||||
function_called();
|
||||
return (int)mock();
|
||||
}
|
||||
|
||||
int get_global_nano_mut(void)
|
||||
{
|
||||
function_called();
|
||||
return (int)mock();
|
||||
}
|
||||
|
||||
char *get_global_reconnect_reason()
|
||||
{
|
||||
function_called();
|
||||
return (char *)(intptr_t)mock();
|
||||
}
|
||||
|
||||
ParodusCfg *get_parodus_cfg(void)
|
||||
{
|
||||
function_called();
|
||||
return (ParodusCfg*) (intptr_t)mock();
|
||||
}
|
||||
|
||||
int pthread_mutex_lock(pthread_mutex_t *restrict mutex)
|
||||
{
|
||||
UNUSED(mutex);
|
||||
function_called();
|
||||
return (int)mock();
|
||||
}
|
||||
|
||||
int pthread_mutex_unlock(pthread_mutex_t *restrict mutex)
|
||||
{
|
||||
UNUSED(mutex);
|
||||
function_called();
|
||||
return (int)mock();
|
||||
}
|
||||
|
||||
int pthread_cond_signal(pthread_cond_t *restrict cond)
|
||||
{
|
||||
UNUSED(cond);
|
||||
function_called();
|
||||
return (int)mock();
|
||||
}
|
||||
|
||||
int pthread_cond_wait(pthread_cond_t *restrict cond, pthread_mutex_t *restrict mutex)
|
||||
{
|
||||
UNUSED(cond); UNUSED(mutex);
|
||||
function_called();
|
||||
return (int)mock();
|
||||
}
|
||||
|
||||
|
||||
int processCrudRequest(wrp_msg_t *reqMsg, wrp_msg_t **responseMsg )
|
||||
{
|
||||
UNUSED(reqMsg);
|
||||
wrp_msg_t *resp_msg = NULL;
|
||||
resp_msg = ( wrp_msg_t *)malloc( sizeof( wrp_msg_t ) );
|
||||
memset(resp_msg, 0, sizeof(wrp_msg_t));
|
||||
|
||||
resp_msg->msg_type = 5;
|
||||
resp_msg->u.crud.transaction_uuid = strdup("1234");
|
||||
resp_msg->u.crud.source = strdup("tag-update");
|
||||
resp_msg->u.crud.dest = strdup("mac:14xxx/parodus/tags");
|
||||
*responseMsg = resp_msg;
|
||||
function_called();
|
||||
return (int)mock();
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Tests */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
void test_addCRUDmsgToQueue()
|
||||
{
|
||||
|
||||
wrp_msg_t *crud_msg = NULL;
|
||||
crud_msg = ( wrp_msg_t *)malloc( sizeof( wrp_msg_t ) );
|
||||
memset(crud_msg, 0, sizeof(wrp_msg_t));
|
||||
|
||||
crud_msg->msg_type = 5;
|
||||
crud_msg->u.crud.transaction_uuid = strdup("bd4ad2d1-5c9c-486f-8e25-52c242b38f71");
|
||||
crud_msg->u.crud.source = strdup("tag-update");
|
||||
crud_msg->u.crud.dest = strdup("mac:14xxx/parodus/tags");
|
||||
|
||||
will_return(pthread_mutex_lock, 0);
|
||||
expect_function_call(pthread_mutex_lock);
|
||||
|
||||
will_return(pthread_mutex_unlock, 0);
|
||||
expect_function_call(pthread_mutex_unlock);
|
||||
|
||||
crudMsgQ = (CrudMsg *)malloc(sizeof(CrudMsg));
|
||||
crudMsgQ->msg = crud_msg;
|
||||
|
||||
crudMsgQ->next = (CrudMsg *) malloc(sizeof(CrudMsg));
|
||||
crudMsgQ->next->msg = crud_msg;
|
||||
crudMsgQ->next->next = NULL;
|
||||
|
||||
addCRUDmsgToQueue(crud_msg);
|
||||
|
||||
free(crudMsgQ->next);
|
||||
free(crudMsgQ);
|
||||
crudMsgQ = NULL;
|
||||
|
||||
wrp_free_struct(crud_msg);
|
||||
|
||||
}
|
||||
|
||||
|
||||
void test_addCRUDmsgToQueueNULL()
|
||||
{
|
||||
wrp_msg_t *crud_msg = NULL;
|
||||
crud_msg = ( wrp_msg_t *)malloc( sizeof( wrp_msg_t ) );
|
||||
memset(crud_msg, 0, sizeof(wrp_msg_t));
|
||||
|
||||
crud_msg->msg_type = 5;
|
||||
crud_msg->u.crud.transaction_uuid = strdup("bd4ad2d1-5c9c-486f-8e25-52c242b38f71");
|
||||
crud_msg->u.crud.source = strdup("tag-update");
|
||||
crud_msg->u.crud.dest = strdup("mac:14xxx/parodus/tags");
|
||||
|
||||
will_return(pthread_mutex_lock, 0);
|
||||
expect_function_call(pthread_mutex_lock);
|
||||
|
||||
will_return(pthread_cond_signal, 0);
|
||||
expect_function_call(pthread_cond_signal);
|
||||
|
||||
will_return(pthread_mutex_unlock, 0);
|
||||
expect_function_call(pthread_mutex_unlock);
|
||||
|
||||
addCRUDmsgToQueue(crud_msg);
|
||||
|
||||
free(crudMsgQ->next);
|
||||
free(crudMsgQ);
|
||||
crudMsgQ = NULL;
|
||||
wrp_free_struct(crud_msg);
|
||||
|
||||
}
|
||||
|
||||
void err_CRUDHandlerTask()
|
||||
{
|
||||
numLoops = 1;
|
||||
crudMsgQ = NULL;
|
||||
|
||||
will_return(pthread_mutex_lock, 0);
|
||||
expect_function_call(pthread_mutex_lock);
|
||||
|
||||
will_return(pthread_cond_wait, 0);
|
||||
expect_function_call(pthread_cond_wait);
|
||||
|
||||
will_return(pthread_mutex_unlock, 0);
|
||||
expect_function_call(pthread_mutex_unlock);
|
||||
|
||||
CRUDHandlerTask();
|
||||
}
|
||||
|
||||
|
||||
void test_CRUDHandlerTask()
|
||||
{
|
||||
numLoops = 1;
|
||||
wrp_msg_t *crud_msg = NULL;
|
||||
crud_msg = ( wrp_msg_t *)malloc( sizeof( wrp_msg_t ) );
|
||||
memset(crud_msg, 0, sizeof(wrp_msg_t));
|
||||
|
||||
crud_msg->msg_type = 5;
|
||||
crud_msg->u.crud.transaction_uuid = strdup("bd4ad2d1-5c9c-486f-8e25-52c242b38f71");
|
||||
crud_msg->u.crud.source = strdup("tag-update");
|
||||
crud_msg->u.crud.dest = strdup("mac:14xxx/parodus/tags");
|
||||
|
||||
crudMsgQ = (CrudMsg *)malloc(sizeof(CrudMsg));
|
||||
crudMsgQ->msg = crud_msg;
|
||||
crudMsgQ->next = NULL;
|
||||
|
||||
will_return(pthread_mutex_lock, 0);
|
||||
expect_function_call(pthread_mutex_lock);
|
||||
|
||||
will_return(pthread_mutex_unlock, 0);
|
||||
expect_function_call(pthread_mutex_unlock);
|
||||
|
||||
will_return(processCrudRequest, 0);
|
||||
expect_function_call(processCrudRequest);
|
||||
|
||||
will_return(get_global_nano_mut, 0);
|
||||
expect_function_call(get_global_nano_mut);
|
||||
|
||||
will_return(pthread_mutex_lock, 0);
|
||||
expect_function_call(pthread_mutex_lock);
|
||||
|
||||
will_return(get_global_UpStreamMsgQ, NULL);
|
||||
expect_function_call(get_global_UpStreamMsgQ);
|
||||
|
||||
will_return(set_global_UpStreamMsgQ, 0);
|
||||
expect_function_call(set_global_UpStreamMsgQ);
|
||||
|
||||
will_return(get_global_nano_con, 0);
|
||||
expect_function_call(get_global_nano_con);
|
||||
|
||||
will_return(pthread_cond_signal, 0);
|
||||
expect_function_call(pthread_cond_signal);
|
||||
|
||||
will_return(get_global_nano_mut, 0);
|
||||
expect_function_call(get_global_nano_mut);
|
||||
|
||||
will_return(pthread_mutex_unlock, 0);
|
||||
expect_function_call(pthread_mutex_unlock);
|
||||
|
||||
CRUDHandlerTask();
|
||||
|
||||
free(crudMsgQ);
|
||||
|
||||
}
|
||||
|
||||
void test_CRUDHandlerTaskFailure()
|
||||
{
|
||||
numLoops = 1;
|
||||
wrp_msg_t *crud_msg = NULL;
|
||||
|
||||
crud_msg = ( wrp_msg_t *)malloc( sizeof( wrp_msg_t ) );
|
||||
memset(crud_msg, 0, sizeof(wrp_msg_t));
|
||||
|
||||
crud_msg->msg_type = 5;
|
||||
crud_msg->u.crud.transaction_uuid = strdup("bd4ad2d1-5c9c-486f-8e25-52c242b38f71");
|
||||
crud_msg->u.crud.source = strdup("tag-update");
|
||||
crud_msg->u.crud.dest = strdup("mac:14xxx/parodus/tags");
|
||||
|
||||
crudMsgQ = (CrudMsg *)malloc(sizeof(CrudMsg));
|
||||
crudMsgQ->msg = crud_msg;
|
||||
crudMsgQ->next = NULL;
|
||||
|
||||
will_return(pthread_mutex_lock, 0);
|
||||
expect_function_call(pthread_mutex_lock);
|
||||
|
||||
will_return(pthread_mutex_unlock, 0);
|
||||
expect_function_call(pthread_mutex_unlock);
|
||||
|
||||
will_return(processCrudRequest, -1);
|
||||
expect_function_call(processCrudRequest);
|
||||
|
||||
|
||||
will_return(get_global_nano_mut, 0);
|
||||
expect_function_call(get_global_nano_mut);
|
||||
|
||||
will_return(pthread_mutex_lock, 0);
|
||||
expect_function_call(pthread_mutex_lock);
|
||||
|
||||
will_return(get_global_UpStreamMsgQ, 0);
|
||||
expect_function_call(get_global_UpStreamMsgQ);
|
||||
|
||||
will_return(set_global_UpStreamMsgQ, 0);
|
||||
expect_function_call(set_global_UpStreamMsgQ);
|
||||
|
||||
will_return(get_global_nano_con, 0);
|
||||
expect_function_call(get_global_nano_con);
|
||||
|
||||
will_return(pthread_cond_signal, 0);
|
||||
expect_function_call(pthread_cond_signal);
|
||||
|
||||
will_return(get_global_nano_mut, 0);
|
||||
expect_function_call(get_global_nano_mut);
|
||||
|
||||
will_return(pthread_mutex_unlock, 0);
|
||||
expect_function_call(pthread_mutex_unlock);
|
||||
|
||||
|
||||
CRUDHandlerTask();
|
||||
|
||||
free(crudMsgQ);
|
||||
|
||||
}
|
||||
|
||||
void test_addCRUDresponseToUpstreamQ()
|
||||
{
|
||||
numLoops = 1;
|
||||
ssize_t resp_size = 0;
|
||||
void *resp_bytes;
|
||||
|
||||
wrp_msg_t *resp_msg = NULL;
|
||||
resp_msg = ( wrp_msg_t *)malloc( sizeof( wrp_msg_t ) );
|
||||
memset(resp_msg, 0, sizeof(wrp_msg_t));
|
||||
|
||||
resp_msg->msg_type = 5;
|
||||
resp_msg->u.crud.transaction_uuid = strdup("1234");
|
||||
resp_msg->u.crud.source = strdup("tag-update");
|
||||
resp_msg->u.crud.dest = strdup("mac:14xxx/parodus/tags");
|
||||
|
||||
resp_size = wrp_struct_to( resp_msg, WRP_BYTES, &resp_bytes );
|
||||
|
||||
will_return(get_global_nano_mut, 0);
|
||||
expect_function_call(get_global_nano_mut);
|
||||
|
||||
will_return(pthread_mutex_lock, 0);
|
||||
expect_function_call(pthread_mutex_lock);
|
||||
|
||||
will_return(get_global_UpStreamMsgQ, 0);
|
||||
expect_function_call(get_global_UpStreamMsgQ);
|
||||
|
||||
will_return(set_global_UpStreamMsgQ, 0);
|
||||
expect_function_call(set_global_UpStreamMsgQ);
|
||||
|
||||
will_return(get_global_nano_con, 0);
|
||||
expect_function_call(get_global_nano_con);
|
||||
|
||||
will_return(pthread_cond_signal, 0);
|
||||
expect_function_call(pthread_cond_signal);
|
||||
|
||||
will_return(get_global_nano_mut, 0);
|
||||
expect_function_call(get_global_nano_mut);
|
||||
|
||||
will_return(pthread_mutex_unlock, 0);
|
||||
expect_function_call(pthread_mutex_unlock);
|
||||
|
||||
addCRUDresponseToUpstreamQ(resp_bytes, resp_size);
|
||||
|
||||
wrp_free_struct(resp_msg);
|
||||
|
||||
}
|
||||
|
||||
|
||||
void test_addCRUDmsgToQueueAllocation()
|
||||
{
|
||||
addCRUDmsgToQueue(NULL);
|
||||
}
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* External Functions */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
int main(void)
|
||||
{
|
||||
const struct CMUnitTest tests[] = {
|
||||
cmocka_unit_test(test_addCRUDmsgToQueueNULL),
|
||||
cmocka_unit_test(test_addCRUDmsgToQueue),
|
||||
cmocka_unit_test(test_addCRUDmsgToQueueAllocation),
|
||||
cmocka_unit_test(err_CRUDHandlerTask),
|
||||
cmocka_unit_test(test_CRUDHandlerTask),
|
||||
cmocka_unit_test(test_CRUDHandlerTaskFailure),
|
||||
cmocka_unit_test(test_addCRUDresponseToUpstreamQ)
|
||||
};
|
||||
|
||||
return cmocka_run_group_tests(tests, NULL, NULL);
|
||||
}
|
||||
2691
tests/test_crud_internal.c
Normal file
2691
tests/test_crud_internal.c
Normal file
File diff suppressed because it is too large
Load Diff
283
tests/test_crud_tasks.c
Normal file
283
tests/test_crud_tasks.c
Normal file
@@ -0,0 +1,283 @@
|
||||
/**
|
||||
* Copyright 2010-2016 Comcast Cable Communications Management, LLC
|
||||
*
|
||||
* 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 <assert.h>
|
||||
#include <errno.h>
|
||||
#include <pthread.h>
|
||||
#include <malloc.h>
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
#include <setjmp.h>
|
||||
#include <cmocka.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <wrp-c.h>
|
||||
#include "../src/crud_tasks.h"
|
||||
#include "../src/config.h"
|
||||
#include "../src/client_list.h"
|
||||
#include "../src/ParodusInternal.h"
|
||||
#include "../src/partners_check.h"
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* File Scoped Variables */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
wrp_msg_t *response = NULL;
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Mocks */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
cJSON * cJSON_Parse(const char *payload)
|
||||
{
|
||||
UNUSED(payload);
|
||||
function_called();
|
||||
return (cJSON *) mock();
|
||||
}
|
||||
|
||||
int createObject(wrp_msg_t *reqMsg , wrp_msg_t **response)
|
||||
{
|
||||
UNUSED(reqMsg); UNUSED(response);
|
||||
function_called();
|
||||
return (int) mock();
|
||||
}
|
||||
|
||||
int retrieveObject(wrp_msg_t *reqMsg , wrp_msg_t **response)
|
||||
{
|
||||
UNUSED(reqMsg); UNUSED(response);
|
||||
function_called();
|
||||
return (int) mock();
|
||||
}
|
||||
|
||||
int updateObject(wrp_msg_t *reqMsg , wrp_msg_t **response)
|
||||
{
|
||||
UNUSED(reqMsg); UNUSED(response);
|
||||
function_called();
|
||||
return (int) mock();
|
||||
}
|
||||
|
||||
int deleteObject(wrp_msg_t *reqMsg , wrp_msg_t **response)
|
||||
{
|
||||
UNUSED(reqMsg); UNUSED(response);
|
||||
function_called();
|
||||
return (int) mock();
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Tests */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
void test_processCrudRequestCreate()
|
||||
{
|
||||
int ret = -1;
|
||||
wrp_msg_t *reqMsg = NULL;
|
||||
reqMsg = ( wrp_msg_t *)malloc( sizeof( wrp_msg_t ) );
|
||||
memset(reqMsg, 0, sizeof(wrp_msg_t));
|
||||
|
||||
reqMsg->msg_type = 5;
|
||||
reqMsg->u.crud.transaction_uuid = strdup("1234");
|
||||
reqMsg->u.crud.source = strdup("tag-update");
|
||||
reqMsg->u.crud.dest = strdup("mac:14xxx/parodus/tags");
|
||||
will_return(createObject, 0);
|
||||
expect_function_call(createObject);
|
||||
|
||||
ret = processCrudRequest(reqMsg, &response);
|
||||
assert_int_equal(ret, 0);
|
||||
|
||||
wrp_free_struct(reqMsg);
|
||||
|
||||
}
|
||||
|
||||
void test_processCrudRequestCreateFailure()
|
||||
{
|
||||
int ret = -2;
|
||||
wrp_msg_t *reqMsg = NULL;
|
||||
reqMsg = ( wrp_msg_t *)malloc( sizeof( wrp_msg_t ) );
|
||||
memset(reqMsg, 0, sizeof(wrp_msg_t));
|
||||
|
||||
reqMsg->msg_type = 5;
|
||||
reqMsg->u.crud.transaction_uuid = strdup("1234");
|
||||
reqMsg->u.crud.source = strdup("tag-update");
|
||||
reqMsg->u.crud.dest = strdup("mac:14xxx/parodus/tags");
|
||||
will_return(createObject, -1);
|
||||
expect_function_call(createObject);
|
||||
ret = processCrudRequest(reqMsg, &response);
|
||||
assert_int_equal(ret, -1);
|
||||
|
||||
wrp_free_struct(reqMsg);
|
||||
|
||||
}
|
||||
|
||||
void test_processCrudRequestRetrieve()
|
||||
{
|
||||
int ret = -2;
|
||||
wrp_msg_t *reqMsg = NULL;
|
||||
reqMsg = ( wrp_msg_t *)malloc( sizeof( wrp_msg_t ) );
|
||||
memset(reqMsg, 0, sizeof(wrp_msg_t));
|
||||
|
||||
reqMsg->msg_type = 6;
|
||||
reqMsg->u.crud.transaction_uuid = strdup("1234");
|
||||
reqMsg->u.crud.source = strdup("tag-update");
|
||||
reqMsg->u.crud.dest = strdup("mac:14xxx/parodus/tags");
|
||||
will_return(retrieveObject, 0);
|
||||
expect_function_call(retrieveObject);
|
||||
ret = processCrudRequest(reqMsg, &response);
|
||||
assert_int_equal(ret, 0);
|
||||
|
||||
wrp_free_struct(reqMsg);
|
||||
|
||||
}
|
||||
|
||||
void test_processCrudRequestRetrieveFailure()
|
||||
{
|
||||
int ret = -2;
|
||||
wrp_msg_t *reqMsg = NULL;
|
||||
reqMsg = ( wrp_msg_t *)malloc( sizeof( wrp_msg_t ) );
|
||||
memset(reqMsg, 0, sizeof(wrp_msg_t));
|
||||
|
||||
reqMsg->msg_type = 6;
|
||||
reqMsg->u.crud.transaction_uuid = strdup("1234");
|
||||
reqMsg->u.crud.source = strdup("tag-update");
|
||||
reqMsg->u.crud.dest = strdup("mac:14xxx/parodus/tags");
|
||||
will_return(retrieveObject, -1);
|
||||
expect_function_call(retrieveObject);
|
||||
|
||||
ret = processCrudRequest(reqMsg, &response);
|
||||
assert_int_equal(ret, -1);
|
||||
|
||||
wrp_free_struct(reqMsg);
|
||||
|
||||
}
|
||||
|
||||
void test_processCrudRequestUpdate()
|
||||
{
|
||||
int ret = -2;
|
||||
wrp_msg_t *reqMsg = NULL;
|
||||
reqMsg = ( wrp_msg_t *)malloc( sizeof( wrp_msg_t ) );
|
||||
memset(reqMsg, 0, sizeof(wrp_msg_t));
|
||||
|
||||
reqMsg->msg_type = 7;
|
||||
reqMsg->u.crud.transaction_uuid = strdup("1234");
|
||||
reqMsg->u.crud.source = strdup("tag-update");
|
||||
reqMsg->u.crud.dest = strdup("mac:14xxx/parodus/tags");
|
||||
will_return(updateObject, 0);
|
||||
expect_function_call(updateObject);
|
||||
ret = processCrudRequest(reqMsg, &response);
|
||||
assert_int_equal(ret, 0);
|
||||
|
||||
wrp_free_struct(reqMsg);
|
||||
|
||||
}
|
||||
|
||||
void test_processCrudRequestUpdateFailure()
|
||||
{
|
||||
int ret = -2;
|
||||
wrp_msg_t *reqMsg = NULL;
|
||||
reqMsg = ( wrp_msg_t *)malloc( sizeof( wrp_msg_t ) );
|
||||
memset(reqMsg, 0, sizeof(wrp_msg_t));
|
||||
|
||||
reqMsg->msg_type = 7;
|
||||
reqMsg->u.crud.transaction_uuid = strdup("1234");
|
||||
reqMsg->u.crud.source = strdup("tag-update");
|
||||
reqMsg->u.crud.dest = strdup("mac:14xxx/parodus/tags");
|
||||
will_return(updateObject, -1);
|
||||
expect_function_call(updateObject);
|
||||
|
||||
ret = processCrudRequest(reqMsg, &response);
|
||||
assert_int_equal(ret, -1);
|
||||
|
||||
wrp_free_struct(reqMsg);
|
||||
|
||||
}
|
||||
|
||||
void test_processCrudRequestDelete()
|
||||
{
|
||||
int ret = -2;
|
||||
wrp_msg_t *reqMsg = NULL;
|
||||
reqMsg = ( wrp_msg_t *)malloc( sizeof( wrp_msg_t ) );
|
||||
memset(reqMsg, 0, sizeof(wrp_msg_t));
|
||||
|
||||
reqMsg->msg_type = 8;
|
||||
reqMsg->u.crud.transaction_uuid = strdup("1234");
|
||||
reqMsg->u.crud.source = strdup("tag-update");
|
||||
reqMsg->u.crud.dest = strdup("mac:14xxx/parodus/tags");
|
||||
will_return(deleteObject, 0);
|
||||
expect_function_call(deleteObject);
|
||||
ret = processCrudRequest(reqMsg, &response);
|
||||
assert_int_equal(ret, 0);
|
||||
|
||||
wrp_free_struct(reqMsg);
|
||||
|
||||
}
|
||||
|
||||
void test_processCrudRequestDeleteFailure()
|
||||
{
|
||||
int ret = -2;
|
||||
wrp_msg_t *reqMsg = NULL;
|
||||
reqMsg = ( wrp_msg_t *)malloc( sizeof( wrp_msg_t ) );
|
||||
memset(reqMsg, 0, sizeof(wrp_msg_t));
|
||||
|
||||
reqMsg->msg_type = 8;
|
||||
reqMsg->u.crud.transaction_uuid = strdup("1234");
|
||||
reqMsg->u.crud.source = strdup("tag-update");
|
||||
reqMsg->u.crud.dest = strdup("mac:14xxx/parodus/tags");
|
||||
will_return(deleteObject, -1);
|
||||
expect_function_call(deleteObject);
|
||||
|
||||
ret = processCrudRequest(reqMsg, &response);
|
||||
assert_int_equal(ret, -1);
|
||||
|
||||
wrp_free_struct(reqMsg);
|
||||
|
||||
}
|
||||
|
||||
void test_processCrudRequestFailure()
|
||||
{
|
||||
int ret = -2;
|
||||
wrp_msg_t *reqMsg = NULL;
|
||||
reqMsg = ( wrp_msg_t *)malloc( sizeof( wrp_msg_t ) );
|
||||
memset(reqMsg, 0, sizeof(wrp_msg_t));
|
||||
|
||||
reqMsg->msg_type = 3;
|
||||
reqMsg->u.crud.transaction_uuid = strdup("1234");
|
||||
reqMsg->u.crud.source = strdup("tag-update");
|
||||
reqMsg->u.crud.dest = strdup("mac:14xxx/parodus/tags");
|
||||
|
||||
ret = processCrudRequest(reqMsg, &response);
|
||||
assert_int_equal(ret, 0);
|
||||
|
||||
wrp_free_struct(reqMsg);
|
||||
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* External Functions */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
int main(void)
|
||||
{
|
||||
const struct CMUnitTest tests[] = {
|
||||
cmocka_unit_test(test_processCrudRequestCreate),
|
||||
cmocka_unit_test(test_processCrudRequestCreateFailure),
|
||||
cmocka_unit_test(test_processCrudRequestRetrieve),
|
||||
cmocka_unit_test(test_processCrudRequestRetrieveFailure),
|
||||
cmocka_unit_test(test_processCrudRequestUpdate),
|
||||
cmocka_unit_test(test_processCrudRequestUpdateFailure),
|
||||
cmocka_unit_test(test_processCrudRequestDelete),
|
||||
cmocka_unit_test(test_processCrudRequestDeleteFailure),
|
||||
cmocka_unit_test(test_processCrudRequestFailure),
|
||||
};
|
||||
|
||||
return cmocka_run_group_tests(tests, NULL, NULL);
|
||||
}
|
||||
@@ -21,6 +21,7 @@
|
||||
#include <stddef.h>
|
||||
#include <setjmp.h>
|
||||
#include <cmocka.h>
|
||||
#include <wrp-c.h>
|
||||
|
||||
#include "../src/downstream.h"
|
||||
#include "../src/ParodusInternal.h"
|
||||
@@ -32,9 +33,16 @@
|
||||
ParodusMsg *ParodusMsgQ;
|
||||
pthread_mutex_t g_mutex;
|
||||
pthread_cond_t g_cond;
|
||||
int crud_test = 0;
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Mocks */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
void addCRUDmsgToQueue(wrp_msg_t *crudMsg)
|
||||
{
|
||||
UNUSED(crudMsg) ;
|
||||
function_called();
|
||||
}
|
||||
|
||||
void sendUpstreamMsgToServer(void **resp_bytes, size_t resp_size)
|
||||
{
|
||||
UNUSED(resp_bytes); UNUSED(resp_size);
|
||||
@@ -60,13 +68,20 @@ ssize_t wrp_to_struct( const void *bytes, const size_t length,
|
||||
function_called();
|
||||
*msg = (wrp_msg_t*) malloc(sizeof(wrp_msg_t));
|
||||
memset(*msg, 0, sizeof(wrp_msg_t));
|
||||
(*msg)->msg_type = WRP_MSG_TYPE__REQ;
|
||||
(*msg)->u.req.dest = (char *) malloc(sizeof(char) *100);
|
||||
(*msg)->u.req.partner_ids = (partners_t *) malloc(sizeof(partners_t));
|
||||
(*msg)->u.req.partner_ids->count = 1;
|
||||
(*msg)->u.req.partner_ids->partner_ids[0] = (char *) malloc(sizeof(char) *64);
|
||||
parStrncpy((*msg)->u.req.dest,"mac:1122334455/iot", 100);
|
||||
parStrncpy((*msg)->u.req.partner_ids->partner_ids[0],"comcast", 64);
|
||||
(*msg)->msg_type = WRP_MSG_TYPE__REQ;
|
||||
(*msg)->u.req.dest = (char *) malloc(sizeof(char) *100);
|
||||
(*msg)->u.req.partner_ids = (partners_t *) malloc(sizeof(partners_t));
|
||||
(*msg)->u.req.partner_ids->count = 1;
|
||||
(*msg)->u.req.partner_ids->partner_ids[0] = (char *) malloc(sizeof(char) *64);
|
||||
parStrncpy((*msg)->u.req.dest,"mac:1122334455/iot", 100);
|
||||
parStrncpy((*msg)->u.req.partner_ids->partner_ids[0],"comcast", 64);
|
||||
if(crud_test)
|
||||
{
|
||||
(*msg)->msg_type = WRP_MSG_TYPE__CREATE;
|
||||
parStrncpy((*msg)->u.crud.dest,"mac:1122334455/parodus", 100);
|
||||
(*msg)->u.crud.source = "tag-update";
|
||||
(*msg)->u.crud.transaction_uuid = "1234";
|
||||
}
|
||||
return (ssize_t) mock();
|
||||
}
|
||||
|
||||
@@ -189,6 +204,23 @@ void err_listenerOnMessageAllNull()
|
||||
listenerOnMessage(NULL, 0);
|
||||
}
|
||||
|
||||
|
||||
void test_listenerOnMessageCRUD()
|
||||
{
|
||||
crud_test = 1;
|
||||
will_return(wrp_to_struct, 2);
|
||||
expect_function_calls(wrp_to_struct, 1);
|
||||
|
||||
will_return(get_numOfClients, 0);
|
||||
expect_function_call(get_numOfClients);
|
||||
will_return(validate_partner_id, 0);
|
||||
expect_function_call(validate_partner_id);
|
||||
will_return(get_global_node, (intptr_t)NULL);
|
||||
expect_function_call(get_global_node);
|
||||
expect_function_call(addCRUDmsgToQueue);
|
||||
listenerOnMessage("Hello", 6);
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* External Functions */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
@@ -202,6 +234,7 @@ int main(void)
|
||||
cmocka_unit_test(err_listenerOnMessageServiceUnavailable),
|
||||
cmocka_unit_test(err_listenerOnMessageInvalidPartnerId),
|
||||
cmocka_unit_test(err_listenerOnMessageAllNull),
|
||||
cmocka_unit_test(test_listenerOnMessageCRUD),
|
||||
};
|
||||
|
||||
return cmocka_run_group_tests(tests, NULL, NULL);
|
||||
|
||||
@@ -58,7 +58,7 @@ static test_t tests[] = {
|
||||
|
||||
.r.msg_type = WRP_MSG_TYPE__CREATE,
|
||||
.r.u.crud.transaction_uuid = "c2bb1f16-09c8-11e7-93ae-92361f002671",
|
||||
.r.u.crud.source = "fake-client1",
|
||||
.r.u.crud.source = "fake-client1/iot",
|
||||
.r.u.crud.dest = "fake-server1",
|
||||
.r.u.crud.partner_ids = NULL,
|
||||
.r.u.crud.headers = NULL,
|
||||
@@ -88,7 +88,7 @@ static test_t tests[] = {
|
||||
|
||||
.r.msg_type = WRP_MSG_TYPE__RETREIVE,
|
||||
.r.u.crud.transaction_uuid = "c2bb1f16-09c8-11e7-93ae-92361f002671",
|
||||
.r.u.crud.source = "fake-client2",
|
||||
.r.u.crud.source = "fake-client2/iot",
|
||||
.r.u.crud.dest = "fake-server2",
|
||||
.r.u.crud.partner_ids = NULL,
|
||||
.r.u.crud.headers = NULL,
|
||||
@@ -118,7 +118,7 @@ static test_t tests[] = {
|
||||
|
||||
.r.msg_type = WRP_MSG_TYPE__UPDATE,
|
||||
.r.u.crud.transaction_uuid = "c2bb1f16-09c8-11e7-93ae-92361f002671",
|
||||
.r.u.crud.source = "fake-client3",
|
||||
.r.u.crud.source = "fake-client3/iot",
|
||||
.r.u.crud.dest = "fake-server3",
|
||||
.r.u.crud.partner_ids = NULL,
|
||||
.r.u.crud.headers = NULL,
|
||||
@@ -148,7 +148,7 @@ static test_t tests[] = {
|
||||
|
||||
.r.msg_type = WRP_MSG_TYPE__DELETE,
|
||||
.r.u.crud.transaction_uuid = "c2bb1f16-09c8-11e7-93ae-92361f002671",
|
||||
.r.u.crud.source = "fake-client4",
|
||||
.r.u.crud.source = "fake-client4/iot",
|
||||
.r.u.crud.dest = "fake-server4",
|
||||
.r.u.crud.partner_ids = NULL,
|
||||
.r.u.crud.headers = NULL,
|
||||
@@ -180,6 +180,12 @@ static uint8_t i;
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Mocks */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
void addCRUDmsgToQueue(wrp_msg_t *crudMsg)
|
||||
{
|
||||
(void)crudMsg;
|
||||
return;
|
||||
}
|
||||
|
||||
int validate_partner_id(wrp_msg_t *msg, partners_t **partnerIds)
|
||||
{
|
||||
(void) msg; (void) partnerIds;
|
||||
|
||||
@@ -44,7 +44,7 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
void test_checkHostIp()
|
||||
{
|
||||
CU_ASSERT_EQUAL(0, checkHostIp("fabric.webpa.comcast.net"))
|
||||
CU_ASSERT_EQUAL(0, checkHostIp("www.python.org"))
|
||||
}
|
||||
|
||||
void add_suites( CU_pSuite *suite )
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
volatile unsigned int heartBeatTimer;
|
||||
bool LastReasonStatus;
|
||||
int closeReason = 0;
|
||||
pthread_mutex_t close_mut;
|
||||
bool close_retry;
|
||||
/*----------------------------------------------------------------------------*/
|
||||
@@ -40,6 +41,16 @@ void set_global_reconnect_reason(char *reason)
|
||||
(void) reason;
|
||||
}
|
||||
|
||||
bool get_global_reconnect_status()
|
||||
{
|
||||
return LastReasonStatus;
|
||||
}
|
||||
|
||||
void set_global_reconnect_status(bool status)
|
||||
{
|
||||
(void) status ;
|
||||
}
|
||||
|
||||
const unsigned char *nopoll_msg_get_payload(noPollMsg *msg)
|
||||
{
|
||||
if( NULL != msg ) {
|
||||
@@ -59,12 +70,27 @@ noPollOpCode nopoll_msg_opcode (noPollMsg * msg)
|
||||
return NOPOLL_UNKNOWN_OP_CODE;
|
||||
}
|
||||
|
||||
nopoll_bool nopoll_msg_is_fragment(noPollMsg *msg)
|
||||
{
|
||||
(void) msg;
|
||||
return nopoll_false;
|
||||
}
|
||||
|
||||
int nopoll_msg_get_payload_size(noPollMsg *msg)
|
||||
{
|
||||
(void) msg;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int nopoll_conn_get_close_status (noPollConn * conn)
|
||||
{
|
||||
(void) conn;
|
||||
if(closeReason)
|
||||
return 1006;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
int nopoll_conn_send_frame (noPollConn * conn, nopoll_bool fin, nopoll_bool masked,
|
||||
noPollOpCode op_code, long length, noPollPtr content, long sleep_in_header)
|
||||
|
||||
@@ -116,16 +142,16 @@ void *a1(void *in)
|
||||
char str[] = "SSL_Socket_Close";
|
||||
(void) in;
|
||||
|
||||
LastReasonStatus = false;
|
||||
set_global_reconnect_status(false);
|
||||
listenerOnCloseMessage(NULL, NULL, NULL);
|
||||
|
||||
LastReasonStatus = false;
|
||||
set_global_reconnect_status(false);
|
||||
listenerOnCloseMessage(NULL, NULL, (noPollPtr) str);
|
||||
|
||||
LastReasonStatus = true;
|
||||
set_global_reconnect_status(true);
|
||||
listenerOnCloseMessage(NULL, NULL, NULL);
|
||||
|
||||
LastReasonStatus = true;
|
||||
closeReason = 1;
|
||||
set_global_reconnect_status(true);
|
||||
listenerOnCloseMessage(NULL, NULL, (noPollPtr) str);
|
||||
|
||||
pthread_exit(0);
|
||||
|
||||
138
tests/test_nopoll_handlers_fragment.c
Normal file
138
tests/test_nopoll_handlers_fragment.c
Normal file
@@ -0,0 +1,138 @@
|
||||
/**
|
||||
* Copyright 2010-2016 Comcast Cable Communications Management, LLC
|
||||
*
|
||||
* 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 <assert.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdbool.h>
|
||||
#include <CUnit/Basic.h>
|
||||
#include <stddef.h>
|
||||
#include <setjmp.h>
|
||||
#include <cmocka.h>
|
||||
#include <nopoll.h>
|
||||
#include <nopoll_private.h>
|
||||
#include <pthread.h>
|
||||
|
||||
#include "../src/nopoll_handlers.h"
|
||||
#include "../src/parodus_log.h"
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* File Scoped Variables */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
volatile unsigned int heartBeatTimer;
|
||||
bool LastReasonStatus;
|
||||
pthread_mutex_t close_mut;
|
||||
bool close_retry;
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Mocks */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
void set_global_reconnect_reason(char *reason)
|
||||
{
|
||||
(void) reason;
|
||||
}
|
||||
|
||||
bool get_global_reconnect_status()
|
||||
{
|
||||
return LastReasonStatus;
|
||||
}
|
||||
|
||||
void set_global_reconnect_status(bool status)
|
||||
{
|
||||
(void) status ;
|
||||
}
|
||||
|
||||
nopoll_bool nopoll_msg_is_fragment(noPollMsg *msg)
|
||||
{
|
||||
(void)msg;
|
||||
function_called();
|
||||
return (nopoll_bool) mock();
|
||||
}
|
||||
|
||||
nopoll_bool nopoll_msg_is_final(noPollMsg *msg)
|
||||
{
|
||||
(void)msg;
|
||||
function_called();
|
||||
return (nopoll_bool) mock();
|
||||
}
|
||||
|
||||
const unsigned char *nopoll_msg_get_payload(noPollMsg *msg)
|
||||
{
|
||||
(void)msg;
|
||||
function_called();
|
||||
|
||||
|
||||
return (const unsigned char *) mock();
|
||||
}
|
||||
|
||||
int nopoll_msg_get_payload_size(noPollMsg *msg)
|
||||
{
|
||||
(void) msg;
|
||||
function_called ();
|
||||
return (int) mock();
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Tests */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
void test_listenerOnMessage_queue_fragment()
|
||||
{
|
||||
noPollMsg *msg, *msg1;
|
||||
msg = nopoll_msg_new ();
|
||||
//1st Fragment
|
||||
msg->payload_size = strlen("hello");
|
||||
msg->payload = nopoll_new (char, msg->payload_size + 1);
|
||||
|
||||
will_return(nopoll_msg_is_fragment, nopoll_true);
|
||||
expect_function_call(nopoll_msg_is_fragment);
|
||||
will_return(nopoll_msg_is_final, nopoll_false);
|
||||
will_return(nopoll_msg_is_final, nopoll_false);
|
||||
expect_function_calls(nopoll_msg_is_final, 2);
|
||||
|
||||
listenerOnMessage_queue(NULL, NULL, msg, NULL);
|
||||
|
||||
//2nd fragment/final message
|
||||
msg1 = nopoll_msg_new ();
|
||||
msg1->payload_size = strlen("world");
|
||||
msg1->payload = nopoll_new (char, msg->payload_size + 1);
|
||||
|
||||
will_return(nopoll_msg_is_fragment, nopoll_true);
|
||||
expect_function_call(nopoll_msg_is_fragment);
|
||||
will_return(nopoll_msg_is_final, nopoll_true);
|
||||
will_return(nopoll_msg_is_final, nopoll_true);
|
||||
expect_function_calls(nopoll_msg_is_final, 2);
|
||||
will_return(nopoll_msg_get_payload, (intptr_t)"helloworld");
|
||||
expect_function_call(nopoll_msg_get_payload);
|
||||
will_return(nopoll_msg_get_payload_size, 10);
|
||||
|
||||
expect_function_call(nopoll_msg_get_payload_size);
|
||||
listenerOnMessage_queue(NULL, NULL, msg1, NULL);
|
||||
//release the message
|
||||
nopoll_msg_unref(msg);
|
||||
nopoll_msg_unref(msg1);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* External Functions */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
int main( void )
|
||||
{
|
||||
const struct CMUnitTest tests[] = {
|
||||
cmocka_unit_test(test_listenerOnMessage_queue_fragment),
|
||||
};
|
||||
return cmocka_run_group_tests(tests, NULL, NULL);
|
||||
}
|
||||
@@ -96,6 +96,26 @@ void listenerOnCloseMessage (noPollCtx * ctx, noPollConn * conn, noPollPtr user_
|
||||
UNUSED(ctx); UNUSED(conn); UNUSED(user_data);
|
||||
}
|
||||
|
||||
void getCurrentTime(struct timespec *timer)
|
||||
{
|
||||
(void) timer;
|
||||
function_called();
|
||||
}
|
||||
|
||||
long timeValDiff(struct timespec *starttime, struct timespec *finishtime)
|
||||
{
|
||||
(void) starttime; (void) finishtime;
|
||||
function_called();
|
||||
return (long) mock();
|
||||
}
|
||||
|
||||
int kill(pid_t pid, int sig)
|
||||
{
|
||||
UNUSED(pid); UNUSED(sig);
|
||||
function_called();
|
||||
return (int) mock();
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Tests */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
@@ -202,6 +222,69 @@ void test_sendMessage()
|
||||
sendMessage(conn, "Hello Parodus!", len);
|
||||
}
|
||||
|
||||
void connStuck_sendMessage()
|
||||
{
|
||||
int len = strlen("Hello Parodus!");
|
||||
|
||||
/* Initialize the timer when connection gets stuck */
|
||||
expect_value(nopoll_conn_is_ok, (intptr_t)conn, (intptr_t)NULL);
|
||||
will_return(nopoll_conn_is_ok, nopoll_false);
|
||||
expect_function_call(nopoll_conn_is_ok);
|
||||
|
||||
expect_function_call(getCurrentTime);
|
||||
sendMessage(NULL, "Hello Parodus!", len);
|
||||
|
||||
/* When connection recovers within 10 mins, it should be able to re-connect */
|
||||
expect_value(nopoll_conn_is_ok, (intptr_t)conn, (intptr_t)NULL);
|
||||
will_return(nopoll_conn_is_ok, nopoll_false);
|
||||
expect_function_call(nopoll_conn_is_ok);
|
||||
|
||||
expect_function_call(getCurrentTime);
|
||||
|
||||
will_return(timeValDiff, 5*60*1000);
|
||||
expect_function_call(timeValDiff);
|
||||
|
||||
expect_value(nopoll_conn_is_ok, (intptr_t)conn, (intptr_t)conn);
|
||||
will_return(nopoll_conn_is_ok, nopoll_true);
|
||||
expect_function_call(nopoll_conn_is_ok);
|
||||
|
||||
expect_value(nopoll_conn_is_ready, (intptr_t)conn, (intptr_t)conn);
|
||||
will_return(nopoll_conn_is_ready, nopoll_true);
|
||||
expect_function_call(nopoll_conn_is_ready);
|
||||
|
||||
expect_value(__nopoll_conn_send_common, (intptr_t)conn, (intptr_t)conn);
|
||||
expect_value(__nopoll_conn_send_common, length, len);
|
||||
will_return(__nopoll_conn_send_common, len);
|
||||
expect_function_calls(__nopoll_conn_send_common, 1);
|
||||
|
||||
sendMessage(conn, "Hello Parodus!", len);
|
||||
|
||||
/* When timer exceeds more than 10 mins kill the process */
|
||||
expect_value(nopoll_conn_is_ok, (intptr_t)conn, (intptr_t)NULL);
|
||||
will_return(nopoll_conn_is_ok, nopoll_false);
|
||||
expect_function_call(nopoll_conn_is_ok);
|
||||
|
||||
sendMessage(NULL, "Hello Parodus!", len);
|
||||
|
||||
expect_function_call(getCurrentTime);
|
||||
|
||||
sendMessage(NULL, "Hello Parodus!", len);
|
||||
|
||||
expect_value(nopoll_conn_is_ok, (intptr_t)conn, (intptr_t)NULL);
|
||||
will_return(nopoll_conn_is_ok, nopoll_false);
|
||||
expect_function_call(nopoll_conn_is_ok);
|
||||
|
||||
expect_function_call(getCurrentTime);
|
||||
|
||||
will_return(timeValDiff, 10*60*1000);
|
||||
expect_function_call(timeValDiff);
|
||||
|
||||
will_return(kill, 1);
|
||||
expect_function_call(kill);
|
||||
|
||||
sendMessage(NULL, "Hello Parodus!", len);
|
||||
}
|
||||
|
||||
void err_sendMessage()
|
||||
{
|
||||
int len = strlen("Hello Parodus!");
|
||||
@@ -234,7 +317,9 @@ void err_sendMessageConnNull()
|
||||
expect_value(nopoll_conn_is_ok, (intptr_t)conn, (intptr_t)NULL);
|
||||
will_return(nopoll_conn_is_ok, nopoll_false);
|
||||
expect_function_call(nopoll_conn_is_ok);
|
||||
|
||||
|
||||
expect_function_call(getCurrentTime);
|
||||
|
||||
sendMessage(NULL, "Hello Parodus!", len);
|
||||
}
|
||||
|
||||
@@ -258,6 +343,7 @@ int main(void)
|
||||
cmocka_unit_test(err_sendResponseFlushWrites),
|
||||
cmocka_unit_test(err_sendResponseConnNull),
|
||||
cmocka_unit_test(test_sendMessage),
|
||||
cmocka_unit_test(connStuck_sendMessage),
|
||||
cmocka_unit_test(err_sendMessage),
|
||||
cmocka_unit_test(err_sendMessageConnNull),
|
||||
cmocka_unit_test(test_reportLog),
|
||||
|
||||
@@ -38,7 +38,16 @@ pthread_t threadId;
|
||||
/* Tests */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
void addCRUDmsgToQueue(wrp_msg_t *crudMsg)
|
||||
{
|
||||
(void)crudMsg;
|
||||
return;
|
||||
}
|
||||
|
||||
void *CRUDHandlerTask()
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
static void add_client()
|
||||
{
|
||||
const wrp_msg_t reg = { .msg_type = WRP_MSG_TYPE__SVC_REGISTRATION,
|
||||
@@ -114,6 +123,11 @@ static void *client_rcv_task()
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void handler(int signum)
|
||||
{
|
||||
UNUSED(signum);
|
||||
pthread_exit(NULL);
|
||||
}
|
||||
|
||||
static void *keep_alive_thread()
|
||||
{
|
||||
@@ -144,9 +158,10 @@ void test_keep_alive()
|
||||
}
|
||||
else
|
||||
{
|
||||
ParodusPrint("Thread created Successfully %d\n", (int ) threadId);
|
||||
ParodusPrint("Thread created Successfully %p\n", threadId);
|
||||
}
|
||||
sleep(3);
|
||||
signal(SIGUSR1, handler);
|
||||
|
||||
while( 1 )
|
||||
{
|
||||
@@ -156,9 +171,9 @@ void test_keep_alive()
|
||||
if(byte >0)
|
||||
{
|
||||
ParodusInfo("Received keep alive msg!!! : %s \n", (char * )buf);
|
||||
kill(threadId, SIGKILL);
|
||||
pthread_kill(threadId, SIGUSR1);
|
||||
|
||||
ParodusInfo("keep_alive_thread with tid %d is stopped\n", threadId);
|
||||
ParodusInfo("keep_alive_thread with tid %p is stopped\n", threadId);
|
||||
break;
|
||||
}
|
||||
else
|
||||
@@ -187,7 +202,6 @@ void add_suites( CU_pSuite *suite )
|
||||
ParodusInfo("--------Start of Test Cases Execution ---------\n");
|
||||
*suite = CU_add_suite( "tests", NULL, NULL );
|
||||
CU_add_test( *suite, "Test 1", test_keep_alive );
|
||||
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
#include <cmocka.h>
|
||||
#include <assert.h>
|
||||
#include <cjwt/cjwt.h>
|
||||
#include <wrp-c.h>
|
||||
|
||||
#include "../src/token.h"
|
||||
#include "../src/ParodusInternal.h"
|
||||
@@ -38,11 +39,11 @@ time_t exp_time_bad = 1463955372; // 5/22/2016
|
||||
|
||||
const char *payload_good = "{" \
|
||||
"\"iss\": \"SHA256:jdcRysFunWUAT852huQoIM9GN6k2s5c7iTMTMgujPAk\"," \
|
||||
"\"endpoint\": \"https://fabric.webpa.comcast.net:8080/\"}";
|
||||
"\"endpoint\": \"https://mydns.mycom.net:8080/\"}";
|
||||
|
||||
const char *payload_insec = "{" \
|
||||
"\"iss\": \"SHA256:jdcRysFunWUAT852huQoIM9GN6k2s5c7iTMTMgujPAk\"," \
|
||||
"\"endpoint\": \"http://fabric.webpa.comcast.net:8080/\"}";
|
||||
"\"endpoint\": \"http://mydns.mycom.net:8080/\"}";
|
||||
|
||||
// missing endpoint
|
||||
const char *payload_no_end = "{" \
|
||||
@@ -52,69 +53,89 @@ const char *txt_record_id = "aabbccddeeff.test.webpa.comcast.net";
|
||||
|
||||
#define MAX_RR_RECS 10
|
||||
|
||||
/*
|
||||
expiration = 2147483647 #1/18/2038
|
||||
endpoint = "https://mydns.mycom.net:8080/"
|
||||
|
||||
dns_rec_claims = {
|
||||
'iss': u'SHA256:jdcRysFunWUAT852huQoIM9GN6k2s5c7iTMTMgujPAk',
|
||||
'endpoint': endpoint,
|
||||
'exp': expiration
|
||||
}
|
||||
*/
|
||||
const char *dns_recs_test =
|
||||
"\"03:ji81f9B4vnaENEZJgPzYiYdVLvbkgg9rbI7RVcEjutIszb7XZA\"\n"
|
||||
"\"01:eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1MTQ3NjQ3OTksImlzcyI6IlNIQTI1NjpqZGNSeXNGdW5XVUFUODUyaHVRb0lNOUdONmsyczVjN2lUTVRNZ3VqUEFrIiwiZW5kcG9pbnQiOiJodHRwczovL2ZhYnJpYy53ZWJwYS5jb21jYXN0Lm5ldDo4MDgwLyJ9.ahYvcvZxKfKt-enfMZOT9JwCr7eGECv2fUYEDbVdm\"\n"
|
||||
"\"02:X1Jq1iPnD8MqkSOyHUQ8a17DOFQSmv8C3ZTKkjtFHEUR8l-KYhaA8bmU7Fzo8m0f4Ub411p4r4VE3KOdv8TWbKgKKIElONJmimpCDvHaUG6SZTaGB_proHyw5Vy5RzK4EAUc0C36hPBF6pIQfl5DgT1I66MHDcklMx2af2_F26Wv4rRX3pU_Q6fvustJhRTBcCJa7S6NZrm_Ca9rkRk5v2dyXkzrrB0_PCIoHITom8DPF8N56EDGzLyY25-\"\n"
|
||||
"\"03:iJmBr4pGROCCbRlbL3GpGDcSFJcaqBQFOriTRk0xKQ\"\n"
|
||||
"\"01:eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJTSEEyNTY6amRjUnlzRnVuV1VBVDg1Mmh1UW9JTTlHTjZrMnM1YzdpVE1UTWd1alBBayIsImVuZHBvaW50IjoiaHR0cHM6Ly9teWRucy5teWNvbS5uZXQ6ODA4MC8iLCJleHAiOjIxNDc0ODM2NDd9.VjG2PzPws2J707PiEaUGOTXD9NWnrGyfAUvvfyXFw-Px3gx5wg1\"\n"
|
||||
"\"02:EXGyJQXrxMYuepAiFPT0sWxvydHvZKxcx7S5MCmlOhRpWZRrzgFceNWMwFcRPAPxovOoc4aYvx2DqGMdckmAD1q3y3Gjjw1qyxd4503jmrXKfjrdW3eFZD_Q454iRVf4c0CMWA5tl0ElOlX9u_HC3G_dPiKGUBU5PpWONgHpg2-ewrQcUe4-J4hBQmqZmRSB9n-6zB1XD80cDQO7aHeJ9aysJS1vgmwaSuT9y6PhPsp05NUC0TDzZVJUX\"\n"
|
||||
;
|
||||
|
||||
const char *dns_recs_extra =
|
||||
"\"03:ji81f9B4vnaENEZJgPzYiYdVLvbkgg9rbI7RVcEjutIszb7XZA\"\n"
|
||||
"\"01:eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1MTQ3NjQ3OTksImlzcyI6IlNIQTI1NjpqZGNSeXNGdW5XVUFUODUyaHVRb0lNOUdONmsyczVjN2lUTVRNZ3VqUEFrIiwiZW5kcG9pbnQiOiJodHRwczovL2ZhYnJpYy53ZWJwYS5jb21jYXN0Lm5ldDo4MDgwLyJ9.ahYvcvZxKfKt-enfMZOT9JwCr7eGECv2fUYEDbVdm\"\n"
|
||||
"\"03:iJmBr4pGROCCbRlbL3GpGDcSFJcaqBQFOriTRk0xKQ\"\n"
|
||||
"\"01:eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJTSEEyNTY6amRjUnlzRnVuV1VBVDg1Mmh1UW9JTTlHTjZrMnM1YzdpVE1UTWd1alBBayIsImVuZHBvaW50IjoiaHR0cHM6Ly9teWRucy5teWNvbS5uZXQ6ODA4MC8iLCJleHAiOjIxNDc0ODM2NDd9.VjG2PzPws2J707PiEaUGOTXD9NWnrGyfAUvvfyXFw-Px3gx5wg1\"\n"
|
||||
"\n" // non-txt record type
|
||||
"\"02:X1Jq1iPnD8MqkSOyHUQ8a17DOFQSmv8C3ZTKkjtFHEUR8l-KYhaA8bmU7Fzo8m0f4Ub411p4r4VE3KOdv8TWbKgKKIElONJmimpCDvHaUG6SZTaGB_proHyw5Vy5RzK4EAUc0C36hPBF6pIQfl5DgT1I66MHDcklMx2af2_F26Wv4rRX3pU_Q6fvustJhRTBcCJa7S6NZrm_Ca9rkRk5v2dyXkzrrB0_PCIoHITom8DPF8N56EDGzLyY25-\"\n"
|
||||
"\"02:EXGyJQXrxMYuepAiFPT0sWxvydHvZKxcx7S5MCmlOhRpWZRrzgFceNWMwFcRPAPxovOoc4aYvx2DqGMdckmAD1q3y3Gjjw1qyxd4503jmrXKfjrdW3eFZD_Q454iRVf4c0CMWA5tl0ElOlX9u_HC3G_dPiKGUBU5PpWONgHpg2-ewrQcUe4-J4hBQmqZmRSB9n-6zB1XD80cDQO7aHeJ9aysJS1vgmwaSuT9y6PhPsp05NUC0TDzZVJUX\"\n"
|
||||
;
|
||||
|
||||
char *rr_recs_test[] = {
|
||||
"eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1MTQ3NjQ3OTksImlzcyI6IlNIQTI1NjpqZGNSeXNGdW5XVUFUODUyaHVRb0lNOUdONmsyczVjN2lUTVRNZ3VqUEFrIiwiZW5kcG9pbnQiOiJodHRwczovL2ZhYnJpYy53ZWJwYS5jb21jYXN0Lm5ldDo4MDgwLyJ9.ahYvcvZxKfKt-enfMZOT9JwCr7eGECv2fUYEDbVdm",
|
||||
"X1Jq1iPnD8MqkSOyHUQ8a17DOFQSmv8C3ZTKkjtFHEUR8l-KYhaA8bmU7Fzo8m0f4Ub411p4r4VE3KOdv8TWbKgKKIElONJmimpCDvHaUG6SZTaGB_proHyw5Vy5RzK4EAUc0C36hPBF6pIQfl5DgT1I66MHDcklMx2af2_F26Wv4rRX3pU_Q6fvustJhRTBcCJa7S6NZrm_Ca9rkRk5v2dyXkzrrB0_PCIoHITom8DPF8N56EDGzLyY25-",
|
||||
"ji81f9B4vnaENEZJgPzYiYdVLvbkgg9rbI7RVcEjutIszb7XZA"
|
||||
"eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJTSEEyNTY6amRjUnlzRnVuV1VBVDg1Mmh1UW9JTTlHTjZrMnM1YzdpVE1UTWd1alBBayIsImVuZHBvaW50IjoiaHR0cHM6Ly9teWRucy5teWNvbS5uZXQ6ODA4MC8iLCJleHAiOjIxNDc0ODM2NDd9.VjG2PzPws2J707PiEaUGOTXD9NWnrGyfAUvvfyXFw-Px3gx5wg1",
|
||||
"EXGyJQXrxMYuepAiFPT0sWxvydHvZKxcx7S5MCmlOhRpWZRrzgFceNWMwFcRPAPxovOoc4aYvx2DqGMdckmAD1q3y3Gjjw1qyxd4503jmrXKfjrdW3eFZD_Q454iRVf4c0CMWA5tl0ElOlX9u_HC3G_dPiKGUBU5PpWONgHpg2-ewrQcUe4-J4hBQmqZmRSB9n-6zB1XD80cDQO7aHeJ9aysJS1vgmwaSuT9y6PhPsp05NUC0TDzZVJUX",
|
||||
"iJmBr4pGROCCbRlbL3GpGDcSFJcaqBQFOriTRk0xKQ"
|
||||
};
|
||||
|
||||
char *dns_jwt_test =
|
||||
"eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1MTQ3NjQ3OTksImlzcyI6IlNIQTI1NjpqZGNSeXNGdW5XVUFUODUyaHVRb0lNOUdONmsyczVjN2lUTVRNZ3VqUEFrIiwiZW5kcG9pbnQiOiJodHRwczovL2ZhYnJpYy53ZWJwYS5jb21jYXN0Lm5ldDo4MDgwLyJ9.ahYvcvZxKfKt-enfMZOT9JwCr7eGECv2fUYEDbVdm"
|
||||
"X1Jq1iPnD8MqkSOyHUQ8a17DOFQSmv8C3ZTKkjtFHEUR8l-KYhaA8bmU7Fzo8m0f4Ub411p4r4VE3KOdv8TWbKgKKIElONJmimpCDvHaUG6SZTaGB_proHyw5Vy5RzK4EAUc0C36hPBF6pIQfl5DgT1I66MHDcklMx2af2_F26Wv4rRX3pU_Q6fvustJhRTBcCJa7S6NZrm_Ca9rkRk5v2dyXkzrrB0_PCIoHITom8DPF8N56EDGzLyY25-"
|
||||
"ji81f9B4vnaENEZJgPzYiYdVLvbkgg9rbI7RVcEjutIszb7XZA"
|
||||
"eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJTSEEyNTY6amRjUnlzRnVuV1VBVDg1Mmh1UW9JTTlHTjZrMnM1YzdpVE1UTWd1alBBayIsImVuZHBvaW50IjoiaHR0cHM6Ly9teWRucy5teWNvbS5uZXQ6ODA4MC8iLCJleHAiOjIxNDc0ODM2NDd9.VjG2PzPws2J707PiEaUGOTXD9NWnrGyfAUvvfyXFw-Px3gx5wg1"
|
||||
"EXGyJQXrxMYuepAiFPT0sWxvydHvZKxcx7S5MCmlOhRpWZRrzgFceNWMwFcRPAPxovOoc4aYvx2DqGMdckmAD1q3y3Gjjw1qyxd4503jmrXKfjrdW3eFZD_Q454iRVf4c0CMWA5tl0ElOlX9u_HC3G_dPiKGUBU5PpWONgHpg2-ewrQcUe4-J4hBQmqZmRSB9n-6zB1XD80cDQO7aHeJ9aysJS1vgmwaSuT9y6PhPsp05NUC0TDzZVJUX"
|
||||
"iJmBr4pGROCCbRlbL3GpGDcSFJcaqBQFOriTRk0xKQ"
|
||||
;
|
||||
|
||||
|
||||
const char *dns_recs_fabric =
|
||||
"\"eyJhbGciOiJub25lIiwidHlwIjoiSldUIn0.eyJlbmRwb2ludCI6Imh0dHBzOi8vZmFicmljLndlYnBhLmNvbWNhc3QubmV0OjgwODAvIn0.24cvUmCGYqqXuSsgC7nNnle2JH-uy6Jwp5BKXADhXpc\""
|
||||
/*
|
||||
expiration = 2147483647 #1/18/2038
|
||||
endpoint = "https://mydns.mycom.net:8080/"
|
||||
|
||||
dns_rec2_claims = {
|
||||
'endpoint': endpoint
|
||||
}
|
||||
*/
|
||||
// no exp in it
|
||||
const char *dns_recs2_test =
|
||||
"\"eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbmRwb2ludCI6Imh0dHBzOi8vbXlkbnMubXljb20ubmV0OjgwODAvIn0.YkudDhp7Ifr6wTsCfrYUUeRf1CMKannC6Bx994OrcBVwqNQ1G5uBXEgsslUnbqV_7FTGPp1Vs058qncmIXtEYxVlHt-mn1UEm6hyC_QGi9FfMHYBS7QHwcCIs467XUFMZayQ3upzZNXObhzJNF0-RR72S61cjSGqf1z5KgyBtoANtW6xCdWB5VV6CqCxlmJNj6d4N8vKiUvN346-UgB_H4AuaXCNdXJ2NP2DxRec-oNTCjhNzRn-6MaB-UwW_gD9CYfQ0vrw2Nv8dO1Sk5Ku94cdIfvUEft-kyqPGKmK8soIggjvmvW0JEPYwrWYY9Ry5SQf80-dLOPXCQSQ3Rzy7Q\""
|
||||
;
|
||||
|
||||
char *rr_recs_fabric[] = {
|
||||
"eyJhbGciOiJub25lIiwidHlwIjoiSldUIn0.eyJlbmRwb2ludCI6Imh0dHBzOi8vZmFicmljLndlYnBhLmNvbWNhc3QubmV0OjgwODAvIn0.24cvUmCGYqqXuSsgC7nNnle2JH-uy6Jwp5BKXADhXpc"
|
||||
// no exp in it
|
||||
char *rr_recs2_test[] = {
|
||||
"eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbmRwb2ludCI6Imh0dHBzOi8vbXlkbnMubXljb20ubmV0OjgwODAvIn0.YkudDhp7Ifr6wTsCfrYUUeRf1CMKannC6Bx994OrcBVwqNQ1G5uBXEgsslUnbqV_7FTGPp1Vs058qncmIXtEYxVlHt-mn1UEm6hyC_QGi9FfMHYBS7QHwcCIs467XUFMZayQ3upzZNXObhzJNF0-RR72S61cjSGqf1z5KgyBtoANtW6xCdWB5VV6CqCxlmJNj6d4N8vKiUvN346-UgB_H4AuaXCNdXJ2NP2DxRec-oNTCjhNzRn-6MaB-UwW_gD9CYfQ0vrw2Nv8dO1Sk5Ku94cdIfvUEft-kyqPGKmK8soIggjvmvW0JEPYwrWYY9Ry5SQf80-dLOPXCQSQ3Rzy7Q"
|
||||
};
|
||||
|
||||
const char *dns_recs_err1 = // missing seq
|
||||
"\"03:ji81f9B4vnaENEZJgPzYiYdVLvbkgg9rbI7RVcEjutIszb7XZA\"\n"
|
||||
"\"eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1MTQ3NjQ3OTksImlzcyI6IlNIQTI1NjpqZGNSeXNGdW5XVUFUODUyaHVRb0lNOUdONmsyczVjN2lUTVRNZ3VqUEFrIiwiZW5kcG9pbnQiOiJodHRwczovL2ZhYnJpYy53ZWJwYS5jb21jYXN0Lm5ldDo4MDgwLyJ9.ahYvcvZxKfKt-enfMZOT9JwCr7eGECv2fUYEDbVdm\"\n"
|
||||
"\"02:X1Jq1iPnD8MqkSOyHUQ8a17DOFQSmv8C3ZTKkjtFHEUR8l-KYhaA8bmU7Fzo8m0f4Ub411p4r4VE3KOdv8TWbKgKKIElONJmimpCDvHaUG6SZTaGB_proHyw5Vy5RzK4EAUc0C36hPBF6pIQfl5DgT1I66MHDcklMx2af2_F26Wv4rRX3pU_Q6fvustJhRTBcCJa7S6NZrm_Ca9rkRk5v2dyXkzrrB0_PCIoHITom8DPF8N56EDGzLyY25-\"\n"
|
||||
"\"03:iJmBr4pGROCCbRlbL3GpGDcSFJcaqBQFOriTRk0xKQ\"\n"
|
||||
"\"eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJTSEEyNTY6amRjUnlzRnVuV1VBVDg1Mmh1UW9JTTlHTjZrMnM1YzdpVE1UTWd1alBBayIsImVuZHBvaW50IjoiaHR0cHM6Ly9teWRucy5teWNvbS5uZXQ6ODA4MC8iLCJleHAiOjIxNDc0ODM2NDd9.VjG2PzPws2J707PiEaUGOTXD9NWnrGyfAUvvfyXFw-Px3gx5wg1\"\n"
|
||||
"\"02:EXGyJQXrxMYuepAiFPT0sWxvydHvZKxcx7S5MCmlOhRpWZRrzgFceNWMwFcRPAPxovOoc4aYvx2DqGMdckmAD1q3y3Gjjw1qyxd4503jmrXKfjrdW3eFZD_Q454iRVf4c0CMWA5tl0ElOlX9u_HC3G_dPiKGUBU5PpWONgHpg2-ewrQcUe4-J4hBQmqZmRSB9n-6zB1XD80cDQO7aHeJ9aysJS1vgmwaSuT9y6PhPsp05NUC0TDzZVJUX\"\n"
|
||||
;
|
||||
|
||||
const char *dns_recs_err2 = // invalid seq
|
||||
"\"03:ji81f9B4vnaENEZJgPzYiYdVLvbkgg9rbI7RVcEjutIszb7XZA\"\n"
|
||||
"\"0:eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1MTQ3NjQ3OTksImlzcyI6IlNIQTI1NjpqZGNSeXNGdW5XVUFUODUyaHVRb0lNOUdONmsyczVjN2lUTVRNZ3VqUEFrIiwiZW5kcG9pbnQiOiJodHRwczovL2ZhYnJpYy53ZWJwYS5jb21jYXN0Lm5ldDo4MDgwLyJ9.ahYvcvZxKfKt-enfMZOT9JwCr7eGECv2fUYEDbVdm\"\n"
|
||||
"\"02:X1Jq1iPnD8MqkSOyHUQ8a17DOFQSmv8C3ZTKkjtFHEUR8l-KYhaA8bmU7Fzo8m0f4Ub411p4r4VE3KOdv8TWbKgKKIElONJmimpCDvHaUG6SZTaGB_proHyw5Vy5RzK4EAUc0C36hPBF6pIQfl5DgT1I66MHDcklMx2af2_F26Wv4rRX3pU_Q6fvustJhRTBcCJa7S6NZrm_Ca9rkRk5v2dyXkzrrB0_PCIoHITom8DPF8N56EDGzLyY25-\"\n"
|
||||
"\"03:iJmBr4pGROCCbRlbL3GpGDcSFJcaqBQFOriTRk0xKQ\"\n"
|
||||
"\"0:eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJTSEEyNTY6amRjUnlzRnVuV1VBVDg1Mmh1UW9JTTlHTjZrMnM1YzdpVE1UTWd1alBBayIsImVuZHBvaW50IjoiaHR0cHM6Ly9teWRucy5teWNvbS5uZXQ6ODA4MC8iLCJleHAiOjIxNDc0ODM2NDd9.VjG2PzPws2J707PiEaUGOTXD9NWnrGyfAUvvfyXFw-Px3gx5wg1\"\n"
|
||||
"\"02:EXGyJQXrxMYuepAiFPT0sWxvydHvZKxcx7S5MCmlOhRpWZRrzgFceNWMwFcRPAPxovOoc4aYvx2DqGMdckmAD1q3y3Gjjw1qyxd4503jmrXKfjrdW3eFZD_Q454iRVf4c0CMWA5tl0ElOlX9u_HC3G_dPiKGUBU5PpWONgHpg2-ewrQcUe4-J4hBQmqZmRSB9n-6zB1XD80cDQO7aHeJ9aysJS1vgmwaSuT9y6PhPsp05NUC0TDzZVJUX\"\n"
|
||||
;
|
||||
|
||||
const char *dns_recs_err3 = // invalid seq too high
|
||||
"\"03:ji81f9B4vnaENEZJgPzYiYdVLvbkgg9rbI7RVcEjutIszb7XZA\"\n"
|
||||
"\"99:eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1MTQ3NjQ3OTksImlzcyI6IlNIQTI1NjpqZGNSeXNGdW5XVUFUODUyaHVRb0lNOUdONmsyczVjN2lUTVRNZ3VqUEFrIiwiZW5kcG9pbnQiOiJodHRwczovL2ZhYnJpYy53ZWJwYS5jb21jYXN0Lm5ldDo4MDgwLyJ9.ahYvcvZxKfKt-enfMZOT9JwCr7eGECv2fUYEDbVdm\"\n"
|
||||
"\"02:X1Jq1iPnD8MqkSOyHUQ8a17DOFQSmv8C3ZTKkjtFHEUR8l-KYhaA8bmU7Fzo8m0f4Ub411p4r4VE3KOdv8TWbKgKKIElONJmimpCDvHaUG6SZTaGB_proHyw5Vy5RzK4EAUc0C36hPBF6pIQfl5DgT1I66MHDcklMx2af2_F26Wv4rRX3pU_Q6fvustJhRTBcCJa7S6NZrm_Ca9rkRk5v2dyXkzrrB0_PCIoHITom8DPF8N56EDGzLyY25-\"\n"
|
||||
"\"03:iJmBr4pGROCCbRlbL3GpGDcSFJcaqBQFOriTRk0xKQ\"\n"
|
||||
"\"99:eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJTSEEyNTY6amRjUnlzRnVuV1VBVDg1Mmh1UW9JTTlHTjZrMnM1YzdpVE1UTWd1alBBayIsImVuZHBvaW50IjoiaHR0cHM6Ly9teWRucy5teWNvbS5uZXQ6ODA4MC8iLCJleHAiOjIxNDc0ODM2NDd9.VjG2PzPws2J707PiEaUGOTXD9NWnrGyfAUvvfyXFw-Px3gx5wg1\"\n"
|
||||
"\"02:EXGyJQXrxMYuepAiFPT0sWxvydHvZKxcx7S5MCmlOhRpWZRrzgFceNWMwFcRPAPxovOoc4aYvx2DqGMdckmAD1q3y3Gjjw1qyxd4503jmrXKfjrdW3eFZD_Q454iRVf4c0CMWA5tl0ElOlX9u_HC3G_dPiKGUBU5PpWONgHpg2-ewrQcUe4-J4hBQmqZmRSB9n-6zB1XD80cDQO7aHeJ9aysJS1vgmwaSuT9y6PhPsp05NUC0TDzZVJUX\"\n"
|
||||
;
|
||||
|
||||
const char *dns_recs_err4 = // duplicate seq number
|
||||
"\"03:ji81f9B4vnaENEZJgPzYiYdVLvbkgg9rbI7RVcEjutIszb7XZA\"\n"
|
||||
"\"03:ji81f9B4vnaENEZJgPzYiYdVLvbkgg9rbI7RVcEjutIszb7XZA\"\n"
|
||||
"\"01:eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1MTQ3NjQ3OTksImlzcyI6IlNIQTI1NjpqZGNSeXNGdW5XVUFUODUyaHVRb0lNOUdONmsyczVjN2lUTVRNZ3VqUEFrIiwiZW5kcG9pbnQiOiJodHRwczovL2ZhYnJpYy53ZWJwYS5jb21jYXN0Lm5ldDo4MDgwLyJ9.ahYvcvZxKfKt-enfMZOT9JwCr7eGECv2fUYEDbVdm\"\n"
|
||||
"\"02:X1Jq1iPnD8MqkSOyHUQ8a17DOFQSmv8C3ZTKkjtFHEUR8l-KYhaA8bmU7Fzo8m0f4Ub411p4r4VE3KOdv8TWbKgKKIElONJmimpCDvHaUG6SZTaGB_proHyw5Vy5RzK4EAUc0C36hPBF6pIQfl5DgT1I66MHDcklMx2af2_F26Wv4rRX3pU_Q6fvustJhRTBcCJa7S6NZrm_Ca9rkRk5v2dyXkzrrB0_PCIoHITom8DPF8N56EDGzLyY25-\"\n"
|
||||
"\"03:iJmBr4pGROCCbRlbL3GpGDcSFJcaqBQFOriTRk0xKQ\"\n"
|
||||
"\"03:iJmBr4pGROCCbRlbL3GpGDcSFJcaqBQFOriTRk0xKQ\"\n"
|
||||
"\"01:eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJTSEEyNTY6amRjUnlzRnVuV1VBVDg1Mmh1UW9JTTlHTjZrMnM1YzdpVE1UTWd1alBBayIsImVuZHBvaW50IjoiaHR0cHM6Ly9teWRucy5teWNvbS5uZXQ6ODA4MC8iLCJleHAiOjIxNDc0ODM2NDd9.VjG2PzPws2J707PiEaUGOTXD9NWnrGyfAUvvfyXFw-Px3gx5wg1\"\n"
|
||||
"\"02:EXGyJQXrxMYuepAiFPT0sWxvydHvZKxcx7S5MCmlOhRpWZRrzgFceNWMwFcRPAPxovOoc4aYvx2DqGMdckmAD1q3y3Gjjw1qyxd4503jmrXKfjrdW3eFZD_Q454iRVf4c0CMWA5tl0ElOlX9u_HC3G_dPiKGUBU5PpWONgHpg2-ewrQcUe4-J4hBQmqZmRSB9n-6zB1XD80cDQO7aHeJ9aysJS1vgmwaSuT9y6PhPsp05NUC0TDzZVJUX\"\n"
|
||||
;
|
||||
|
||||
const char *dns_recs_err5 = // missing rec 1
|
||||
"\"03:ji81f9B4vnaENEZJgPzYiYdVLvbkgg9rbI7RVcEjutIszb7XZA\"\n"
|
||||
"\"03:iJmBr4pGROCCbRlbL3GpGDcSFJcaqBQFOriTRk0xKQ\"\n"
|
||||
"\n" // non-txt record type
|
||||
"\"02:X1Jq1iPnD8MqkSOyHUQ8a17DOFQSmv8C3ZTKkjtFHEUR8l-KYhaA8bmU7Fzo8m0f4Ub411p4r4VE3KOdv8TWbKgKKIElONJmimpCDvHaUG6SZTaGB_proHyw5Vy5RzK4EAUc0C36hPBF6pIQfl5DgT1I66MHDcklMx2af2_F26Wv4rRX3pU_Q6fvustJhRTBcCJa7S6NZrm_Ca9rkRk5v2dyXkzrrB0_PCIoHITom8DPF8N56EDGzLyY25-\"\n"
|
||||
"\"02:EXGyJQXrxMYuepAiFPT0sWxvydHvZKxcx7S5MCmlOhRpWZRrzgFceNWMwFcRPAPxovOoc4aYvx2DqGMdckmAD1q3y3Gjjw1qyxd4503jmrXKfjrdW3eFZD_Q454iRVf4c0CMWA5tl0ElOlX9u_HC3G_dPiKGUBU5PpWONgHpg2-ewrQcUe4-J4hBQmqZmRSB9n-6zB1XD80cDQO7aHeJ9aysJS1vgmwaSuT9y6PhPsp05NUC0TDzZVJUX\"\n"
|
||||
;
|
||||
|
||||
cjwt_t jwt1; // secure, payload good
|
||||
@@ -123,7 +144,8 @@ cjwt_t jwt3; // insecure
|
||||
cjwt_t jwt4; // missing endpoint
|
||||
|
||||
// internal functions in token.c to be tested
|
||||
extern int analyze_jwt (const cjwt_t *jwt);
|
||||
extern int analyze_jwt (const cjwt_t *jwt, char *url_buf, int url_buflen,
|
||||
char *port_buf, int port_buflen);
|
||||
extern bool validate_algo(const cjwt_t *jwt);
|
||||
extern int nquery(const char* dns_txt_record_id,u_char *nsbuf);
|
||||
extern bool valid_b64_char (char c);
|
||||
@@ -137,6 +159,17 @@ extern void read_key_from_file (const char *fname, char *buf, size_t buflen);
|
||||
extern const char *get_tok (const char *src, int delim, char *result, int resultsize);
|
||||
extern unsigned int get_algo_mask (const char *algo_str);
|
||||
|
||||
void addCRUDmsgToQueue(wrp_msg_t *crudMsg)
|
||||
{
|
||||
(void)crudMsg;
|
||||
return;
|
||||
}
|
||||
|
||||
void *CRUDHandlerTask()
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int setup_test_jwts (void)
|
||||
{
|
||||
memset (&jwt1, 0, sizeof(cjwt_t));
|
||||
@@ -182,8 +215,8 @@ static int get_dns_text (const char *dns_rec_id, u_char *nsbuf, int bufsize)
|
||||
rec = dns_recs_test;
|
||||
else if (strstr (dns_rec_id, ".extra.") != NULL)
|
||||
rec = dns_recs_extra;
|
||||
else if (strstr (dns_rec_id, ".fabric.") != NULL)
|
||||
rec = dns_recs_fabric;
|
||||
else if (strstr (dns_rec_id, ".test2.") != NULL)
|
||||
rec = dns_recs2_test;
|
||||
else if (strstr (dns_rec_id, ".err1.") != NULL)
|
||||
rec = dns_recs_err1;
|
||||
else if (strstr (dns_rec_id, ".err2.") != NULL)
|
||||
@@ -204,6 +237,9 @@ static int get_dns_text (const char *dns_rec_id, u_char *nsbuf, int bufsize)
|
||||
/* Mocks */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
// These mocks assume that the pieces of a dns txt record end with '\n';
|
||||
|
||||
|
||||
int ns_initparse(const u_char *nsbuf, int l, ns_msg *msg_handle)
|
||||
{
|
||||
UNUSED(l);
|
||||
@@ -248,12 +284,14 @@ int ns_parserr(ns_msg *msg_handle, ns_sect sect, int rec, ns_rr *rr)
|
||||
ptr += (l+1);
|
||||
}
|
||||
|
||||
if (strlen (ptr) == 0) {
|
||||
l = strlen(ptr);
|
||||
if (l == 0) {
|
||||
rr->type = ns_t_key;
|
||||
} else {
|
||||
rr->type = ns_t_txt;
|
||||
}
|
||||
rr->rdata = (u_char *) ptr;
|
||||
rr->rdlength = l;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -282,26 +320,34 @@ void __res_nclose (res_state statp)
|
||||
function_called ();
|
||||
}
|
||||
|
||||
// Analyzes a jwt structure
|
||||
void test_analyze_jwt ()
|
||||
{
|
||||
char port[8];
|
||||
char server_Address[256];
|
||||
int ret = setup_test_jwts ();
|
||||
assert_int_equal (ret, 0);
|
||||
ret = analyze_jwt (&jwt1);
|
||||
ret = analyze_jwt (&jwt1, server_Address, (int) sizeof(server_Address),
|
||||
port, (int) sizeof(port));
|
||||
assert_int_equal (ret, 0);
|
||||
ret = analyze_jwt (&jwt2);
|
||||
assert_string_equal (server_Address, "mydns.mycom.net");
|
||||
assert_string_equal (port, "8080");
|
||||
ret = analyze_jwt (&jwt2, server_Address, (int) sizeof(server_Address),
|
||||
port, (int) sizeof(port));
|
||||
assert_int_equal (ret, TOKEN_ERR_JWT_EXPIRED);
|
||||
ret = analyze_jwt (&jwt3);
|
||||
ret = analyze_jwt (&jwt3, server_Address, (int) sizeof(server_Address),
|
||||
port, (int) sizeof(port));
|
||||
assert_int_equal (ret, 1);
|
||||
ret = analyze_jwt (&jwt4);
|
||||
ret = analyze_jwt (&jwt4, server_Address, (int) sizeof(server_Address),
|
||||
port, (int) sizeof(port));
|
||||
assert_int_equal (ret, TOKEN_ERR_INVALID_JWT_CONTENT);
|
||||
|
||||
}
|
||||
|
||||
void test_validate_algo ()
|
||||
{
|
||||
bool ret;
|
||||
ParodusCfg cfg;
|
||||
parStrncpy (cfg.jwt_algo, "none:RS256", sizeof(cfg.jwt_algo));
|
||||
cfg.jwt_algo = 1025;
|
||||
set_parodus_cfg (&cfg);
|
||||
jwt1.header.alg = alg_rs256;
|
||||
ret = validate_algo (&jwt1);
|
||||
@@ -353,12 +399,14 @@ void test_strip_rrdata ()
|
||||
const char *result;
|
||||
int rlen;
|
||||
|
||||
rlen = strlen (s1);
|
||||
result = strip_rr_data (s1, &rlen);
|
||||
assert_int_equal (rlen, s1len);
|
||||
if (rlen == s1len) {
|
||||
assert_int_equal (strncmp (result, ss1, rlen), 0);
|
||||
}
|
||||
|
||||
rlen = strlen (s2);
|
||||
result = strip_rr_data (s2, &rlen);
|
||||
assert_int_equal (rlen, s1len);
|
||||
if (rlen == s1len) {
|
||||
@@ -444,7 +492,7 @@ void test_get_rr_seq_table()
|
||||
assert_int_equal (ret, 0);
|
||||
}
|
||||
|
||||
ret = get_dns_text (".fabric.", nsbuf, 4096);
|
||||
ret = get_dns_text (".test2.", nsbuf, 4096);
|
||||
assert_int_equal (ret, 0);
|
||||
ns_initparse (nsbuf, 4096, &msg_handle);
|
||||
assert_int_equal (msg_handle._counts[ns_s_an], 1);
|
||||
@@ -452,9 +500,9 @@ void test_get_rr_seq_table()
|
||||
assert_int_equal (num_txt_recs, 1);
|
||||
assert_ptr_not_equal (seq_table[0].rr_ptr, NULL);
|
||||
if (NULL != seq_table[0].rr_ptr) {
|
||||
int len = strlen (rr_recs_fabric[0]);
|
||||
int len = strlen (rr_recs2_test[0]);
|
||||
assert_int_equal (len, seq_table[0].rr_len);
|
||||
ret = strncmp (seq_table[0].rr_ptr, rr_recs_fabric[0], len);
|
||||
ret = strncmp (seq_table[0].rr_ptr, rr_recs2_test[0], len);
|
||||
assert_int_equal (ret, 0);
|
||||
}
|
||||
|
||||
@@ -566,53 +614,58 @@ void test_query_dns ()
|
||||
void test_allow_insecure_conn ()
|
||||
{
|
||||
int insecure;
|
||||
char port_buf[6] = "8080";
|
||||
ParodusCfg *cfg = get_parodus_cfg();
|
||||
|
||||
parStrncpy (cfg->hw_mac, "aabbccddeeff", sizeof(cfg->hw_mac));
|
||||
parStrncpy (cfg->dns_txt_url, "test", sizeof(cfg->dns_txt_url));
|
||||
parStrncpy (cfg->jwt_algo, "none:RS256", sizeof(cfg->jwt_algo));
|
||||
parStrncpy (cfg->dns_txt_url, "test.mydns.mycom.net", sizeof(cfg->dns_txt_url));
|
||||
cfg->jwt_algo = 1025;
|
||||
|
||||
read_key_from_file ("../../tests/webpa-rs256.pem", cfg->jwt_key, 4096);
|
||||
read_key_from_file ("../../tests/pubkey4.pem", cfg->jwt_key, 4096);
|
||||
|
||||
will_return (__res_ninit, 0);
|
||||
expect_function_call (__res_ninit);
|
||||
expect_function_call (__res_nclose);
|
||||
|
||||
insecure = allow_insecure_conn ();
|
||||
insecure = allow_insecure_conn (cfg->dns_txt_url, sizeof(cfg->dns_txt_url),
|
||||
port_buf, sizeof(port_buf));
|
||||
assert_int_equal (insecure, 0);
|
||||
|
||||
parStrncpy (cfg->hw_mac, "aabbccddeeff", sizeof(cfg->hw_mac));
|
||||
parStrncpy (cfg->dns_txt_url, "err5", sizeof(cfg->dns_txt_url));
|
||||
parStrncpy (cfg->dns_txt_url, "err5.mydns.mycom.net", sizeof(cfg->dns_txt_url));
|
||||
|
||||
will_return (__res_ninit, 0);
|
||||
expect_function_call (__res_ninit);
|
||||
expect_function_call (__res_nclose);
|
||||
|
||||
insecure = allow_insecure_conn ();
|
||||
insecure = allow_insecure_conn (cfg->dns_txt_url, sizeof(cfg->dns_txt_url),
|
||||
port_buf, sizeof(port_buf));
|
||||
assert_int_equal (insecure, TOKEN_ERR_QUERY_DNS_FAIL);
|
||||
|
||||
parStrncpy (cfg->hw_mac, "aabbccddeeff", sizeof(cfg->hw_mac));
|
||||
parStrncpy (cfg->dns_txt_url, "test", sizeof(cfg->dns_txt_url));
|
||||
parStrncpy (cfg->jwt_algo, "none:RS256", sizeof(cfg->jwt_algo));
|
||||
parStrncpy (cfg->dns_txt_url, "test.mydns.mycom.net", sizeof(cfg->dns_txt_url));
|
||||
cfg->jwt_algo = 1024;
|
||||
parStrncpy (cfg->jwt_key, "xxxxxxxxxx", sizeof(cfg->jwt_key));
|
||||
|
||||
will_return (__res_ninit, 0);
|
||||
expect_function_call (__res_ninit);
|
||||
expect_function_call (__res_nclose);
|
||||
|
||||
insecure = allow_insecure_conn ();
|
||||
insecure = allow_insecure_conn (cfg->dns_txt_url, sizeof(cfg->dns_txt_url),
|
||||
port_buf, sizeof(port_buf));
|
||||
assert_int_equal (insecure, TOKEN_ERR_JWT_DECODE_FAIL);
|
||||
|
||||
parStrncpy (cfg->hw_mac, "aabbccddeeff", sizeof(cfg->hw_mac));
|
||||
parStrncpy (cfg->dns_txt_url, "test", sizeof(cfg->dns_txt_url));
|
||||
parStrncpy (cfg->jwt_algo, "none:RS512", sizeof(cfg->jwt_algo));
|
||||
read_key_from_file ("../../tests/webpa-rs256.pem", cfg->jwt_key, 4096);
|
||||
parStrncpy (cfg->dns_txt_url, "test.mydns.mycom.net", sizeof(cfg->dns_txt_url));
|
||||
cfg->jwt_algo = 4097;
|
||||
read_key_from_file ("../../tests/pubkey4.pem", cfg->jwt_key, 4096);
|
||||
|
||||
will_return (__res_ninit, 0);
|
||||
expect_function_call (__res_ninit);
|
||||
expect_function_call (__res_nclose);
|
||||
|
||||
insecure = allow_insecure_conn ();
|
||||
insecure = allow_insecure_conn (cfg->dns_txt_url, sizeof(cfg->dns_txt_url),
|
||||
port_buf, sizeof(port_buf));
|
||||
assert_int_equal (insecure, TOKEN_ERR_ALGO_NOT_ALLOWED);
|
||||
|
||||
}
|
||||
@@ -644,11 +697,11 @@ void test_get_algo_mask ()
|
||||
{
|
||||
unsigned mask;
|
||||
|
||||
mask = get_algo_mask ("none");
|
||||
assert_int_equal ((int) mask, 1);
|
||||
mask = get_algo_mask ("rs256");
|
||||
assert_int_equal ((int) mask, 1024);
|
||||
|
||||
mask = get_algo_mask ("none:rs256");
|
||||
assert_int_equal ((int) mask, 1025);
|
||||
mask = get_algo_mask ("rs512:rs256");
|
||||
assert_int_equal ((int) mask, 5120);
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
@@ -668,7 +721,7 @@ int main(void)
|
||||
cmocka_unit_test(test_get_rr_seq_table),
|
||||
cmocka_unit_test(test_assemble_jwt_from_dns),
|
||||
cmocka_unit_test(test_query_dns),
|
||||
//cmocka_unit_test(test_allow_insecure_conn),
|
||||
cmocka_unit_test(test_allow_insecure_conn),
|
||||
cmocka_unit_test(test_get_tok),
|
||||
cmocka_unit_test(test_get_algo_mask),
|
||||
};
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#include <setjmp.h>
|
||||
#include <cmocka.h>
|
||||
#include <assert.h>
|
||||
#include <wrp-c.h>
|
||||
|
||||
#include "../src/token.h"
|
||||
|
||||
@@ -30,11 +31,25 @@
|
||||
/* Mocks */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
void addCRUDmsgToQueue(wrp_msg_t *crudMsg)
|
||||
{
|
||||
(void)crudMsg;
|
||||
return;
|
||||
}
|
||||
|
||||
void *CRUDHandlerTask()
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void test_allow_insecure_conn ()
|
||||
{
|
||||
int insecure;
|
||||
insecure = allow_insecure_conn ();
|
||||
assert_int_equal (insecure, 1);
|
||||
char *server_Address = NULL;
|
||||
char *port = NULL;
|
||||
insecure = allow_insecure_conn (server_Address,(int) sizeof(server_Address),
|
||||
port, (int) sizeof(port));
|
||||
assert_int_equal (insecure, -1);
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
@@ -42,6 +42,9 @@ extern size_t metaPackSize;
|
||||
extern UpStreamMsg *UpStreamMsgQ;
|
||||
int numLoops = 1;
|
||||
wrp_msg_t *temp = NULL;
|
||||
extern pthread_mutex_t nano_mut;
|
||||
extern pthread_cond_t nano_con;
|
||||
static int crud_test = 0;
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Mocks */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
@@ -141,7 +144,19 @@ ssize_t wrp_to_struct( const void *bytes, const size_t length, const enum wrp_fo
|
||||
{
|
||||
UNUSED(bytes); UNUSED(length); UNUSED(fmt);
|
||||
function_called();
|
||||
*msg = temp;
|
||||
if(crud_test)
|
||||
{
|
||||
wrp_msg_t *resp_msg = NULL;
|
||||
resp_msg = ( wrp_msg_t *)malloc( sizeof( wrp_msg_t ) );
|
||||
memset(resp_msg, 0, sizeof(wrp_msg_t));
|
||||
resp_msg->msg_type = 5;
|
||||
resp_msg->u.crud.source = strdup("mac:14xxx/tags");
|
||||
*msg = resp_msg;
|
||||
}
|
||||
else
|
||||
{
|
||||
*msg = temp;
|
||||
}
|
||||
return (ssize_t)mock();
|
||||
}
|
||||
|
||||
@@ -280,10 +295,9 @@ void test_processUpstreamMessage()
|
||||
expect_function_call(appendEncodedData);
|
||||
|
||||
expect_function_call(sendMessage);
|
||||
|
||||
expect_function_call(wrp_free_struct);
|
||||
will_return(nn_freemsg,1);
|
||||
will_return(nn_freemsg, 0);
|
||||
expect_function_call(nn_freemsg);
|
||||
expect_function_call(wrp_free_struct);
|
||||
|
||||
processUpstreamMessage();
|
||||
free(temp);
|
||||
@@ -317,10 +331,9 @@ void test_processUpstreamMessageInvalidPartner()
|
||||
expect_function_call(appendEncodedData);
|
||||
|
||||
expect_function_call(sendMessage);
|
||||
|
||||
expect_function_call(wrp_free_struct);
|
||||
will_return(nn_freemsg,1);
|
||||
will_return(nn_freemsg, 0);
|
||||
expect_function_call(nn_freemsg);
|
||||
expect_function_call(wrp_free_struct);
|
||||
processUpstreamMessage();
|
||||
free(temp);
|
||||
free(UpStreamMsgQ->next);
|
||||
@@ -375,10 +388,9 @@ void test_processUpstreamMessageRegMsg()
|
||||
|
||||
will_return(get_numOfClients, 1);
|
||||
expect_function_call(get_numOfClients);
|
||||
|
||||
expect_function_call(wrp_free_struct);
|
||||
will_return(nn_freemsg,1);
|
||||
will_return(nn_freemsg, 0);
|
||||
expect_function_call(nn_freemsg);
|
||||
expect_function_call(wrp_free_struct);
|
||||
|
||||
processUpstreamMessage();
|
||||
free(temp);
|
||||
@@ -417,10 +429,9 @@ void test_processUpstreamMessageRegMsgNoClients()
|
||||
|
||||
will_return(addToList, 0);
|
||||
expect_function_call(addToList);
|
||||
|
||||
expect_function_call(wrp_free_struct);
|
||||
will_return(nn_freemsg,1);
|
||||
will_return(nn_freemsg, 0);
|
||||
expect_function_call(nn_freemsg);
|
||||
expect_function_call(wrp_free_struct);
|
||||
|
||||
processUpstreamMessage();
|
||||
free(temp);
|
||||
@@ -449,12 +460,11 @@ void err_processUpstreamMessageDecodeErr()
|
||||
temp = (wrp_msg_t *) malloc(sizeof(wrp_msg_t));
|
||||
memset(temp,0,sizeof(wrp_msg_t));
|
||||
temp->msg_type = 3;
|
||||
|
||||
will_return(wrp_to_struct, -1);
|
||||
expect_function_call(wrp_to_struct);
|
||||
expect_function_call(wrp_free_struct);
|
||||
will_return(nn_freemsg,1);
|
||||
will_return(nn_freemsg, 0);
|
||||
expect_function_call(nn_freemsg);
|
||||
expect_function_call(wrp_free_struct);
|
||||
processUpstreamMessage();
|
||||
free(temp);
|
||||
free(UpStreamMsgQ);
|
||||
@@ -475,10 +485,9 @@ void err_processUpstreamMessageMetapackFailure()
|
||||
|
||||
will_return(wrp_to_struct, 15);
|
||||
expect_function_call(wrp_to_struct);
|
||||
|
||||
will_return(nn_freemsg, 0);
|
||||
expect_function_call(nn_freemsg);
|
||||
expect_function_call(wrp_free_struct);
|
||||
will_return(nn_freemsg,1);
|
||||
expect_function_call(nn_freemsg);
|
||||
processUpstreamMessage();
|
||||
free(temp);
|
||||
free(UpStreamMsgQ);
|
||||
@@ -538,10 +547,9 @@ void err_processUpstreamMessageRegMsg()
|
||||
|
||||
will_return(addToList, -1);
|
||||
expect_function_call(addToList);
|
||||
|
||||
will_return(nn_freemsg, 0);
|
||||
expect_function_call(nn_freemsg);
|
||||
expect_function_call(wrp_free_struct);
|
||||
will_return(nn_freemsg,1);
|
||||
expect_function_call(nn_freemsg);
|
||||
|
||||
processUpstreamMessage();
|
||||
free(temp);
|
||||
@@ -574,6 +582,56 @@ void err_sendUpstreamMsgToServer()
|
||||
sendUpstreamMsgToServer(NULL, 110);
|
||||
}
|
||||
|
||||
void test_get_global_UpStreamMsgQ()
|
||||
{
|
||||
assert_ptr_equal(UpStreamMsgQ, get_global_UpStreamMsgQ());
|
||||
}
|
||||
|
||||
void test_set_global_UpStreamMsgQ()
|
||||
{
|
||||
static UpStreamMsg *UpStreamQ;
|
||||
UpStreamQ = (UpStreamMsg *) malloc(sizeof(UpStreamMsg));
|
||||
UpStreamQ->msg = "First Message";
|
||||
UpStreamQ->len = 13;
|
||||
UpStreamQ->next = NULL;
|
||||
set_global_UpStreamMsgQ(UpStreamQ);
|
||||
assert_string_equal(UpStreamQ->msg, (char *)get_global_UpStreamMsgQ()->msg);
|
||||
assert_int_equal(UpStreamQ->len, get_global_UpStreamMsgQ()->len);
|
||||
free(UpStreamQ->next);
|
||||
free(UpStreamQ);
|
||||
}
|
||||
|
||||
void test_get_global_nano_con()
|
||||
{
|
||||
assert_ptr_equal(&nano_con, get_global_nano_con());
|
||||
}
|
||||
|
||||
void test_get_global_nano_mut()
|
||||
{
|
||||
assert_ptr_equal(&nano_mut, get_global_nano_mut());
|
||||
}
|
||||
|
||||
void test_processUpstreamMsgCrud_nnfree()
|
||||
{
|
||||
numLoops = 1;
|
||||
crud_test = 1;
|
||||
metaPackSize = 0;
|
||||
UpStreamMsgQ = (UpStreamMsg *) malloc(sizeof(UpStreamMsg));
|
||||
UpStreamMsgQ->msg = "First Message";
|
||||
UpStreamMsgQ->len = 13;
|
||||
UpStreamMsgQ->next = NULL;
|
||||
|
||||
will_return(wrp_to_struct, 12);
|
||||
expect_function_call(wrp_to_struct);
|
||||
will_return(nn_freemsg, 0);
|
||||
expect_function_call(nn_freemsg);
|
||||
expect_function_call(wrp_free_struct);
|
||||
processUpstreamMessage();
|
||||
free(UpStreamMsgQ);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* External Functions */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
@@ -597,6 +655,11 @@ int main(void)
|
||||
cmocka_unit_test(err_processUpstreamMessageRegMsg),
|
||||
cmocka_unit_test(test_sendUpstreamMsgToServer),
|
||||
cmocka_unit_test(err_sendUpstreamMsgToServer),
|
||||
cmocka_unit_test(test_get_global_UpStreamMsgQ),
|
||||
cmocka_unit_test(test_set_global_UpStreamMsgQ),
|
||||
cmocka_unit_test(test_get_global_nano_con),
|
||||
cmocka_unit_test(test_get_global_nano_mut),
|
||||
cmocka_unit_test(test_processUpstreamMsgCrud_nnfree),
|
||||
};
|
||||
|
||||
return cmocka_run_group_tests(tests, NULL, NULL);
|
||||
|
||||
Reference in New Issue
Block a user