76 for (; get_params !=
NULL; get_params = get_params->
next) {
80 for (; path_vars !=
NULL; path_vars = path_vars->
next) {
84 for (; headers !=
NULL; headers = headers->
next) {
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) \
105 handler(#name, response_code, get_params, path_vars, headers, body, response); \
140 .children = { &
bang }
206 const char *basePath;
210 info->name = __func__;
211 info->category =
"/res/ari/";
212 info->summary =
"Test simple API get.";
213 info->description =
"Test ARI binding logic.";
222 ast_test_validate(
test, 200 == response->response_code);
226 ast_test_validate(
test,
NULL != basePathJson);
228 ast_test_validate(
test, 0 == strcmp(
"http://stasis.asterisk.org/ari", basePath));
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.";
252 ast_test_validate(
test, 200 == response->response_code);
256 ast_test_validate(
test,
NULL == basePathJson);
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.";
279 ast_test_validate(
test, 404 == response->response_code);
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.";
302 ast_test_validate(
test, 404 == response->response_code);
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.";
341 expected =
ast_json_pack(
"{s: s, s: {s: s, s: s, s: s}, s: {s: s, s: s}, s: {}}",
346 "api_key",
"aritestro:aritestropw",
356 ast_test_validate(
test, 200 == response->response_code);
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.";
387 expected =
ast_json_pack(
"{s: s, s: {s: s}, s: {}, s: {s: s}}",
390 "api_key",
"aritestro:aritestropw",
399 ast_test_validate(
test, 200 == response->response_code);
406 struct ast_test *
test,
const char *creds,
int expect_pass,
int expect_rc)
420 expected =
ast_json_pack(
"{s: s, s: {s: s}, s: {}, s: {s: s}}",
421 "name",
"bang_delete",
432 ast_test_validate(
test, expect_rc == response->response_code);
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.";
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.";
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.";
504 expected =
ast_json_pack(
"{s: s, s: {s: s, s: s, s: s}, s: {s: s, s: s}, s: {}}",
509 "api_key",
"aritest:aritestpw",
519 ast_test_validate(
test, 200 == response->response_code);
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.";
554 ast_test_validate(
test, 405 == response->response_code);
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.";
583 ast_test_validate(
test, 401 == response->response_code);
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.";
617 ast_test_validate(
test, 404 == response->response_code);
660 .
requires =
"res_ari",
Asterisk RESTful API hooks.
int ast_ari_remove_handler(struct stasis_rest_handlers *handler)
void ast_ari_get_docs(const char *uri, const char *prefix, struct ast_variable *headers, struct ast_ari_response *response)
int ast_ari_add_handler(struct stasis_rest_handlers *handler)
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)
Asterisk main include file. File version handling, generic pbx functions.
#define ast_calloc(num, len)
A wrapper for calloc()
#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.
struct ast_json * ast_json_string_create(const char *value)
Construct a JSON string from value.
struct ast_json * ast_json_null(void)
Get the JSON null value.
void ast_json_unref(struct ast_json *value)
Decrease refcount on value. If refcount reaches zero, value is freed.
int ast_json_equal(const struct ast_json *lhs, const struct ast_json *rhs)
Compare two JSON objects.
struct ast_json * ast_json_pack(char const *format,...)
Helper for creating complex JSON values.
int ast_json_object_set(struct ast_json *object, const char *key, struct ast_json *value)
Set a field in a JSON object.
const char * ast_json_string_get(const struct ast_json *string)
Get the value of a JSON string.
struct ast_json * ast_json_object_get(struct ast_json *object, const char *key)
Get a field from a JSON object.
Asterisk module definitions.
#define AST_MODULE_INFO(keystr, flags_to_set, desc, fields...)
@ AST_MODULE_SUPPORT_CORE
#define ASTERISK_GPL_KEY
The text the key() function should return.
@ AST_MODULE_LOAD_SUCCESS
#define ast_str_create(init_len)
Create a malloc'ed dynamic length string.
struct ast_json * message
Abstract JSON element (object, array, string, int, ...).
Contains all the initialization information required to store a new test definition.
Structure for variables, used for configurations and for channel variables.
struct ast_variable * next
Handler for a single RESTful path segment.
const char * path_segment
#define AST_TEST_REGISTER(cb)
#define AST_TEST_UNREGISTER(cb)
#define AST_TEST_DEFINE(hdr)
static void response_free(struct ast_ari_response *resp)
#define HANDLER(name, response_code)
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)
static void * setup_invocation_test(void)
static struct stasis_rest_handlers test_root
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)
static struct ast_ari_response * response_alloc(void)
static struct stasis_rest_handlers bar
static int invocation_count
static struct stasis_rest_handlers bam
static int load_module(void)
static int unload_module(void)
static void tear_down_invocation_test(void *ignore)
static struct stasis_rest_handlers bang
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.