16 #ifndef AVS_CAPABILITIES_ASSETMANAGER_ACSDKASSETMANAGER_TEST_ASSETMANAGERTEST_H_ 17 #define AVS_CAPABILITIES_ASSETMANAGER_ACSDKASSETMANAGER_TEST_ASSETMANAGERTEST_H_ 22 #include "RequesterMetadata.h" 26 #include "archive_entry.h" 40 TESTING_DIRECTORY = TMP_DIR +
"/davs_testing";
41 BASE_DIR = TMP_DIR +
"/davs";
42 DAVS_TMP = TMP_DIR +
"/davstmp";
43 DAVS_RESOURCES_DIR = BASE_DIR +
"/resources";
44 DAVS_REQUESTS_DIR = BASE_DIR +
"/requests";
45 URL_RESOURCES_DIR =
"/tmp/urlResources";
46 filesystem::makeDirectory(URL_RESOURCES_DIR);
48 commsHandler = InMemoryAmdCommunicationHandler::create();
50 tarArtifact->commsHandler = commsHandler;
51 unavailableArtifact->commsHandler = commsHandler;
52 tarUrlArtifact->commsHandler = commsHandler;
53 unavailableUrlArtifact->commsHandler = commsHandler;
54 httpUrlArtifact->commsHandler = commsHandler;
55 nonApprovedUrlArtifact->commsHandler = commsHandler;
59 allowUrlList = UrlAllowListWrapper::create(
60 {
"https://s3.amazonaws.com/alexareminderservice.prod.usamazon.reminder.earcons/echo_system_alerts_reminder_start_v",
61 "https://tinytts.amazon.com/",
62 "https://tinytts-eu-west-1.amazon.com/",
63 "https://tinytts-us-west-2.amazon.com/",
70 uploadArtifactFromRequest(tarArtifact->request);
71 uploadArtifactFromRequest(tarUrlArtifact->request, 100);
74 davsEndpointHandler = DavsEndpointHandlerV3::create(
"123");
79 shutdownAssetManager();
80 filesystem::removeAll(URL_RESOURCES_DIR);
81 filesystem::removeAll(TMP_DIR);
85 if (assetManager !=
nullptr) {
88 davsClient = DavsClient::create(DAVS_TMP, authDelegateMock, wifiMonitorMock, davsEndpointHandler);
89 assetManager = AssetManager::create(commsHandler, davsClient, BASE_DIR, authDelegateMock, allowUrlList);
91 assetManager->onIdleChanged(1);
95 if (assetManager ==
nullptr) {
102 const shared_ptr<ArtifactRequest>& request,
104 const string&
id =
"",
105 milliseconds ttlDelta = minutes(60)) {
106 filesystem::makeDirectory(TESTING_DIRECTORY);
107 auto metadata = RequesterMetadata::create(request);
108 auto type = metadata->getRequest()->getRequestType();
109 if (
type == Type::DAVS) {
110 auto davsRequest = static_pointer_cast<
DavsRequest>(request);
111 if (davsRequest !=
nullptr) {
112 service.uploadBinaryArtifact(
113 davsRequest->getType(),
114 davsRequest->getKey(),
115 davsRequest->getFilters(),
116 createTarFile(TESTING_DIRECTORY,
"target", size),
120 }
else if (
type == Type::URL) {
121 auto urlRequest = static_pointer_cast<
UrlRequest>(request);
122 if (urlRequest !=
nullptr) {
123 createTarFile(URL_RESOURCES_DIR,
"urlTarget", 1);
128 static string createTarFile(
const string& dir,
const string& filename,
size_t size = 1) {
129 auto tarPath = dir +
"/" + filename +
".tar.gz";
130 auto data =
string(size,
'a');
132 auto a = archive_write_new();
133 archive_write_add_filter_gzip(a);
134 archive_write_set_format_pax_restricted(a);
135 archive_write_open_filename(a, tarPath.c_str());
137 auto entry = archive_entry_new();
138 archive_entry_set_pathname(entry, filename.c_str());
139 archive_entry_set_size(entry, static_cast<la_int64_t>(data.size()));
140 archive_entry_set_filetype(entry, AE_IFREG);
141 archive_entry_set_perm(entry, 0644);
142 archive_write_header(a, entry);
143 archive_write_data(a, data.c_str(), data.size());
144 archive_entry_free(entry);
146 archive_write_close(a);
147 archive_write_free(a);
163 shared_ptr<alexaClientSDK::avsCommon::sdkInterfaces::AuthDelegateInterface>
authDelegateMock;
164 shared_ptr<alexaClientSDK::avsCommon::sdkInterfaces::InternetConnectionMonitorInterface>
wifiMonitorMock;
170 shared_ptr<ArtifactUnderTest> tarArtifact = make_shared<ArtifactUnderTest>(
nullptr, DavsRequest::create(
"test",
"tar", {{
"filter1", {
"value1"}}, {
"filter2", {
"value2"}}}, Region::NA, ArtifactRequest::UNPACK));
171 shared_ptr<ArtifactUnderTest> unavailableArtifact = make_shared<ArtifactUnderTest>(
nullptr, DavsRequest::create(
"test",
"not_found", {{
"filter1", {
"value1"}}}, Region::NA, ArtifactRequest::UNPACK));
172 shared_ptr<ArtifactUnderTest> tarUrlArtifact = make_shared<ArtifactUnderTest>(
nullptr, UrlRequest::create(
"test:///tmp/urlResources/urlTarget.tar.gz",
"urlArtifact", ArtifactRequest::UNPACK));
173 shared_ptr<ArtifactUnderTest> unavailableUrlArtifact = make_shared<ArtifactUnderTest>(
nullptr, UrlRequest::create(
"test:///unavailableUrlArtifact",
"unavailableUrlArtifact"));
174 shared_ptr<ArtifactUnderTest> httpUrlArtifact = make_shared<ArtifactUnderTest>(
nullptr, UrlRequest::create(
"http://tinytts.amazon.com/",
"httpUrlArtifact"));
175 shared_ptr<ArtifactUnderTest> nonApprovedUrlArtifact = make_shared<ArtifactUnderTest>(
nullptr, UrlRequest::create(
"https://evil.com/",
"nonApprovedUrlArtifact"));
179 #endif // AVS_CAPABILITIES_ASSETMANAGER_ACSDKASSETMANAGER_TEST_ASSETMANAGERTEST_H_ Definition: DavsServiceMock.h:32
string DAVS_RESOURCES_DIR
Definition: AssetManagerTest.h:155
void SetUp() override
Definition: AssetManagerTest.h:38
shared_ptr< AmdCommunicationInterface > commsHandler
Definition: AssetManagerTest.h:167
static bool useDavsService
Definition: CurlWrapperMock.h:31
void startAssetManager()
Definition: AssetManagerTest.h:84
#define ASSERT_NE(val1, val2)
Definition: gtest.h:1960
Definition: AssetManagerTest.h:36
static bool downloadShallFail
Definition: CurlWrapperMock.h:32
::std::string string
Definition: gtest-port.h:1097
string TMP_DIR
Definition: AssetManagerTest.h:151
Definition: AssetManager.h:32
string DAVS_TMP
Definition: AssetManagerTest.h:154
DavsServiceMock service
Definition: AssetManagerTest.h:160
shared_ptr< DavsEndpointHandlerV3 > davsEndpointHandler
Definition: AssetManagerTest.h:165
Definition: DavsRequest.h:29
Definition: UrlRequest.h:25
void uploadArtifactFromRequest(const shared_ptr< ArtifactRequest > &request, size_t size=1, const string &id="", milliseconds ttlDelta=minutes(60))
Definition: AssetManagerTest.h:101
string BASE_DIR
Definition: AssetManagerTest.h:153
void shutdownAssetManager()
Definition: AssetManagerTest.h:94
Definition: ArtifactRequest.h:27
shared_ptr< AssetManager > assetManager
Definition: AssetManagerTest.h:162
shared_ptr< DavsClient > davsClient
Definition: AssetManagerTest.h:161
Definition: MockHTTP2Connection.cpp:20
shared_ptr< alexaClientSDK::avsCommon::sdkInterfaces::AuthDelegateInterface > authDelegateMock
Definition: AssetManagerTest.h:163
std::string createTmpDir(const std::string &prefix="test")
Definition: AmdMetricWrapper.h:31
Definition: DavsClient.h:28
string URL_RESOURCES_DIR
Definition: AssetManagerTest.h:157
string DAVS_REQUESTS_DIR
Definition: AssetManagerTest.h:156
static std::shared_ptr< AuthDelegateMock > create()
Definition: AuthDelegateMock.cpp:32
static string createTarFile(const string &dir, const string &filename, size_t size=1)
Definition: AssetManagerTest.h:128
void TearDown() override
Definition: AssetManagerTest.h:78
type
Definition: upload.py:443
static std::shared_ptr< InternetConnectionMonitorMock > create()
Definition: InternetConnectionMonitorMock.cpp:32
string URL_WORKING_DIR
Definition: AssetManagerTest.h:158
Definition: ArtifactHandlerInterface.h:24
shared_ptr< UrlAllowListWrapper > allowUrlList
Definition: AssetManagerTest.h:166
shared_ptr< alexaClientSDK::avsCommon::sdkInterfaces::InternetConnectionMonitorInterface > wifiMonitorMock
Definition: AssetManagerTest.h:164
string TESTING_DIRECTORY
Definition: AssetManagerTest.h:152