Commit 9c6583fe authored by Ian Craggs's avatar Ian Craggs

Merge branch 'testcase-for-issue-190-without-serverURI' of…

Merge branch 'testcase-for-issue-190-without-serverURI' of https://github.com/JuergenKosel/paho.mqtt.c into fixes
parents eabca5bf 34e55007
...@@ -2,3 +2,4 @@ ...@@ -2,3 +2,4 @@
/build/ /build/
/build.paho/ /build.paho/
*.swp *.swp
/build.paho
...@@ -290,25 +290,31 @@ ADD_TEST( ...@@ -290,25 +290,31 @@ ADD_TEST(
) )
ADD_TEST( ADD_TEST(
NAME test5-3a-server-auth-server-cert-in-client-store NAME test5-2d-multual-ssl-auth-client-missing-client-cert
COMMAND test5 "--test_no" "5" "--hostname" ${MQTT_SSL_HOSTNAME} "--client_key" "${CERTDIR}/client.pem" "--server_key" "${CERTDIR}/test-root-ca.crt" COMMAND test5 "--test_no" "5" "--hostname" ${MQTT_SSL_HOSTNAME} "--client_key" "${CERTDIR}/client.pem" "--server_key" "${CERTDIR}/test-root-ca.crt"
) )
ADD_TEST( ADD_TEST(
NAME test5-3b-server-auth-client-missing-broker-cert NAME test5-3a-server-auth-server-cert-in-client-store
COMMAND test5 "--test_no" "6" "--hostname" ${MQTT_SSL_HOSTNAME} "--client_key" "${CERTDIR}/client.pem" "--server_key" "${CERTDIR}/test-root-ca.crt" COMMAND test5 "--test_no" "6" "--hostname" ${MQTT_SSL_HOSTNAME} "--client_key" "${CERTDIR}/client.pem" "--server_key" "${CERTDIR}/test-root-ca.crt"
) )
ADD_TEST( ADD_TEST(
NAME test5-4-accept-invalid-certificates NAME test5-3b-server-auth-client-missing-broker-cert
COMMAND test5 "--test_no" "7" "--hostname" ${MQTT_SSL_HOSTNAME} "--client_key" "${CERTDIR}/client.pem" "--server_key" "${CERTDIR}/test-root-ca.crt" COMMAND test5 "--test_no" "7" "--hostname" ${MQTT_SSL_HOSTNAME} "--client_key" "${CERTDIR}/client.pem" "--server_key" "${CERTDIR}/test-root-ca.crt"
) )
ADD_TEST(
NAME test5-4-accept-invalid-certificates
COMMAND test5 "--test_no" "8" "--hostname" ${MQTT_SSL_HOSTNAME} "--client_key" "${CERTDIR}/client.pem" "--server_key" "${CERTDIR}/test-root-ca.crt"
)
SET_TESTS_PROPERTIES( SET_TESTS_PROPERTIES(
test5-1-ssl-connection-to-no-SSL-server test5-1-ssl-connection-to-no-SSL-server
test5-2a-multual-ssl-auth-certificates-in-place test5-2a-multual-ssl-auth-certificates-in-place
test5-2b-multual-ssl-auth-broker-missing-client-cert test5-2b-multual-ssl-auth-broker-missing-client-cert
test5-2c-multual-ssl-auth-client-missing-broker-cert test5-2c-multual-ssl-auth-client-missing-broker-cert
test5-2d-multual-ssl-auth-client-missing-client-cert
test5-3a-server-auth-server-cert-in-client-store test5-3a-server-auth-server-cert-in-client-store
test5-3b-server-auth-client-missing-broker-cert test5-3b-server-auth-client-missing-broker-cert
test5-4-accept-invalid-certificates test5-4-accept-invalid-certificates
......
...@@ -1008,6 +1008,7 @@ int test2d(struct Options options) ...@@ -1008,6 +1008,7 @@ int test2d(struct Options options)
int rc = 0; int rc = 0;
char* test_topic = "C client test2d"; char* test_topic = "C client test2d";
int count = 0; int count = 0;
unsigned int iteration = 0;
failures = 0; failures = 0;
MyLog( MyLog(
...@@ -1016,19 +1017,24 @@ int test2d(struct Options options) ...@@ -1016,19 +1017,24 @@ int test2d(struct Options options)
fprintf(xml, "<testcase classname=\"test2d\" name=\"%s\"", testname); fprintf(xml, "<testcase classname=\"test2d\" name=\"%s\"", testname);
global_start_time = start_clock(); global_start_time = start_clock();
// As reported in https://github.com/eclipse/paho.mqtt.c/issues/190
// there is/was some race condition, which caused _sometimes_ that the library failed to detect,
// that the connect attempt has already failed.
// Therefore we need to test this several times!
for (iteration = 0; !failures && (iteration < 20) ; iteration++)
{
rc = MQTTAsync_create(&c, options.mutual_auth_connection, rc = MQTTAsync_create(&c, options.mutual_auth_connection,
"test2d", MQTTCLIENT_PERSISTENCE_DEFAULT, NULL); "test2d", MQTTCLIENT_PERSISTENCE_DEFAULT, NULL);
assert("good rc from create", rc == MQTTASYNC_SUCCESS, "rc was %d\n", rc); assert("good rc from create", rc == MQTTASYNC_SUCCESS, "rc was %d\n", rc);
if (rc != MQTTASYNC_SUCCESS) if (rc != MQTTASYNC_SUCCESS)
{ {
MQTTAsync_destroy(&c); MQTTAsync_destroy(&c);
goto exit; failures++;
break;
} }
opts.keepAliveInterval = 20; opts.keepAliveInterval = 60;
opts.cleansession = 1; opts.cleansession = 1;
opts.username = "testuser";
opts.password = "testpassword";
opts.will = &wopts; opts.will = &wopts;
opts.will->message = "will message"; opts.will->message = "will message";
...@@ -1041,30 +1047,40 @@ int test2d(struct Options options) ...@@ -1041,30 +1047,40 @@ int test2d(struct Options options)
opts.context = c; opts.context = c;
opts.ssl = &sslopts; opts.ssl = &sslopts;
//if (options.server_key_file != NULL) opts.ssl->trustStore = options.server_key_file; /*file of certificates trusted by client*/ if (options.server_key_file != NULL) opts.ssl->trustStore = options.server_key_file; /*file of certificates trusted by client*/
//opts.ssl->keyStore = options.client_key_file; /*file of certificate for client to present to server*/ opts.ssl->keyStore = NULL; /*file of certificate for client to present to server - In this test the client has no certificate! */
//if (options.client_key_pass != NULL) //if (options.client_key_pass != NULL)
// opts.ssl->privateKeyPassword = options.client_key_pass; // opts.ssl->privateKeyPassword = options.client_key_pass;
//opts.ssl->enabledCipherSuites = "DEFAULT"; //opts.ssl->enabledCipherSuites = "DEFAULT";
//opts.ssl->enabledServerCertAuth = 0; //opts.ssl->enabledServerCertAuth = 0;
test2dFinished = 0;
MyLog(LOGA_DEBUG, "Connecting"); MyLog(LOGA_DEBUG, "Connecting");
rc = MQTTAsync_connect(c, &opts); rc = MQTTAsync_connect(c, &opts);
assert("Good rc from connect", rc == MQTTASYNC_SUCCESS, "rc was %d", rc); assert("Good rc from connect", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
if (rc != MQTTASYNC_SUCCESS) if (rc != MQTTASYNC_SUCCESS)
{ {
failures++; failures++;
goto exit; MyLog(LOGA_INFO, "Failed in iteration %d\n",iteration);
MQTTAsync_destroy(&c);
break;
} }
#define TEST2D_COUNT 1000
while (!test2dFinished && ++count < 10000) while (!test2dFinished && ++count < TEST2D_COUNT)
{
#if defined(WIN32) #if defined(WIN32)
Sleep(100); Sleep(100);
#else #else
usleep(10000L); usleep(10000L);
#endif #endif
}
exit: MQTTAsync_destroy(&c); if (!test2dFinished && count >= TEST2D_COUNT)
{
MyLog(LOGA_INFO, "Failed in iteration %d\n",iteration);
failures++;
}
MQTTAsync_destroy(&c);
}
MyLog(LOGA_INFO, "%s: test %s. %d tests run, %d failures.", MyLog(LOGA_INFO, "%s: test %s. %d tests run, %d failures.",
(failures == 0) ? "passed" : "failed", testname, tests, failures); (failures == 0) ? "passed" : "failed", testname, tests, failures);
write_test_result(); write_test_result();
...@@ -2122,8 +2138,8 @@ int main(int argc, char** argv) ...@@ -2122,8 +2138,8 @@ int main(int argc, char** argv)
int* numtests = &tests; int* numtests = &tests;
int rc = 0; int rc = 0;
int (*tests[])() = int (*tests[])() =
{ NULL, test1, test2a, test2b, test2c, test3a, test3b, test4, /* test5a, { NULL, test1, test2a, test2b, test2c, test2d, test3a, test3b, test4, /* test5a,
test5b, test5c, */ test6, test7, test2d }; test5b, test5c, */ test6, test7 };
xml = fopen("TEST-test5.xml", "w"); xml = fopen("TEST-test5.xml", "w");
fprintf(xml, "<testsuite name=\"test5\" tests=\"%lu\">\n", ARRAY_SIZE(tests) - 1); fprintf(xml, "<testsuite name=\"test5\" tests=\"%lu\">\n", ARRAY_SIZE(tests) - 1);
...@@ -2157,3 +2173,8 @@ int main(int argc, char** argv) ...@@ -2157,3 +2173,8 @@ int main(int argc, char** argv)
return rc; return rc;
} }
/* Local Variables: */
/* indent-tabs-mode: t */
/* c-basic-offset: 8 */
/* End: */
...@@ -21,6 +21,7 @@ cafile test/tls-testing/keys/all-ca.crt ...@@ -21,6 +21,7 @@ cafile test/tls-testing/keys/all-ca.crt
certfile test/tls-testing/keys/server/server.crt certfile test/tls-testing/keys/server/server.crt
keyfile test/tls-testing/keys/server/server.key keyfile test/tls-testing/keys/server/server.key
require_certificate true require_certificate true
use_identity_as_username false
#tls_version tlsv1 #tls_version tlsv1
# server authentication - no client authentication # server authentication - no client authentication
......
...@@ -3,6 +3,8 @@ ...@@ -3,6 +3,8 @@
if [ "$TRAVIS_OS_NAME" == "linux" ]; then if [ "$TRAVIS_OS_NAME" == "linux" ]; then
pwd pwd
sudo service mosquitto stop sudo service mosquitto stop
# Stop any mosquitto instance which may be still running from previous runs
killall mosquitto
mosquitto -h mosquitto -h
mosquitto -c test/tls-testing/mosquitto.conf & mosquitto -c test/tls-testing/mosquitto.conf &
fi fi
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment