Exemplo n.º 1
1
void CreateDatabasesUnitTests::Test_CreateDatabases_SQLServer()
{
    AppSecInc::Msi::MsiShim hInstall;

    std::wstring testdatapath = AppSecInc::File::GetModuleDirectoryW() + L"\\TestData_DataSourceUnitTests";
    for each(const std::wstring& idtfile in AppSecInc::File::GetFiles(testdatapath, L"*.idt"))
    {
        std::wstring idtfile_name = AppSecInc::File::GetFileNameW(idtfile);
        std::wcout << std::endl << L" Importing \"" << idtfile_name << L"\"";
        hInstall.Import(testdatapath, idtfile_name);
    }

    AppSecInc::Msi::MsiInstall msiInstall(hInstall);
    std::wstring databasename = AppSecInc::Com::GenerateGUIDStringW();
    AppSecInc::StringUtils::lrtrim(databasename, L"{}");
    std::wcout << std::endl << L"Database: " << databasename;
    msiInstall.SetProperty(L"MSSQL_DATABASE_NAME", databasename);
	msiInstall.SetProperty(L"INSTALLLOCATION", AppSecInc::File::GetSpecialFolderPath(CSIDL_COMMON_APPDATA) + L"\\");

    AppSecInc::Xml::XmlDocument xml;

    CPPUNIT_ASSERT(ERROR_SUCCESS == hInstall.ExecuteCA(L"DataSource.dll", L"CreateDatabases_SQLServer_Immediate"));
    xml.LoadXml(msiInstall.GetProperty(L"CreateDatabases_SQLServer_Deferred_Install"));

    // two databases, both have create actions, one is checkIfExists
    CPPUNIT_ASSERT(2 == xml.SelectNodes(L"/MSSQLDatabases/MSSQLDatabase")->length);
    CPPUNIT_ASSERT(2 == xml.SelectNodes(L"/MSSQLDatabases/MSSQLDatabase[@actions='create']")->length);
    CPPUNIT_ASSERT(1 == xml.SelectNodes(L"/MSSQLDatabases/MSSQLDatabase[@checkIfExists='false']")->length);
    CPPUNIT_ASSERT(1 == xml.SelectNodes(L"/MSSQLDatabases/MSSQLDatabase[@checkIfExists='true']")->length);
    // only the first database has options, but each have two file specs
    CPPUNIT_ASSERT(1 == xml.SelectNodes(L"/MSSQLDatabases/MSSQLDatabase/MSSQLDatabaseOptions/MSSQLDatabaseOption")->length);
    CPPUNIT_ASSERT(4 == xml.SelectNodes(L"/MSSQLDatabases/MSSQLDatabase/MSSQLDatabaseFileSpecs/MSSQLDatabaseFileSpec")->length);

    // connection strings must be encrypted
    MSXML2::IXMLDOMNodeListPtr connectionStrings = xml.SelectNodes(L"/MSSQLDatabases/MSSQLDatabase/ConnectionString/text()");
    for (int i = 0; i < connectionStrings->length; i++)
    {
        std::wstring encrypted = StringUtils::mb2wc(StringUtils::bstr2mb(connectionStrings->item[i]->text));
        AppSecInc::Crypt::DPAPIImpl::UnProtect(encrypted); // Fails if input string is not encrypted
    }

    // create the databases
    msiInstall.SetProperty(L"CustomActionData", msiInstall.GetProperty(L"CreateDatabases_SQLServer_Deferred_Install"));
    CPPUNIT_ASSERT(ERROR_SUCCESS == hInstall.ExecuteCA(L"DataSource.dll", L"CreateDatabases_SQLServer_Deferred"));

    // check that both databases exist
    AppSecInc::Databases::MSSQL::MSSQLConnectionInfo connection_info;
    connection_info.SetIPAddress(L"localhost");
    AppSecInc::Databases::MSSQL::MSSQLDatabase database(connection_info);   
    database.Connect();
    // check the first database
    database.SetName(databasename);
    CPPUNIT_ASSERT(database.Exists());
    // check the second database
    database.SetName(databasename + L"2");
    CPPUNIT_ASSERT(database.Exists());

    // drop the created databases
    MSXML2::IXMLDOMNodePtr mssqldatabase_node;
    MSXML2::IXMLDOMNodeListPtr mssqldatabase_nodes = xml.SelectNodes(L"/MSSQLDatabases/MSSQLDatabase");
    while(NULL != (mssqldatabase_node = mssqldatabase_nodes->nextNode()))
        xml.SetAttribute(L"actions", L"drop", mssqldatabase_node); 

    msiInstall.SetProperty(L"CustomActionData", xml.GetXml());
    CPPUNIT_ASSERT(ERROR_SUCCESS == hInstall.ExecuteCA(L"DataSource.dll", L"CreateDatabases_SQLServer_Deferred"));
}
Exemplo n.º 2
0
void XmlDocumentUnitTests::testCreate()
{
	AppSecInc::Xml::XmlDocument xml;
    xml.LoadXml(L"<xml />");
    CPPUNIT_ASSERT(! xml.GetXml().empty());
    xml.Create();
    CPPUNIT_ASSERT(xml.GetXml().empty());
}
Exemplo n.º 3
0
void XmlDocumentUnitTests::testLoad() 
{ 
	std::wstring xmlfile = GetLocalFileLocation(L"store.xml");
	std::wcout << std::endl << L"Xml: " << xmlfile.c_str();
	AppSecInc::Xml::XmlDocument xml;
	xml.Load(xmlfile, CLSID_DOMDocument);
	CPPUNIT_ASSERT(AppSecInc::StringUtils::startsWith(xml.GetXml(), 
		L"<bookstore xmlns=\"http://www.lucernepublishing.com\">"));
}
Exemplo n.º 4
0
void CreateDatabasesUnitTests::Test_CreateDatabases_Access()
{
    AppSecInc::Msi::MsiShim hInstall;

    std::wstring testdatapath = AppSecInc::File::GetModuleDirectoryW() + L"\\TestData_DataSourceUnitTests";
    for each(const std::wstring& idtfile in AppSecInc::File::GetFiles(testdatapath, L"*.idt"))
    {
        std::wstring idtfile_name = AppSecInc::File::GetFileNameW(idtfile);
        std::wcout << std::endl << L" Importing \"" << idtfile_name << L"\"";
        hInstall.Import(testdatapath, idtfile_name);
    }

    AppSecInc::Msi::MsiInstall msiInstall(hInstall);
    std::wstring dbq = AppSecInc::File::DirectoryCombine(
        AppSecInc::File::GetTemporaryDirectoryW(),
        AppSecInc::Com::GenerateGUIDStringW() + L".dbq");
    std::wcout << std::endl << L"DBQ: " << dbq;
    msiInstall.SetProperty(L"ACCESS_DATABASE_DBQ", dbq);
	msiInstall.SetProperty(L"INSTALLLOCATION", AppSecInc::File::GetSpecialFolderPath(CSIDL_COMMON_APPDATA) + L"\\");

    AppSecInc::Xml::XmlDocument xml;

    CPPUNIT_ASSERT(ERROR_SUCCESS == hInstall.ExecuteCA(L"DataSource.dll", L"CreateDatabases_Access_Immediate"));
    xml.LoadXml(msiInstall.GetProperty(L"CreateDatabases_Access_Deferred_Install"));

    // two databases, both have create actions, one is checkIfExists
    CPPUNIT_ASSERT(1 == xml.SelectNodes(L"/AccessDatabases/AccessDatabase")->length);
    CPPUNIT_ASSERT(1 == xml.SelectNodes(L"/AccessDatabases/AccessDatabase[@actions='create']")->length);
    CPPUNIT_ASSERT(1 == xml.SelectNodes(L"/AccessDatabases/AccessDatabase[@checkIfExists='false']")->length);
    CPPUNIT_ASSERT(0 == xml.SelectNodes(L"/AccessDatabases/AccessDatabase[@checkIfExists='true']")->length);

    // connection strings must be encrypted
    MSXML2::IXMLDOMNodeListPtr connectionStrings = xml.SelectNodes(L"/AccessDatabases/AccessDatabase/ConnectionString/text()");
    for (int i = 0; i < connectionStrings->length; i++)
    {
        std::wstring encrypted = StringUtils::mb2wc(StringUtils::bstr2mb(connectionStrings->item[i]->text));
        AppSecInc::Crypt::DPAPIImpl::UnProtect(encrypted); // Fails if input string is not encrypted
    }

    // create the databases
    msiInstall.SetProperty(L"CustomActionData", msiInstall.GetProperty(L"CreateDatabases_Access_Deferred_Install"));
    CPPUNIT_ASSERT(ERROR_SUCCESS == hInstall.ExecuteCA(L"DataSource.dll", L"CreateDatabases_Access_Deferred"));

    // check that the database exists
    AppSecInc::Databases::Access::AccessDatabase database;
    database.SetDBQ(dbq);
    CPPUNIT_ASSERT(database.Exists());

    // drop the created databases
    MSXML2::IXMLDOMNodePtr Accessdatabase_node;
    MSXML2::IXMLDOMNodeListPtr Accessdatabase_nodes = xml.SelectNodes(L"/AccessDatabases/AccessDatabase");
    while(NULL != (Accessdatabase_node = Accessdatabase_nodes->nextNode()))
        xml.SetAttribute(L"actions", L"drop", Accessdatabase_node); 

    msiInstall.SetProperty(L"CustomActionData", xml.GetXml());
    CPPUNIT_ASSERT(ERROR_SUCCESS == hInstall.ExecuteCA(L"DataSource.dll", L"CreateDatabases_Access_Deferred"));
}
Exemplo n.º 5
0
void XmlDocumentUnitTests::testGetXml()
{
	std::wstring xmlfile = GetLocalFileLocation(L"store.xml");
	std::wcout << std::endl << L"Xml: " << xmlfile;
	AppSecInc::Xml::XmlDocument xml;
	xml.Load(xmlfile);
    std::wstring outerxml = xml.GetXml();
    CPPUNIT_ASSERT(! outerxml.empty());
    //! \todo read the file with File::ReadToEnd (implement) and compare data
}
Exemplo n.º 6
0
void XmlDocumentUnitTests::testSetAttribute()
{
	AppSecInc::Xml::XmlDocument xml;
    xml.Create();
    xml.AppendChild(L"xml");

    {
        xml.SetAttribute(L"name", L"value", xml.SelectNode(L"/xml"));
        std::wstring data = xml.GetXml();
        AppSecInc::StringUtils::lrtrim(data, L"\r\n");
        std::wcout << std::endl << data;
        CPPUNIT_ASSERT(data == L"<xml name=\"value\"/>");
    }
}
Exemplo n.º 7
0
void XmlDocumentUnitTests::testAppendChild()
{
	AppSecInc::Xml::XmlDocument xml;
    xml.Create();
    xml.AppendChild(L"xml");

    {
        std::wstring data = xml.GetXml();
        AppSecInc::StringUtils::lrtrim(data, L"\r\n");
        std::wcout << std::endl << data;
        CPPUNIT_ASSERT(! data.empty());
        CPPUNIT_ASSERT(data == L"<xml/>");
    }

    {
        xml.AppendChild(L"node", xml.SelectNode(L"/xml"));
        std::wstring data = xml.GetXml();
        AppSecInc::StringUtils::lrtrim(data, L"\r\n");
        std::wcout << std::endl << data;
        CPPUNIT_ASSERT(! data.empty());
        CPPUNIT_ASSERT(data == L"<xml><node/></xml>");
    }
}
Exemplo n.º 8
0
void AccessDatabaseUnitTests::testLoadSave()
{
    AccessDatabase database1;
    database1.SetDBQ(L"test");

    AppSecInc::Xml::XmlDocument doc;
    doc.Create();
    MSXML2::IXMLDOMNodePtr root = doc.AppendChild(L"Databases");
    MSXML2::IXMLDOMNodePtr database_root = database1.Save(doc, root);

    std::wcout << std::endl << doc.GetXml();

    AccessDatabase database2;
    database2.Load(doc, database_root);

    CPPUNIT_ASSERT(database2.GetDBQ() == database1.GetDBQ());
}