test_setup_requests.c revision 48e27400d23e2586530cf943524e50c74d79a915
/**
* 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 <cmocka.h>
#include "am.h"
#include "utility.h"
#define TOKEN_NAME "C-name"
#define TEST_TOKEN_VALUE "AQIC5wM2LY4Sfcyro187TdQ7LJIs373_tJP4Lb2VXBv-Qoc.*AAJTSQACMDEAAlNLABM5MjExNjg2Nzk3Mjg3MjI4MDA2*"
/**
* Compare only the prefix against the string.
* Return the result of strncmp, so 0 means no differences, etc.
*/
}
{
char* path = "/d/e/f;1=2";
char* token = TEST_TOKEN_VALUE;
char* url = 0;
return AM_SUCCESS;
}
{
char* path = "/x/y/../../d/e/f";
char* url = 0;
return AM_SUCCESS;
}
{
char* path = "/x/../../../d/e/f";
char* url = 0;
return AM_SUCCESS;
}
{
// note that the parser does not accept namespaces and it does not normalize character content.
char* saml =
"</x>";
char* url = 0;
return AM_SUCCESS;
}
/*****************************************************************************************************/
void test_setup_with_simple_token(void **state) {
(void)state;
am_state_func_t const* func_array = 0;
int array_len = 0;
struct {
} ctx;
am_config_t config = {
.override_host = AM_TRUE,
.resolve_client_host = 0,
};
am_request_t request = {
.client_ip = "209.173.53.167",
.client_host = "d.e.f",
.method = AM_REQUEST_GET,
.token = 0,
};
}
void test_setup_with_valid_path(void **state) {
(void)state;
am_state_func_t const* func_array = 0;
int array_len = 0;
struct {
} ctx;
am_config_t config = {
.override_host = AM_TRUE,
.resolve_client_host = 0,
};
am_request_t request = {
.client_ip = "2001:5c0:9168:0:0:0:0:1",
.client_host = "d.e.f:8090",
.method = AM_REQUEST_GET,
.token = 0,
};
}
void test_setup_with_invalid_path(void **state) {
(void)state;
am_state_func_t const* func_array = 0;
int array_len = 0;
struct {
} ctx;
am_config_t config = {
.override_host = AM_TRUE,
.resolve_client_host = 0,
};
am_request_t request = {
.client_ip = "2001:5c0:9168:0:0:0:0:1",
.client_host = "d.e.f:8080",
.method = AM_REQUEST_GET,
.token = 0,
};
// this should fail because the invalid path tried to refer outside of the root
}
void test_setup_with_SAML_token(void **state) {
(void)state;
am_state_func_t const* func_array = 0;
int array_len = 0;
// create a dummy request
struct {
} ctx;
am_config_t config = {
.override_port = AM_TRUE,
.cdsso_enable = 1,
.resolve_client_host = 0,
};
am_request_t request = {
.instance_id = 0,
.client_ip = "209.173.53.167,09.173.53.168",
.client_host = "d.e.f:37289423,g.h.i",
.content_type = "application/xml",
.token = 0,
};
}
/*
* note: this test requires an internet connection since it contacts a DNS server to verify the client host
*/
void test_setup_with_resolve_host(void **state) {
(void)state;
am_state_func_t const* func_array = 0;
int array_len = 0;
struct {
} ctx;
am_config_t config = {
.override_host = AM_TRUE,
.resolve_client_host = 1,
};
am_request_t request = {
.client_ip = "2001:4860:4860::8888,2001:5c0:9168:0:0:0:0:1",
.client_host = "www.google.com",
.method = AM_REQUEST_GET,
.token = 0,
};
}