44 #define CATEGORY "/res/http_media_cache/" 46 #define TEST_URI "test_media_cache" 66 #define VALIDATE_EXPIRES(test, bucket_file, expected, delta) do { \ 67 RAII_VAR(struct ast_bucket_metadata *, metadata, ast_bucket_file_metadata_get((bucket_file), "__actual_expires"), ao2_cleanup); \ 69 ast_test_validate(test, metadata != NULL); \ 70 ast_test_validate(test, sscanf(metadata->value, "%d", &actual_expires) == 1); \ 71 ast_test_status_update(test, "Checking %d >= %d and %d <= %d\n", \ 72 (int) ((expected) + (delta)), actual_expires, \ 73 (int) ((expected) - (delta)), actual_expires); \ 74 ast_test_validate(test, (((expected) + (delta) >= actual_expires) && ((expected) - (delta) <= actual_expires))); \ 77 #define VALIDATE_STR_METADATA(test, bucket_file, key, expected) do { \ 78 RAII_VAR(struct ast_bucket_metadata *, metadata, ast_bucket_file_metadata_get((bucket_file), (key)), ao2_cleanup); \ 79 ast_test_validate(test, metadata != NULL); \ 80 ast_test_validate(test, !strcmp(metadata->value, (expected))); \ 83 #define SET_OR_APPEND_CACHE_CONTROL(str) do { \ 84 if (!ast_str_strlen((str))) { \ 85 ast_str_set(&(str), 0, "%s", "cache-control: "); \ 87 ast_str_append(&(str), 0, "%s", ", "); \ 93 char file_name[64] =
"/tmp/test-media-cache-XXXXXX";
107 fd = mkstemp(file_name);
113 memset(buf, 1,
sizeof(buf));
114 if (write(fd, buf,
sizeof(buf)) !=
sizeof(buf)) {
121 fd = open(file_name, 0);
157 ast_strftime(tmbuf,
sizeof(tmbuf),
"%a, %d %b %Y %T %z", &now_time);
165 for (v = headers; v; v = v->
next) {
192 ast_http_error(ser, 418,
"I'm a Teapot",
"Please don't ask me to brew coffee.");
231 info->name = __func__;
233 info->summary =
"Test retrieval of a resource with Cache-Control directives that affect staleness";
235 "This test covers retrieval of a resource with the Cache-Control header,\n" 236 "which specifies no-cache and/or must-revalidate.";
242 snprintf(uri,
sizeof(uri),
"%s/%s",
server_uri,
"foo.wav");
251 ast_test_validate(
test, bucket_file !=
NULL);
259 ast_test_validate(
test, bucket_file !=
NULL);
269 ast_test_validate(
test, bucket_file !=
NULL);
280 ast_test_validate(
test, bucket_file !=
NULL);
288 ast_test_validate(
test, bucket_file !=
NULL);
298 ast_test_validate(
test, bucket_file !=
NULL);
313 info->name = __func__;
315 info->summary =
"Test retrieval of a resource with age specifiers in Cache-Control";
317 "This test covers retrieval of a resource with the Cache-Control header,\n" 318 "which specifies max-age and/or s-maxage. The test verifies proper precedence\n" 319 "ordering of the header attributes, along with its relation if the Expires\n" 320 "header is present.";
326 snprintf(uri,
sizeof(uri),
"%s/%s",
server_uri,
"foo.wav");
335 ast_test_validate(
test, bucket_file !=
NULL);
345 ast_test_validate(
test, bucket_file !=
NULL);
355 ast_test_validate(
test, bucket_file !=
NULL);
366 ast_test_validate(
test, bucket_file !=
NULL);
377 ast_test_validate(
test, bucket_file !=
NULL);
388 ast_test_validate(
test, bucket_file !=
NULL);
399 ast_test_validate(
test, bucket_file !=
NULL);
414 info->name = __func__;
416 info->summary =
"Test retrieval of an expired resource with an ETag";
418 "This test covers a staleness check of a resource with an ETag\n" 419 "that has also expired. It guarantees that even if a resource\n" 420 "is expired, we will still not consider it stale if the resource\n" 421 "has not changed per the ETag value.";
433 snprintf(uri,
sizeof(uri),
"%s/%s",
server_uri,
"foo.wav");
436 ast_test_validate(
test, bucket_file !=
NULL);
455 info->name = __func__;
457 info->summary =
"Test retrieval with explicit expiration";
459 "This test covers retrieving a resource that has an Expires.\n" 460 "After retrieval of the resource, staleness is checked. With\n" 461 "a non-expired resource, we expect the resource to not be stale.\n" 462 "When the expiration has occurred, we expect the staleness check\n" 474 snprintf(uri,
sizeof(uri),
"%s/%s",
server_uri,
"foo.wav");
477 ast_test_validate(
test, bucket_file !=
NULL);
489 ast_test_validate(
test, bucket_file !=
NULL);
505 info->name = __func__;
507 info->summary =
"Test retrieval with an ETag";
509 "This test covers retrieving a resource that has an ETag.\n" 510 "After retrieval of the resource, staleness is checked. With\n" 511 "matching ETags, we expect the resource to not be stale. When\n" 512 "the ETag does not match, we expect the resource to be stale.";
523 snprintf(uri,
sizeof(uri),
"%s/%s",
server_uri,
"foo.wav");
526 ast_test_validate(
test, bucket_file !=
NULL);
548 info->name = __func__;
550 info->summary =
"Test nominal retrieval";
552 "Test nominal retrieval of a resource.";
562 snprintf(uri,
sizeof(uri),
"%s/%s",
server_uri,
"foo.wav");
565 ast_test_validate(
test, bucket_file !=
NULL);
581 info->name = __func__;
583 info->summary =
"Test nominal creation";
585 "Test nominal creation of a resource.";
595 snprintf(uri,
sizeof(uri),
"%s/%s",
server_uri,
"foo.wav");
598 ast_test_validate(
test, bucket_file !=
NULL);
612 const char *bindport;
700 .requires =
"res_http_media_cache",
struct ast_variable * next
Contains all the initialization information required to store a new test definition.
Asterisk main include file. File version handling, generic pbx functions.
void ast_http_error(struct ast_tcptls_session_instance *ser, int status, const char *title, const char *text)
Send HTTP error message and close socket.
int ast_test_register_init(const char *category, ast_test_init_cb_t *cb)
struct test_options::@511 cache_control
int ast_http_uri_link(struct ast_http_uri *urihandler)
Register a URI handler.
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
#define CONFIG_STATUS_FILEINVALID
struct ast_bucket_file * ast_bucket_file_retrieve(const char *uri)
Retrieve a bucket file.
struct ast_tm * ast_localtime(const struct timeval *timep, struct ast_tm *p_tm, const char *zone)
Timezone-independent version of localtime_r(3).
Structure for variables, used for configurations and for channel variables.
void ast_http_uri_unlink(struct ast_http_uri *urihandler)
Unregister a URI handler.
#define AST_TEST_REGISTER(cb)
int ast_str_append(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Append to a thread local dynamic string.
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
struct ast_bucket_file * ast_bucket_file_alloc(const char *uri)
Allocate a new bucket file.
void ast_http_send(struct ast_tcptls_session_instance *ser, enum ast_http_method method, int status_code, const char *status_title, struct ast_str *http_header, struct ast_str *out, int fd, unsigned int static_content)
Generic function for sending HTTP/1.1 response.
#define ast_strlen_zero(foo)
Support for Private Asterisk HTTP Servers.
#define ast_config_load(filename, flags)
Load a config file.
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
#define ast_test_status_update(a, b, c...)
#define ao2_ref(o, delta)
void ast_config_destroy(struct ast_config *config)
Destroys a config.
int ast_bucket_file_delete(struct ast_bucket_file *file)
Delete a bucket file from backend storage.
int ast_bucket_file_is_stale(struct ast_bucket_file *file)
Retrieve whether or not the backing datastore views the bucket file as stale.
const char * ast_sorcery_object_get_id(const void *object)
Get the unique identifier of a sorcery object.
Bucket file structure, contains reference to file and information about it.
describes a server instance
#define CONFIG_STATUS_FILEUNCHANGED
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
#define AST_TEST_UNREGISTER(cb)
Module has failed to load, may be in an inconsistent state.
int ast_strftime(char *buf, size_t len, const char *format, const struct ast_tm *tm)
Special version of strftime(3) that handles fractions of a second. Takes the same arguments as strfti...
int ast_bucket_file_temporary_create(struct ast_bucket_file *file)
Common file snapshot creation callback for creating a temporary file.
Structure used to handle boolean flags.
AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_GLOBAL_SYMBOLS|AST_MODFLAG_LOAD_ORDER, "HTTP Phone Provisioning",.support_level=AST_MODULE_SUPPORT_EXTENDED,.load=load_module,.unload=unload_module,.reload=reload,.load_pri=AST_MODPRI_CHANNEL_DEPEND,.requires="http",)
size_t ast_str_strlen(const struct ast_str *buf)
Returns the current length of the string stored within buf.
#define S_OR(a, b)
returns the equivalent of logic or for strings: first one if not empty, otherwise second one...
int attribute_pure ast_false(const char *val)
Make sure something is false. Determine if a string containing a boolean value is "false"...
Definition of a URI handler.
const char * ast_config_option(struct ast_config *cfg, const char *cat, const char *var)
Retrieve a configuration variable within the configuration set.
int error(const char *format,...)
ast_http_method
HTTP Request methods known by Asterisk.
#define ASTERISK_GPL_KEY
The text the key() function should return.
Asterisk module definitions.
void ast_http_request_close_on_completion(struct ast_tcptls_session_instance *ser)
Request the HTTP connection be closed after this HTTP request.
int ast_bucket_file_create(struct ast_bucket_file *file)
Create a new bucket file in backend storage.
struct ast_sockaddr bindaddr
#define ast_str_create(init_len)
Create a malloc'ed dynamic length string.
static char prefix[MAX_PREFIX]