Gabriele Contini
2020-03-21 079123b5c4c25a453ba4d3c6ffa1b5f9f39c5dad
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#define BOOST_TEST_MODULE integration_test_hw_identifier
 
#include <boost/test/unit_test.hpp>
#include <fstream>
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <boost/filesystem.hpp>
#include <licensecc_properties.h>
#include <licensecc_properties_test.h>
 
#include <licensecc/licensecc.h>
#include "../../src/library/ini/SimpleIni.h"
#include "../../src/library/hw_identifier/hw_identifier_facade.hpp"
#include "../../src/library/os/os.h"
#include "../../src/library/os/network.hpp"
#include "generate-license.h"
 
 
namespace license {
namespace test {
namespace fs = boost::filesystem;
using namespace std;
using namespace hw_identifier;
 
/**
 * If the current pc has at least one disk generate a hardware identifier using disk, generate a license, verify the license
 * is OK
 */
 
static void generate_and_verify_license(LCC_API_HW_IDENTIFICATION_STRATEGY strategy, const string& lic_fname) {
    BOOST_TEST_CHECKPOINT("Before generate");
    const string identifier_out = HwIdentifierFacade::generate_user_pc_signature(strategy);
    BOOST_TEST_CHECKPOINT("After generate signature");
    cout << "Identifier:" << identifier_out << endl;
    vector<string> extraArgs;
    extraArgs.push_back("-s");
    extraArgs.push_back(identifier_out);
    BOOST_TEST_CHECKPOINT("Before generate license");
    const string licLocation = generate_license(lic_fname, extraArgs);
    LicenseInfo license;
    LicenseLocation location = {LICENSE_PATH};
    std::copy(licLocation.begin(), licLocation.end(), location.licenseData);
    const LCC_EVENT_TYPE result = acquire_license(nullptr, &location, &license);
    BOOST_CHECK_EQUAL(result, LICENSE_OK);
    BOOST_CHECK_EQUAL(license.has_expiry, false);
    BOOST_CHECK_EQUAL(license.linked_to_pc, true);
}
 
BOOST_AUTO_TEST_CASE(volid_lic_file) {
    HwIdentifier identifier_out;
    size_t disk_num;
    FUNCTION_RETURN result_diskinfos = getDiskInfos(nullptr, &disk_num);
    if ((result_diskinfos == FUNC_RET_BUFFER_TOO_SMALL || result_diskinfos == FUNC_RET_OK) && disk_num > 0) {
        generate_and_verify_license(LCC_API_HW_IDENTIFICATION_STRATEGY::STRATEGY_DISK_NUM, "volid_lic_file");
    } else {
        BOOST_TEST_MESSAGE("No disk found skipping testing disk hardware identifier");
    }
}
 
BOOST_AUTO_TEST_CASE(volume_name_lic_file) {
    HwIdentifier identifier_out;
    size_t disk_num;
    FUNCTION_RETURN result_diskinfos = getDiskInfos(nullptr, &disk_num);
    if ((result_diskinfos == FUNC_RET_BUFFER_TOO_SMALL || result_diskinfos == FUNC_RET_OK) && disk_num > 0) {
        generate_and_verify_license(LCC_API_HW_IDENTIFICATION_STRATEGY::STRATEGY_DISK_LABEL, "volume_name_lic_file");
    } else {
        BOOST_TEST_MESSAGE("No disk found skipping testing volume name disk hardware identifier");
    }
}
 
BOOST_AUTO_TEST_CASE(strategy_mac_address) {
    vector<os::OsAdapterInfo> adapters;
    FUNCTION_RETURN result_adapterInfos = os::getAdapterInfos(adapters);
    if ((result_adapterInfos == FUNC_RET_BUFFER_TOO_SMALL || result_adapterInfos == FUNC_RET_OK) &&
        adapters.size() > 0) {
        generate_and_verify_license(LCC_API_HW_IDENTIFICATION_STRATEGY::STRATEGY_ETHERNET, "strategy_mac_address");
    } else {
        BOOST_TEST_MESSAGE("No ethernet adapter found skipping testing mac address hardware identifier");
    }
}
 
BOOST_AUTO_TEST_CASE(strategy_ip_address) {
    vector<os::OsAdapterInfo> adapters;
    FUNCTION_RETURN result_adapterInfos = os::getAdapterInfos(adapters);
    if ((result_adapterInfos == FUNC_RET_BUFFER_TOO_SMALL || result_adapterInfos == FUNC_RET_OK) &&
        adapters.size() > 0) {
        generate_and_verify_license(LCC_API_HW_IDENTIFICATION_STRATEGY::STRATEGY_IP_ADDRESS, "strategy_ip_address");
    } else {
        BOOST_TEST_MESSAGE("No ethernet adapter found skipping testing ip hardware identifier");
    }
}
 
}  // namespace test
}  // namespace license