// xestiacalendar_caldav.h - Xestia Calendar CalDAV Object Unit Tests // // (c) 2016 Xestia Software Development. // // This file is part of Xestia Calendar. // // Xestia Address Book is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by the // Free Software Foundation, version 3 of the license. // // Xestia Address Book is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License along // with Xestia Calendar. If not, see #include "../objects/CalDAV/CalDAV.h" #include "xestiacalendar_testcommon.h" #include #include using namespace std; TEST(CalDAV, BasicTests){ CalDAVConnectionData ConnPlain; CalDAVConnectionData ConnNormal; CalDAVConnectionData ConnInvalidSSL; CalDAVConnectionData ConnTimeout; ProcessConnectionDataFileResult DataFileResult; bool ValidDataPlain = false; bool ValidDataNormal = false; bool ValidDataInvalidSSL = false; bool ValidDataTimeout = false; // Attempt to read the caldavtest-plain.auth file. DataFileResult = ProcessConnectionDataFile("caldavtest-plain.auth", &ConnPlain); if (DataFileResult == PROCESSCONNECTIONDATAFILE_OK){ ValidDataPlain = true; } // Attempt to read the caldavtest.auth file. DataFileResult = ProcessConnectionDataFile("caldavtest.auth", &ConnNormal); if (DataFileResult == PROCESSCONNECTIONDATAFILE_OK){ ValidDataNormal = true; } // Attempt to read the caldavtest-fail.auth file. DataFileResult = ProcessConnectionDataFile("caldavtest-fail.auth", &ConnInvalidSSL); if (DataFileResult == PROCESSCONNECTIONDATAFILE_OK){ ValidDataInvalidSSL = true; } // Attempt to read the caldavtest-timeout.auth file. DataFileResult = ProcessConnectionDataFile("caldavtest-fail.auth", &ConnTimeout); if (DataFileResult == PROCESSCONNECTIONDATAFILE_OK){ ValidDataTimeout = true; } if (ValidDataPlain == false){ // Cannot read the caldavtest-plain.auth file properly. cout << "The caldavtest-plain.auth file does not exist or is invalid!" << endl; cout << "Please create the caldavtest-plain.auth file using the following format:" << endl << endl; cout << "server=localname" << endl; cout << "port=8080" << endl; cout << "user=username" << endl; cout << "pass=password" << endl; cout << "ssl=false" << endl; cout << "prefix=/lalala/lookatme/thisisa/prefix" << endl << endl; } if (ValidDataNormal == false){ // Cannot read the caldavtest.auth file properly. cout << "The caldavtest.auth file does not exist or is invalid!" << endl; cout << "Please create the caldavtest.auth file using the following format:" << endl << endl; cout << "server=localname" << endl; cout << "port=8080" << endl; cout << "user=username" << endl; cout << "pass=password" << endl; cout << "ssl=false" << endl; cout << "prefix=/lalala/lookatme/thisisa/prefix" << endl << endl; } if (ValidDataInvalidSSL == false){ // Cannot read the caldavtest-fail.auth file properly. cout << "The caldavtest-fail.auth file does not exist or is invalid!" << endl; cout << "Please create the caldavtest-fail.auth file using the following format:" << endl << endl; cout << "server=fail.localname" << endl; cout << "port=8080" << endl; cout << "user=username" << endl; cout << "pass=password" << endl; cout << "ssl=false" << endl; cout << "prefix=/lalala/lookatme/thisisa/prefix" << endl << endl; } if (ValidDataTimeout == false){ // Cannot read the caldavtest-timeout.auth file properly. cout << "The caldavtest-timeout.auth file does not exist or is invalid!" << endl; cout << "Please create the caldavtest-timeout.auth file using the following format:" << endl << endl; cout << "server=fail.localname" << endl; cout << "port=8080" << endl; cout << "user=username" << endl; cout << "pass=password" << endl; cout << "ssl=false" << endl; cout << "prefix=/lalala/lookatme/thisisa/prefix" << endl << endl; } ASSERT_EQ(true, ValidDataPlain); ASSERT_EQ(true, ValidDataNormal); ASSERT_EQ(true, ValidDataInvalidSSL); ASSERT_EQ(true, ValidDataTimeout); // (*nix version) Setup an initial connection (just plain // text). CalDAV CalDAVPlain; CalDAVPlain.SetupConnectionData(&ConnPlain); // Verify that the settings match with the CalDAVConnectionData // passed. CalDAVStatus CalDAVPlainStatus = CalDAVPlain.GetConnectionData(); ASSERT_EQ(CalDAVPlainStatus.Hostname, ConnPlain.Hostname); ASSERT_EQ(CalDAVPlainStatus.Username, ConnPlain.Username); ASSERT_EQ(CalDAVPlainStatus.Port, ConnPlain.Port); ASSERT_EQ(CalDAVPlainStatus.Prefix, ConnPlain.Prefix); ASSERT_EQ(CalDAVPlainStatus.UseSSL, ConnPlain.UseSSL); // Verify that the connection was successful. CalDAVServerResult ConnResult = CalDAVPlain.Connect(); ASSERT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result); ASSERT_EQ(200, ConnResult.HTTPCode); ASSERT_EQ(CURLE_OK, ConnResult.Code); // Do another connection and this time the connection should // fail due to being an invalid host name. CalDAVConnectionData ConnPlainFail; ConnPlainFail.Hostname = "server.invalid"; ConnPlainFail.Username = "fail"; ConnPlainFail.Password = "fail"; ConnPlainFail.Port = 80; ConnPlainFail.UseSSL = false; // Setup the CalDAV connection object. CalDAV CalDAVPlainFail; CalDAVPlainFail.SetupConnectionData(&ConnPlainFail); // Setup the CalDAVStatus object. CalDAVStatus CalDAVPlainFailStatus = CalDAVPlain.GetConnectionData(); // Connect and fail. ConnResult = CalDAVPlainFail.Connect(); ASSERT_EQ(CALDAVQUERYRESULT_SERVERERROR, ConnResult.Result); ASSERT_EQ(0, ConnResult.HTTPCode); ASSERT_EQ(CURLE_COULDNT_RESOLVE_HOST, ConnResult.Code); // (*nix version) Setup an initial connection (with a valid // SSL certificate). CalDAV CalDAVNormal; CalDAVNormal.SetupConnectionData(&ConnNormal); // Verify that the settings match with the CalDAVConnectionData // passed. CalDAVStatus CalDAVNormalStatus = CalDAVNormal.GetConnectionData(); ASSERT_EQ(CalDAVNormalStatus.Hostname, ConnNormal.Hostname); ASSERT_EQ(CalDAVNormalStatus.Username, ConnNormal.Username); ASSERT_EQ(CalDAVNormalStatus.Port, ConnNormal.Port); ASSERT_EQ(CalDAVNormalStatus.Prefix, ConnNormal.Prefix); ASSERT_EQ(CalDAVNormalStatus.UseSSL, ConnNormal.UseSSL); // Verify that the connection was successful (with a valid // SSL certificate). ConnResult = CalDAVNormal.Connect(); ASSERT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result); ASSERT_EQ(200, ConnResult.HTTPCode); ASSERT_EQ(CURLE_OK, ConnResult.Code); // (*nix version) Setup an initial connection on a server that // will fail due to having an invalid SSL certificate. // Verify that the connection had failed. (with an invalid // SSL certificate). // (*nix version) Setup an inital connection on a server where // a timeout occurs. // Verify that the connection had timed out. }