test_notenforced_lists.c revision b0e02a0dd364decf4697db706d59eb72b6aeba62
/**
* 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 "cmocka.h"
am_status_t ip_address_match(const char *ip, const char **list, unsigned int listsize, unsigned long instance_id);
#define array_of(a) ((const char *[]){ a })
#define array_len(a) ( (&a) [1] - a )
{ \
assert_int_equal(ip_address_match(addr, array_of(range), 1, 0l), expect ? AM_SUCCESS : AM_NOT_FOUND); \
} while (0)
{ \
assert_int_equal(ip_address_match(addr, array_of(range), 1, 0l), expect ? AM_SUCCESS : AM_NOT_FOUND); \
} while (0)
// this is in ip.c, as an alternative to inet_net_pton, which is not protable and seems faulty.
#ifdef _WIN32
{
return -1;
}
#endif
/*
* (i) the output of ipv6_pton is as expected.
*
* (ii) also tests that the masked binary can be round-tripped - i.e. converted to a presentation
* address and then to exactly the same binary with no bits masked. This checks that the masking is correct.
*/
static void ipv6_compare(int expected, const char * p)
{
if (bits != -1)
{
// roundtrip
}
#if 0
{
//printf("different results: inet_net_pton returns %d\n", ctl_bits);
}
if (ctl_bits != -1)
{
}
{
{
}
{
printf("different binaries\n");
}
}
printf("--------\n");
#endif
}
static void test_ip6()
{
ipv6_compare(28, "2001:20::/28"); // ORCHIDv2 (Overlay Routable Cryptographic Hash Identifiers). inet_net_pton says they are invalid
}
void test_ip6_addresses(void ** state) {
(void)state;
test_ip6();
}
void test_ip_ranges(void ** state) {
(void)state;
// V4
// bad ranges
// V6
}
static void test_range_ip4_notenforced(void **state) {
int array_len = 0;
struct am_config_map not_enforced_ips [] = {
{ "", "192.153.0.0-192.168.0.23" },
};
struct ctx {
void *dummy;
} ctx;
am_config_t config = {
.instance_id = 0,
.notif_enable = AM_TRUE,
.not_enforced_fetch_attr = 0,
.not_enforced_map_sz = 0,
.not_enforced_ext_map_sz = 0,
.logout_map_sz = 0,
};
am_request_t request = {
.instance_id = 0,
};
}
void test_cidr_ip6_notenforced_fetch_attr(void **state) {
int array_len = 0;
struct am_config_map not_enforced_ips [] = {
{ "", "2001:5c0:9168:0:0:0:0:1-2001:5c0:9168:0:0:0:0:2" },
{ "", "2001:5c0:9168::/48" },
};
struct ctx {
void *dummy;
} ctx;
am_config_t config = {
.instance_id = 0,
.notif_enable = AM_TRUE,
.not_enforced_fetch_attr = 1,
.not_enforced_map_sz = 0,
.not_enforced_ext_map_sz = 0,
.logout_map_sz = 0,
};
am_request_t request = {
.instance_id = 0,
};
}
void test_cidr_ip6_notenforced_get(void **state) {
int array_len = 0;
struct am_config_map not_enforced_ips[] = {
{ "GET,", "2001:5c0:9168::1-2001:5c0:9168::2" },
{ "POST,", "2001:6c0:9168::/48" },
};
struct ctx {
void *dummy;
} ctx;
am_config_t config = {
.instance_id = 0,
.notif_enable = AM_TRUE,
.not_enforced_fetch_attr = 1,
.not_enforced_map_sz = 0,
.not_enforced_ext_map_sz = 0,
.logout_map_sz = 0,
};
am_request_t request = {
.instance_id = 0,
.method = AM_REQUEST_GET,
};
}
void test_url_notenforced_get(void **state) {
int array_len = 0;
struct ctx {
void *dummy;
} ctx;
struct am_config_map not_enforced_ips[] = {
{ "GET,0", "2001:5c0:9168:0:0:0:0:1-2001:5c0:9168:0:0:0:0:2" },
{ "POST,0", "2001:5c0:9168::/48" },
};
struct am_config_map not_enforced_map[] = {
{ "GET,0", ".+://\\.+" },
{ "POST,0", "https://www\\..+/path.*" },
};
am_config_t config = {
.instance_id = 0,
.notif_enable = AM_TRUE,
.not_enforced_invert = 0,
.not_enforced_ext_map_sz = 0,
.logout_map_sz = 0,
};
am_request_t request = {
.instance_id = 0,
};
}
void test_deny_url_notenforced_get(void **state) {
int array_len = 0;
struct am_config_map not_enforced_ips[] = {
{ "GET,0", "2001:5c0:9168:0:0:0:0:1-2001:5c0:9168:0:0:0:0:2" },
{ "POST,0", "2001:5c0:9168::/48" },
};
struct am_config_map not_enforced_map[] = {
{ "GET,0", "https://www.url.com:90/path" },
{ "POST,0", "https://www.url.com/path" },
};
struct ctx {
void *dummy;
} ctx;
am_config_t config = {
.instance_id = 0,
.notif_enable = AM_TRUE,
.not_enforced_fetch_attr = 1,
.not_enforced_invert = 0,
.not_enforced_ext_map_sz = 0,
.logout_map_sz = 0,
};
am_request_t request = {
.instance_id = 0,
};
}