From a33877aacea27c19440ab9e673a376351c94f172 Mon Sep 17 00:00:00 2001 From: Chris Rienzo Date: Sun, 14 Jul 2019 12:24:30 -0400 Subject: [PATCH] FS-11931 [mod_http_cache] convert tests to use switch_test --- .gitignore | 12 ++ configure.ac | 1 + .../applications/mod_http_cache/Makefile.am | 2 + src/mod/applications/mod_http_cache/aws.c | 12 +- src/mod/applications/mod_http_cache/aws.h | 13 +- src/mod/applications/mod_http_cache/common.c | 2 +- src/mod/applications/mod_http_cache/common.h | 2 +- .../mod_http_cache/test/Makefile.am | 4 + .../mod_http_cache/test/test_aws.c | 140 ++++++++++++++++++ .../mod_http_cache/test_aws/Makefile | 12 -- .../mod_http_cache/test_aws/main.c | 131 ---------------- .../mod_http_cache/test_aws/test.h | 113 -------------- .../mod_http_cache/test_aws/test_aws.c | 6 - 13 files changed, 170 insertions(+), 280 deletions(-) create mode 100644 src/mod/applications/mod_http_cache/test/Makefile.am create mode 100644 src/mod/applications/mod_http_cache/test/test_aws.c delete mode 100644 src/mod/applications/mod_http_cache/test_aws/Makefile delete mode 100644 src/mod/applications/mod_http_cache/test_aws/main.c delete mode 100644 src/mod/applications/mod_http_cache/test_aws/test.h delete mode 100644 src/mod/applications/mod_http_cache/test_aws/test_aws.c diff --git a/.gitignore b/.gitignore index d6aff02c1b..fb53ac2cf0 100644 --- a/.gitignore +++ b/.gitignore @@ -260,3 +260,15 @@ libs/libsilk-*/ libs/rabbitmq-c-*/ libs/rabbitmq-c-*.zip libs/ffmpeg-*/ + +src/mod/applications/mod_test/test/test_asr +src/mod/event_handlers/mod_rayo/test/test_iks +src/mod/event_handlers/mod_rayo/test/test_nlsml +src/mod/event_handlers/mod_rayo/test/test_srgs +src/mod/applications/mod_http_cache/test/Makefile +src/mod/applications/mod_http_cache/test/Makefile.in +src/mod/applications/mod_http_cache/test/test-suite.log +src/mod/applications/mod_http_cache/test/test_aws +src/mod/applications/mod_http_cache/test/test_aws.log +src/mod/applications/mod_http_cache/test/test_aws.trs + diff --git a/configure.ac b/configure.ac index 70b559c4f0..17dec43e16 100644 --- a/configure.ac +++ b/configure.ac @@ -1865,6 +1865,7 @@ AC_CONFIG_FILES([Makefile src/mod/applications/mod_hiredis/Makefile src/mod/applications/mod_httapi/Makefile src/mod/applications/mod_http_cache/Makefile + src/mod/applications/mod_http_cache/test/Makefile src/mod/applications/mod_ladspa/Makefile src/mod/applications/mod_lcr/Makefile src/mod/applications/mod_limit/Makefile diff --git a/src/mod/applications/mod_http_cache/Makefile.am b/src/mod/applications/mod_http_cache/Makefile.am index ad61e7a13b..4edb28826d 100644 --- a/src/mod/applications/mod_http_cache/Makefile.am +++ b/src/mod/applications/mod_http_cache/Makefile.am @@ -7,3 +7,5 @@ mod_http_cache_la_CFLAGS = $(AM_CFLAGS) mod_http_cache_la_CPPFLAGS = $(CURL_CFLAGS) $(AM_CPPFLAGS) mod_http_cache_la_LIBADD = $(switch_builddir)/libfreeswitch.la mod_http_cache_la_LDFLAGS = $(CURL_LIBS) -avoid-version -module -no-undefined -shared + +SUBDIRS=. test diff --git a/src/mod/applications/mod_http_cache/aws.c b/src/mod/applications/mod_http_cache/aws.c index 02ee58fde9..e6d488ef4f 100644 --- a/src/mod/applications/mod_http_cache/aws.c +++ b/src/mod/applications/mod_http_cache/aws.c @@ -47,7 +47,7 @@ * @param date header * @return the string_to_sign (must be freed) */ -char *aws_s3_string_to_sign(const char *verb, const char *bucket, const char *object, const char *content_type, const char *content_md5, const char *date) +static char *aws_s3_string_to_sign(const char *verb, const char *bucket, const char *object, const char *content_type, const char *content_md5, const char *date) { /* * String to sign has the following format: @@ -66,7 +66,7 @@ char *aws_s3_string_to_sign(const char *verb, const char *bucket, const char *ob * @param aws_secret_access_key secret access key * @return the signature buffer or NULL if missing input */ -char *aws_s3_signature(char *signature, int signature_length, const char *string_to_sign, const char *aws_secret_access_key) +static char *aws_s3_signature(char *signature, int signature_length, const char *string_to_sign, const char *aws_secret_access_key) { #if defined(HAVE_OPENSSL) unsigned int signature_raw_length = SHA1_LENGTH; @@ -107,7 +107,7 @@ char *aws_s3_signature(char *signature, int signature_length, const char *string * @param expires seconds since the epoch * @return presigned_url */ -char *aws_s3_presigned_url_create(const char *verb, const char *url, const char *base_domain, const char *content_type, const char *content_md5, const char *aws_access_key_id, const char *aws_secret_access_key, const char *expires) +SWITCH_DECLARE(char *) aws_s3_presigned_url_create(const char *verb, const char *url, const char *base_domain, const char *content_type, const char *content_md5, const char *aws_access_key_id, const char *aws_secret_access_key, const char *expires) { char signature[S3_SIGNATURE_LENGTH_MAX]; char signature_url_encoded[S3_SIGNATURE_LENGTH_MAX]; @@ -143,7 +143,7 @@ char *aws_s3_presigned_url_create(const char *verb, const char *url, const char * @param date header * @return signature for Authorization header */ -char *aws_s3_authentication_create(const char *verb, const char *url, const char *base_domain, const char *content_type, const char *content_md5, const char *aws_access_key_id, const char *aws_secret_access_key, const char *date) +static char *aws_s3_authentication_create(const char *verb, const char *url, const char *base_domain, const char *content_type, const char *content_md5, const char *aws_access_key_id, const char *aws_secret_access_key, const char *date) { char signature[S3_SIGNATURE_LENGTH_MAX]; char *string_to_sign; @@ -162,7 +162,7 @@ char *aws_s3_authentication_create(const char *verb, const char *url, const char return switch_mprintf("AWS %s:%s", aws_access_key_id, signature); } -switch_status_t aws_s3_config_profile(switch_xml_t xml, http_profile_t *profile) +SWITCH_DECLARE(switch_status_t) aws_s3_config_profile(switch_xml_t xml, http_profile_t *profile) { switch_status_t status = SWITCH_STATUS_SUCCESS; switch_xml_t base_domain_xml = switch_xml_child(xml, "base-domain"); @@ -217,7 +217,7 @@ switch_status_t aws_s3_config_profile(switch_xml_t xml, http_profile_t *profile) * @param url * @return updated headers */ -switch_curl_slist_t *aws_s3_append_headers(http_profile_t *profile, switch_curl_slist_t *headers, +SWITCH_DECLARE(switch_curl_slist_t) *aws_s3_append_headers(http_profile_t *profile, switch_curl_slist_t *headers, const char *verb, unsigned int content_length, const char *content_type, const char *url, const unsigned int block_num, char **query_string) { char date[256]; diff --git a/src/mod/applications/mod_http_cache/aws.h b/src/mod/applications/mod_http_cache/aws.h index 6b6b05d065..633dbc8d6f 100644 --- a/src/mod/applications/mod_http_cache/aws.h +++ b/src/mod/applications/mod_http_cache/aws.h @@ -36,17 +36,10 @@ /* (SHA1_LENGTH * 1.37 base64 bytes per byte * 3 url-encoded bytes per byte) */ #define S3_SIGNATURE_LENGTH_MAX 83 -switch_curl_slist_t *aws_s3_append_headers(http_profile_t *profile, switch_curl_slist_t *headers, +SWITCH_DECLARE(switch_curl_slist_t) *aws_s3_append_headers(http_profile_t *profile, switch_curl_slist_t *headers, const char *verb, unsigned int content_length, const char *content_type, const char *url, const unsigned int block_num, char **query_string); -switch_status_t aws_s3_config_profile(switch_xml_t xml, http_profile_t *profile); - -// the following functions are exposed only so that the unit tests still work -char *aws_s3_string_to_sign(const char *verb, const char *bucket, const char *object, const char *content_type, const char *content_md5, const char *date); -char *aws_s3_signature(char *signature, int signature_length, const char *string_to_sign, const char *aws_secret_access_key); -void aws_s3_parse_url(char *url, const char *base_domain, char **bucket, char **object); -char *aws_s3_presigned_url_create(const char *verb, const char *url, const char *base_domain, const char *content_type, const char *content_md5, const char *aws_access_key_id, const char *aws_secret_access_key, const char *expires); -char *aws_s3_authentication_create(const char *verb, const char *url, const char *base_domain, const char *content_type, const char *content_md5, const char *aws_access_key_id, const char *aws_secret_access_key, const char *date); - +SWITCH_DECLARE(switch_status_t) aws_s3_config_profile(switch_xml_t xml, http_profile_t *profile); +SWITCH_DECLARE(char *) aws_s3_presigned_url_create(const char *verb, const char *url, const char *base_domain, const char *content_type, const char *content_md5, const char *aws_access_key_id, const char *aws_secret_access_key, const char *expires); #endif diff --git a/src/mod/applications/mod_http_cache/common.c b/src/mod/applications/mod_http_cache/common.c index 0292ebd81c..13c43156d7 100644 --- a/src/mod/applications/mod_http_cache/common.c +++ b/src/mod/applications/mod_http_cache/common.c @@ -63,7 +63,7 @@ static char *my_strrstr(const char *haystack, const char *needle) return NULL; } -void parse_url(char *url, const char *base_domain, const char *default_base_domain, char **bucket, char **object) +SWITCH_DECLARE(void) parse_url(char *url, const char *base_domain, const char *default_base_domain, char **bucket, char **object) { char *bucket_start = NULL; char *bucket_end; diff --git a/src/mod/applications/mod_http_cache/common.h b/src/mod/applications/mod_http_cache/common.h index 1df0d88546..278af9b9d6 100644 --- a/src/mod/applications/mod_http_cache/common.h +++ b/src/mod/applications/mod_http_cache/common.h @@ -23,7 +23,7 @@ struct http_profile { typedef struct http_profile http_profile_t; -void parse_url(char *url, const char *base_domain, const char *default_base_domain, char **bucket, char **object); +SWITCH_DECLARE(void) parse_url(char *url, const char *base_domain, const char *default_base_domain, char **bucket, char **object); #endif diff --git a/src/mod/applications/mod_http_cache/test/Makefile.am b/src/mod/applications/mod_http_cache/test/Makefile.am new file mode 100644 index 0000000000..76561fca3b --- /dev/null +++ b/src/mod/applications/mod_http_cache/test/Makefile.am @@ -0,0 +1,4 @@ +bin_PROGRAMS = test_aws +AM_CFLAGS = $(SWITCH_AM_CFLAGS) +AM_LDFLAGS = $(switch_builddir)/libfreeswitch.la -avoid-version -no-undefined $(SWITCH_AM_LDFLAGS) ../mod_http_cache.la +TESTS = $(bin_PROGRAMS) diff --git a/src/mod/applications/mod_http_cache/test/test_aws.c b/src/mod/applications/mod_http_cache/test/test_aws.c new file mode 100644 index 0000000000..1d827e30d6 --- /dev/null +++ b/src/mod/applications/mod_http_cache/test/test_aws.c @@ -0,0 +1,140 @@ + +#include +#include +#include "../aws.c" + +FST_BEGIN() +{ +FST_SUITE_BEGIN(aws) +{ +FST_SETUP_BEGIN() +{ +} +FST_SETUP_END() + +FST_TEARDOWN_BEGIN() +{ +} +FST_TEARDOWN_END() + +FST_TEST_BEGIN(test_string_to_sign) +{ + fst_check_string_equals("GET\n\n\nFri, 17 May 2013 19:35:26 GMT\n/rienzo-vault/troporocks.mp3", aws_s3_string_to_sign("GET", "rienzo-vault", "troporocks.mp3", "", "", "Fri, 17 May 2013 19:35:26 GMT")); + fst_check_string_equals("GET\nc8fdb181845a4ca6b8fec737b3581d76\naudio/mpeg\nThu, 17 Nov 2005 18:49:58 GMT\n/foo/man.chu", aws_s3_string_to_sign("GET", "foo", "man.chu", "audio/mpeg", "c8fdb181845a4ca6b8fec737b3581d76", "Thu, 17 Nov 2005 18:49:58 GMT")); + fst_check_string_equals("\n\n\n\n//", aws_s3_string_to_sign("", "", "", "", "", "")); + fst_check_string_equals("\n\n\n\n//", aws_s3_string_to_sign(NULL, NULL, NULL, NULL, NULL, NULL)); + fst_check_string_equals("PUT\n\naudio/wav\nWed, 12 Jun 2013 13:16:58 GMT\n/bucket/voicemails/recording.wav", aws_s3_string_to_sign("PUT", "bucket", "voicemails/recording.wav", "audio/wav", "", "Wed, 12 Jun 2013 13:16:58 GMT")); +} +FST_TEST_END() + +FST_TEST_BEGIN(test_signature) +{ + char signature[S3_SIGNATURE_LENGTH_MAX]; + signature[0] = '\0'; + fst_check_string_equals("weGrLrc9HDlkYPTepVl0A9VYNlw=", aws_s3_signature(signature, S3_SIGNATURE_LENGTH_MAX, "GET\n\n\nFri, 17 May 2013 19:35:26 GMT\n/rienzo-vault/troporocks.mp3", "hOIZt1oeTX1JzINOMBoKf0BxONRZNQT1J8gIznLx")); + fst_check_string_equals("jZNOcbfWmD/A/f3hSvVzXZjM2HU=", aws_s3_signature(signature, S3_SIGNATURE_LENGTH_MAX, "PUT\nc8fdb181845a4ca6b8fec737b3581d76\ntext/html\nThu, 17 Nov 2005 18:49:58 GMT\nx-amz-magic:abracadabra\nx-amz-meta-author:foo@bar.com\n/quotes/nelson", "OtxrzxIsfpFjA7SwPzILwy8Bw21TLhquhboDYROV")); + fst_check_string_equals("5m+HAmc5JsrgyDelh9+a2dNrzN8=", aws_s3_signature(signature, S3_SIGNATURE_LENGTH_MAX, "GET\n\n\n\nx-amz-date:Thu, 17 Nov 2005 18:49:58 GMT\nx-amz-magic:abracadabra\n/quotes/nelson", "OtxrzxIsfpFjA7SwPzILwy8Bw21TLhquhboDYROV")); + fst_check_string_equals("OKA87rVp3c4kd59t8D3diFmTfuo=", aws_s3_signature(signature, S3_SIGNATURE_LENGTH_MAX, "", "OtxrzxIsfpFjA7SwPzILwy8Bw21TLhquhboDYROV")); + fst_check_string_equals("OKA87rVp3c4kd59t8D3diFmTfuo=", aws_s3_signature(signature, S3_SIGNATURE_LENGTH_MAX, NULL, "OtxrzxIsfpFjA7SwPzILwy8Bw21TLhquhboDYROV")); + fst_check(aws_s3_signature(signature, S3_SIGNATURE_LENGTH_MAX, "GET\n\n\n\nx-amz-date:Thu, 17 Nov 2005 18:49:58 GMT\nx-amz-magic:abracadabra\n/quotes/nelson", "") == NULL); + fst_check(aws_s3_signature(signature, S3_SIGNATURE_LENGTH_MAX, "", "") == NULL); + fst_check(aws_s3_signature(signature, S3_SIGNATURE_LENGTH_MAX, NULL, NULL) == NULL); + fst_check(aws_s3_signature(NULL, S3_SIGNATURE_LENGTH_MAX, "PUT\nc8fdb181845a4ca6b8fec737b3581d76\ntext/html\nThu, 17 Nov 2005 18:49:58 GMT\nx-amz-magic:abracadabra\nx-amz-meta-author:foo@bar.com\n/quotes/nelson", "OtxrzxIsfpFjA7SwPzILwy8Bw21TLhquhboDYROV") == NULL); + fst_check(aws_s3_signature(signature, 0, "PUT\nc8fdb181845a4ca6b8fec737b3581d76\ntext/html\nThu, 17 Nov 2005 18:49:58 GMT\nx-amz-magic:abracadabra\nx-amz-meta-author:foo@bar.com\n/quotes/nelson", "OtxrzxIsfpFjA7SwPzILwy8Bw21TLhquhboDYROV") == NULL); + fst_check_string_equals("jZNO", aws_s3_signature(signature, 5, "PUT\nc8fdb181845a4ca6b8fec737b3581d76\ntext/html\nThu, 17 Nov 2005 18:49:58 GMT\nx-amz-magic:abracadabra\nx-amz-meta-author:foo@bar.com\n/quotes/nelson", "OtxrzxIsfpFjA7SwPzILwy8Bw21TLhquhboDYROV")); +} +FST_TEST_END() + +FST_TEST_BEGIN(test_parse_url) +{ + char *bucket; + char *object; + char url[512] = { 0 }; + + snprintf(url, sizeof(url), "http://quotes.s3.amazonaws.com/nelson"); + parse_url(url, NULL, "s3", &bucket, &object); + fst_check_string_equals("quotes", bucket); + fst_check_string_equals("nelson", object); + + snprintf(url, sizeof(url), "https://quotes.s3.amazonaws.com/nelson.mp3"); + parse_url(url, NULL, "s3", &bucket, &object); + fst_check_string_equals("quotes", bucket); + fst_check_string_equals("nelson.mp3", object); + + snprintf(url, sizeof(url), "http://s3.amazonaws.com/quotes/nelson"); + parse_url(url, NULL, "s3", &bucket, &object); + fst_check(bucket == NULL); + fst_check(object == NULL); + + snprintf(url, sizeof(url), "http://quotes/quotes/nelson"); + parse_url(url, NULL, "s3", &bucket, &object); + fst_check(bucket == NULL); + fst_check(object == NULL); + + snprintf(url, sizeof(url), "http://quotes.s3.amazonaws.com/"); + parse_url(url, NULL, "s3", &bucket, &object); + fst_check(bucket == NULL); + fst_check(object == NULL); + + snprintf(url, sizeof(url), "http://quotes.s3.amazonaws.com"); + parse_url(url, NULL, "s3", &bucket, &object); + fst_check(bucket == NULL); + fst_check(object == NULL); + + snprintf(url, sizeof(url), "http://quotes"); + parse_url(url, NULL, "s3", &bucket, &object); + fst_check(bucket == NULL); + fst_check(object == NULL); + + snprintf(url, sizeof(url), ""); + parse_url(url, NULL, "s3", &bucket, &object); + fst_check(bucket == NULL); + fst_check(object == NULL); + + parse_url(NULL, NULL, "s3", &bucket, &object); + fst_check(bucket == NULL); + fst_check(object == NULL); + + snprintf(url, sizeof(url), "http://bucket.s3.amazonaws.com/voicemails/recording.wav"); + parse_url(url, NULL, "s3", &bucket, &object); + fst_check_string_equals("bucket", bucket); + fst_check_string_equals("voicemails/recording.wav", object); + + snprintf(url, sizeof(url), "https://my-bucket-with-dash.s3-us-west-2.amazonaws.com/greeting/file/1002/Lumino.mp3"); + parse_url(url, NULL, "s3", &bucket, &object); + fst_check_string_equals("my-bucket-with-dash", bucket); + fst_check_string_equals("greeting/file/1002/Lumino.mp3", object); + + snprintf(url, sizeof(url), "http://quotes.s3.foo.bar.s3.amazonaws.com/greeting/file/1002/Lumino.mp3"); + parse_url(url, NULL, "s3", &bucket, &object); + fst_check_string_equals("quotes.s3.foo.bar", bucket); + fst_check_string_equals("greeting/file/1002/Lumino.mp3", object); + + snprintf(url, sizeof(url), "http://quotes.s3.foo.bar.example.com/greeting/file/1002/Lumino.mp3"); + parse_url(url, "example.com", "s3", &bucket, &object); + fst_check_string_equals("quotes.s3.foo.bar", bucket); + fst_check_string_equals("greeting/file/1002/Lumino.mp3", object); +} +FST_TEST_END() + +FST_TEST_BEGIN(test_authorization_header) +{ + fst_check_string_equals("AWS AKIAIOSFODNN7EXAMPLE:YJkomOaqUJlvEluDq4fpusID38Y=", aws_s3_authentication_create("GET", "https://vault.s3.amazonaws.com/awesome.mp3", NULL, "audio/mpeg", "", "AKIAIOSFODNN7EXAMPLE", "0123456789012345678901234567890123456789", "1234567890")); + fst_check_string_equals("AWS AKIAIOSFODNN7EXAMPLE:YJkomOaqUJlvEluDq4fpusID38Y=", aws_s3_authentication_create("GET", "https://vault.s3.amazonaws.com/awesome.mp3", "s3.amazonaws.com", "audio/mpeg", "", "AKIAIOSFODNN7EXAMPLE", "0123456789012345678901234567890123456789", "1234567890")); + fst_check_string_equals("AWS AKIAIOSFODNN7EXAMPLE:YJkomOaqUJlvEluDq4fpusID38Y=", aws_s3_authentication_create("GET", "https://vault.example.com/awesome.mp3", "example.com", "audio/mpeg", "", "AKIAIOSFODNN7EXAMPLE", "0123456789012345678901234567890123456789", "1234567890")); +} +FST_TEST_END() + +FST_TEST_BEGIN(test_presigned_url) +{ + fst_check_string_equals("https://vault.s3.amazonaws.com/awesome.mp3?Signature=YJkomOaqUJlvEluDq4fpusID38Y%3D&Expires=1234567890&AWSAccessKeyId=AKIAIOSFODNN7EXAMPLE", aws_s3_presigned_url_create("GET", "https://vault.s3.amazonaws.com/awesome.mp3", NULL, "audio/mpeg", "", "AKIAIOSFODNN7EXAMPLE", "0123456789012345678901234567890123456789", "1234567890")); + fst_check_string_equals("https://vault.s3.amazonaws.com/awesome.mp3?Signature=YJkomOaqUJlvEluDq4fpusID38Y%3D&Expires=1234567890&AWSAccessKeyId=AKIAIOSFODNN7EXAMPLE", aws_s3_presigned_url_create("GET", "https://vault.s3.amazonaws.com/awesome.mp3", "s3.amazonaws.com", "audio/mpeg", "", "AKIAIOSFODNN7EXAMPLE", "0123456789012345678901234567890123456789", "1234567890")); + fst_check_string_equals("https://vault.example.com/awesome.mp3?Signature=YJkomOaqUJlvEluDq4fpusID38Y%3D&Expires=1234567890&AWSAccessKeyId=AKIAIOSFODNN7EXAMPLE", aws_s3_presigned_url_create("GET", "https://vault.example.com/awesome.mp3", "example.com", "audio/mpeg", "", "AKIAIOSFODNN7EXAMPLE", "0123456789012345678901234567890123456789", "1234567890")); +} +FST_TEST_END() + +} +FST_SUITE_END() + +} +FST_END() diff --git a/src/mod/applications/mod_http_cache/test_aws/Makefile b/src/mod/applications/mod_http_cache/test_aws/Makefile deleted file mode 100644 index df46a358b8..0000000000 --- a/src/mod/applications/mod_http_cache/test_aws/Makefile +++ /dev/null @@ -1,12 +0,0 @@ -BASE=../../../../.. - -LOCAL_CFLAGS += -I../ -I./ -LOCAL_OBJS= main.o ../aws.o ../common.o -LOCAL_SOURCES= main.c -include $(BASE)/build/modmake.rules - -local_all: - libtool --mode=link gcc main.o ../aws.o -o test test_aws.la - -local_clean: - -rm test diff --git a/src/mod/applications/mod_http_cache/test_aws/main.c b/src/mod/applications/mod_http_cache/test_aws/main.c deleted file mode 100644 index 2608802fbb..0000000000 --- a/src/mod/applications/mod_http_cache/test_aws/main.c +++ /dev/null @@ -1,131 +0,0 @@ - - -#include -#include "test.h" -#include "aws.h" - -/** - * Test string to sign generation - */ -static void test_string_to_sign(void) -{ - ASSERT_STRING_EQUALS("GET\n\n\nFri, 17 May 2013 19:35:26 GMT\n/rienzo-vault/troporocks.mp3", aws_s3_string_to_sign("GET", "rienzo-vault", "troporocks.mp3", "", "", "Fri, 17 May 2013 19:35:26 GMT")); - ASSERT_STRING_EQUALS("GET\nc8fdb181845a4ca6b8fec737b3581d76\naudio/mpeg\nThu, 17 Nov 2005 18:49:58 GMT\n/foo/man.chu", aws_s3_string_to_sign("GET", "foo", "man.chu", "audio/mpeg", "c8fdb181845a4ca6b8fec737b3581d76", "Thu, 17 Nov 2005 18:49:58 GMT")); - ASSERT_STRING_EQUALS("\n\n\n\n//", aws_s3_string_to_sign("", "", "", "", "", "")); - ASSERT_STRING_EQUALS("\n\n\n\n//", aws_s3_string_to_sign(NULL, NULL, NULL, NULL, NULL, NULL)); - ASSERT_STRING_EQUALS("PUT\n\naudio/wav\nWed, 12 Jun 2013 13:16:58 GMT\n/bucket/voicemails/recording.wav", aws_s3_string_to_sign("PUT", "bucket", "voicemails/recording.wav", "audio/wav", "", "Wed, 12 Jun 2013 13:16:58 GMT")); -} - -/** - * Test signature generation - */ -static void test_signature(void) -{ - char signature[S3_SIGNATURE_LENGTH_MAX]; - signature[0] = '\0'; - ASSERT_STRING_EQUALS("weGrLrc9HDlkYPTepVl0A9VYNlw=", aws_s3_signature(signature, S3_SIGNATURE_LENGTH_MAX, "GET\n\n\nFri, 17 May 2013 19:35:26 GMT\n/rienzo-vault/troporocks.mp3", "hOIZt1oeTX1JzINOMBoKf0BxONRZNQT1J8gIznLx")); - ASSERT_STRING_EQUALS("jZNOcbfWmD/A/f3hSvVzXZjM2HU=", aws_s3_signature(signature, S3_SIGNATURE_LENGTH_MAX, "PUT\nc8fdb181845a4ca6b8fec737b3581d76\ntext/html\nThu, 17 Nov 2005 18:49:58 GMT\nx-amz-magic:abracadabra\nx-amz-meta-author:foo@bar.com\n/quotes/nelson", "OtxrzxIsfpFjA7SwPzILwy8Bw21TLhquhboDYROV")); - ASSERT_STRING_EQUALS("5m+HAmc5JsrgyDelh9+a2dNrzN8=", aws_s3_signature(signature, S3_SIGNATURE_LENGTH_MAX, "GET\n\n\n\nx-amz-date:Thu, 17 Nov 2005 18:49:58 GMT\nx-amz-magic:abracadabra\n/quotes/nelson", "OtxrzxIsfpFjA7SwPzILwy8Bw21TLhquhboDYROV")); - ASSERT_STRING_EQUALS("OKA87rVp3c4kd59t8D3diFmTfuo=", aws_s3_signature(signature, S3_SIGNATURE_LENGTH_MAX, "", "OtxrzxIsfpFjA7SwPzILwy8Bw21TLhquhboDYROV")); - ASSERT_STRING_EQUALS("OKA87rVp3c4kd59t8D3diFmTfuo=", aws_s3_signature(signature, S3_SIGNATURE_LENGTH_MAX, NULL, "OtxrzxIsfpFjA7SwPzILwy8Bw21TLhquhboDYROV")); - ASSERT_NULL(aws_s3_signature(signature, S3_SIGNATURE_LENGTH_MAX, "GET\n\n\n\nx-amz-date:Thu, 17 Nov 2005 18:49:58 GMT\nx-amz-magic:abracadabra\n/quotes/nelson", "")); - ASSERT_NULL(aws_s3_signature(signature, S3_SIGNATURE_LENGTH_MAX, "", "")); - ASSERT_NULL(aws_s3_signature(signature, S3_SIGNATURE_LENGTH_MAX, NULL, NULL)); - ASSERT_NULL(aws_s3_signature(NULL, S3_SIGNATURE_LENGTH_MAX, "PUT\nc8fdb181845a4ca6b8fec737b3581d76\ntext/html\nThu, 17 Nov 2005 18:49:58 GMT\nx-amz-magic:abracadabra\nx-amz-meta-author:foo@bar.com\n/quotes/nelson", "OtxrzxIsfpFjA7SwPzILwy8Bw21TLhquhboDYROV")); - ASSERT_NULL(aws_s3_signature(signature, 0, "PUT\nc8fdb181845a4ca6b8fec737b3581d76\ntext/html\nThu, 17 Nov 2005 18:49:58 GMT\nx-amz-magic:abracadabra\nx-amz-meta-author:foo@bar.com\n/quotes/nelson", "OtxrzxIsfpFjA7SwPzILwy8Bw21TLhquhboDYROV")); - ASSERT_STRING_EQUALS("jZNO", aws_s3_signature(signature, 5, "PUT\nc8fdb181845a4ca6b8fec737b3581d76\ntext/html\nThu, 17 Nov 2005 18:49:58 GMT\nx-amz-magic:abracadabra\nx-amz-meta-author:foo@bar.com\n/quotes/nelson", "OtxrzxIsfpFjA7SwPzILwy8Bw21TLhquhboDYROV")); -} - -/** - * Test bucket/object extraction from URL - */ -static void test_parse_url(void) -{ - char *bucket; - char *object; - parse_url(strdup("http://quotes.s3.amazonaws.com/nelson"), NULL, "s3", &bucket, &object); - ASSERT_STRING_EQUALS("quotes", bucket); - ASSERT_STRING_EQUALS("nelson", object); - - parse_url(strdup("https://quotes.s3.amazonaws.com/nelson.mp3"), NULL, "s3", &bucket, &object); - ASSERT_STRING_EQUALS("quotes", bucket); - ASSERT_STRING_EQUALS("nelson.mp3", object); - - parse_url(strdup("http://s3.amazonaws.com/quotes/nelson"), NULL, "s3", &bucket, &object); - ASSERT_NULL(bucket); - ASSERT_NULL(object); - - parse_url(strdup("http://quotes/quotes/nelson"), NULL, "s3", &bucket, &object); - ASSERT_NULL(bucket); - ASSERT_NULL(object); - - parse_url(strdup("http://quotes.s3.amazonaws.com/"), NULL, "s3", &bucket, &object); - ASSERT_NULL(bucket); - ASSERT_NULL(object); - - parse_url(strdup("http://quotes.s3.amazonaws.com"), NULL, "s3", &bucket, &object); - ASSERT_NULL(bucket); - ASSERT_NULL(object); - - parse_url(strdup("http://quotes"), NULL, "s3", &bucket, &object); - ASSERT_NULL(bucket); - ASSERT_NULL(object); - - parse_url(strdup(""), NULL, "s3", &bucket, &object); - ASSERT_NULL(bucket); - ASSERT_NULL(object); - - parse_url(NULL, NULL, "s3", &bucket, &object); - ASSERT_NULL(bucket); - ASSERT_NULL(object); - - parse_url(strdup("http://bucket.s3.amazonaws.com/voicemails/recording.wav"), NULL, "s3", &bucket, &object); - ASSERT_STRING_EQUALS("bucket", bucket); - ASSERT_STRING_EQUALS("voicemails/recording.wav", object); - - parse_url(strdup("https://my-bucket-with-dash.s3-us-west-2.amazonaws.com/greeting/file/1002/Lumino.mp3"), NULL, "s3", &bucket, &object); - ASSERT_STRING_EQUALS("my-bucket-with-dash", bucket); - ASSERT_STRING_EQUALS("greeting/file/1002/Lumino.mp3", object); - - parse_url(strdup("http://quotes.s3.foo.bar.s3.amazonaws.com/greeting/file/1002/Lumino.mp3"), NULL, "s3", &bucket, &object); - ASSERT_STRING_EQUALS("quotes.s3.foo.bar", bucket); - ASSERT_STRING_EQUALS("greeting/file/1002/Lumino.mp3", object); - - parse_url(strdup("http://quotes.s3.foo.bar.example.com/greeting/file/1002/Lumino.mp3"), "example.com", "s3", &bucket, &object); - ASSERT_STRING_EQUALS("quotes.s3.foo.bar", bucket); - ASSERT_STRING_EQUALS("greeting/file/1002/Lumino.mp3", object); -} - -/** - * Test Authorization header creation - */ -static void test_authorization_header(void) -{ - ASSERT_STRING_EQUALS("AWS AKIAIOSFODNN7EXAMPLE:YJkomOaqUJlvEluDq4fpusID38Y=", aws_s3_authentication_create("GET", "https://vault.s3.amazonaws.com/awesome.mp3", NULL, "audio/mpeg", "", "AKIAIOSFODNN7EXAMPLE", "0123456789012345678901234567890123456789", "1234567890")); - ASSERT_STRING_EQUALS("AWS AKIAIOSFODNN7EXAMPLE:YJkomOaqUJlvEluDq4fpusID38Y=", aws_s3_authentication_create("GET", "https://vault.s3.amazonaws.com/awesome.mp3", "s3.amazonaws.com", "audio/mpeg", "", "AKIAIOSFODNN7EXAMPLE", "0123456789012345678901234567890123456789", "1234567890")); - ASSERT_STRING_EQUALS("AWS AKIAIOSFODNN7EXAMPLE:YJkomOaqUJlvEluDq4fpusID38Y=", aws_s3_authentication_create("GET", "https://vault.example.com/awesome.mp3", "example.com", "audio/mpeg", "", "AKIAIOSFODNN7EXAMPLE", "0123456789012345678901234567890123456789", "1234567890")); -} - -/** - * Test pre-signed URL creation - */ -static void test_presigned_url(void) -{ - ASSERT_STRING_EQUALS("https://vault.s3.amazonaws.com/awesome.mp3?Signature=YJkomOaqUJlvEluDq4fpusID38Y%3D&Expires=1234567890&AWSAccessKeyId=AKIAIOSFODNN7EXAMPLE", aws_s3_presigned_url_create("GET", "https://vault.s3.amazonaws.com/awesome.mp3", NULL, "audio/mpeg", "", "AKIAIOSFODNN7EXAMPLE", "0123456789012345678901234567890123456789", "1234567890")); - ASSERT_STRING_EQUALS("https://vault.s3.amazonaws.com/awesome.mp3?Signature=YJkomOaqUJlvEluDq4fpusID38Y%3D&Expires=1234567890&AWSAccessKeyId=AKIAIOSFODNN7EXAMPLE", aws_s3_presigned_url_create("GET", "https://vault.s3.amazonaws.com/awesome.mp3", "s3.amazonaws.com", "audio/mpeg", "", "AKIAIOSFODNN7EXAMPLE", "0123456789012345678901234567890123456789", "1234567890")); - ASSERT_STRING_EQUALS("https://vault.example.com/awesome.mp3?Signature=YJkomOaqUJlvEluDq4fpusID38Y%3D&Expires=1234567890&AWSAccessKeyId=AKIAIOSFODNN7EXAMPLE", aws_s3_presigned_url_create("GET", "https://vault.example.com/awesome.mp3", "example.com", "audio/mpeg", "", "AKIAIOSFODNN7EXAMPLE", "0123456789012345678901234567890123456789", "1234567890")); -} - -/** - * main program - */ -int main(int argc, char **argv) -{ - TEST_INIT - TEST(test_string_to_sign); - TEST(test_signature); - TEST(test_parse_url); - TEST(test_authorization_header); - TEST(test_presigned_url); - return 0; -} diff --git a/src/mod/applications/mod_http_cache/test_aws/test.h b/src/mod/applications/mod_http_cache/test_aws/test.h deleted file mode 100644 index 91c9b7960a..0000000000 --- a/src/mod/applications/mod_http_cache/test_aws/test.h +++ /dev/null @@ -1,113 +0,0 @@ -/* - * test.h for FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application - * Copyright (C) 2013, Grasshopper - * - * Version: MPL 1.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is test.h for FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application - * - * The Initial Developer of the Original Code is Grasshopper - * Portions created by the Initial Developer are Copyright (C) - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Chris Rienzo - * - * test.h -- simple unit testing macros - * - */ -#ifndef TEST_H -#define TEST_H - -#define assert_equals(test, expected_str, expected, actual, file, line) \ -{ \ - int actual_val = actual; \ - if (expected != actual_val) { \ - printf("TEST\t%s\tFAIL\t%s\t%i\t!=\t%i\t%s:%i\n", test, expected_str, expected, actual_val, file, line); \ - exit(1); \ - } else { \ - printf("TEST\t%s\tPASS\n", test); \ - } \ -} - -#define assert_string_equals(test, expected, actual, file, line) \ -{ \ - const char *actual_str = actual; \ - if (!actual_str || strcmp(expected, actual_str)) { \ - printf("TEST\t%s\tFAIL\t\t%s\t!=\t%s\t%s:%i\n", test, expected, actual_str, file, line); \ - exit(1); \ - } else { \ - printf("TEST\t%s\tPASS\n", test); \ - } \ -} - -#define assert_not_null(test, actual, file, line) \ -{ \ - const void *actual_val = actual; \ - if (!actual_val) { \ - printf("TEST\t%s\tFAIL\t\t\t\t\t%s:%i\n", test, file, line); \ - exit(1); \ - } else { \ - printf("TEST\t%s\tPASS\n", test); \ - } \ -} - -#define assert_null(test, actual, file, line) \ -{ \ - const void *actual_val = actual; \ - if (actual_val) { \ - printf("TEST\t%s\tFAIL\t\t\t\t\t%s:%i\n", test, file, line); \ - exit(1); \ - } else { \ - printf("TEST\t%s\tPASS\n", test); \ - } \ -} - -#define assert_true(test, actual, file, line) \ -{ \ - int actual_val = actual; \ - if (!actual_val) { \ - printf("TEST\t%s\tFAIL\t\t\t\t\t%s:%i\n", test, file, line); \ - exit(1); \ - } else { \ - printf("TEST\t%s\tPASS\n", test); \ - } \ -} - -#define assert_false(test, actual, file, line) \ -{ \ - int actual_val = actual; \ - if (actual_val) { \ - printf("TEST\t%s\tFAIL\t\t\t\t\t%s:%i\n", test, file, line); \ - exit(1); \ - } else { \ - printf("TEST\t%s\tPASS\n", test); \ - } \ -} - -#define ASSERT_EQUALS(expected, actual) assert_equals(#actual, #expected, expected, actual, __FILE__, __LINE__) -#define ASSERT_STRING_EQUALS(expected, actual) assert_string_equals(#actual, expected, actual, __FILE__, __LINE__) -#define ASSERT_NOT_NULL(actual) assert_not_null(#actual " not null", actual, __FILE__, __LINE__) -#define ASSERT_NULL(actual) assert_null(#actual " is null", actual, __FILE__, __LINE__) -#define ASSERT_TRUE(actual) assert_true(#actual " is true", actual, __FILE__, __LINE__) -#define ASSERT_FALSE(actual) assert_false(#actual " is false", actual, __FILE__, __LINE__) - -#define SKIP_ASSERT_EQUALS(expected, actual) if (0) { ASSERT_EQUALS(expected, actual); } - -#define TEST(name) printf("TEST BEGIN\t" #name "\n"); name(); printf("TEST END\t"#name "\tPASS\n"); - -#define SKIP_TEST(name) if (0) { TEST(name) }; - -#define TEST_INIT const char *err; switch_core_init(0, SWITCH_TRUE, &err); - -#endif diff --git a/src/mod/applications/mod_http_cache/test_aws/test_aws.c b/src/mod/applications/mod_http_cache/test_aws/test_aws.c deleted file mode 100644 index a0953207de..0000000000 --- a/src/mod/applications/mod_http_cache/test_aws/test_aws.c +++ /dev/null @@ -1,6 +0,0 @@ -int dummy(int i) -{ - return 0; -} - -