Fix leaks in tests
* basic_tests.c: * login_tests.c: * login_tests_saml2.c: * random_tests.c: free replaced string, unref used nodes, initialize local variables when necessary, free newly allocated strings.
This commit is contained in:
parent
e863eefdeb
commit
7e6dfb7683
|
@ -166,6 +166,7 @@ START_TEST(test09_test_deserialization)
|
|||
node = lasso_node_new_from_dump(content);
|
||||
fail_unless(node != NULL, "node should be parsed");
|
||||
g_object_unref(node);
|
||||
g_free(content);
|
||||
}
|
||||
END_TEST
|
||||
|
||||
|
|
|
@ -290,6 +290,7 @@ START_TEST(test02_serviceProviderLogin)
|
|||
rc = lasso_login_accept_sso(spLoginContext);
|
||||
fail_unless(rc == 0, "lasso_login_accept_sso must fail");
|
||||
|
||||
g_free(spLoginDump);
|
||||
g_free(serviceProviderId);
|
||||
g_free(serviceProviderContextDump);
|
||||
g_free(identityProviderContextDump);
|
||||
|
|
|
@ -83,12 +83,12 @@ generateServiceProviderContextDump()
|
|||
static char*
|
||||
generateIdentityProviderContextDumpMemory()
|
||||
{
|
||||
LassoServer *serverContext;
|
||||
char *metadata;
|
||||
char *private_key;
|
||||
char *certificate;
|
||||
LassoServer *serverContext = NULL;
|
||||
char *metadata = NULL;
|
||||
char *private_key = NULL;
|
||||
char *certificate = NULL;
|
||||
guint len;
|
||||
char *ret;
|
||||
char *ret = NULL;
|
||||
|
||||
g_file_get_contents(TESTSDATADIR "/idp5-saml2/metadata.xml", &metadata, &len, NULL);
|
||||
g_file_get_contents(TESTSDATADIR "/idp5-saml2/private-key.pem", &private_key, &len, NULL);
|
||||
|
@ -132,20 +132,20 @@ END_TEST
|
|||
|
||||
START_TEST(test02_saml2_serviceProviderLogin)
|
||||
{
|
||||
char *serviceProviderContextDump, *identityProviderContextDump;
|
||||
LassoServer *spContext, *idpContext;
|
||||
LassoLogin *spLoginContext, *idpLoginContext;
|
||||
LassoSamlp2AuthnRequest *request;
|
||||
char *serviceProviderContextDump = NULL, *identityProviderContextDump = NULL;
|
||||
LassoServer *spContext = NULL, *idpContext = NULL;
|
||||
LassoLogin *spLoginContext = NULL, *idpLoginContext = NULL;
|
||||
LassoSamlp2AuthnRequest *request = NULL;
|
||||
int rc;
|
||||
char *relayState;
|
||||
char *authnRequestUrl, *authnRequestQuery;
|
||||
char *responseUrl, *responseQuery;
|
||||
char *idpIdentityContextDump, *idpSessionContextDump;
|
||||
char *serviceProviderId, *soapRequestMsg, *soapResponseMsg;
|
||||
char *spIdentityContextDump;
|
||||
char *spSessionDump;
|
||||
char *spLoginDump, *idpLoginDump;
|
||||
char *found;
|
||||
char *relayState = NULL;
|
||||
char *authnRequestUrl = NULL, *authnRequestQuery = NULL;
|
||||
char *responseUrl = NULL, *responseQuery = NULL;
|
||||
char *idpIdentityContextDump = NULL, *idpSessionContextDump = NULL;
|
||||
char *serviceProviderId = NULL, *soapRequestMsg = NULL, *soapResponseMsg = NULL;
|
||||
char *spIdentityContextDump = NULL;
|
||||
char *spSessionDump = NULL;
|
||||
char *spLoginDump = NULL, *idpLoginDump = NULL;
|
||||
char *found = NULL;
|
||||
|
||||
serviceProviderContextDump = generateServiceProviderContextDump();
|
||||
spContext = lasso_server_new_from_dump(serviceProviderContextDump);
|
||||
|
@ -158,10 +158,10 @@ START_TEST(test02_saml2_serviceProviderLogin)
|
|||
request = LASSO_SAMLP2_AUTHN_REQUEST(LASSO_PROFILE(spLoginContext)->request);
|
||||
fail_unless(LASSO_IS_SAMLP2_AUTHN_REQUEST(request), "request should be authn_request");
|
||||
request->IsPassive = 0;
|
||||
request->NameIDPolicy->Format = g_strdup(LASSO_SAML2_NAME_IDENTIFIER_FORMAT_PERSISTENT);
|
||||
lasso_assign_string(request->NameIDPolicy->Format, LASSO_SAML2_NAME_IDENTIFIER_FORMAT_PERSISTENT);
|
||||
request->NameIDPolicy->AllowCreate = 1;
|
||||
relayState = "fake[]";
|
||||
LASSO_PROFILE(spLoginContext)->msg_relayState = g_strdup(relayState);
|
||||
lasso_assign_string(LASSO_PROFILE(spLoginContext)->msg_relayState, relayState);
|
||||
rc = lasso_login_build_authn_request_msg(spLoginContext);
|
||||
fail_unless(rc == 0, "lasso_login_build_authn_request_msg failed");
|
||||
authnRequestUrl = LASSO_PROFILE(spLoginContext)->msg_url;
|
||||
|
@ -223,7 +223,7 @@ START_TEST(test02_saml2_serviceProviderLogin)
|
|||
"responseQuery should contain a RelayState parameter");
|
||||
fail_unless(strstr(responseQuery, "fake%5B%5D") != NULL,
|
||||
"responseQuery RelayState parameter should be encoded");
|
||||
serviceProviderId = g_strdup(LASSO_PROFILE(idpLoginContext)->remote_providerID);
|
||||
lasso_assign_string(serviceProviderId, LASSO_PROFILE(idpLoginContext)->remote_providerID);
|
||||
fail_unless(serviceProviderId != NULL,
|
||||
"lasso_profile_get_remote_providerID shouldn't return NULL");
|
||||
|
||||
|
@ -296,6 +296,7 @@ START_TEST(test02_saml2_serviceProviderLogin)
|
|||
g_free(idpIdentityContextDump);
|
||||
g_free(spIdentityContextDump);
|
||||
g_free(spSessionDump);
|
||||
g_free(spLoginDump);
|
||||
g_object_unref(spContext);
|
||||
g_object_unref(idpContext);
|
||||
g_object_unref(spLoginContext);
|
||||
|
@ -305,19 +306,19 @@ END_TEST
|
|||
|
||||
START_TEST(test03_saml2_serviceProviderLogin)
|
||||
{
|
||||
char *serviceProviderContextDump, *identityProviderContextDump;
|
||||
LassoServer *spContext, *idpContext;
|
||||
LassoLogin *spLoginContext, *idpLoginContext;
|
||||
LassoSamlp2AuthnRequest *request;
|
||||
char *serviceProviderContextDump = NULL, *identityProviderContextDump = NULL;
|
||||
LassoServer *spContext = NULL, *idpContext = NULL;
|
||||
LassoLogin *spLoginContext = NULL, *idpLoginContext = NULL;
|
||||
LassoSamlp2AuthnRequest *request = NULL;
|
||||
char *relayState = NULL;
|
||||
char *authnRequestUrl = NULL, *authnRequestQuery = NULL;
|
||||
char *responseUrl = NULL, *responseQuery = NULL;
|
||||
char *idpIdentityContextDump = NULL, *idpSessionContextDump = NULL;
|
||||
char *serviceProviderId = NULL, *soapRequestMsg = NULL, *soapResponseMsg = NULL;
|
||||
char *spIdentityContextDump = NULL;
|
||||
char *spSessionDump = NULL;
|
||||
char *idpLoginDump = NULL;
|
||||
int rc;
|
||||
char *relayState;
|
||||
char *authnRequestUrl, *authnRequestQuery;
|
||||
char *responseUrl, *responseQuery;
|
||||
char *idpIdentityContextDump, *idpSessionContextDump;
|
||||
char *serviceProviderId, *soapRequestMsg, *soapResponseMsg;
|
||||
char *spIdentityContextDump;
|
||||
char *spSessionDump;
|
||||
char *idpLoginDump;
|
||||
|
||||
serviceProviderContextDump = generateServiceProviderContextDump();
|
||||
spContext = lasso_server_new_from_dump(serviceProviderContextDump);
|
||||
|
@ -330,10 +331,10 @@ START_TEST(test03_saml2_serviceProviderLogin)
|
|||
request = LASSO_SAMLP2_AUTHN_REQUEST(LASSO_PROFILE(spLoginContext)->request);
|
||||
fail_unless(LASSO_IS_SAMLP2_AUTHN_REQUEST(request), "request should be authn_request");
|
||||
request->IsPassive = 0;
|
||||
request->NameIDPolicy->Format = g_strdup(LASSO_SAML2_NAME_IDENTIFIER_FORMAT_PERSISTENT);
|
||||
lasso_assign_string(request->NameIDPolicy->Format, LASSO_SAML2_NAME_IDENTIFIER_FORMAT_PERSISTENT);
|
||||
request->NameIDPolicy->AllowCreate = 1;
|
||||
relayState = "fake";
|
||||
LASSO_PROFILE(spLoginContext)->msg_relayState = g_strdup(relayState);
|
||||
lasso_assign_string(LASSO_PROFILE(spLoginContext)->msg_relayState, relayState);
|
||||
rc = lasso_login_build_authn_request_msg(spLoginContext);
|
||||
fail_unless(rc == 0, "lasso_login_build_authn_request_msg failed");
|
||||
authnRequestUrl = LASSO_PROFILE(spLoginContext)->msg_url;
|
||||
|
@ -382,7 +383,7 @@ START_TEST(test03_saml2_serviceProviderLogin)
|
|||
responseQuery = strchr(responseUrl, '?')+1;
|
||||
fail_unless(strlen(responseQuery) > 0,
|
||||
"responseQuery shouldn't be an empty string");
|
||||
serviceProviderId = g_strdup(LASSO_PROFILE(idpLoginContext)->remote_providerID);
|
||||
lasso_assign_string(serviceProviderId, LASSO_PROFILE(idpLoginContext)->remote_providerID);
|
||||
fail_unless(serviceProviderId != NULL,
|
||||
"lasso_profile_get_remote_providerID shouldn't return NULL");
|
||||
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
#include <lasso/xml/lib_authentication_statement.h>
|
||||
#include <lasso/xml/saml_name_identifier.h>
|
||||
#include <lasso/xml/samlp_response.h>
|
||||
#include "../lasso/utils.h"
|
||||
|
||||
|
||||
Suite* random_suite();
|
||||
|
@ -49,6 +50,7 @@ START_TEST(test01_provider_new)
|
|||
dump = lasso_node_dump(LASSO_NODE(provider));
|
||||
printf("dump:\n%s\n", dump);
|
||||
g_object_unref(provider);
|
||||
lasso_release_string(dump);
|
||||
}
|
||||
END_TEST
|
||||
|
||||
|
@ -63,12 +65,13 @@ START_TEST(test02_provider_new_from_dump)
|
|||
TESTSDATADIR "/ca1-la/certificate.pem");
|
||||
|
||||
dump = lasso_node_dump(LASSO_NODE(provider1));
|
||||
|
||||
provider2 = lasso_provider_new_from_dump(dump);
|
||||
lasso_release_string(dump);
|
||||
dump = lasso_node_dump(LASSO_NODE(provider2));
|
||||
printf("dump:\n%s\n", dump);
|
||||
g_object_unref(provider1);
|
||||
g_object_unref(provider2);
|
||||
lasso_release_string(dump);
|
||||
}
|
||||
END_TEST
|
||||
|
||||
|
@ -86,6 +89,7 @@ START_TEST(test01_server_new)
|
|||
dump = lasso_node_dump(LASSO_NODE(server));
|
||||
printf("dump:%s\n", dump);
|
||||
g_object_unref(server);
|
||||
lasso_release_string(dump);
|
||||
}
|
||||
END_TEST
|
||||
|
||||
|
@ -108,6 +112,7 @@ START_TEST(test02_server_add_provider)
|
|||
|
||||
dump = lasso_node_dump(LASSO_NODE(server));
|
||||
g_object_unref(server);
|
||||
lasso_release_string(dump);
|
||||
}
|
||||
END_TEST
|
||||
|
||||
|
@ -205,17 +210,22 @@ START_TEST(test06_lib_statuscode)
|
|||
* starts with lib:, that namespace must be defined. (was bug#416)
|
||||
*/
|
||||
LassoSamlpResponse *response = LASSO_SAMLP_RESPONSE(lasso_samlp_response_new());
|
||||
char *dump = NULL;
|
||||
|
||||
response->Status->StatusCode->Value = g_strdup(LASSO_SAML_STATUS_CODE_SUCCESS);
|
||||
fail_unless(strstr(lasso_node_dump(LASSO_NODE(response)), "xmlns:lib=") == NULL,
|
||||
lasso_assign_string(response->Status->StatusCode->Value, LASSO_SAML_STATUS_CODE_SUCCESS);
|
||||
dump = lasso_node_dump(LASSO_NODE(response));
|
||||
fail_unless(strstr(dump, "xmlns:lib=") == NULL,
|
||||
"liberty namespace should not be defined");
|
||||
lasso_release_string(dump);
|
||||
|
||||
response->Status->StatusCode->Value = g_strdup(LASSO_SAML_STATUS_CODE_RESPONDER);
|
||||
lasso_assign_string(response->Status->StatusCode->Value, LASSO_SAML_STATUS_CODE_RESPONDER);
|
||||
response->Status->StatusCode->StatusCode = lasso_samlp_status_code_new();
|
||||
response->Status->StatusCode->StatusCode->Value = g_strdup(
|
||||
LASSO_LIB_STATUS_CODE_UNKNOWN_PRINCIPAL);
|
||||
fail_unless(strstr(lasso_node_dump(LASSO_NODE(response)), "xmlns:lib=") != NULL,
|
||||
dump = lasso_node_dump(LASSO_NODE(response));
|
||||
fail_unless(strstr(dump, "xmlns:lib=") != NULL,
|
||||
"liberty namespace should be defined");
|
||||
lasso_release_string(dump);
|
||||
g_object_unref(response);
|
||||
}
|
||||
END_TEST
|
||||
|
|
Loading…
Reference in New Issue