test_policy_cache.c revision ca31ce007b10515c89f93829ba24dab7b0a19e2d
/**
* 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 2014 - 2015 ForgeRock AS.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <setjmp.h>
#include "platform.h"
#include "am.h"
#include "utility.h"
#include "list.h"
#include "thread.h"
#include "cmocka.h"
void am_worker_pool_init_reset();
void am_net_init_ssl_reset();
void dump_cache_memory(void);
char* policy_xml = "<PolicyService version='1.0' revisionNumber='60'>"
"<PolicyResponse requestId='4' issueInstant='1424783306343' >"
" <ResourceResult name='http://vb2.local.com:80/testwebsite'>"
" <PolicyDecision>"
" <ResponseAttributes> <!-- these can have multiple (0..n) value elements -->"
" <AttributeValuePair>"
" <Attribute name='Attributes,key:0,0'/> <Value>Attributes,value:0,0,0</Value> <Value>Attributes,value:0,0,1</Value>"
" </AttributeValuePair>"
" <AttributeValuePair>"
" <Attribute name='Attributes,key:0,1'/> <Value>Attributes,value:0,1,0</Value>"
" </AttributeValuePair>"
" </ResponseAttributes>"
" <ActionDecision timeToLive='1234'> <!-- these can have no value elements, which defaults to ? -->"
" <AttributeValuePair>"
" <Attribute name='PUT'/> <Value>deny</Value>"
" </AttributeValuePair>"
" <Advices>"
" <AttributeValuePair>"
" <Attribute name='Advices,key:0,0'/> <Value>Advices,value:0,0,0</Value>"
" </AttributeValuePair>"
" <AttributeValuePair>"
" <Attribute name='Advices,key:0,1'/> <Value>Advices,value:0,1,0</Value>"
" </AttributeValuePair>"
" </Advices>"
" </ActionDecision>"
" <ActionDecision timeToLive='5678'>"
" <AttributeValuePair>"
" <Attribute name='GET'/> <Value>allow</Value>"
" </AttributeValuePair>"
" <Advices>"
" <AttributeValuePair>"
" <Attribute name='Advices,key:0,0'/> <Value>Advices,value:0,0,0</Value>"
" </AttributeValuePair>"
" <AttributeValuePair>"
" <Attribute name='Advices,key:0,1'/> <Value>Advices,value:0,1,0</Value>"
" </AttributeValuePair>"
" </Advices>"
" </ActionDecision>"
" <ActionDecision timeToLive='9012'>"
" <AttributeValuePair>"
" <Attribute name='POST'/> <Value>allow</Value>"
" </AttributeValuePair>"
" <Advices>"
" <AttributeValuePair>"
" <Attribute name='Advices,key:0,0'/> <Value>Advices,value:0,0,0</Value>"
" </AttributeValuePair>"
" <AttributeValuePair>"
" <Attribute name='Advices,key:0,1'/> <Value>Advices,value:0,1,0</Value>"
" </AttributeValuePair>"
" <AttributeValuePair>"
" <Attribute name='Advices,key:0,2'/> <Value>Advices,value:0,2,0</Value>"
" </AttributeValuePair>"
" </Advices>"
" </ActionDecision>"
" <ResponseDecisions>"
" <AttributeValuePair>"
" <Attribute name='Decision,key:0,0'/> <Value>Decision,value:0,0,0</Value>"
" </AttributeValuePair>"
" <AttributeValuePair>"
" <Attribute name='Decision,key:0,1'/> <Value>Decision,value:0,1,0</Value>"
" </AttributeValuePair>"
" <AttributeValuePair>"
" <Attribute name='Decision,key:0,2'/> <Value>Decision,value:0,2,0</Value>"
" </AttributeValuePair>"
" </ResponseDecisions>"
" </PolicyDecision>"
" </ResourceResult>"
"</PolicyResponse>"
"</PolicyService>";
char* policy_for_url =
"<PolicyService version=\"1.0\" revisionNumber=\"60\">"
" <PolicyResponse requestId=\"4\" issueInstant=\"9999999999999\" >"
" <ResourceResult name=\"%s\">"
" <PolicyDecision>"
" <ResponseAttributes>"
" </ResponseAttributes>"
" <ActionDecision timeToLive=\"9999999999999999999\">"
" <AttributeValuePair>"
" <Attribute name=\"POST\"/>"
" <Value>allow</Value>"
" </AttributeValuePair>"
" <Advices>"
" </Advices>"
" </ActionDecision>"
" <ActionDecision timeToLive=\"9999999999999999999\">"
" <AttributeValuePair>"
" <Attribute name=\"PATCH\"/>"
" <Value>allow</Value>"
" </AttributeValuePair>"
" <Advices>"
" </Advices>"
" </ActionDecision>"
" <ActionDecision timeToLive=\"9999999999999999999\">"
" <AttributeValuePair>"
" <Attribute name=\"GET\"/>"
" <Value>allow</Value>"
" </AttributeValuePair>"
" <Advices>"
" </Advices>"
" </ActionDecision>"
" <ActionDecision timeToLive=\"9999999999999999999\">"
" <AttributeValuePair>"
" <Attribute name=\"DELETE\"/>"
" <Value>allow</Value>"
" </AttributeValuePair>"
" <Advices>"
" </Advices>"
" </ActionDecision>"
" <ActionDecision timeToLive=\"9999999999999999999\">"
" <AttributeValuePair>"
" <Attribute name=\"OPTIONS\"/>"
" <Value>allow</Value>"
" </AttributeValuePair>"
" <Advices>"
" </Advices>"
" </ActionDecision>"
" <ActionDecision timeToLive=\"9999999999999999999\">"
" <AttributeValuePair>"
" <Attribute name=\"HEAD\"/>"
" <Value>allow</Value>"
" </AttributeValuePair>"
" <Advices>"
" </Advices>"
" </ActionDecision>"
" <ActionDecision timeToLive=\"9999999999999999999\">"
" <AttributeValuePair>"
" <Attribute name=\"PUT\"/>"
" <Value>allow</Value>"
" </AttributeValuePair>"
" <Advices>"
" </Advices>"
" </ActionDecision>"
" </PolicyDecision>"
" </ResourceResult>"
" </PolicyResponse>"
"</PolicyService>";
char* pll = "<?xml version='1.0' encoding='UTF-8' standalone='yes'?>"
"<ResponseSet vers='1.0' svcid='poicy' reqid='48'>"
" <Response><![CDATA[%s]]></Response>"
"</ResponseSet>";
/**
* Substitute our chosen URL into the "policy for url" string above. That way we can pretend
* we're getting different responses for different URLs. All the values are "allow" anyway.
*/
static char* get_policy_for_url(const char* url) {
return NULL;
}
return result;
}
{
int key_policy_seq, key_attr_seq;
char* key_format = NULL;
char* value_format = NULL;
assert_int_equal(sscanf(nvp->v, value_format, &value_policy_seq, &value_attr_seq, &value_value_seq), 3);
}
{
struct am_namevalue * nvp;
int count = 0;
count++;
}
return count;
}
{
struct am_policy_result* r = result;
assert_non_null(r);
}
/***************************************************************************************************/
void test_policy_result_reader(void **state) {
struct am_policy_result* result;
}
void test_policy_cache_simple(void **state) {
struct am_policy_result * result;
struct am_policy_result * r = NULL;
// destroy the cache, if it exists
}
const char alphabet[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789*";
{
int i;
for (i = 0; i < count; i++) {
}
}
static int test_cache_with_seed(int seed, int test_size, am_request_t * request, struct am_policy_result * result)
{
int i;
char key[128];
/* create initial entries */
for(i = 0; i < test_size; i++) {
printf("test_cache_with_seed: capacity is %d\n", i);
capacity = i;
break;
}
if (i % 1000 == 0)
printf("loaded %d..\n", i);
}
/* should refresh the whole lot */
for(i = 0; i < capacity; i++) {
if (i % 1000 == 0)
printf("reloaded %d..\n", i);
}
/* read them all back */
for(i = 0; i < capacity; i++) {
struct am_policy_result * r = NULL;
if (i % 1000 == 0)
printf("read %d..\n", i);
}
return capacity;
}
}
static void test_cache_keys(int test_size, char** keys, am_request_t* request, struct am_policy_result* result)
{
int i;
/* create initial entries */
for(i = 0; i < test_size; i++) {
}
/* should refresh the whole lot */
for(i = 0; i < test_size; i++) {
}
/* read them all back */
for(i = 0; i < test_size; i++) {
struct am_policy_result * r = NULL;
assert_int_equal(am_get_session_policy_cache_entry(request, keys [i], &r, &session, &ets), AM_SUCCESS);
}
}
void test_policy_cache_many_entries(void **state) {
const int test_size = 198;
struct am_policy_result * result;
// destroy the cache, if it exists
}
void test_policy_cache_purge_many_entries(void **state) {
const int test_size = 4096;
const int cache_valid_secs = 10000;
struct am_policy_result * result;
int capacity;
// destroy the cache, if it exists
}
void test_policy_cache_purge_during_insert(void **state) {
struct am_policy_result * result;
int loaded;
long elapsed;
// destroy the cache, if it exists
// time load to capacity
printf("starting timing phase..\n");
// wait the TTL to expire
// this update should trigger purge
printf("verifying expiry during load.. \n");
}
/**
* Now vary the incoming URL a bit and check we can get the same values out.
*/
int i;
struct am_policy_result * policy_result;
char fake_session[64];
char* urls[] = {
};
// destroy the cache, if it exists
/**
* Add the URLS above into the cache via the same session id
*/
assert_int_equal(am_add_session_policy_cache_entry(&request, fake_session, policy_result, NULL), AM_SUCCESS);
}
/**
* Check we can retrieve the URLs above from the cache via the same session id
*/
struct am_policy_result * r = NULL;
}
}
}
} else {
}
}
}
struct test_cache_params {
int test_size;
char** keys;
int iterations;
struct am_policy_result * result;
};
static void* test_cache_procedure(void * params)
{
int i;
struct test_cache_params * p = params;
for (i = 0; i < p->iterations; i++) {
}
return 0;
}
void test_policy_cache_multithread() {
struct am_policy_result* result;
/* this must be slightly less than the maximum because re-use of shm chunks might use more space */
#define TEST_SIZE 195
char key_buffer[64];
int i;
struct test_cache_params params = {
.iterations = 32,
};
#define NTHREADS 2
double dt;
for (i = 0; i < TEST_SIZE; i++) {
}
for (i = 0; i < NTHREADS; i++) {
}
for (i = 0; i < NTHREADS; i++) {
AM_THREAD_JOIN(threads[i]);
}
for (i = 0; i < TEST_SIZE; i++) {
}
}
}
/**
* This is an internal test of the mechanism for replaying a given number of randomly generated strings
*/
void test_key_creation(void **state) {
#define TEST_SIZE_1 10
char* keys[TEST_SIZE_1];
char key[64];
int i;
srand(543542);
for(i = 0; i < TEST_SIZE_1; i++) {
}
srand(543542);
for(i = 0; i < TEST_SIZE_1; i++) {
}
}