/**
* 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 <string.h>
#include <setjmp.h>
#include "platform.h"
#include "am.h"
#include "utility.h"
#include "thread.h"
#include "cmocka.h"
void am_worker_pool_init_reset();
void am_net_init_ssl_reset();
{
return AM_SUCCESS;
}
static am_status_t set_custom_response(struct am_request * request, const char * data, const char * content_type)
{
return AM_SUCCESS;
}
int array_len = 0;
char * post_data =
"<NotificationSet version='1.0'>"
" <Notification>"
//option - invalidate config changed ( not for specific instance )
//" <AgentConfigChangeNotification />"
//option - invalidate session by sid ( state must be present, not is not used )
//" <SessionNotification>"
//" <Session sid='my-session' state='destroyed' />"
//" </SessionNotification>"
//option remove specific resources from the cache - check that it is the right service
//these can't be removed by resource from the session cache
" <PolicyChangeNotification serviceName='identified-service' >"
" <ResourceName type='added' >a.b.c:3232/d/e/f</ResourceName>"
" <ResourceName type='deleted' >a.b.c:3232/d/e/f</ResourceName>"
" <ResourceName type='modified' >a.b.c:3232/d/e/f</ResourceName>"
" </PolicyChangeNotification>"
" </Notification>"
"</NotificationSet>";
struct ctx {
void *dummy;
} ctx;
.instance_id = 0,
.notif_enable = AM_TRUE,
};
.instance_id = 0,
};
/* this is not a notification */
}
int array_len = 0;
char * post_data =
"<NotificationSet version='1.0'>"
" <Notification>"
//option - invalidate config changed ( not for specific instance )
//" <AgentConfigChangeNotification />"
//option - invalidate session by sid ( state must be present, not is not used )
//" <SessionNotification>"
//" <Session sid='my-session' state='destroyed' />"
//" </SessionNotification>"
//option remove specific resources from the cache - check that it is the right service
//these can't be removed by resource from the session cache
" <PolicyChangeNotification serviceName='identified-service' >"
" <ResourceName type='added' >a.b.c:3232/d/e/f</ResourceName>"
" <ResourceName type='deleted' >a.b.c:3232/d/e/f</ResourceName>"
" <ResourceName type='modified' >a.b.c:3232/d/e/f</ResourceName>"
" </PolicyChangeNotification>"
" </Notification>"
"</NotificationSet>";
struct ctx {
void *dummy;
} ctx;
.instance_id = 0,
.notif_enable = AM_TRUE,
};
.instance_id = 0,
};
/* this is a notification */
sleep(2);
}
char * session_notification =
"<NotificationSet version='1.0'>"
" <Notification>"
" <SessionNotification> <Session sid='XXX' state='destroyed' /> </SessionNotification>"
" </Notification>"
"</NotificationSet>";
int array_len = 0;
struct ctx {
void *dummy;
} ctx;
.instance_id = 0,
.token_cache_valid = 0,
.notif_enable = AM_TRUE,
};
.instance_id = 0,
};
char * 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>"
" <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>";
"<ResponseSet vers='1.0' svcid='poicy' reqid='48'>"
" <Response><![CDATA[%s]]></Response>"
"</ResponseSet>";
struct am_policy_result * r = NULL;
assert_int_equal(am_add_session_policy_cache_entry(&request, session_id, result, NULL), AM_SUCCESS);
/* find the session */
assert_int_equal(am_get_session_policy_cache_entry(&request, session_id, &r, &session, &ets), AM_SUCCESS);
/* this is a notification */
/* wait for the worker to have finished */
sleep(2);
assert_int_equal(am_get_session_policy_cache_entry(&request, session_id, &r, &session, &ets), AM_NOT_FOUND);
}
int array_len = 0;
struct ctx {
void *dummy;
} ctx;
char * session_notification =
"<NotificationSet version='1.0'>"
" <Notification>"
" <PolicyChangeNotification serviceName='identified-service' >"
" <ResourceName type='deleted' >a.b.c:3232/d/e/f</ResourceName>"
" <ResourceName type='modified' >a.b.c:3232/d/e/f</ResourceName>"
" </PolicyChangeNotification>"
" </Notification>"
"</NotificationSet>";
.instance_id = 0,
.token_cache_valid = 0,
.notif_enable = AM_TRUE,
};
.instance_id = 0,
};
char * xml =
"<PolicyService version='1.0' revisionNumber='60'>"
" <PolicyResponse requestId='4' issueInstant='1424783306343' >"
" <ResourceResult name='a.b.c:3232/d/e/f'>"
" <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>"
" <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>";
"<ResponseSet vers='1.0' svcid='poicy' reqid='48'>"
" <Response><![CDATA[%s]]></Response>"
"</ResponseSet>";
/* when the worker has finished, the session result list should be unchanged, but policy cache entry removed */
struct am_policy_result * r = NULL;
struct am_policy_result * p;
/* add the resources to the policy cache */
}
/* send a resource notification for the cached resource */
sleep(2);
assert_int_equal(am_get_session_policy_cache_entry(&request, session_id, &r, &session, &ets), AM_SUCCESS);
if (r != NULL) {
// check that the notification has been received, which will invalidate the cache entry
}
}