2626
2727#define HTTP_STATUS_OK 200
2828
29+ struct test {
30+ struct evp_agent_context * agent ;
31+ struct EVP_client * client ;
32+ };
33+
34+ static struct test test ;
35+
2936static void
3037blob_cb (EVP_BLOB_CALLBACK_REASON reason , const void * vp , void * userData )
3138{
@@ -37,7 +44,7 @@ blob_cb(EVP_BLOB_CALLBACK_REASON reason, const void *vp, void *userData)
3744}
3845
3946void
40- blob_type_http_ext_test (void * * state )
47+ test_http_ext_get_memory (void * * state )
4148{
4249 /* This should test the HttpExt blob type.
4350 *
@@ -46,28 +53,18 @@ blob_type_http_ext_test(void **state)
4653 * Finally we test the headers limit and the free function.
4754 */
4855
49- // start agent
50- struct evp_agent_context * ctxt = agent_test_start ();
51-
52- // create backdoor instance
53- struct EVP_client * sdk_handle =
54- evp_agent_add_instance (ctxt , "backdoor" );
55- assert_non_null (sdk_handle );
56+ // test HTTP GET to memory
57+ struct test * ctxt = * state ;
5658
57- // prepare tests
5859 EVP_RESULT result ;
59- static struct EVP_BlobLocalStore localstore ;
60- static char cb_data ;
61- localstore .io_cb = 0 ;
62- localstore .blob_len = 0 ;
63- localstore .filename = NULL ;
60+ struct EVP_BlobLocalStore localstore = {0 };
61+ char cb_data ;
6462
6563 struct EVP_BlobRequestHttpExt * request =
6664 EVP_BlobRequestHttpExt_initialize ();
6765 EVP_BlobRequestHttpExt_setUrl (request , TEST_HTTP_GET_URL );
6866
69- // test HTTP GET to memory
70- result = EVP_blobOperation (sdk_handle , EVP_BLOB_TYPE_HTTP_EXT ,
67+ result = EVP_blobOperation (ctxt -> client , EVP_BLOB_TYPE_HTTP_EXT ,
7168 EVP_BLOB_OP_GET , request , & localstore ,
7269 blob_cb , & cb_data );
7370 assert_int_equal (result , EVP_OK );
@@ -79,16 +76,32 @@ blob_type_http_ext_test(void **state)
7976 expect_value (blob_cb , result -> result , EVP_BLOB_RESULT_SUCCESS );
8077 expect_value (blob_cb , result -> http_status , HTTP_STATUS_OK );
8178 expect_value (blob_cb , result -> error , 0 );
82- result = EVP_processEvent (sdk_handle , 1000 );
79+ result = EVP_processEvent (ctxt -> client , 1000 );
8380 assert_int_equal (result , EVP_OK );
8481
82+ EVP_BlobRequestHttpExt_free (request );
83+ }
84+
85+ void
86+ test_http_ext_get_file (void * * state )
87+ {
8588 // test HTTP GET to file
89+ struct test * ctxt = * state ;
90+
91+ char * filename ;
92+ xasprintf (& filename , "%s/%s" , path_get (MODULE_INSTANCE_PATH_ID ),
93+ TEST_HTTP_GET_FILE );
94+ EVP_RESULT result ;
95+ struct EVP_BlobLocalStore localstore = {.filename = filename };
96+ char cb_data ;
97+
98+ struct EVP_BlobRequestHttpExt * request =
99+ EVP_BlobRequestHttpExt_initialize ();
86100 EVP_BlobRequestHttpExt_setUrl (request , TEST_HTTP_GET_URL );
87- xasprintf ((char * * )& localstore .filename , "%s/%s" ,
88- path_get (MODULE_INSTANCE_PATH_ID ), TEST_HTTP_GET_FILE );
101+
89102 /* we can't use expect_string because webclient_perform will be called
90103 * from a different thread */
91- result = EVP_blobOperation (sdk_handle , EVP_BLOB_TYPE_HTTP_EXT ,
104+ result = EVP_blobOperation (ctxt -> client , EVP_BLOB_TYPE_HTTP_EXT ,
92105 EVP_BLOB_OP_GET , request , & localstore ,
93106 blob_cb , & cb_data );
94107 free (__UNCONST (localstore .filename ));
@@ -100,14 +113,30 @@ blob_type_http_ext_test(void **state)
100113 expect_value (blob_cb , result -> result , EVP_BLOB_RESULT_SUCCESS );
101114 expect_value (blob_cb , result -> http_status , HTTP_STATUS_OK );
102115 expect_value (blob_cb , result -> error , 0 );
103- result = EVP_processEvent (sdk_handle , 1000 );
116+ result = EVP_processEvent (ctxt -> client , 1000 );
104117 assert_int_equal (result , EVP_OK );
105118
106- // test HTTP PUT to file
119+ EVP_BlobRequestHttpExt_free (request );
120+ }
121+
122+ void
123+ test_http_ext_put_file (void * * state )
124+ {
125+ // test HTTP PUT file
126+ struct test * ctxt = * state ;
127+
128+ char * filename ;
129+ xasprintf (& filename , "%s/%s" , path_get (MODULE_INSTANCE_PATH_ID ),
130+ TEST_HTTP_GET_FILE );
131+ EVP_RESULT result ;
132+ struct EVP_BlobLocalStore localstore = {.filename = filename };
133+ char cb_data ;
134+
135+ struct EVP_BlobRequestHttpExt * request =
136+ EVP_BlobRequestHttpExt_initialize ();
107137 EVP_BlobRequestHttpExt_setUrl (request , TEST_HTTP_PUT_URL );
108- xasprintf ((char * * )& localstore .filename , "%s/%s" ,
109- path_get (MODULE_INSTANCE_PATH_ID ), TEST_HTTP_PUT_FILE );
110- result = EVP_blobOperation (sdk_handle , EVP_BLOB_TYPE_HTTP_EXT ,
138+
139+ result = EVP_blobOperation (ctxt -> client , EVP_BLOB_TYPE_HTTP_EXT ,
111140 EVP_BLOB_OP_PUT , request , & localstore ,
112141 blob_cb , & cb_data );
113142 free (__UNCONST (localstore .filename ));
@@ -119,16 +148,32 @@ blob_type_http_ext_test(void **state)
119148 expect_value (blob_cb , result -> result , EVP_BLOB_RESULT_SUCCESS );
120149 expect_value (blob_cb , result -> http_status , HTTP_STATUS_OK );
121150 expect_value (blob_cb , result -> error , 0 );
122- result = EVP_processEvent (sdk_handle , 1000 );
151+ result = EVP_processEvent (ctxt -> client , 1000 );
123152 assert_int_equal (result , EVP_OK );
124153
154+ EVP_BlobRequestHttpExt_free (request );
155+ }
156+
157+ void
158+ test_http_ext_get_file_range (void * * state )
159+ {
125160 // test HTTP GET with RANGE
161+ struct test * ctxt = * state ;
162+
163+ char * filename ;
164+ xasprintf (& filename , "%s/%s" , path_get (MODULE_INSTANCE_PATH_ID ),
165+ TEST_HTTP_GET_FILE );
166+ EVP_RESULT result ;
167+ struct EVP_BlobLocalStore localstore = {.filename = filename };
168+ char cb_data ;
169+
170+ struct EVP_BlobRequestHttpExt * request =
171+ EVP_BlobRequestHttpExt_initialize ();
126172 EVP_BlobRequestHttpExt_setUrl (request , TEST_HTTP_GET_URL );
127173 EVP_BlobRequestHttpExt_addHeader (request , "Range" ,
128174 TEST_HTTP_GET_RANGE );
129- xasprintf ((char * * )& localstore .filename , "%s/%s" ,
130- path_get (MODULE_INSTANCE_PATH_ID ), TEST_HTTP_GET_FILE );
131- result = EVP_blobOperation (sdk_handle , EVP_BLOB_TYPE_HTTP_EXT ,
175+
176+ result = EVP_blobOperation (ctxt -> client , EVP_BLOB_TYPE_HTTP_EXT ,
132177 EVP_BLOB_OP_GET , request , & localstore ,
133178 blob_cb , & cb_data );
134179
@@ -142,14 +187,33 @@ blob_type_http_ext_test(void **state)
142187 expect_value (blob_cb , result -> result , EVP_BLOB_RESULT_SUCCESS );
143188 expect_value (blob_cb , result -> http_status , HTTP_STATUS_OK );
144189 expect_value (blob_cb , result -> error , 0 );
145- result = EVP_processEvent (sdk_handle , 1000 );
190+ result = EVP_processEvent (ctxt -> client , 1000 );
146191 assert_int_equal (result , EVP_OK );
147192
193+ EVP_BlobRequestHttpExt_free (request );
194+ }
195+
196+ void
197+ test_http_ext_get_file_range_azure (void * * state )
198+ {
148199 // test HTTP GET with RANGE and Azure header
200+ struct test * ctxt = * state ;
201+
202+ char * filename ;
203+ xasprintf (& filename , "%s/%s" , path_get (MODULE_INSTANCE_PATH_ID ),
204+ TEST_HTTP_GET_FILE );
205+ EVP_RESULT result ;
206+ struct EVP_BlobLocalStore localstore = {.filename = filename };
207+ char cb_data ;
208+
209+ struct EVP_BlobRequestHttpExt * request =
210+ EVP_BlobRequestHttpExt_initialize ();
211+ EVP_BlobRequestHttpExt_setUrl (request , TEST_HTTP_GET_URL );
149212 EVP_BlobRequestHttpExt_addHeader (request , "Range" ,
150213 TEST_HTTP_GET_RANGE );
151214 EVP_BlobRequestHttpExt_addAzureHeader (request );
152- result = EVP_blobOperation (sdk_handle , EVP_BLOB_TYPE_HTTP_EXT ,
215+
216+ result = EVP_blobOperation (ctxt -> client , EVP_BLOB_TYPE_HTTP_EXT ,
153217 EVP_BLOB_OP_GET , request , & localstore ,
154218 blob_cb , & cb_data );
155219
@@ -167,13 +231,30 @@ blob_type_http_ext_test(void **state)
167231 expect_value (blob_cb , result -> result , EVP_BLOB_RESULT_SUCCESS );
168232 expect_value (blob_cb , result -> http_status , HTTP_STATUS_OK );
169233 expect_value (blob_cb , result -> error , 0 );
170- result = EVP_processEvent (sdk_handle , 1000 );
234+ result = EVP_processEvent (ctxt -> client , 1000 );
171235 assert_int_equal (result , EVP_OK );
172236
237+ EVP_BlobRequestHttpExt_free (request );
238+ }
239+
240+ void
241+ test_http_ext_get_null_memory_range_azure (void * * state )
242+ {
173243 // Test download to null memory
174- localstore .filename = NULL ;
175- localstore .io_cb = NULL ;
176- result = EVP_blobOperation (sdk_handle , EVP_BLOB_TYPE_HTTP_EXT ,
244+ struct test * ctxt = * state ;
245+
246+ EVP_RESULT result ;
247+ struct EVP_BlobLocalStore localstore = {0 };
248+ char cb_data ;
249+
250+ struct EVP_BlobRequestHttpExt * request =
251+ EVP_BlobRequestHttpExt_initialize ();
252+ EVP_BlobRequestHttpExt_setUrl (request , TEST_HTTP_GET_URL );
253+ EVP_BlobRequestHttpExt_addHeader (request , "Range" ,
254+ TEST_HTTP_GET_RANGE );
255+ EVP_BlobRequestHttpExt_addAzureHeader (request );
256+
257+ result = EVP_blobOperation (ctxt -> client , EVP_BLOB_TYPE_HTTP_EXT ,
177258 EVP_BLOB_OP_GET , request , & localstore ,
178259 blob_cb , & cb_data );
179260
@@ -189,9 +270,17 @@ blob_type_http_ext_test(void **state)
189270 expect_value (blob_cb , result -> result , EVP_BLOB_RESULT_SUCCESS );
190271 expect_value (blob_cb , result -> http_status , HTTP_STATUS_OK );
191272 expect_value (blob_cb , result -> error , 0 );
192- result = EVP_processEvent (sdk_handle , 1000 );
273+ result = EVP_processEvent (ctxt -> client , 1000 );
193274 assert_int_equal (result , EVP_OK );
194275
276+ EVP_BlobRequestHttpExt_free (request );
277+ }
278+
279+ void
280+ test_http_ext_header_limits (void * * state )
281+ {
282+ struct EVP_BlobRequestHttpExt * request =
283+ EVP_BlobRequestHttpExt_initialize ();
195284 // Test the headers limit and the free function
196285 unsigned int i ;
197286 // We start with 2 because there are already 2 headers in the request
@@ -217,6 +306,13 @@ setup(void **state)
217306 assert_int_equal (0 , systemf ("touch %s/%s" ,
218307 path_get (MODULE_INSTANCE_PATH_ID ),
219308 TEST_HTTP_PUT_FILE ));
309+ // start agent
310+ test .agent = agent_test_start ();
311+
312+ // create backdoor instance
313+ test .client = evp_agent_add_instance (test .agent , "backdoor" );
314+ assert_non_null (test .client );
315+ * state = & test ;
220316 return 0 ;
221317}
222318
@@ -232,7 +328,13 @@ main(void)
232328{
233329 // define tests
234330 const struct CMUnitTest tests [] = {
235- cmocka_unit_test (blob_type_http_ext_test ),
331+ cmocka_unit_test (test_http_ext_get_memory ),
332+ cmocka_unit_test (test_http_ext_get_file ),
333+ cmocka_unit_test (test_http_ext_put_file ),
334+ cmocka_unit_test (test_http_ext_get_file_range ),
335+ cmocka_unit_test (test_http_ext_get_file_range_azure ),
336+ cmocka_unit_test (test_http_ext_get_null_memory_range_azure ),
337+ cmocka_unit_test (test_http_ext_header_limits ),
236338 };
237339 // setup and run tests
238340 return cmocka_run_group_tests (tests , setup , teardown );
0 commit comments