mirror of
https://github.com/signalwire/freeswitch.git
synced 2026-10-14 23:34:13 +00:00
mod_http_cache: added native Amazon S3 support
This commit is contained in:
1 parent
fe000f18fd
commit
8c8b2176d2
9 files changed
+798
-34
No files matched your search
@@ -0,0 +1,12 @@
|
||||
BASE=../../../../..
|
||||
|
||||
LOCAL_CFLAGS += -I../ -I./
|
||||
LOCAL_OBJS= main.o ../aws.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
|
||||
@@ -0,0 +1,131 @@
|
||||
|
||||
|
||||
#include <switch.h>
|
||||
#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));
|
||||
}
|
||||
|
||||
/**
|
||||
* 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"));
|
||||
/* TODO freeswitch bug... */
|
||||
//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 amazon URL detection
|
||||
*/
|
||||
static void test_check_url(void)
|
||||
{
|
||||
ASSERT_TRUE(aws_s3_is_s3_url("http://bucket.s3.amazonaws.com/object.ext"));
|
||||
ASSERT_TRUE(aws_s3_is_s3_url("http://bucket.s3.amazonaws.com/object"));
|
||||
ASSERT_TRUE(aws_s3_is_s3_url("http://red.bucket.s3.amazonaws.com/object.ext"));
|
||||
ASSERT_TRUE(aws_s3_is_s3_url("https://bucket.s3.amazonaws.com/object.ext"));
|
||||
ASSERT_TRUE(aws_s3_is_s3_url("https://bucket.s3.amazonaws.com/object"));
|
||||
ASSERT_FALSE(aws_s3_is_s3_url("bucket.s3.amazonaws.com/object.ext"));
|
||||
ASSERT_FALSE(aws_s3_is_s3_url("https://s3.amazonaws.com/bucket/object"));
|
||||
ASSERT_FALSE(aws_s3_is_s3_url("http://s3.amazonaws.com/bucket/object"));
|
||||
ASSERT_FALSE(aws_s3_is_s3_url("http://google.com/"));
|
||||
ASSERT_FALSE(aws_s3_is_s3_url("http://phono.com/audio/troporocks.mp3"));
|
||||
ASSERT_FALSE(aws_s3_is_s3_url(""));
|
||||
ASSERT_FALSE(aws_s3_is_s3_url(NULL));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test bucket/object extraction from URL
|
||||
*/
|
||||
static void test_parse_url(void)
|
||||
{
|
||||
char *bucket;
|
||||
char *object;
|
||||
aws_s3_parse_url(strdup("http://quotes.s3.amazonaws.com/nelson"), &bucket, &object);
|
||||
ASSERT_STRING_EQUALS("quotes", bucket);
|
||||
ASSERT_STRING_EQUALS("nelson", object);
|
||||
|
||||
aws_s3_parse_url(strdup("https://quotes.s3.amazonaws.com/nelson.mp3"), &bucket, &object);
|
||||
ASSERT_STRING_EQUALS("quotes", bucket);
|
||||
ASSERT_STRING_EQUALS("nelson.mp3", object);
|
||||
|
||||
aws_s3_parse_url(strdup("http://s3.amazonaws.com/quotes/nelson"), &bucket, &object);
|
||||
ASSERT_NULL(bucket);
|
||||
ASSERT_NULL(object);
|
||||
|
||||
aws_s3_parse_url(strdup("http://quotes/quotes/nelson"), &bucket, &object);
|
||||
ASSERT_NULL(bucket);
|
||||
ASSERT_NULL(object);
|
||||
|
||||
aws_s3_parse_url(strdup("http://quotes.s3.amazonaws.com/"), &bucket, &object);
|
||||
ASSERT_NULL(bucket);
|
||||
ASSERT_NULL(object);
|
||||
|
||||
aws_s3_parse_url(strdup("http://quotes.s3.amazonaws.com"), &bucket, &object);
|
||||
ASSERT_NULL(bucket);
|
||||
ASSERT_NULL(object);
|
||||
|
||||
aws_s3_parse_url(strdup("http://quotes"), &bucket, &object);
|
||||
ASSERT_NULL(bucket);
|
||||
ASSERT_NULL(object);
|
||||
|
||||
aws_s3_parse_url(strdup(""), &bucket, &object);
|
||||
ASSERT_NULL(bucket);
|
||||
ASSERT_NULL(object);
|
||||
|
||||
aws_s3_parse_url(NULL, &bucket, &object);
|
||||
ASSERT_NULL(bucket);
|
||||
ASSERT_NULL(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", "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", "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_check_url);
|
||||
TEST(test_parse_url);
|
||||
TEST(test_authorization_header);
|
||||
TEST(test_presigned_url);
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
/*
|
||||
* 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 <chris.rienzo@grasshopper.com>
|
||||
*
|
||||
* 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
|
||||
@@ -0,0 +1,6 @@
|
||||
int dummy(int i)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user