test_sdap.c revision 0321da68a393943797ea8cb9eb5e9672431ff8f4
/*
Authors:
Jakub Hrozek <jhrozek@redhat.com>
Copyright (C) 2014 Red Hat
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 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, see <http://www.gnu.org/licenses/>.
*/
#include <talloc.h>
#include <tevent.h>
#include <errno.h>
#include <popt.h>
#include "tests/cmocka/common_mock.h"
#include "providers/ldap/ldap_opts.h"
#include "providers/ipa/ipa_opts.h"
#include "util/crypto/sss_crypto.h"
/* mock an LDAP entry */
struct mock_ldap_attr {
const char *name;
const char **values;
};
struct mock_ldap_entry {
const char *dn;
struct mock_ldap_attr *attrs;
};
struct mock_ldap_entry *global_ldap_entry;
static int mock_ldap_entry_iter(void)
{
return sss_mock_type(int);
}
static struct mock_ldap_entry *mock_ldap_entry_get(void)
{
return sss_mock_ptr_type(struct mock_ldap_entry *);
}
{
}
struct mock_ldap_entry *entry)
{
/* no attributes, done */
return dref;
}
}
} else {
}
}
return dref;
}
/* libldap wrappers */
int option,
void *invalue)
{
return LDAP_OPT_SUCCESS;
}
{
}
void __wrap_ldap_memfree(void *p)
{
return;
}
LDAP_CONST char *target)
{
const char **attrvals;
/* Should we return empty array here? */
break;
}
}
return NULL;
}
count = 0;
for (i = 0; attrvals[i]; i++) {
count++;
}
struct berval *,
count + 1);
for (i = 0; attrvals[i]; i++) {
assert_non_null(vals[i]);
return NULL;
}
}
return vals;
}
{
}
BerElement **berout)
{
}
{
int index = mock_ldap_entry_iter();
char *val;
}
return val;
}
/* Mock parsing search base without overlinking the test */
struct sdap_search_base ***_search_bases)
{
return EOK;
}
/* Utility function */
const char *attr,
const char *value)
{
const char *v;
int ret;
assert_non_null(v);
assert_string_equal(v, value);
}
const char *attr)
{
int ret;
const char *v;
}
struct parse_test_ctx {
struct sdap_handle sh;
};
void parse_entry_test_setup(void **state)
{
struct parse_test_ctx *test_ctx;
}
void parse_entry_test_teardown(void **state)
{
struct parse_test_ctx);
}
void test_parse_with_map(void **state)
{
int ret;
struct sysdb_attrs *attrs;
struct parse_test_ctx);
struct mock_ldap_entry test_ipa_user;
struct sdap_attr_map *map;
struct ldb_message_element *el;
struct mock_ldap_attr test_ipa_user_attrs[] = {
};
&attrs, false);
/* Every entry has a DN */
"cn=testuser,dc=example,dc=com");
/* Test the single-valued attribute */
/* Multivalued attributes must return all values */
/* The SSH attribute must be base64 encoded */
&key_len);
/* The extra attribute must not be downloaded, it's not present in map */
}
/* Some searches, like rootDSE search do not use any map */
void test_parse_no_map(void **state)
{
int ret;
struct sysdb_attrs *attrs;
struct parse_test_ctx);
struct mock_ldap_entry test_nomap_entry;
struct ldb_message_element *el;
struct mock_ldap_attr test_nomap_entry_attrs[] = {
};
"cn=testentry,dc=example,dc=com");
/* Multivalued attributes must return all values */
}
/* Only DN and OC, no real attributes */
void test_parse_no_attrs(void **state)
{
int ret;
struct sysdb_attrs *attrs;
struct parse_test_ctx);
struct mock_ldap_entry test_rfc2307_user;
struct sdap_attr_map *map;
struct mock_ldap_attr test_rfc2307_user_attrs[] = {
};
&attrs, false);
"cn=testuser,dc=example,dc=com");
}
void test_parse_dups(void **state)
{
int ret;
struct sysdb_attrs *attrs;
struct parse_test_ctx);
struct mock_ldap_entry test_dupattr_user;
struct sdap_attr_map *map;
int i;
struct mock_ldap_attr test_dupattr_attrs[] = {
};
/* Set both uidNumber and gidNumber to idNumber */
for (i = 0; i < SDAP_OPTS_USER; i++) {
}
}
&attrs, false);
/* Every entry has a DN */
"cn=dupuser,dc=example,dc=com");
/* Test the single-valued attribute */
}
void test_parse_deref(void **state)
{
struct sdap_attr_map_info minfo;
struct parse_test_ctx);
struct sdap_deref_attrs **res;
struct mock_ldap_attr test_ipa_user_attrs[] = {
};
struct mock_ldap_entry test_ipa_user;
/* The extra attribute must not be downloaded, it's not present in map */
assert_non_null(res[0]);
"cn=testuser,dc=example,dc=com");
}
void test_parse_deref_no_attrs(void **state)
{
struct sdap_attr_map_info minfo;
struct parse_test_ctx);
struct sdap_deref_attrs **res;
struct mock_ldap_entry test_ipa_user;
}
void test_parse_deref_map_mismatch(void **state)
{
struct sdap_attr_map_info minfo;
struct parse_test_ctx);
struct sdap_deref_attrs **res;
struct mock_ldap_attr test_ipa_user_attrs[] = {
};
struct mock_ldap_entry test_ipa_user;
/* the group map didn't match, so no attrs will be parsed out of the map */
}
/* Negative test - objectclass doesn't match the map */
void test_parse_bad_oc(void **state)
{
int ret;
struct sysdb_attrs *attrs;
struct parse_test_ctx);
struct mock_ldap_entry test_rfc2307_user;
struct sdap_attr_map *map;
struct mock_ldap_attr test_rfc2307_user_attrs[] = {
};
&attrs, false);
}
/* Negative test - the entry has no objectClass. Just make sure
* we don't crash
*/
void test_parse_no_oc(void **state)
{
int ret;
struct sysdb_attrs *attrs;
struct parse_test_ctx);
struct mock_ldap_entry test_rfc2307_user;
struct sdap_attr_map *map;
struct mock_ldap_attr test_rfc2307_user_attrs[] = {
};
&attrs, false);
}
/* Negative test - the entry has no DN. Just make sure
* we don't crash and detect the failure.
*/
void test_parse_no_dn(void **state)
{
int ret;
struct sysdb_attrs *attrs;
struct parse_test_ctx);
struct mock_ldap_entry test_rfc2307_user;
struct sdap_attr_map *map;
struct mock_ldap_attr test_rfc2307_user_attrs[] = {
};
&attrs, false);
}
{
int opt;
struct poptOption long_options[] = {
};
/* Negative tests */
};
/* Set debug level to invalid value so we can deside if -d 0 was used. */
switch(opt) {
default:
return 1;
}
}
/* Even though normally the tests should clean up after themselves
* they might not after a failed run. Remove the old db to be sure */
}