diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
commit | 6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch) | |
tree | a68f146d7fa01f0134297619fbe7e33db084e0aa /comm/mailnews/addrbook/test/unit/test_LDAPSyncQuery.js | |
parent | Initial commit. (diff) | |
download | thunderbird-upstream.tar.xz thunderbird-upstream.zip |
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'comm/mailnews/addrbook/test/unit/test_LDAPSyncQuery.js')
-rw-r--r-- | comm/mailnews/addrbook/test/unit/test_LDAPSyncQuery.js | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/comm/mailnews/addrbook/test/unit/test_LDAPSyncQuery.js b/comm/mailnews/addrbook/test/unit/test_LDAPSyncQuery.js new file mode 100644 index 0000000000..9e2d1cc97e --- /dev/null +++ b/comm/mailnews/addrbook/test/unit/test_LDAPSyncQuery.js @@ -0,0 +1,66 @@ +/* -*- Mode: JavaScript; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ + +/** + * Test suite for nsILDAPSyncQuery. + */ + +const { LDAPDaemon, LDAPHandlerFn } = ChromeUtils.import( + "resource://testing-common/mailnews/Ldapd.jsm" +); +const { BinaryServer } = ChromeUtils.import( + "resource://testing-common/mailnews/Binaryd.jsm" +); + +const nsILDAPSyncQuery = Ci.nsILDAPSyncQuery; +const LDAPSyncQueryContractID = "@mozilla.org/ldapsyncquery;1"; + +function getLDAPAttributes(urlSpec) { + let url = Services.io.newURI(urlSpec).QueryInterface(Ci.nsILDAPURL); + let ldapquery = Cc[LDAPSyncQueryContractID].createInstance(nsILDAPSyncQuery); + let payload = ldapquery.getQueryResults(url, Ci.nsILDAPConnection.VERSION3); + // Returns a string with one attr per line. + return payload; +} + +add_task(async function test_LDAPSyncQuery() { + // Set up fake LDAP server, loaded with some contacts. + let daemon = new LDAPDaemon(); + let raw = await IOUtils.readUTF8( + do_get_file( + "../../../../mailnews/addrbook/test/unit/data/ldap_contacts.json" + ).path + ); + let testContacts = JSON.parse(raw); + daemon.add(...Object.values(testContacts)); + // daemon.setDebug(true); + + let server = new BinaryServer(LDAPHandlerFn, daemon); + server.start(); + + // Fetch only the Holmes family. + let out = getLDAPAttributes( + `ldap://localhost:${server.port}/??sub?(sn=Holmes)` + ); + if (daemon.debug) { + dump(`--- getLDAPAttributes() ---\n${out}\n--------------------\n`); + } + + // Make sure we got the contacts we expected: + Assert.ok(out.includes("cn=Eurus Holmes")); + Assert.ok(out.includes("cn=Mycroft Holmes")); + Assert.ok(out.includes("cn=Sherlock Holmes")); + + // Sanity check: make sure some non-Holmes people were excluded. + Assert.ok(!out.includes("cn=John Watson")); + Assert.ok(!out.includes("cn=Jim Moriarty")); + + // Fetch again but this time the filter is without parens. + out = getLDAPAttributes(`ldap://localhost:${server.port}/??sub?sn=Holmes`); + + // Make sure we got the contacts we expected: + Assert.ok(out.includes("cn=Eurus Holmes")); + Assert.ok(out.includes("cn=Mycroft Holmes")); + Assert.ok(out.includes("cn=Sherlock Holmes")); + + server.stop(); +}); |