From 232146775bb00769a3c208441ad0fa28bfe7f42f Mon Sep 17 00:00:00 2001 From: Ralph Boehme Date: Sat, 9 Oct 2021 16:44:25 +0200 Subject: [PATCH] selftest: add a test ignored spotlight/elasticsearch mapping failures Signed-off-by: Ralph Boehme Reviewed-by: Noel Power --- .../samba.unittests.mdsparser_es_failures | 1 + selftest/tests.py | 6 +++ source3/rpc_server/mdssvc/test_mdsparser_es.c | 54 +++++++++++++++++++ 3 files changed, 61 insertions(+) create mode 100644 selftest/knownfail.d/samba.unittests.mdsparser_es_failures diff --git a/selftest/knownfail.d/samba.unittests.mdsparser_es_failures b/selftest/knownfail.d/samba.unittests.mdsparser_es_failures new file mode 100644 index 00000000000..90c3af6fee9 --- /dev/null +++ b/selftest/knownfail.d/samba.unittests.mdsparser_es_failures @@ -0,0 +1 @@ +^samba.unittests.mdsparser_es_failures.test_mdsparser_es\(none\)$ diff --git a/selftest/tests.py b/selftest/tests.py index 128374210c4..8ff635f2777 100644 --- a/selftest/tests.py +++ b/selftest/tests.py @@ -435,6 +435,12 @@ plantestsuite("samba.unittests.test_oLschema2ldif", "none", if with_elasticsearch_backend: plantestsuite("samba.unittests.mdsparser_es", "none", [os.path.join(bindir(), "default/source3/test_mdsparser_es")] + [configuration]) + plantestsuite("samba.unittests.mdsparser_es_failures", "none", + [os.path.join(bindir(), "default/source3/test_mdsparser_es"), + " --option=elasticsearch:testmappingfailures=yes", + " --option=elasticsearch:ignoreunknownattribute=yes", + " --option=elasticsearch:ignoreunknowntype=yes"] + + [configuration]) plantestsuite("samba.unittests.credentials", "none", [os.path.join(bindir(), "default/auth/credentials/test_creds")]) plantestsuite("samba.unittests.tsocket_bsd_addr", "none", diff --git a/source3/rpc_server/mdssvc/test_mdsparser_es.c b/source3/rpc_server/mdssvc/test_mdsparser_es.c index b5cb86db9a7..af2b8e64840 100644 --- a/source3/rpc_server/mdssvc/test_mdsparser_es.c +++ b/source3/rpc_server/mdssvc/test_mdsparser_es.c @@ -161,6 +161,40 @@ static struct { } }; +static struct { + const char *mds; + const char *es; +} map_ignore_failures[] = { + { + "*==\"Samba\"||foo==\"bar\"", + "(Samba)" PATH_QUERY_SUBEXPR + }, { + "*==\"Samba\"&&foo==\"bar\"", + "(Samba)" PATH_QUERY_SUBEXPR + }, { + "*==\"Samba\"||kMDItemContentType==\"666\"", + "(Samba)" PATH_QUERY_SUBEXPR + }, { + "*==\"Samba\"&&kMDItemContentType==\"666\"", + "(Samba)" PATH_QUERY_SUBEXPR + }, { + "*==\"Samba\"||foo==\"bar\"||kMDItemContentType==\"666\"", + "(Samba)" PATH_QUERY_SUBEXPR + }, { + "*==\"Samba\"&&foo==\"bar\"&&kMDItemContentType==\"666\"", + "(Samba)" PATH_QUERY_SUBEXPR + }, { + "foo==\"bar\"||kMDItemContentType==\"666\"||*==\"Samba\"||x!=\"6\"", + "(Samba)" PATH_QUERY_SUBEXPR + }, { + "*==\"Samba\"||InRange(foo,1,2)", + "(Samba)" PATH_QUERY_SUBEXPR + }, { + "*==\"Samba\"||foo==$time.iso(2018-10-01T10:00:00Z)", + "(Samba)" PATH_QUERY_SUBEXPR + } +}; + static void test_mdsparser_es(void **state) { TALLOC_CTX *frame = talloc_stackframe(); @@ -192,6 +226,26 @@ static void test_mdsparser_es(void **state) assert_string_equal(es_query, map[i].es); } + if (!lp_parm_bool(GLOBAL_SECTION_SNUM, + "elasticsearch", + "test mapping failures", + false)) + { + goto done; + } + + for (i = 0; i < ARRAY_SIZE(map_ignore_failures); i++) { + DBG_DEBUG("Mapping: %s\n", map_ignore_failures[i].mds); + ok = map_spotlight_to_es_query(frame, + mappings, + path_scope, + map_ignore_failures[i].mds, + &es_query); + assert_true(ok); + assert_string_equal(es_query, map_ignore_failures[i].es); + } + +done: json_decref(mappings); TALLOC_FREE(frame); }