diff options
author | David M. Lee <dlee@digium.com> | 2013-07-03 17:58:45 +0000 |
---|---|---|
committer | David M. Lee <dlee@digium.com> | 2013-07-03 17:58:45 +0000 |
commit | a75fd32212c35b41143442bd757387fad636177a (patch) | |
tree | 461033acf36f4596d8fc9800a1195e12207b3ea2 /tests/test_utils.c | |
parent | c4adaf91067559dd5aa90577e181693abade0602 (diff) |
ARI - channel recording support
This patch is the first step in adding recording support to the
Asterisk REST Interface.
Recordings are stored in /var/spool/recording. Since recordings may be
destructive (overwriting existing files), the API rejects attempts to
escape the recording directory (avoiding issues if someone attempts to
record to ../../lib/sounds/greeting, for example).
(closes issue ASTERISK-21594)
(closes issue ASTERISK-21581)
Review: https://reviewboard.asterisk.org/r/2612/
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@393550 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'tests/test_utils.c')
-rw-r--r-- | tests/test_utils.c | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/tests/test_utils.c b/tests/test_utils.c index 7cc4cf611..f956e5b27 100644 --- a/tests/test_utils.c +++ b/tests/test_utils.c @@ -42,6 +42,8 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$"); #include "asterisk/channel.h" #include "asterisk/module.h" +#include <sys/stat.h> + AST_TEST_DEFINE(uri_encode_decode_test) { int res = AST_TEST_PASS; @@ -421,6 +423,93 @@ AST_TEST_DEFINE(agi_loaded_test) return res; } +AST_TEST_DEFINE(safe_mkdir_test) +{ + char base_path[] = "/tmp/safe_mkdir.XXXXXX"; + char path[80] = {}; + int res; + struct stat actual; + + switch (cmd) { + case TEST_INIT: + info->name = __func__; + info->category = "/main/utils/"; + info->summary = "Safe mkdir test"; + info->description = + "This test ensures that ast_safe_mkdir does what it is " + "supposed to"; + return AST_TEST_NOT_RUN; + case TEST_EXECUTE: + break; + } + + if (mkdtemp(base_path) == NULL) { + ast_test_status_update(test, "Failed to create tmpdir for test\n"); + return AST_TEST_FAIL; + } + + snprintf(path, sizeof(path), "%s/should_work", base_path); + res = ast_safe_mkdir(base_path, path, 0777); + ast_test_validate(test, 0 == res); + res = stat(path, &actual); + ast_test_validate(test, 0 == res); + ast_test_validate(test, S_ISDIR(actual.st_mode)); + + snprintf(path, sizeof(path), "%s/should/also/work", base_path); + res = ast_safe_mkdir(base_path, path, 0777); + ast_test_validate(test, 0 == res); + res = stat(path, &actual); + ast_test_validate(test, 0 == res); + ast_test_validate(test, S_ISDIR(actual.st_mode)); + + snprintf(path, sizeof(path), "%s/even/this/../should/work", base_path); + res = ast_safe_mkdir(base_path, path, 0777); + ast_test_validate(test, 0 == res); + snprintf(path, sizeof(path), "%s/even/should/work", base_path); + res = stat(path, &actual); + ast_test_validate(test, 0 == res); + ast_test_validate(test, S_ISDIR(actual.st_mode)); + + snprintf(path, sizeof(path), + "%s/surprisingly/this/should//////////////////work", base_path); + res = ast_safe_mkdir(base_path, path, 0777); + ast_test_validate(test, 0 == res); + snprintf(path, sizeof(path), + "%s/surprisingly/this/should/work", base_path); + res = stat(path, &actual); + ast_test_validate(test, 0 == res); + ast_test_validate(test, S_ISDIR(actual.st_mode)); + + snprintf(path, sizeof(path), "/should_not_work"); + res = ast_safe_mkdir(base_path, path, 0777); + ast_test_validate(test, 0 != res); + ast_test_validate(test, EPERM == errno); + res = stat(path, &actual); + ast_test_validate(test, 0 != res); + ast_test_validate(test, ENOENT == errno); + + snprintf(path, sizeof(path), "%s/../nor_should_this", base_path); + res = ast_safe_mkdir(base_path, path, 0777); + ast_test_validate(test, 0 != res); + ast_test_validate(test, EPERM == errno); + strncpy(path, "/tmp/nor_should_this", sizeof(path)); + res = stat(path, &actual); + ast_test_validate(test, 0 != res); + ast_test_validate(test, ENOENT == errno); + + snprintf(path, sizeof(path), + "%s/this/especially/should/not/../../../../../work", base_path); + res = ast_safe_mkdir(base_path, path, 0777); + ast_test_validate(test, 0 != res); + ast_test_validate(test, EPERM == errno); + strncpy(path, "/tmp/work", sizeof(path)); + res = stat(path, &actual); + ast_test_validate(test, 0 != res); + ast_test_validate(test, ENOENT == errno); + + return AST_TEST_PASS; +} + AST_TEST_DEFINE(crypt_test) { RAII_VAR(char *, password_crypted, NULL, ast_free); @@ -467,6 +556,7 @@ static int unload_module(void) AST_TEST_UNREGISTER(crypto_loaded_test); AST_TEST_UNREGISTER(adsi_loaded_test); AST_TEST_UNREGISTER(agi_loaded_test); + AST_TEST_UNREGISTER(safe_mkdir_test); AST_TEST_UNREGISTER(crypt_test); return 0; } @@ -481,6 +571,7 @@ static int load_module(void) AST_TEST_REGISTER(crypto_loaded_test); AST_TEST_REGISTER(adsi_loaded_test); AST_TEST_REGISTER(agi_loaded_test); + AST_TEST_REGISTER(safe_mkdir_test); AST_TEST_REGISTER(crypt_test); return AST_MODULE_LOAD_SUCCESS; } |