.travis.yml
@@ -92,6 +92,22 @@ "cd /root/open-license-manager/build && make && make install && VIRT_ENV=CONTAINER make test" - os: linux dist: bionic name: "CentOS-8 Docker" before_script: - docker run --name centos8_toconfigure -v `pwd`:/root/open-license-manager centos:centos8 /bin/bash -c \ "yum -y update && yum -y groupinstall 'Development Tools' && yum -y install wget cmake boost boost-devel openssl-devel zlib-devel && dnf -y --enablerepo=PowerTools install boost-static && wget https://github.com/openssl/openssl/archive/OpenSSL_1_1_1d.tar.gz && tar xzf OpenSSL_1_1_1d.tar.gz && cd openssl-OpenSSL_1_1_1d && ./config && make -j 8 && make install && cd /root/lcc-license-manager/build && cmake .." - docker commit centos8_toconfigure centos8_configured script: - docker run --name centos8_make -v `pwd`:/root/open-license-manager centos8_configured /bin/bash -c \ "cd /root/open-license-manager/build && make && make install && VIRT_ENV=CONTAINER make test" - os: linux dist: bionic name: "Ubuntu 18.04 - MinGW cross-compile for Windows x64" env: - CTEST_OUTPUT_ON_FAILURE=1 README.md
@@ -7,14 +7,12 @@ [](https://opensource.org/licenses/BSD-3-Clause) [](https://travis-ci.org/open-license-manager/open-license-manager) [](https://www.codacy.com/manual/gcontini/open-license-manager?utm_source=github.com&utm_medium=referral&utm_content=open-license-manager/open-license-manager&utm_campaign=Badge_Grade) [)](http://github.com/open-license-manager/open-license-manager/issues) [](http://github.com/open-license-manager/open-license-manager/issues) It allows to protect the software you develop from unauthorized copies, limit the usage in time, to a specific set of machines, or prevent the usage in virtualized environments. It is an Open License Manager that helps to keep your software closed :smirk: . A comprehensive [list of features](https://github.com/open-license-manager/open-license-manager/wiki/features), and their status is available in the project wiki. ** Warning! documentation outdated. We're in process of releasing the 2.0.0 verision that include a large update. Documentation still refers to 1.1.x series. In case of doubts look to .travis.yml file for hints on how to build the library. ** ## License The project is donated to the community. It comes with a very large freedom of use for everyone, and it will always be. @@ -22,27 +20,30 @@ ## Project Structure The software is made by 2 main sub-components: * a C++ library with a nice C api, `licensecc` with minimal (or no) external dependencies (the part you have to integrate in your software). * a C++ library with a nice C api, `licensecc` with minimal (or no) external dependencies (the part you have to integrate in your software) that is the project you're currently in. * a license generator lcc-license-generator `lcc` for customizing the library and generate the licenses. these modules are planned.... The following modules are planned... * a license [backoffice](../../issues/7) in php (in order to handle multiple licenses). * a license debugger to be sent to the final customer when there are licensing problems. * a [log descriptor](../../issues/8) in order to decrypt logs generated by the license system. # How to build Below an overview of the basic build procedure, you can find [detailed instructions](https://github.com/open-license-manager/open-license-manager/wiki/Build-the-library) for your environment in the wiki. Below an overview of the basic build procedure, you can find detailed instructions for [linux](https://github.com/open-license-manager/open-license-manager/wiki/Build-the-library) or [windows](https://github.com/open-license-manager/open-license-manager/wiki/Build-the-library-win) in the wiki. ## prerequisites * Operating system: Linux(Ubuntu, CentOS), Windows * compilers: GCC (Linux) MINGW (Linux cross compile for Windows), MINGW or MSVC (Windows) * tools : cmake, git, make/ninja(linux) * libs : If target is linux Openssl is required. Windows depends only on system libraries. Boost is necessary to build license generator and to run the tests but it's NOT a dependency of the `licensecc` library. * tools : cmake(>3.6), git, make/ninja(linux) * libs : If target is linux Openssl is required. Windows depends only on system libraries. Boost is necessary to build license generator and to run the tests but it's NOT a dependency of the final `licensecc` library. For a complete list of dependencies and supported environments see [the wiki](https://github.com/open-license-manager/open-license-manager/wiki/Dependencies) Clone the project. It has submodules, don't forget the `--recursive` option. ``` git clone https://github.com/open-license-manager/open-license-manager.git git clone --recursive https://github.com/open-license-manager/open-license-manager.git cd open-license-manager/ mkdir build cd build ``` cmake/Findlcc.cmake
@@ -46,7 +46,8 @@ find_package(PkgConfig) if(LCC_LOCATION) # First search the PATH and specific locations. find_package(lcc HINTS ${LCC_LOCATION} CONFIG) #try to find it without looping on this module if(NOT lcc_FOUND) find_program(LCC_EXECUTABLE NAMES ${lcc_names} HINTS ${LCC_LOCATION} DOC "lcc command line client") FIND_PACKAGE_HANDLE_STANDARD_ARGS(lcc FOUND_VAR LCC_FOUND @@ -54,6 +55,7 @@ FAIL_MESSAGE "Error finding lcc executable. variable LCC_LOCATION non set correctly.") add_executable(license_generator::lcc IMPORTED GLOBAL) set_property(TARGET license_generator::lcc PROPERTY IMPORTED_LOCATION ${LCC_EXECUTABLE}) ENDIF(NOT lcc_FOUND) ELSE(LCC_LOCATION) find_package(lcc HINTS ${CMAKE_BINARY_DIR} CONFIG) #try to find it without looping on this module @@ -76,6 +78,7 @@ set(failure_messge "All the options to find lcc executable failed. And i can't compile one from source GIT_SUBMODULE was turned off or failed. Please update submodules and try again.") endif() add_subdirectory("${PROJECT_SOURCE_DIR}/extern/license-generator") set(lcc_FOUND TRUE) ENDIF(NOT lcc_FOUND) ENDIF(LCC_LOCATION) extern/license-generator
@@ -1 +1 @@ Subproject commit 33b74eb3fcf786dcf1a2f53b038917437cbeb8cd Subproject commit c40c0951e77c012a1c4043182c88ae5fe185efea src/library/LicenseReader.cpp
@@ -44,7 +44,6 @@ LicenseReader::LicenseReader(const LicenseLocation *licenseLocation) : licenseLocation(licenseLocation) {} EventRegistry LicenseReader::readLicenses(const string &product, vector<FullLicenseInfo> &licenseInfoOut) const { vector<string> diskFiles; vector<unique_ptr<locate::LocatorStrategy>> locator_strategies; FUNCTION_RETURN ret = locate::LocatorFactory::get_active_strategies(locator_strategies, licenseLocation); EventRegistry eventRegistry; src/library/base/logger.c
@@ -26,7 +26,7 @@ static void getLogFname(char* logpath) { #ifdef __unix__ char const *folder = getenv("TMPDIR"); const char *folder = getenv("TMPDIR"); if (folder == 0) { folder = "/tmp"; } @@ -42,10 +42,10 @@ } void _log(const char* format, ...) { char logpath[MAX_PATH]; va_list args; char * buffer; if (logFile == NULL) { char logpath[MAX_PATH]; getLogFname(logpath); logFile = fopen(logpath, "a"); if (logFile == NULL) { src/library/licensecc.cpp
@@ -23,9 +23,9 @@ void print_error(char out_buffer[256], LicenseInfo* licenseInfo) {} bool identify_pc(IDENTIFICATION_STRATEGY pc_id_method, char* chbuffer, size_t bufSize) { PcSignature identifier_out; FUNCTION_RETURN result = FUNC_RET_BUFFER_TOO_SMALL; if (bufSize >= sizeof(PcSignature)) { PcSignature identifier_out; result = generate_user_pc_signature(identifier_out, pc_id_method); strncpy(chbuffer, identifier_out, bufSize); } src/library/locate/ApplicationFolder.cpp
@@ -7,8 +7,10 @@ #include <fstream> #include <sstream> #include <string> #include <iostream> #include <licensecc/datatypes.h> #include <licensecc_properties.h> #include "../base/logger.h" #include "../base/base.h" @@ -16,7 +18,6 @@ #include "../base/FileUtils.hpp" #include "../os/os.h" #include "ApplicationFolder.hpp" #include <iostream> namespace license { namespace locate { @@ -32,7 +33,7 @@ const FUNCTION_RETURN fret = getModuleName(fname); if (fret == FUNC_RET_OK) { const string module_name = remove_extension(fname); const string temptativeLicense = string(module_name) + ".lic"; const string temptativeLicense = string(module_name) + LICENSE_FILE_EXTENSION; ifstream f(temptativeLicense.c_str()); if (f.good()) { diskFiles.push_back(temptativeLicense); src/library/locate/LocatorFactory.cpp
@@ -5,8 +5,6 @@ * Author: Gabriele Contini */ #include "licensecc_properties.h" #include "LocatorStrategy.hpp" #include "LocatorFactory.hpp" #include "ApplicationFolder.hpp" @@ -16,16 +14,19 @@ namespace license { namespace locate { static std::vector<std::unique_ptr<LocatorStrategy>> extra_strategies; bool LocatorFactory::find_license_near_moduleb = FIND_LICENSE_NEAR_MODULE; bool LocatorFactory::find_license_with_env_varb = FIND_LICENSE_WITH_ENV_VAR; FUNCTION_RETURN LocatorFactory::get_active_strategies(std::vector<std::unique_ptr<LocatorStrategy>> &strategies, const LicenseLocation *locationHint) { #if (FIND_LICENSE_NEAR_MODULE) if (find_license_near_moduleb) { strategies.push_back(std::unique_ptr<LocatorStrategy>((LocatorStrategy *)new ApplicationFolder())); #endif #if (FIND_LICENSE_WITH_ENV_VAR) } if (find_license_with_env_varb) { strategies.push_back(std::unique_ptr<LocatorStrategy>((LocatorStrategy *)new EnvironmentVarLocation())); strategies.push_back(std::unique_ptr<LocatorStrategy>((LocatorStrategy *)new EnvironmentVarData())); #endif } if (locationHint != nullptr) { strategies.push_back(std::unique_ptr<LocatorStrategy>((LocatorStrategy *)new ExternalDefinition(locationHint))); } src/library/locate/LocatorFactory.hpp
@@ -5,6 +5,7 @@ #include <string> #include <vector> #include <licensecc/datatypes.h> #include <licensecc_properties.h> #include "../base/base.h" #include "LocatorStrategy.hpp" @@ -14,16 +15,18 @@ class LocatorFactory { private: static bool find_license_near_moduleb; static bool find_license_with_env_varb; inline LocatorFactory() { } inline ~LocatorFactory() { } public: static FUNCTION_RETURN get_active_strategies( std::vector<std::unique_ptr<LocatorStrategy>> &strategiesOut, const LicenseLocation *locationHint); static void find_license_near_module(bool enable) { find_license_near_moduleb = enable; } static void find_license_with_env_var(bool enable) { find_license_with_env_varb = enable; } }; } src/library/os/CMakeLists.txt
@@ -1,6 +1,3 @@ target_sources(licensecc_static PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/os.c) IF(UNIX OR OPENSSL_FOUND) IF(UNIX) target_sources(licensecc_static PRIVATE src/library/os/os-linux.c
@@ -22,8 +22,7 @@ *@param uuid uuid as read in /dev/disk/by-uuid *@param buffer_out: unsigned char buffer[8] output buffer for result */ static void parseUUID(const char *uuid, unsigned char *buffer_out, unsigned int out_size) { static void parseUUID(const char *uuid, unsigned char *buffer_out, unsigned int out_size) { size_t len; unsigned int i, j; char *hexuuid; @@ -93,12 +92,9 @@ currentDrive = 0; while (NULL != (ent = getmntent(aFile))) { if ((strncmp(ent->mnt_type, "ext", 3) == 0 || strncmp(ent->mnt_type, "xfs", 3) == 0 || strncmp(ent->mnt_type, "vfat", 4) == 0 || strncmp(ent->mnt_type, "ntfs", 4) == 0) && ent->mnt_fsname != NULL && strncmp(ent->mnt_fsname, "/dev/", 5) == 0) { if ((strncmp(ent->mnt_type, "ext", 3) == 0 || strncmp(ent->mnt_type, "xfs", 3) == 0 || strncmp(ent->mnt_type, "vfat", 4) == 0 || strncmp(ent->mnt_type, "ntfs", 4) == 0) && ent->mnt_fsname != NULL && strncmp(ent->mnt_fsname, "/dev/", 5) == 0) { if (stat(ent->mnt_fsname, &mount_stat) == 0) { drive_found = -1; for (i = 0; i < currentDrive; i++) { @@ -109,8 +105,7 @@ if (drive_found == -1) { LOG_DEBUG("mntent: %s %s %d\n", ent->mnt_fsname, ent->mnt_dir, (unsigned long int)mount_stat.st_ino); strncpy(tmpDrives[currentDrive].device, ent->mnt_fsname, 255 - 1); strncpy(tmpDrives[currentDrive].device, ent->mnt_fsname, 255 - 1); statDrives[currentDrive] = mount_stat.st_ino; drive_found = currentDrive; currentDrive++; @@ -144,17 +139,12 @@ if (stat(cur_dir, &sym_stat) == 0) { for (i = 0; i < currentDrive; i++) { if (sym_stat.st_ino == statDrives[i]) { parseUUID(dir->d_name, tmpDrives[i].disk_sn, sizeof(tmpDrives[i].disk_sn)); parseUUID(dir->d_name, tmpDrives[i].disk_sn, sizeof(tmpDrives[i].disk_sn)); #ifdef _DEBUG VALGRIND_CHECK_VALUE_IS_DEFINED(tmpDrives[i].device); LOG_DEBUG("uuid %d %s %02x%02x%02x%02x\n", i, tmpDrives[i].device, tmpDrives[i].disk_sn[0], tmpDrives[i].disk_sn[1], tmpDrives[i].disk_sn[2], tmpDrives[i].disk_sn[3]); LOG_DEBUG("uuid %d %s %02x%02x%02x%02x\n", i, tmpDrives[i].device, tmpDrives[i].disk_sn[0], tmpDrives[i].disk_sn[1], tmpDrives[i].disk_sn[2], tmpDrives[i].disk_sn[3]); #endif } } @@ -171,8 +161,7 @@ for (i = 0; i < currentDrive; i++) { if (sym_stat.st_ino == statDrives[i]) { strncpy(tmpDrives[i].label, dir->d_name, 255 - 1); printf("label %d %s %s\n", i, tmpDrives[i].label, tmpDrives[i].device); printf("label %d %s %s\n", i, tmpDrives[i].label, tmpDrives[i].device); } } } @@ -202,19 +191,15 @@ return result; } void os_initialize() { } void os_initialize() {} static void _getCpuid(unsigned int *p, unsigned int ax) { __asm __volatile ( "movl %%ebx, %%esi\n\t" __asm __volatile( "movl %%ebx, %%esi\n\t" "cpuid\n\t" "xchgl %%ebx, %%esi" : "=a" (p[0]), "=S" (p[1]), "=c" (p[2]), "=d" (p[3]) : "0" (ax) ); : "=a"(p[0]), "=S"(p[1]), "=c"(p[2]), "=d"(p[3]) : "0"(ax)); } FUNCTION_RETURN getCpuId(unsigned char identifier[6]) { @@ -266,9 +251,7 @@ } //0=NO 1=Docker/Lxc static int checkLXC() { return (access("/var/run/systemd/container",F_OK)==0) ? 1:0; } static int checkLXC() { return (access("/var/run/systemd/container", F_OK) == 0) ? 1 : 0; } VIRTUALIZATION getVirtualization() { VIRTUALIZATION result = NONE; src/library/os/os.c
File was deleted src/templates/licensecc_properties.h.in
@@ -4,9 +4,10 @@ #define LCC_PROJECT_NAME "@LCC_PROJECT_NAME@" //License retrieval configuration #define FIND_LICENSE_NEAR_MODULE 1 #define FIND_LICENSE_WITH_ENV_VAR 0 #define FIND_LICENSE_NEAR_MODULE true #define FIND_LICENSE_WITH_ENV_VAR false #define LICENSE_FILE_EXTENSION ".lic" #define LICENSE_LOCATION_ENV_VAR "LICENSE_LOCATION" #define LICENSE_DATA_ENV_VAR "LICENSE_DATA" src/templates/licensecc_properties_test.h.in
@@ -19,7 +19,7 @@ * command line parameters */ #define PARAM_BASE64 "base64" #define PARAM_LICENSE_NAME "license-name" #define PARAM_LICENSE_OUTPUT "output-file-name" #define PARAM_PRODUCT_NAME "product-name" #define PARAM_PROJECT_FOLDER "project-folder" #define PARAM_PRIMARY_KEY "primary-key" test/functional/generate-license.cpp
@@ -37,7 +37,7 @@ stringstream ss; ss << LCC_EXE << " license issue"; ss << " --" PARAM_PRIMARY_KEY " " << LCC_PROJECT_PRIVATE_KEY; ss << " --" PARAM_LICENSE_NAME " " << license_name; ss << " --" PARAM_LICENSE_OUTPUT " " << license_fname_s; ss << " --" PARAM_PROJECT_FOLDER " " << LCC_TEST_LICENSES_PROJECT; for (int i = 0; i < other_args.size(); i++) { test/functional/standard-license_test.cpp
@@ -17,7 +17,10 @@ using namespace license; using namespace std; BOOST_AUTO_TEST_CASE( standard_lic_file ) { /** * Test a generic license with no expiry neither client id. */ BOOST_AUTO_TEST_CASE(test_generic_license) { const vector<string> extraArgs; const string licLocation = generate_license("standard_license", extraArgs); /* */ test/library/LicenseLocator_test.cpp
@@ -30,12 +30,9 @@ static boost::optional<path> find_file(const path& dir_path, const path& file_name) { const recursive_directory_iterator end; const auto it = find_if(recursive_directory_iterator(dir_path), end, [&file_name](const directory_entry& e) { return e.path().filename() == file_name; }); [&file_name](const directory_entry &e) { return e.path().filename() == file_name; }); return it == end ? boost::optional<path>() : it->path(); } /***************************************************************************** * Application Folder tests @@ -51,7 +48,8 @@ exeFileFound = exeLocation.has_value(); if (exeFileFound) { referenceExeFileName = exeLocation.get().string(); referenceLicenseFileName = referenceExeFileName.replace(referenceExeFileName.find(BOOST_TEST_MODULE ".exe"), referenceLicenseFileName = referenceExeFileName.replace(referenceExeFileName.find(BOOST_TEST_MODULE ".exe"), string(BOOST_TEST_MODULE ".exe").size(), BOOST_TEST_MODULE ".lic"); } #else @@ -76,13 +74,10 @@ string currentLocation = licenseInfos[0]; BOOST_CHECK_MESSAGE(equivalent(path(referenceLicenseFileName),path(currentLocation)), "file " +currentLocation + "found at expected location"); string licenseRealContent = applicationFolder.retrieve_license_content( currentLocation); string licenseRealContent = applicationFolder.retrieve_license_content(currentLocation); src.seekg(0, ios::beg); std::string referenceContent((std::istreambuf_iterator<char>(src)), std::istreambuf_iterator<char>()); BOOST_CHECK_MESSAGE(referenceContent.compare(licenseRealContent) == 0, "File content is same"); std::string referenceContent((std::istreambuf_iterator<char>(src)), std::istreambuf_iterator<char>()); BOOST_CHECK_MESSAGE(referenceContent.compare(licenseRealContent) == 0, "File content is same"); remove(referenceLicenseFileName.c_str()); } } @@ -93,13 +88,11 @@ BOOST_AUTO_TEST_CASE( external_definition ) { //an application can define multiple license locations separated by ';' const char *applicationDefinedString = MOCK_LICENSE ";/this/one/doesnt/exist"; const char *applicationDefinedString = MOCK_LICENSE ";/this/one/doesnt/exist"; //read test license std::ifstream src(MOCK_LICENSE, std::ios::binary); std::string referenceContent((std::istreambuf_iterator<char>(src)), std::istreambuf_iterator<char>()); std::string referenceContent((std::istreambuf_iterator<char>(src)), std::istreambuf_iterator<char>()); license::EventRegistry registry; const LicenseLocation licLocation={applicationDefinedString,nullptr}; ExternalDefinition externalDefinition(&licLocation); @@ -107,12 +100,9 @@ BOOST_CHECK(registry.isGood()); BOOST_CHECK_EQUAL(1, licenseInfos.size()); string currentLocation = licenseInfos[0]; BOOST_CHECK_MESSAGE(string(MOCK_LICENSE).compare(currentLocation) == 0, "file found at expected location"); string licenseRealContent = externalDefinition.retrieve_license_content( currentLocation); BOOST_CHECK_MESSAGE(referenceContent.compare(licenseRealContent) == 0, "File content is same"); BOOST_CHECK_MESSAGE(string(MOCK_LICENSE).compare(currentLocation) == 0, "file found at expected location"); string licenseRealContent = externalDefinition.retrieve_license_content(currentLocation); BOOST_CHECK_MESSAGE(referenceContent.compare(licenseRealContent) == 0, "File content is same"); } /** @@ -125,15 +115,11 @@ ExternalDefinition externalDefinition(&licLocation); vector<string> licenseInfos = externalDefinition.license_locations(registry); BOOST_CHECK_MESSAGE(registry.isGood(), "No fatal error for now, only warnings"); BOOST_CHECK_MESSAGE(registry.isGood(), "No fatal error for now, only warnings"); registry.turnWarningsIntoErrors(); BOOST_REQUIRE_MESSAGE(!registry.isGood(), "Error detected"); BOOST_CHECK_EQUAL(0, licenseInfos.size()); BOOST_CHECK_MESSAGE( registry.getLastFailure()->event_type == LICENSE_FILE_NOT_FOUND, "Error detected"); BOOST_CHECK_MESSAGE(registry.getLastFailure()->event_type == LICENSE_FILE_NOT_FOUND, "Error detected"); } /***************************************************************************** @@ -141,8 +127,7 @@ *****************************************************************************/ BOOST_AUTO_TEST_CASE( environment_var_location ) { //an application can define multiple license locations separated by ';' const char *environment_variable_value = MOCK_LICENSE ";/this/one/doesnt/exist"; const char *environment_variable_value = MOCK_LICENSE ";/this/one/doesnt/exist"; #ifdef _WIN32 _putenv_s(LICENSE_LOCATION_ENV_VAR, environment_variable_value); #else @@ -150,22 +135,17 @@ #endif //read test license std::ifstream src(MOCK_LICENSE, std::ios::binary); std::string referenceContent((std::istreambuf_iterator<char>(src)), std::istreambuf_iterator<char>()); std::string referenceContent((std::istreambuf_iterator<char>(src)), std::istreambuf_iterator<char>()); license::EventRegistry registry; EnvironmentVarLocation envVarLocationStrategy; vector<string> licenseInfos = envVarLocationStrategy.license_locations( registry); vector<string> licenseInfos = envVarLocationStrategy.license_locations(registry); BOOST_CHECK(registry.isGood()); BOOST_CHECK_EQUAL(1, licenseInfos.size()); string currentLocation = licenseInfos[0]; BOOST_CHECK_MESSAGE(string(MOCK_LICENSE).compare(currentLocation) == 0, "file found at expected location"); string licenseRealContent = envVarLocationStrategy.retrieve_license_content( currentLocation); BOOST_CHECK_MESSAGE(referenceContent.compare(licenseRealContent) == 0, "File content is same"); BOOST_CHECK_MESSAGE(string(MOCK_LICENSE).compare(currentLocation) == 0, "file found at expected location"); string licenseRealContent = envVarLocationStrategy.retrieve_license_content(currentLocation); BOOST_CHECK_MESSAGE(referenceContent.compare(licenseRealContent) == 0, "File content is same"); UNSETENV(LICENSE_LOCATION_ENV_VAR); } @@ -173,22 +153,17 @@ * The license file doesn't exist. Check that the locator reports the right error */ BOOST_AUTO_TEST_CASE( environment_var_location_not_found ) { const char *environment_variable_value = PROJECT_TEST_SRC_DIR "/this/file/doesnt/exist"; const char *environment_variable_value = PROJECT_TEST_SRC_DIR "/this/file/doesnt/exist"; SETENV(LICENSE_LOCATION_ENV_VAR, environment_variable_value); license::EventRegistry registry; EnvironmentVarLocation envVarLocationStrategy; vector<string> licenseInfos = envVarLocationStrategy.license_locations( registry); BOOST_CHECK_MESSAGE(registry.isGood(), "No fatal error for now, only warnings"); vector<string> licenseInfos = envVarLocationStrategy.license_locations(registry); BOOST_CHECK_MESSAGE(registry.isGood(), "No fatal error for now, only warnings"); registry.turnWarningsIntoErrors(); BOOST_REQUIRE_MESSAGE(!registry.isGood(), "Error detected"); BOOST_CHECK_EQUAL(0, licenseInfos.size()); BOOST_CHECK_MESSAGE( registry.getLastFailure()->event_type == LICENSE_FILE_NOT_FOUND, "Error detected"); BOOST_CHECK_MESSAGE(registry.getLastFailure()->event_type == LICENSE_FILE_NOT_FOUND, "Error detected"); UNSETENV(LICENSE_LOCATION_ENV_VAR); } @@ -199,18 +174,13 @@ UNSETENV(LICENSE_LOCATION_ENV_VAR); license::EventRegistry registry; EnvironmentVarLocation environmentVarLocation; vector<string> licenseInfos = environmentVarLocation.license_locations( registry); vector<string> licenseInfos = environmentVarLocation.license_locations(registry); BOOST_CHECK_MESSAGE(registry.isGood(), "No fatal error for now, only warnings"); BOOST_CHECK_MESSAGE(registry.isGood(), "No fatal error for now, only warnings"); registry.turnWarningsIntoErrors(); BOOST_REQUIRE_MESSAGE(!registry.isGood(), "Error detected"); BOOST_CHECK_EQUAL(0, licenseInfos.size()); BOOST_CHECK_MESSAGE( registry.getLastFailure()->event_type == ENVIRONMENT_VARIABLE_NOT_DEFINED, "Error detected"); BOOST_CHECK_MESSAGE(registry.getLastFailure()->event_type == ENVIRONMENT_VARIABLE_NOT_DEFINED, "Error detected"); } } //namespace test test/library/LicenseReader_test.cpp
@@ -11,13 +11,15 @@ #include "../../src/library/base/EventRegistry.h" #include "../../src/library/os/os.h" #include "../../src/library/locate/LocatorFactory.hpp" #include "../../src/library/LicenseReader.hpp" namespace license { namespace test { using namespace license; using namespace std; /** * Read license at fixed location * Read license at application provided location */ BOOST_AUTO_TEST_CASE(read_single_file) { const char *licLocation = PROJECT_TEST_SRC_DIR "/library/test_reader.ini"; @@ -50,7 +52,9 @@ */ BOOST_AUTO_TEST_CASE(file_not_found) { const char *licLocation = PROJECT_TEST_SRC_DIR "/library/not_found.ini"; // const char * envName = "MYVAR"; locate::LocatorFactory::find_license_near_module(false); locate::LocatorFactory::find_license_with_env_var(false); const LicenseLocation location = {licLocation, nullptr}; LicenseReader licenseReader(&location); vector<FullLicenseInfo> licenseInfos; @@ -67,14 +71,15 @@ BOOST_AUTO_TEST_CASE(env_var_not_defined) { UNSETENV(LICENSE_LOCATION_ENV_VAR); const LicenseLocation location = {nullptr, nullptr}; locate::LocatorFactory::find_license_near_module(false); locate::LocatorFactory::find_license_with_env_var(true); LicenseReader licenseReader(&location); vector<FullLicenseInfo> licenseInfos; const EventRegistry registry = licenseReader.readLicenses("PRODUCT", licenseInfos); BOOST_CHECK(!registry.isGood()); BOOST_CHECK_EQUAL(0, licenseInfos.size()); BOOST_ASSERT(registry.getLastFailure() != NULL); BOOST_CHECK_MESSAGE((ENVIRONMENT_VARIABLE_NOT_DEFINED == registry.getLastFailure()->event_type) || (LICENSE_FILE_NOT_FOUND == registry.getLastFailure()->event_type), BOOST_CHECK_MESSAGE((ENVIRONMENT_VARIABLE_NOT_DEFINED == registry.getLastFailure()->event_type), "error as expected"); } @@ -85,6 +90,8 @@ BOOST_AUTO_TEST_CASE(env_var_point_to_wrong_file) { const char *environment_variable_value = PROJECT_TEST_SRC_DIR "/this/file/doesnt/exist"; SETENV(LICENSE_LOCATION_ENV_VAR, environment_variable_value) locate::LocatorFactory::find_license_near_module(false); locate::LocatorFactory::find_license_with_env_var(true); const LicenseLocation location = {nullptr, nullptr}; LicenseReader licenseReader(&location); @@ -97,4 +104,5 @@ BOOST_CHECK_EQUAL(LICENSE_FILE_NOT_FOUND, registry.getLastFailure()->event_type); UNSETENV(LICENSE_LOCATION_ENV_VAR); } } /* namespace test*/ } // namespace test } // namespace license