Пример #1
0
/**
 * 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"));
}
Пример #2
0
//TODO: add more tests
static bool testGetName() {

	Dish dish = dishCreate("Boiled Student", "Stav Doolman", 2);

	char* name;
	ASSERT_SUCCESS(dishGetName(dish, &name));
	ASSERT_STRING_EQUALS(name, "Boiled Student");
	name[0] = 'B';

	char* dupName;
	ASSERT_SUCCESS(dishGetName(dish, &dupName));
	ASSERT_STRING_EQUALS(dupName, "Boiled Student");

	free(name);
	free(dupName);
	dishDestroy(dish);
	return true;
}
Пример #3
0
/**
 * Test matching with duplicate tags
 */
static void test_match_duplicate_tag_grammar(void)
{
  struct cspeech_srgs_parser *parser;
  struct cspeech_srgs_grammar *grammar;
  char *interpretation;

  parser = cspeech_srgs_parser_new("1234");
  ASSERT_NOT_NULL((grammar = cspeech_srgs_parse(parser, duplicate_tag_grammar)));

  ASSERT_EQUALS(CSMT_NO_MATCH, cspeech_srgs_grammar_match(grammar, "0", &interpretation));
  ASSERT_NULL(interpretation);
  ASSERT_EQUALS(CSMT_MATCH_END, cspeech_srgs_grammar_match(grammar, "1", &interpretation));
  ASSERT_STRING_EQUALS("2", interpretation);
  ASSERT_EQUALS(CSMT_NO_MATCH, cspeech_srgs_grammar_match(grammar, "2", &interpretation));
  ASSERT_NULL(interpretation);
  ASSERT_EQUALS(CSMT_NO_MATCH, cspeech_srgs_grammar_match(grammar, "3", &interpretation));
  ASSERT_NULL(interpretation);
  ASSERT_EQUALS(CSMT_NO_MATCH, cspeech_srgs_grammar_match(grammar, "4", &interpretation));
  ASSERT_NULL(interpretation);
  ASSERT_EQUALS(CSMT_MATCH_END, cspeech_srgs_grammar_match(grammar, "5", &interpretation));
  ASSERT_STRING_EQUALS("2", interpretation);
  ASSERT_EQUALS(CSMT_NO_MATCH, cspeech_srgs_grammar_match(grammar, "6", &interpretation));
  ASSERT_NULL(interpretation);
  ASSERT_EQUALS(CSMT_MATCH_END, cspeech_srgs_grammar_match(grammar, "7", &interpretation));
  ASSERT_STRING_EQUALS("4", interpretation);
  ASSERT_EQUALS(CSMT_NO_MATCH, cspeech_srgs_grammar_match(grammar, "8", &interpretation));
  ASSERT_NULL(interpretation);
  ASSERT_EQUALS(CSMT_MATCH_END, cspeech_srgs_grammar_match(grammar, "9", &interpretation));
  ASSERT_STRING_EQUALS("4", interpretation);
  ASSERT_EQUALS(CSMT_NO_MATCH, cspeech_srgs_grammar_match(grammar, "#", &interpretation));
  ASSERT_NULL(interpretation);
  ASSERT_EQUALS(CSMT_NO_MATCH, cspeech_srgs_grammar_match(grammar, "*", &interpretation));
  ASSERT_NULL(interpretation);
  ASSERT_EQUALS(CSMT_NO_MATCH, cspeech_srgs_grammar_match(grammar, "A", &interpretation));
  ASSERT_NULL(interpretation);
  ASSERT_EQUALS(CSMT_NO_MATCH, cspeech_srgs_grammar_match(grammar, "27", &interpretation));
  ASSERT_NULL(interpretation);
  ASSERT_EQUALS(CSMT_NO_MATCH, cspeech_srgs_grammar_match(grammar, "223", &interpretation));
  ASSERT_NULL(interpretation);
  ASSERT_EQUALS(CSMT_NO_MATCH, cspeech_srgs_grammar_match(grammar, "0123456789*#", &interpretation));
  ASSERT_NULL(interpretation);

  cspeech_srgs_parser_destroy(parser);
}
Пример #4
0
//TODO: add more tests
static bool testSetName() {

	Dish dish = dishCreate("Sweet & Sour Dor", "Ofer Givoli", 2);

	ASSERT_SUCCESS(dishSetName(dish, "Just Dor"));
	char* name;
	dishGetName(dish, &name);
	ASSERT_STRING_EQUALS(name, "Just Dor");
	free(name);

	char newName[] = "New Blabla";
	ASSERT_SUCCESS(dishSetName(dish, newName));
	newName[0] = 'M';
	dishGetName(dish, &name);
	ASSERT_STRING_EQUALS(name, "New Blabla");
	free(name);

	dishDestroy(dish);
	return true;
}
Пример #5
0
//TODO: add more tests
static bool testGetCook() {

	Dish dish = dishCreate("Rotten Shlomo", "Sarai Duek", 2);

	char* cook;
	ASSERT_SUCCESS(dishGetCook(dish, &cook));
	ASSERT_STRING_EQUALS(cook, "Sarai Duek");

	free(cook);
	dishDestroy(dish);
	return true;
}
Пример #6
0
static void test_dialback_key(void)
{
	ASSERT_STRING_EQUALS("37c69b1cf07a3f67c04a5ef5902fa5114f2c76fe4a2686482ba5b89323075643", iks_server_dialback_key("s3cr3tf0rd14lb4ck", "xmpp.example.com", "example.org", "D60000229F"));
	ASSERT_NULL(iks_server_dialback_key("", "xmpp.example.com", "example.org", "D60000229F"));
	ASSERT_NULL(iks_server_dialback_key("s3cr3tf0rd14lb4ck", "", "example.org", "D60000229F"));
	ASSERT_NULL(iks_server_dialback_key("s3cr3tf0rd14lb4ck", "xmpp.example.com", "", "D60000229F"));
	ASSERT_NULL(iks_server_dialback_key("s3cr3tf0rd14lb4ck", "xmpp.example.com", "example.org", ""));
	ASSERT_NULL(iks_server_dialback_key(NULL, "xmpp.example.com", "example.org", "D60000229F"));
	ASSERT_NULL(iks_server_dialback_key("s3cr3tf0rd14lb4ck", NULL, "example.org", "D60000229F"));
	ASSERT_NULL(iks_server_dialback_key("s3cr3tf0rd14lb4ck", "xmpp.example.com", NULL, "D60000229F"));
	ASSERT_NULL(iks_server_dialback_key("s3cr3tf0rd14lb4ck", "xmpp.example.com", "example.org", NULL));
}
Пример #7
0
static void test_normal_cdata(void)
{
	iks *iq = NULL;
	iks *input = NULL;
	iksparser *p = iks_dom_new(&iq);
	const char *cdata;
	ASSERT_EQUALS(IKS_OK, iks_parse(p, normal_cdata, 0, 1));
	iks_parser_delete(p);
	ASSERT_NOT_NULL((input = iks_find(iq, "input")));
	ASSERT_NOT_NULL((cdata = iks_find_cdata(input, "grammar")));
	ASSERT_STRING_EQUALS("1 DIGITS", cdata);
	iks_delete(iq);
}
Пример #8
0
static void test_repeating_bracket(void)
{
	iks *iq = NULL;
	iks *input = NULL;
	iksparser *p = iks_dom_new(&iq);
	const char *cdata;
	ASSERT_EQUALS(IKS_OK, iks_parse(p, repeating_bracket, 0, 1));
	iks_parser_delete(p);
	ASSERT_NOT_NULL((input = iks_find(iq, "input")));
	ASSERT_NOT_NULL((cdata = iks_find_cdata(input, "grammar")));
	ASSERT_STRING_EQUALS("[1 DIGITS]>]]]]]]]]] ]] ", cdata);
	iks_delete(iq);
}
Пример #9
0
static void test_jsgf(void)
{
  struct cspeech_srgs_parser *parser;
  struct cspeech_srgs_grammar *grammar;
  const char *jsgf;
  parser = cspeech_srgs_parser_new("1234");

  ASSERT_NOT_NULL((grammar = cspeech_srgs_parse(parser, adhearsion_ask_grammar)));
  ASSERT_NOT_NULL((jsgf = cspeech_srgs_grammar_to_jsgf(grammar)));
  ASSERT_NOT_NULL((grammar = cspeech_srgs_parse(parser, voice_srgs1)));
  ASSERT_NOT_NULL((jsgf = cspeech_srgs_grammar_to_jsgf(grammar)));
  ASSERT_STRING_EQUALS(voice_jsgf, jsgf);
  ASSERT_NOT_NULL((grammar = cspeech_srgs_parse(parser, multi_rule_grammar)));
  ASSERT_NOT_NULL((jsgf = cspeech_srgs_grammar_to_jsgf(grammar)));
  ASSERT_NOT_NULL((grammar = cspeech_srgs_parse(parser, rayo_test_srgs)));
  ASSERT_NOT_NULL((jsgf = cspeech_srgs_grammar_to_jsgf(grammar)));
  ASSERT_NULL(cspeech_srgs_grammar_to_jsgf(NULL));
  cspeech_srgs_parser_destroy(parser);
}
Пример #10
0
/**
 * 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:[email protected]\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:[email protected]\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:[email protected]\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:[email protected]\n/quotes/nelson", "OtxrzxIsfpFjA7SwPzILwy8Bw21TLhquhboDYROV"));
}
Пример #11
0
/**
 * 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"), NULL, &bucket, &object);
	ASSERT_STRING_EQUALS("quotes", bucket);
	ASSERT_STRING_EQUALS("nelson", object);

	aws_s3_parse_url(strdup("https://quotes.s3.amazonaws.com/nelson.mp3"), NULL, &bucket, &object);
	ASSERT_STRING_EQUALS("quotes", bucket);
	ASSERT_STRING_EQUALS("nelson.mp3", object);

	aws_s3_parse_url(strdup("http://s3.amazonaws.com/quotes/nelson"), NULL, &bucket, &object);
	ASSERT_NULL(bucket);
	ASSERT_NULL(object);

	aws_s3_parse_url(strdup("http://quotes/quotes/nelson"), NULL, &bucket, &object);
	ASSERT_NULL(bucket);
	ASSERT_NULL(object);

	aws_s3_parse_url(strdup("http://quotes.s3.amazonaws.com/"), NULL, &bucket, &object);
	ASSERT_NULL(bucket);
	ASSERT_NULL(object);

	aws_s3_parse_url(strdup("http://quotes.s3.amazonaws.com"), NULL, &bucket, &object);
	ASSERT_NULL(bucket);
	ASSERT_NULL(object);

	aws_s3_parse_url(strdup("http://quotes"), NULL, &bucket, &object);
	ASSERT_NULL(bucket);
	ASSERT_NULL(object);

	aws_s3_parse_url(strdup(""), NULL, &bucket, &object);
	ASSERT_NULL(bucket);
	ASSERT_NULL(object);

	aws_s3_parse_url(NULL, NULL, &bucket, &object);
	ASSERT_NULL(bucket);
	ASSERT_NULL(object);

	aws_s3_parse_url(strdup("http://bucket.s3.amazonaws.com/voicemails/recording.wav"), NULL, &bucket, &object);
	ASSERT_STRING_EQUALS("bucket", bucket);
	ASSERT_STRING_EQUALS("voicemails/recording.wav", object);

	aws_s3_parse_url(strdup("https://my-bucket-with-dash.s3-us-west-2.amazonaws.com/greeting/file/1002/Lumino.mp3"), NULL, &bucket, &object);
	ASSERT_STRING_EQUALS("my-bucket-with-dash", bucket);
	ASSERT_STRING_EQUALS("greeting/file/1002/Lumino.mp3", object);
	
	aws_s3_parse_url(strdup("http://quotes.s3.foo.bar.s3.amazonaws.com/greeting/file/1002/Lumino.mp3"), NULL, &bucket, &object);
	ASSERT_STRING_EQUALS("quotes.s3.foo.bar", bucket);
	ASSERT_STRING_EQUALS("greeting/file/1002/Lumino.mp3", object);

	aws_s3_parse_url(strdup("http://quotes.s3.foo.bar.example.com/greeting/file/1002/Lumino.mp3"), "example.com", &bucket, &object);
	ASSERT_STRING_EQUALS("quotes.s3.foo.bar", bucket);
	ASSERT_STRING_EQUALS("greeting/file/1002/Lumino.mp3", object);
}
Пример #12
0
/**
 * 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"));
}
Пример #13
0
/**
 * 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"));
}