test_policy_cache.c revision 2e840960b0fa8189b1271ae984b33c031ae69530
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford/**
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford * The contents of this file are subject to the terms of the Common Development and
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford * Distribution License (the License). You may not use this file except in compliance with the
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford * License.
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford *
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford * specific language governing permission and limitations under the License.
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford *
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford * When distributing Covered Software, include this CDDL Header Notice in each file and include
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford * Header, with the fields enclosed by brackets [] replaced by your own identifying
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford * information: "Portions copyright [year] [name of copyright owner]".
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford *
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford * Copyright 2014 - 2015 ForgeRock AS.
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford */
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford#include <stdio.h>
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford#include <stdlib.h>
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford#include <string.h>
4c6011bfcf29cd75d6af86f192d709221f4d5d3aMareks Malnacs#include <setjmp.h>
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford
4c6011bfcf29cd75d6af86f192d709221f4d5d3aMareks Malnacs#include "platform.h"
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford#include "am.h"
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford#include "utility.h"
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford#include "list.h"
4c6011bfcf29cd75d6af86f192d709221f4d5d3aMareks Malnacs#include "thread.h"
4c6011bfcf29cd75d6af86f192d709221f4d5d3aMareks Malnacs#include "cmocka.h"
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford
48e27400d23e2586530cf943524e50c74d79a915Tony Bamfordvoid* am_parse_policy_xml(unsigned long instance_id, const char* xml, size_t xml_sz, int scope);
4c6011bfcf29cd75d6af86f192d709221f4d5d3aMareks Malnacsvoid am_worker_pool_init_reset();
4c6011bfcf29cd75d6af86f192d709221f4d5d3aMareks Malnacsvoid am_net_init_ssl_reset();
2e840960b0fa8189b1271ae984b33c031ae69530Nicholas Jamesint am_purge_caches(time_t expiry_time);
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford
48e27400d23e2586530cf943524e50c74d79a915Tony Bamfordchar* policy_xml = "<PolicyService version='1.0' revisionNumber='60'>"
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford "<PolicyResponse requestId='4' issueInstant='1424783306343' >"
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford " <ResourceResult name='http://vb2.local.com:80/testwebsite'>"
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford " <PolicyDecision>"
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford " <ResponseAttributes> <!-- these can have multiple (0..n) value elements -->"
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford " <AttributeValuePair>"
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford " <Attribute name='Attributes,key:0,0'/> <Value>Attributes,value:0,0,0</Value> <Value>Attributes,value:0,0,1</Value>"
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford " </AttributeValuePair>"
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford " <AttributeValuePair>"
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford " <Attribute name='Attributes,key:0,1'/> <Value>Attributes,value:0,1,0</Value>"
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford " </AttributeValuePair>"
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford " </ResponseAttributes>"
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford " <ActionDecision timeToLive='1234'> <!-- these can have no value elements, which defaults to ? -->"
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford " <AttributeValuePair>"
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford " <Attribute name='PUT'/> <Value>deny</Value>"
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford " </AttributeValuePair>"
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford " <Advices>"
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford " <AttributeValuePair>"
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford " <Attribute name='Advices,key:0,0'/> <Value>Advices,value:0,0,0</Value>"
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford " </AttributeValuePair>"
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford " <AttributeValuePair>"
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford " <Attribute name='Advices,key:0,1'/> <Value>Advices,value:0,1,0</Value>"
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford " </AttributeValuePair>"
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford " </Advices>"
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford " </ActionDecision>"
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford " <ActionDecision timeToLive='5678'>"
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford " <AttributeValuePair>"
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford " <Attribute name='GET'/> <Value>allow</Value>"
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford " </AttributeValuePair>"
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford " <Advices>"
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford " <AttributeValuePair>"
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford " <Attribute name='Advices,key:0,0'/> <Value>Advices,value:0,0,0</Value>"
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford " </AttributeValuePair>"
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford " <AttributeValuePair>"
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford " <Attribute name='Advices,key:0,1'/> <Value>Advices,value:0,1,0</Value>"
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford " </AttributeValuePair>"
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford " </Advices>"
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford " </ActionDecision>"
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford " <ActionDecision timeToLive='9012'>"
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford " <AttributeValuePair>"
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford " <Attribute name='POST'/> <Value>allow</Value>"
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford " </AttributeValuePair>"
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford " <Advices>"
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford " <AttributeValuePair>"
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford " <Attribute name='Advices,key:0,0'/> <Value>Advices,value:0,0,0</Value>"
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford " </AttributeValuePair>"
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford " <AttributeValuePair>"
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford " <Attribute name='Advices,key:0,1'/> <Value>Advices,value:0,1,0</Value>"
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford " </AttributeValuePair>"
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford " <AttributeValuePair>"
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford " <Attribute name='Advices,key:0,2'/> <Value>Advices,value:0,2,0</Value>"
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford " </AttributeValuePair>"
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford " </Advices>"
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford " </ActionDecision>"
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford " <ResponseDecisions>"
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford " <AttributeValuePair>"
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford " <Attribute name='Decision,key:0,0'/> <Value>Decision,value:0,0,0</Value>"
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford " </AttributeValuePair>"
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford " <AttributeValuePair>"
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford " <Attribute name='Decision,key:0,1'/> <Value>Decision,value:0,1,0</Value>"
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford " </AttributeValuePair>"
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford " <AttributeValuePair>"
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford " <Attribute name='Decision,key:0,2'/> <Value>Decision,value:0,2,0</Value>"
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford " </AttributeValuePair>"
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford " </ResponseDecisions>"
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford " </PolicyDecision>"
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford " </ResourceResult>"
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford "</PolicyResponse>"
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford "</PolicyService>";
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamfordchar* policy_for_url =
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford "<PolicyService version=\"1.0\" revisionNumber=\"60\">"
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford " <PolicyResponse requestId=\"4\" issueInstant=\"9999999999999\" >"
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford " <ResourceResult name=\"%s\">"
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford " <PolicyDecision>"
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford " <ResponseAttributes>"
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford " </ResponseAttributes>"
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford " <ActionDecision timeToLive=\"9999999999999999999\">"
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford " <AttributeValuePair>"
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford " <Attribute name=\"POST\"/>"
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford " <Value>allow</Value>"
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford " </AttributeValuePair>"
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford " <Advices>"
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford " </Advices>"
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford " </ActionDecision>"
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford " <ActionDecision timeToLive=\"9999999999999999999\">"
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford " <AttributeValuePair>"
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford " <Attribute name=\"PATCH\"/>"
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford " <Value>allow</Value>"
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford " </AttributeValuePair>"
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford " <Advices>"
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford " </Advices>"
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford " </ActionDecision>"
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford " <ActionDecision timeToLive=\"9999999999999999999\">"
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford " <AttributeValuePair>"
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford " <Attribute name=\"GET\"/>"
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford " <Value>allow</Value>"
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford " </AttributeValuePair>"
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford " <Advices>"
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford " </Advices>"
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford " </ActionDecision>"
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford " <ActionDecision timeToLive=\"9999999999999999999\">"
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford " <AttributeValuePair>"
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford " <Attribute name=\"DELETE\"/>"
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford " <Value>allow</Value>"
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford " </AttributeValuePair>"
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford " <Advices>"
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford " </Advices>"
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford " </ActionDecision>"
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford " <ActionDecision timeToLive=\"9999999999999999999\">"
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford " <AttributeValuePair>"
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford " <Attribute name=\"OPTIONS\"/>"
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford " <Value>allow</Value>"
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford " </AttributeValuePair>"
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford " <Advices>"
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford " </Advices>"
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford " </ActionDecision>"
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford " <ActionDecision timeToLive=\"9999999999999999999\">"
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford " <AttributeValuePair>"
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford " <Attribute name=\"HEAD\"/>"
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford " <Value>allow</Value>"
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford " </AttributeValuePair>"
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford " <Advices>"
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford " </Advices>"
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford " </ActionDecision>"
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford " <ActionDecision timeToLive=\"9999999999999999999\">"
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford " <AttributeValuePair>"
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford " <Attribute name=\"PUT\"/>"
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford " <Value>allow</Value>"
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford " </AttributeValuePair>"
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford " <Advices>"
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford " </Advices>"
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford " </ActionDecision>"
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford " </PolicyDecision>"
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford " </ResourceResult>"
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford " </PolicyResponse>"
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford "</PolicyService>";
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford
48e27400d23e2586530cf943524e50c74d79a915Tony Bamfordchar* pll = "<?xml version='1.0' encoding='UTF-8' standalone='yes'?>"
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford "<ResponseSet vers='1.0' svcid='poicy' reqid='48'>"
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford " <Response><![CDATA[%s]]></Response>"
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford "</ResponseSet>";
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford/**
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford * Substitute our chosen URL into the "policy for url" string above. That way we can pretend
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford * we're getting different responses for different URLs. All the values are "allow" anyway.
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford */
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamfordstatic char* get_policy_for_url(const char* url) {
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford char* buff1 = NULL;
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford char* result = NULL;
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford am_asprintf(&buff1, policy_for_url, url);
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford if (buff1 == NULL) {
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford return NULL;
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford }
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford am_asprintf(&result, pll, buff1);
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford am_free(buff1);
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford return result;
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford}
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford
48e27400d23e2586530cf943524e50c74d79a915Tony Bamfordstatic void test_namevalue_pair(const char* prefix, struct am_namevalue* nvp)
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford{
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford int key_policy_seq, key_attr_seq;
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford int value_policy_seq, value_attr_seq, value_value_seq;
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford
4c6011bfcf29cd75d6af86f192d709221f4d5d3aMareks Malnacs char* key_format = NULL;
4c6011bfcf29cd75d6af86f192d709221f4d5d3aMareks Malnacs char* value_format = NULL;
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford
4c6011bfcf29cd75d6af86f192d709221f4d5d3aMareks Malnacs am_asprintf(&key_format, "%s%s", prefix, ",key:%d,%d");
4c6011bfcf29cd75d6af86f192d709221f4d5d3aMareks Malnacs am_asprintf(&value_format, "%s%s", prefix, ",value:%d,%d,%d");
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford assert_int_equal(sscanf(nvp->n, key_format, &key_policy_seq, &key_attr_seq), 2);
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford assert_int_equal(sscanf(nvp->v, value_format, &value_policy_seq, &value_attr_seq, &value_value_seq), 3);
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford assert_int_equal(key_policy_seq, value_policy_seq);
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford assert_int_equal(key_attr_seq, value_attr_seq);
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford free(key_format);
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford free(value_format);
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford}
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford
48e27400d23e2586530cf943524e50c74d79a915Tony Bamfordstatic int test_attributes(const char * prefix, struct am_namevalue * head)
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford{
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford struct am_namevalue * nvp;
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford int count = 0;
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford for (nvp = head; nvp; nvp = nvp->next) {
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford test_namevalue_pair(prefix, nvp);
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford count++;
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford }
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford return count;
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford}
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford
48e27400d23e2586530cf943524e50c74d79a915Tony Bamfordstatic void test_policy_structure(struct am_policy_result * result)
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford{
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford struct am_policy_result* r = result;
4c6011bfcf29cd75d6af86f192d709221f4d5d3aMareks Malnacs struct am_action_decision* ad = r != NULL ? r->action_decisions : NULL;
4c6011bfcf29cd75d6af86f192d709221f4d5d3aMareks Malnacs
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford assert_non_null(r);
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford assert_string_equal(r->resource, "http://vb2.local.com:80/testwebsite");
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford assert_int_equal(test_attributes("Attributes", r->response_attributes), 3);
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford assert_int_equal(test_attributes("Decision", r->response_decisions), 3);
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford assert_non_null(ad);
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford assert_string_equal(am_method_num_to_str(ad->method), "PUT");
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford assert_string_equal(ad->action ? "allow" : "deny", "deny");
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford assert_int_equal(ad->ttl, 1234);
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford assert_int_equal(test_attributes("Advices", ad->advices), 2);
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford ad = ad->next;
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford assert_non_null(ad);
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford assert_string_equal(am_method_num_to_str(ad->method), "GET");
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford assert_string_equal(ad->action ? "allow" : "deny", "allow");
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford assert_int_equal(ad->ttl, 5678);
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford assert_int_equal(test_attributes("Advices", ad->advices), 2);
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford ad = ad->next;
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford assert_non_null(ad);
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford assert_string_equal(am_method_num_to_str(ad->method), "POST");
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford assert_string_equal(ad->action ? "allow" : "deny", "allow");
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford assert_int_equal(ad->ttl, 9012);
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford assert_int_equal(test_attributes("Advices", ad->advices), 3);
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford delete_am_policy_result_list(&result);
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford}
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford/***************************************************************************************************/
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford
48e27400d23e2586530cf943524e50c74d79a915Tony Bamfordvoid test_policy_result_reader(void **state) {
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford size_t size;
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford char* buffer = NULL;
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford struct am_policy_result* result;
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford
4c6011bfcf29cd75d6af86f192d709221f4d5d3aMareks Malnacs am_asprintf(&buffer, pll, policy_xml);
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford size = strlen(pll);
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford result = am_parse_policy_xml(0l, buffer, size, 0);
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford free(buffer);
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford test_policy_structure(result);
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford}
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford
48e27400d23e2586530cf943524e50c74d79a915Tony Bamfordvoid test_policy_cache_simple(void **state) {
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford
4c6011bfcf29cd75d6af86f192d709221f4d5d3aMareks Malnacs am_config_t config;
4c6011bfcf29cd75d6af86f192d709221f4d5d3aMareks Malnacs am_request_t request;
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford char* buffer = NULL;
4c6011bfcf29cd75d6af86f192d709221f4d5d3aMareks Malnacs struct am_policy_result * result;
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford time_t ets;
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford struct am_policy_result * r = NULL;
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford struct am_namevalue * session = NULL;
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford
4c6011bfcf29cd75d6af86f192d709221f4d5d3aMareks Malnacs memset(&config, 0, sizeof(am_config_t));
4c6011bfcf29cd75d6af86f192d709221f4d5d3aMareks Malnacs memset(&request, 0, sizeof(am_request_t));
4c6011bfcf29cd75d6af86f192d709221f4d5d3aMareks Malnacs request.conf = &config;
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford
4c6011bfcf29cd75d6af86f192d709221f4d5d3aMareks Malnacs am_asprintf(&buffer, pll, policy_xml);
4c6011bfcf29cd75d6af86f192d709221f4d5d3aMareks Malnacs result = am_parse_policy_xml(0l, buffer, strlen(buffer), 0);
4c6011bfcf29cd75d6af86f192d709221f4d5d3aMareks Malnacs
4c6011bfcf29cd75d6af86f192d709221f4d5d3aMareks Malnacs free(buffer);
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford // destroy the cache, if it exists
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford am_cache_destroy();
4c6011bfcf29cd75d6af86f192d709221f4d5d3aMareks Malnacs assert_int_equal(am_init(), AM_SUCCESS);
4c6011bfcf29cd75d6af86f192d709221f4d5d3aMareks Malnacs am_init_worker();
4c6011bfcf29cd75d6af86f192d709221f4d5d3aMareks Malnacs
4c6011bfcf29cd75d6af86f192d709221f4d5d3aMareks Malnacs am_add_session_policy_cache_entry(&request, "Policy-key", result, NULL);
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford am_get_session_policy_cache_entry(&request, "Policy-key", &r, &session, &ets);
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford
4c6011bfcf29cd75d6af86f192d709221f4d5d3aMareks Malnacs am_shutdown_worker();
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford am_cache_destroy();
4c6011bfcf29cd75d6af86f192d709221f4d5d3aMareks Malnacs am_worker_pool_init_reset();
4c6011bfcf29cd75d6af86f192d709221f4d5d3aMareks Malnacs am_net_init_ssl_reset();
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford test_policy_structure(r);
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford}
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford
48e27400d23e2586530cf943524e50c74d79a915Tony Bamfordconst char alphabet[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789*";
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford
48e27400d23e2586530cf943524e50c74d79a915Tony Bamfordvoid create_random_cache_key(char * buffer, size_t size)
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford{
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford int i;
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford size_t count = size - 1;
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford size_t len = sizeof(alphabet) - 1;
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford for (i = 0; i < count; i++) {
4c6011bfcf29cd75d6af86f192d709221f4d5d3aMareks Malnacs buffer[i] = alphabet[rand() % len];
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford }
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford buffer[count] = 0;
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford}
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford
2e840960b0fa8189b1271ae984b33c031ae69530Nicholas Jamesstatic void test_cache_with_seed(int seed, int test_size, am_request_t * request, struct am_policy_result * result)
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford{
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford int i;
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford char key[64];
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford
4c6011bfcf29cd75d6af86f192d709221f4d5d3aMareks Malnacs /* create initial entries */
2e840960b0fa8189b1271ae984b33c031ae69530Nicholas James srand(seed);
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford for(i = 0; i < test_size; i++) {
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford create_random_cache_key(key, sizeof(key));
4c6011bfcf29cd75d6af86f192d709221f4d5d3aMareks Malnacs assert_int_equal(am_add_session_policy_cache_entry(request, key, result, NULL), AM_SUCCESS);
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford }
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford
4c6011bfcf29cd75d6af86f192d709221f4d5d3aMareks Malnacs /* should refresh the whole lot */
2e840960b0fa8189b1271ae984b33c031ae69530Nicholas James srand(seed);
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford for(i = 0; i < test_size; i++) {
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford create_random_cache_key(key, sizeof(key));
4c6011bfcf29cd75d6af86f192d709221f4d5d3aMareks Malnacs assert_int_equal(am_add_session_policy_cache_entry(request, key, result, NULL), AM_SUCCESS);
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford }
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford
4c6011bfcf29cd75d6af86f192d709221f4d5d3aMareks Malnacs /* read them all back */
2e840960b0fa8189b1271ae984b33c031ae69530Nicholas James srand(seed);
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford for(i = 0; i < test_size; i++) {
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford time_t ets;
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford struct am_policy_result * r = NULL;
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford struct am_namevalue * session = NULL;
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford create_random_cache_key(key, sizeof(key));
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford assert_int_equal(am_get_session_policy_cache_entry(request, key, &r, &session, &ets), AM_SUCCESS);
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford test_policy_structure(r);
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford }
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford}
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford
2e840960b0fa8189b1271ae984b33c031ae69530Nicholas Jamesstatic void test_cache(int test_size, am_request_t * request, struct am_policy_result * result) {
2e840960b0fa8189b1271ae984b33c031ae69530Nicholas James test_cache_with_seed(543542, test_size, request, result);
2e840960b0fa8189b1271ae984b33c031ae69530Nicholas James}
2e840960b0fa8189b1271ae984b33c031ae69530Nicholas James
2e840960b0fa8189b1271ae984b33c031ae69530Nicholas James
48e27400d23e2586530cf943524e50c74d79a915Tony Bamfordstatic void test_cache_keys(int test_size, char** keys, am_request_t* request, struct am_policy_result* result)
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford{
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford int i;
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford
4c6011bfcf29cd75d6af86f192d709221f4d5d3aMareks Malnacs /* create initial entries */
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford for(i = 0; i < test_size; i++) {
4c6011bfcf29cd75d6af86f192d709221f4d5d3aMareks Malnacs assert_int_equal(am_add_session_policy_cache_entry(request, keys [i], result, NULL), AM_SUCCESS);
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford }
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford
4c6011bfcf29cd75d6af86f192d709221f4d5d3aMareks Malnacs /* should refresh the whole lot */
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford for(i = 0; i < test_size; i++) {
4c6011bfcf29cd75d6af86f192d709221f4d5d3aMareks Malnacs assert_int_equal(am_add_session_policy_cache_entry(request, keys [i], result, NULL), AM_SUCCESS);
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford }
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford
4c6011bfcf29cd75d6af86f192d709221f4d5d3aMareks Malnacs /* read them all back */
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford for(i = 0; i < test_size; i++) {
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford time_t ets;
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford struct am_policy_result * r = NULL;
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford struct am_namevalue * session = NULL;
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford assert_int_equal(am_get_session_policy_cache_entry(request, keys [i], &r, &session, &ets), AM_SUCCESS);
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford test_policy_structure(r);
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford }
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford}
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford
48e27400d23e2586530cf943524e50c74d79a915Tony Bamfordvoid test_policy_cache_many_entries(void **state) {
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford const int test_size = 198;
4c6011bfcf29cd75d6af86f192d709221f4d5d3aMareks Malnacs char* buffer = NULL;
4c6011bfcf29cd75d6af86f192d709221f4d5d3aMareks Malnacs struct am_policy_result * result;
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford
4c6011bfcf29cd75d6af86f192d709221f4d5d3aMareks Malnacs am_config_t config;
4c6011bfcf29cd75d6af86f192d709221f4d5d3aMareks Malnacs am_request_t request;
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford
4c6011bfcf29cd75d6af86f192d709221f4d5d3aMareks Malnacs memset(&config, 0, sizeof(am_config_t));
4c6011bfcf29cd75d6af86f192d709221f4d5d3aMareks Malnacs memset(&request, 0, sizeof(am_request_t));
4c6011bfcf29cd75d6af86f192d709221f4d5d3aMareks Malnacs request.conf = &config;
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford
4c6011bfcf29cd75d6af86f192d709221f4d5d3aMareks Malnacs am_asprintf(&buffer, pll, policy_xml);
4c6011bfcf29cd75d6af86f192d709221f4d5d3aMareks Malnacs result = am_parse_policy_xml(0l, buffer, strlen(buffer), 0);
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford free(buffer);
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford // destroy the cache, if it exists
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford am_cache_destroy();
4c6011bfcf29cd75d6af86f192d709221f4d5d3aMareks Malnacs assert_int_equal(am_init(), AM_SUCCESS);
4c6011bfcf29cd75d6af86f192d709221f4d5d3aMareks Malnacs am_init_worker();
4c6011bfcf29cd75d6af86f192d709221f4d5d3aMareks Malnacs
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford test_cache(test_size, &request, result);
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford delete_am_policy_result_list(&result);
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford
4c6011bfcf29cd75d6af86f192d709221f4d5d3aMareks Malnacs am_shutdown_worker();
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford am_cache_destroy();
4c6011bfcf29cd75d6af86f192d709221f4d5d3aMareks Malnacs am_worker_pool_init_reset();
4c6011bfcf29cd75d6af86f192d709221f4d5d3aMareks Malnacs am_net_init_ssl_reset();
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford}
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford
2e840960b0fa8189b1271ae984b33c031ae69530Nicholas Jamesvoid test_policy_cache_purge_many_entries(void **state) {
2e840960b0fa8189b1271ae984b33c031ae69530Nicholas James
2e840960b0fa8189b1271ae984b33c031ae69530Nicholas James const int test_size = 198;
2e840960b0fa8189b1271ae984b33c031ae69530Nicholas James char* buffer = NULL;
2e840960b0fa8189b1271ae984b33c031ae69530Nicholas James struct am_policy_result * result;
2e840960b0fa8189b1271ae984b33c031ae69530Nicholas James
2e840960b0fa8189b1271ae984b33c031ae69530Nicholas James am_config_t config;
2e840960b0fa8189b1271ae984b33c031ae69530Nicholas James am_request_t request;
2e840960b0fa8189b1271ae984b33c031ae69530Nicholas James
2e840960b0fa8189b1271ae984b33c031ae69530Nicholas James memset(&config, 0, sizeof(am_config_t));
2e840960b0fa8189b1271ae984b33c031ae69530Nicholas James memset(&request, 0, sizeof(am_request_t));
2e840960b0fa8189b1271ae984b33c031ae69530Nicholas James request.conf = &config;
2e840960b0fa8189b1271ae984b33c031ae69530Nicholas James
2e840960b0fa8189b1271ae984b33c031ae69530Nicholas James am_asprintf(&buffer, pll, policy_xml);
2e840960b0fa8189b1271ae984b33c031ae69530Nicholas James result = am_parse_policy_xml(0l, buffer, strlen(buffer), 0);
2e840960b0fa8189b1271ae984b33c031ae69530Nicholas James
2e840960b0fa8189b1271ae984b33c031ae69530Nicholas James free(buffer);
2e840960b0fa8189b1271ae984b33c031ae69530Nicholas James
2e840960b0fa8189b1271ae984b33c031ae69530Nicholas James // destroy the cache, if it exists
2e840960b0fa8189b1271ae984b33c031ae69530Nicholas James am_cache_destroy();
2e840960b0fa8189b1271ae984b33c031ae69530Nicholas James assert_int_equal(am_init(), AM_SUCCESS);
2e840960b0fa8189b1271ae984b33c031ae69530Nicholas James am_init_worker();
2e840960b0fa8189b1271ae984b33c031ae69530Nicholas James
2e840960b0fa8189b1271ae984b33c031ae69530Nicholas James test_cache(test_size, &request, result);
2e840960b0fa8189b1271ae984b33c031ae69530Nicholas James
2e840960b0fa8189b1271ae984b33c031ae69530Nicholas James assert_int_equal(am_purge_caches(time(NULL) + 10), test_size);
2e840960b0fa8189b1271ae984b33c031ae69530Nicholas James
2e840960b0fa8189b1271ae984b33c031ae69530Nicholas James delete_am_policy_result_list(&result);
2e840960b0fa8189b1271ae984b33c031ae69530Nicholas James
2e840960b0fa8189b1271ae984b33c031ae69530Nicholas James am_shutdown_worker();
2e840960b0fa8189b1271ae984b33c031ae69530Nicholas James am_cache_destroy();
2e840960b0fa8189b1271ae984b33c031ae69530Nicholas James am_worker_pool_init_reset();
2e840960b0fa8189b1271ae984b33c031ae69530Nicholas James am_net_init_ssl_reset();
2e840960b0fa8189b1271ae984b33c031ae69530Nicholas James}
2e840960b0fa8189b1271ae984b33c031ae69530Nicholas James
2e840960b0fa8189b1271ae984b33c031ae69530Nicholas Jamesvoid test_policy_cache_purge_during_insert(void **state) {
2e840960b0fa8189b1271ae984b33c031ae69530Nicholas James
2e840960b0fa8189b1271ae984b33c031ae69530Nicholas James const int test_size = 198;
2e840960b0fa8189b1271ae984b33c031ae69530Nicholas James char* buffer = NULL;
2e840960b0fa8189b1271ae984b33c031ae69530Nicholas James struct am_policy_result * result;
2e840960b0fa8189b1271ae984b33c031ae69530Nicholas James
2e840960b0fa8189b1271ae984b33c031ae69530Nicholas James am_config_t config;
2e840960b0fa8189b1271ae984b33c031ae69530Nicholas James am_request_t request;
2e840960b0fa8189b1271ae984b33c031ae69530Nicholas James
2e840960b0fa8189b1271ae984b33c031ae69530Nicholas James memset(&config, 0, sizeof(am_config_t));
2e840960b0fa8189b1271ae984b33c031ae69530Nicholas James memset(&request, 0, sizeof(am_request_t));
2e840960b0fa8189b1271ae984b33c031ae69530Nicholas James request.conf = &config;
2e840960b0fa8189b1271ae984b33c031ae69530Nicholas James
2e840960b0fa8189b1271ae984b33c031ae69530Nicholas James am_asprintf(&buffer, pll, policy_xml);
2e840960b0fa8189b1271ae984b33c031ae69530Nicholas James result = am_parse_policy_xml(0l, buffer, strlen(buffer), 0);
2e840960b0fa8189b1271ae984b33c031ae69530Nicholas James
2e840960b0fa8189b1271ae984b33c031ae69530Nicholas James free(buffer);
2e840960b0fa8189b1271ae984b33c031ae69530Nicholas James
2e840960b0fa8189b1271ae984b33c031ae69530Nicholas James // destroy the cache, if it exists
2e840960b0fa8189b1271ae984b33c031ae69530Nicholas James am_cache_destroy();
2e840960b0fa8189b1271ae984b33c031ae69530Nicholas James assert_int_equal(am_init(), AM_SUCCESS);
2e840960b0fa8189b1271ae984b33c031ae69530Nicholas James am_init_worker();
2e840960b0fa8189b1271ae984b33c031ae69530Nicholas James
2e840960b0fa8189b1271ae984b33c031ae69530Nicholas James test_cache(test_size, &request, result);
2e840960b0fa8189b1271ae984b33c031ae69530Nicholas James
2e840960b0fa8189b1271ae984b33c031ae69530Nicholas James // wait 2 seconds for the TTL to expire
2e840960b0fa8189b1271ae984b33c031ae69530Nicholas James sleep(2);
2e840960b0fa8189b1271ae984b33c031ae69530Nicholas James
2e840960b0fa8189b1271ae984b33c031ae69530Nicholas James // another 10 is too many without the purge functionality
2e840960b0fa8189b1271ae984b33c031ae69530Nicholas James test_cache_with_seed(321213, 10, &request, result);
2e840960b0fa8189b1271ae984b33c031ae69530Nicholas James
2e840960b0fa8189b1271ae984b33c031ae69530Nicholas James // check that there are only these 10 left
2e840960b0fa8189b1271ae984b33c031ae69530Nicholas James assert_int_equal(am_purge_caches(time(NULL) + 10), 10);
2e840960b0fa8189b1271ae984b33c031ae69530Nicholas James
2e840960b0fa8189b1271ae984b33c031ae69530Nicholas James delete_am_policy_result_list(&result);
2e840960b0fa8189b1271ae984b33c031ae69530Nicholas James
2e840960b0fa8189b1271ae984b33c031ae69530Nicholas James am_shutdown_worker();
2e840960b0fa8189b1271ae984b33c031ae69530Nicholas James am_cache_destroy();
2e840960b0fa8189b1271ae984b33c031ae69530Nicholas James am_worker_pool_init_reset();
2e840960b0fa8189b1271ae984b33c031ae69530Nicholas James am_net_init_ssl_reset();
2e840960b0fa8189b1271ae984b33c031ae69530Nicholas James}
2e840960b0fa8189b1271ae984b33c031ae69530Nicholas James
2e840960b0fa8189b1271ae984b33c031ae69530Nicholas James
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford/**
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford * Now vary the incoming URL a bit and check we can get the same values out.
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford */
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamfordvoid test_policy_cache_with_many_different_entries_single_session(void **state) {
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford int i;
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford char* buffer = NULL;
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford struct am_policy_result * policy_result;
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford char fake_session[64];
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford char* urls[] = {
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford "http://agent.a-example.com:8080/allowed.html",
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford "http://agent.b-example.com:8080/allowed.html?attr1=value1",
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford "http://agent.c-example.com:8080/also-allowed.html",
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford "http://agent.d-example.com:8080/allow.php",
acd3d5e2fd1764e71799b27badbd349550ca9400Mareks Malnacs "http://agent.c-example.com:8080/also-allowed.html",
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford "http://agent.e-example.com:8080/allowed/index.html",
acd3d5e2fd1764e71799b27badbd349550ca9400Mareks Malnacs "http://agent.a-example.com:8080/allowed.html",
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford };
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford am_config_t config;
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford am_request_t request;
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford // destroy the cache, if it exists
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford am_cache_destroy();
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford assert_int_equal(am_init(), AM_SUCCESS);
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford am_init_worker();
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford create_random_cache_key(fake_session, sizeof(fake_session));
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford /**
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford * Add the URLS above into the cache via the same session id
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford */
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford for (i = 0; i < sizeof(urls)/sizeof(urls[0]); i++) {
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford memset(&config, 0, sizeof(am_config_t));
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford memset(&request, 0, sizeof(am_request_t));
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford request.conf = &config;
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford buffer = get_policy_for_url(urls[i]);
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford policy_result = am_parse_policy_xml(0l, buffer, strlen(buffer), 0);
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford free(buffer);
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford assert_int_equal(am_add_session_policy_cache_entry(&request, fake_session, policy_result, NULL), AM_SUCCESS);
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford }
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford /**
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford * Check we can retrieve the URLs above from the cache via the same session id
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford */
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford for (i = 0; i < sizeof(urls)/sizeof(urls[0]); i++) {
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford time_t ets;
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford struct am_policy_result * r = NULL;
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford struct am_policy_result * result = NULL;
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford struct am_namevalue * session = NULL;
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford memset(&config, 0, sizeof(am_config_t));
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford memset(&request, 0, sizeof(am_request_t));
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford request.conf = &config;
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford request.orig_url = urls[i];
acd3d5e2fd1764e71799b27badbd349550ca9400Mareks Malnacs
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford if (am_get_session_policy_cache_entry(&request, fake_session, &r, &session, &ets) == AM_SUCCESS) {
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford am_bool_t found = AM_FALSE;
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford for (result = r; result != NULL; result = result->next) {
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford if (strcmp(result->resource, urls[i]) == 0) {
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford found = AM_TRUE;
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford }
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford }
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford if (found == AM_FALSE) {
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford AM_LOG_ERROR(0, "Failed to match policy for URL %s, although results retrieved", urls[i]);
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford }
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford assert_int_equal(found, AM_TRUE);
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford } else {
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford AM_LOG_ERROR(0, "Failed to retrieve policy for URL %s", urls[i]);
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford }
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford }
acd3d5e2fd1764e71799b27badbd349550ca9400Mareks Malnacs
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford am_shutdown_worker();
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford am_cache_destroy();
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford am_worker_pool_init_reset();
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford am_net_init_ssl_reset();
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford}
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford
48e27400d23e2586530cf943524e50c74d79a915Tony Bamfordstruct test_cache_params {
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford int test_size;
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford char** keys;
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford int iterations;
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford am_request_t * request;
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford struct am_policy_result * result;
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford};
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford
48e27400d23e2586530cf943524e50c74d79a915Tony Bamfordstatic void* test_cache_procedure(void * params)
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford{
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford int i;
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford struct test_cache_params * p = params;
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford for (i = 0; i < p->iterations; i++) {
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford test_cache_keys(p->test_size, p->keys, p->request, p->result);
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford }
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford return 0;
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford}
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford
4c6011bfcf29cd75d6af86f192d709221f4d5d3aMareks Malnacsvoid test_policy_cache_multithread() {
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford
4c6011bfcf29cd75d6af86f192d709221f4d5d3aMareks Malnacs am_config_t config;
4c6011bfcf29cd75d6af86f192d709221f4d5d3aMareks Malnacs am_request_t request;
4c6011bfcf29cd75d6af86f192d709221f4d5d3aMareks Malnacs char* buffer = NULL;
4c6011bfcf29cd75d6af86f192d709221f4d5d3aMareks Malnacs struct am_policy_result* result;
4c6011bfcf29cd75d6af86f192d709221f4d5d3aMareks Malnacs /* this must be slightly less than the maximum because re-use of shm chunks might use more space */
4c6011bfcf29cd75d6af86f192d709221f4d5d3aMareks Malnacs#define TEST_SIZE 195
4c6011bfcf29cd75d6af86f192d709221f4d5d3aMareks Malnacs char* keys [TEST_SIZE];
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford char key_buffer[64];
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford int i;
4c6011bfcf29cd75d6af86f192d709221f4d5d3aMareks Malnacs
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford am_cache_destroy();
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford
4c6011bfcf29cd75d6af86f192d709221f4d5d3aMareks Malnacs memset(&config, 0, sizeof (am_config_t));
4c6011bfcf29cd75d6af86f192d709221f4d5d3aMareks Malnacs memset(&request, 0, sizeof (am_request_t));
4c6011bfcf29cd75d6af86f192d709221f4d5d3aMareks Malnacs request.conf = &config;
4c6011bfcf29cd75d6af86f192d709221f4d5d3aMareks Malnacs
4c6011bfcf29cd75d6af86f192d709221f4d5d3aMareks Malnacs am_asprintf(&buffer, pll, policy_xml);
4c6011bfcf29cd75d6af86f192d709221f4d5d3aMareks Malnacs result = am_parse_policy_xml(0l, buffer, strlen(buffer), 0);
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford free(buffer);
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford
4c6011bfcf29cd75d6af86f192d709221f4d5d3aMareks Malnacs assert_non_null(result);
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford
4c6011bfcf29cd75d6af86f192d709221f4d5d3aMareks Malnacs if (result != NULL) {
4c6011bfcf29cd75d6af86f192d709221f4d5d3aMareks Malnacs struct test_cache_params params = {
4c6011bfcf29cd75d6af86f192d709221f4d5d3aMareks Malnacs .test_size = TEST_SIZE,
4c6011bfcf29cd75d6af86f192d709221f4d5d3aMareks Malnacs .keys = keys,
4c6011bfcf29cd75d6af86f192d709221f4d5d3aMareks Malnacs
4c6011bfcf29cd75d6af86f192d709221f4d5d3aMareks Malnacs .iterations = 32,
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford
4c6011bfcf29cd75d6af86f192d709221f4d5d3aMareks Malnacs .request = &request,
4c6011bfcf29cd75d6af86f192d709221f4d5d3aMareks Malnacs .result = result,
4c6011bfcf29cd75d6af86f192d709221f4d5d3aMareks Malnacs };
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford
4c6011bfcf29cd75d6af86f192d709221f4d5d3aMareks Malnacs long t0 = clock();
4c6011bfcf29cd75d6af86f192d709221f4d5d3aMareks Malnacs#define NTHREADS 2
4c6011bfcf29cd75d6af86f192d709221f4d5d3aMareks Malnacs am_thread_t threads [NTHREADS];
4c6011bfcf29cd75d6af86f192d709221f4d5d3aMareks Malnacs double dt;
4c6011bfcf29cd75d6af86f192d709221f4d5d3aMareks Malnacs
4c6011bfcf29cd75d6af86f192d709221f4d5d3aMareks Malnacs for (i = 0; i < TEST_SIZE; i++) {
4c6011bfcf29cd75d6af86f192d709221f4d5d3aMareks Malnacs create_random_cache_key(key_buffer, sizeof (key_buffer));
4c6011bfcf29cd75d6af86f192d709221f4d5d3aMareks Malnacs keys[i] = strdup(key_buffer);
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford }
4c6011bfcf29cd75d6af86f192d709221f4d5d3aMareks Malnacs
4c6011bfcf29cd75d6af86f192d709221f4d5d3aMareks Malnacs assert_int_equal(am_cache_init(), AM_SUCCESS);
4c6011bfcf29cd75d6af86f192d709221f4d5d3aMareks Malnacs
4c6011bfcf29cd75d6af86f192d709221f4d5d3aMareks Malnacs fprintf(stdout, "info: started multithreaded cache tests.. ");
4c6011bfcf29cd75d6af86f192d709221f4d5d3aMareks Malnacs fflush(stdout);
4c6011bfcf29cd75d6af86f192d709221f4d5d3aMareks Malnacs
4c6011bfcf29cd75d6af86f192d709221f4d5d3aMareks Malnacs for (i = 0; i < NTHREADS; i++) {
4c6011bfcf29cd75d6af86f192d709221f4d5d3aMareks Malnacs AM_THREAD_CREATE(threads[i], test_cache_procedure, &params);
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford }
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford
4c6011bfcf29cd75d6af86f192d709221f4d5d3aMareks Malnacs for (i = 0; i < NTHREADS; i++) {
4c6011bfcf29cd75d6af86f192d709221f4d5d3aMareks Malnacs AM_THREAD_JOIN(threads[i]);
4c6011bfcf29cd75d6af86f192d709221f4d5d3aMareks Malnacs }
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford
4c6011bfcf29cd75d6af86f192d709221f4d5d3aMareks Malnacs dt = ((double) (clock() - t0)) / CLOCKS_PER_SEC;
4c6011bfcf29cd75d6af86f192d709221f4d5d3aMareks Malnacs fprintf(stdout, "finished after %lf secs\n", dt);
4c6011bfcf29cd75d6af86f192d709221f4d5d3aMareks Malnacs
4c6011bfcf29cd75d6af86f192d709221f4d5d3aMareks Malnacs assert_int_equal(am_cache_shutdown(), AM_SUCCESS);
4c6011bfcf29cd75d6af86f192d709221f4d5d3aMareks Malnacs
4c6011bfcf29cd75d6af86f192d709221f4d5d3aMareks Malnacs delete_am_policy_result_list(&result);
4c6011bfcf29cd75d6af86f192d709221f4d5d3aMareks Malnacs
4c6011bfcf29cd75d6af86f192d709221f4d5d3aMareks Malnacs for (i = 0; i < TEST_SIZE; i++) {
4c6011bfcf29cd75d6af86f192d709221f4d5d3aMareks Malnacs free(keys[i]);
4c6011bfcf29cd75d6af86f192d709221f4d5d3aMareks Malnacs }
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford }
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford
ef2c6005cfeddae287cd168584dd348ba8eba6adTony Bamford am_cache_destroy();
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford}
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford/**
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford * This is an internal test of the mechanism for replaying a given number of randomly generated strings
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford */
48e27400d23e2586530cf943524e50c74d79a915Tony Bamfordvoid test_key_creation(void **state) {
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford
4c6011bfcf29cd75d6af86f192d709221f4d5d3aMareks Malnacs#define TEST_SIZE_1 10
4c6011bfcf29cd75d6af86f192d709221f4d5d3aMareks Malnacs char* keys[TEST_SIZE_1];
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford char key[64];
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford int i;
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford
4c6011bfcf29cd75d6af86f192d709221f4d5d3aMareks Malnacs srand(543542);
4c6011bfcf29cd75d6af86f192d709221f4d5d3aMareks Malnacs for(i = 0; i < TEST_SIZE_1; i++) {
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford create_random_cache_key(key, sizeof(key));
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford keys[i] = strdup(key);
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford }
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford
4c6011bfcf29cd75d6af86f192d709221f4d5d3aMareks Malnacs srand(543542);
4c6011bfcf29cd75d6af86f192d709221f4d5d3aMareks Malnacs for(i = 0; i < TEST_SIZE_1; i++) {
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford create_random_cache_key(key, sizeof(key));
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford assert_string_equal(key, keys[i]);
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford }
48e27400d23e2586530cf943524e50c74d79a915Tony Bamford}