First release of open-appsec source code

This commit is contained in:
roybarda
2022-10-26 19:33:19 +03:00
parent 3883109caf
commit a883352f79
1353 changed files with 276290 additions and 1 deletions

View File

@@ -0,0 +1,46 @@
// Copyright (C) 2022 Check Point Software Technologies Ltd. All rights reserved.
// Licensed under the Apache License, Version 2.0 (the "License");
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef __MOCK_DETAILS_RESOLVER_H__
#define __MOCK_DETAILS_RESOLVER_H__
#include <iostream>
#include "i_details_resolver.h"
#include "cptest.h"
#include "maybe_res.h"
std::ostream &
operator<<(std::ostream &os, const Maybe<std::tuple<std::string, std::string, std::string>> &)
{
return os;
}
class MockDetailsResolver
:
public Singleton::Provide<I_DetailsResolver>::From<MockProvider<I_DetailsResolver>>
{
public:
MOCK_METHOD0(getHostname, Maybe<std::string>());
MOCK_METHOD0(getPlatform, Maybe<std::string>());
MOCK_METHOD0(getArch, Maybe<std::string>());
MOCK_METHOD0(getAgentVersion, std::string());
MOCK_METHOD0(isReverseProxy, bool());
MOCK_METHOD0(isKernelVersion3OrHigher, bool());
MOCK_METHOD0(isGwNotVsx, bool());
MOCK_METHOD0(getResolvedDetails, std::map<std::string, std::string>());
MOCK_METHOD0(isVersionEqualOrAboveR8110, bool());
MOCK_METHOD0(parseNginxMetadata, Maybe<std::tuple<std::string, std::string, std::string>>());
};
#endif // __MOCK_DETAILS_RESOLVER_H__

View File

@@ -0,0 +1,42 @@
// Copyright (C) 2022 Check Point Software Technologies Ltd. All rights reserved.
// Licensed under the Apache License, Version 2.0 (the "License");
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef __MOCK_DOWNLOADER_H__
#define __MOCK_DOWNLOADER_H__
#include "cptest.h"
#include "i_downloader.h"
#include <string>
class MockDownloader :
public Singleton::Provide<I_Downloader>::From<MockProvider<I_Downloader>>
{
public:
MOCK_CONST_METHOD3(
downloadFileFromFog,
Maybe<std::string>(const std::string &, Package::ChecksumTypes, const GetResourceFile &)
);
MOCK_CONST_METHOD2(
downloadVirtualFileFromFog,
Maybe<std::map<std::string, std::string>>(const GetResourceFile &, Package::ChecksumTypes)
);
MOCK_CONST_METHOD4(
downloadFileFromURL,
Maybe<std::string>(const std::string &, const std::string &, Package::ChecksumTypes, const std::string &)
);
};
#endif // __MOCK_DOWNLOADER_H__

View File

@@ -0,0 +1,28 @@
// Copyright (C) 2022 Check Point Software Technologies Ltd. All rights reserved.
// Licensed under the Apache License, Version 2.0 (the "License");
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef __MOCK_MANIFEST_CONTROLLER_H__
#define __MOCK_MANIFEST_CONTROLLER_H__
#include "i_manifest_controller.h"
#include "cptest.h"
class MockManifestController :
public Singleton::Provide<I_ManifestController>::From<MockProvider<I_ManifestController>>
{
public:
MOCK_METHOD1(updateManifest, bool(const std::string &));
MOCK_METHOD0(loadAfterSelfUpdate, bool());
};
#endif // __MOCK_MANIFEST_CONTROLLER_H__

View File

@@ -0,0 +1,39 @@
// Copyright (C) 2022 Check Point Software Technologies Ltd. All rights reserved.
// Licensed under the Apache License, Version 2.0 (the "License");
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef __MOCK_MESSAGING_DOWNLOADER_H__
#define __MOCK_MESSAGING_DOWNLOADER_H__
#include "cptest.h"
#include <string>
#include "i_messaging_downloader.h"
class MockMessagingDownloader
:
public Singleton::Provide<I_MessagingDownloader>::From<MockProvider<I_MessagingDownloader>>
{
public:
MOCK_METHOD4(
downloadFile,
bool(
const std::string &,
const std::string &,
OnCompleteCB,
const unsigned int
)
);
};
#endif // __MOCK_MESSAGING_DOWNLOADER_H__

View File

@@ -0,0 +1,63 @@
// Copyright (C) 2022 Check Point Software Technologies Ltd. All rights reserved.
// Licensed under the Apache License, Version 2.0 (the "License");
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef __MOCK_ORCHESTRATION_STATUS_H__
#define __MOCK_ORCHESTRATION_STATUS_H__
#include "i_orchestration_status.h"
#include "cptest.h"
class MockOrchestrationStatus
:
public Singleton::Provide<I_OrchestrationStatus>::From<MockProvider<I_OrchestrationStatus>>
{
public:
MOCK_METHOD0(writeStatusToFile, void());
MOCK_METHOD0(recoverFields, void());
MOCK_METHOD1(setUpgradeMode, void(const std::string &));
MOCK_METHOD1(setAgentType, void(const std::string &));
MOCK_METHOD1(setRegistrationStatus, void(const std::string &));
MOCK_METHOD1(setFogAddress, void(const std::string &));
MOCK_METHOD1(setPolicyVersion, void(const std::string &));
MOCK_METHOD1(setIsConfigurationUpdated, void(EnumArray<OrchestrationStatusConfigType, bool> config_types));
MOCK_METHOD0(setLastUpdateAttempt, void());
MOCK_METHOD3(setAgentDetails, void(const std::string &, const std::string &, const std::string &));
MOCK_METHOD3(setFieldStatus,
void(const OrchestrationStatusFieldType &, const OrchestrationStatusResult &, const std::string &));
MOCK_METHOD4(setRegistrationDetails,
void(const std::string &, const std::string &, const std::string &, const std::string &)
);
MOCK_METHOD3(setServiceConfiguration,
void(const std::string &, const std::string &, const OrchestrationStatusConfigType &)
);
MOCK_CONST_METHOD0(getLastUpdateAttempt, const std::string&());
MOCK_CONST_METHOD0(getUpdateStatus, const std::string&());
MOCK_CONST_METHOD0(getUpdateTime, const std::string&());
MOCK_CONST_METHOD0(getLastManifestUpdate, const std::string&());
MOCK_CONST_METHOD0(getPolicyVersion, const std::string&());
MOCK_CONST_METHOD0(getLastPolicyUpdate, const std::string&());
MOCK_CONST_METHOD0(getLastSettingsUpdate, const std::string&());
MOCK_CONST_METHOD0(getUpgradeMode, const std::string&());
MOCK_CONST_METHOD0(getFogAddress, const std::string&());
MOCK_CONST_METHOD0(getRegistrationStatus, const std::string&());
MOCK_CONST_METHOD0(getAgentId, const std::string&());
MOCK_CONST_METHOD0(getProfileId, const std::string&());
MOCK_CONST_METHOD0(getTenantId, const std::string&());
MOCK_CONST_METHOD0(getManifestStatus, const std::string&());
MOCK_CONST_METHOD0(getManifestError, const std::string&());
MOCK_CONST_METHOD0(getServicePolicies, const std::map<std::string, std::string>&());
MOCK_CONST_METHOD0(getServiceSettings, const std::map<std::string, std::string>&());
MOCK_CONST_METHOD0(getRegistrationDetails, const std::string());
};
#endif // __MOCK_ORCHESTRATION_STATUS_H__

View File

@@ -0,0 +1,58 @@
// Copyright (C) 2022 Check Point Software Technologies Ltd. All rights reserved.
// Licensed under the Apache License, Version 2.0 (the "License");
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef __MOCK_ORCHESTRATION_TOOLS_H__
#define __MOCK_ORCHESTRATION_TOOLS_H__
#include "cptest.h"
#include "i_orchestration_tools.h"
template <typename T>
std::ostream &
operator<<(std::ostream &os, const std::vector<T> &)
{
return os;
}
template <typename T, typename S>
std::ostream &
operator<<(std::ostream &os, const std::map<T, S> &)
{
return os;
}
class MockOrchestrationTools
:
public Singleton::Provide<I_OrchestrationTools>::From<MockProvider<I_OrchestrationTools>>
{
public:
MOCK_CONST_METHOD1(loadPackagesFromJson, Maybe<std::map<std::string, Package>>(const std::string &));
MOCK_CONST_METHOD2(packagesToJsonFile, bool(const std::map<std::string, Package> &, const std::string &));
MOCK_CONST_METHOD1(isNonEmptyFile, bool(const std::string &));
MOCK_CONST_METHOD1(readFile, Maybe<std::string>(const std::string &));
MOCK_CONST_METHOD2(writeFile, bool(const std::string &, const std::string &));
MOCK_CONST_METHOD1(removeFile, bool(const std::string &));
MOCK_CONST_METHOD2(copyFile, bool(const std::string &, const std::string &));
MOCK_CONST_METHOD2(calculateChecksum, Maybe<std::string>(Package::ChecksumTypes, const std::string &));
MOCK_CONST_METHOD2(
jsonObjectSplitter,
Maybe<std::map<std::string, std::string>>(const std::string &, const std::string &)
);
MOCK_CONST_METHOD1(doesFileExist, bool(const std::string &));
MOCK_CONST_METHOD1(createDirectory, bool(const std::string &));
MOCK_CONST_METHOD1(doesDirectoryExist, bool(const std::string &));
MOCK_CONST_METHOD1(executeCmd, bool(const std::string &));
MOCK_CONST_METHOD1(base64Encode, std::string(const std::string &));
MOCK_CONST_METHOD1(base64Decode, std::string(const std::string &));
};
#endif // __MOCK_ORCHESTRATION_TOOLS_H__

View File

@@ -0,0 +1,31 @@
// Copyright (C) 2022 Check Point Software Technologies Ltd. All rights reserved.
// Licensed under the Apache License, Version 2.0 (the "License");
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef __MOCK_PACKAGE_HANDLER_H__
#define __MOCK_PACKAGE_HANDLER_H__
#include "i_package_handler.h"
#include "cptest.h"
class MockPackageHandler :
public Singleton::Provide<I_PackageHandler>::From<MockProvider<I_PackageHandler>>
{
public:
MOCK_CONST_METHOD3(installPackage, bool(const std::string &, const std::string &, bool));
MOCK_CONST_METHOD3(uninstallPackage, bool(const std::string &, const std::string &, const std::string &));
MOCK_CONST_METHOD2(preInstallPackage, bool(const std::string &, const std::string &));
MOCK_CONST_METHOD2(postInstallPackage, bool(const std::string &, const std::string &));
MOCK_CONST_METHOD2(updateSavedPackage, bool(const std::string &, const std::string &));
MOCK_CONST_METHOD2(shouldInstallPackage, bool(const std::string &, const std::string &));
};
#endif // __MOCK_PACKAGE_HANDLER_H__

View File

@@ -0,0 +1,62 @@
// Copyright (C) 2022 Check Point Software Technologies Ltd. All rights reserved.
// Licensed under the Apache License, Version 2.0 (the "License");
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef __MOCK_SERVICE_CONTROLLER_H__
#define __MOCK_SERVICE_CONTROLLER_H__
#include "i_service_controller.h"
#include "cptest.h"
#include <string>
class MockServiceController :
public Singleton::Provide<I_ServiceController>::From<MockProvider<I_ServiceController>>
{
public:
MOCK_CONST_METHOD0(getPolicyVersion, const std::string &());
MOCK_CONST_METHOD0(getUpdatePolicyVersion, const std::string &());
MOCK_METHOD4(
updateServiceConfiguration,
bool(
const std::string &new_policy_path,
const std::string &new_settings_path,
const std::vector<std::string> &new_data_files,
const std::string &tenant_id
)
);
MOCK_METHOD1(isServiceInstalled, bool(const std::string &service_name));
MOCK_METHOD4(
registerServiceConfig,
void(
const std::string &service_name,
PortNumber listening_port,
const std::vector<std::string> &expected_configurations,
const std::string &id
)
);
typedef std::map<std::string, PortNumber> ServicePortMap;
MOCK_METHOD0(getServiceToPortMap, ServicePortMap());
MOCK_METHOD2(updateReconfStatus, void(int id, ReconfStatus status));
MOCK_METHOD4(
startReconfStatus,
void(int id, ReconfStatus status, const std::string &serivce_name, const std::string &service_id)
);
};
#endif // __MOCK_SERVICE_CONTROLLER_H__

View File

@@ -0,0 +1,37 @@
// Copyright (C) 2022 Check Point Software Technologies Ltd. All rights reserved.
// Licensed under the Apache License, Version 2.0 (the "License");
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef __MOCK_UPDATE_COMMUNICATION_H__
#define __MOCK_UPDATE_COMMUNICATION_H__
#include "i_update_communication.h"
#include "cptest.h"
std::ostream &
operator<<(std::ostream &os, const CheckUpdateRequest &)
{
return os;
}
class MockUpdateCommunication :
public Singleton::Provide<I_UpdateCommunication>::From<MockProvider<I_UpdateCommunication>>
{
public:
MOCK_METHOD0(authenticateAgent, Maybe<void>());
MOCK_METHOD1(getUpdate, Maybe<void>(CheckUpdateRequest &));
MOCK_METHOD1(downloadAttributeFile, Maybe<std::string>(const GetResourceFile &));
MOCK_METHOD1(setAddressExtenesion, void(const std::string &));
MOCK_CONST_METHOD1(sendPolicyVersion, Maybe<void>(const std::string &));
};
#endif // __MOCK_UPDATE_COMMUNICATION_H__