merge with latest parodus

This commit is contained in:
Bill Williams
2018-01-19 14:39:17 -08:00
parent bbf8813303
commit 7f2aa3f826
10 changed files with 437 additions and 157 deletions

View File

@@ -208,6 +208,7 @@ ExternalProject_Add(cjwt
PREFIX ${CMAKE_CURRENT_BINARY_DIR}/_prefix/cjwt
GIT_REPOSITORY https://github.com/Comcast/cjwt.git
GIT_TAG "master"
#GIT_TAG "abd4376ff56212d16f69e850a64f6e095857ca39"
CMAKE_ARGS += -DCMAKE_INSTALL_PREFIX=${INSTALL_DIR} -DBUILD_TESTING=OFF
)
add_library(libcjwt STATIC SHARED IMPORTED)

View File

@@ -34,7 +34,6 @@
/*----------------------------------------------------------------------------*/
static ParodusCfg parodusCfg;
static char token_application[64] = {'\0'};
/*----------------------------------------------------------------------------*/
/* External Functions */
@@ -50,10 +49,7 @@ void set_parodus_cfg(ParodusCfg *cfg)
memcpy(&parodusCfg, cfg, sizeof(ParodusCfg));
}
char *get_token_application(void)
{
return token_application;
}
static void execute_token_script(char *token, char *name, size_t len, char *mac, char *serNum);
const char *get_tok (const char *src, int delim, char *result, int resultsize)
{
@@ -122,7 +118,7 @@ void read_key_from_file (const char *fname, char *buf, size_t buflen)
ParodusInfo ("%d bytes read\n", nbytes);
}
void get_webpa_token(char *token, char *name, size_t len, char *serNum, char *mac)
static void execute_token_script(char *token, char *name, size_t len, char *mac, char *serNum)
{
FILE* out = NULL, *file = NULL;
char command[MAX_BUF_SIZE] = {'\0'};
@@ -169,6 +165,68 @@ static int parse_mac_address (char *target, const char *arg)
return 0;
}
static int server_is_http (const char *full_url,
const char **server_ptr)
{
int http_match;
const char *ptr;
if (strncmp(full_url, "https://", 8) == 0) {
http_match = 0;
ptr = full_url + 8;
} else if (strncmp(full_url, "http://", 7) == 0) {
http_match = 1;
ptr = full_url + 7;
} else {
ParodusError ("Invalid url %s\n", full_url);
return -1;
}
if (NULL != server_ptr)
*server_ptr = ptr;
return http_match;
}
int parse_webpa_url(const char *full_url,
char *server_addr, int server_addr_buflen,
char *port_buf, int port_buflen)
{
const char *server_ptr;
char *port_val;
char *end_port;
size_t server_len;
int http_match;
ParodusInfo ("full url: %s\n", full_url);
http_match = server_is_http (full_url, &server_ptr);
if (http_match < 0)
return http_match;
ParodusInfo ("server address copied from url\n");
parStrncpy (server_addr, server_ptr, server_addr_buflen);
server_len = strlen(server_addr);
// If there's a '/' on end, null it out
if ((server_len>0) && (server_addr[server_len-1] == '/'))
server_addr[server_len-1] = '\0';
// Look for ':'
port_val = strchr (server_addr, ':');
if (NULL == port_val) {
parStrncpy (port_buf, "8080", port_buflen);
} else {
*port_val = '\0'; // terminate server address with null
port_val++;
end_port = strchr (port_val, '/');
if (NULL != end_port)
*end_port = '\0'; // terminate port with null
parStrncpy (port_buf, port_val, port_buflen);
}
ParodusInfo ("server %s, port %s, http_match %d\n",
server_addr, port_buf, http_match);
return http_match;
}
void parseCommandLine(int argc,char **argv,ParodusCfg * cfg)
{
static const struct option long_options[] = {
@@ -189,13 +247,14 @@ void parseCommandLine(int argc,char **argv,ParodusCfg * cfg)
{"seshat-url", required_argument, 0, 'e'},
#endif
{"dns-id", required_argument, 0, 'D'},
{"acquire-jwt", required_argument, 0, 'j'},
{"jwt-algo", required_argument, 0, 'a'},
{"jwt-key", required_argument, 0, 'k'},
{"ssl-cert-path", required_argument, 0, 'c'},
{"force-ipv4", no_argument, 0, '4'},
{"force-ipv6", no_argument, 0, '6'},
{"webpa-token", required_argument, 0, 'T'},
{"port", required_argument, 0, 'P'},
{"token-read-script", required_argument, 0, 'T'},
{"token-acquisition-script", required_argument, 0, 'J'},
{0, 0, 0, 0}
};
int c;
@@ -211,7 +270,7 @@ void parseCommandLine(int argc,char **argv,ParodusCfg * cfg)
/* 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:a:k:c:4:6:T:P",
c = getopt_long (argc, argv, "m:s:f:d:r:n:b:u:t:o:i:l:p:e:D:j:a:k:c:4:6:T:J",
long_options, &option_index);
/* Detect the end of the options. */
@@ -265,7 +324,11 @@ void parseCommandLine(int argc,char **argv,ParodusCfg * cfg)
break;
case 'u':
parStrncpy(cfg->webpa_url, optarg,sizeof(cfg->webpa_url));
parStrncpy(cfg->webpa_url, optarg,sizeof(cfg->webpa_url));
if (server_is_http (cfg->webpa_url, NULL) < 0) {
ParodusError ("Bad webpa url %s\n", optarg);
abort ();
}
ParodusInfo("webpa_url is %s\n",cfg->webpa_url);
break;
@@ -296,6 +359,11 @@ void parseCommandLine(int argc,char **argv,ParodusCfg * cfg)
ParodusInfo("parodus dns_id is %s\n",cfg->dns_id);
break;
case 'j':
cfg->acquire_jwt = atoi(optarg);
ParodusInfo("acquire jwt option is %d\n",cfg->acquire_jwt);
break;
case 'a':
// the command line argument is a list of allowed algoritms,
// separated by colons, like "RS256:RS512:none"
@@ -332,15 +400,12 @@ void parseCommandLine(int argc,char **argv,ParodusCfg * cfg)
cfg->flags |= FLAGS_IPV6_ONLY;
break;
case 'T':
parStrncpy(token_application, optarg, sizeof(token_application));
get_webpa_token(cfg->webpa_token,optarg,sizeof(cfg->webpa_token),cfg->hw_serial_number,cfg->hw_mac);
ParodusInfo("webpa_token is %s\n",cfg->webpa_token);
case 'J':
parStrncpy(cfg->token_acquisition_script, optarg,sizeof(cfg->token_acquisition_script));
break;
case 'P':
cfg->port = atoi(optarg);
case 'T':
parStrncpy(cfg->token_read_script, optarg,sizeof(cfg->token_read_script));
break;
case '?':
@@ -366,6 +431,63 @@ void parseCommandLine(int argc,char **argv,ParodusCfg * cfg)
}
}
/*
* call parodus create/acquisition script to create new auth token, if success then calls
* execute_token_script func with args as parodus read script.
*/
void createNewAuthToken(char *newToken, size_t len)
{
//Call create script
char output[12] = {'\0'};
execute_token_script(output,get_parodus_cfg()->token_acquisition_script,sizeof(output),get_parodus_cfg()->hw_mac,get_parodus_cfg()->hw_serial_number);
if (strlen(output)>0 && strcmp(output,"SUCCESS")==0)
{
//Call read script
execute_token_script(newToken,get_parodus_cfg()->token_read_script,len,get_parodus_cfg()->hw_mac,get_parodus_cfg()->hw_serial_number);
}
else
{
ParodusError("Failed to create new token\n");
}
}
/*
* Fetches authorization token from the output of read script. If read script returns "ERROR"
* it will call createNewAuthToken to create and read new token
*/
void getAuthToken(ParodusCfg *cfg)
{
//local var to update cfg->webpa_auth_token only in success case
char output[4069] = {'\0'} ;
if( strlen(cfg->token_read_script) !=0 && strlen(cfg->token_acquisition_script) !=0)
{
execute_token_script(output,cfg->token_read_script,sizeof(output),cfg->hw_mac,cfg->hw_serial_number);
if ((strlen(output) == 0))
{
ParodusError("Unable to get auth token\n");
}
else if(strcmp(output,"ERROR")==0)
{
ParodusInfo("Failed to read token from %s. Proceeding to create new token.\n",cfg->token_read_script);
//Call create/acquisition script
createNewAuthToken(cfg->webpa_auth_token, sizeof(cfg->webpa_auth_token));
}
else
{
ParodusInfo("update cfg->webpa_auth_token in success case\n");
parStrncpy(cfg->webpa_auth_token, output, sizeof(cfg->webpa_auth_token));
}
}
else
{
ParodusInfo("Both read and write file are NULL \n");
}
}
void setDefaultValuesToCfg(ParodusCfg *cfg)
{
if(cfg == NULL)
@@ -377,7 +499,8 @@ void setDefaultValuesToCfg(ParodusCfg *cfg)
ParodusInfo("Setting default values to parodusCfg\n");
parStrncpy(cfg->local_url, PARODUS_UPSTREAM, sizeof(cfg->local_url));
cfg->acquire_jwt = 0;
parStrncpy(cfg->dns_id, DNS_ID,sizeof(cfg->dns_id));
parStrncpy(cfg->jwt_key, "\0", sizeof(cfg->jwt_key));
@@ -387,7 +510,6 @@ void setDefaultValuesToCfg(ParodusCfg *cfg)
parStrncpy(cfg->cert_path, "\0", sizeof(cfg->cert_path));
cfg->flags = 0;
cfg->port = 8080;
parStrncpy(cfg->webpa_path_url, WEBPA_PATH_URL,sizeof(cfg->webpa_path_url));
@@ -500,6 +622,8 @@ void loadParodusCfg(ParodusCfg * config,ParodusCfg *cfg)
ParodusInfo("seshat_url is NULL. Read from tmp file\n");
}
#endif
cfg->acquire_jwt = config->acquire_jwt;
if( strlen(config->dns_id) !=0)
{
parStrncpy(cfg->dns_id, config->dns_id,sizeof(cfg->dns_id));
@@ -532,20 +656,27 @@ void loadParodusCfg(ParodusCfg * config,ParodusCfg *cfg)
ParodusPrint("cert_path is NULL. set to empty\n");
}
if( strlen(config->webpa_token) !=0)
if(strlen(config->token_acquisition_script )!=0)
{
parStrncpy(cfg->webpa_token, config->webpa_token,sizeof(cfg->webpa_token));
parStrncpy(cfg->token_acquisition_script, config->token_acquisition_script,sizeof(cfg->token_acquisition_script));
}
else
{
ParodusPrint("webpa_token is NULL. read from tmp file\n");
ParodusPrint("token_acquisition_script is NULL. read from tmp file\n");
}
if(strlen(config->token_read_script )!=0)
{
parStrncpy(cfg->token_read_script, config->token_read_script,sizeof(cfg->token_read_script));
}
else
{
ParodusPrint("token_read_script is NULL. read from tmp file\n");
}
cfg->boot_time = config->boot_time;
cfg->webpa_ping_timeout = config->webpa_ping_timeout;
cfg->webpa_backoff_max = config->webpa_backoff_max;
cfg->port = config->port;
ParodusPrint("cfg->port is :%d\n",cfg->port);
parStrncpy(cfg->webpa_path_url, WEBPA_PATH_URL,sizeof(cfg->webpa_path_url));
snprintf(cfg->webpa_protocol, sizeof(cfg->webpa_protocol), "%s-%s", PROTOCOL_VALUE, GIT_COMMIT_TAG);
ParodusInfo("cfg->webpa_protocol is %s\n", cfg->webpa_protocol);

View File

@@ -84,11 +84,13 @@ typedef struct
char seshat_url[128];
#endif
char dns_id[64];
unsigned int acquire_jwt;
unsigned int jwt_algo; // bit mask set for each allowed algorithm
char jwt_key[4096]; // may be read in from a pem file
char cert_path[64];
char webpa_token[4096];
unsigned int port;
char webpa_auth_token[4096];
char token_acquisition_script[64];
char token_read_script[64];
} ParodusCfg;
#define FLAGS_IPV6_ONLY (1 << 0)
@@ -99,13 +101,31 @@ typedef struct
/*----------------------------------------------------------------------------*/
void loadParodusCfg(ParodusCfg * config,ParodusCfg *cfg);
void get_webpa_token(char *token, char *name, size_t len,char *serNum, char *mac);
void createNewAuthToken(char *newToken, size_t len);
void parseCommandLine(int argc,char **argv,ParodusCfg * cfg);
void setDefaultValuesToCfg(ParodusCfg *cfg);
void getAuthToken(ParodusCfg *cfg);
// Accessor for the global config structure.
ParodusCfg *get_parodus_cfg(void);
void set_parodus_cfg(ParodusCfg *);
char *get_token_application(void) ;
/**
* parse a webpa url. Extract the server address, the port
* and return whether it's secure or not
*
* @param full_url full url
* @param server_addr buffer containing server address found in url
* @param server_addr_buflen len of the server addr buffer provided by caller
* @param port_buf buffer containing port value found in url
* @param port_buflen len of the port buffer provided by caller
* @return 1 if insecure connection is allowed, 0 if not,
* or -1 if error
*/
int parse_webpa_url(const char *full_url,
char *server_addr, int server_addr_buflen,
char *port_buf, int port_buflen);
#ifdef __cplusplus
}
#endif

View File

@@ -81,7 +81,6 @@ int createNopollConnection(noPollCtx *ctx)
char redirectURL[128]={'\0'};
int status=0;
int allow_insecure;
char *temp_ptr;
int connErr=0;
struct timespec connErr_start,connErr_end,*connErr_startPtr,*connErr_endPtr;
connErr_startPtr = &connErr_start;
@@ -92,7 +91,7 @@ int createNopollConnection(noPollCtx *ctx)
char device_id[32]={'\0'};
char user_agent[512]={'\0'};
char * extra_headers = NULL;
char new_token[4096] ;
char header_string[4096] ={'\0'};
if(ctx == NULL) {
return nopoll_false;
@@ -102,12 +101,21 @@ 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);
snprintf(port,sizeof(port),"%d",get_parodus_cfg()->port);
parStrncpy(server_Address, get_parodus_cfg()->webpa_url, sizeof(server_Address));
//query dns and validate JWT
allow_insecure = allow_insecure_conn(
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);
@@ -126,10 +134,16 @@ int createNopollConnection(noPollCtx *ctx)
snprintf(device_id, sizeof(device_id), "mac:%s", deviceMAC);
ParodusInfo("Device_id %s\n",device_id);
extra_headers = nopoll_strdup_printf("\r\nX-WebPA-Device-Name: %s"
if(0 != strlen(get_parodus_cfg()->webpa_auth_token)){
snprintf(header_string, sizeof(get_parodus_cfg()->webpa_auth_token)+20, "Authorization:Bearer %s", get_parodus_cfg()->webpa_auth_token);
}
extra_headers = nopoll_strdup_printf("\r\nX-WebPA-Device-Name: %s"
"\r\nX-WebPA-Device-Protocols: wrp-0.11,getset-0.1"
"\r\nX-WebPA-Token: %s"
"\r\nUser-Agent: %s" "\r\nX-WebPA-Convey: %s",device_id,((0 != strlen(get_parodus_cfg()->webpa_token)) ? get_parodus_cfg()->webpa_token : ""),user_agent,(strlen(conveyHeader) > 0)? conveyHeader :"");
"\r\n%s"
"\r\nUser-Agent: %s" "\r\nX-WebPA-Convey: %s",device_id,((0 != strlen(get_parodus_cfg()->webpa_auth_token)) ? header_string : "X-WebPA-Token:"),user_agent,(strlen(conveyHeader) > 0)? conveyHeader :"");
do
{
@@ -161,7 +175,9 @@ 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
parStrncpy(server_Address, get_parodus_cfg()->webpa_url, sizeof(server_Address));
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;
@@ -184,27 +200,34 @@ int createNopollConnection(noPollCtx *ctx)
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
temp_ptr = strtok(redirectURL , ":"); //skip Redirect
temp_ptr = strtok(NULL , ":"); // skip https
temp_ptr = strtok(NULL , ":");
parStrncpy(server_Address, temp_ptr+2, sizeof(server_Address));
parStrncpy(port, strtok(NULL , "/"), sizeof(port));
ParodusInfo("Trying to Connect to new Redirected server : %s with port : %s\n", server_Address, port);
if (strncmp (redirect_ptr, "Redirect:", 9) == 0)
redirect_ptr += 9;
allow_insecure = parse_webpa_url (redirect_ptr,
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));
} 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
c = 2;
}
else if(status == 403)
{
ParodusError("Received Unauthorized response with status: %d\n", status);
//Get new token and update auth header
get_webpa_token(new_token,get_token_application(),sizeof(new_token),get_parodus_cfg()->hw_serial_number, get_parodus_cfg()->hw_mac);
//Get new token and update auth header
char new_token[4096] ={'\0'};
if (strlen(get_parodus_cfg()->token_acquisition_script) >0)
createNewAuthToken(new_token,sizeof(new_token));
extra_headers = nopoll_strdup_printf("\r\nX-WebPA-Device-Name: %s"
"\r\nX-WebPA-Device-Protocols: wrp-0.11,getset-0.1"
"\r\nX-WebPA-Token: %s"
"\r\nAuthorization:Bearer %s"
"\r\nUser-Agent: %s" "\r\nX-WebPA-Convey: %s",device_id,((0 != strlen(new_token)) ? new_token : ""),user_agent,(strlen(conveyHeader) > 0)? conveyHeader :"");
//reset c=2 to start backoffRetryTime as retrying
@@ -216,8 +239,9 @@ 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
parStrncpy(server_Address, get_parodus_cfg()->webpa_url, sizeof(server_Address));
snprintf(port,sizeof(port),"%d",get_parodus_cfg()->port);
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);
c++;
@@ -269,8 +293,9 @@ int createNopollConnection(noPollCtx *ctx)
sleep(backoffRetryTime);
c++;
// Copy the server address and port from config to avoid retrying to the same failing talaria redirected node
parStrncpy(server_Address, get_parodus_cfg()->webpa_url, sizeof(server_Address));
snprintf(port,sizeof(port),"%d",get_parodus_cfg()->port);
allow_insecure = parse_webpa_url (get_parodus_cfg()->webpa_url,
server_Address, (int) sizeof(server_Address),
port, (int) sizeof(port));
}
}while(initial_retry);

View File

@@ -78,6 +78,7 @@ int main( int argc, char **argv)
ParodusInfo("********** Starting component: Parodus **********\n ");
setDefaultValuesToCfg(cfg);
parseCommandLine(argc,argv,cfg);
getAuthToken(cfg);
createSocketConnection( NULL);

View File

@@ -116,9 +116,6 @@ int analyze_jwt (const cjwt_t *jwt, char *url_buf, int url_buflen,
{
cJSON *claims = jwt->private_claims;
cJSON *endpoint = NULL;
const char *endpoint_value;
char *port_val;
size_t url_len;
time_t exp_time, cur_time;
int http_match;
@@ -134,17 +131,6 @@ int analyze_jwt (const cjwt_t *jwt, char *url_buf, int url_buflen,
}
ParodusInfo ("JWT endpoint: %s\n", endpoint->valuestring);
if (strncmp(endpoint->valuestring, "https://", 8) == 0) {
http_match = 0;
endpoint_value = endpoint->valuestring + 8;
} else if (strncmp(endpoint->valuestring, "http://", 7) == 0) {
http_match = 1;
endpoint_value = endpoint->valuestring + 7;
} else {
ParodusError ("Invalid endpoint claim in JWT\n");
return TOKEN_ERR_BAD_ENDPOINT;
}
ParodusInfo ("JWT is_http strncmp: %d\n", http_match);
exp_time = jwt->exp.tv_sec;
if (0 == exp_time) {
ParodusError ("exp not found in JWT payload\n");
@@ -157,19 +143,14 @@ int analyze_jwt (const cjwt_t *jwt, char *url_buf, int url_buflen,
return TOKEN_ERR_JWT_EXPIRED;
}
}
ParodusInfo ("Endpoint copied from JWT\n");
parStrncpy (url_buf, endpoint_value, url_buflen);
url_len = strlen(url_buf);
// If there's a '/' on end, null it out
if ((url_len>0) && (url_buf[url_len-1] == '/'))
url_buf[url_len-1] = '\0';
// Look for ':'
port_val = strchr (url_buf, ':');
if (NULL != port_val) {
*port_val = '\0'; // terminate server address with null
parStrncpy (port_buf, port_val+1, port_buflen);
http_match = parse_webpa_url (endpoint->valuestring,
url_buf, url_buflen, port_buf, port_buflen);
if (http_match < 0) {
ParodusError ("Invalid endpoint claim in JWT\n");
return TOKEN_ERR_BAD_ENDPOINT;
}
ParodusInfo ("JWT is_http strncmp: %d\n", http_match);
return http_match;
}
@@ -555,6 +536,10 @@ end:
if (NULL != jwt_token)
free (jwt_token);
#else
(void) url_buf;
(void) url_buflen;
(void) port_buf;
(void) port_buflen;
int insecure = TOKEN_NO_DNS_QUERY;
#endif
ParodusPrint ("Allow Insecure %d\n", insecure);

View File

@@ -17,14 +17,17 @@ set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DTEST ")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -W -g -fprofile-arcs -ftest-coverage -O0")
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fprofile-arcs -ftest-coverage -O0")
set (PARODUS_COMMON_SRC ../src/string_helpers.c ../src/mutex.c ../src/time.c ../src/config.c ../src/spin_thread.c ../src/token.c)
set (PARODUS_COMMON_LIBS gcov -lcunit -lcimplog -lwrp-c -luuid -lpthread -lmsgpackc -lnopoll -lnanomsg -Wl,--no-as-needed -lcjson -ltrower-base64 -lssl -lcrypto -lrt -lm)
set (PARODUS_COMMON_LIBS gcov -lcunit -lcimplog -lwrp-c
-luuid -lpthread -lmsgpackc -lnopoll -lnanomsg
-Wl,--no-as-needed -lcjson -lcjwt -ltrower-base64
-lssl -lcrypto -lrt -lm)
if (ENABLE_SESHAT)
set (PARODUS_COMMON_LIBS -llibseshat ${PARODUS_COMMON_LIBS})
endif (ENABLE_SESHAT)
if (FEATURE_DNS_QUERY)
set (PARODUS_COMMON_LIBS ${PARODUS_COMMON_LIBS} -lcjwt -lucresolv -lresolv)
set (PARODUS_COMMON_LIBS ${PARODUS_COMMON_LIBS} -lucresolv -lresolv)
endif (FEATURE_DNS_QUERY)
if(NOT DISABLE_VALGRIND)

View File

@@ -1,3 +1,3 @@
sudo ./parodus --hw-model=TG1682 --hw-serial-number=Fer23u948590 --hw-manufacturer=ARRISGroup,Inc. --hw-mac=aabbccddeeff --hw-last-reboot-reason=unknown --fw-name=TG1682_DEV_master_2016000000sdy --boot-time=123589 --webpa-ping-time=180 --webpa-backoff-max=0 --webpa-inteface-used=p7p1 --webpa-url=fabric-beta.webpa.comcast.net --jwt-algo=none:RS256 --jwt-key=../../tests/webpa-rs256.pem --dns-id=fabric.xmidt
sudo ./parodus --hw-model=TG1682 --hw-serial-number=Fer23u948590 --hw-manufacturer=ARRISGroup,Inc. --hw-mac=aabbccddeeff --hw-last-reboot-reason=unknown --fw-name=TG1682_DEV_master_2016000000sdy --boot-time=123589 --webpa-ping-timeout=180 --webpa-backoff-max=0 --webpa-interface-used=p7p1 --webpa-url=https://fabric-beta.webpa.comcast.net --acquire-jwt=1 --jwt-algo=none:RS256 --jwt-key=../../tests/webpa-rs256.pem --dns-id=fabric.xmidt

View File

@@ -26,7 +26,6 @@
#include "../src/config.h"
#include "../src/ParodusInternal.h"
#define K_argc 18
/*----------------------------------------------------------------------------*/
/* Mocks */
@@ -57,7 +56,7 @@ void test_setParodusConfig()
parStrncpy(cfg.hw_last_reboot_reason , "unknown", sizeof(cfg.hw_last_reboot_reason));
parStrncpy(cfg.fw_name , "2.364s2", sizeof(cfg.fw_name));
parStrncpy(cfg.webpa_path_url , "/v1", sizeof(cfg.webpa_path_url));
parStrncpy(cfg.webpa_url , "localhost", sizeof(cfg.webpa_url));
parStrncpy(cfg.webpa_url , "http://127.0.0.1", sizeof(cfg.webpa_url));
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));
@@ -69,7 +68,12 @@ void test_setParodusConfig()
cfg.boot_time = 423457;
cfg.webpa_ping_timeout = 30;
cfg.webpa_backoff_max = 255;
#ifdef FEATURE_DNS_QUERY
cfg.acquire_jwt = 1;
parStrncpy(cfg.dns_id, "test",sizeof(cfg.dns_id));
cfg.jwt_algo = 1025;
parStrncpy(cfg.jwt_key, "key.txt",sizeof(cfg.jwt_key));
#endif
set_parodus_cfg(&cfg);
ParodusCfg *temp = get_parodus_cfg();
@@ -92,6 +96,12 @@ void test_setParodusConfig()
assert_int_equal((int) cfg.boot_time, (int) temp->boot_time);
assert_int_equal((int) cfg.webpa_ping_timeout, (int) temp->webpa_ping_timeout);
assert_int_equal((int) cfg.webpa_backoff_max, (int) temp->webpa_backoff_max);
#ifdef FEATURE_DNS_QUERY
assert_int_equal( (int) cfg.acquire_jwt, (int) temp->acquire_jwt);
assert_string_equal(cfg.dns_id, temp->dns_id);
assert_int_equal( (int) cfg.jwt_algo, (int) temp->jwt_algo);
assert_string_equal(cfg.jwt_key, temp->jwt_key);
#endif
}
void test_getParodusConfig()
@@ -109,35 +119,40 @@ void test_getParodusConfig()
void test_parseCommandLine()
{
int argc =K_argc;
#ifndef ENABLE_SESHAT
argc = argc - 1;
#endif
char * command[argc+1];
int i = 0;
char expectedToken[128] = {'\0'};
char expectedToken[1280] = {'\0'};
command[i++] = "parodus";
command[i++] = "--hw-model=TG1682";
command[i++] = "--hw-serial-number=Fer23u948590";
command[i++] = "--hw-manufacturer=ARRISGroup,Inc.";
command[i++] = "--hw-mac=123567892366";
command[i++] = "--hw-last-reboot-reason=unknown";
command[i++] = "--fw-name=TG1682_DEV_master_2016000000sdy";
command[i++] = "--webpa-ping-time=180";
command[i++] = "--webpa-interface-used=br0";
command[i++] = "--webpa-url=localhost";
command[i++] = "--webpa-backoff-max=0";
command[i++] = "--boot-time=1234";
command[i++] = "--parodus-local-url=tcp://127.0.0.1:6666";
command[i++] = "--partner-id=cox";
char *command[] = {"parodus",
"--hw-model=TG1682",
"--hw-serial-number=Fer23u948590",
"--hw-manufacturer=ARRISGroup,Inc.",
"--hw-mac=123567892366",
"--hw-last-reboot-reason=unknown",
"--fw-name=TG1682_DEV_master_2016000000sdy",
"--webpa-ping-time=180",
"--webpa-interface-used=br0",
"--webpa-url=http://127.0.0.1",
"--webpa-backoff-max=0",
"--boot-time=1234",
"--parodus-local-url=tcp://127.0.0.1:6666",
"--partner-id=cox",
#ifdef ENABLE_SESHAT
command[i++] = "--seshat-url=ipc://127.0.0.1:7777";
"--seshat-url=ipc://127.0.0.1:7777",
#endif
command[i++] = "--force-ipv4";
command[i++] = "--force-ipv6";
command[i++] = "--webpa-token=/tmp/token.sh";
command[i] = '\0';
"--force-ipv4",
"--force-ipv6",
"--token-read-script=/tmp/token.sh",
"--token-acquisition-script=/tmp/token.sh",
"--ssl-cert-path=/etc/ssl/certs/ca-certificates.crt",
#ifdef FEATURE_DNS_QUERY
"--acquire-jwt=1",
"--dns-id=fabric",
"--jwt-key=../../tests/webpa-rs256.pem",
"--jwt-key=AGdyuwyhwl2ow2ydsoioiygkshwdthuwd",
"--jwt-algo=none:RS256",
#endif
NULL
};
int argc = (sizeof (command) / sizeof (char *)) - 1;
ParodusCfg parodusCfg;
memset(&parodusCfg,0,sizeof(parodusCfg));
@@ -152,7 +167,7 @@ void test_parseCommandLine()
assert_string_equal( parodusCfg.fw_name, "TG1682_DEV_master_2016000000sdy");
assert_int_equal( (int) parodusCfg.webpa_ping_timeout,180);
assert_string_equal( parodusCfg.webpa_interface_used, "br0");
assert_string_equal( parodusCfg.webpa_url, "localhost");
assert_string_equal( parodusCfg.webpa_url, "http://127.0.0.1");
assert_int_equal( (int) parodusCfg.webpa_backoff_max,0);
assert_int_equal( (int) parodusCfg.boot_time,1234);
assert_string_equal( parodusCfg.local_url,"tcp://127.0.0.1:6666");
@@ -162,7 +177,18 @@ void test_parseCommandLine()
#endif
assert_int_equal( (int) parodusCfg.flags, FLAGS_IPV6_ONLY|FLAGS_IPV4_ONLY);
sprintf(expectedToken,"secure-token-%s-%s",parodusCfg.hw_serial_number,parodusCfg.hw_mac);
assert_string_equal( parodusCfg.webpa_token,expectedToken);
getAuthToken(&parodusCfg);
set_parodus_cfg(&parodusCfg);
assert_string_equal( get_parodus_cfg()->webpa_auth_token,expectedToken);
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_id, "fabric");
assert_int_equal( (int) parodusCfg.jwt_algo, 1025);
assert_string_equal(parodusCfg.jwt_key, "AGdyuwyhwl2ow2ydsoioiygkshwdthuwd");
#endif
}
@@ -173,10 +199,7 @@ void test_parseCommandLineNull()
void err_parseCommandLine()
{
int argc =K_argc;
#ifndef ENABLE_SESHAT
argc = argc - 1;
#endif
int argc = 19;
char * command[20]={'\0'};
command[0] = "parodus";
@@ -205,12 +228,24 @@ void test_loadParodusCfg()
parStrncpy(Cfg->hw_last_reboot_reason , "unknown", sizeof(Cfg->hw_last_reboot_reason));
parStrncpy(Cfg->fw_name , "2.364s2", sizeof(Cfg->fw_name));
parStrncpy(Cfg->webpa_path_url , "/v1", sizeof(Cfg->webpa_path_url));
parStrncpy(Cfg->webpa_url , "localhost", sizeof(Cfg->webpa_url));
parStrncpy(Cfg->webpa_url , "http://127.0.0.1", sizeof(Cfg->webpa_url));
parStrncpy(Cfg->webpa_interface_used , "eth0", sizeof(Cfg->webpa_interface_used));
snprintf(protocol, sizeof(protocol), "%s-%s", PROTOCOL_VALUE, GIT_COMMIT_TAG);
parStrncpy(Cfg->webpa_protocol , protocol, sizeof(Cfg->webpa_protocol));
parStrncpy(Cfg->local_url , "tcp://10.0.0.1:6000", sizeof(Cfg->local_url));
parStrncpy(Cfg->partner_id , "shaw", sizeof(Cfg->partner_id));
#ifdef FEATURE_DNS_QUERY
Cfg->acquire_jwt = 1;
parStrncpy(Cfg->dns_id, "fabric",sizeof(Cfg->dns_id));
Cfg->jwt_algo = 1025;
parStrncpy(Cfg->jwt_key, "AGdyuwyhwl2ow2ydsoioiygkshwdthuwd",sizeof(Cfg->jwt_key));
#endif
parStrncpy(Cfg->token_acquisition_script , "/tmp/token.sh", sizeof(Cfg->token_acquisition_script));
parStrncpy(Cfg->token_read_script , "/tmp/token.sh", sizeof(Cfg->token_read_script));
parStrncpy(Cfg->cert_path, "/etc/ssl.crt",sizeof(Cfg->cert_path));
#ifdef ENABLE_SESHAT
parStrncpy(Cfg->seshat_url, "ipc://tmp/seshat_service.url", sizeof(Cfg->seshat_url));
#endif
memset(&tmpcfg,0,sizeof(ParodusCfg));
loadParodusCfg(Cfg,&tmpcfg);
@@ -222,6 +257,18 @@ void test_loadParodusCfg()
assert_string_equal( tmpcfg.local_url, "tcp://10.0.0.1:6000");
assert_string_equal( tmpcfg.partner_id, "shaw");
assert_string_equal( tmpcfg.webpa_protocol, protocol);
#ifdef FEATURE_DNS_QUERY
assert_int_equal( (int) tmpcfg.acquire_jwt, 1);
assert_string_equal(tmpcfg.dns_id, "fabric");
assert_int_equal( (int) tmpcfg.jwt_algo, 1025);
assert_string_equal(tmpcfg.jwt_key, "AGdyuwyhwl2ow2ydsoioiygkshwdthuwd");
#endif
assert_string_equal( tmpcfg.token_acquisition_script,"/tmp/token.sh");
assert_string_equal( tmpcfg.token_read_script,"/tmp/token.sh");
assert_string_equal(tmpcfg.cert_path, "/etc/ssl.crt");
#ifdef ENABLE_SESHAT
assert_string_equal(tmpcfg.seshat_url, "ipc://tmp/seshat_service.url");
#endif
free(Cfg);
}
@@ -276,6 +323,29 @@ void test_parodusGitVersion()
assert_int_equal(n, 0);
}
void test_setDefaultValuesToCfg()
{
ParodusCfg *cfg = (ParodusCfg *) malloc(sizeof(ParodusCfg));
memset(cfg,0,sizeof(ParodusCfg));
setDefaultValuesToCfg(cfg);
assert_string_equal( cfg->local_url, PARODUS_UPSTREAM);
#ifdef FEATURE_DNS_QUERY
assert_int_equal(cfg->acquire_jwt, 0);
assert_string_equal(cfg->dns_id, DNS_ID);
assert_string_equal(cfg->jwt_key, "\0");
assert_int_equal( (int)cfg->jwt_algo, 0);
#endif
assert_string_equal(cfg->cert_path, "\0");
assert_int_equal((int)cfg->flags, 0);
assert_string_equal(cfg->webpa_path_url, WEBPA_PATH_URL);
assert_string_equal(cfg->webpa_uuid, "1234567-345456546");
}
void err_setDefaultValuesToCfg()
{
setDefaultValuesToCfg(NULL);
}
/*----------------------------------------------------------------------------*/
/* External Functions */
/*----------------------------------------------------------------------------*/
@@ -290,8 +360,10 @@ int main(void)
cmocka_unit_test(err_loadParodusCfg),
cmocka_unit_test(test_parseCommandLine),
cmocka_unit_test(test_parseCommandLineNull),
cmocka_unit_test(err_parseCommandLine),
cmocka_unit_test(test_parodusGitVersion)
//cmocka_unit_test(err_parseCommandLine),
cmocka_unit_test(test_parodusGitVersion),
cmocka_unit_test(test_setDefaultValuesToCfg),
cmocka_unit_test(err_setDefaultValuesToCfg),
};
return cmocka_run_group_tests(tests, NULL, NULL);

View File

@@ -28,6 +28,9 @@
#include "../src/connection.h"
#include "../src/config.h"
#define SECURE_WEBPA_URL "https://127.0.0.1"
#define UNSECURE_WEBPA_URL "http://127.0.0.1"
#define HOST_IP "127.0.0.1"
/*----------------------------------------------------------------------------*/
/* File Scoped Variables */
@@ -38,6 +41,8 @@ bool LastReasonStatus;
volatile unsigned int heartBeatTimer;
pthread_mutex_t close_mut;
int g_status;
char *g_redirect_url;
/*----------------------------------------------------------------------------*/
/* Mocks */
/*----------------------------------------------------------------------------*/
@@ -92,19 +97,26 @@ void setGlobalHttpStatus(int status)
g_status=status;
}
void setGlobalRedirectUrl (char *redirect_url)
{
g_redirect_url = redirect_url;
}
nopoll_bool nopoll_conn_wait_until_connection_ready (noPollConn * conn, int timeout, int *status, char * message)
{
UNUSED(timeout); UNUSED(message);
UNUSED(conn);
*status = getGlobalHttpStatus();
if (NULL != g_redirect_url)
parStrncpy (message, g_redirect_url, 128);
function_called();
return (nopoll_bool) mock();
}
int allow_insecure_conn (void)
{
function_called ();
return (int) mock();
function_called ();
return (int) mock();
}
char* getWebpaConveyHeader()
@@ -190,24 +202,24 @@ void test_createSecureConnection()
memset(cfg, 0, sizeof(ParodusCfg));
cfg->flags = 0;
parStrncpy(cfg->webpa_url , "localhost", sizeof(cfg->webpa_url));
parStrncpy(cfg->webpa_url , SECURE_WEBPA_URL, sizeof(cfg->webpa_url));
set_parodus_cfg(cfg);
assert_non_null(ctx);
will_return (allow_insecure_conn, 0);
expect_function_call (allow_insecure_conn);
will_return (strncmp, 0);
expect_function_call (strncmp);
will_return(getWebpaConveyHeader, (intptr_t)"WebPA-1.6 (TG1682)");
expect_function_call(getWebpaConveyHeader);
expect_value(nopoll_conn_tls_new6, (intptr_t)ctx, (intptr_t)ctx);
expect_string(nopoll_conn_tls_new6, (intptr_t)host_ip, "localhost");
expect_string(nopoll_conn_tls_new6, (intptr_t)host_ip, HOST_IP);
will_return(nopoll_conn_tls_new6, NULL);
expect_function_call(nopoll_conn_tls_new6);
expect_value(nopoll_conn_tls_new, (intptr_t)ctx, (intptr_t)ctx);
expect_string(nopoll_conn_tls_new, (intptr_t)host_ip, "localhost");
expect_string(nopoll_conn_tls_new, (intptr_t)host_ip, HOST_IP);
will_return(nopoll_conn_tls_new, (intptr_t)&gNPConn);
expect_function_call(nopoll_conn_tls_new);
@@ -234,19 +246,21 @@ void test_createConnection()
assert_non_null(cfg);
cfg->flags = 0;
parStrncpy(cfg->webpa_url , "localhost", sizeof(cfg->webpa_url));
parStrncpy(cfg->webpa_url , UNSECURE_WEBPA_URL, sizeof(cfg->webpa_url));
set_parodus_cfg(cfg);
assert_non_null(ctx);
will_return (allow_insecure_conn, 1);
expect_function_call (allow_insecure_conn);
will_return (strncmp, -1);
expect_function_call (strncmp);
will_return (strncmp, 0);
expect_function_call (strncmp);
will_return(getWebpaConveyHeader, (intptr_t)"WebPA-1.6 (TG1682)");
expect_function_call(getWebpaConveyHeader);
expect_value(nopoll_conn_new_opts, (intptr_t)ctx, (intptr_t)ctx);
expect_string(nopoll_conn_new_opts, (intptr_t)host_ip, "localhost");
expect_string(nopoll_conn_new_opts, (intptr_t)host_ip, HOST_IP);
will_return(nopoll_conn_new_opts, (intptr_t)&gNPConn);
expect_function_call(nopoll_conn_new_opts);
@@ -273,24 +287,24 @@ void test_createConnectionConnNull()
cfg->flags = 0;
cfg->webpa_backoff_max = 2;
parStrncpy(cfg->webpa_url , "localhost",sizeof(cfg->webpa_url));
parStrncpy(cfg->webpa_url , SECURE_WEBPA_URL,sizeof(cfg->webpa_url));
set_parodus_cfg(cfg);
assert_non_null(ctx);
will_return (allow_insecure_conn, 0);
expect_function_call (allow_insecure_conn);
will_return (strncmp, 0);
expect_function_call (strncmp);
will_return(getWebpaConveyHeader, (intptr_t)"");
expect_function_call(getWebpaConveyHeader);
expect_value(nopoll_conn_tls_new6, (intptr_t)ctx, (intptr_t)ctx);
expect_string(nopoll_conn_tls_new6, (intptr_t)host_ip, "localhost");
expect_string(nopoll_conn_tls_new6, (intptr_t)host_ip, HOST_IP);
will_return(nopoll_conn_tls_new6, NULL);
expect_function_call(nopoll_conn_tls_new6);
expect_value(nopoll_conn_tls_new, (intptr_t)ctx, (intptr_t)ctx);
expect_string(nopoll_conn_tls_new, (intptr_t)host_ip, "localhost");
expect_string(nopoll_conn_tls_new, (intptr_t)host_ip, HOST_IP);
will_return(nopoll_conn_tls_new, (intptr_t)NULL);
expect_function_call(nopoll_conn_tls_new);
@@ -299,14 +313,17 @@ void test_createConnectionConnNull()
expect_function_call(getCurrentTime);
will_return (strncmp, 0);
expect_function_call (strncmp);
expect_value(nopoll_conn_tls_new6, (intptr_t)ctx, (intptr_t)ctx);
expect_string(nopoll_conn_tls_new6, (intptr_t)host_ip, "localhost");
expect_string(nopoll_conn_tls_new6, (intptr_t)host_ip, HOST_IP);
will_return(nopoll_conn_tls_new6, NULL);
expect_function_call(nopoll_conn_tls_new6);
expect_value(nopoll_conn_tls_new, (intptr_t)ctx, (intptr_t)ctx);
expect_string(nopoll_conn_tls_new,(intptr_t)host_ip, "localhost");
expect_string(nopoll_conn_tls_new,(intptr_t)host_ip, HOST_IP);
will_return(nopoll_conn_tls_new, (intptr_t)NULL);
expect_function_call(nopoll_conn_tls_new);
@@ -324,13 +341,16 @@ void test_createConnectionConnNull()
will_return(kill, 1);
expect_function_call(kill);
will_return (strncmp, 0);
expect_function_call (strncmp);
expect_value(nopoll_conn_tls_new6, (intptr_t)ctx, (intptr_t)ctx);
expect_string(nopoll_conn_tls_new6, (intptr_t)host_ip, "localhost");
expect_string(nopoll_conn_tls_new6, (intptr_t)host_ip, HOST_IP);
will_return(nopoll_conn_tls_new6, NULL);
expect_function_call(nopoll_conn_tls_new6);
expect_value(nopoll_conn_tls_new, (intptr_t)ctx, (intptr_t)ctx);
expect_string(nopoll_conn_tls_new, (intptr_t)host_ip, "localhost");
expect_string(nopoll_conn_tls_new, (intptr_t)host_ip, HOST_IP);
will_return(nopoll_conn_tls_new, (intptr_t)&gNPConn);
expect_function_call(nopoll_conn_tls_new);
@@ -356,24 +376,31 @@ void test_createConnectionConnNotOk()
assert_non_null(cfg);
cfg->flags = 0;
parStrncpy(cfg->webpa_url , "localhost", sizeof(cfg->webpa_url));
parStrncpy(cfg->webpa_url , UNSECURE_WEBPA_URL, sizeof(cfg->webpa_url));
set_parodus_cfg(cfg);
assert_non_null(ctx);
will_return (allow_insecure_conn, 1);
expect_function_call (allow_insecure_conn);
will_return (strncmp, 1);
expect_function_call (strncmp);
will_return (strncmp, 0);
expect_function_call (strncmp);
will_return(getWebpaConveyHeader, (intptr_t)"WebPA-1.6 (TG1682)");
expect_function_call(getWebpaConveyHeader);
expect_value(nopoll_conn_new_opts, (intptr_t)ctx, (intptr_t)ctx);
expect_string(nopoll_conn_new_opts, (intptr_t)host_ip, "localhost");
expect_string(nopoll_conn_new_opts, (intptr_t)host_ip, HOST_IP);
will_return(nopoll_conn_new_opts, (intptr_t)&gNPConn);
expect_function_call(nopoll_conn_new_opts);
will_return(nopoll_conn_is_ok, nopoll_false);
expect_function_call(nopoll_conn_is_ok);
will_return (strncmp, 1);
expect_function_call (strncmp);
will_return (strncmp, 0);
expect_function_call (strncmp);
expect_function_call(nopoll_conn_close);
will_return(nopoll_conn_ref_count, 1);
@@ -382,7 +409,7 @@ void test_createConnectionConnNotOk()
expect_function_call(nopoll_conn_unref);
expect_value(nopoll_conn_new_opts, (intptr_t)ctx, (intptr_t)ctx);
expect_string(nopoll_conn_new_opts, (intptr_t)host_ip, "localhost");
expect_string(nopoll_conn_new_opts, (intptr_t)host_ip, HOST_IP);
will_return(nopoll_conn_new_opts, (intptr_t)&gNPConn);
expect_function_call(nopoll_conn_new_opts);
@@ -393,13 +420,18 @@ void test_createConnectionConnNotOk()
will_return(nopoll_conn_wait_until_connection_ready, nopoll_false);
expect_function_call(nopoll_conn_wait_until_connection_ready);
will_return (strncmp, 1);
expect_function_call (strncmp);
will_return (strncmp, 0);
expect_function_call (strncmp);
expect_function_call(nopoll_conn_close);
will_return(nopoll_conn_ref_count, 0);
expect_function_call(nopoll_conn_ref_count);
expect_value(nopoll_conn_new_opts, (intptr_t)ctx, (intptr_t)ctx);
expect_string(nopoll_conn_new_opts, (intptr_t)host_ip, "localhost");
expect_string(nopoll_conn_new_opts, (intptr_t)host_ip, HOST_IP);
will_return(nopoll_conn_new_opts, (intptr_t)&gNPConn);
expect_function_call(nopoll_conn_new_opts);
@@ -427,24 +459,31 @@ void test_createConnectionConnRedirect()
assert_non_null(cfg);
cfg->flags = 0;
parStrncpy(cfg->webpa_url , "localhost", sizeof(cfg->webpa_url));
parStrncpy(cfg->webpa_url , UNSECURE_WEBPA_URL, sizeof(cfg->webpa_url));
set_parodus_cfg(cfg);
assert_non_null(ctx);
will_return (allow_insecure_conn, 1);
expect_function_call (allow_insecure_conn);
will_return (strncmp, 1);
expect_function_call (strncmp);
will_return (strncmp, 0);
expect_function_call (strncmp);
will_return(getWebpaConveyHeader, (intptr_t)"WebPA-1.6 (TG1682)");
expect_function_call(getWebpaConveyHeader);
expect_value(nopoll_conn_new_opts, (intptr_t)ctx, (intptr_t)ctx);
expect_string(nopoll_conn_new_opts, (intptr_t)host_ip, "localhost");
expect_string(nopoll_conn_new_opts, (intptr_t)host_ip, HOST_IP);
will_return(nopoll_conn_new_opts, (intptr_t)&gNPConn);
expect_function_call(nopoll_conn_new_opts);
will_return(nopoll_conn_is_ok, nopoll_false);
expect_function_call(nopoll_conn_is_ok);
will_return (strncmp, 1);
expect_function_call (strncmp);
will_return (strncmp, 0);
expect_function_call (strncmp);
expect_function_call(nopoll_conn_close);
will_return(nopoll_conn_ref_count, 1);
@@ -453,22 +492,25 @@ void test_createConnectionConnRedirect()
expect_function_call(nopoll_conn_unref);
expect_value(nopoll_conn_new_opts, (intptr_t)ctx, (intptr_t)ctx);
expect_string(nopoll_conn_new_opts, (intptr_t)host_ip, "localhost");
expect_string(nopoll_conn_new_opts, (intptr_t)host_ip, HOST_IP);
will_return(nopoll_conn_new_opts, (intptr_t)&gNPConn);
expect_function_call(nopoll_conn_new_opts);
will_return(nopoll_conn_is_ok, nopoll_true);
expect_function_call(nopoll_conn_is_ok);
setGlobalHttpStatus(307);
setGlobalRedirectUrl ("Redirect:http://10.0.0.12");
will_return(nopoll_conn_wait_until_connection_ready, nopoll_false);
expect_function_call(nopoll_conn_wait_until_connection_ready);
will_return(strtok, (intptr_t)"");
will_return(strtok, (intptr_t)"");
will_return(strtok, (intptr_t)"p.10.0.0.12");
will_return(strtok, (intptr_t)"8080");
expect_function_calls(strtok, 4);
will_return (strncmp, 0);
expect_function_call (strncmp);
will_return (strncmp, -1);
expect_function_call (strncmp);
will_return (strncmp, 0);
expect_function_call (strncmp);
expect_function_call(nopoll_conn_close);