/**
* The contents of this file are subject to the terms of the Common Development and
* Distribution License (the License). You may not use this file except in compliance with the
* License.
*
* You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
* specific language governing permission and limitations under the License.
*
* When distributing Covered Software, include this CDDL Header Notice in each file and include
* the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
* Header, with the fields enclosed by brackets [] replaced by your own identifying
* information: "Portions copyright [year] [name of copyright owner]".
*
* Copyright 2015 ForgeRock AS.
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h>
#include <setjmp.h>
#include "am.h"
#include "platform.h"
#include "utility.h"
#include "log.h"
#include "cmocka.h"
/**
* This is the marker we spatter throughout our destination buffer for testing purposes. It must not be null
* because as far as this code is concerned, null is valid data. We need this to be invalid and noticable.
* Thus I chose control A.
*/
/**
* Encode the string stored in p and make non printing characters (including nulls) visible by representing
* them as \HH where HH is the hex value in the shortest width possible (so null comes out as \0). We return
* a pointer to a dynamically allocated piece of memory which should be freed. This routine isn't particularly
* efficient.
*/
buf[0] = '\0';
while(len--) {
if (*p < ' ' || *p == 127) {
} else {
buf2[0] = *p;
}
p++;
}
}
/**
* Find the first marker character in "dest" and return the number of characters before it.
*/
const char* p = dest;
while (*p != MARKER) {
p++;
}
return p - dest;
}
/**
* Compare the actual and expected values. If they do not match, dump out a representation of both the expected
* and actual values so we can see what has gone wrong. If they do match, print "SUCCESS" and return 0. In
* this way we draw maximum attention to ourselves only if the test fails.
*/
if (actual_len != expected_len) {
printf("actual length and expected lengths are different (%lu vs %lu)\n",
return 1;
}
printf("actual and expected strings are different (although the same length)\n");
return 1;
}
return 0;
}
/************************************************************************************************************/
"Made glorious summer by this son of York";
static const char* as_you_like_it_1 = "All the world's a stage, and all the men and women merely players";
static const char* as_you_like_it_3 = "and one man in his time plays many parts, his acts being seven ages";
/************************************************************************************************************/
/**
* test mem2cpy, returning 1 if the test fails, 0 if it succeeds.
*/
(void)state;
char a[] = "ABCDEF";
char b[] = "GHI";
}
/**
* test mem3cpy, returning 1 if the test fails, 0 if it succeeds.
*/
(void)state;
char a[] = "ABCDEF";
char b[] = "GHI";
char c[] = "JKLMN";
}
/**
* Test the match function.
*/
(void)state;
// for some reason, passing in null results in an "ok" match
}
/**
* Note that the match_groups function isn't tested here because it is only invoked once in the entire codebase.
* Also I can't quite figure what the length parameters should be set to.
*/
int result;
return result;
}
/**
* Test the am_vasprintf function.
*/
int returned = am_vasprintf_test(&buff, "%s: %s; %s", as_you_like_it_1, as_you_like_it_2, as_you_like_it_3);
int correct_length = strlen(as_you_like_it_1) + 2 + strlen(as_you_like_it_2) + 2 + strlen(as_you_like_it_3);
}
/**
* test the am_asprintf function. Obviously one thing we cannot do is pass it a pointer to the
* stack as it's first parmameter - if we do, it crashes.
*/
}
/**
* test the am_free function. Obviously we can't pass a stack-based reference to it, that will cause it
* to crash. Similarly we can only pass a pointer directly returned from one of the memory allocation functions,
* as opposed to something returned and incremented a little.
*/
/* this is about the only thing I can think of asserting here
* at least it "proves" we made it this far.
*/
assert_true(1);
}
/**
* test am_strldup, which duplicates a lowercase version of the string into dynamic memory.
* In fact am_stridup was only written while tidying up stristr.
*/
assert_string_equal(lowercase_text1, "all the world's a stage, and all the men and women merely players");
/* this at least proves we survived the freeing */
assert_true(1);
}
/**
* Test case insensitive string searching.
*/
}
/**
* Test base 64 encoding and decoding. Note that https://www.base64encode.org/ has been
* particularly helpful here. Also note the importance of setting "length" correctly before
* its address is passed into the encoding function. The decoding function doesn't care.
*/
const char* r3_out = "Tm93IGlzIHRoZSB3aW50ZXIgb2Ygb3VyIGRpc2NvbnRlbnQsIE1hZGUgZ2xvcmlvdXMgc3VtbWVyIGJ5IHRoaXMgc29uIG9mIFlvcms=";
}
/**
* Note that I can't think of a good way to test delete_am_cookie_list.
*/
/**
* Test the rather odd char_count function,
*/
int last;
assert_int_equal(result, 0);
}
/**
* Test encryption and decryption. This function does the obvious test of taking text, encoding
* it and decoding it again to see if we end up with the same thing.
*/
// "result" now points to a dynamically allocated area filled with the encrypted password
// now decode back to the original text (hopefully)
}
/**
* Test the escaping of characters supported by xml_entity_escape.
*/
char* amp;
char* apos;
char* quot;
char* gt;
char* lt;
}
/**
* Test the rather odd am_strsep function.
*/
char* match;
int counter = 0;
/* Note: do not use a multi character separator */
counter++;
}
}
/**
* Test the parsing of URLs.
*/
int result;
}
/**
* test the url encode and decode functions.
*/
buff[0] = '\0';
}
}
char * original;
}
}
/*
* this test is disabled by not using the required parameter
*
*/
void test_property_map_load() {
char * data;
data_sz = 0;
data_sz = 0;
data_sz = 0;
}
char * data;
data = "a.b.0 = 0\r\na.b.1 = 1\r\na.b.empty =\r\n";
// new value ok, change doesn't override
data = "a.b.2 = 2\r\na.b.1 = override\r\n";
// override to a.b.1, different space round existing values
data = "a.b.0=\t\t\t0 \n\r\t a.b.2 = 2\r\na.b.1 = override 1\r\n";
// no override to a.b.1, set after comment
data = "a.b.1 = override 2\r\n#comment\na.b.3=3";
}
(* counter)++;
return AM_TRUE;
}
char * data;
// no final line ending
data = "a.b.0 = 0\r\na.b.1 = 1";
// no change with non-property formats, empty property name
data = "abc\r\ndef\n\t\t=ghi";
int counter = 0;
}
static int compare_keys(const void *a, const void *b) {
return strcmp((char *)a, (char *)b);
}
for (i = 0; i < KEY_REMOVE_TEST_ITERATIONS; i++) {
if (*addr)
dups++;
else
}
// reorder
for (i = 0; i < KEY_REMOVE_TEST_ITERATIONS; i++) {
dups--;
}
assert_int_equal(dups, 0);
assert_int_equal(counter, 0);
}
char *loaded;
}
char *loaded;
}
/* producing the same url encoding as prior versions of the agents */
}