Asterisk - The Open Source Telephony Project GIT-master-5467495
Loading...
Searching...
No Matches
test_ari.c
Go to the documentation of this file.
1/*
2 * Asterisk -- An open source telephony toolkit.
3 *
4 * Copyright (C) 2013, Digium, Inc.
5 *
6 * David M. Lee, II <dlee@digium.com>
7 *
8 * See http://www.asterisk.org for more information about
9 * the Asterisk project. Please do not directly contact
10 * any of the maintainers of this project for assistance;
11 * the project provides a web site, mailing lists and IRC
12 * channels for your use.
13 *
14 * This program is free software, distributed under the terms of
15 * the GNU General Public License Version 2. See the LICENSE file
16 * at the top of the source tree.
17 */
18
19/*!
20 * \file
21 * \brief Test ARI API.
22 * \author\verbatim David M. Lee, II <dlee@digium.com> \endverbatim
23 *
24 * \ingroup tests
25 */
26
27/*** MODULEINFO
28 <depend>TEST_FRAMEWORK</depend>
29 <depend>res_ari</depend>
30 <support_level>core</support_level>
31 ***/
32
33#include "asterisk.h"
34
35#include "asterisk/module.h"
36#include "asterisk/test.h"
37#include "asterisk/ari.h"
38
39/*!@{*/
40
41/*!
42 * \internal
43 * The following code defines a simple RESTful API for unit testing. The
44 * response encodes the inputs of the invocation. The invocation_count
45 * counter is also incremented.
46 *
47 * - /foo (GET)
48 * - /foo/bar (GET, POST)
49 * - /foo/{bam} (GET)
50 * - /foo/{bam}/bang (GET, POST, DE1LETE)
51 */
52
54
55/*!
56 * \internal
57 * Shared code for all handlers
58 */
59static void handler(const char *name,
60 int response_code,
61 struct ast_variable *get_params,
62 struct ast_variable *path_vars,
63 struct ast_variable *headers,
64 struct ast_json *body,
65 struct ast_ari_response *response)
66{
67 struct ast_json *message = ast_json_pack("{s: s, s: {}, s: {}, s: {}}",
68 "name", name,
69 "get_params",
70 "path_vars",
71 "headers");
72 struct ast_json *get_params_obj = ast_json_object_get(message, "get_params");
73 struct ast_json *path_vars_obj = ast_json_object_get(message, "path_vars");
74 struct ast_json *headers_obj = ast_json_object_get(message, "headers");
75
76 for (; get_params != NULL; get_params = get_params->next) {
77 ast_json_object_set(get_params_obj, get_params->name, ast_json_string_create(get_params->value));
78 }
79
80 for (; path_vars != NULL; path_vars = path_vars->next) {
81 ast_json_object_set(path_vars_obj, path_vars->name, ast_json_string_create(path_vars->value));
82 }
83
84 for (; headers != NULL; headers = headers->next) {
85 ast_json_object_set(headers_obj, headers->name, ast_json_string_create(headers->value));
86 }
87
89 response->response_code = response_code;
90 response->message = message;
91}
92
93/*!
94 * \internal
95 * Macro to reduce the handler definition boiler-plate.
96 */
97#define HANDLER(name, response_code) \
98 static void name(struct ast_tcptls_session_instance *ser, \
99 struct ast_variable *get_params, \
100 struct ast_variable *path_vars, \
101 struct ast_variable *headers, \
102 struct ast_json *body, \
103 struct ast_ari_response *response) \
104 { \
105 handler(#name, response_code, get_params, path_vars, headers, body, response); \
106 }
107
108HANDLER(bang_get, 200)
109HANDLER(bang_post, 200)
110HANDLER(bang_delete, 204)
111HANDLER(bar_get, 200)
112HANDLER(bar_post, 200)
113HANDLER(bam_get, 200)
114HANDLER(foo_get, 200)
115
116static struct stasis_rest_handlers bang = {
117 .path_segment = "bang",
118 .callbacks = {
119 [AST_HTTP_GET] = bang_get,
120 [AST_HTTP_POST] = bang_post,
121 [AST_HTTP_DELETE] = bang_delete,
122 },
123 .num_children = 0
124};
125static struct stasis_rest_handlers bar = {
126 .path_segment = "bar",
127 .callbacks = {
128 [AST_HTTP_GET] = bar_get,
129 [AST_HTTP_POST] = bar_post,
130 },
131 .num_children = 0
132};
133static struct stasis_rest_handlers bam = {
134 .path_segment = "bam",
135 .is_wildcard = 1,
136 .callbacks = {
137 [AST_HTTP_GET] = bam_get,
138 },
139 .num_children = 1,
140 .children = { &bang }
141};
143 .path_segment = "foo",
144 .callbacks = {
145 [AST_HTTP_GET] = foo_get,
146 },
147 .num_children = 3,
148 .children = { &bar, &bam, &bang }
149};
150/*!@}*/
151
152/*!
153 * \internal
154 * \c ast_ari_response constructor.
155 */
157{
158 struct ast_ari_response *resp = ast_calloc(1, sizeof(struct ast_ari_response));
159 resp->headers = ast_str_create(24);
160 return resp;
161}
162
163/*!
164 * \internal
165 * \c ast_ari_response destructor.
166 */
167static void response_free(struct ast_ari_response *resp)
168{
169 if (!resp) {
170 return;
171 }
172 ast_free(resp->headers);
173 ast_json_unref(resp->message);
174 ast_free(resp);
175}
176
177/*!
178 * \ internal
179 * Setup test fixture for invocation tests.
180 */
181static void *setup_invocation_test(void) {
182 int r;
185 ast_assert(r == 0);
186 return &invocation_count;
187}
188
189/*!
190 * \ internal
191 * Tear down test fixture for invocation tests.
192 */
193static void tear_down_invocation_test(void *ignore) {
194 if (!ignore) {
195 return;
196 }
198}
199
200
202{
203 RAII_VAR(struct ast_ari_response *, response, NULL, response_free);
205 struct ast_json *basePathJson;
206 const char *basePath;
207
208 switch (cmd) {
209 case TEST_INIT:
210 info->name = __func__;
211 info->category = "/res/ari/";
212 info->summary = "Test simple API get.";
213 info->description = "Test ARI binding logic.";
214 return AST_TEST_NOT_RUN;
215 case TEST_EXECUTE:
216 break;
217 }
218
219 response = response_alloc();
220 headers = ast_variable_new("Host", "stasis.asterisk.org", __FILE__);
221 ast_ari_get_docs("resources.json", "", headers, response);
222 ast_test_validate(test, 200 == response->response_code);
223
224 /* basePath should be relative to the Host header */
225 basePathJson = ast_json_object_get(response->message, "basePath");
226 ast_test_validate(test, NULL != basePathJson);
227 basePath = ast_json_string_get(basePathJson);
228 ast_test_validate(test, 0 == strcmp("http://stasis.asterisk.org/ari", basePath));
229
230 return AST_TEST_PASS;
231}
232
233AST_TEST_DEFINE(get_docs_nohost)
234{
235 RAII_VAR(struct ast_ari_response *, response, NULL, response_free);
236 struct ast_variable *headers = NULL;
237 struct ast_json *basePathJson;
238
239 switch (cmd) {
240 case TEST_INIT:
241 info->name = __func__;
242 info->category = "/res/ari/";
243 info->summary = "Test API get without a Host header";
244 info->description = "Test ARI binding logic.";
245 return AST_TEST_NOT_RUN;
246 case TEST_EXECUTE:
247 break;
248 }
249
250 response = response_alloc();
251 ast_ari_get_docs("resources.json", "", headers, response);
252 ast_test_validate(test, 200 == response->response_code);
253
254 /* basePath should be relative to the Host header */
255 basePathJson = ast_json_object_get(response->message, "basePath");
256 ast_test_validate(test, NULL == basePathJson);
257
258 return AST_TEST_PASS;
259}
260
261AST_TEST_DEFINE(get_docs_notfound)
262{
263 RAII_VAR(struct ast_ari_response *, response, NULL, response_free);
264 struct ast_variable *headers = NULL;
265
266 switch (cmd) {
267 case TEST_INIT:
268 info->name = __func__;
269 info->category = "/res/ari/";
270 info->summary = "Test API get for invalid resource";
271 info->description = "Test ARI binding logic.";
272 return AST_TEST_NOT_RUN;
273 case TEST_EXECUTE:
274 break;
275 }
276
277 response = response_alloc();
278 ast_ari_get_docs("i-am-not-a-resource.json", "", headers, response);
279 ast_test_validate(test, 404 == response->response_code);
280
281 return AST_TEST_PASS;
282}
283
284AST_TEST_DEFINE(get_docs_hackerz)
285{
286 RAII_VAR(struct ast_ari_response *, response, NULL, response_free);
287 struct ast_variable *headers = NULL;
288
289 switch (cmd) {
290 case TEST_INIT:
291 info->name = __func__;
292 info->category = "/res/ari/";
293 info->summary = "Test API get for a file outside the rest-api path";
294 info->description = "Test ARI binding logic.";
295 return AST_TEST_NOT_RUN;
296 case TEST_EXECUTE:
297 break;
298 }
299
300 response = response_alloc();
301 ast_ari_get_docs("../../../../sbin/asterisk", "", headers, response);
302 ast_test_validate(test, 404 == response->response_code);
303
304 return AST_TEST_PASS;
305}
306
308{
309 RAII_VAR(void *, fixture, NULL, tear_down_invocation_test);
310 RAII_VAR(struct ast_ari_response *, response, NULL, response_free);
311 RAII_VAR(struct ast_json *, expected, NULL, ast_json_unref);
312 struct ast_variable *tail = NULL;
313 RAII_VAR(struct ast_variable *, get_params, NULL, ast_variables_destroy);
314 RAII_VAR(struct ast_variable *, headers, NULL, ast_variables_destroy);
315
316 switch (cmd) {
317 case TEST_INIT:
318 info->name = __func__;
319 info->category = "/res/ari/";
320 info->summary = "Test simple GET of an HTTP resource.";
321 info->description = "Test ARI binding logic.";
322 return AST_TEST_NOT_RUN;
323 case TEST_EXECUTE:
324 break;
325 }
326
327 fixture = setup_invocation_test();
328 response = response_alloc();
329 tail = ast_variable_list_append_hint(&get_params, NULL, ast_variable_new("get1", "get-one", __FILE__));
330 ast_assert(tail != NULL);
331 tail = ast_variable_list_append_hint(&get_params, NULL, ast_variable_new("get2", "get-two", __FILE__));
332 ast_assert(tail != NULL);
333 tail = ast_variable_list_append_hint(&get_params, NULL, ast_variable_new("api_key", "aritestro:aritestropw", __FILE__));
334 ast_assert(tail != NULL);
335
336 tail = ast_variable_list_append_hint(&headers, NULL, ast_variable_new("head1", "head-one", __FILE__));
337 ast_assert(tail != NULL);
338 tail = ast_variable_list_append_hint(&headers, NULL, ast_variable_new("head2", "head-two", __FILE__));
339 ast_assert(tail != NULL);
340
341 expected = ast_json_pack("{s: s, s: {s: s, s: s, s: s}, s: {s: s, s: s}, s: {}}",
342 "name", "foo_get",
343 "get_params",
344 "get1", "get-one",
345 "get2", "get-two",
346 "api_key", "aritestro:aritestropw",
347 "headers",
348 "head1", "head-one",
349 "head2", "head-two",
350 "path_vars");
351
352 ast_ari_invoke(NULL, ARI_INVOKE_SOURCE_TEST, NULL, "foo", AST_HTTP_GET, get_params, headers,
353 ast_json_null(), response);
354
355 ast_test_validate(test, 1 == invocation_count);
356 ast_test_validate(test, 200 == response->response_code);
357 ast_test_validate(test, ast_json_equal(expected, response->message));
358
359 return AST_TEST_PASS;
360}
361
362AST_TEST_DEFINE(invoke_wildcard)
363{
364 RAII_VAR(void *, fixture, NULL, tear_down_invocation_test);
365 RAII_VAR(struct ast_ari_response *, response, NULL, response_free);
366 RAII_VAR(struct ast_json *, expected, NULL, ast_json_unref);
367 struct ast_variable *tail = NULL;
368 RAII_VAR(struct ast_variable *, get_params, NULL, ast_variables_destroy);
369 struct ast_variable *headers = NULL;
370
371 switch (cmd) {
372 case TEST_INIT:
373 info->name = __func__;
374 info->category = "/res/ari/";
375 info->summary = "Test GET of a wildcard resource.";
376 info->description = "Test ARI binding logic.";
377 return AST_TEST_NOT_RUN;
378 case TEST_EXECUTE:
379 break;
380 }
381
382 fixture = setup_invocation_test();
383 response = response_alloc();
384 tail = ast_variable_list_append_hint(&get_params, NULL, ast_variable_new("api_key", "aritestro:aritestropw", __FILE__));
385 ast_assert(tail != NULL);
386
387 expected = ast_json_pack("{s: s, s: {s: s}, s: {}, s: {s: s}}",
388 "name", "bam_get",
389 "get_params",
390 "api_key", "aritestro:aritestropw",
391 "headers",
392 "path_vars",
393 "bam", "foshizzle");
394
395 ast_ari_invoke(NULL, ARI_INVOKE_SOURCE_TEST, NULL, "foo/foshizzle", AST_HTTP_GET, get_params, headers,
396 ast_json_null(), response);
397
398 ast_test_validate(test, 1 == invocation_count);
399 ast_test_validate(test, 200 == response->response_code);
400 ast_test_validate(test, ast_json_equal(expected, response->message));
401
402 return AST_TEST_PASS;
403}
404
406 struct ast_test *test, const char *creds, int expect_pass, int expect_rc)
407{
408 RAII_VAR(void *, fixture, NULL, tear_down_invocation_test);
409 RAII_VAR(struct ast_ari_response *, response, NULL, response_free);
410 RAII_VAR(struct ast_json *, expected, NULL, ast_json_unref);
411 struct ast_variable *tail = NULL;
412 RAII_VAR(struct ast_variable *, get_params, NULL, ast_variables_destroy);
413 struct ast_variable *headers = NULL;
414
415 fixture = setup_invocation_test();
416 response = response_alloc();
417 tail = ast_variable_list_append_hint(&get_params, NULL, ast_variable_new("api_key", creds, __FILE__));
418 ast_assert(tail != NULL);
419
420 expected = ast_json_pack("{s: s, s: {s: s}, s: {}, s: {s: s}}",
421 "name", "bang_delete",
422 "get_params",
423 "api_key", creds,
424 "headers",
425 "path_vars",
426 "bam", "foshizzle");
427
428 ast_ari_invoke(NULL, ARI_INVOKE_SOURCE_TEST, NULL, "foo/foshizzle/bang", AST_HTTP_DELETE, get_params, headers,
429 ast_json_null(), response);
430
431 ast_test_validate(test, expect_pass == invocation_count);
432 ast_test_validate(test, expect_rc == response->response_code);
433 ast_test_validate(test, ast_json_equal(expected, response->message) == expect_pass);
434
435 return AST_TEST_PASS;
436}
437
438AST_TEST_DEFINE(invoke_delete)
439{
440 switch (cmd) {
441 case TEST_INIT:
442 info->name = __func__;
443 info->category = "/res/ari/";
444 info->summary = "Test DELETE of an HTTP resource.";
445 info->description = "Test ARI binding logic.";
446 return AST_TEST_NOT_RUN;
447 case TEST_EXECUTE:
448 break;
449 }
450
451 return invoke_delete_common(info, cmd, test, "aritest:aritestpw", 1, 204);
452}
453
454AST_TEST_DEFINE(invoke_delete_forbidden)
455{
456 switch (cmd) {
457 case TEST_INIT:
458 info->name = __func__;
459 info->category = "/res/ari/";
460 info->summary = "Test forbidden DELETE of an HTTP resource.";
461 info->description = "Test ARI binding logic.";
462 return AST_TEST_NOT_RUN;
463 case TEST_EXECUTE:
464 break;
465 }
466
467 return invoke_delete_common(info, cmd, test, "aritestro:aritestropw", 0, 403);
468}
469
470AST_TEST_DEFINE(invoke_post)
471{
472 RAII_VAR(void *, fixture, NULL, tear_down_invocation_test);
473 RAII_VAR(struct ast_ari_response *, response, NULL, response_free);
474 RAII_VAR(struct ast_json *, expected, NULL, ast_json_unref);
475 struct ast_variable *tail = NULL;
476 RAII_VAR(struct ast_variable *, get_params, NULL, ast_variables_destroy);
477 RAII_VAR(struct ast_variable *, headers, NULL, ast_variables_destroy);
478
479 switch (cmd) {
480 case TEST_INIT:
481 info->name = __func__;
482 info->category = "/res/ari/";
483 info->summary = "Test POST of an HTTP resource.";
484 info->description = "Test ARI binding logic.";
485 return AST_TEST_NOT_RUN;
486 case TEST_EXECUTE:
487 break;
488 }
489
490 fixture = setup_invocation_test();
491 response = response_alloc();
492 tail = ast_variable_list_append_hint(&get_params, NULL, ast_variable_new("get1", "get-one", __FILE__));
493 ast_assert(tail != NULL);
494 tail = ast_variable_list_append_hint(&get_params, NULL, ast_variable_new("get2", "get-two", __FILE__));
495 ast_assert(tail != NULL);
496 tail = ast_variable_list_append_hint(&get_params, NULL, ast_variable_new("api_key", "aritest:aritestpw", __FILE__));
497 ast_assert(tail != NULL);
498
499 tail = ast_variable_list_append_hint(&headers, NULL, ast_variable_new("head1", "head-one", __FILE__));
500 ast_assert(tail != NULL);
501 tail = ast_variable_list_append_hint(&headers, NULL, ast_variable_new("head2", "head-two", __FILE__));
502 ast_assert(tail != NULL);
503
504 expected = ast_json_pack("{s: s, s: {s: s, s: s, s: s}, s: {s: s, s: s}, s: {}}",
505 "name", "bar_post",
506 "get_params",
507 "get1", "get-one",
508 "get2", "get-two",
509 "api_key", "aritest:aritestpw",
510 "headers",
511 "head1", "head-one",
512 "head2", "head-two",
513 "path_vars");
514
515 ast_ari_invoke(NULL, ARI_INVOKE_SOURCE_TEST, NULL, "foo/bar", AST_HTTP_POST, get_params, headers,
516 ast_json_null(), response);
517
518 ast_test_validate(test, 1 == invocation_count);
519 ast_test_validate(test, 200 == response->response_code);
520 ast_test_validate(test, ast_json_equal(expected, response->message));
521
522 return AST_TEST_PASS;
523}
524
525AST_TEST_DEFINE(invoke_bad_post)
526{
527 RAII_VAR(void *, fixture, NULL, tear_down_invocation_test);
528 RAII_VAR(struct ast_ari_response *, response, NULL, response_free);
529 struct ast_variable *tail = NULL;
530 RAII_VAR(struct ast_variable *, get_params, NULL, ast_variables_destroy);
531 struct ast_variable *headers = NULL;
532
533 switch (cmd) {
534 case TEST_INIT:
535 info->name = __func__;
536 info->category = "/res/ari/";
537 info->summary = "Test POST on a resource that doesn't support it.";
538 info->description = "Test ARI binding logic.";
539 return AST_TEST_NOT_RUN;
540 case TEST_EXECUTE:
541 break;
542 }
543
544 fixture = setup_invocation_test();
545 response = response_alloc();
546
547 tail = ast_variable_list_append_hint(&get_params, NULL, ast_variable_new("api_key", "aritest:aritestpw", __FILE__));
548 ast_assert(tail != NULL);
549
550 ast_ari_invoke(NULL, ARI_INVOKE_SOURCE_TEST, NULL, "foo", AST_HTTP_POST, get_params, headers,
551 ast_json_null(), response);
552
553 ast_test_validate(test, 0 == invocation_count);
554 ast_test_validate(test, 405 == response->response_code);
555
556 return AST_TEST_PASS;
557}
558
559AST_TEST_DEFINE(invoke_no_user)
560{
561 RAII_VAR(void *, fixture, NULL, tear_down_invocation_test);
562 RAII_VAR(struct ast_ari_response *, response, NULL, response_free);
563 struct ast_variable *get_params = NULL;
564 struct ast_variable *headers = NULL;
565
566 switch (cmd) {
567 case TEST_INIT:
568 info->name = __func__;
569 info->category = "/res/ari/";
570 info->summary = "Test POST on a resource that doesn't support it.";
571 info->description = "Test ARI binding logic.";
572 return AST_TEST_NOT_RUN;
573 case TEST_EXECUTE:
574 break;
575 }
576
577 fixture = setup_invocation_test();
578 response = response_alloc();
579 ast_ari_invoke(NULL, ARI_INVOKE_SOURCE_TEST, NULL, "foo", AST_HTTP_POST, get_params, headers,
580 ast_json_null(), response);
581
582 ast_test_validate(test, 0 == invocation_count);
583 ast_test_validate(test, 401 == response->response_code);
584
585 return AST_TEST_PASS;
586}
587
588AST_TEST_DEFINE(invoke_not_found)
589{
590 RAII_VAR(void *, fixture, NULL, tear_down_invocation_test);
591 RAII_VAR(struct ast_ari_response *, response, NULL, response_free);
592 struct ast_variable *tail = NULL;
593 RAII_VAR(struct ast_variable *, get_params, NULL, ast_variables_destroy);
594 struct ast_variable *headers = NULL;
595
596 switch (cmd) {
597 case TEST_INIT:
598 info->name = __func__;
599 info->category = "/res/ari/";
600 info->summary = "Test GET on a resource that does not exist.";
601 info->description = "Test ARI binding logic.";
602 return AST_TEST_NOT_RUN;
603 case TEST_EXECUTE:
604 break;
605 }
606
607 fixture = setup_invocation_test();
608 response = response_alloc();
609
610 tail = ast_variable_list_append_hint(&get_params, NULL, ast_variable_new("api_key", "aritest:aritestpw", __FILE__));
611 ast_assert(tail != NULL);
612
613 ast_ari_invoke(NULL, ARI_INVOKE_SOURCE_TEST, NULL, "foo/fizzle/i-am-not-a-resource", AST_HTTP_GET, get_params, headers,
614 ast_json_null(), response);
615
616 ast_test_validate(test, 0 == invocation_count);
617 ast_test_validate(test, 404 == response->response_code);
618
619 return AST_TEST_PASS;
620}
621
622static int unload_module(void)
623{
624 AST_TEST_UNREGISTER(get_docs);
625 AST_TEST_UNREGISTER(get_docs_nohost);
626 AST_TEST_UNREGISTER(get_docs_notfound);
627 AST_TEST_UNREGISTER(get_docs_hackerz);
628 AST_TEST_UNREGISTER(invoke_get);
629 AST_TEST_UNREGISTER(invoke_wildcard);
630 AST_TEST_UNREGISTER(invoke_delete);
631 AST_TEST_UNREGISTER(invoke_delete_forbidden);
632 AST_TEST_UNREGISTER(invoke_post);
633 AST_TEST_UNREGISTER(invoke_bad_post);
634 AST_TEST_UNREGISTER(invoke_no_user);
635 AST_TEST_UNREGISTER(invoke_not_found);
636 return 0;
637}
638
639static int load_module(void)
640{
641 AST_TEST_REGISTER(get_docs);
642 AST_TEST_REGISTER(get_docs_nohost);
643 AST_TEST_REGISTER(get_docs_notfound);
644 AST_TEST_REGISTER(get_docs_hackerz);
645 AST_TEST_REGISTER(invoke_get);
646 AST_TEST_REGISTER(invoke_wildcard);
647 AST_TEST_REGISTER(invoke_delete);
648 AST_TEST_REGISTER(invoke_delete_forbidden);
649 AST_TEST_REGISTER(invoke_post);
650 AST_TEST_REGISTER(invoke_bad_post);
651 AST_TEST_REGISTER(invoke_no_user);
652 AST_TEST_REGISTER(invoke_not_found);
654}
655
657 .support_level = AST_MODULE_SUPPORT_CORE,
658 .load = load_module,
659 .unload = unload_module,
660 .requires = "res_ari",
Asterisk RESTful API hooks.
@ ARI_INVOKE_SOURCE_TEST
Definition ari.h:150
int ast_ari_remove_handler(struct stasis_rest_handlers *handler)
Definition res_ari.c:155
void ast_ari_get_docs(const char *uri, const char *prefix, struct ast_variable *headers, struct ast_ari_response *response)
Definition res_ari.c:818
int ast_ari_add_handler(struct stasis_rest_handlers *handler)
Definition res_ari.c:132
enum ast_ari_invoke_result ast_ari_invoke(struct ast_tcptls_session_instance *ser, enum ast_ari_invoke_source source, const struct ast_http_uri *urih, const char *uri, enum ast_http_method method, struct ast_variable *get_params, struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
Definition res_ari.c:612
Asterisk main include file. File version handling, generic pbx functions.
#define ast_free(a)
Definition astmm.h:180
#define ast_calloc(num, len)
A wrapper for calloc()
Definition astmm.h:202
static const char name[]
Definition format_mp3.c:68
@ AST_HTTP_DELETE
Definition http.h:64
@ AST_HTTP_POST
Definition http.h:61
@ AST_HTTP_GET
Definition http.h:60
#define ast_variable_new(name, value, filename)
struct ast_variable * ast_variable_list_append_hint(struct ast_variable **head, struct ast_variable *search_hint, struct ast_variable *new_var)
Appends a variable list to the end of another list.
void ast_variables_destroy(struct ast_variable *var)
Free variable list.
Definition extconf.c:1260
struct ast_json * ast_json_string_create(const char *value)
Construct a JSON string from value.
Definition json.c:278
struct ast_json * ast_json_null(void)
Get the JSON null value.
Definition json.c:248
void ast_json_unref(struct ast_json *value)
Decrease refcount on value. If refcount reaches zero, value is freed.
Definition json.c:73
int ast_json_equal(const struct ast_json *lhs, const struct ast_json *rhs)
Compare two JSON objects.
Definition json.c:357
struct ast_json * ast_json_pack(char const *format,...)
Helper for creating complex JSON values.
Definition json.c:612
int ast_json_object_set(struct ast_json *object, const char *key, struct ast_json *value)
Set a field in a JSON object.
Definition json.c:414
const char * ast_json_string_get(const struct ast_json *string)
Get the value of a JSON string.
Definition json.c:283
struct ast_json * ast_json_object_get(struct ast_json *object, const char *key)
Get a field from a JSON object.
Definition json.c:407
Asterisk module definitions.
@ AST_MODFLAG_DEFAULT
Definition module.h:329
#define AST_MODULE_INFO(keystr, flags_to_set, desc, fields...)
Definition module.h:557
@ AST_MODULE_SUPPORT_CORE
Definition module.h:121
#define ASTERISK_GPL_KEY
The text the key() function should return.
Definition module.h:46
@ AST_MODULE_LOAD_SUCCESS
Definition module.h:70
#define NULL
Definition resample.c:96
#define ast_str_create(init_len)
Create a malloc'ed dynamic length string.
Definition strings.h:659
struct ast_str * headers
Definition ari.h:105
struct ast_json * message
Definition ari.h:103
int response_code
Definition ari.h:108
Abstract JSON element (object, array, string, int, ...).
Contains all the initialization information required to store a new test definition.
Definition test.h:235
Structure for variables, used for configurations and for channel variables.
struct ast_variable * next
Handler for a single RESTful path segment.
Definition ari.h:69
const char * path_segment
Definition ari.h:71
Test Framework API.
ast_test_command
Definition test.h:199
@ TEST_INIT
Definition test.h:200
@ TEST_EXECUTE
Definition test.h:201
#define AST_TEST_REGISTER(cb)
Definition test.h:127
#define AST_TEST_UNREGISTER(cb)
Definition test.h:128
#define AST_TEST_DEFINE(hdr)
Definition test.h:126
ast_test_result_state
Definition test.h:193
@ AST_TEST_PASS
Definition test.h:195
@ AST_TEST_NOT_RUN
Definition test.h:194
static void response_free(struct ast_ari_response *resp)
Definition test_ari.c:167
#define HANDLER(name, response_code)
Definition test_ari.c:97
static enum ast_test_result_state invoke_delete_common(struct ast_test_info *info, enum ast_test_command cmd, struct ast_test *test, const char *creds, int expect_pass, int expect_rc)
Definition test_ari.c:405
static void * setup_invocation_test(void)
Definition test_ari.c:181
static struct stasis_rest_handlers test_root
Definition test_ari.c:142
static void handler(const char *name, int response_code, struct ast_variable *get_params, struct ast_variable *path_vars, struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
Definition test_ari.c:59
static struct ast_ari_response * response_alloc(void)
Definition test_ari.c:156
static struct stasis_rest_handlers bar
Definition test_ari.c:125
static int invocation_count
Definition test_ari.c:53
static struct stasis_rest_handlers bam
Definition test_ari.c:133
static int load_module(void)
Definition test_ari.c:639
static int unload_module(void)
Definition test_ari.c:622
static void tear_down_invocation_test(void *ignore)
Definition test_ari.c:193
static struct stasis_rest_handlers bang
Definition test_ari.c:116
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Definition utils.h:981
#define ast_assert(a)
Definition utils.h:779