Add SP initiated logout test to SAML 2.0 regression tests

* tests/login_tests_saml2.c:
   add logout to first SAML 2.0 login regression test.
 * tests/tests.h:
   add macros to simplify checking of return value with check macros
   (encapsulate fail_unless macro to check for NULL/non-NULL values and
   good rc value (0) or expected bad value).
This commit is contained in:
Benjamin Dauvergne 2009-12-01 02:06:07 +00:00
parent 896d9abd3f
commit 4f973512b9
3 changed files with 85 additions and 1 deletions

View File

@ -32,7 +32,7 @@ perfs_LDFLAGS = -rpath `cd $(top_builddir)/lasso/.libs/; pwd`
endif
EXTRA_DIST = tests.c login_tests.c basic_tests.c random_tests.c metadata_tests.c integration
EXTRA_DIST = tests.c login_tests.c basic_tests.c random_tests.c metadata_tests.c integration tests.h
SUBDIRS = data metadata

View File

@ -32,6 +32,7 @@
#include "../lasso/utils.h"
#include "../lasso/backward_comp.h"
#include "./tests.h"
static char*
generateIdentityProviderContextDump()
@ -135,10 +136,13 @@ START_TEST(test02_saml2_serviceProviderLogin)
char *serviceProviderContextDump = NULL, *identityProviderContextDump = NULL;
LassoServer *spContext = NULL, *idpContext = NULL;
LassoLogin *spLoginContext = NULL, *idpLoginContext = NULL;
LassoLogout *spLogoutContext = NULL, *idpLogoutContext = NULL;
LassoSamlp2AuthnRequest *request = NULL;
int rc;
char *relayState = NULL;
char *authnRequestUrl = NULL, *authnRequestQuery = NULL;
char *logoutRequestUrl = NULL, *logoutRequestQuery = NULL;
char *logoutResponseUrl = NULL, *logoutResponseQuery = NULL;
char *responseUrl = NULL, *responseQuery = NULL;
char *idpIdentityContextDump = NULL, *idpSessionContextDump = NULL;
char *serviceProviderId = NULL, *soapRequestMsg = NULL, *soapResponseMsg = NULL;
@ -288,6 +292,43 @@ START_TEST(test02_saml2_serviceProviderLogin)
rc = lasso_login_accept_sso(spLoginContext);
fail_unless(rc != 0, "lasso_login_accept_sso must fail");
/* logout test */
/* generate a logout request */
check_not_null(idpLogoutContext = lasso_logout_new(idpContext));
check_good_rc(lasso_profile_set_session_from_dump(&idpLogoutContext->parent, idpSessionContextDump));
check_good_rc(lasso_logout_init_request(idpLogoutContext, NULL, LASSO_HTTP_METHOD_REDIRECT));
check_good_rc(lasso_logout_build_request_msg(idpLogoutContext));
check_not_null(idpLogoutContext->parent.msg_url);
check_null(idpLogoutContext->parent.msg_body);
check_null(idpLogoutContext->parent.msg_relayState);
lasso_assign_string(logoutRequestUrl, idpLogoutContext->parent.msg_url);
lasso_release_gobject(idpLogoutContext);
logoutRequestQuery = strchr(logoutRequestUrl, '?');
logoutRequestQuery += 1; /* keep only the query */
check_not_null(logoutRequestQuery);
/* process the logout request */
check_not_null(spLogoutContext = lasso_logout_new(spContext));
check_good_rc(rc = lasso_profile_set_session_from_dump(&spLogoutContext->parent, spSessionDump));
check_good_rc(rc = lasso_logout_process_request_msg(spLogoutContext, logoutRequestQuery));
check_good_rc(rc = lasso_logout_validate_request(spLogoutContext));
check_good_rc(rc = lasso_logout_build_response_msg(spLogoutContext));
check_not_null(spLogoutContext->parent.msg_url);
check_null(spLogoutContext->parent.msg_body);
check_null(spLogoutContext->parent.msg_relayState);
lasso_assign_string(logoutResponseUrl, spLogoutContext->parent.msg_url);
check_not_null(logoutResponseQuery = strchr(logoutResponseUrl, '?'));
logoutResponseQuery += 1; /* keep only the query */
lasso_release_gobject(spLogoutContext);
/* process the response */
check_not_null(idpLogoutContext = lasso_logout_new(idpContext));
check_good_rc(lasso_profile_set_session_from_dump(&idpLogoutContext->parent, idpSessionContextDump));
check_good_rc(lasso_logout_process_response_msg(idpLogoutContext, logoutResponseQuery));
lasso_release_gobject(idpLogoutContext);
lasso_release_string(logoutRequestUrl);
lasso_release_string(logoutResponseUrl);
g_free(idpLoginDump);
g_free(serviceProviderId);
g_free(serviceProviderContextDump);

43
tests/tests.h Normal file
View File

@ -0,0 +1,43 @@
/* $Id$ * * Lasso - A free implementation of the Liberty Alliance specifications.
*
* Copyright (C) 2004-2007 Entr'ouvert
* http://lasso.entrouvert.org
*
* Authors: See AUTHORS file in top-level directory.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef __TESTS_H__
#define __TESTS_H__
#define check_not_null(what) \
fail_unless((what) != NULL, #what " returned NULL");
#define check_null(what) \
fail_unless((what) == NULL, #what " returned NULL");
#define check_good_rc(what) \
{ int __rc = (what); \
fail_unless(__rc == 0, #what " failed, rc = %s", lasso_strerror(__rc)); \
}
#define check_bad_rc(what, how) \
{ int __rc = (what); \
fail_unless(__rc == how, #what " is not %s, rc = %s", lasso_strerror(how), lasso_strerror(__rc)); \
}
#endif /*__TESTS_H__ */