package.xml0000664000175000017500000016777412653735542011341 0ustar janjan Horde_Kolab_Server pear.horde.org Kolab_Server A package for manipulating the Kolab user database This package reads/writes entries in the Kolab user database stored in LDAP. Gunnar Wrobel wrobel p@rdus.de yes 2016-02-01 2.0.5 1.0.0 stable stable LGPL-2.1 * [jan] Mark PHP 7 as supported. 5.3.0 8.0.0alpha1 8.0.0alpha1 1.7.0 Horde_Auth pear.horde.org 2.0.0 3.0.0alpha1 3.0.0alpha1 Horde_Exception pear.horde.org 2.0.0 3.0.0alpha1 3.0.0alpha1 Horde_Util pear.horde.org 2.0.0 3.0.0alpha1 3.0.0alpha1 hash Horde_Date pear.horde.org 2.0.0 3.0.0alpha1 3.0.0alpha1 Horde_Ldap pear.horde.org 2.0.0 3.0.0alpha1 3.0.0alpha1 Horde_Test pear.horde.org 2.4.0 3.0.0alpha1 3.0.0alpha1 ldap 0.1.1 0.1.0 alpha alpha LGPL-2.1 * Renamed package to Kolab_Server. * Removed an unnecessary translation. * Added dnForMailOrAlias function to Horde_Kolab_Server. * Fixed experimental KOLAB_ATTR_IMAPHOST attribute. 0.1.0 0.1.0 alpha alpha 2008-07-29 LGPL-2.1 * Initial release. 2008-10-29 0.2.0 0.2.0 alpha alpha LGPL-2.1 * Fixed retrieval of the users IMAP home server. * Allowed retrieving a DN for an id matching either mail, uid or alias. (Kolab issue 2587, https://www.intevation.de/roundup/kolab/issue2587) * Moved Kolab session handler from Kolab_Storage to Kolab_Server. * Enabled retrieval of the users free/busy server. (Enhancement: #6699) * Added capability to list objects. * Added write capabilities to the package. * Moved the IMAP drivers from Kolab_Storage to Kolab_Server as the IMAP connection must be handled by the Kolab session. * Added a test class for simplified PHPUnit testing. 2008-12-16 0.3.0 0.2.0 alpha alpha LGPL-2.1 * Fixed the fallback for a missing freebusy_server value. * Fixed identification of external addresses. 2008-12-16 0.4.0 0.2.0 alpha alpha LGPL-2.1 * Fixed objectClass evaluation to respect case-insensitivity (Bug: #7694) * kolab/issue2207 (Make it possible to enable and disable users to be able to use the webclient) * Added fullname attribute as support for kolab/issue2546 (Horde should use name and email from ldap as defaults) * Fixed initialization of parameters retrieved from LDAP. * Fixed addrsForIdOrMail to return only lowercased mail addresses (kolab/issue3426, https://www.intevation.de/roundup/kolab/issue3426) * Fixed testing problems with the test IMAP driver. * Fixed notices when retrieving LDAP attributes. 0.8.0 0.8.0 alpha alpha 2010-02-17 LGPL-2.1 * Converted the package to Horde 4 / PHP 5. * Split the session driver into a separate package (Kolab_Session). * Use exceptions rather than PEAR errors. * Schema support. * Use class variables to represent objectClass attributes. Thus it is possible to accomodate for variable attribute names. * Cleaner class structure that matches the objectClass structure and also allows one to represent logical classes. * Separate classes to handle the LDAP tree structure in a more flexible way. * Added LDAP write support. * Real LDAP server unit testing. * Support configurable attribute mapping. * Added getGroupAddresses() to return the mail addresses of groups the user belongs to. 1.0.0alpha1 1.0.0 alpha alpha 2011-03-08 LGPL-2.1 * First alpha release for Horde 4. 1.0.0beta1 1.0.0 beta beta 2011-03-16 LGPL-2.1 * First beta release for Horde 4. 1.0.0RC1 1.0.0 beta beta 2011-03-22 LGPL-2.1 * First release candidate for Horde 4. 1.0.0RC2 1.0.0 beta beta 2011-03-29 LGPL-2.1 * Second release candidate for Horde 4. 1.0.0 1.0.0 stable stable 2011-04-06 LGPL-2.1 * First stable release for Horde 4. * [jan] Use Horde_Auth for generating password hashes. 1.0.1 1.0.0 stable stable 2011-08-31 LGPL-2.1 * [gwr] Fix reading the user name. 1.0.2 1.0.0 stable stable 2012-04-10 LGPL-2.1 * [rla] Add license file. * [jan] Fix tests to work with PHPUnit 3.6. 2.0.0alpha1 1.0.0 alpha stable 2012-07-05 LGPL-2.1 * First alpha release for Horde 5. 2.0.0beta1 1.0.0 beta stable 2012-07-19 LGPL-2.1 * First beta release for Horde 5. 2.0.0RC1 1.0.0 beta stable 2012-10-26 LGPL-2.1 * [jan] Reduce logging level of debug messages. 2.0.0 1.0.0 stable stable 2012-10-30 LGPL-2.1 * First stable release for Horde 5. 2.0.1 1.0.0 stable stable 2012-11-19 LGPL-2.1 * [mms] Use new Horde_Test layout. 2.0.2 1.0.0 stable stable 2013-03-05 LGPL-2.1 * [jan] Improve unit tests. 2.0.3 1.0.0 stable stable 2015-01-07 LGPL-2.1 * [jan] Improve PSR-2 compatibility. * [jan] Remove PHPUnit dependency. 2.0.4 1.0.0 stable stable 2015-04-28 LGPL-2.1 * [jan] Fix issues with certain locales like Turkish. 2.0.5 1.0.0 stable stable 2016-02-01 LGPL-2.1 * [jan] Mark PHP 7 as supported. Horde_Kolab_Server-2.0.5/doc/Horde/Kolab/Server/examples/server.php0000664000175000017500000000177412653735542023307 0ustar janjandnForMailAddress('wrobel@example.com'); var_dump($dn); /** Fetch the corresponding object */ $object = $server->fetch($dn); var_dump(get_class($object)); /** Display object attributes */ var_dump($object->get(Horde_Kolab_Server_Object::ATTRIBUTE_CN)); Horde_Kolab_Server-2.0.5/doc/Horde/Kolab/Server/COPYING0000664000175000017500000005764612653735542020516 0ustar janjan GNU LESSER GENERAL PUBLIC LICENSE Version 2.1, February 1999 Copyright (C) 1991, 1999 Free Software Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. [This is the first released version of the Lesser GPL. It also counts as the successor of the GNU Library Public License, version 2, hence the version number 2.1.] Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public Licenses are intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This license, the Lesser General Public License, applies to some specially designated software packages--typically libraries--of the Free Software Foundation and other authors who decide to use it. You can use it too, but we suggest you first think carefully about whether this license or the ordinary General Public License is the better strategy to use in any particular case, based on the explanations below. When we speak of free software, we are referring to freedom of use, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish); that you receive source code or can get it if you want it; that you can change the software and use pieces of it in new free programs; and that you are informed that you can do these things. To protect your rights, we need to make restrictions that forbid distributors to deny you these rights or to ask you to surrender these rights. These restrictions translate to certain responsibilities for you if you distribute copies of the library or if you modify it. For example, if you distribute copies of the library, whether gratis or for a fee, you must give the recipients all the rights that we gave you. You must make sure that they, too, receive or can get the source code. If you link other code with the library, you must provide complete object files to the recipients, so that they can relink them with the library after making changes to the library and recompiling it. And you must show them these terms so they know their rights. We protect your rights with a two-step method: (1) we copyright the library, and (2) we offer you this license, which gives you legal permission to copy, distribute and/or modify the library. To protect each distributor, we want to make it very clear that there is no warranty for the free library. Also, if the library is modified by someone else and passed on, the recipients should know that what they have is not the original version, so that the original author's reputation will not be affected by problems that might be introduced by others. Finally, software patents pose a constant threat to the existence of any free program. We wish to make sure that a company cannot effectively restrict the users of a free program by obtaining a restrictive license from a patent holder. Therefore, we insist that any patent license obtained for a version of the library must be consistent with the full freedom of use specified in this license. Most GNU software, including some libraries, is covered by the ordinary GNU General Public License. This license, the GNU Lesser General Public License, applies to certain designated libraries, and is quite different from the ordinary General Public License. We use this license for certain libraries in order to permit linking those libraries into non-free programs. When a program is linked with a library, whether statically or using a shared library, the combination of the two is legally speaking a combined work, a derivative of the original library. The ordinary General Public License therefore permits such linking only if the entire combination fits its criteria of freedom. The Lesser General Public License permits more lax criteria for linking other code with the library. We call this license the "Lesser" General Public License because it does Less to protect the user's freedom than the ordinary General Public License. It also provides other free software developers Less of an advantage over competing non-free programs. These disadvantages are the reason we use the ordinary General Public License for many libraries. However, the Lesser license provides advantages in certain special circumstances. For example, on rare occasions, there may be a special need to encourage the widest possible use of a certain library, so that it becomes a de-facto standard. To achieve this, non-free programs must be allowed to use the library. A more frequent case is that a free library does the same job as widely used non-free libraries. In this case, there is little to gain by limiting the free library to free software only, so we use the Lesser General Public License. In other cases, permission to use a particular library in non-free programs enables a greater number of people to use a large body of free software. For example, permission to use the GNU C Library in non-free programs enables many more people to use the whole GNU operating system, as well as its variant, the GNU/Linux operating system. Although the Lesser General Public License is Less protective of the users' freedom, it does ensure that the user of a program that is linked with the Library has the freedom and the wherewithal to run that program using a modified version of the Library. The precise terms and conditions for copying, distribution and modification follow. Pay close attention to the difference between a "work based on the library" and a "work that uses the library". The former contains code derived from the library, whereas the latter must be combined with the library in order to run. GNU LESSER GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any software library or other program which contains a notice placed by the copyright holder or other authorized party saying it may be distributed under the terms of this Lesser General Public License (also called "this License"). Each licensee is addressed as "you". A "library" means a collection of software functions and/or data prepared so as to be conveniently linked with application programs (which use some of those functions and data) to form executables. The "Library", below, refers to any such software library or work which has been distributed under these terms. A "work based on the Library" means either the Library or any derivative work under copyright law: that is to say, a work containing the Library or a portion of it, either verbatim or with modifications and/or translated straightforwardly into another language. (Hereinafter, translation is included without limitation in the term "modification".) "Source code" for a work means the preferred form of the work for making modifications to it. For a library, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the library. Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running a program using the Library is not restricted, and output from such a program is covered only if its contents constitute a work based on the Library (independent of the use of the Library in a tool for writing it). Whether that is true depends on what the Library does and what the program that uses the Library does. 1. You may copy and distribute verbatim copies of the Library's complete source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and distribute a copy of this License along with the Library. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Library or any portion of it, thus forming a work based on the Library, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) The modified work must itself be a software library. b) You must cause the files modified to carry prominent notices stating that you changed the files and the date of any change. c) You must cause the whole of the work to be licensed at no charge to all third parties under the terms of this License. d) If a facility in the modified Library refers to a function or a table of data to be supplied by an application program that uses the facility, other than as an argument passed when the facility is invoked, then you must make a good faith effort to ensure that, in the event an application does not supply such function or table, the facility still operates, and performs whatever part of its purpose remains meaningful. (For example, a function in a library to compute square roots has a purpose that is entirely well-defined independent of the application. Therefore, Subsection 2d requires that any application-supplied function or table used by this function must be optional: if the application does not supply it, the square root function must still compute square roots.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Library, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Library, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Library. In addition, mere aggregation of another work not based on the Library with the Library (or with a work based on the Library) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may opt to apply the terms of the ordinary GNU General Public License instead of this License to a given copy of the Library. To do this, you must alter all the notices that refer to this License, so that they refer to the ordinary GNU General Public License, version 2, instead of to this License. (If a newer version than version 2 of the ordinary GNU General Public License has appeared, then you can specify that version instead if you wish.) Do not make any other change in these notices. Once this change is made in a given copy, it is irreversible for that copy, so the ordinary GNU General Public License applies to all subsequent copies and derivative works made from that copy. This option is useful when you wish to copy part of the code of the Library into a program that is not a library. 4. You may copy and distribute the Library (or a portion or derivative of it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange. If distribution of object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place satisfies the requirement to distribute the source code, even though third parties are not compelled to copy the source along with the object code. 5. A program that contains no derivative of any portion of the Library, but is designed to work with the Library by being compiled or linked with it, is called a "work that uses the Library". Such a work, in isolation, is not a derivative work of the Library, and therefore falls outside the scope of this License. However, linking a "work that uses the Library" with the Library creates an executable that is a derivative of the Library (because it contains portions of the Library), rather than a "work that uses the library". The executable is therefore covered by this License. Section 6 states terms for distribution of such executables. When a "work that uses the Library" uses material from a header file that is part of the Library, the object code for the work may be a derivative work of the Library even though the source code is not. Whether this is true is especially significant if the work can be linked without the Library, or if the work is itself a library. The threshold for this to be true is not precisely defined by law. If such an object file uses only numerical parameters, data structure layouts and accessors, and small macros and small inline functions (ten lines or less in length), then the use of the object file is unrestricted, regardless of whether it is legally a derivative work. (Executables containing this object code plus portions of the Library will still fall under Section 6.) Otherwise, if the work is a derivative of the Library, you may distribute the object code for the work under the terms of Section 6. Any executables containing that work also fall under Section 6, whether or not they are linked directly with the Library itself. 6. As an exception to the Sections above, you may also combine or link a "work that uses the Library" with the Library to produce a work containing portions of the Library, and distribute that work under terms of your choice, provided that the terms permit modification of the work for the customer's own use and reverse engineering for debugging such modifications. You must give prominent notice with each copy of the work that the Library is used in it and that the Library and its use are covered by this License. You must supply a copy of this License. If the work during execution displays copyright notices, you must include the copyright notice for the Library among them, as well as a reference directing the user to the copy of this License. Also, you must do one of these things: a) Accompany the work with the complete corresponding machine-readable source code for the Library including whatever changes were used in the work (which must be distributed under Sections 1 and 2 above); and, if the work is an executable linked with the Library, with the complete machine-readable "work that uses the Library", as object code and/or source code, so that the user can modify the Library and then relink to produce a modified executable containing the modified Library. (It is understood that the user who changes the contents of definitions files in the Library will not necessarily be able to recompile the application to use the modified definitions.) b) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (1) uses at run time a copy of the library already present on the user's computer system, rather than copying library functions into the executable, and (2) will operate properly with a modified version of the library, if the user installs one, as long as the modified version is interface-compatible with the version that the work was made with. c) Accompany the work with a written offer, valid for at least three years, to give the same user the materials specified in Subsection 6a, above, for a charge no more than the cost of performing this distribution. d) If distribution of the work is made by offering access to copy from a designated place, offer equivalent access to copy the above specified materials from the same place. e) Verify that the user has already received a copy of these materials or that you have already sent this user a copy. For an executable, the required form of the "work that uses the Library" must include any data and utility programs needed for reproducing the executable from it. However, as a special exception, the materials to be distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. It may happen that this requirement contradicts the license restrictions of other proprietary libraries that do not normally accompany the operating system. Such a contradiction means you cannot use both them and the Library together in an executable that you distribute. 7. You may place library facilities that are a work based on the Library side-by-side in a single library together with other library facilities not covered by this License, and distribute such a combined library, provided that the separate distribution of the work based on the Library and of the other library facilities is otherwise permitted, and provided that you do these two things: a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities. This must be distributed under the terms of the Sections above. b) Give prominent notice with the combined library of the fact that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work. 8. You may not copy, modify, sublicense, link with, or distribute the Library except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense, link with, or distribute the Library is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 9. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Library or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Library (or any work based on the Library), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Library or works based on it. 10. Each time you redistribute the Library (or any work based on the Library), the recipient automatically receives a license from the original licensor to copy, distribute, link with or modify the Library subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties with this License. 11. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Library at all. For example, if a patent license would not permit royalty-free redistribution of the Library by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Library. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply, and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 12. If the distribution and/or use of the Library is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Library under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 13. The Free Software Foundation may publish revised and/or new versions of the Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Library specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Library does not specify a license version number, you may choose any version ever published by the Free Software Foundation. 14. If you wish to incorporate parts of the Library into other free programs whose distribution conditions are incompatible with these, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS Horde_Kolab_Server-2.0.5/doc/Horde/Kolab/Server/TODO0000664000175000017500000000135312653735542020133 0ustar janjan==================================== Kolab_Server Development TODO List ==================================== - Ensure getBaseUid always returns a value (see Kolab_Freebusy/lib/Horde/Kolab/FreeBusy/Access.php) - Ensure the correct hostnames for a user get returned (getServer). - Implement currently missing scenarios. - Implement Kolab-webadmin functions - Check Kolab-webadmin patches in Kolab issue tracker. - Check with current HEAD applications. - Implement initial server bootstrap - Load-Balancing. - Read entry after writing and detect inconsistencies. - Password history support - Support alias attribute names - Support size restrictions. - Implement search result caching. - Remove Horde_Date dependency. Horde_Kolab_Server-2.0.5/doc/Horde/Kolab/Server/usage.txt0000664000175000017500000000742412653735542021315 0ustar janjanThe "Horde_Kolab_Server" package allows you to access the Kolab Server user database. Installation of the package =========================== The package is being distributed as a standard PEAR package by the Horde project. As long as you have PEAR installed, installation should be straight forward. pear channel-discover pear.horde.org pear install --force channel://pear.horde.org/Horde_Kolab_Server "pear" will probably complain about the library (and its dependencies) not being marked stable yet but the "--force" option allows to ignore these warnings. Using the package =========================== This section will present some examples on how to fetch information from the Kolab Server database. Currently the package only provides a LDAP and a test driver as possible backends. The test driver is for internal testing purposes only and emulates a LDAP system without requiring access to a real LDAP database. So most developers will use the LDAP back end. In order to enable the driver some basic configuration is required. Configurations for Horde are always set in the global "$conf" variable. A possible configuration for "Horde_Kolab_Server" could look like this: global $conf; $conf['kolab']['server']['driver'] = 'ldap'; $conf['kolab']['server']['params']['server'] = 'example.com'; $conf['kolab']['server']['params']['base_dn'] = 'dc=example,dc=com'; $conf['kolab']['server']['params']['bind_dn'] = 'cn=nobody,cn=internal,dc=example,dc=com'; $conf['kolab']['server']['params']['bind_pw'] = 'MY_VERY_SECRET_PASSWORD'; With this base configuration the developer can load the code and initialize the server object: require_once 'Horde/Kolab/Server.php'; $server = Horde_Kolab_Server::singleton(); This server handler serves two primary purposes: * Identifying the ID of an object on basis of a given attribute * Fetching an object from the database based on the ID A common request to the Kolab LDAP database is to return the ID of a user given a mail address. The "$server" object will return the "DN" ("distinguished name") of the object in the LDAP database: $dn = $server->dnForMailAddress('wrobel@example.com'); The returned "DN" could look like this: var_dump($dn); string(32) "cn=Gunnar Wrobel,dc=example,dc=com" For alternative methods of retrieving a particular "DN" you should consult the detailed package documentation (see below). This "DN" can now be used to fetch the object from the database: $object = $server->fetch($dn); The "$server" object will always return an object of class "Horde_Kolab_Server_Object". But you will receive a sub class of this parent class that matches the type of the object. For the example given above the server handler returns an object of type "Horde_Kolab_Server_Object_user": var_dump(get_class($object)); string(30) "Horde_Kolab_Server_Object_user" Depending on the sub class such an object presents different features. One primary method is common to all the objects though: Fetching attribute values with "get()". $attr = $object->get(Horde_Kolab_Server_Object::ATTRIBUTE_CN); "Horde_Kolab_Server_Object::ATTRIBUTE_CN" is being used to retrieve the "common name" of the object: var_dump($attr); string(13) "Gunnar Wrobel" For additional details about the different objects and attribute types you should consult the detailed package documentation (see below). Detailed package documentation ============================== A detailed documentation based on the code comments and extracted via phpDocumentor can be found at http://dev.horde.org/api/framework/. Simply select the package "Kolab_Server" in the package selection box in the upper right corner. ToDo ==== Currently the package only implements read access. At some point it should allow write access, too. This is required to convert the Kolab webadmin to use this package. Horde_Kolab_Server-2.0.5/lib/Horde/Kolab/Server/Connection/Mock/Ldap.php0000664000175000017500000004646512653735542024042 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * This class provides a class for testing the Kolab Server DB. * * Copyright 2008-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Connection_Mock_Ldap { /** * Connection parameters. * * @var array */ private $_params; /** * The current database data. * * @var array */ private $_data; /** * Is the connection bound via username / password? * * @var boolean */ private $_bound = false; /** * Constructor. * * @param array $params Connection parameters. * @param array $data Mockup LDAP data. */ public function __construct(array $params, array $data) { $this->_params = $params; $this->_data = $data; } /** * Binds the LDAP connection with a specific user and pass. * * @param string $dn DN to bind with * @param string $pw Password associated to this DN. * * @return NULL * * @throws Horde_Kolab_Server_Exception If the user does not exit, he has no * password, provided an incorrect * password or anonymous binding is not * allowed. */ public function bind($dn = '', $pw = '') { if ($dn == '' && $pw == '') { if (isset($this->_params['binddn']) && isset($this->_params['bindpw'])) { $dn = $this->_params['binddn']; $pw = $this->_params['bindpw']; } } if ($dn != '') { if (!isset($this->_data[$dn])) { throw new Horde_Kolab_Server_Exception('User does not exist!'); } if (!isset($this->_data[$dn]['data']['userPassword'][0])) { throw new Horde_Kolab_Server_Exception('User has no password entry!'); } if ($this->_data[$dn]['data']['userPassword'][0] != $pw) { throw new Horde_Kolab_Server_Exception_Bindfailed('Incorrect password!'); } } else if (!empty($this->_params['no_anonymous_bind'])) { throw new Horde_Kolab_Server_Exception('Anonymous bind is not allowed!'); } $this->_bound = true; } /** * Get a specific entry based on the DN * * @param string $dn DN of the entry that should be fetched * @param array $attr Array of Attributes to select. If ommitted, all attributes are fetched. * * @return Horde_Ldap_Entry|Horde_Ldap_Error Reference to a Horde_Ldap_Entry object or Horde_Ldap_Error object * @todo Maybe check against the shema should be done to be sure the attribute type exists */ public function getEntry($dn, $attr = array()) { $this->_checkBound(); if (!is_array($attr)) { $attr = array($attr); } $result = $this->search($dn, '(objectClass=*)', array('scope' => 'base', 'attributes' => $attr)); if ($result->count() == 0) { throw new Horde_Kolab_Server_Exception('Could not fetch entry '.$dn.': no entry found'); } $entry = $result->shiftEntry(); if (false == $entry) { throw new Horde_Kolab_Server_Exception('Could not fetch entry (error retrieving entry from search result)'); } return $entry; } /** * Search for object data. * * @param string $base The search base * @param string $filter The LDAP search filter. * @param string $params Additional search parameters. * * @return array The result array. * * @throws Horde_Kolab_Server_Exception If the search operation encountered * a problem. */ public function search($base = null, $filter = null, $params = array()) { $this->_checkBound(); if (isset($params['attributes'])) { $attributes = $params['attributes']; if (!is_array($attributes)) { $attributes = array($attributes); } } else { $attributes = array(); } $result = array(); if (!empty($filter)) { $filter = $this->parse($filter); $result = $this->doSearch($filter, $attributes); } else { if (!isset($params['scope']) || $params['scope'] == 'sub') { foreach (array_keys($this->_data) as $dn) { if (empty($attributes)) { $result[] = $this->_data[$dn]; } else { $selection = $this->_data[$dn]; foreach ($this->_data[$dn]['data'] as $attr => $value) { if (!in_array($attr, $attributes)) { unset($selection['data'][$attr]); } } $result[] = $selection; } } } else if ($params['scope'] == 'base') { if (isset($this->_data[$base])) { $result[] = $this->_data[$base]; } else { $result = array(); } } else if ($params['scope'] == 'one') { throw new Horde_Kolab_Server_Exception('Not implemented!'); } } if (empty($result)) { $search = new Horde_Kolab_Server_Connection_Mock_Search(array()); return $search; } if (!empty($base)) { $subtree = array(); foreach ($result as $entry) { if (preg_match('/' . $base . '$/', $entry['dn'])) { $subtree[] = $entry; } } $result = $subtree; } $search = new Horde_Kolab_Server_Connection_Mock_Search($this->getEntries($result)); return $search; } /** * Return the entries of a result. * * @param array $result The LDAP search result. * * @return mixed The entries of the result or false. */ public function getEntries($result) { if (is_array($result)) { $data = array(); foreach ($result as $entry) { $t = $entry['data']; $t['dn'] = $entry['dn']; $data[$entry['dn']] = $t; } return $data; } return false; } /** * Parse LDAP filter. * Partially derived from Net_LDAP_Filter. * * @param string $filter The filter string. * * @return array An array of the parsed filter. * * @throws Horde_Kolab_Server_Exception If parsing the filter expression * fails. */ public function parse($filter) { $result = array(); if (preg_match('/^\((.+?)\)$/', $filter, $matches)) { if (in_array(substr($matches[1], 0, 1), array('!', '|', '&'))) { $result['op'] = substr($matches[1], 0, 1); $result['sub'] = $this->parseSub(substr($matches[1], 1)); return $result; } else { if (stristr($matches[1], ')(')) { throw new Horde_Kolab_Server_Exception('Filter parsing error: invalid filter syntax - multiple leaf components detected!'); } else { $filter_parts = preg_split('/(?|<|>=|<=)/', $matches[1], 2, PREG_SPLIT_DELIM_CAPTURE); if (count($filter_parts) != 3) { throw new Horde_Kolab_Server_Exception('Filter parsing error: invalid filter syntax - unknown matching rule used'); } else { $result['att'] = $filter_parts[0]; $result['log'] = $filter_parts[1]; $val = Horde_Ldap_Util::unescapeFilterValue($filter_parts[2]); $result['val'] = $val[0]; return $result; } } } } else { throw new Horde_Kolab_Server_Exception(sprintf("Filter parsing error: %s - filter components must be enclosed in round brackets", $filter)); } } /** * Parse a LDAP subfilter. * * @param string $filter The subfilter string. * * @return array An array of the parsed subfilter. * * @throws Horde_Kolab_Server_Exception */ public function parseSub($filter) { $result = array(); $level = 0; $collect = ''; while (preg_match('/^(\(.+?\))(.*)/', $filter, $matches)) { if (in_array(substr($matches[1], 0, 2), array('(!', '(|', '(&'))) { $level++; } if ($level) { $collect .= $matches[1]; if (substr($matches[2], 0, 1) == ')') { $collect .= ')'; $matches[2] = substr($matches[2], 1); $level--; if (!$level) { $result[] = $this->parse($collect); } } } else { $result[] = $this->parse($matches[1]); } $filter = $matches[2]; } return $result; } /** * Perform the search. * * @param array $filter Filter criteria- * @param array $attributes Restrict the search result to * these attributes. * * @return array A LDAP serach result. * * @throws Horde_Kolab_Server_Exception If the search operation is not * available. */ public function doSearch($filter, $attributes = null) { if (isset($filter['log'])) { $result = array(); foreach ($this->_data as $element) { if (isset($element['data'][$filter['att']])) { switch ($filter['log']) { case '=': $value = $element['data'][$filter['att']]; if (!empty($value) && is_array($value)) { $keys = array_keys($value); $first = $value[$keys[0]]; } else { $first = $value; } if ((($filter['val'] == '*') && !empty($value)) || $value == $filter['val'] || (substr($filter['val'], 0, 1) == '*' && substr($filter['val'], strlen($filter['val']) - 1) == '*' && strpos($first, substr($filter['val'], 1, strlen($filter['val']) - 2)) !== false) || (is_array($value) && in_array($filter['val'], $value))) { if (empty($attributes)) { $result[] = $element; } else { $selection = $element; foreach ($element['data'] as $attr => $value) { if (!in_array($attr, $attributes)) { unset($selection['data'][$attr]); } } $result[] = $selection; } } break; default: throw new Horde_Kolab_Server_Exception("Not implemented!"); } } } return $result; } else { $subresult = array(); $filtercount = count($filter['sub']); foreach ($filter['sub'] as $subfilter) { $subresult = array_merge($subresult, $this->doSearch($subfilter, $attributes)); } $result = array(); $dns = array(); foreach ($subresult as $element) { $dns[] = $element['dn']; $result[$element['dn']] = $element; } switch ($filter['op']) { case '&': $count = array_count_values($dns); $selection = array(); foreach ($count as $dn => $value) { if ($value == $filtercount) { $selection[] = $result[$dn]; } } return $selection; case '|': return array_values($result); case '!': $dns = array(); foreach ($result as $entry) { if (!in_array($entry['dn'], $dns) ) { $dns[] = $entry['dn']; } } $all_dns = array_keys($this->_data); $diff = array_diff($all_dns, $dns); $result = array(); foreach ($diff as $dn) { if (empty($attributes)) { $result[] = $this->_data[$dn]; } else { $selection = $this->_data[$dn]; foreach ($this->_data[$dn]['data'] as $attr => $value) { if (!in_array($attr, $attributes)) { unset($selection['data'][$attr]); } } $result[] = $selection; } } return $result; default: throw new Horde_Kolab_Server_Exception("Not implemented!"); } } } /** * Add a new entryobject to a directory. * * @param Horde_Ldap_Entry $entry Horde_Ldap_Entry * * @return Horde_Ldap_Error|true Horde_Ldap_Error object or true */ public function add($entry) { $this->_checkBound(); $ldap_data = $this->toStorage($entry->getValues()); $guid = $entry->getDn(); $this->_data[$guid] = array( 'dn' => $guid, 'data' => array_merge($ldap_data, array('dn' => $guid)), ); } /** * Modify an ldapentry directly on the server * * @param string|Horde_Ldap_Entry &$entry DN-string or Horde_Ldap_Entry * @param array $parms Array of changes * * @access public * @return Horde_Ldap_Error|true Horde_Ldap_Error object or true */ public function modify($entry, $data = array()) { $this->_checkBound(); $guid = $entry->getDn(); if (isset($data['delete'])) { foreach ($data['delete'] as $k => $v) { if (is_int($k)) { if (isset($this->_data[$guid]['data'][$w])) { /** Delete a complete attribute */ unset($this->_data[$guid]['data'][$w]); } } else { if (isset($this->_data[$guid]['data'][$l])) { if (!is_array($v)) { $v = array($v); } foreach ($v as $w) { $key = array_search($w, $this->_data[$guid]['data'][$l]); if ($key !== false) { /** Delete a single value */ unset($this->_data[$guid]['data'][$l][$key]); } } } } } } if (isset($data['replace'])) { $ldap_data = $this->toStorage($data['replace']); $this->_data[$guid] = array( 'dn' => $guid, 'data' => array_merge($this->_data[$guid]['data'], $ldap_data, array('dn' => $guid)), ); } if (isset($data['add'])) { $ldap_data = $this->toStorage($data['add']); foreach ($ldap_data as $k => $v) { if (is_array($v)) { foreach ($v as $w) { $this->_data[$guid]['data'][$k][] = $w; } } else { $this->_data[$guid]['data'][$k][] = $v; } $this->_data[$guid]['data'][$k] = array_values($this->_data[$guid]['data'][$k]); } } } /** * Delete an object. * * @param string $uid The UID of the object to be deleted. * * @return NULL * * @throws Horde_Kolab_Server_Exception */ public function delete($uid) { $this->_checkBound(); if (isset($this->_data[$uid])) { unset($this->_data[$uid]); } else { throw new Horde_Kolab_Server_MissingObjectException(sprintf("No such object: %s", $uid)); } } /** * Rename an object. * * @param string $uid The UID of the object to be renamed. * @param string $new The new UID of the object. * * @return NULL * * @throws Horde_Kolab_Server_Exception */ public function move($uid, $new) { $this->_checkBound(); if (isset($this->_data[$uid])) { $this->_data[$new] = $this->_data[$uid]; unset($this->_data[$uid]); } } public function schema() { //@todo: implement } /** * Rewrite a data array to our internal storage format. * * @param array $data The attributes of the object to be added/replaced. * * @return array The transformed data set. */ protected function toStorage($data) { $ldap_data = array(); foreach ($data as $key => $val) { if (!is_array($val)) { $val = array($val); } $ldap_data[$key] = $val; } return $ldap_data; } /** * Check if the current connection is bound. * * @return NULL * * @throws Horde_Kolab_Server_Exception If the connection is not bound. */ private function _checkBound() { if (!$this->_bound) { throw new Horde_Kolab_Server_Exception('Unbound connection!'); } } } Horde_Kolab_Server-2.0.5/lib/Horde/Kolab/Server/Connection/Mock/Search.php0000664000175000017500000000327712653735542024361 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * A mockup class to simulate LDAP search results. * * Copyright 2008-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Connection_Mock_Search extends Horde_Ldap_Search { /** * The search result. * * @var array */ private $_result; /** * Constructor. * * @param array $result The search result. */ public function __construct(array $result) { $this->_result = $result; } /** * The number of result entries. * * @return int The number of elements. */ public function count() { return count($this->_result); } /** * Test if the last search exceeded the size limit. * * @return boolean True if the last search exceeded the size limit. */ public function sizeLimitExceeded() { return false; } /** * Return the result as an array. * * @return array The resulting array. */ public function asArray() { return $this->_result; } } Horde_Kolab_Server-2.0.5/lib/Horde/Kolab/Server/Connection/File.php0000664000175000017500000000657612653735542023147 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * This class provides a persistant class for testing the Kolab Server DB. * * Copyright 2008-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Connection_File extends Horde_Kolab_Server_Connection_Mock { /** * The file for storing the database data. * * @var string */ private $_file; /** * Set configuration parameters. * * @param array $params The parameters. * * @return NULL */ public function setParams(array $params) { if (isset($params['file'])) { $this->_file = $params['file']; } parent::setParams($params); } /** * Get the file parameter. * * @return NULL */ private function _getFile() { if (empty($this->_file)) { throw new Horde_Kolab_Server_Exception('The file based driver requires a \'file\' parameter.'); } return $this->_file; } /** * Load the current state of the database. * * @return NULL */ protected function load() { $raw_data = file_get_contents($this->_getFile()); if (!$raw_data === false) { $data = @unserialize($raw_data); if ($data !== false) { $this->data = $data; } else { $error = error_get_last(); if (isset($this->logger)) { $this->logger->warn(sprintf('Horde_Kolab_Server_file failed to read the database from %s. Error was: %s', $this->_getFile(), $error['message'])); } $this->data = array(); } } } /** * Store the current state of the database. * * @return NULL */ protected function store() { $raw_data = serialize($this->data); $result = @file_put_contents($this->_getFile(), $raw_data); if ($result === false) { $error = error_get_last(); if (isset($this->logger)) { $this->logger->warn(sprintf('Horde_Kolab_Server_file failed to store the database in %s. Error was: %s', $this->_getFile(), $error['message'])); } } } /** * Cleans the current state of the database. * * @return NULL */ public function clean() { unlink($this->_getFile()); $this->data = array(); $this->store(); } /** * Returns the path to the storage location of the database. * * @return string The path to the database. */ public function getStoragePath() { return $this->_getFile(); } } Horde_Kolab_Server-2.0.5/lib/Horde/Kolab/Server/Connection/Interface.php0000664000175000017500000000213212653735542024150 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * Interface for connection handling. * * Copyright 2008-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ interface Horde_Kolab_Server_Connection_Interface { /** * Get the server read connection. * * @return mixed The connection for reading data. */ public function getRead(); /** * Get the server write connection. * * @return mixed The connection for writing data. */ public function getWrite(); }Horde_Kolab_Server-2.0.5/lib/Horde/Kolab/Server/Connection/Mock.php0000664000175000017500000000310712653735542023144 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * This class provides a class for testing the Kolab Server DB. * * Copyright 2008-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Connection_Mock implements Horde_Kolab_Server_Connection_Interface { /** * The LDAP connection handle. * * @var Horde_Ldap */ private $_ldap; /** * Constructor * * @param Horde_Ldap $ldap The ldap connection. */ public function __construct(Horde_Kolab_Server_Connection_Mock_Ldap $ldap) { $this->_ldap = $ldap; } /** * Get the server read connection. * * @return mixed The connection for reading data. */ public function getRead() { return $this->_ldap; } /** * Get the server write connection. * * @return mixed The connection for writing data. */ public function getWrite() { return $this->_ldap; } }Horde_Kolab_Server-2.0.5/lib/Horde/Kolab/Server/Connection/Simpleldap.php0000664000175000017500000000302112653735542024340 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * A simple LDAP setup without read-only slaves. * * Copyright 2008-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Connection_Simpleldap implements Horde_Kolab_Server_Connection_Interface { /** * The LDAP connection handle. * * @var Horde_Ldap */ private $_ldap; /** * Constructor * * @param Horde_Ldap $ldap The ldap connection. */ public function __construct(Horde_Ldap $ldap) { $this->_ldap = $ldap; } /** * Get the server read connection. * * @return mixed The connection for reading data. */ public function getRead() { return $this->_ldap; } /** * Get the server write connection. * * @return mixed The connection for writing data. */ public function getWrite() { return $this->_ldap; } }Horde_Kolab_Server-2.0.5/lib/Horde/Kolab/Server/Connection/Splittedldap.php0000664000175000017500000000347212653735542024711 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * A connection to a LDAP master/slave setup. * * Copyright 2008-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Connection_Splittedldap implements Horde_Kolab_Server_Connection_Interface { /** * LDAP read connection handle. * * @var Horde_Ldap */ private $_ldap_read; /** * LDAP write connection handle. * * @var Horde_Ldap */ private $_ldap_write; /** * Constructor * * @param Horde_Ldap $ldap_read The ldap_read connection. * @param Horde_Ldap $ldap_write The ldap_write connection. */ public function __construct( Horde_Ldap $ldap_read, Horde_Ldap $ldap_write ) { $this->_ldap_read = $ldap_read; $this->_ldap_write = $ldap_write; } /** * Get the server read connection. * * @return mixed The connection for reading data. */ public function getRead() { return $this->_ldap_read; } /** * Get the server write connection. * * @return mixed The connection for writing data. */ public function getWrite() { return $this->_ldap_write; } }Horde_Kolab_Server-2.0.5/lib/Horde/Kolab/Server/Decorator/Clean.php0000664000175000017500000001535612653735542023131 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * A cleanup decoration for Kolab Servers that allows to remove all added * objects. * * Copyright 2008-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Decorator_Clean implements Horde_Kolab_Server_Interface { /** * The server we delegate to. * * @var Horde_Kolab_Server */ private $_server; /** * The objects added. * * @var array */ private $_added = array(); /** * Constructor. * * @param Horde_Kolab_Server $server The base server connection. */ public function __construct( Horde_Kolab_Server_Interface $server ) { $this->_server = $server; } /** * Connect to the server. * * @param string $guid The global unique id of the user. * @param string $pass The password. * * @return NULL. * * @throws Horde_Kolab_Server_Exception If the connection failed. */ public function connectGuid($guid = null, $pass = null) { $this->_server->connectGuid($guid, $pass); } /** * Get the current GUID * * @return string The GUID of the connected user. */ public function getGuid() { return $this->_server->getGuid(); } /** * Get the base GUID of this server * * @return string The base GUID of this server. */ public function getBaseGuid() { return $this->_server->getBaseGuid(); } /** * Low level access to reading object data. * * @param string $guid The object to retrieve. * @param array $attrs Restrict to these attributes. * * @return array An array of attributes. * * @throws Horde_Kolab_Server_Exception If the search operation hit an error * or returned no result. */ public function read($guid, array $attrs = array()) { return $this->_server->read($guid); } /** * Low level access to reading some object attributes. * * @param string $guid The object to retrieve. * @param string $attrs Restrict to these attributes. * * @return array An array of attributes. * * @throws Horde_Kolab_Server_Exception * * @see Horde_Kolab_Server::read */ public function readAttributes($guid, array $attrs) { return $this->_server->readAttributes($guid, $attrs); } /** * Finds object data matching a given set of criteria. * * @param string $query The LDAP search query * @param array $params Additional search parameters. * * @return Horde_Kolab_Server_Result The result object. * * @throws Horde_Kolab_Server_Exception */ public function find($query, array $params = array()) { return $this->_server->find($query, $params); } /** * Finds all object data below a parent matching a given set of criteria. * * @param string $query The LDAP search query * @param string $parent The parent to search below. * @param array $params Additional search parameters. * * @return Horde_Kolab_Server_Result The result object. * * @throws Horde_Kolab_Server_Exception */ public function findBelow($query, $parent, array $params = array()) { return $this->_server->findBelow($query, $parent, $params); } /** * Modify existing object data. * * @param Horde_Kolab_Server_Object $object The object to be modified. * @param array $data The attributes of the object * to be stored. * * @return NULL * * @throws Horde_Kolab_Server_Exception */ public function save( Horde_Kolab_Server_Object_Interface $object, array $data ) { $this->_server->save($object, $data); } /** * Add new object data. * * @param Horde_Kolab_Server_Object $object The object to be added. * @param array $data The attributes of the object * to be added. * * @return NULL * * @throws Horde_Kolab_Server_Exception */ public function add( Horde_Kolab_Server_Object_Interface $object, array $data ) { $this->_server->add($object, $data); $this->_added[] = $object->getGuid(); } /** * Delete an object. * * @param string $guid The GUID of the object to be deleted. * * @return NULL * * @throws Horde_Kolab_Server_Exception */ public function delete($guid) { $this->_server->delete($guid); if (in_array($guid, $this->_added)) { $this->_added = array_diff($this->_added, array($guid)); } } /** * Rename an object. * * @param string $guid The GUID of the object to be renamed. * @param string $new The new GUID of the object. * * @return NULL * * @throws Horde_Kolab_Server_Exception */ public function rename($guid, $new) { $this->_server->rename($guid, $new); } /** * Return the ldap schema. * * @return Horde_Ldap_Schema The LDAP schema. * * @throws Horde_Kolab_Server_Exception If retrieval of the schema failed. */ public function getSchema() { return $this->_server->getSchema(); } /** * Get the parent GUID of this object. * * @param string $guid The GUID of the child. * * @return string the parent GUID of this object. */ public function getParentGuid($guid) { return $this->_server->getParentGuid($guid); } /** * Cleanup the server. * * @throws Horde_Kolab_Server_Exception */ public function cleanup() { foreach ($this->_added as $guid) { $this->delete($guid); } } /** * Destructor. */ public function __destruct() { try { $this->cleanup(); } catch (Horde_Kolab_Server_Exception $e) { } } } Horde_Kolab_Server-2.0.5/lib/Horde/Kolab/Server/Decorator/Count.php0000664000175000017500000002061112653735542023165 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * A server decorator that counts the number of database calls and * reports them via a logger. * * Copyright 2008-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Decorator_Count implements Horde_Kolab_Server_Interface { /** * The server we delegate to. * * @var Horde_Kolab_Server */ private $_server; /** * The log handler. * * @var Horde_Log_Logger */ private $_logger; /** * The statistic. * * @var array */ private $_count = array(); /** * Constructor. * * @param Horde_Kolab_Server $server The base server connection. * @param mixed $logger The log handler. The class must at * least provide the debug() method. */ public function __construct( Horde_Kolab_Server_Interface $server, $logger ) { $this->_server = $server; $this->_logger = $logger; } /** * Destructor. * * Logs the counted events. */ public function __destruct() { foreach ($this->_count as $method => $count) { $this->_logger->debug( sprintf( 'Horde_Kolab_Server: Method %s called %s times.', $method, $count ) ); } } /** * Connect to the server. * * @param string $guid The global unique id of the user. * @param string $pass The password. * * @return NULL. * * @throws Horde_Kolab_Server_Exception If the connection failed. */ public function connectGuid($guid = null, $pass = null) { $this->_server->connectGuid($guid, $pass); if (!isset($this->_count['connectGuid'])) { $this->_count['connectGuid'] = 1; } else { $this->_count['connectGuid']++; } } /** * Get the current GUID * * @return string The GUID of the connected user. */ public function getGuid() { return $this->_server->getGuid(); } /** * Get the base GUID of this server * * @return string The base GUID of this server. */ public function getBaseGuid() { return $this->_server->getBaseGuid(); } /** * Low level access to reading object data. * * @param string $guid The object to retrieve. * @param array $attrs Restrict to these attributes. * * @return array An array of attributes. * * @throws Horde_Kolab_Server_Exception If the search operation hit an error * or returned no result. */ public function read($guid, array $attrs = array()) { if (!isset($this->_count['read'])) { $this->_count['read'] = 1; } else { $this->_count['read']++; } return $this->_server->read($guid); } /** * Low level access to reading some object attributes. * * @param string $guid The object to retrieve. * @param string $attrs Restrict to these attributes. * * @return array An array of attributes. * * @throws Horde_Kolab_Server_Exception * * @see Horde_Kolab_Server::read */ public function readAttributes($guid, array $attrs) { if (!isset($this->_count['readAttributes'])) { $this->_count['readAttributes'] = 1; } else { $this->_count['readAttributes']++; } return $this->_server->readAttributes($guid, $attrs); } /** * Finds object data matching a given set of criteria. * * @param string $query The LDAP search query * @param array $params Additional search parameters. * * @return Horde_Kolab_Server_Result The result object. * * @throws Horde_Kolab_Server_Exception */ public function find($query, array $params = array()) { if (!isset($this->_count['find'])) { $this->_count['find'] = 1; } else { $this->_count['find']++; } return $this->_server->find($query, $params); } /** * Finds all object data below a parent matching a given set of criteria. * * @param string $query The LDAP search query * @param string $parent The parent to search below. * @param array $params Additional search parameters. * * @return Horde_Kolab_Server_Result The result object. * * @throws Horde_Kolab_Server_Exception */ public function findBelow($query, $parent, array $params = array()) { if (!isset($this->_count['findBelow'])) { $this->_count['findBelow'] = 1; } else { $this->_count['findBelow']++; } return $this->_server->findBelow($query, $parent, $params); } /** * Modify existing object data. * * @param Horde_Kolab_Server_Object $object The object to be modified. * @param array $data The attributes of the object * to be stored. * * @return NULL * * @throws Horde_Kolab_Server_Exception */ public function save( Horde_Kolab_Server_Object_Interface $object, array $data ) { $this->_server->save($object, $data); if (!isset($this->_count['save'])) { $this->_count['save'] = 1; } else { $this->_count['save']++; } } /** * Add new object data. * * @param Horde_Kolab_Server_Object $object The object to be added. * @param array $data The attributes of the object * to be added. * * @return NULL * * @throws Horde_Kolab_Server_Exception */ public function add( Horde_Kolab_Server_Object_Interface $object, array $data ) { $this->_server->add($object, $data); if (!isset($this->_count['add'])) { $this->_count['add'] = 1; } else { $this->_count['add']++; } } /** * Delete an object. * * @param string $guid The GUID of the object to be deleted. * * @return NULL * * @throws Horde_Kolab_Server_Exception */ public function delete($guid) { $this->_server->delete($guid); if (!isset($this->_count['delete'])) { $this->_count['delete'] = 1; } else { $this->_count['delete']++; } } /** * Rename an object. * * @param string $guid The GUID of the object to be renamed. * @param string $new The new GUID of the object. * * @return NULL * * @throws Horde_Kolab_Server_Exception */ public function rename($guid, $new) { $this->_server->rename($guid, $new); if (!isset($this->_count['rename'])) { $this->_count['rename'] = 1; } else { $this->_count['rename']++; } } /** * Return the ldap schema. * * @return Horde_Ldap_Schema The LDAP schema. * * @throws Horde_Kolab_Server_Exception If retrieval of the schema failed. */ public function getSchema() { return $this->_server->getSchema(); if (!isset($this->_count['getSchema'])) { $this->_count['getSchema'] = 1; } else { $this->_count['getSchema']++; } } /** * Get the parent GUID of this object. * * @param string $guid The GUID of the child. * * @return string the parent GUID of this object. */ public function getParentGuid($guid) { return $this->_server->getParentGuid($guid); } } Horde_Kolab_Server-2.0.5/lib/Horde/Kolab/Server/Decorator/Log.php0000664000175000017500000002166012653735542022623 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * A server delegation that logs server access via Horde_Log_Logger. * * Copyright 2008-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Decorator_Log implements Horde_Kolab_Server_Interface { /** * The server we delegate to. * * @var Horde_Kolab_Server */ private $_server; /** * The log handler. * * @var mixed */ private $_logger; /** * Constructor. * * @param Horde_Kolab_Server $server The base server connection. * @param mixed $logger The log handler. The class must at * least provide the debug() and warn() * methods. */ public function __construct(Horde_Kolab_Server_Interface $server, $logger) { $this->_server = $server; $this->_logger = $logger; } /** * Connect to the server. * * @param string $guid The global unique id of the user. * @param string $pass The password. * * @return NULL. * * @throws Horde_Kolab_Server_Exception If the connection failed. */ public function connectGuid($guid = null, $pass = null) { try { $this->_server->connectGuid($guid, $pass); $this->_logger->debug( sprintf( "Successfully connected to the Kolab Server as \"%s\".", $guid ) ); } catch (Horde_Kolab_Server_Exception $e) { $this->_logger->debug( sprintf( "Failed connecting to the Kolab Server as \"%s\"! Error: %s", $guid, $e->getMessage() ) ); throw $e; } } /** * Get the current GUID * * @return string The GUID of the connected user. */ public function getGuid() { return $this->_server->getGuid(); } /** * Get the base GUID of this server * * @return string The base GUID of this server. */ public function getBaseGuid() { return $this->_server->getBaseGuid(); } /** * Low level access to reading object data. * * @param string $guid The object to retrieve. * @param array $attrs Restrict to these attributes. * * @return array An array of attributes. * * @throws Horde_Kolab_Server_Exception If the search operation hit an error * or returned no result. */ public function read($guid, array $attrs = array()) { return $this->_server->read($guid); } /** * Low level access to reading some object attributes. * * @param string $guid The object to retrieve. * @param string $attrs Restrict to these attributes. * * @return array An array of attributes. * * @throws Horde_Kolab_Server_Exception * * @see Horde_Kolab_Server::read */ public function readAttributes($guid, array $attrs) { return $this->_server->readAttributes($guid, $attrs); } /** * Finds object data matching a given set of criteria. * * @param string $query The LDAP search query * @param array $params Additional search parameters. * * @return Horde_Kolab_Server_Result The result object. * * @throws Horde_Kolab_Server_Exception */ public function find($query, array $params = array()) { $result = $this->_server->find($query, $params); $this->_logger->debug( sprintf( "Query %s identified %s result(s).", $query, $result->count() ) ); return $result; } /** * Finds all object data below a parent matching a given set of criteria. * * @param string $query The LDAP search query * @param string $parent The parent to search below. * @param array $params Additional search parameters. * * @return Horde_Kolab_Server_Result The result object. * * @throws Horde_Kolab_Server_Exception */ public function findBelow($query, $parent, array $params = array()) { return $this->_server->findBelow($query, $parent, $params); } /** * Modify existing object data. * * @param Horde_Kolab_Server_Object $object The object to be modified. * @param array $data The attributes of the object * to be stored. * * @return NULL * * @throws Horde_Kolab_Server_Exception */ public function save( Horde_Kolab_Server_Object_Interface $object, array $data ) { try { $this->_server->save($object, $data); $this->_logger->debug( sprintf( "The object \"%s\" has been successfully saved!", $object->getGuid() ) ); } catch (Horde_Kolab_Server_Exception $e) { $this->_logger->warn( sprintf( "Failed saving object \"%s\"! Error: %s", $object->getGuid(), $e->getMessage() ) ); } } /** * Add new object data. * * @param Horde_Kolab_Server_Object $object The object to be added. * @param array $data The attributes of the object * to be added. * * @return NULL * * @throws Horde_Kolab_Server_Exception */ public function add( Horde_Kolab_Server_Object_Interface $object, array $data ) { try { $this->_server->add($object, $data); $this->_logger->debug( sprintf( "The object \"%s\" has been successfully added!", $object->getGuid() ) ); } catch (Horde_Kolab_Server_Exception $e) { $this->_logger->warn( sprintf( "Failed adding object \"%s\"! Error: %s", $object->getGuid(), $e->getMessage() ) ); } } /** * Delete an object. * * @param string $guid The GUID of the object to be deleted. * * @return NULL * * @throws Horde_Kolab_Server_Exception */ public function delete($guid) { try { $this->_server->delete($guid); $this->_logger->debug( sprintf("The object \"%s\" has been successfully deleted!", $guid) ); } catch (Horde_Kolab_Server_Exception $e) { $this->_logger->warn( sprintf( "Failed deleting object \"%s\"! Error: %s", $object->getGuid(), $e->getMessage() ) ); } } /** * Rename an object. * * @param string $guid The GUID of the object to be renamed. * @param string $new The new GUID of the object. * * @return NULL * * @throws Horde_Kolab_Server_Exception */ public function rename($guid, $new) { try { $this->_server->rename($guid, $new); $this->_logger->debug( sprintf( "The object \"%s\" has been successfully renamed to \"%s\"!", $guid, $new ) ); } catch (Horde_Kolab_Server_Exception $e) { $this->_logger->warn( sprintf( "Failed saving object \"%s\"! Error: %s", $object->getGuid(), $e->getMessage() ) ); } } /** * Return the ldap schema. * * @return Horde_Ldap_Schema The LDAP schema. * * @throws Horde_Kolab_Server_Exception If retrieval of the schema failed. */ public function getSchema() { return $this->_server->getSchema(); } /** * Get the parent GUID of this object. * * @param string $guid The GUID of the child. * * @return string the parent GUID of this object. */ public function getParentGuid($guid) { return $this->_server->getParentGuid($guid); } } Horde_Kolab_Server-2.0.5/lib/Horde/Kolab/Server/Decorator/Map.php0000664000175000017500000002210212653735542022607 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * A server delegation that maps object attributes. * * Copyright 2008-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Decorator_Map implements Horde_Kolab_Server_Interface { /** * The server we delegate to. * * @var Horde_Kolab_Server */ private $_server; /** * The attribute mapping. * * @var array */ private $_mapping; /** * Constructor. * * @param Horde_Kolab_Server $server The base server connection. * @param array $mapping The attribute mapping. */ public function __construct( Horde_Kolab_Server_Interface $server, array $mapping ) { $this->_server = $server; $this->_mapping = $mapping; } /** * Connect to the server. Use this method if the user name you can provide * does not match a GUID. In this case it will be required to map this user * name first. * * @param string $user The user name. * @param string $pass The password. * * @return NULL. * * @throws Horde_Kolab_Server_Exception If the connection failed. */ public function connect($user = null, $pass = null) { $this->_server->connect($user, $pass); } /** * Connect to the server. * * @param string $guid The global unique id of the user. * @param string $pass The password. * * @return NULL. * * @throws Horde_Kolab_Server_Exception If the connection failed. */ public function connectGuid($guid = '', $pass = '') { $this->_server->connectGuid($guid, $pass); } /** * Get the current GUID * * @return string The GUID of the connected user. */ public function getGuid() { $this->_server->getGuid(); } /** * Get the base GUID of this server * * @return string The base GUID of this server. */ public function getBaseGuid() { $this->_server->getBaseGuid(); } /** * Low level access to reading object data. * * @param string $guid The object to retrieve. * @param array $attrs Restrict to these attributes. * * @return array An array of attributes. * * @throws Horde_Kolab_Server_Exception If the search operation hit an error * or returned no result. */ public function read($guid, array $attrs = array()) { $data = $this->_server->read($guid); $this->unmapAttributes($data); return $data; } /** * Low level access to reading some object attributes. * * @param string $guid The object to retrieve. * @param string $attrs Restrict to these attributes. * * @return array An array of attributes. * * @throws Horde_Kolab_Server_Exception * * @see Horde_Kolab_Server::read */ public function readAttributes($guid, array $attrs) { $this->mapKeys($attrs); $data = $this->_server->readAttributes($guid, $attrs); $this->unmapAttributes($data); return $data; } /** * Finds object data matching a given set of criteria. * * @param string $query The LDAP search query * @param array $params Additional search parameters. * * @return array The result array. * * @throws Horde_Kolab_Server_Exception */ public function find($query, array $params = array()) { $criteria = new Horde_Kolab_Server_Query_Element_Mapped($criteria, $this); $data = $this->_server->find($criteria, $params); $this->unmapAttributes($data); return $data; } /** * Finds all object data below a parent matching a given set of criteria. * * @param string $query The LDAP search query * @param string $parent The parent to search below. * @param array $params Additional search parameters. * * @return array The result array. * * @throws Horde_Kolab_Server_Exception */ public function findBelow($query, $parent, array $params = array()) { $criteria = new Horde_Kolab_Server_Query_Element_Mapped($criteria, $this); $data = $this->_server->findBelow($criteria, $parent, $params); $this->unmapAttributes($data); return $data; } /** * Modify existing object data. * * @param string $guid The GUID of the object to be added. * @param array $data The attributes of the object to be added. * * @return NULL * * @throws Horde_Kolab_Server_Exception */ public function save( Horde_Kolab_Server_Object_Interface $object, array $data ) { //@todo: This will not work this way as we need to map internal // attributes. $this->mapAttributes($data); $this->_server->save($object, $data); } /** * Add new object data. * * @param string $guid The GUID of the object to be added. * @param array $data The attributes of the object to be added. * * @return NULL * * @throws Horde_Kolab_Server_Exception */ public function add( Horde_Kolab_Server_Object_Interface $object, array $data ) { //@todo: This will not work this way as we need to map internal // attributes. $this->mapAttributes($data); $this->_server->add($object, $data); } /** * Delete an object. * * @param string $guid The GUID of the object to be deleted. * * @return NULL * * @throws Horde_Kolab_Server_Exception */ public function delete($guid) { $this->_server->delete($guid); } /** * Rename an object. * * @param string $guid The GUID of the object to be renamed. * @param string $new The new GUID of the object. * * @return NULL * * @throws Horde_Kolab_Server_Exception */ public function rename($guid, $new) { $this->_server->rename($guid, $new); } /** * Return the ldap schema. * * @return Horde_Ldap_Schema The LDAP schema. * * @throws Horde_Kolab_Server_Exception If retrieval of the schema failed. */ public function getSchema() { return $this->_server->getSchema(); } /** * Map attributes defined within this library to their real world * counterparts. * * @param array &$data The data that has been read and needs to be mapped. * * @return NULL */ protected function unmapAttributes(&$data) { foreach ($data as &$element) { foreach ($this->mapping as $attribute => $map) { if (isset($element[$map])) { $element[$attribute] = $element[$map]; unset($element[$map]); } } } } /** * Map attributes defined within this library into their real world * counterparts. * * @param array &$data The data to be written. * * @return NULL */ protected function mapAttributes(&$data) { foreach ($this->mapping as $attribute => $map) { if (isset($data[$attribute])) { $data[$map] = $data[$attribute]; unset($data[$attribute]); } } } /** * Map attribute keys defined within this library into their real world * counterparts. * * @param array &$keys The attribute keys. * * @return NULL */ protected function mapKeys(&$keys) { foreach ($this->mapping as $attribute => $map) { $key = array_search($attribute, $keys); if ($key !== false) { $keys[$key] = $map; } } } /** * Map a single attribute key defined within this library into its real * world counterpart. * * @param array $field The attribute name. * * @return The real name of this attribute on the server we connect to. */ public function mapField($field) { if (isset($this->mapping[$field])) { return $this->mapping[$field]; } return $field; } /** * Get the parent GUID of this object. * * @param string $guid The GUID of the child. * * @return string the parent GUID of this object. */ public function getParentGuid($guid) { return $this->_server->getParentGuid($guid); } } Horde_Kolab_Server-2.0.5/lib/Horde/Kolab/Server/Exception/Bindfailed.php0000664000175000017500000000157312653735542024140 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * Indicate that the given bind credentials were invalid. * * Copyright 2009-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Exception_Bindfailed extends Horde_Kolab_Server_Exception { } Horde_Kolab_Server-2.0.5/lib/Horde/Kolab/Server/Exception/Novalue.php0000664000175000017500000000152212653735542023522 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * Indicate a missing attribute value. * * Copyright 2009-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Exception_Novalue extends Horde_Kolab_Server_Exception { } Horde_Kolab_Server-2.0.5/lib/Horde/Kolab/Server/Ldap/Changes.php0000664000175000017500000000563112653735542022410 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * A helper class to determine an LDAP changeset. * * Copyright 2008-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Ldap_Changes { /** * The object to be modified. * * @var Horde_Kolab_Server_Object */ private $_object; /** * The new dataset. * * @var array */ private $_data; /** * Constructor. * * @param Horde_Kolab_Server_Object $object The object to be modified. * @param array $data The attributes of the object * to be stored. */ public function __construct( Horde_Kolab_Server_Object_Interface $object, array $data ) { $this->_object = $object; $this->_data = $data; } /** * Return an LDAP changeset from the difference between the current object * data and the new dataset. * * @return array The LDAP changeset. */ public function getChangeset() { $cs = array(); $old = $this->_object->readInternal(); $new = $this->_data; $attributes = array_merge(array_keys($old), array_keys($new)); foreach ($attributes as $attribute) { if (!isset($old[$attribute])) { $cs['add'][$attribute] = $new[$attribute]; continue; } if (!isset($new[$attribute])) { $cs['delete'][] = $attribute; continue; } if (count($new[$attribute]) == 1 && count($old[$attribute]) == 1 ) { if ($new[$attribute][0] == $old[$attribute][0]) { continue; } else { $cs['replace'][$attribute] = $new[$attribute][0]; continue; } } $adds = array_diff($new[$attribute], $old[$attribute]); if (!empty($adds)) { $cs['add'][$attribute] = array_values($adds); } $deletes = array_diff($old[$attribute], $new[$attribute]); if (!empty($deletes)) { $cs['delete'][$attribute] = array_values($deletes); } } return $cs; } }Horde_Kolab_Server-2.0.5/lib/Horde/Kolab/Server/Ldap/Filtered.php0000664000175000017500000000422712653735542022576 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * This class provides methods to deal with objects stored in * a filtered LDAP db. * * Copyright 2008-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Ldap_Filtered extends Horde_Kolab_Server_Ldap { /** * A global filter to add to each query. * * @var string */ private $_filter; /** * Constructor. * * @param Horde_Kolab_Server_Connection $connection The LDAP connection. * @param string $base_dn The LDAP server base DN. * @param string $filter A global filter to add * to all queries. */ public function __construct( Horde_Kolab_Server_Connection_Interface $connection, $base_dn, $filter = null ) { parent::__construct($connection, $base_dn); $this->_filter = $filter; } /** * Finds all object data below a parent matching a given set of criteria. * * @param string $query The LDAP search query * @param string $parent The parent to search below. * @param array $params Additional search parameters. * * @return Horde_Kolab_Server_Result The result object. * * @throws Horde_Kolab_Server_Exception */ public function findBelow($query, $parent, array $params = array()) { $query = '(&(' . $this->_filter . ')' . $query . ')'; return $this->_search($query, $params, $parent); } } Horde_Kolab_Server-2.0.5/lib/Horde/Kolab/Server/Ldap/Standard.php0000664000175000017500000000263412653735542022600 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * This class provides methods to deal with objects stored in * a standard LDAP db. * * Copyright 2008-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Ldap_Standard extends Horde_Kolab_Server_Ldap { /** * Finds all object data below a parent matching a given set of criteria. * * @param string $query The LDAP search query * @param string $parent The parent to search below. * @param array $params Additional search parameters. * * @return Horde_Kolab_Server_Result The result object. * * @throws Horde_Kolab_Server_Exception */ public function findBelow($query, $parent, array $params = array()) { return $this->_search($query, $params, $parent); } } Horde_Kolab_Server-2.0.5/lib/Horde/Kolab/Server/List/Base.php0000664000175000017500000000571112653735542021744 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * A server list implementation. * * Copyright 2008-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_List_Base implements Horde_Kolab_Server_List_Interface { /** * List all objects of a specific type. * * @param string $type The type of the objects to be listed * @param array $params Additional parameters. * * @return array An array of Kolab objects. * * @throws Horde_Kolab_Server_Exception * * @todo Sorting */ public function listObjects($type, $params = null) { $result = Horde_Kolab_Server_Object::loadClass($type); $vars = get_class_vars($type); $criteria = call_user_func(array($type, 'getFilter')); $filter = $this->searchQuery($criteria); $sort = $vars['sort_by']; if (isset($params['sort'])) { $sort = $params['sort']; } $options = array('scope' => 'sub'); if (isset($params['attributes'])) { $options['attributes'] = $params['attributes']; } else { $options['attributes'] = $this->getAttributes($type); } $data = $this->search($filter, $options, $base); if (empty($data)) { return array(); } if ($sort) { /* @todo: sorting */ /* $data = $result->as_sorted_struct(); */ /*$this->sort($result, $sort); */ } if (isset($params['from'])) { $from = $params['from']; } else { $from = -1; } if (isset($params['to'])) { $sort = $params['to']; } else { $to = -1; } if (!empty($vars['required_group'])) { $required_group = new Horde_Kolab_Server_Object_Kolabgroupofnames( $this, null, $vars['required_group'] ); } $objects = array(); foreach ($data as $uid => $entry) { if (!empty($vars['required_group'])) { if (!$required_group->exists() || !$required_group->isMember($uid)) { continue; } } $objects[$uid] = &Horde_Kolab_Server_Object::factory( $type, $uid, $this, $entry ); } return $objects; } }Horde_Kolab_Server-2.0.5/lib/Horde/Kolab/Server/List/Interface.php0000664000175000017500000000222412653735542022766 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * Interface for server lists. * * Copyright 2008-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ interface Horde_Kolab_Server_List_Interface { /** * List all objects of a specific type. * * @param string $type The type of the objects to be listed * @param array $params Additional parameters. * * @return array An array of Kolab objects. * * @throws Horde_Kolab_Server_Exception * * @todo Sorting */ public function listObjects($type, $params = null); }Horde_Kolab_Server-2.0.5/lib/Horde/Kolab/Server/Object/Attribute/Base.php0000664000175000017500000000510512653735542024177 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * The base class representing Kolab object attributes. * * Copyright 2008-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ abstract class Horde_Kolab_Server_Object_Attribute_Base implements Horde_Kolab_Server_Object_Attribute_Interface { /** * The attribute name. * * @param string */ protected $name; /** * The internal attribute adapter. * * @param Horde_Kolab_Server_Structure_Attribute_Interface */ protected $attribute; /** * Constructor * * @param Horde_Kolab_Server_Structure_Attribute_Interface $attribute The internal attribute adapter. * @param string $name The name of this attribute. */ public function __construct( Horde_Kolab_Server_Structure_Attribute_Interface $attribute, $name ) { $this->attribute = $attribute; $this->name = $name; } /** * Return the internal attribute adapter. * * @return Horde_Kolab_Server_Structure_Attribute_Interface The internal * attribute. */ public function getAttribute() { return $this->attribute; } /** * Return the name of this attribute. * * @return string The name of this attribute. */ public function getName() { return $this->name; } /** * Return if this attribute is undefined in the given data array. * * @param array $changes The data array to test. * * @return string The name of this object. */ public function isEmpty(array $changes) { if ((!in_array($this->name, array_keys($changes)) || $changes[$this->name] === null || $changes[$this->name] === '' || $changes[$this->name] === array()) ) { return true; } return false; } }Horde_Kolab_Server-2.0.5/lib/Horde/Kolab/Server/Object/Attribute/Createtimestamp.php0000664000175000017500000000257712653735542026466 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * The "createTimestamp" attribute. * * Copyright 2008-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Object_Attribute_Createtimestamp extends Horde_Kolab_Server_Object_Attribute_External { /** The attribute name */ const NAME = 'createTimestamp'; /** * Constructor * * @param Horde_Kolab_Server_Object $object The object this attribute * belongs to. * @param Horde_Kolab_Server_Composite $composite The link to the server. */ public function __construct( Horde_Kolab_Server_Object $object, Horde_Kolab_Server_Composite $composite ) { parent::__construct($object, $composite, self::NAME); } }Horde_Kolab_Server-2.0.5/lib/Horde/Kolab/Server/Object/Attribute/Createtimestampdate.php0000664000175000017500000000216112653735542027311 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * The "createTimestamp" attribute converted to Horde_Date. * * Copyright 2008-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Object_Attribute_Createtimestampdate extends Horde_Kolab_Server_Object_Attribute_Createtimestamp { /** * Return the value of this attribute. * * @return mixed The value of this attribute. */ public function value() { return new Horde_Date(parent::value()); } }Horde_Kolab_Server-2.0.5/lib/Horde/Kolab/Server/Object/Attribute/Decorator.php0000664000175000017500000000523112653735542025247 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * A base class for attribute decorators. * * Copyright 2008-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Object_Attribute_Decorator implements Horde_Kolab_Server_Object_Attribute_Interface { /** * The decorated attribute. * * @param Horde_Kolab_Server_Object_Attribute */ protected $_attribute; /** * Constructor * * @param Horde_Kolab_Server_Object_Attribute $attribute The decorated * attribute. */ public function __construct( Horde_Kolab_Server_Object_Attribute_Interface $attribute ) { $this->_attribute = $attribute; } /** * Return the value of this attribute. * * @return array The value(s) of this attribute. */ public function value() { return $this->_attribute->value(); } /** * Return the new internal state for this attribute. * * @param array $changes The object data that should be updated. * * @return array The resulting internal state. * * @throws Horde_Kolab_Server_Exception If storing the value failed. */ public function update(array $changes) { return $this->_attribute->update($changes); } /** * Return the internal attribute adapter. * * @return Horde_Kolab_Server_Structure_Attribute_Interface The internal */ public function getAttribute() { return $this->_attribute->getAttribute(); } /** * Return the name of this attribute. * * @return string The name of this attribute. */ public function getName() { return $this->_attribute->getName(); } /** * Return if this attribute is undefined in the given data array. * * @param array $changes The data array to test. * * @return string The name of this object. */ public function isEmpty(array $changes) { return $this->_attribute->isEmpty($changes); } }Horde_Kolab_Server-2.0.5/lib/Horde/Kolab/Server/Object/Attribute/Default.php0000664000175000017500000000406012653735542024710 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * A decorator to represent an object attribute with a default. * * Copyright 2008-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Object_Attribute_Default extends Horde_Kolab_Server_Object_Attribute_Decorator { /** * The default value for the attribute. * * @param mixed */ private $_default; /** * Constructor * * @param Horde_Kolab_Server_Object_Attribute $attribute The decorated * attribute. * @param mixed $default The default value. */ public function __construct( Horde_Kolab_Server_Object_Attribute $attribute, $default ) { $this->_default = $default; parent::__construct($attribute); } /** * Return the new internal state for this attribute. * * @param array $changes The object data that should be updated. * * @return array The resulting internal state. * * @throws Horde_Kolab_Server_Exception If storing the value failed. */ public function update(array $changes) { if (!$this->_attribute->getObject()->exists() && !$this->_attribute->isEmpty($changes)) { $changes[$this->_attribute->getExternalName()] = $this->_default; } return $this->_attribute->changes($changes); } }Horde_Kolab_Server-2.0.5/lib/Horde/Kolab/Server/Object/Attribute/Empty.php0000664000175000017500000000206612653735542024426 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * The base class representing Kolab object attributes. * * Copyright 2008-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Object_Attribute_Empty extends Horde_Kolab_Server_Object_Attribute_Value { /** * Return the value of this attribute. * * @return mixed The value of this attribute. */ public function value() { return ''; } }Horde_Kolab_Server-2.0.5/lib/Horde/Kolab/Server/Object/Attribute/External.php0000664000175000017500000000304012653735542025103 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * The class represents external-only object attributes. * * Copyright 2008-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Object_Attribute_External extends Horde_Kolab_Server_Object_Attribute_Value { /** * Return the new internal state for this attribute. * * @param array $changes The object data that should be updated. * * @return array The resulting internal state. * * @throws Horde_Kolab_Server_Exception If storing the value failed. */ public function update(array $changes) { $changes = parent::update($changes); if (!empty($changes)) { throw new Horde_Kolab_Server_Exception( sprintf( "The value for \"%s\" may not be modified!", $this->_name ) ); } return $changes; } }Horde_Kolab_Server-2.0.5/lib/Horde/Kolab/Server/Object/Attribute/Field.php0000664000175000017500000001104412653735542024347 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * The base class representing Kolab object attributes. * * Copyright 2008-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ abstract class Horde_Kolab_Server_Object_Attribute_Field extends Horde_Kolab_Server_Object_Attribute_Base { /** * Quote field separators within a LDAP value. * * @param string $string The string that should be quoted. * * @return string The quoted string. */ protected function quote($string) { return str_replace(array('\\', '$',), array('\\5c', '\\24',), $string); } /** * Unquote a LDAP value. * * @param string $string The string that should be unquoted. * * @return string The unquoted string. */ protected function unquote($string) { return str_replace(array('\\5c', '\\24',), array('\\', '$',), $string); } /** * Get a derived attribute value by returning a given position in a * delimited string. * * @param string $basekey Name of the attribute that holds the * delimited string. * @param string $field The position of the field to retrieve. * @param string $separator The field separator. * @param int $max_count The maximal number of fields. * * @return mixed The value of the attribute. */ protected function getField($basekey, $field = 0, $separator = '$', $max_count = null) { $base = $this->_get($basekey); if (empty($base)) { return; } if (!empty($max_count)) { $fields = explode($separator, $base, $max_count); } else { $fields = explode($separator, $base); } return isset($fields[$field]) ? $this->unquote($fields[$field]) : null; } /** * Set a collapsed attribute value. * * @param string $key The attribute to collapse into. * @param array $attributes The attributes to collapse. * @param array $info The information currently working on. * @param string $separator Separate the fields using this character. * @param boolean $unset Unset the base values. * * @return NULL. */ protected function setField($key, $attributes, &$info, $separator = '$', $unset = true) { /** * Check how many empty entries we have at the end of the array. We * may omit these together with their field separators. */ krsort($attributes); $empty = true; $end = count($attributes); foreach ($attributes as $attribute) { /** * We do not expect the callee to always provide all attributes * required for a collapsed attribute. So it is necessary to check * for old values here. */ if (!isset($info[$attribute])) { $old = $this->get($attribute); if (!empty($old)) { $info[$attribute] = $old; } } if ($empty && empty($info[$attribute])) { $end--; } else { $empty = false; } } if ($empty) { return; } ksort($attributes); $unset = $attributes; $result = ''; for ($i = 0; $i < $end; $i++) { $akey = array_shift($attributes); $value = $info[$akey]; if (is_array($value)) { $value = $value[0]; } $result .= $this->quote($value); if ($i != ($end - 1)) { $result .= $separator; } } if ($unset === true) { foreach ($unset as $attribute) { unset($info[$attribute]); } } $info[$key] = $result; } }Horde_Kolab_Server-2.0.5/lib/Horde/Kolab/Server/Object/Attribute/Firstnamelastname.php0000664000175000017500000000320512653735542027001 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * The name of a person in "firstname lastname" format. * * Copyright 2008-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Object_Attribute_Firstnamelastname extends Horde_Kolab_Server_Object_Attribute_Value { /** * Constructor * * @param Horde_Kolab_Server_Structure_Attribute_Interface $object The object * this attribute belongs to. * @param string $name The name of this attribute. */ public function __construct( Horde_Kolab_Server_Structure_Attribute_Double $attribute, $name ) { parent::__construct($attribute, $name); } /** * Return the value of this attribute. * * @return array The value(s) of this attribute. * * @throws Horde_Kolab_Server_Exception If retrieval of the value failed. */ public function value() { $values = $this->attribute->value(); return sprintf('%s %s', $values['givenName'][0], $values['sn'][0]); } }Horde_Kolab_Server-2.0.5/lib/Horde/Kolab/Server/Object/Attribute/Guid.php0000664000175000017500000000273512653735542024223 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * The GUID attribute. * * Copyright 2008-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Object_Attribute_Guid extends Horde_Kolab_Server_Object_Attribute_External { /** * Constructor * * @param Horde_Kolab_Server_Object $object The object this attribute * belongs to. * @param Horde_Kolab_Server_Composite $composite The link to the server. */ public function __construct( Horde_Kolab_Server_Object $object, Horde_Kolab_Server_Composite $composite ) { parent::__construct($object, $composite, 'Guid'); } /** * Return the value of this attribute. * * @return array The value(s) of this attribute. */ public function value() { return $this->_object->getGuid(); } }Horde_Kolab_Server-2.0.5/lib/Horde/Kolab/Server/Object/Attribute/Id.php0000664000175000017500000000317712653735542023670 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * The id part of the GUID of this object. * * Copyright 2008-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Object_Attribute_Id extends Horde_Kolab_Server_Object_Attribute_External { /** * Constructor * * @param Horde_Kolab_Server_Object $object The object this attribute * belongs to. * @param Horde_Kolab_Server_Composite $composite The link to the server. */ public function __construct( Horde_Kolab_Server_Object $object, Horde_Kolab_Server_Composite $composite ) { parent::__construct($object, $composite, 'Id'); } /** * Return the value of this attribute. * * @return array The value(s) of this attribute. */ public function value() { $guid = $this->_object->getGuid(); $base = $this->_composite->server->getBaseUid(); return substr($guid, 0, strlen($guid) - strlen($base) - 1); } }Horde_Kolab_Server-2.0.5/lib/Horde/Kolab/Server/Object/Attribute/Interface.php0000664000175000017500000000371612653735542025233 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * The interface representing Kolab object attributes. * * Copyright 2008-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ interface Horde_Kolab_Server_Object_Attribute_Interface { /** * Return the value of this attribute. * * @return array The value(s) of this attribute. * * @throws Horde_Kolab_Server_Exception If retrieval of the value failed. */ public function value(); /** * Return the new internal state for this attribute. * * @param array $changes The object data that should be updated. * * @return array The resulting internal state. * * @throws Horde_Kolab_Server_Exception If storing the value failed. */ public function update(array $changes); /** * Return the internal attribute adapter. * * @return Horde_Kolab_Server_Structure_Attribute_Interface The internal */ public function getAttribute(); /** * Return the name of this attribute. * * @return string The name of this attribute. */ public function getName(); /** * Return if this attribute is undefined in the given data array. * * @param array $changes The data array to test. * * @return string The name of this object. */ public function isEmpty(array $changes); }Horde_Kolab_Server-2.0.5/lib/Horde/Kolab/Server/Object/Attribute/Internal.php0000664000175000017500000000233012653735542025076 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * The class represents internal-only object attributes. * * Copyright 2008-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Object_Attribute_Internal extends Horde_Kolab_Server_Object_Attribute_Value { /** * Return the value of this attribute. * * @return array The value(s) of this attribute. */ public function value() { throw new Horde_Kolab_Server_Exception( sprintf( "Attribute \"%s\" is not visible!", $this->_name ) ); } }Horde_Kolab_Server-2.0.5/lib/Horde/Kolab/Server/Object/Attribute/Locked.php0000664000175000017500000000353512653735542024533 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * A decorator to represent a Kolab object attribute that can only be written on * object creation and is immutable afterwards. * * Copyright 2008-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Object_Attribute_Locked extends Horde_Kolab_Server_Object_Attribute_Decorator { /** * Return the new internal state for this attribute. * * @param array $changes The object data that should be updated. * * @return array The resulting internal state. * * @throws Horde_Kolab_Server_Exception If storing the value failed. */ public function update(array $changes) { if ($this->_attribute->isEmpty($changes)) { return array(); } $changes = $this->_attribute->update($changes); if (!empty($changes) && $this->getObject()->exists()) { throw new Horde_Kolab_Server_Exception( sprintf( "The value for \"%s\" may not be modified on an existing object!", $this->_attribute->getName() ) ); } return $changes; } }Horde_Kolab_Server-2.0.5/lib/Horde/Kolab/Server/Object/Attribute/Modifytimestamp.php0000664000175000017500000000257712653735542026512 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * The "modifyTimestamp" attribute. * * Copyright 2008-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Object_Attribute_Modifytimestamp extends Horde_Kolab_Server_Object_Attribute_External { /** The attribute name */ const NAME = 'modifyTimestamp'; /** * Constructor * * @param Horde_Kolab_Server_Object $object The object this attribute * belongs to. * @param Horde_Kolab_Server_Composite $composite The link to the server. */ public function __construct( Horde_Kolab_Server_Object $object, Horde_Kolab_Server_Composite $composite ) { parent::__construct($object, $composite, self::NAME); } }Horde_Kolab_Server-2.0.5/lib/Horde/Kolab/Server/Object/Attribute/Modifytimestampdate.php0000664000175000017500000000216112653735542027335 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * The "modifyTimestamp" attribute converted to Horde_Date. * * Copyright 2008-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Object_Attribute_Modifytimestampdate extends Horde_Kolab_Server_Object_Attribute_Modifytimestamp { /** * Return the value of this attribute. * * @return mixed The value of this attribute. */ public function value() { return new Horde_Date(parent::value()); } }Horde_Kolab_Server-2.0.5/lib/Horde/Kolab/Server/Object/Attribute/Objectclass.php0000664000175000017500000000305012653735542025556 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * The "objectClass" attribute. * * Copyright 2008-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Object_Attribute_Objectclass extends Horde_Kolab_Server_Object_Attribute_Decorator { /** * Constructor * * @param Horde_Kolab_Server_Object $object The object this attribute * belongs to. * @param Horde_Kolab_Server_Composite $composite The link to the server. */ public function __construct( Horde_Kolab_Server_Object_Interface $object, Horde_Kolab_Server_Composite $composite ) { $this->_attribute = new Horde_Kolab_Server_Object_Attribute_Required( new Horde_Kolab_Server_Object_Attribute_Locked( new Horde_Kolab_Server_Object_Attribute_Value( $object, $composite, 'Objectclass' ) ) ); } }Horde_Kolab_Server-2.0.5/lib/Horde/Kolab/Server/Object/Attribute/Openldapaci.php0000664000175000017500000000246012653735542025545 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * The "OpenLDAPaci" attribute. * * Copyright 2008-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Object_Attribute_Openldapaci extends Horde_Kolab_Server_Object_Attribute_Value { /** * Constructor * * @param Horde_Kolab_Server_Object $object The object this attribute * belongs to. * @param Horde_Kolab_Server_Composite $composite The link to the server. */ public function __construct( Horde_Kolab_Server_Object $object, Horde_Kolab_Server_Composite $composite ) { parent::__construct($object, $composite, 'Openldapaci'); } }Horde_Kolab_Server-2.0.5/lib/Horde/Kolab/Server/Object/Attribute/Required.php0000664000175000017500000000317712653735542025114 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * A decorator to represent required Kolab object attributes. * * Copyright 2008-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Object_Attribute_Required extends Horde_Kolab_Server_Object_Attribute_Decorator { /** * Return the new internal state for this attribute. * * @param array $changes The object data that should be updated. * * @return array The resulting internal state. * * @throws Horde_Kolab_Server_Exception If storing the value failed. */ public function update(array $changes) { $changes = $this->_attribute->update($changes); if (empty($changes) && !$this->_attribute->getObject()->exists()) { throw new Horde_Kolab_Server_Exception( sprintf( "The value for \"%s\" is empty but required!", $this->_attribute->getExternalName() ) ); } return $changes; } }Horde_Kolab_Server-2.0.5/lib/Horde/Kolab/Server/Object/Attribute/Single.php0000664000175000017500000000254612653735542024554 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * A decorator to represent a Kolab object attribute that can only be written on * object creation and is immutable afterwards. * * Copyright 2008-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Object_Attribute_Single extends Horde_Kolab_Server_Object_Attribute_Decorator { /** * Return the value of this attribute. * * @return array The value(s) of this attribute. */ public function value() { $value = $this->_attribute->value(); if (is_array($value)) { return array_shift($value); } else { return $value; } } }Horde_Kolab_Server-2.0.5/lib/Horde/Kolab/Server/Object/Attribute/Value.php0000664000175000017500000000500512653735542024400 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * The base class representing Kolab object attributes. * * Copyright 2008-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Object_Attribute_Value extends Horde_Kolab_Server_Object_Attribute_Base { /** * Return the value of this attribute. * * @return array The value(s) of this attribute. * * @throws Horde_Kolab_Server_Exception If retrieval of the value failed. */ public function value() { $internal = $this->attribute->value(); if (isset($internal[$this->name])) { return $internal[$this->name]; } else { throw new Horde_Kolab_Server_Exception(sprintf('Missing value %s!', $this->name)); } } /** * Indicate that a value will be saved by deleting it from the original data * array. * * @param array &$changes The object data that should be changed. * * @return NULL */ public function consume(array &$changes) { if (isset($changes[$this->name])) { unset($changes[$this->name]); } } /** * Return the new internal state for this attribute. * * @param array $changes The object data that should be updated. * * @return array The resulting internal state. * * @throws Horde_Kolab_Server_Exception If storing the value failed. */ public function update(array $changes) { if (!$this->isEmpty($changes)) { $value = $changes[$this->name]; if (!is_array($value)) { $value = array($value); } return $this->attribute->update($value); } try { $old = $this->attribute->value(); return $this->attribute->update(array()); } catch (Horde_Kolab_Server_Exception_Novalue $e) { return array(); } } }Horde_Kolab_Server-2.0.5/lib/Horde/Kolab/Server/Object/Attribute/Writelock.php0000664000175000017500000000316612653735542025275 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * A decorator to represent a Kolab object attribute that can never be written. * * Copyright 2008-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Object_Attribute_Writelock extends Horde_Kolab_Server_Object_Attribute_Decorator { /** * Return the new internal state for this attribute. * * @param array $changes The object data that should be updated. * * @return array The resulting internal state. * * @throws Horde_Kolab_Server_Exception If storing the value failed. */ public function update(array $changes) { $changes = $this->_attribute->update($changes); if (!empty($changes)) { throw new Horde_Kolab_Server_Exception( sprintf( "The value for \"%s\" may not be modified!", $this->_attribute->getExternalName() ) ); } return $changes; } }Horde_Kolab_Server-2.0.5/lib/Horde/Kolab/Server/Object/Kolab/Address.php0000664000175000017500000000525212653735542024002 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * This class provides methods to deal with global address book * entries for Kolab. * * Copyright 2008-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Object_Kolab_Address extends Horde_Kolab_Server_Object_Kolabinetorgperson { /** * Attributes derived from the LDAP values. * * @var array */ public $derived_attributes = array( self::ATTRIBUTE_LNFN, self::ATTRIBUTE_FNLN, ); /** * The ldap classes for this type of object. * * @var array */ public static $object_classes = array( self::OBJECTCLASS_TOP, self::OBJECTCLASS_INETORGPERSON, self::OBJECTCLASS_KOLABINETORGPERSON, ); /** * Return the filter string to retrieve this object type. * * @return string The filter to retrieve this object type from the server * database. */ public static function getFilter() { $criteria = array('AND' => array( array('field' => self::ATTRIBUTE_SN, 'op' => 'any'), array('field' => self::ATTRIBUTE_OC, 'op' => '=', 'test' => self::OBJECTCLASS_INETORGPERSON), array('NOT' => array( array('field' => self::ATTRIBUTE_SID, 'op' => 'any'), ), ), ), ); return $criteria; } /** * Convert the object attributes to a hash. * * @param string $attrs The attributes to return. * * @return array|PEAR_Error The hash representing this object. */ public function toHash($attrs = null) { if (!isset($attrs)) { $attrs = array( self::ATTRIBUTE_LNFN, ); } return parent::toHash($attrs); } } Horde_Kolab_Server-2.0.5/lib/Horde/Kolab/Server/Object/Kolab/Administrator.php0000664000175000017500000000360712653735542025237 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * This class provides methods to deal with administrator * entries for Kolab. * * Copyright 2008-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Object_Kolab_Administrator extends Horde_Kolab_Server_Object_Kolab_Adminrole { /** * The group the UID must be member of so that this object really * matches this class type. This may not include the root UID. * * @var string */ /* public $required_group = array(self::ATTRIBUTE_CN => 'admin', */ /* Horde_Kolab_Server_Object_Kolabgroupofnames::ATTRIBUTE_VISIBILITY => false); */ /** * Returns the server url of the given type for this user. * * This method is used to encapsulate multidomain support. * * @param string $server_type The type of server URL that should be returned. * * @return string The server url or empty on error. */ public function getServer($server_type) { global $conf; switch ($server_type) { case 'homeserver': default: $server = $this->get(self::ATTRIBUTE_HOMESERVER); if (empty($server)) { $server = $_SERVER['SERVER_NAME']; } return $server; } } } Horde_Kolab_Server-2.0.5/lib/Horde/Kolab/Server/Object/Kolab/Adminrole.php0000664000175000017500000000710212653735542024323 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * This class provides methods to deal with administrator object types. * * Copyright 2008-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Object_Kolab_Adminrole extends Horde_Kolab_Server_Object_Kolabinetorgperson { public static $init_attributes = array( ); /** * The group the UID must be member of so that this object really * matches this class type. This may not include the root UID. * * @var string */ public $required_group; /** * Return the filter string to retrieve this object type. * * @return string The filter to retrieve this object type from the server * database. */ public static function getFilter() { if (isset($conf['kolab']['server']['params']['admin'][self::ATTRIBUTE_SID])) { $manager = $conf['kolab']['server']['params']['admin'][self::ATTRIBUTE_SID]; } else { $manager = 'manager'; } $criteria = array('AND' => array( array('field' => self::ATTRIBUTE_CN, 'op' => 'any'), array('field' => self::ATTRIBUTE_SN, 'op' => 'any'), array('field' => self::ATTRIBUTE_OC, 'op' => '=', 'test' => self::OBJECTCLASS_INETORGPERSON), array('NOT' => array( array('field' => self::ATTRIBUTE_SID, 'op' => '=', 'test' => $manager), ), ), ), ); return $criteria; } /** * Saves object information. * * @param array $info The information about the object. * * @return boolean|PEAR_Error True on success. */ public function save(array $info) { $admin_group = new Horde_Kolab_Server_Object_Kolabgroupofnames($this->server, null, $this->required_group); $save_result = parent::save($info); if (!$admin_group->exists()) { $data = array_merge($this->required_group, array(Horde_Kolab_Server_Object_Kolabgroupofnames::ATTRIBUTE_MEMBER => array($this->uid))); } else { $result = $admin_group->isMember($this->uid); if ($result === false) { $members = $admin_group->getMembers(); $members[] = $this->uid; $data = array(Horde_Kolab_Server_Object_Kolabgroupofnames::ATTRIBUTE_MEMBER => $members); } else { $data = null; } } if (!empty($data)) { return $admin_group->save($data); } return $save_result; } } Horde_Kolab_Server-2.0.5/lib/Horde/Kolab/Server/Object/Kolab/Distlist.php0000664000175000017500000000307412653735542024214 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * This class provides methods to deal with distribution lists for Kolab. * * Copyright 2008-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Object_Kolab_Distlist extends Horde_Kolab_Server_Object_Kolabgroupofnames { /** * Return the filter string to retrieve this object type. * * @return string The filter to retrieve this object type from the server * database. */ public static function getFilter() { $criteria = array('AND' => array( array('field' => self::ATTRIBUTE_MAIL, 'op' => 'any'), array('field' => self::ATTRIBUTE_OC, 'op' => '=', 'test' => self::OBJECTCLASS_KOLABGROUPOFNAMES), ), ); return $criteria; } }; Horde_Kolab_Server-2.0.5/lib/Horde/Kolab/Server/Object/Kolab/Domainmaintainer.php0000664000175000017500000000716612653735542025702 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * This class provides methods associated to Kolab domain maintainers. * * Copyright 2008-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Object_Kolab_Domainmaintainer extends Horde_Kolab_Server_Object_Kolab_Adminrole { const ATTRIBUTE_DOMAIN = 'domain'; /** * A structure to initialize the attribute structure for this class. * * @var array */ public static $init_attributes = array( 'defined' => array( self::ATTRIBUTE_DOMAIN, ), ); /** * The group the UID must be member of so that this object really * matches this class type. This may not include the root UID. * * @var array */ public $required_group = array(self::ATTRIBUTE_CN => 'domain-maintainer', Horde_Kolab_Server_Object_Kolabgroupofnames::ATTRIBUTE_VISIBILITY => false); /** * Convert the object attributes to a hash. * * @param string $attrs The attributes to return. * * @return array|PEAR_Error The hash representing this object. */ public function toHash($attrs = null) { if (!isset($attrs)) { $attrs = array( self::ATTRIBUTE_SID, self::ATTRIBUTE_LNFN, self::ATTRIBUTE_DOMAIN, ); } return parent::toHash($attrs); } /** * Distill the server side object information to save. * * @param array $info The information about the object. * * @return NULL. * * @throws Horde_Kolab_Server_Exception If the given information contains errors. */ public function prepareObjectInformation(array &$info) { foreach ($info[self::ATTRIBUTE_DOMAIN] as $domain) { $domain_uid = sprintf('cn=%s,cn=domain,cn=internal,%s', $domain, $this->server->getBaseUid()); //@todo: This should be made easier by the group object $domain_group = $this->server->fetch($domain_uid, 'Horde_Kolab_Server_Object_Kolabgroupofnames'); if ($domain_group instanceof PEAR_Error) { return $domain_group; } if (!$domain_group->exists()) { $members = array($this->uid); $domain_group->save(array(self::ATTRIBUTE_CN => $domain, Horde_Kolab_Server_Object_Kolabgroupofnames::ATTRIBUTE_MEMBER => $members)); } else { $result = $domain_group->isMember($this->uid); if ($result instanceof PEAR_Error) { return $result; } if ($result === false) { $members = $domain_group->getMembers(); $members[] = $this->uid; $domain_group->save(array(Horde_Kolab_Server_Object_Kolabgroupofnames::ATTRIBUTE_MEMBER => $members)); } } } parent::prepareObjectInformation($info); } } Horde_Kolab_Server-2.0.5/lib/Horde/Kolab/Server/Object/Kolab/Maintainer.php0000664000175000017500000000235112653735542024501 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * This class provides methods to deal with maintainer * entries for Kolab. * * Copyright 2008-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Object_Kolab_Maintainer extends Horde_Kolab_Server_Object_Kolab_Adminrole { /** * The group the UID must be member of so that this object really * matches this class type. This may not include the root UID. * * @var array */ public $required_group = array(self::ATTRIBUTE_CN => 'maintainer', Horde_Kolab_Server_Object_Kolabgroupofnames::ATTRIBUTE_VISIBILITY => false); } Horde_Kolab_Server-2.0.5/lib/Horde/Kolab/Server/Object/Kolab/User.php0000664000175000017500000001156212653735542023334 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * This class provides methods to deal with Kolab users stored in * the Kolab db. * * Copyright 2008-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Object_Kolab_User extends Horde_Kolab_Server_Object_Kolabinetorgperson { /** Define attributes specific to this object type */ /** The user type */ const ATTRIBUTE_USERTYPE = 'usertype'; /** The first name */ const ATTRIBUTE_FN = 'fn'; /** Define the possible Kolab user types */ const USERTYPE_STANDARD = 0; const USERTYPE_INTERNAL = 1; const USERTYPE_GROUP = 2; const USERTYPE_RESOURCE = 3; /** * A structure to initialize the attribute structure for this class. * * @var array */ /* public static $init_attributes = array( */ /* 'derived' => array( */ /* self::ATTRIBUTE_USERTYPE => array(), */ /* self::ATTRIBUTE_FN => array(), */ /* ), */ /* 'required' => array( */ /* self::ATTRIBUTE_USERPASSWORD, */ /* ), */ /* ); */ /** * Return the filter string to retrieve this object type. * * @return string The filter to retrieve this object type from the server * database. */ public static function getFilter() { $criteria = array('AND' => array( array('field' => self::ATTRIBUTE_SN, 'op' => 'any'), array('field' => self::ATTRIBUTE_MAIL, 'op' => 'any'), array('field' => self::ATTRIBUTE_SID, 'op' => 'any'), array('field' => self::ATTRIBUTE_OC, 'op' => '=', 'test' => self::OBJECTCLASS_KOLABINETORGPERSON), ), ); return $criteria; } /** * Derive an attribute value. * * @param string $attr The attribute to derive. * * @return mixed The value of the attribute. */ protected function derive($attr) { switch ($attr) { case self::ATTRIBUTE_USERTYPE: if (strpos($this->_uid, 'cn=internal')) { return self::USERTYPE_INTERNAL; } else if (strpos($this->_uid, 'cn=group')) { return self::USERTYPE_GROUP; } else if (strpos($this->_uid, 'cn=resource')) { return self::USERTYPE_RESOURCE; } else { return self::USERTYPE_STANDARD; } case self::ATTRIBUTE_FN: return $this->getFn(); default: return parent::derive($attr); } } /** * Convert the object attributes to a hash. * * @param string $attrs The attributes to return. * * @return array|PEAR_Error The hash representing this object. */ public function toHash($attrs = null) { if (!isset($attrs)) { $attrs = array( self::ATTRIBUTE_SID, self::ATTRIBUTE_FN, self::ATTRIBUTE_MAIL, self::ATTRIBUTE_USERTYPE, ); } return parent::toHash($attrs); } /** * Get the "first name" attribute of this object * * @todo: This should get refactored to be combined with the Id value. * * @return string the "first name" of this object */ protected function getFn() { $sn = $this->_get(self::ATTRIBUTE_SN, true); $cn = $this->_get(self::ATTRIBUTE_CN, true); return trim(substr($cn, 0, strlen($cn) - strlen($sn))); } /** * Get the groups for this object * * @return mixed|PEAR_Error An array of group ids, false if no groups were * found. */ public function getGroups() { return $this->server->getGroups($this->uid); } /** * Get the group mail addresses for this object * * @return mixed|PEAR_Error An array of group addresses, false if no groups were * found. */ function getGroupAddresses() { return $this->server->getGroupAddresses($this->uid); } }; Horde_Kolab_Server-2.0.5/lib/Horde/Kolab/Server/Object/Base.php0000664000175000017500000001503412653735542022236 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * This class provides methods to deal with Kolab objects stored in * the Kolab db. * * Copyright 2008-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ abstract class Horde_Kolab_Server_Object_Base implements Horde_Kolab_Server_Object_Interface { /** * Link to the Kolab server. * * @var Horde_Kolab_Server_Composite */ private $_composite; /** * GUID of this object on the Kolab server. * * @var string */ protected $guid; /** * Initialize the Kolab Object. Provide either the GUID * * @param Horde_Kolab_Server_Composite $composite The link to the Kolab server. * @param string $guid GUID of the object. */ public function __construct( Horde_Kolab_Server_Composite $composite, $guid = null ) { $this->_composite = $composite; $this->guid = $guid; } /** * Get the GUID of this object * * @return string the GUID of this object */ public function getGuid() { if ($this->guid === null) { throw new Horde_Kolab_Server_Exception( 'Uninitialized object is missing GUID!' ); } return $this->guid; } /** * Get the external attributes supported by this object. * * @return array The external attributes supported by this object. This is a * list of abbreviated attribute class names. */ public function getExternalAttributes() { return $this->_composite->structure->getExternalAttributes($this); } /** * Get the internal attributes supported by this object. * * @return array The internal attributes supported by this object. */ public function getInternalAttributes() { return $this->_composite->structure->getInternalAttributes($this); } /** * Does the object exist? * * @return boolean True if the object exists, false otherwise. */ public function exists() { try { $this->readInternal(); return true; } catch (Horde_Kolab_Server_Exception $e) { return false; } } /** * Read the object data. * * @return array The read data. */ public function readInternal() { return $this->_composite->server->readAttributes( $this->getGuid(), $this->getInternalAttributes() ); } /** * Get the specified internal attributes. * * @param array $attributes The internal attribute. * * @return array The value(s) of these attribute */ public function getInternal(array $attributes) { $result = $this->readInternal(); $values = array(); foreach ($attributes as $attribute) { if (!isset($result[$attribute])) { throw new Horde_Kolab_Server_Exception_Novalue( sprintf( "No value for attribute \"%s\"!", $attribute ) ); } $values[$attribute] = $result[$attribute]; } return $values; } /** * Get the specified attribute of this object. * * @param string $attr The attribute to read. * * @return mixed The value of this attribute. */ public function getExternal($attr) { if (!in_array($attr, $this->getExternalAttributes())) { throw new Horde_Kolab_Server_Exception( sprintf("Attribute \"%s\" not supported!", $attr) ); } $attribute = $this->_composite->structure->getExternalAttribute( $attr, $this ); return $attribute->value(); } /** * Saves object information. This may either create a new entry or modify an * existing entry. * * Please note that fields with multiple allowed values require the callee * to provide the full set of values for the field. Any old values that are * not resubmitted will be considered to be deleted. * * @param array $info The information about the object. * * @return NULL * * @throws Horde_Kolab_Server_Exception If saving the data failed. */ public function save(array $info) { /** Handle all class specific transformations of the provided data */ $this->prepareObjectInformation($info); $internal = $this->getNewInternal($info); $guid = $this->_composite->structure->generateServerGuid( get_class($this), $this->generateId($internal), $internal ); if ($this->exists()) { if ($guid != $this->guid) { $this->_composite->server->rename($this->guid, $guid); $this->guid = $guid; } $result = $this->_composite->server->save($this, $internal); } else { $this->guid = $guid; $this->_composite->server->add($this, $internal); } } /** * Transform the given data array into the new internal dataset. * * @param array $info The information about the object. * * @return NULL * * @throws Horde_Kolab_Server_Exception If transforming the data failed. */ protected function getNewInternal($info) { $internal = array(); foreach ($info as $external => $value) { $attribute = $this->_composite->structure->getExternalAttribute( $external, $this ); $internal = array_merge($internal, $attribute->update($info)); } return $internal; } /** * Delete this object. * * @return NULL * * @throws Horde_Kolab_Server_Exception If deleting the object failed. */ public function delete() { $this->_composite->server->delete($this->getGuid()); } } Horde_Kolab_Server-2.0.5/lib/Horde/Kolab/Server/Object/Factory.php0000664000175000017500000000451612653735542022776 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * Factory methods for Horde_Kolab_Server_Object instances. * * Copyright 2008-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Object_Factory { /** * Attempts to return a concrete Horde_Kolab_Server_Object instance based on * $type. * * @param mixed $type The type of the Horde_Kolab_Server_Object subclass * to return. * @param string $uid UID of the object * @param array $storage A link to the Kolab_Server class handling read/write. * @param array $data A possible array of data for the object * * @return Horde_Kolab_Server_Object|PEAR_Error The newly created concrete * Horde_Kolab_Server_Object instance. */ public static function factory( $type, $uid, Horde_Kolab_Server_Composite $storage, $data = null ) { if (class_exists($type)) { $object = new $type($storage, $uid, $data); } else { throw new Horde_Kolab_Server_Exception('Class definition of ' . $type . ' not found.'); } $object = new Horde_Kolab_Server_Object_Hash($object); return $object; } /** * Attempts to load the concrete Horde_Kolab_Server_Object class based on * $type. * * @param mixed $type The type of the Horde_Kolab_Server_Object subclass. * * @static * * @return true|PEAR_Error True if successfull. */ public static function loadClass($type) { if (!class_exists($type)) { throw new Horde_Kolab_Server_Exception('Class definition of ' . $type . ' not found.'); } } } Horde_Kolab_Server-2.0.5/lib/Horde/Kolab/Server/Object/Groupofnames.php0000664000175000017500000001103412653735542024025 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * This class provides methods to deal with groups. * * Copyright 2008-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Object_Groupofnames extends Horde_Kolab_Server_Object_Top { /** The specific object class of this object type */ const OBJECTCLASS_GROUPOFNAMES = 'groupOfNames'; /** Define attributes specific to this object type */ /** The common name */ const ATTRIBUTE_CN = 'cn'; /** The members of this group */ const ATTRIBUTE_MEMBER = 'member'; /** * A structure to initialize the attribute structure for this class. * * @var array */ public static $init_attributes = array( 'required' => array( self::ATTRIBUTE_CN, self::ATTRIBUTE_MEMBER, ), 'defined' => array( self::ATTRIBUTE_CN, self::ATTRIBUTE_MEMBER, ), 'object_classes' => array( self::OBJECTCLASS_GROUPOFNAMES, ), ); /** * Return the filter string to retrieve this object type. * * @static * * @return string The filter to retrieve this object type from the server * database. */ public static function getFilter() { return '(' . self::ATTRIBUTE_OC . '=' . self::OBJECTCLASS_GROUPOFNAMES . ')'; } /** * Generates an ID for the given information. * * @param array &$info The data of the object. * * @static * * @return string|PEAR_Error The ID. */ public function generateId(array &$info) { $id = $info[self::ATTRIBUTE_CN]; if (is_array($id)) { $id = $id[0]; } return trim(self::ATTRIBUTE_CN . '=' . $id, " \t\n\r\0\x0B,"); } /** * Retrieve the member list for this group. * * @return array|PEAR_Error The list of members in this group. */ public function getMembers() { return $this->get(self::ATTRIBUTE_MEMBER, false); } /** * Add a member to this group. * * @param string $member The UID of the member to add. * * @return array|PEAR_Error True if successful. */ public function addMember($member) { if (!in_array($member, $this->getMembers())) { $this->_cache[self::ATTRIBUTE_MEMBER][] = $member; } else { throw new Horde_Kolab_Server_Exception("The UID %s is already a member of the group %s!", $member, $this->_uid); } return $this->save($this->_cache); } /** * Delete a member from this group. * * @param string $member The UID of the member to delete. * * @return array|PEAR_Error True if successful. */ public function deleteMember($member) { $members = $this->getMembers(); if (in_array($member, $members)) { //@todo: As the member attribute is required we may not remove the last member $this->_cache[self::ATTRIBUTE_MEMBER] = array_diff($this->_cache[self::ATTRIBUTE_MEMBER], array($member)); } else { throw new Horde_Kolab_Server_Exception("The UID %s is no member of the group %s!", $member, $this->_uid); } return $this->save($this->_cache); } /** * Is the specified UID member of this group? * * @param string $member The UID of the member to check. * * @return boolean|PEAR_Error True if the UID is a member of the group, * false otherwise. */ public function isMember($member) { $members = $this->getMembers(); if (!is_array($members)) { return $member == $members; } if (!in_array($member, $members)) { return false; } else { return true; } } } Horde_Kolab_Server-2.0.5/lib/Horde/Kolab/Server/Object/Hash.php0000664000175000017500000001377312653735542022257 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * Provides array access to Kolab objects. * * Copyright 2008-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Object_Hash implements Horde_Kolab_Server_Object_Interface //@todo: Implement ArrayAccess { /** * Link to the decorated object. * * @var Horde_Kolab_Server_Object */ private $_object; /** * Initialize the Kolab Object. Provide either the GUID * * @param Horde_Kolab_Server_Object $object The represented object. */ public function __construct( Horde_Kolab_Server_Object_Interface $object ) { $this->_object = $object; } /** * Get the GUID of this object * * @return string the GUID of this object */ public function getGuid() { return $this->_object->getGuid(); } /** * Get the external attributes supported by this object. * * @return array The external attributes supported by this object. This is * an association of attribute names and attribute handler class names. */ public function getExternalAttributes() { return $this->_object->getExternalAttributes(); } /** * Get the internal attributes supported by this object. * * @return array The internal attributes supported by this object. */ public function getInternalAttributes() { return $this->_object->getInternalAttributes(); } /** * Does the object exist? * * @return NULL */ public function exists() { return $this->_object->exists(); } /** * Read the object into the cache * * @return array The read data. */ public function readInternal() { return $this->_object->readInternal(); } /** * Get the specified internal attributes. * * @param array $attributes The internal attribute. * * @return array The value(s) of these attribute */ public function getInternal(array $attributes) { return $this->_object->getInternal($attributes); } /** * Get the specified attribute of this object. * * @param string $attr The attribute to read. * * @return mixed The value of this attribute. */ public function getExternal($attr) { return $this->_object->getExternal($attr); } /** * Get the specified attribute of this object and ensure that only a single * value is being returned. * * @param string $attr The attribute to read. * * @return mixed The value of this attribute. */ public function getSingle($attr) { $value = $this->getExternal($attr); //@todo: Check if that can actually be something other than an array. if (is_array($value)) { return array_shift($value); } else { return $value; } } /** * Convert the object attributes to a hash. * * @param array $attrs The attributes to return. * @param boolean $single Should only a single attribute be returned? * * @return array|PEAR_Error The hash representing this object. */ public function toHash(array $attrs = array(), $single = true) { $result = array(); /** * Return all supported attributes if no specific attributes were * requested. */ if (empty($attrs)) { $attrs = array_keys($this->attributes); } foreach ($attrs as $key) { if ($single) { $result[$key] = $this->getSingle($key); } else { $result[$key] = $this->getExternal($key); } } return $result; } /** * Saves object information. This may either create a new entry or modify an * existing entry. * * Please note that fields with multiple allowed values require the callee * to provide the full set of values for the field. Any old values that are * not resubmitted will be considered to be deleted. * * @param array $info The information about the object. * * @return NULL * * @throws Horde_Kolab_Server_Exception If saving the data failed. */ public function save(array $info) { $this->_object->save($info); } /** * Delete this object. * * @return NULL * * @throws Horde_Kolab_Server_Exception If deleting the object failed. */ public function delete() { $this->_object->delete(); } /** * Generates an ID for the given information. * * @param array &$info The data of the object. * * @return string The ID. */ public function generateId(array &$info) { $this->_object->generateId($info); } /** * Distill the server side object information to save. * * @param array &$info The information about the object. * * @return NULL. * * @throws Horde_Kolab_Server_Exception If the given information contains errors. */ public function prepareObjectInformation(array &$info) { $this->_object->prepareObjectInformation($info); } /** * Returns the set of actions supported by this object type. * * @return array An array of supported actions. */ public function getActions() { $this->_object->getActions(); } } Horde_Kolab_Server-2.0.5/lib/Horde/Kolab/Server/Object/Inetorgperson.php0000664000175000017500000003331012653735542024217 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * This class provides basic methods common to all Kolab server objects. * * Copyright 2008-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Object_Inetorgperson extends Horde_Kolab_Server_Object_Organizationalperson { /** The specific object class of this object type */ const OBJECTCLASS_INETORGPERSON = 'inetOrgPerson'; /** * The attributes defined for this class. * * @var array */ public static $attributes = array( 'uid', 'mail','Firstnamelastname', /* 'Organization', 'Businesscategory', 'Homephone', 'Mobile', */ /* 'Photo', 'Jpegphoto', 'Givenname', 'Middlenames', */ /* 'Homepostaladdress', 'Labeleduri', 'Lastnamefirstname', */ /* 'Usersmimecertificate' */ ); /** * A structure to initialize the attribute structure for this class. * * @var array */ /* public static $init_attributes = array( */ /* 'defined' => array( */ /* self::ATTRIBUTE_SID, */ /* self::ATTRIBUTE_GIVENNAME, */ /* self::ATTRIBUTE_LABELEDURI, */ /* self::ATTRIBUTE_HOMEPOSTALADDRESS, */ /* self::ATTRIBUTE_ORGANIZATION, */ /* self::ATTRIBUTE_BUSINESSCATEGORY, */ /* self::ATTRIBUTE_HOMEPHONE, */ /* self::ATTRIBUTE_MOBILE, */ /* self::ATTRIBUTE_PHOTO, */ /* self::ATTRIBUTE_JPEGPHOTO, */ /* self::ATTRIBUTE_SMIMECERTIFICATE, */ /* ), */ /* 'derived' => array( */ /* self::ATTRARRAY_HOMEPOSTALADDRESS => array( */ /* 'base' => array( */ /* self::ATTRIBUTE_HOMEPOSTALADDRESS, */ /* self::ATTRIBUTE_GIVENNAME, */ /* self::ATTRIBUTE_SN */ /* ), */ /* 'method' => 'getHomePostalAddressHash', */ /* ), */ /* self::ATTRARRAY_LABELEDURI => array( */ /* 'base' => array( */ /* self::ATTRIBUTE_LABELEDURI, */ /* ), */ /* 'method' => 'getLabeledUriHash', */ /* ), */ /* self::ATTRIBUTE_GIVENNAME => array( */ /* 'base' => array( */ /* self::ATTRIBUTE_GIVENNAME, */ /* ), */ /* 'method' => 'getField', */ /* 'args' => array( */ /* self::ATTRIBUTE_GIVENNAME, */ /* 0, */ /* ' ' */ /* ), */ /* ), */ /* self::ATTRIBUTE_MIDDLENAMES => array( */ /* 'base' => array( */ /* self::ATTRIBUTE_GIVENNAME, */ /* ), */ /* 'method' => 'getField', */ /* 'args' => array( */ /* self::ATTRIBUTE_GIVENNAME, */ /* 1, */ /* ' ', */ /* 2 */ /* ), */ /* ), */ /* self::ATTRIBUTE_FNLN => array( */ /* 'base' => array( */ /* self::ATTRIBUTE_GIVENNAME, */ /* self::ATTRIBUTE_SN */ /* ), */ /* 'method' => 'getFnLn', */ /* ), */ /* self::ATTRIBUTE_LNFN => array( */ /* 'base' => array( */ /* self::ATTRIBUTE_GIVENNAME, */ /* self::ATTRIBUTE_SN */ /* ), */ /* 'method' => 'getLnFn', */ /* ), */ /* ), */ /* 'collapsed' => array( */ /* self::ATTRIBUTE_GIVENNAME => array( */ /* 'base' => array( */ /* self::ATTRIBUTE_GIVENNAME, */ /* self::ATTRIBUTE_MIDDLENAMES, */ /* ), */ /* 'method' => 'setField', */ /* 'args' => array( */ /* ' ', */ /* ), */ /* ), */ /* self::ATTRIBUTE_LABELEDURI => array( */ /* 'base' => array( */ /* self::ATTRARRAY_LABELEDURI, */ /* ), */ /* 'method' => 'setLabeledUriHash', */ /* ), */ /* self::ATTRIBUTE_HOMEPOSTALADDRESS => array( */ /* 'base' => array( */ /* self::ATTRARRAY_HOMEPOSTALADDRESS, */ /* ), */ /* 'method' => 'setHomePostalAddressHash', */ /* ), */ /* ), */ /* 'locked' => array( */ /* self::ATTRIBUTE_MAIL, */ /* ), */ /* 'object_classes' => array( */ /* self::OBJECTCLASS_INETORGPERSON, */ /* ), */ /* ); */ /** * Return the filter string to retrieve this object type. * * @static * * @return string The filter to retrieve this object type from the server * database. */ public static function getFilter() { $criteria = array('AND' => array(array('field' => self::ATTRIBUTE_OC, 'op' => '=', 'test' => self::OBJECTCLASS_INETORGPERSON), ), ); return $criteria; } /** * Get the name of this Object as "Firstname Lastname". * * @return string The name. */ protected function getFnLn() { $gn = $this->get(self::ATTRIBUTE_GIVENNAME, true); $sn = $this->get(self::ATTRIBUTE_SN, true); return sprintf('%s %s', $gn, $sn); } /** * Get the name of this Object as "Lastname, Firstname". * * @return string The name. */ protected function getLnFn() { $gn = $this->get(self::ATTRIBUTE_GIVENNAME, true); $sn = $this->get(self::ATTRIBUTE_SN, true); return sprintf('%s, %s', $sn, $gn); } /** * Return a hash of URIs. The keys of the hash are the labels. * * @return array The URIs. */ protected function getLabeledUriHash() { $result = array(); $uris = $this->get(self::ATTRIBUTE_LABELEDURI, false); if (empty($uris)) { return array(); } if (!is_array($uris)) { $uris = array($uris); } foreach ($uris as $uri) { list($address, $label) = explode(' ', $uri, 2); if (!isset($result[$label])) { $result[$label] = array($address); } else { $result[$label][] = $address; } } return $result; } /** * Store a hash of URIs. The keys of the hash are the labels. * * @param string $key The attribute to collapse into. * @param array $attributes The attributes to collapse. * @param array &$info The information currently working on. * * @return NULL */ protected function setLabeledUriHash($key, $attributes, &$info) { $result = array(); $uris = $info[self::ATTRARRAY_LABELEDURI]; foreach ($uris as $label => $addresses) { if (!is_array($addresses)) { $addresses = array($addresses); } foreach ($addresses as $address) { $result[] = $address . ' ' . $label; } } $info[self::ATTRIBUTE_LABELEDURI] = $result; unset($info[self::ATTRARRAY_LABELEDURI]); } /** * Get home postal addresses as an array. * * @return array The home addressses. */ protected function getHomePostalAddressHash() { $result = array(); $addresses = $this->get(self::ATTRIBUTE_HOMEPOSTALADDRESS); if (empty($addresses)) { return $addresses; } if (!is_array($addresses)) { $addresses = array($addresses); } foreach ($addresses as $address) { list($name_segment, $street_segment, $postal_address, $postal_code, $city) = sscanf('%s$%s$%s$%s %s', $address); if ($name_segment == "Post office box") { $result[] = array( self::ATTRIBUTE_POSTOFFICEBOX => $street_segment, self::ATTRIBUTE_POSTALADDRESS => $postal_address, self::ATTRIBUTE_POSTALCODE => $postal_code, self::ATTRIBUTE_CITY => $city ); } else { $result[] = array( self::ATTRIBUTE_STREET => $street_segment, self::ATTRIBUTE_POSTALADDRESS => $postal_address, self::ATTRIBUTE_POSTALCODE => $postal_code, self::ATTRIBUTE_CITY => $city ); } } return $result; } /** * Store home postal addresses provided as array. * * @param string $key The attribute to collapse into. * @param array $attributes The attributes to collapse. * @param array &$info The information currently working on. * * @return NULL */ protected function setHomePostalAddressHash($key, $attributes, &$info) { $result = array(); $db_postal_data = array(); $db_elements = array(self::ATTRIBUTE_GIVENNAME, self::ATTRIBUTE_SN); foreach ($db_elements as $attribute) { if (!empty($info[$attribute])) { if (is_array($info[$attribute])) { $new = $info[$attribute][0]; } else { $new = $info[$attribute]; } $db_postal_data[$attribute] = $this->quote($new); } else { $old = $this->_get($attribute, true); if (!empty($old)) { $db_postal_data[$attribute] = $this->quote($old); } else { $db_postal_data[$attribute] = ''; } } } $elements = array(self::ATTRIBUTE_STREET, self::ATTRIBUTE_POSTOFFICEBOX, self::ATTRIBUTE_POSTALADDRESS, self::ATTRIBUTE_POSTALCODE, self::ATTRIBUTE_CITY); if (!empty($info[self::ATTRARRAY_HOMEPOSTALADDRESS])) { $addresses = $info[self::ATTRARRAY_HOMEPOSTALADDRESS]; } else { $addresses = $this->get(self::ATTRARRAY_HOMEPOSTALADDRESS); } foreach ($addresses as $address) { $postal_data = array(); foreach ($elements as $element) { if (isset($address[$element])) { $postal_data[$element] = $this->quote($address[$element]); } else { $postal_data[$element] = ''; } } if (!empty($postal_data[self::ATTRIBUTE_STREET])) { $postal_data['street_segment'] = $postal_data[self::ATTRIBUTE_STREET]; $postal_data['name_segment'] = $db_postal_data[self::ATTRIBUTE_GIVENNAME] . ' ' . $db_postal_data[self::ATTRIBUTE_SN]; } else { $postal_data['street_segment'] = $postal_data[self::ATTRIBUTE_POSTOFFICEBOX]; $postal_data['name_segment'] = "Post office box"; } $result[] = sprintf('%s$%s$%s$%s %s', $postal_data['name_segment'], $postal_data['street_segment'], $postal_data[self::ATTRIBUTE_POSTALADDRESS], $postal_data[self::ATTRIBUTE_POSTALCODE], $postal_data[self::ATTRIBUTE_CITY]); } $info[self::ATTRIBUTE_HOMEPOSTALADDRESS] = $result; unset($info[self::ATTRARRAY_HOMEPOSTALADDRESS]); } /** * Generates an ID for the given information. * * @param array $info The data of the object. * * @static * * @return string|PEAR_Error The ID. */ public function generateId(array &$info) { if ($this->exists()) { if (!isset($info[self::ATTRIBUTE_GIVENNAME]) && !isset($info[self::ATTRIBUTE_SN])) { return false; } if (!isset($info[self::ATTRIBUTE_GIVENNAME])) { $info[self::ATTRIBUTE_GIVENNAME] = $this->get(self::ATTRIBUTE_GIVENNAME); } if (!isset($info[self::ATTRIBUTE_SN])) { $info[self::ATTRIBUTE_SN] = $this->get(self::ATTRIBUTE_SN); } } $id_mapfields = array(self::ATTRIBUTE_GIVENNAME, self::ATTRIBUTE_SN); $id_format = self::ATTRIBUTE_CN . '=' . '%s %s'; $fieldarray = array(); foreach ($id_mapfields as $mapfield) { if (isset($info[$mapfield])) { $id = $info[$mapfield]; if (is_array($id)) { $id = $id[0]; } $fieldarray[] = $this->server->structure->quoteForUid($id); } else { $fieldarray[] = ''; } } return trim(vsprintf($id_format, $fieldarray), " \t\n\r\0\x0B,"); } }Horde_Kolab_Server-2.0.5/lib/Horde/Kolab/Server/Object/Interface.php0000664000175000017500000000712112653735542023262 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * Interface describing Kolab objects stored in the server database. * * Copyright 2008-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ interface Horde_Kolab_Server_Object_Interface { /** * Get the GUID of this object * * @return string the GUID of this object */ public function getGuid(); /** * Get the external attributes supported by this object. * * @return array The external attributes supported by this object. This is a * list of abbreviated attribute class names. */ public function getExternalAttributes(); /** * Get the internal attributes supported by this object. * * @return array The internal attributes supported by this object. */ public function getInternalAttributes(); /** * Does the object exist? * * @return boolean True if the object exists, false otherwise. */ public function exists(); /** * Read the object into the cache * * @return array The read data. */ public function readInternal(); /** * Get the specified internal attributes. * * @param array $attributes The internal attribute. * * @return array The value(s) of these attribute */ public function getInternal(array $attributes); /** * Get the specified attribute of this object. * * @param string $attr The attribute to read. * * @return mixed The value of this attribute. */ public function getExternal($attr); /** * Saves object information. This may either create a new entry or modify an * existing entry. * * Please note that fields with multiple allowed values require the callee * to provide the full set of values for the field. Any old values that are * not resubmitted will be considered to be deleted. * * @param array $info The information about the object. * * @return NULL * * @throws Horde_Kolab_Server_Exception If saving the data failed. */ public function save(array $info); /** * Delete this object. * * @return NULL * * @throws Horde_Kolab_Server_Exception If deleting the object failed. */ public function delete(); /** * Generates an ID for the given information. * * @param array &$info The data of the object. * * @return string The ID. */ public function generateId(array &$info); /** * Distill the server side object information to save. * * @param array &$info The information about the object. * * @return NULL. * * @throws Horde_Kolab_Server_Exception If the given information contains errors. */ public function prepareObjectInformation(array &$info); /** * Returns the set of actions supported by this object type. * * @return array An array of supported actions. */ public function getActions(); } Horde_Kolab_Server-2.0.5/lib/Horde/Kolab/Server/Object/Kolab.php0000664000175000017500000000520212653735542022410 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * This class provides methods to deal with the Kolab server configuration * object. * * Copyright 2008-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Object_Kolab extends Horde_Kolab_Server_Object_Groupofnames { /** Define attributes specific to this object type */ /** The name attribute for this type of object class */ const ATTRIBUTE_K = 'k'; /** * How many days into the past should the free/busy data on the server be * calculated? */ const ATTRIBUTE_FBPAST = 'kolabFreeBusyPast'; /** The specific object class of this object type */ const OBJECTCLASS_KOLAB = 'kolab'; /** * A structure to initialize the attribute structure for this class. * * @var array */ public static $init_attributes = array( 'defined' => array( self::ATTRIBUTE_K, self::ATTRIBUTE_FBPAST, ), 'object_classes' => array( self::OBJECTCLASS_KOLAB, ), ); /** * Return the filter string to retrieve this object type. * * @return string The filter to retrieve this object type from the server * database. */ public static function getFilter() { $criteria = array('AND' => array( array('field' => self::ATTRIBUTE_K, 'op' => '=', 'test' => 'kolab'), array('field' => self::ATTRIBUTE_OC, 'op' => '=', 'test' => self::OBJECTCLASS_KOLAB), ), ); return $criteria; } /** * Generates an ID for the given information. * * @param array &$info The data of the object. * * @static * * @return string|PEAR_Error The ID. */ public function generateId(array &$info) { return self::ATTRIBUTE_K . '=kolab'; } } Horde_Kolab_Server-2.0.5/lib/Horde/Kolab/Server/Object/Kolabgermanbankarrangement.php0000664000175000017500000001446012653735542026670 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * This class provides a representation of german bank account * information. * * Copyright 2008-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Object_Kolabgermanbankarrangement extends Horde_Kolab_Server_Object_Top { /** Define attributes specific to this object type */ /** The number of the account */ const ATTRIBUTE_NUMBER = 'kolabGermanBankAccountNumber'; /** The numeric ID of the bank */ const ATTRIBUTE_BANKCODE = 'kolabGermanBankCode'; /** Account holder */ const ATTRIBUTE_HOLDER = 'kolabGermanBankAccountHolder'; /** Name of the bank */ const ATTRIBUTE_BANKNAME = 'kolabGermanBankName'; /** Additional information */ const ATTRIBUTE_INFO = 'kolabGermanBankAccountInfo'; /** The uid of the owner of this account */ const ATTRIBUTE_OWNERUID = 'kolabGermanBankAccountOwnerUid'; /** The specific object class of this object type */ const OBJECTCLASS_KOLABGERMANBANKARRANGEMENT = 'kolabGermanBankArrangement'; /** * A structure to initialize the attribute structure for this class. * * @var array */ public static $init_attributes = array( 'defined' => array( self::ATTRIBUTE_NUMBER, self::ATTRIBUTE_BANKCODE, self::ATTRIBUTE_HOLDER, self::ATTRIBUTE_BANKNAME, self::ATTRIBUTE_INFO, ), 'derived' => array( self::ATTRIBUTE_OWNERUID => array( 'method' => 'getParentUid', 'args' => array( 2, ), ), ), 'collapsed' => array( self::ATTRIBUTE_OWNERUID => array( 'base' => array( self::ATTRIBUTE_OWNERUID ), 'method' => 'removeAttribute', ), ), 'required' => array( self::ATTRIBUTE_NUMBER, self::ATTRIBUTE_BANKCODE, ), 'object_classes' => array( self::OBJECTCLASS_KOLABGERMANBANKARRANGEMENT, ), ); /** * Generates an ID for the given information. * * @param array &$info The data of the object. * * @static * * @return string|PEAR_Error The ID. */ public function generateId(array &$info) { if (!isset($info[self::ATTRIBUTE_OWNERUID])) { $uid = $this->get(self::ATTRIBUTE_OWNERUID); if (empty($uid)) { throw new Horde_Kolab_Server_Exception("No parent object provided!", Horde_Kolab_Server_Exception::INVALID_INFORMATION); } } else { if (is_array($info[self::ATTRIBUTE_OWNERUID])) { $uid = $info[self::ATTRIBUTE_OWNERUID][0]; } else { $uid = $info[self::ATTRIBUTE_OWNERUID]; } } $object = $this->server->fetch($uid); if (!$object->exists()) { throw new Horde_Kolab_Server_Exception(sprintf("The parent object %s does not exist!", $uid), Horde_Kolab_Server_Exception::INVALID_INFORMATION); } if (!isset($info[self::ATTRIBUTE_NUMBER])) { $number = $this->get(self::ATTRIBUTE_NUMBER); if (empty($number)) { throw new Horde_Kolab_Server_Exception("No account number given!", Horde_Kolab_Server_Exception::INVALID_INFORMATION); } } else { if (is_array($info[self::ATTRIBUTE_NUMBER])) { $number = $info[self::ATTRIBUTE_NUMBER][0]; } else { $number = $info[self::ATTRIBUTE_NUMBER]; } } if (!isset($info[self::ATTRIBUTE_BANKCODE])) { $bankcode = $this->get(self::ATTRIBUTE_BANKCODE); if (empty($bankcode)) { throw new Horde_Kolab_Server_Exception("No bankcode given!", Horde_Kolab_Server_Exception::INVALID_INFORMATION); } } else { if (is_array($info[self::ATTRIBUTE_BANKCODE])) { $bankcode = $info[self::ATTRIBUTE_BANKCODE][0]; } else { $bankcode = $info[self::ATTRIBUTE_BANKCODE]; } } $base = substr($uid, 0, strpos($uid, $this->server->getBaseUid()) - 1); unset($info[self::ATTRIBUTE_OWNERUID]); return self::ATTRIBUTE_NUMBER . '=' . $this->server->structure->quoteForUid($number) . ',' . self::ATTRIBUTE_BANKCODE . '=' . $this->server->structure->quoteForUid($bankcode) . ',' . $base; } /** * Returns the set of search operations supported by this object type. * * @return array An array of supported search operations. */ public static function getSearchOperations() { $searches = array( /* 'accountsForMail', */ ); return $searches; } /** * Returns the UIDs of the bank accounts for the user with the given mail * address. * * @param Horde_Kolab_Server $server The server to query. * @param string $mail Search objects with this mail alias. * * @return mixed The UIDs or false if there was no result. * * @throws Horde_Kolab_Server_Exception */ public static function accountsForMail($server, $mail) { $uid = $server->uidForMail($mail, Horde_Kolab_Server_Object::RESULT_SINGLE); return self::objectsForUid($server, $uid, self::OBJECTCLASS_KOLABGERMANBANKARRANGEMENT); } }Horde_Kolab_Server-2.0.5/lib/Horde/Kolab/Server/Object/Kolabgroupofnames.php0000664000175000017500000002037112653735542025042 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * This class provides methods to deal with groups for Kolab. * * Copyright 2008-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Object_Kolabgroupofnames extends Horde_Kolab_Server_Object_Groupofnames { /** Define attributes specific to this object type */ /** The visibility of the group */ const ATTRIBUTE_VISIBILITY = 'visible'; /** The ou subtree of the group */ const ATTRIBUTE_OU = 'ou'; /** The members of this group */ const ATTRIBUTE_MEMBER = 'member'; /** The mail address of this group */ const ATTRIBUTE_MAIL = 'mail'; /** The specific object class of this object type */ const OBJECTCLASS_KOLABGROUPOFNAMES = 'kolabGroupOfNames'; /** * A structure to initialize the attribute structure for this class. * * @var array */ public static $init_attributes = array( 'defined' => array( self::ATTRIBUTE_VISIBILITY, self::ATTRIBUTE_MAIL, ), 'derived' => array( self::ATTRIBUTE_VISIBILITY => array(), ), 'object_classes' => array( self::OBJECTCLASS_KOLABGROUPOFNAMES, ), ); /** * Return the filter string to retrieve this object type. * * @return string The filter to retrieve this object type from the server * database. */ public static function getFilter() { $criteria = array('AND' => array(array('field' => self::ATTRIBUTE_OC, 'op' => '=', 'test' => self::OBJECTCLASS_KOLABGROUPOFNAMES), ), ); return $criteria; } /** * Derive an attribute value. * * @param string $attr The attribute to derive. * * @return mixed The value of the attribute. */ protected function derive($attr) { switch ($attr) { case self::ATTRIBUTE_VISIBILITY: //@todo This needs structural knowledge and should be in a //structural class. return strpos($this->uid, 'cn=internal') === false; default: return parent::derive($attr); } } /** * Generates an ID for the given information. * * @param array $info The data of the object. * * @static * * @return string|PEAR_Error The ID. */ public function generateId(array &$info) { if ($this->exists()) { if (!isset($info[self::ATTRIBUTE_MAIL]) && !isset($info[self::ATTRIBUTE_CN])) { return false; } if (!isset($info[self::ATTRIBUTE_MAIL])) { $info[self::ATTRIBUTE_MAIL] = $this->get(self::ATTRIBUTE_MAIL); } if (!isset($info[self::ATTRIBUTE_CN])) { $info[self::ATTRIBUTE_CN] = $this->get(self::ATTRIBUTE_CN); } } if (isset($info[self::ATTRIBUTE_MAIL])) { $id = $info[self::ATTRIBUTE_MAIL]; } else { $id = $info[self::ATTRIBUTE_CN]; } if (is_array($id)) { $id = $id[0]; } return self::ATTRIBUTE_CN . '=' . $this->server->structure->quoteForUid(trim($id, " \t\n\r\0\x0B,")); } /** * Distill the server side object information to save. * * @param array $info The information about the object. * * @return NULL. * * @throws Horde_Kolab_Server_Exception If the given information contains errors. */ public function prepareObjectInformation(array &$info) { if (!$this->exists()) { if (!isset($info[self::ATTRIBUTE_CN])) { if (!isset($info[self::ATTRIBUTE_MAIL])) { throw new Horde_Kolab_Server_Exception('Either the mail address or the common name has to be specified for a group object!'); } else { $info[self::ATTRIBUTE_CN] = $info[self::ATTRIBUTE_MAIL]; } } } } /** * Returns the set of search operations supported by this object type. * * @return array An array of supported search operations. */ public static function getSearchOperations() { $searches = array( /* 'gidForMail', */ /* 'memberOfGroupAddress', */ /* 'getGroupAddresses', */ ); return $searches; } /** * Identify the GID for the first group found with the given mail. * * @param string $mail Search for groups with this mail address. * @param int $restrict A Horde_Kolab_Server::RESULT_* result restriction. * * @return mixed The GID or false if there was no result. * * @throws Horde_Kolab_Server_Exception */ public static function gidForMail($server, $mail, $restrict = 0) { $criteria = array('AND' => array(array('field' => self::ATTRIBUTE_MAIL, 'op' => '=', 'test' => $mail), ), ); return self::gidForSearch($server, $criteria, $restrict); } /** * Is the given UID member of the group with the given mail address? * * @param string $uid UID of the user. * @param string $mail Search the group with this mail address. * * @return boolean True in case the user is in the group, false otherwise. * * @throws Horde_Kolab_Server_Exception */ public static function memberOfGroupAddress($server, $uid, $mail) { $criteria = array('AND' => array( array('field' => self::ATTRIBUTE_MAIL, 'op' => '=', 'test' => $mail), array('field' => self::ATTRIBUTE_MEMBER, 'op' => '=', 'test' => $uid), ), ); $result = self::gidForSearch($server, $criteria, self::RESULT_SINGLE); return !empty($result); } /** * Get the mail addresses for the group of this object. * * @param string $uid The UID of the object to fetch. * * @return array An array of mail addresses. * * @throws Horde_Kolab_Server_Exception */ public static function getGroupAddresses($server, $uid) { $criteria = array('AND' => array( array('field' => self::ATTRIBUTE_OC, 'op' => '=', 'test' => self::OBJECTCLASS_GROUPOFNAMES), array('field' => self::ATTRIBUTE_MEMBER, 'op' => '=', 'test' => $uid), ), ); $data = self::attrsForSearch($server, $criteria, array(self::ATTRIBUTE_MAIL), self::RESULT_MANY); if (empty($data)) { return array(); } $mails = array(); foreach ($data as $element) { if (isset($element[self::ATTRIBUTE_MAIL])) { if (is_array($element[self::ATTRIBUTE_MAIL])) { $mails = array_merge($mails, $element[self::ATTRIBUTE_MAIL]); } else { $mails[] = $element[self::ATTRIBUTE_MAIL]; } } } return $mails; } } Horde_Kolab_Server-2.0.5/lib/Horde/Kolab/Server/Object/Kolabinetorgperson.php0000664000175000017500000002562312653735542025240 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * This class provides basic methods common to all Kolab server objects. * * Copyright 2008-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Object_Kolabinetorgperson extends Horde_Kolab_Server_Object_Inetorgperson { /** The specific object class of this object type */ const OBJECTCLASS_KOLABINETORGPERSON = 'kolabInetOrgPerson'; /** Define attributes specific to this object type */ /** * The attributes defined for this class. * * @var array */ public static $attributes = array( 'alias', 'kolabHomeServer', 'kolabFreebusyHost' /* 'kolabDelegate', 'kolabDeleteFlag', 'kolabFreeBusyFuture', */ /* , , 'kolabImapServer', */ /* 'kolabInvitationPolicy', 'kolabSalutation', 'gender', */ /* 'kolabMaritalStatus', 'homeFacsimileTelephoneNumber', 'germanTaxId', */ /* 'c', 'cyrus-userquota', 'kolabAllowSMTPRecipient', 'kolabAllowSMTPFrom', */ /* 'apple-birthday', 'apple-birthdayDate', 'birthPlace', 'birthName', */ /* 'pseudonym', 'countryOfCitizenship', 'legalForm', */ /* 'tradeRegisterRegisteredCapital', 'bylawURI', 'dateOfIncorporation', */ /* 'legalRepresentative', 'commercialProcuration', */ /* 'legalRepresentationPolicy', 'actingDeputy', 'VATNumber', */ /* 'otherLegalRelationship', 'inLiquidation', 'tradeRegisterType', */ /* 'tradeRegisterLocation', 'tradeRegisterIdentifier', 'tradeRegisterURI', */ /* 'tradeRegisterLastChangedDate', 'domainComponent', */ ); /** * A structure to initialize the attribute structure for this class. * * @var array */ /* public static $init_attributes = array( */ /* 'defined' => array( */ /* self::ATTRIBUTE_DELEGATE, */ /* self::ATTRIBUTE_DELETED, */ /* self::ATTRIBUTE_FBFUTURE, */ /* self::ATTRIBUTE_HOMESERVER, */ /* self::ATTRIBUTE_FREEBUSYHOST, */ /* self::ATTRIBUTE_IMAPHOST, */ /* self::ATTRIBUTE_IPOLICY, */ /* self::ATTRIBUTE_SALUTATION, */ /* self::ATTRIBUTE_GENDER, */ /* self::ATTRIBUTE_MARITALSTATUS, */ /* self::ATTRIBUTE_HOMEFAX, */ /* self::ATTRIBUTE_GERMANTAXID, */ /* self::ATTRIBUTE_COUNTRY, */ /* self::ATTRIBUTE_QUOTA, */ /* self::ATTRIBUTE_ALLOWEDRECIPIENTS, */ /* self::ATTRIBUTE_ALLOWEDFROM, */ /* self::ATTRIBUTE_DATEOFBIRTH, */ /* self::ATTRIBUTE_PLACEOFBIRTH, */ /* self::ATTRIBUTE_BIRTHNAME, */ /* self::ATTRIBUTE_PSEUDONYM, */ /* self::ATTRIBUTE_COUNTRYCITIZENSHIP, */ /* self::ATTRIBUTE_LEGALFORM, */ /* self::ATTRIBUTE_REGISTEREDCAPITAL, */ /* self::ATTRIBUTE_BYLAWURI, */ /* self::ATTRIBUTE_DATEOFINCORPORATION, */ /* self::ATTRIBUTE_LEGALREPRESENTATIVE, */ /* self::ATTRIBUTE_COMMERCIALPROCURATION, */ /* self::ATTRIBUTE_LEGALREPRESENTATIONPOLICY, */ /* self::ATTRIBUTE_ACTINGDEPUTY, */ /* self::ATTRIBUTE_VATNUMBER, */ /* self::ATTRIBUTE_OTHERLEGAL, */ /* self::ATTRIBUTE_INLIQUIDATION, */ /* self::ATTRIBUTE_TRTYPE, */ /* self::ATTRIBUTE_TRLOCATION, */ /* self::ATTRIBUTE_TRIDENTIFIER, */ /* self::ATTRIBUTE_TRURI, */ /* self::ATTRIBUTE_TRLASTCHANGED, */ /* self::ATTRIBUTE_DC, */ /* ), */ /* 'locked' => array( */ /* self::ATTRIBUTE_MAIL, */ /* ), */ /* /\** */ /* * Derived attributes are calculated based on other attribute values. */ /* *\/ */ /* 'derived' => array( */ /* self::ATTRDATE_DATEOFBIRTH => array( */ /* 'method' => 'getDate', */ /* 'args' => array( */ /* self::ATTRIBUTE_DATEOFBIRTH, */ /* ), */ /* ), */ /* ), */ /* 'object_classes' => array( */ /* self::OBJECTCLASS_KOLABINETORGPERSON, */ /* ), */ /* ); */ /** * Generates an ID for the given information. * * @param array $info The data of the object. * * @static * * @return string|PEAR_Error The ID. */ public function generateId(array &$info) { /** * Never rename the object, even if the components of the CN attribute * changed */ if ($this->exists()) { return false; } return self::ATTRIBUTE_CN . '=' . $this->generateCn($info); } /** * Generates the common name for the given information. * * @param array $info The data of the object. * * @return string The common name. */ public function generateCn($info) { global $conf; /** The fields that should get mapped into the user ID. */ if (isset($conf['kolab']['server']['params']['user_cn_mapfields'])) { $id_mapfields = $conf['kolab']['server']['params']['user_cn_mapfields']; } else { $id_mapfields = array(self::ATTRIBUTE_GIVENNAME, self::ATTRIBUTE_SN); } /** The user ID format. */ if (isset($conf['kolab']['server']['params']['user_cn_format'])) { $id_format = $conf['kolab']['server']['params']['user_cn_format']; } else { $id_format = '%s %s'; } $fieldarray = array(); foreach ($id_mapfields as $mapfield) { if (isset($info[$mapfield])) { $id = $info[$mapfield]; if (is_array($id)) { $id = $id[0]; } $fieldarray[] = $this->server->structure->quoteForUid($id); } else { $fieldarray[] = ''; } } return trim(vsprintf($id_format, $fieldarray), " \t\n\r\0\x0B,"); } /** * Distill the server side object information to save. * * @param array $info The information about the object. * * @return NULL. * * @throws Horde_Kolab_Server_Exception If the given information contains errors. */ public function prepareObjectInformation(array &$info) { if (!$this->exists()) { if (!isset($info[self::ATTRIBUTE_CN])) { if (!isset($info[self::ATTRIBUTE_SN]) || !isset($info[self::ATTRIBUTE_GIVENNAME])) { throw new Horde_Kolab_Server_Exception("Either the last name or the given name is missing!"); } else { $info[self::ATTRIBUTE_CN] = $this->generateCn($info); } } } } /** * Return the filter string to retrieve this object type. * * @return string The filter to retrieve this object type from the server * database. */ public static function getFilter() { $filter = new Horde_Kolab_Server_Query_Element_Equals( 'Objectclass', self::OBJECTCLASS_KOLABINETORGPERSON ); return $filter; } /** * List the external pop3 accounts of this object. * * @return array The data of the pop3 accounts. */ public function getExternalAccounts() { $result = array(); $account_uids = $this->objectsForUid($this->server, $this->uid, Horde_Kolab_Server_Object_Kolabpop3account::OBJECTCLASS_KOLABEXTERNALPOP3ACCOUNT); if ($account_uids !== false) { foreach ($account_uids as $account_uid) { $account = $this->server->fetch($account_uid, 'Horde_Kolab_Server_Object_Kolabpop3account'); $result[] = $account->toHash(); } } return $result; } /** * Create/update an external pop3 accounts of this object. * * @param array $account The account data. * * @return NULL */ public function saveExternalAccount($account) { $account[Horde_Kolab_Server_Object_Kolabpop3account::ATTRIBUTE_OWNERUID] = $this->getUid(); $object = &Horde_Kolab_Server_Object::factory('Horde_Kolab_Server_Object_Kolabpop3account', null, $this->server, $account); $object->save(); } /** * Delete an external account. * * @param string $mail The mail address of the pop3 account. * * @return NULL */ public function deleteExternalAccount($mail) { $account[Horde_Kolab_Server_Object_Kolabpop3account::ATTRIBUTE_OWNERUID] = $this->getUid(); $account[Horde_Kolab_Server_Object_Kolabpop3account::ATTRIBUTE_MAIL] = $mail; $object = &Horde_Kolab_Server_Object::factory('Horde_Kolab_Server_Object_Kolabpop3account', null, $this->server, $account); $object->delete(); } /** * Returns the server url of the given type for this user. * * This method is used to encapsulate multidomain support. * * @param string $server_type The type of server URL that should be returned. * * @return string The server url or empty on error. */ public function getServer($server_type) { global $conf; switch ($server_type) { case 'freebusy': $server = $this->get(self::ATTRIBUTE_FREEBUSYHOST); if (!empty($server)) { return $server; } if (isset($conf['kolab']['freebusy']['server'])) { return $conf['kolab']['freebusy']['server']; } $server = $this->getServer('homeserver'); if (empty($server)) { $server = $_SERVER['SERVER_NAME']; } if (isset($conf['kolab']['server']['freebusy_url_format'])) { return sprintf($conf['kolab']['server']['freebusy_url_format'], $server); } else { return 'https://' . $server . '/freebusy'; } case 'imap': $server = $this->get(self::ATTRIBUTE_IMAPHOST); if (!empty($server)) { return $server; } case 'homeserver': default: return $this->get(self::ATTRIBUTE_HOMESERVER); } } }Horde_Kolab_Server-2.0.5/lib/Horde/Kolab/Server/Object/Kolabpop3account.php0000664000175000017500000001505212653735542024573 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * This class provides a representation of pop3 mail accounts. * * Copyright 2008-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Object_Kolabpop3account extends Horde_Kolab_Server_Object_Top { /** Define attributes specific to this object type */ /** Server the account resides on */ const ATTRIBUTE_SERVER = 'externalPop3AccountServer'; /** User name for the account */ const ATTRIBUTE_LOGINNAME = 'externalPop3AccountLoginName'; /** Password for the account */ const ATTRIBUTE_PASSWORD = 'externalPop3EncryptedAccountPassword'; /** Description of the account */ const ATTRIBUTE_DESCRIPTION = 'externalPop3AccountDescription'; /** Mail address of the account */ const ATTRIBUTE_MAIL = 'externalPop3AccountMail'; /** Port to connect to */ const ATTRIBUTE_PORT = 'externalPop3AccountPort'; /** Use SSL when fetching mail from the account? */ const ATTRIBUTE_USESSL = 'externalPop3AccountUseSSL'; /** Use TLS when fetching mail from the account? */ const ATTRIBUTE_USETLS = 'externalPop3AccountUseTLS'; /** Login method for the external account */ const ATTRIBUTE_LOGINMETHOD = 'externalPop3AccountLoginMethod'; /** Validate the server certificate when connecting via SSL/TLS? */ const ATTRIBUTE_CHECKCERTIFICATE = 'externalPop3AccountCheckServerCertificate'; /** Should the fetched mail be deleted on the external account or not? */ const ATTRIBUTE_KEEPMAILONSERVER = 'externalPop3AccountKeepMailOnServer'; /** The uid of the owner of this account */ const ATTRIBUTE_OWNERUID = 'externalPop3AccountOwnerUid'; /** The specific object class of this object type */ const OBJECTCLASS_KOLABEXTERNALPOP3ACCOUNT = 'kolabExternalPop3Account'; /** * A structure to initialize the attribute structure for this class. * * @var array */ public static $init_attributes = array( 'defined' => array( self::ATTRIBUTE_SERVER, self::ATTRIBUTE_LOGINNAME, self::ATTRIBUTE_PASSWORD, self::ATTRIBUTE_DESCRIPTION, self::ATTRIBUTE_MAIL, self::ATTRIBUTE_PORT, self::ATTRIBUTE_USESSL, self::ATTRIBUTE_USETLS, self::ATTRIBUTE_LOGINMETHOD, self::ATTRIBUTE_CHECKCERTIFICATE, self::ATTRIBUTE_KEEPMAILONSERVER, ), 'derived' => array( self::ATTRIBUTE_OWNERUID => array( 'method' => 'getParentUid', ), ), 'collapsed' => array( self::ATTRIBUTE_OWNERUID => array( 'base' => array( self::ATTRIBUTE_OWNERUID ), 'method' => 'removeAttribute', ), ), 'required' => array( self::ATTRIBUTE_MAIL, self::ATTRIBUTE_SERVER, self::ATTRIBUTE_LOGINNAME, self::ATTRIBUTE_PASSWORD, ), 'object_classes' => array( self::OBJECTCLASS_KOLABEXTERNALPOP3ACCOUNT, ), ); /** * Generates an ID for the given information. * * @param array &$info The data of the object. * * @return string|PEAR_Error The ID. */ public function generateId(array &$info) { if (!isset($info[self::ATTRIBUTE_OWNERUID])) { $uid = $this->get(self::ATTRIBUTE_OWNERUID); if (empty($uid)) { throw new Horde_Kolab_Server_Exception("No parent object provided!", Horde_Kolab_Server_Exception::INVALID_INFORMATION); } } else { if (is_array($info[self::ATTRIBUTE_OWNERUID])) { $uid = $info[self::ATTRIBUTE_OWNERUID][0]; } else { $uid = $info[self::ATTRIBUTE_OWNERUID]; } } $object = $this->server->fetch($uid); if (!$object->exists()) { throw new Horde_Kolab_Server_Exception(sprintf("The parent object %s does not exist!", $uid), Horde_Kolab_Server_Exception::INVALID_INFORMATION); } if (!isset($info[self::ATTRIBUTE_MAIL])) { $mail = $this->get(self::ATTRIBUTE_MAIL); if (empty($mail)) { throw new Horde_Kolab_Server_Exception("No mail given!", Horde_Kolab_Server_Exception::INVALID_INFORMATION); } } else { if (is_array($info[self::ATTRIBUTE_MAIL])) { $mail = $info[self::ATTRIBUTE_MAIL][0]; } else { $mail = $info[self::ATTRIBUTE_MAIL]; } } $base = substr($uid, 0, strpos($uid, $this->server->getBaseUid()) - 1); unset($info[self::ATTRIBUTE_OWNERUID]); return self::ATTRIBUTE_MAIL . '=' . $this->server->structure->quoteForUid($mail) . ',' . $base; } /** * Returns the set of search operations supported by this object type. * * @return array An array of supported search operations. */ public static function getSearchOperations() { $searches = array( /* 'pop3AccountsForMail', */ ); return $searches; } /** * Returns the UIDs of the pop3 accounts for the user with the given mail * address. * * @param Horde_Kolab_Server $server The server to query. * @param string $mail Search objects with this mail alias. * * @return mixed The UIDs or false if there was no result. * * @throws Horde_Kolab_Server_Exception */ public static function pop3AccountsForMail($server, $mail) { $uid = $server->uidForMail($mail, Horde_Kolab_Server_Object::RESULT_SINGLE); return self::objectsForUid($server, $uid, self::OBJECTCLASS_KOLABEXTERNALPOP3ACCOUNT); } }Horde_Kolab_Server-2.0.5/lib/Horde/Kolab/Server/Object/Kolabsharedfolder.php0000664000175000017500000000614712653735542025004 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * This class provides methods to deal with shared folders * entries for Kolab. * * Copyright 2008-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Object_Kolabsharedfolder extends Horde_Kolab_Server_Object_Top { /** Define attributes specific to this object type */ /** The common name */ const ATTRIBUTE_CN = 'cn'; /** The type of this folder */ const ATTRIBUTE_FOLDERTYPE = 'kolabFolderType'; /** The home server of this folder */ const ATTRIBUTE_HOMESERVER = 'kolabHomeServer'; /** The specific object class of this object type */ const OBJECTCLASS_KOLABSHAREDFOLDER = 'kolabSharedFolder'; /** * A structure to initialize the attribute structure for this class. * * @var array */ public static $init_attributes = array( 'defined' => array( self::ATTRIBUTE_CN, self::ATTRIBUTE_HOMESERVER, ), 'required' => array( self::ATTRIBUTE_CN, ), 'object_classes' => array( self::OBJECTCLASS_KOLABSHAREDFOLDER, ), ); /** * Return the filter string to retrieve this object type. * * @return string The filter to retrieve this object type from the server * database. */ public static function getFilter() { $criteria = array('AND' => array(array('field' => self::ATTRIBUTE_OC, 'op' => '=', 'test' => self::OBJECTCLASS_KOLABSHAREDFOLDER), ), ); return $criteria; } /** * Generates an ID for the given information. * * @param array &$info The data of the object. * * @static * * @return string|PEAR_Error The ID. */ public function generateId(array &$info) { return self::ATTRIBUTE_CN . '=' . $this->server->structure->quoteForUid(trim($info['cn'], " \t\n\r\0\x0B,")); } /** * Convert the object attributes to a hash. * * @param string $attrs The attributes to return. * * @return array|PEAR_Error The hash representing this object. */ public function toHash($attrs = null) { if (!isset($attrs)) { $attrs = array( self::ATTRIBUTE_CN, self::ATTRIBUTE_HOMESERVER, self::ATTRIBUTE_FOLDERTYPE, ); } return parent::toHash($attrs); } } Horde_Kolab_Server-2.0.5/lib/Horde/Kolab/Server/Object/Mcached.php0000664000175000017500000002036112653735542022707 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * Low level caching for the Kolab object. * * Copyright 2008-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Object_Mcached implements Horde_Kolab_Server_Object_Interface { /** * Link to the decorated object. * * @var Horde_Kolab_Server_Object */ private $_object; /** * The external attributes supported by this class. * * @var array */ protected $_attributes_ext; /** * The internal attributes required for this class. * * @var array */ protected $_attributes_int; /** * Does the object exist? * * @return boolean True if the object exists, false otherwise. */ private $_exists; /** * The cached internal result * * @var array */ private $_cache_int = array(); /** * The cached external attribute values * * @var array */ private $_cache_ext = array(); /** * A cache for the list of actions this object supports. * * @var array */ protected $_actions; /** * Initialize the Kolab Object. Provide either the GUID * * @param Horde_Kolab_Server_Composite $composite The link to the Kolab server. * @param string $guid GUID of the object. */ public function __construct( Horde_Kolab_Server_Object $object ) { $this->_object = $object; } /** * Get the GUID of this object * * @return string the GUID of this object */ public function getGuid() { return $this->_object->getGuid(); } /** * Get the external attributes supported by this object. * * @return array The external attributes supported by this object. This is a * list of abbreviated attribute class names. */ public function getExternalAttributes() { if (empty($this->_attributes_ext)) { $this->_attributes_ext = $this->_object->getExternalAttributes(); } return $this->_attributes_ext; } /** * Get the internal attributes supported by this object. * * @return array The internal attributes supported by this object. This is * an association of internal attribute names an the correspodning attribute * class names. */ public function getInternalAttributes() { if (empty($this->_attributes_int)) { $this->_attributes_int = $this->_object->getInternalAttributes(); } return $this->_attributes_int; } /** * Set the internal data of this object. * * @param array $data A data array for the object. * * @return NULL */ public function setInternalData(array $data) { $this->_cache_int = $data; } /** * Does the object exist? * * @return NULL */ public function exists() { if ($this->_exists === null) { $this->_exists = $this->_object->exists(); } return $this->_exists; } /** * Read the object data. * * @return array The read data. */ public function readInternal() { $this->_cache_int = array_merge( $this->_cache_int, $this->_object->readInternal() ); } /** * Get the specified internal attributes. * * @param array $attributes The internal attribute. * * @return array The value(s) of these attribute */ public function getInternal(array $attributes) { if (!isset($this->_cache_int[$attr])) { if (!in_array($attr, array_keys($this->getInternalAttributes()))) { throw new Horde_Kolab_Server_Exception(sprintf("Attribute \"%s\" not supported!", $attr)); } $this->_object->readInternal(); if (!isset($this->_cache_int[$attr])) { throw new Horde_Kolab_Server_Exception(sprintf("Failed to read attribute \"%s\"!", $attr)); } } return $this->_cache_int[$attr]; } /** * Get the specified attribute of this object. * * @param string $attr The attribute to read. * * @return mixed The value of this attribute. */ public function getExternal($attr) { if (!isset($this->_cache_ext[$attr])) { $this->_cache_ext[$attr] = $this->_object->getExternal($attr); } return $this->_cache_ext[$attr]; } /** * Get the specified attribute of this object and ensure that only a single * value is being returned. * * @param string $attr The attribute to read. * * @return mixed The value of this attribute. */ public function getSingle($attr) { return $this->_object->getSingle($attr); } /** * Convert the object attributes to a hash. * * @param array $attrs The attributes to return. * @param boolean $single Should only a single attribute be returned? * * @return array|PEAR_Error The hash representing this object. */ public function toHash(array $attrs = array(), $single = true) { return $this->_object->toHash($attrs, $single); } /** * Saves object information. This may either create a new entry or modify an * existing entry. * * Please note that fields with multiple allowed values require the callee * to provide the full set of values for the field. Any old values that are * not resubmitted will be considered to be deleted. * * @param array $info The information about the object. * * @return NULL * * @throws Horde_Kolab_Server_Exception If saving the data failed. */ public function save(array $info) { $this->_object->save($info); /** Mark the object as existing */ $this->_exists = true; /** * Throw away the cache data to ensure it gets refetched in case we need * to access it again */ $this->_cache_ext = array(); $this->_cache_int = array(); } /** * Delete this object. * * @return NULL * * @throws Horde_Kolab_Server_Exception If deleting the object failed. */ public function delete() { $this->_object->delete(); /** Mark the object as missing */ $this->_exists = false; /** * Throw away the cache data to ensure it gets refetched in case we need * to access it again */ $this->_cache_ext = array(); $this->_cache_int = array(); } /** * Generates an ID for the given information. * * @param array &$info The data of the object. * * @return string The ID. */ public function generateId(array &$info) { $this->_object->generateId($info); } /** * Distill the server side object information to save. * * @param array &$info The information about the object. * * @return NULL. * * @throws Horde_Kolab_Server_Exception If the given information contains errors. */ public function prepareObjectInformation(array &$info) { $this->_object->prepareObjectInformation($info); } /** * Returns the set of actions supported by this object type. * * @return array An array of supported actions. */ public function getActions() { if (!isset($this->_actions)) { $this->_actions = $this->_object->getActions(); } return $this->_actions; } } Horde_Kolab_Server-2.0.5/lib/Horde/Kolab/Server/Object/Organizationalperson.php0000664000175000017500000001202412653735542025570 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * This class provides methods for the organizationalPerson objectclass. * * Copyright 2009-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Object_Organizationalperson extends Horde_Kolab_Server_Object_Person { /** Define attributes specific to this object type */ /** The postal address */ const ATTRIBUTE_POSTALADDRESS = 'postalAddress'; /** The job title */ const ATTRIBUTE_JOBTITLE = 'title'; /** The street address */ const ATTRIBUTE_STREET = 'street'; /** The post office box */ const ATTRIBUTE_POSTOFFICEBOX = 'postOfficeBox'; /** The postal code */ const ATTRIBUTE_POSTALCODE = 'postalCode'; /** The city */ const ATTRIBUTE_CITY = 'l'; /** The fax number */ const ATTRIBUTE_FAX = 'facsimileTelephoneNumber'; /** The specific object class of this object type */ const OBJECTCLASS_ORGANIZATIONALPERSON = 'organizationalPerson'; /** * A structure to initialize the attribute structure for this class. * * @var array */ /* public static $init_attributes = array( */ /* 'defined' => array( */ /* self::ATTRIBUTE_JOBTITLE, */ /* self::ATTRIBUTE_STREET, */ /* self::ATTRIBUTE_POSTOFFICEBOX, */ /* self::ATTRIBUTE_POSTALCODE, */ /* self::ATTRIBUTE_CITY, */ /* self::ATTRIBUTE_FAX, */ /* self::ATTRIBUTE_POSTALADDRESS, */ /* ), */ /* 'collapsed' => array( */ /* self::ATTRIBUTE_POSTALADDRESS => array( */ /* 'base' => array( */ /* self::ATTRIBUTE_SN, */ /* self::ATTRIBUTE_STREET, */ /* self::ATTRIBUTE_POSTOFFICEBOX, */ /* self::ATTRIBUTE_POSTALCODE, */ /* self::ATTRIBUTE_CITY, */ /* ), */ /* 'method' => 'setPostalAddress', */ /* ), */ /* ), */ /* 'object_classes' => array( */ /* self::OBJECTCLASS_ORGANIZATIONALPERSON, */ /* ), */ /* ); */ /** * Return the filter string to retrieve this object type. * * @static * * @return string The filter to retrieve this object type from the server * database. */ public static function getFilter() { $criteria = array('AND' => array(array('field' => self::ATTRIBUTE_OC, 'op' => '=', 'test' => self::OBJECTCLASS_ORGANIZATIONALPERSON), ), ); return $criteria; } /** * Set the complete postal address. * * @param string $key The attribute to collapse into. * @param array $attributes The attributes to collapse. * @param array &$info The information currently working on. * * @return NULL. */ protected function setPostalAddress($key, $attributes, &$info) { $empty = true; $postal_data = array(); foreach ($attributes as $attribute) { if (isset($info[$attribute])) { if (is_array($info[$attribute])) { $new = $info[$attribute][0]; } else { $new = $info[$attribute]; } $postal_data[$attribute] = $this->quote($new); $empty = false; } else { $old = $this->get($attribute, true); if (!empty($old)) { $postal_data[$attribute] = $old; $empty = false; } else { $postal_data[$attribute] = ''; } } } if ($empty === true) { return; } if (!empty($postal_data[self::ATTRIBUTE_POSTOFFICEBOX])) { $postal_data['street_segment'] = $postal_data[self::ATTRIBUTE_POSTOFFICEBOX]; } else { $postal_data['street_segment'] = $postal_data[self::ATTRIBUTE_STREET]; } $info[$key] = sprintf('%s$%s$%s %s', $postal_data[self::ATTRIBUTE_SN], $postal_data['street_segment'], $postal_data[self::ATTRIBUTE_POSTALCODE], $postal_data[self::ATTRIBUTE_CITY]); } }Horde_Kolab_Server-2.0.5/lib/Horde/Kolab/Server/Object/Person.php0000664000175000017500000001171612653735542022635 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * This class provides methods for the person objectclass. * * Copyright 2009-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Object_Person extends Horde_Kolab_Server_Object_Top { /** The specific object class of this object type */ const OBJECTCLASS_PERSON = 'person'; /** * A structure to initialize the attribute structure for this class. * * @var array */ public static $init_attributes = array( 'Cn', 'Sn', 'Userpassword', 'Userpasswordraw', /* 'Telephonenumber' */ /* 'defined' => array( */ /* self::ATTRIBUTE_CN, */ /* self::ATTRIBUTE_SN, */ /* self::ATTRIBUTE_USERPASSWORD, */ /* self::ATTRIBUTE_TELNO, */ /* ), */ /* 'derived' => array( */ /* self::ATTRIBUTE_USERPASSWORD => array( */ /* 'base' => array( */ /* self::ATTRIBUTE_USERPASSWORD */ /* ), */ /* 'method' => 'getEmpty', */ /* ), */ /* self::ATTRIBUTE_USERPASSWORDRAW => array( */ /* 'base' => array( */ /* self::ATTRIBUTE_USERPASSWORD */ /* ), */ /* 'method' => '_get', */ /* 'args' => array( */ /* self::ATTRIBUTE_USERPASSWORD, */ /* ), */ /* ), */ /* ), */ /* 'required' => array( */ /* self::ATTRIBUTE_CN, */ /* self::ATTRIBUTE_SN, */ /* ), */ /* 'object_classes' => array( */ /* self::OBJECTCLASS_PERSON */ /* ), */ ); /** * Salt and hash the password. * * @param string $password The password. * * @return string The salted hashed password. */ protected function hashPassword($password) { $type = isset($this->server->params['hashtype']) ? $this->server->params['hashtype'] : 'ssha'; return Horde_Auth::getCryptedPassword($password, '', $type, true); } /** * Return the filter string to retrieve this object type. * * @static * * @return string The filter to retrieve this object type from the server * database. */ public static function getFilter() { return new Horde_Kolab_Server_Query_Element_Equals( Horde_Kolab_Server_Object_Attribute_Objectclass::NAME, self::OBJECTCLASS_PERSON ); } /** * Generates an ID for the given information. * * @param array $info The data of the object. * * @static * * @return string The ID. */ public function generateId(array &$info) { $cn = Horde_Kolab_Server_Object_Attribute_Cn::NAME; $sn = Horde_Kolab_Server_Object_Attribute_Sn::NAME; if ($this->exists()) { if (!isset($info[$cn]) && !isset($info[$sn])) { return $this->getGuid(); } if (!isset($info[$cn])) { $old = $this->getInternal($cn); if (!empty($old)) { return $this->getGuid(); } } } if (!empty($info[$cn])) { $id = $info[$cn]; } else { $id = $info[$sn]; } if (is_array($id)) { $id = $id[0]; } return $cn . '=' . $this->server->structure->quoteForUid($id); } /** * Distill the server side object information to save. * * @param array $info The information about the object. * * @return array The set of information. * * @throws Horde_Kolab_Server_Exception If the given information contains errors. */ public function prepareObjectInformation(array &$info) { $cn = Horde_Kolab_Server_Object_Attribute_Cn::NAME; $sn = Horde_Kolab_Server_Object_Attribute_Sn::NAME; if (!$this->exists() && empty($info[$cn]) && !empty($info[$sn])) { $info[$cn] = $info[$sn]; } if (!empty($info[self::ATTRIBUTE_USERPASSWORD])) { $info[self::ATTRIBUTE_USERPASSWORD] = $this->hashPassword($info[self::ATTRIBUTE_USERPASSWORD]); } else if (isset($info[self::ATTRIBUTE_USERPASSWORD])) { unset($info[self::ATTRIBUTE_USERPASSWORD]); } } }Horde_Kolab_Server-2.0.5/lib/Horde/Kolab/Server/Object/Searches.php0000664000175000017500000000217712653735542023125 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * An interface indicating that an object class provides additional search * operations. * * Copyright 2008-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ interface Horde_Kolab_Server_Object_Searches { /** * Return the filter string to retrieve this object type. * * @return string The filter to retrieve this object type from the server * database. */ public static function getFilter(); }Horde_Kolab_Server-2.0.5/lib/Horde/Kolab/Server/Object/Top.php0000664000175000017500000000474612653735542022136 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * This class provides methods to deal with Kolab objects stored in * the Kolab db. * * Copyright 2008-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ abstract class Horde_Kolab_Server_Object_Top extends Horde_Kolab_Server_Object_Base implements Horde_Kolab_Server_Object_Searches { /** Define the possible Kolab object classes */ const OBJECTCLASS_TOP = 'top'; /** * The attributes defined for this class. * * @var array */ public static $attributes = array( 'objectClass', 'Openldapaci', 'Guid', 'Id', 'Createtimestamp', 'Modifytimestamp', 'Createtimestampdate', 'Modifytimestampdate', ); public static $object_classes = array( self::OBJECTCLASS_TOP, ); /** * Sort by this attributes. * * @var string */ public $sort_by = 'Guid'; /** * Return the filter string to retrieve this object type. * * @static * * @return string The filter to retrieve this object type from the server * database. */ public static function getFilter() { return new Horde_Kolab_Server_Query_Element_Equals( Horde_Kolab_Server_Object_Attribute_Objectclass::NAME, self::OBJECTCLASS_TOP ); } /** * Distill the server side object information to save. * * @param array &$info The information about the object. * * @return NULL. * * @throws Horde_Kolab_Server_Exception If the given information contains errors. */ public function prepareObjectInformation(array &$info) { } /** * Returns the set of actions supported by this object type. * * @return array An array of supported actions. */ public function getActions() { return array(); } } Horde_Kolab_Server-2.0.5/lib/Horde/Kolab/Server/Objects/Base.php0000664000175000017500000001776212653735542022433 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * This class provides methods to deal with Kolab objects stored in * the Kolab object db. * * Copyright 2008-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Objects_Base implements Horde_Kolab_Server_Objects_Interface { /** * A link to the composite server handler. * * @var Horde_Kolab_Server_Composite */ private $_composite; /** * Set the composite server reference for this object. * * @param Horde_Kolab_Server_Composite $composite A link to the composite * server handler. * * @return NULL */ public function setComposite( Horde_Kolab_Server_Composite $composite ) { $this->_composite = $composite; } /** * Fetch a Kolab object. * * This method will not retrieve any data from the server * immediately. Instead it will simply generate a new instance for the * desired object. * * The server data will only be accessed once you start reading the object * data. * * This method can also be used in order to fetch non-existing objects that * will be saved later. This is however not recommended and you should * rather use the add($info) method for that. * * If you do not provide the object type the server will try to determine it * automatically based on the uid. As this requires reading data from the * server it is recommended to specify the object type whenever it is known. * * If you do not specify a uid the object corresponding to the user bound to * the server will be returned. * * @param string $guid The GUID of the object to fetch. * @param string $type The type of the object to fetch. * * @return Kolab_Object The corresponding Kolab object. * * @throws Horde_Kolab_Server_Exception */ public function fetch($guid = null, $type = null) { if (!isset($guid)) { $guid = $this->_composite->server->getGuid(); } if (empty($type)) { $type = $this->_composite->structure->determineType($guid); } $object = Horde_Kolab_Server_Object_Factory::factory( $type, $guid, $this->_composite ); return $object; } /** * Add a Kolab object. * * @param array $info The object to store. * * @return Kolab_Object The newly created Kolab object. * * @throws Horde_Kolab_Server_Exception If the type of the object to add has * been left undefined or the object * already exists. */ public function add(array $info) { if (!isset($info['type'])) { throw new Horde_Kolab_Server_Exception( 'The type of a new object must be specified!'); } $type = $info['type']; unset($info['type']); $object = &Horde_Kolab_Server_Object::factory($type, null, $this, $info); if ($object->exists()) { throw new Horde_Kolab_Server_Exception( sprintf("The object with the uid \"%s\" does already exist!", $object->get(Horde_Kolab_Server_Object::ATTRIBUTE_UID))); } $object->save(); return $object; } /** * Generate a hash representation for a list of objects. * * The approach taken here is somewhat slow as the server data gets fetched * into objects first which are then converted to hashes again. Since a * server search will usually deliver the result as a hash the intermediate * object conversion is inefficient. * * But as the object classes are able to treat the attributes returned from * the server with custom parsing, this is currently the preferred * method. Especially for large result sets it would be better if this * method would call a static object class function that operate on the * result array returned from the server without using objects. * * @param string $type The type of the objects to be listed * @param array $params Additional parameters. * * @return array An array of Kolab objects. * * @throws Horde_Kolab_Server_Exception * * @todo The LDAP driver needs a more efficient version of this call as it * is not required to generate objects before returning data as a * hash. It can be derived directly from the LDAP result. */ public function listHash($type, $params = null) { $list = $this->listObjects($type, $params); if (isset($params['attributes'])) { $attributes = $params['attributes']; } else { $attributes = null; } $hash = array(); foreach ($list as $uid => $entry) { $hash[$uid] = $entry->toHash($attributes); } return $hash; } /** * List all objects of a specific type. * * @param string $type The type of the objects to be listed * @param array $params Additional parameters. * * @return array An array of Kolab objects. * * @throws Horde_Kolab_Server_Exception * * @todo Sorting * @todo Is this LDAP specific? */ public function listObjects($type, $params = null) { if (empty($params['base_dn'])) { $base = $this->_base_dn; } else { $base = $params['base_dn']; } $result = Horde_Kolab_Server_Object::loadClass($type); $vars = get_class_vars($type); $criteria = call_user_func(array($type, 'getFilter')); $filter = $this->searchQuery($criteria); $sort = $vars['sort_by']; if (isset($params['sort'])) { $sort = $params['sort']; } $options = array('scope' => 'sub'); if (isset($params['attributes'])) { $options['attributes'] = $params['attributes']; } else { $options['attributes'] = $this->getAttributes($type); } $data = $this->search($filter, $options, $base); if (empty($data)) { return array(); } if ($sort) { /* @todo: sorting */ /* $data = $result->as_sorted_struct(); */ /*$this->sort($result, $sort); */ } if (isset($params['from'])) { $from = $params['from']; } else { $from = -1; } if (isset($params['to'])) { $sort = $params['to']; } else { $to = -1; } if (!empty($vars['required_group'])) { $required_group = new Horde_Kolab_Server_Object_Kolabgroupofnames($this, null, $vars['required_group']); } $objects = array(); foreach ($data as $uid => $entry) { if (!empty($vars['required_group'])) { if (!$required_group->exists() || !$required_group->isMember($uid)) { continue; } } $objects[$uid] = &Horde_Kolab_Server_Object::factory($type, $uid, $this, $entry); } return $objects; } }Horde_Kolab_Server-2.0.5/lib/Horde/Kolab/Server/Objects/Interface.php0000664000175000017500000001042312653735542023444 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * Interface for a server object list. * * Copyright 2008-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ interface Horde_Kolab_Server_Objects_Interface { /** * Set the composite server reference for this object. * * @param Horde_Kolab_Server_Composite $composite A link to the composite * server handler. */ public function setComposite( Horde_Kolab_Server_Composite $composite ); /** * Add a Kolab object. * * @param array $info The object to store. * * @return Kolab_Object The newly created Kolab object. * * @throws Horde_Kolab_Server_Exception If the type of the object to add has * been left undefined or the object * already exists. */ public function add(array $info); /** * Fetch a Kolab object. * * This method will not retrieve any data from the server * immediately. Instead it will simply generate a new instance for the * desired object. * * The server data will only be accessed once you start reading the object * data. * * This method can also be used in order to fetch non-existing objects that * will be saved later. This is however not recommended and you should * rather use the add($info) method for that. * * If you do not provide the object type the server will try to determine it * automatically based on the uid. As this requires reading data from the * server it is recommended to specify the object type whenever it is known. * * If you do not specify a uid the object corresponding to the user bound to * the server will be returned. * * @param string $uid The UID of the object to fetch. * @param string $type The type of the object to fetch. * * @return Kolab_Object The corresponding Kolab object. * * @throws Horde_Kolab_Server_Exception */ public function fetch($uid = null, $type = null); /** * List all objects of a specific type * * @param string $type The type of the objects to be listed * @param array $params Additional parameters. * * @return array An array of Kolab objects. * * @throws Horde_Kolab_Server_Exception */ public function listObjects($type, $params = null); /** * Generate a hash representation for a list of objects. * * The approach taken here is somewhat slow as the server data gets fetched * into objects first which are then converted to hashes again. Since a * server search will usually deliver the result as a hash the intermediate * object conversion is inefficient. * * But as the object classes are able to treat the attributes returned from * the server with custom parsing, this is currently the preferred * method. Especially for large result sets it would be better if this * method would call a static object class function that operate on the * result array returned from the server without using objects. * * @param string $type The type of the objects to be listed * @param array $params Additional parameters. * * @return array An array of Kolab objects. * * @throws Horde_Kolab_Server_Exception * * @todo The LDAP driver needs a more efficient version of this call as it * is not required to generate objects before returning data as a * hash. It can be derived directly from the LDAP result. */ public function listHash($type, $params = null); }Horde_Kolab_Server-2.0.5/lib/Horde/Kolab/Server/Query/Element/And.php0000664000175000017500000000210612653735542023352 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * An element grouping by and. * * Copyright 2008-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Query_Element_And extends Horde_Kolab_Server_Query_Element_Group { /** * Convert this element to a query element. * * @return mixed The element as query. */ public function convert( Horde_Kolab_Server_Query_Interface $writer ) { return $writer->convertAnd($this); } }Horde_Kolab_Server-2.0.5/lib/Horde/Kolab/Server/Query/Element/Approx.php0000664000175000017500000000214712653735542024126 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * An element expressing an 'approx' match. * * Copyright 2008-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Query_Element_Approx extends Horde_Kolab_Server_Query_Element_Single { /** * Convert this element to a query element. * * @return mixed The element as query. */ public function convert( Horde_Kolab_Server_Query_Interface $writer ) { return $writer->convertApprox($this); } }Horde_Kolab_Server-2.0.5/lib/Horde/Kolab/Server/Query/Element/Begins.php0000664000175000017500000000214712653735542024064 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * An element expressing an 'begins' match. * * Copyright 2008-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Query_Element_Begins extends Horde_Kolab_Server_Query_Element_Single { /** * Convert this element to a query element. * * @return mixed The element as query. */ public function convert( Horde_Kolab_Server_Query_Interface $writer ) { return $writer->convertBegins($this); } }Horde_Kolab_Server-2.0.5/lib/Horde/Kolab/Server/Query/Element/Contains.php0000664000175000017500000000215712653735542024434 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * An element expressing an 'contains' match. * * Copyright 2008-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Query_Element_Contains extends Horde_Kolab_Server_Query_Element_Single { /** * Convert this element to a query element. * * @return mixed The element as query. */ public function convert( Horde_Kolab_Server_Query_Interface $writer ) { return $writer->convertContains($this); } }Horde_Kolab_Server-2.0.5/lib/Horde/Kolab/Server/Query/Element/Ends.php0000664000175000017500000000213712653735542023545 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * An element expressing an 'ends' match. * * Copyright 2008-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Query_Element_Ends extends Horde_Kolab_Server_Query_Element_Single { /** * Convert this element to a query element. * * @return mixed The element as query. */ public function convert( Horde_Kolab_Server_Query_Interface $writer ) { return $writer->convertEnds($this); } }Horde_Kolab_Server-2.0.5/lib/Horde/Kolab/Server/Query/Element/Equals.php0000664000175000017500000000214712653735542024107 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * An element expressing an 'equals' match. * * Copyright 2008-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Query_Element_Equals extends Horde_Kolab_Server_Query_Element_Single { /** * Convert this element to a query element. * * @return mixed The element as query. */ public function convert( Horde_Kolab_Server_Query_Interface $writer ) { return $writer->convertEquals($this); } }Horde_Kolab_Server-2.0.5/lib/Horde/Kolab/Server/Query/Element/Greater.php0000664000175000017500000000215312653735542024243 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * An element expressing an 'greater' match. * * Copyright 2008-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Query_Element_Greater extends Horde_Kolab_Server_Query_Element_Single { /** * Convert this element to a query element. * * @return mixed The element as query. */ public function convert( Horde_Kolab_Server_Query_Interface $writer ) { return $writer->convertGreater($this); } }Horde_Kolab_Server-2.0.5/lib/Horde/Kolab/Server/Query/Element/Group.php0000664000175000017500000000353712653735542023755 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * A grouped query element. * * Copyright 2008-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ abstract class Horde_Kolab_Server_Query_Element_Group implements Horde_Kolab_Server_Query_Element_Interface { /** * The group elements. * * @var array */ protected $_elements; /** * Constructor. * * @param array $elements The group elements. */ public function __construct(array $elements) { $this->_elements = $elements; } /** * Return the query element name. * * This should never be called for group elements. * * @return string The name of the query element. */ public function getName() { throw new Horde_Kolab_Server_Exception('Not supported!'); } /** * Return the value of this element. * * This should never be called for group elements. * * @return mixed The query value. */ public function getValue() { throw new Horde_Kolab_Server_Exception('Not supported!'); } /** * Return the elements of this group. * * @return mixed The group elements. */ public function getElements() { return $this->_elements; } }Horde_Kolab_Server-2.0.5/lib/Horde/Kolab/Server/Query/Element/Interface.php0000664000175000017500000000265112653735542024555 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * Interface for server query elements. * * Copyright 2008-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ interface Horde_Kolab_Server_Query_Element_Interface { /** * Return the query element name. * * @return string The name of the query element. */ public function getName(); /** * Return the value of this element. * * @return mixed The query value. */ public function getValue(); /** * Return the elements of this group. * * @return mixed The group elements. */ public function getElements(); /** * Convert this element to a query element. * * @return mixedd The element as query. */ public function convert( Horde_Kolab_Server_Query_Interface $writer ); }Horde_Kolab_Server-2.0.5/lib/Horde/Kolab/Server/Query/Element/Less.php0000664000175000017500000000213712653735542023562 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * An element expressing an 'less' match. * * Copyright 2008-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Query_Element_Less extends Horde_Kolab_Server_Query_Element_Single { /** * Convert this element to a query element. * * @return mixed The element as query. */ public function convert( Horde_Kolab_Server_Query_Interface $writer ) { return $writer->convertLess($this); } }Horde_Kolab_Server-2.0.5/lib/Horde/Kolab/Server/Query/Element/Mapped.php0000664000175000017500000000502312653735542024057 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * A mapped query element. * * Copyright 2008-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Query_Element_Mapped implements Horde_Kolab_Server_Query_Element_Interface { /** * Delegated element. * * @var Horde_Kolab_Server_Query_Element */ private $_element; /** * Name mapper. * * @var Horde_Kolab_Server_Mapped */ private $_mapper; /** * Constructor. * * @param Horde_Kolab_Server_Query_Element $element The mapped element. * @param Horde_Kolab_Server_Mapped $mapper The mapping handler. */ public function __construct( Horde_Kolab_Server_Query_Element_Interface $element, Horde_Kolab_Server_Decorator_Map $mapper ) { $this->_element = $element; $this->_mapper = $mapper; } /** * Return the query element name. * * @return string The name of the query element. */ public function getName() { return $this->_mapper->mapField($this->_element->getName()); } /** * Return the value of this element. * * @return mixed The query value. */ public function getValue() { return $this->_element->getValue(); } /** * Return the elements of this group. * * @return mixed The group elements. */ public function getElements() { $elements = array(); foreach ($this->_element->getElements() as $element) { $elements[] = new Horde_Kolab_Server_Query_Element_Mapped( $element, $this->_mapper ); } return $elements; } /** * Convert this element to a string. * * @return string The query string of the element. */ public function convert( Horde_Kolab_Server_Query_Interface $writer ) { return $this->_element->convert($writer); } }Horde_Kolab_Server-2.0.5/lib/Horde/Kolab/Server/Query/Element/Not.php0000664000175000017500000000245612653735542023420 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * A negating element. * * Copyright 2008-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Query_Element_Not extends Horde_Kolab_Server_Query_Element_Group { /** * Constructor. * * @param array $elements The group elements. */ public function __construct( Horde_Kolab_Server_Query_Element_Interface $element ) { parent::__construct(array($element)); } /** * Convert this element to a query element. * * @return mixed The element as query. */ public function convert( Horde_Kolab_Server_Query_Interface $writer ) { return $writer->convertNot($this); } }Horde_Kolab_Server-2.0.5/lib/Horde/Kolab/Server/Query/Element/Or.php0000664000175000017500000000210212653735542023224 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * An element grouping by or. * * Copyright 2008-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Query_Element_Or extends Horde_Kolab_Server_Query_Element_Group { /** * Convert this element to a query element. * * @return mixed The element as query. */ public function convert( Horde_Kolab_Server_Query_Interface $writer ) { return $writer->convertOr($this); } }Horde_Kolab_Server-2.0.5/lib/Horde/Kolab/Server/Query/Element/Single.php0000664000175000017500000000362712653735542024102 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * A single query element. * * Copyright 2008-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ abstract class Horde_Kolab_Server_Query_Element_Single implements Horde_Kolab_Server_Query_Element_Interface { /** * The element name. * * @var string */ protected $_name; /** * The comparison value. * * @var mixed */ protected $_value; /** * Constructor. * * @param string $name The element name. * @param mixed $value The comparison value. */ public function __construct($name, $value) { $this->_name = $name; $this->_value = $value; } /** * Return the query element name. * * @return string The name of the query element. */ public function getName() { return $this->_name; } /** * Return the value of this element. * * @return mixed The query value. */ public function getValue() { return $this->_value; } /** * Return the elements of this group. * * This should never be called for single elements. * * @return mixed The group elements. */ public function getElements() { throw new Horde_Kolab_Server_Exception('Not supported!'); } }Horde_Kolab_Server-2.0.5/lib/Horde/Kolab/Server/Query/Interface.php0000664000175000017500000000761312653735542023167 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * Interface for server queries. * * Copyright 2008-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ interface Horde_Kolab_Server_Query_Interface { /** * Return the query as a string. * * @return string The query in string format. */ public function __toString(); /** * Convert the equals element to query format. * * @param Horde_Kolab_Server_Query_Element_Single $single The element to convert. * * @return mixed The query element in query format. */ public function convertEquals(Horde_Kolab_Server_Query_Element_Equals $equals); /** * Convert the begins element to query format. * * @param Horde_Kolab_Server_Query_Element_Single $single The element to convert. * * @return mixed The query element in query format. */ public function convertBegins(Horde_Kolab_Server_Query_Element_Begins $begins); /** * Convert the ends element to query format. * * @param Horde_Kolab_Server_Query_Element_Single $single The element to convert. * * @return mixed The query element in query format. */ public function convertEnds(Horde_Kolab_Server_Query_Element_Ends $ends); /** * Convert the contains element to query format. * * @param Horde_Kolab_Server_Query_Element_Single $single The element to convert. * * @return mixed The query element in query format. */ public function convertContains(Horde_Kolab_Server_Query_Element_Contains $contains); /** * Convert the less element to query format. * * @param Horde_Kolab_Server_Query_Element_Single $single The element to convert. * * @return mixed The query element in query format. */ public function convertLess(Horde_Kolab_Server_Query_Element_Less $less); /** * Convert the greater element to query format. * * @param Horde_Kolab_Server_Query_Element_Single $single The element to convert. * * @return mixed The query element in query format. */ public function convertGreater(Horde_Kolab_Server_Query_Element_Greater $greater); /** * Convert the approx element to query format. * * @param Horde_Kolab_Server_Query_Element_Single $single The element to convert. * * @return mixed The query element in query format. */ public function convertApprox(Horde_Kolab_Server_Query_Element_Approx $approx); /** * Convert the not element to query format. * * @param Horde_Kolab_Server_Query_Element_Group $group The element to convert. * * @return mixed The query element in query format. */ public function convertNot(Horde_Kolab_Server_Query_Element_Not $not); /** * Convert the and element to query format. * * @param Horde_Kolab_Server_Query_Element_Group $group The element to convert. * * @return mixed The query element in query format. */ public function convertAnd(Horde_Kolab_Server_Query_Element_And $and); /** * Convert the or element to query format. * * @param Horde_Kolab_Server_Query_Element_Group $group The element to convert. * * @return mixed The query element in query format. */ public function convertOr(Horde_Kolab_Server_Query_Element_Group $or); }Horde_Kolab_Server-2.0.5/lib/Horde/Kolab/Server/Query/Ldap.php0000664000175000017500000002064412653735542022146 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * Handler for LDAP server queries. * * Copyright 2008-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Query_Ldap implements Horde_Kolab_Server_Query_Interface { /** * The query criteria. * * @var Horde_Kolab_Server_Query_Element */ private $_criteria; /** * The db structure. * * @var Horde_Kolab_Server_Structure */ private $_structure; /** * Constructor. * * @param array $criteria The query criteria. */ public function __construct( Horde_Kolab_Server_Query_Element_Interface $criteria, Horde_Kolab_Server_Structure_Interface $structure ) { $this->_criteria = $criteria; $this->_structure = $structure; } /** * Return the query as a string. * * @return string The query in string format. * * @throws Horde_Kolab_Server_Exception If the query is malformed. */ public function __toString() { try { $filter = $this->_criteria->convert($this); return (string)$filter; } catch (Horde_Kolab_Server_Exception $e) { return ''; } } /** * Convert the equals element to query format. * * @param Horde_Kolab_Server_Query_Element_Equals $equals The element to convert. * * @return mixed The query element in query format. * * @throws Horde_Kolab_Server_Exception If the query is malformed. */ public function convertEquals(Horde_Kolab_Server_Query_Element_Equals $equals) { return $this->_convertSingle($equals, 'equals'); } /** * Convert the begins element to query format. * * @param Horde_Kolab_Server_Query_Element_Begins $begins The element to convert. * * @return mixed The query element in query format. * * @throws Horde_Kolab_Server_Exception If the query is malformed. */ public function convertBegins(Horde_Kolab_Server_Query_Element_Begins $begins) { return $this->_convertSingle($begins, 'begins'); } /** * Convert the ends element to query format. * * @param Horde_Kolab_Server_Query_Element_Ends $ends The element to convert. * * @return mixed The query element in query format. * * @throws Horde_Kolab_Server_Exception If the query is malformed. */ public function convertEnds(Horde_Kolab_Server_Query_Element_Ends $ends) { return $this->_convertSingle($ends, 'ends'); } /** * Convert the contains element to query format. * * @param Horde_Kolab_Server_Query_Element_Contains $contains The element to convert. * * @return mixed The query element in query format. * * @throws Horde_Kolab_Server_Exception If the query is malformed. */ public function convertContains(Horde_Kolab_Server_Query_Element_Contains $contains) { return $this->_convertSingle($contains, 'contains'); } /** * Convert the less element to query format. * * @param Horde_Kolab_Server_Query_Element_Less $less The element to convert. * * @return mixed The query element in query format. * * @throws Horde_Kolab_Server_Exception If the query is malformed. */ public function convertLess(Horde_Kolab_Server_Query_Element_Less $less) { return $this->_convertSingle($less, 'less'); } /** * Convert the greater element to query format. * * @param Horde_Kolab_Server_Query_Element_Grater $grater The element to convert. * * @return mixed The query element in query format. * * @throws Horde_Kolab_Server_Exception If the query is malformed. */ public function convertGreater(Horde_Kolab_Server_Query_Element_Greater $greater) { return $this->_convertSingle($greater, 'greater'); } /** * Convert the approx element to query format. * * @param Horde_Kolab_Server_Query_Element_Approx $approx The element to convert. * * @return mixed The query element in query format. * * @throws Horde_Kolab_Server_Exception If the query is malformed. */ public function convertApprox(Horde_Kolab_Server_Query_Element_Approx $approx) { return $this->_convertSingle($approx, 'approx'); } /** * Convert the single element to query format. * * @param Horde_Kolab_Server_Query_Element_Single $single The element to convert. * @param string $operator The element operation. * * @return mixed The query element in query format. * * @throws Horde_Kolab_Server_Exception If the query is malformed. */ private function _convertSingle( Horde_Kolab_Server_Query_Element_Single $single, $operator ) { try { return Horde_Ldap_Filter::create( $this->_structure->mapExternalToInternalAttribute( $single->getName() ), $operator, $single->getValue() ); } catch (Horde_Ldap_Exception $e) { throw new Horde_Kolab_Server_Exception( $e->getMessage(), Horde_Kolab_Server_Exception::INVALID_QUERY, $e ); } } /** * Convert the not element to query format. * * @param Horde_Kolab_Server_Query_Element_Group $group The element to convert. * * @return mixed The query element in query format. * * @throws Horde_Kolab_Server_Exception If the query is malformed. */ public function convertNot(Horde_Kolab_Server_Query_Element_Not $not) { $elements = $not->getElements(); try { return Horde_Ldap_Filter::combine('!', $elements[0]->convert($this)); } catch (Horde_Ldap_Exception $e) { throw new Horde_Kolab_Server_Exception( $e->getMessage(), Horde_Kolab_Server_Exception::INVALID_QUERY, $e ); } } /** * Convert the and element to query format. * * @param Horde_Kolab_Server_Query_Element_Group $group The element to convert. * * @return mixed The query element in query format. * * @throws Horde_Kolab_Server_Exception If the query is malformed. */ public function convertAnd(Horde_Kolab_Server_Query_Element_And $and) { return $this->_convertGroup($and, '&'); } /** * Convert the or element to query format. * * @param Horde_Kolab_Server_Query_Element_Group $group The element to convert. * * @return mixed The query element in query format. * * @throws Horde_Kolab_Server_Exception If the query is malformed. */ public function convertOr(Horde_Kolab_Server_Query_Element_Group $or) { return $this->_convertGroup($or, '|'); } /** * Convert the group element to query format. * * @param Horde_Kolab_Server_Query_Element_Group $group The element to convert. * @param string $operator The element operation. * * @return mixed The query element in query format. * * @throws Horde_Kolab_Server_Exception If the query is malformed. */ public function _convertGroup( Horde_Kolab_Server_Query_Element_Group $group, $operator ) { $filters = array(); foreach ($group->getElements() as $element) { $filters[] = $element->convert($this); } try { return Horde_Ldap_Filter::combine($operator, $filters); } catch (Horde_Ldap_Exception $e) { throw new Horde_Kolab_Server_Exception( $e->getMessage(), Horde_Kolab_Server_Exception::INVALID_QUERY, $e ); } } }Horde_Kolab_Server-2.0.5/lib/Horde/Kolab/Server/Result/Interface.php0000664000175000017500000000235512653735542023336 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * Interface for query results. * * Copyright 2008-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ interface Horde_Kolab_Server_Result_Interface { /** * The number of result entries. * * @return int The number of elements. */ public function count(); /** * Test if the last search exceeded the size limit. * * @return boolean True if the last search exceeded the size limit. */ public function sizeLimitExceeded(); /** * Return the result as an array. * * @return array The resulting array. */ public function asArray(); }Horde_Kolab_Server-2.0.5/lib/Horde/Kolab/Server/Result/Ldap.php0000664000175000017500000000337312653735542022317 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * Handler for LDAP query results. * * Copyright 2008-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Result_Ldap implements Horde_Kolab_Server_Result_Interface { /** * The search result. * * @var Horde_Ldap_Search */ private $_search; /** * Constructor. * * @param Horde_Ldap_Search $search The LDAP search result. */ public function __construct(Horde_Ldap_Search $search) { $this->_search = $search; } /** * The number of result entries. * * @return int The number of elements. */ public function count() { return $this->_search->count(); } /** * Test if the last search exceeded the size limit. * * @return boolean True if the last search exceeded the size limit. */ public function sizeLimitExceeded() { return $this->_search->sizeLimitExceeded(); } /** * Return the result as an array. * * @return array The resulting array. */ public function asArray() { return $this->_search->asArray(); } }Horde_Kolab_Server-2.0.5/lib/Horde/Kolab/Server/Schema/Decorator/Cache.php0000664000175000017500000002472412653735542024311 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * This class handles the db schema. * * Copyright 2008-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Schema_Decorator_Cache implements Horde_Kolab_Server_Schema_Interface { /** Maximum accepted level for the object class hierarchy */ const MAX_HIERARCHY = 100; /** * A cache for object attribute definitions. * * @var array */ protected $attributes; /** * A link to the composite server handler. * * @var Horde_Kolab_Server_Composite */ protected $composite; /** * Set the composite server reference for this object. * * @param Horde_Kolab_Server_Composite $composite A link to the composite * server handler. * * @return NULL */ public function setComposite( Horde_Kolab_Server_Composite $composite ) { $this->composite = $composite; } /** * Return the schema for the given objectClass. * * @param string $objectclass Fetch the schema for this objectClass. * * @return array The schema for the given objectClass. * * @throws Horde_Kolab_Server_Exception If retrieval of the schema failed. */ public function getObjectclassSchema($objectclass) { if (!empty($this->_config['schema_support'])) { $schema = $this->_getSchema(); $info = $schema->get('objectclass', $objectclass); $this->_handleError($info, Horde_Kolab_Server_Exception::SYSTEM); return $info; } return parent::getObjectclassSchema($objectclass); } /** * Return the schema for the given attribute. * * @param string $attribute Fetch the schema for this attribute. * * @return array The schema for the given attribute. * * @throws Horde_Kolab_Server_Exception If retrieval of the schema failed. */ public function getAttributeSchema($attribute) { if (!empty($this->_config['schema_support'])) { $schema = $this->_getSchema(); $info = $schema->get('attribute', $attribute); $this->_handleError($info, Horde_Kolab_Server_Exception::SYSTEM); return $info; } return parent::getAttributeSchema($attribute); } /** * Return the attributes supported by the given object class. * * @param string $class Determine the attributes for this class. * * @return array The supported attributes. * * @throws Horde_Kolab_Server_Exception If the schema analysis fails. */ public function getExternalAttributes($class) { if (!isset($this->attributes)) { if (isset($this->cache)) { register_shutdown_function(array($this, 'shutdown')); } } if (empty($this->attributes[$class])) { if (isset($this->cache)) { $this->attributes[$class] = @unserialize($cache->get('attributes_' . $class, $this->params['cache_lifetime'])); } if (empty($this->attributes[$class])) { $childclass = $class; $classes = array(); $level = 0; while ($childclass != 'Horde_Kolab_Server_Object' && $level < self::MAX_HIERARCHY) { $classes[] = $childclass; $childclass = get_parent_class($childclass); $level++; } /** Finally add the basic object class */ $classes[] = $childclass; if ($level == self::MAX_HIERARCHY) { if (isset($this->logger)) { $logger->err(sprintf('The maximal level of the object hierarchy has been exceeded for class \"%s\"!', $class)); } } /** * Collect attributes from bottom to top. */ $classes = array_reverse($classes); $types = array('defined', 'required', 'derived', 'collapsed', 'defaults', 'locked', 'object_classes'); foreach ($types as $type) { $$type = array(); } foreach ($classes as $childclass) { $vars = get_class_vars($childclass); if (isset($vars['init_attributes'])) { foreach ($types as $type) { /** * If the user wishes to adhere to the schema * information from the server we will skip the * attributes defined within the object class here. */ if (!empty($this->params['schema_override']) && in_array($type, 'defined', 'required')) { continue; } if (isset($vars['init_attributes'][$type])) { $$type = array_merge($$type, $vars['init_attributes'][$type]); } } } } $attrs = array(); foreach ($object_classes as $object_class) { $info = $this->getObjectclassSchema($object_class); if (isset($info['may'])) { $defined = array_merge($defined, $info['may']); } if (isset($info['must'])) { $defined = array_merge($defined, $info['must']); $required = array_merge($required, $info['must']); } foreach ($defined as $attribute) { try { $attrs[$attribute] = $this->getAttributeSchema($attribute); } catch (Horde_Kolab_Server_Exception $e) { /** * If the server considers the attribute to be * invalid we mark it. */ $attrs[$attribute] = array('invalid' => true); } } foreach ($required as $attribute) { $attrs[$attribute]['required'] = true; } foreach ($locked as $attribute) { $attrs[$attribute]['locked'] = true; } foreach ($defaults as $attribute => $default) { $attrs[$attribute]['default'] = $default; } $attrs[Horde_Kolab_Server_Object::ATTRIBUTE_OC]['default'] = $object_classes; } foreach ($derived as $key => $attributes) { $supported = true; if (isset($attributes['base'])) { foreach ($attributes['base'] as $attribute) { /** * Usually derived attribute are determined on basis * of one or more attributes. If any of these is not * supported the derived attribute should not be * included into the set of supported attributes. */ if (!isset($attrs[$attribute])) { unset($derived[$attribute]); $supported = false; break; } } } if ($supported) { $attrs[$key] = $attributes; } } $check_collapsed = $collapsed; foreach ($check_collapsed as $key => $attributes) { if (isset($attributes['base'])) { foreach ($attributes['base'] as $attribute) { /** * Usually collapsed attribute are determined on basis * of one or more attributes. If any of these is not * supported the collapsed attribute should not be * included into the set of supported attributes. */ if (!isset($attrs[$attribute])) { unset($collapsed[$attribute]); } } } } $this->attributes[$class] = array($attrs, array( 'derived' => array_keys($derived), 'collapsed' => $collapsed, 'locked' => $locked, 'required' => $required)); } } return $this->attributes[$class]; } public function getInternalAttributes($class) { } /** * Stores the attribute definitions in the cache. */ public function shutdown() { if (isset($this->attributes)) { if (isset($this->cache)) { foreach ($this->attributes as $key => $value) { try { $this->cache->set('attributes_' . $key, @serialize($value)); } catch (Exception $e) { } } } } } }Horde_Kolab_Server-2.0.5/lib/Horde/Kolab/Server/Schema/Base.php0000664000175000017500000002127712653735542022236 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * This class handles the db schema. * * Copyright 2008-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Schema_Base implements Horde_Kolab_Server_Schema_Interface { /** * A link to the composite server handler. * * @var Horde_Kolab_Server_Composite */ private $_composite; /** * Set the composite server reference for this object. * * @param Horde_Kolab_Server_Composite $composite A link to the composite * server handler. * * @return NULL */ public function setComposite( Horde_Kolab_Server_Composite $composite ) { $this->_composite = $composite; } /** * Return the schema for the given objectClass. * * @param string $objectclass Fetch the schema for this objectClass. * * @return array The schema for the given objectClass. * * @throws Horde_Kolab_Server_Exception If retrieval of the schema failed. */ public function getObjectclassSchema($objectclass) { if (!empty($this->_config['schema_support'])) { $schema = $this->_getSchema(); $info = $schema->get('objectclass', $objectclass); $this->_handleError($info, Horde_Kolab_Server_Exception::SYSTEM); return $info; } return parent::getObjectclassSchema($objectclass); } /** * Return the schema for the given attribute. * * @param string $attribute Fetch the schema for this attribute. * * @return array The schema for the given attribute. * * @throws Horde_Kolab_Server_Exception If retrieval of the schema failed. */ public function getAttributeSchema($attribute) { if (!empty($this->_config['schema_support'])) { $schema = $this->_getSchema(); $info = $schema->get('attribute', $attribute); $this->_handleError($info, Horde_Kolab_Server_Exception::SYSTEM); return $info; } return parent::getAttributeSchema($attribute); } /** * Return the attributes supported by the given object class. * * @param string $class Determine the attributes for this class. * * @return array The supported attributes. * * @throws Horde_Kolab_Server_Exception If the schema analysis fails. */ public function getExternalAttributes($class) { $childclass = get_class($class); $classes = array(); $level = 0; while ($childclass != 'Horde_Kolab_Server_Object_Top' && $level < self::MAX_HIERARCHY) { $classes[] = $childclass; $childclass = get_parent_class($childclass); $level++; } /** Finally add the basic object class */ $classes[] = $childclass; //@todo: Throw exception here if ($level == self::MAX_HIERARCHY) { if (isset($this->logger)) { $logger->err(sprintf('The maximal level of the object hierarchy has been exceeded for class \"%s\"!', $class)); } } /** * Collect attributes from bottom to top. */ $classes = array_reverse($classes); $attributes = array(); foreach ($classes as $childclass) { $vars = get_class_vars($childclass); if (isset($vars['attributes'])) { /** * If the user wishes to adhere to the schema * information from the server we will skip the * attributes defined within the object class here. */ if (!empty($this->params['schema_override'])) { continue; } $attributes = array_merge($vars['attributes'], $attributes); } } /* $attrs = array(); */ /* foreach ($object_classes as $object_class) { */ /* $info = $this->getObjectclassSchema($object_class); */ /* if (isset($info['may'])) { */ /* $defined = array_merge($defined, $info['may']); */ /* } */ /* if (isset($info['must'])) { */ /* $defined = array_merge($defined, $info['must']); */ /* $required = array_merge($required, $info['must']); */ /* } */ /* foreach ($defined as $attribute) { */ /* try { */ /* $attrs[$attribute] = $this->getAttributeSchema($attribute); */ /* } catch (Horde_Kolab_Server_Exception $e) { */ /* /\** */ /* * If the server considers the attribute to be */ /* * invalid we mark it. */ /* *\/ */ /* $attrs[$attribute] = array('invalid' => true); */ /* } */ /* } */ /* foreach ($required as $attribute) { */ /* $attrs[$attribute]['required'] = true; */ /* } */ /* foreach ($locked as $attribute) { */ /* $attrs[$attribute]['locked'] = true; */ /* } */ /* foreach ($defaults as $attribute => $default) { */ /* $attrs[$attribute]['default'] = $default; */ /* } */ /* $attrs[Horde_Kolab_Server_Object::ATTRIBUTE_OC]['default'] = $object_classes; */ /* } */ /* foreach ($derived as $key => $attributes) { */ /* $supported = true; */ /* if (isset($attributes['base'])) { */ /* foreach ($attributes['base'] as $attribute) { */ /* /\** */ /* * Usually derived attribute are determined on basis */ /* * of one or more attributes. If any of these is not */ /* * supported the derived attribute should not be */ /* * included into the set of supported attributes. */ /* *\/ */ /* if (!isset($attrs[$attribute])) { */ /* unset($derived[$attribute]); */ /* $supported = false; */ /* break; */ /* } */ /* } */ /* } */ /* if ($supported) { */ /* $attrs[$key] = $attributes; */ /* } */ /* } */ /* $check_collapsed = $collapsed; */ /* foreach ($check_collapsed as $key => $attributes) { */ /* if (isset($attributes['base'])) { */ /* foreach ($attributes['base'] as $attribute) { */ /* /\** */ /* * Usually collapsed attribute are determined on basis */ /* * of one or more attributes. If any of these is not */ /* * supported the collapsed attribute should not be */ /* * included into the set of supported attributes. */ /* *\/ */ /* if (!isset($attrs[$attribute])) { */ /* unset($collapsed[$attribute]); */ /* } */ /* } */ /* } */ /* } */ /* $this->attributes[$class] = array($attrs, */ /* array( */ /* 'derived' => array_keys($derived), */ /* 'collapsed' => $collapsed, */ /* 'locked' => $locked, */ /* 'required' => $required)); */ return $attributes; } /** * Stores the attribute definitions in the cache. * * @return Horde_Kolab_Server The concrete Horde_Kolab_Server reference. */ public function shutdown() { if (isset($this->attributes)) { if (isset($this->cache)) { foreach ($this->attributes as $key => $value) { $this->cache->set('attributes_' . $key, @serialize($value)); } } } } }Horde_Kolab_Server-2.0.5/lib/Horde/Kolab/Server/Schema/Interface.php0000664000175000017500000000352012653735542023253 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * Interface for the schema handler of a Kolab database. * * Copyright 2008-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ interface Horde_Kolab_Server_Schema_Interface { /** * Set the composite server reference for this object. * * @param Horde_Kolab_Server_Composite $composite A link to the composite * server handler. */ public function setComposite( Horde_Kolab_Server_Composite $composite ); /** * Return the schema for the given objectClass. * * @param string $objectclass Fetch the schema for this objectClass. * * @return array The schema for the given objectClass. * * @throws Horde_Kolab_Server_Exception If retrieval of the schema failed. */ public function getObjectclassSchema($objectclass); /** * Return the schema for the given attribute. * * @param string $attribute Fetch the schema for this attribute. * * @return array The schema for the given attribute. * * @throws Horde_Kolab_Server_Exception If retrieval of the schema failed. */ public function getAttributeSchema($attribute); }Horde_Kolab_Server-2.0.5/lib/Horde/Kolab/Server/Search/Operation/Constraint/Single.php0000664000175000017500000000361712653735542026674 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * Return only a single search result. * * Copyright 2008-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Search_Operation_Constraint_Single implements Horde_Kolab_Server_Search_Operation_Interface { /** * A link to the search. * * @var Horde_Kolab_Server_Search_Operation */ private $_search; /** * Constructor * * @param Horde_Kolab_Server_Search $search The search being restricted. */ public function __construct( Horde_Kolab_Server_Search_Operation_Interface $search ) { $this->_search = $search; } /** * Return the reference to the server structure. * * @return Horde_Kolab_Server_Structure_Interface */ public function getStructure() { return $this->_search->getStructure(); } /** * Delegate to the actual search operation. * * @param string $method The name of the called method. * @param array $args Arguments of the call. * * @return array The search result. */ public function __call($method, $args) { $args = func_get_args(); $result = call_user_func_array(array($this->_search, $method), $args); return array_shift($result); } }Horde_Kolab_Server-2.0.5/lib/Horde/Kolab/Server/Search/Operation/Constraint/Strict.php0000664000175000017500000000432612653735542026721 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * Ensures that a search yields only a single return value. * * Copyright 2008-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Search_Operation_Constraint_Strict implements Horde_Kolab_Server_Search_Operation_Interface { /** * A link to the search. * * @var Horde_Kolab_Server_Search */ private $_search; /** * Constructor * * @param Horde_Kolab_Server_Search $search The search being restricted. */ public function __construct( Horde_Kolab_Server_Search_Operation_Interface $search ) { $this->_search = $search; } /** * Return the reference to the server structure. * * @return Horde_Kolab_Server_Structure_Interface */ public function getStructure() { return $this->_search->getStructure(); } /** * Delegate to the actual search operation. * * @param string $method The name of the called method. * @param array $args Arguments of the call. * * @return array The search result. */ public function __call($method, $args) { $result = call_user_func_array(array($this->_search, $method), $args); if (count($result) > 1) { throw new Horde_Kolab_Server_Exception( sprintf( "Found %s results when expecting only one!", count($result) ), Horde_Kolab_Server_Exception::SEARCH_CONSTRAINT_TOO_MANY ); } return array_shift($result); } }Horde_Kolab_Server-2.0.5/lib/Horde/Kolab/Server/Search/Operation/Addressesforuidormail.php0000664000175000017500000000774212653735542027664 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * Return the mail addresses of the KolabInetOrgPersons with the given uid or * mail address and include all alias and delegate addresses. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Search_Operation_Addressesforuidormail extends Horde_Kolab_Server_Search_Operation_Base { /** * The basic attribute search. * * @var Horde_Kolab_Server_Search_Operation */ private $_search; /** * Constructor * * @param Horde_Kolab_Server_Composite $composite A link to the composite * server handler. */ public function __construct(Horde_Kolab_Server_Composite $composite) { $this->_composite = $composite; $this->_search = new Horde_Kolab_Server_Search_Operation_Attributes( $this->getComposite() ); } /** * Return the mail addresses of the KolabInetOrgPersons with the given uid * or mail address and include all alias and delegate addresses. * * @param string $uid The uid to search for. * @param string $mail The mail address to search for. * * @return array The GUID(s). * * @throws Horde_Kolab_Server_Exception */ public function searchAddressesForUidOrMail($uid, $mail) { $criteria = new Horde_Kolab_Server_Query_Element_And( new Horde_Kolab_Server_Query_Element_Equals( 'Objectclass', Horde_Kolab_Server_Object_Kolabinetorgperson::OBJECTCLASS_KOLABINETORGPERSON ), new Horde_Kolab_Server_Query_Element_Or( new Horde_Kolab_Server_Query_Element_Equals( 'Uid', $uid ), new Horde_Kolab_Server_Query_Element_Equals( 'Mail', $mail ) ) ); $search = new Horde_Kolab_Server_Search_Operation_Constraint_Strict( $this->_search ); $data = $search->searchAttributes( $criteria, array('Mail', 'Alias') ); if (empty($data)) { return array(); } $mail = $this->getComposite()->structure->getAttributeInternal( 'Mail' ); $alias = $this->getComposite()->structure->getAttributeInternal( 'Alias' ); if (isset($result[$alias])) { $addrs = array_merge($data[$mail], $data[$alias]); } else { $addrs = $data[$mail]; } $criteria = new Horde_Kolab_Server_Query_Element_And( new Horde_Kolab_Server_Query_Element_Equals( 'Objectclass', Horde_Kolab_Server_Object_Kolabinetorgperson::OBJECTCLASS_KOLABINETORGPERSON ), new Horde_Kolab_Server_Query_Element_Equals( 'Delegate', $data[$mail][0] ) ); $data = $this->_search->searchAttributes( $criteria, array('Mail', 'Alias') ); if (!empty($data)) { foreach ($data as $adr) { if (isset($adr[$mail])) { $addrs = array_merge($addrs, $adr[$mail]); } if (isset($adr[$alias])) { $addrs = array_merge($addrs, $adr[$alias]); } } } $addrs = array_map('Horde_String::lower', $addrs); return $addrs; } }Horde_Kolab_Server-2.0.5/lib/Horde/Kolab/Server/Search/Operation/Attributes.php0000664000175000017500000000262712653735542025455 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * Basic attributes search. * * Copyright 2008-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Search_Operation_Attributes extends Horde_Kolab_Server_Search_Operation_Base { /** * Perform the search. * * @param Horde_Kolab_Server_Query_Element $criteria The search criteria. * @param array $attributes The attributes to * retrieve. * * @return mixed The search result. */ public function searchAttributes( Horde_Kolab_Server_Query_Element $criteria, array $attributes ) { $params = array('attributes' => $attributes); return $this->getComposite()->structure->find($criteria, $params); } }Horde_Kolab_Server-2.0.5/lib/Horde/Kolab/Server/Search/Operation/Base.php0000664000175000017500000000377312653735542024204 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * An interface marking object class search operations. * * Copyright 2008-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ abstract class Horde_Kolab_Server_Search_Operation_Base implements Horde_Kolab_Server_Search_Operation_Interface { /** * A link to the server structure. * * @var Horde_Kolab_Server_Structure_Interface */ private $_structure; /** * Constructor * * @param Horde_Kolab_Server_Structure_Interface $structure A link to the * server * structure. */ public function __construct( Horde_Kolab_Server_Structure_Interface $structure ) { $this->_structure = $structure; } /** * Return the reference to the server structure. * * @return Horde_Kolab_Server_Structure_Interface */ public function getStructure() { return $this->_structure; } /** * Identify the GUID(s) of the result entry(s). * * @param array $result The LDAP search result. * * @return boolean|array The GUID(s) or false if there was no result. */ protected function guidFromResult( Horde_Kolab_Server_Result_Interface $result ) { return array_keys($result->asArray()); } }Horde_Kolab_Server-2.0.5/lib/Horde/Kolab/Server/Search/Operation/Children.php0000664000175000017500000000274212653735542025055 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * Basic GUID search. * * Copyright 2008-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Search_Operation_Children extends Horde_Kolab_Server_Search_Operation_Base { /** * Perform the search. * * @param string $parent_guid The guid of the parent. * @param string $objectclass The type of children to return. * * @return mixed The search result. */ public function searchChildren($parent_guid, $objectclass) { $criteria = new Horde_Kolab_Server_Query_Element_Equals( 'Objectclass', $objectclass ); $params = array( 'attributes' => Horde_Kolab_Server_Object_Top::ATTRIBUTE_GUID ); $data = $this->_composite->server->findBelow( $criteria, $parent, $params ); return self::guidFromResult($data); } }Horde_Kolab_Server-2.0.5/lib/Horde/Kolab/Server/Search/Operation/Groupsformember.php0000664000175000017500000000252712653735542026504 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * Return the groups for the given member element. * * Copyright 2008-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Search_Operation_Groupsformember extends Horde_Kolab_Server_Search_Operation_Restrictgroups { /** * Return the groups for the given member element. * * @param string $guid The guid of the member. * * @return array The group GUID(s). * * @throws Horde_Kolab_Server_Exception */ public function searchGroupsForMember($guid) { $criteria = new Horde_Kolab_Server_Query_Element_Equals( 'member', $guid ); return parent::searchRestrictGroups($criteria); } }Horde_Kolab_Server-2.0.5/lib/Horde/Kolab/Server/Search/Operation/Guid.php0000664000175000017500000000241512653735542024212 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * Basic GUID search. * * Copyright 2008-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Search_Operation_Guid extends Horde_Kolab_Server_Search_Operation_Base { /** * Perform the search. * * @param Horde_Kolab_Server_Query_Element $criteria The search criteria. * * @return array The search result. */ public function searchGuid( Horde_Kolab_Server_Query_Element_Interface $criteria ) { $params = array( 'attributes' => 'guid' ); $data = $this->getStructure()->find($criteria, $params); return self::guidFromResult($data); } }Horde_Kolab_Server-2.0.5/lib/Horde/Kolab/Server/Search/Operation/Guidforalias.php0000664000175000017500000000255212653735542025735 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * Return all KolabInetOrgPersons with the given alias address. * * Copyright 2008-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Search_Operation_Guidforalias extends Horde_Kolab_Server_Search_Operation_Restrictkolab { /** * Return all KolabInetOrgPersons with the given alias. * * @param string $alias The alias address to search for. * * @return array The GUID(s). * * @throws Horde_Kolab_Server_Exception */ public function searchGuidForAlias($alias) { $criteria = new Horde_Kolab_Server_Query_Element_Equals( 'alias', $alias ); return parent::searchRestrictKolab($criteria); } }Horde_Kolab_Server-2.0.5/lib/Horde/Kolab/Server/Search/Operation/Guidforcn.php0000664000175000017500000000255412653735542025246 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * Identify the GUID for the objects found with the given common name. * * Copyright 2008-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Search_Operation_Guidforcn extends Horde_Kolab_Server_Search_Operation_Guid { /** * Identify the GUID for the objects found with the given common name. * * @param string $cn Search for objects with this common name. * * @return array The GUID(s). * * @throws Horde_Kolab_Server_Exception */ public function searchGuidForCn($cn) { $criteria = new Horde_Kolab_Server_Query_Element_Equals( 'cn', $cn ); return parent::searchGuid($criteria); } }Horde_Kolab_Server-2.0.5/lib/Horde/Kolab/Server/Search/Operation/Guidforkolabusers.php0000664000175000017500000000251012653735542027010 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * Return the GUIDs of all KolabInetOrgPersons. * * Copyright 2008-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Search_Operation_Guidforkolabusers extends Horde_Kolab_Server_Search_Operation_Guid { /** * Return the GUIDs of all KolabInetOrgPersons. * * @return array The GUID(s). * * @throws Horde_Kolab_Server_Exception */ public function searchGuidForKolabUsers() { $criteria = new Horde_Kolab_Server_Query_Element_Equals( 'Objectclass', Horde_Kolab_Server_Object_Kolabinetorgperson::OBJECTCLASS_KOLABINETORGPERSON ); return parent::searchGuid($criteria); } }Horde_Kolab_Server-2.0.5/lib/Horde/Kolab/Server/Search/Operation/Guidformail.php0000664000175000017500000000253012653735542025562 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * Return all KolabInetOrgPersons with the given mail address. * * Copyright 2008-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Search_Operation_Guidformail extends Horde_Kolab_Server_Search_Operation_Restrictkolab { /** * Return all KolabInetOrgPersons with the given mail. * * @param string $mail The mail to search for. * * @return array The GUID(s). * * @throws Horde_Kolab_Server_Exception */ public function searchGuidForMail($mail) { $criteria = new Horde_Kolab_Server_Query_Element_Equals( 'mail', $mail ); return parent::searchRestrictKolab($criteria); } }Horde_Kolab_Server-2.0.5/lib/Horde/Kolab/Server/Search/Operation/Guidformailoralias.php0000664000175000017500000000320612653735542027136 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * Return all KolabInetOrgPersons with the given mail or alias address. * * Copyright 2008-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Search_Operation_Guidformailoralias extends Horde_Kolab_Server_Search_Operation_Restrictkolab { /** * Return all KolabInetOrgPersons with the given mail or alias address. * * @param string $mail The mail address to search for. * @param string $alias The alias address to search for. * * @return array The GUID(s). * * @throws Horde_Kolab_Server_Exception */ public function searchGuidForMailOrAlias($mail, $alias) { $criteria = new Horde_Kolab_Server_Query_Element_Or( new Horde_Kolab_Server_Query_Element_Equals( 'Mail', $mail ), new Horde_Kolab_Server_Query_Element_Equals( 'Alias', $alias ) ); return parent::searchRestrictKolab($criteria); } }Horde_Kolab_Server-2.0.5/lib/Horde/Kolab/Server/Search/Operation/Guidforuid.php0000664000175000017500000000247612653735542025432 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * Return all KolabInetOrgPersons with the given uid. * * Copyright 2008-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Search_Operation_Guidforuid extends Horde_Kolab_Server_Search_Operation_Restrictkolab { /** * Return all KolabInetOrgPersons with the given uid. * * @param string $uid The uid to search for. * * @return array The GUID(s). * * @throws Horde_Kolab_Server_Exception */ public function searchGuidForUid($uid) { $criteria = new Horde_Kolab_Server_Query_Element_Equals( 'uid', $uid ); return parent::searchRestrictKolab($criteria); } }Horde_Kolab_Server-2.0.5/lib/Horde/Kolab/Server/Search/Operation/Guidforuidormail.php0000664000175000017500000000500312653735542026623 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * Return all KolabInetOrgPersons with the given uid or mail address. * * Copyright 2008-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Search_Operation_Guidforuidormail implements Horde_Kolab_Server_Search_Operation_Interface { /** * A link to the search. * * @var Horde_Kolab_Server_Search */ private $_search; /** * Constructor * * @param Horde_Kolab_Server_Structure_Interface $structure A link to the * server * structure. */ public function __construct( Horde_Kolab_Server_Structure_Interface $structure ) { $this->_search = new Horde_Kolab_Server_Search_Operation_Constraint_Strict( new Horde_Kolab_Server_Search_Operation_Restrictkolab( $structure ) ); } /** * Return the reference to the server structure. * * @return Horde_Kolab_Server_Structure_Interface */ public function getStructure() { return $this->_search->getStructure(); } /** * Return all KolabInetOrgPersons with the given uid or mail address. * * @param string $id The uid or mail address to search for. * * @return array The GUID(s). * * @throws Horde_Kolab_Server_Exception */ public function searchGuidForUidOrMail($id) { $criteria = new Horde_Kolab_Server_Query_Element_Or( array( new Horde_Kolab_Server_Query_Element_Equals( 'Uid', $id ), new Horde_Kolab_Server_Query_Element_Equals( 'Mail', $id ) ) ); return $this->_search->searchRestrictKolab($criteria); } }Horde_Kolab_Server-2.0.5/lib/Horde/Kolab/Server/Search/Operation/Guidforuidormailoralias.php0000664000175000017500000000342012653735542030177 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * Return all KolabInetOrgPersons with the given uid, mail or alias address. * * Copyright 2008-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Search_Operation_Guidforuidormailoralias extends Horde_Kolab_Server_Search_Operation_Restrictkolab { /** * Return all KolabInetOrgPersons with the given uid, mail or alias address. * * @param string $id The uid or mail address or alias address to search for. * * @return array The GUID(s). * * @throws Horde_Kolab_Server_Exception */ public function searchGuidForUidOrMailOrAlias($id) { $criteria = new Horde_Kolab_Server_Query_Element_Or( array( new Horde_Kolab_Server_Query_Element_Equals( 'Uid', $id ), new Horde_Kolab_Server_Query_Element_Equals( 'Mail', $id ), new Horde_Kolab_Server_Query_Element_Equals( 'Alias', $id ) ) ); return parent::searchRestrictKolab($criteria); } }Horde_Kolab_Server-2.0.5/lib/Horde/Kolab/Server/Search/Operation/Interface.php0000664000175000017500000000200112653735542025211 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * An interface marking object class search operations. * * Copyright 2008-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ interface Horde_Kolab_Server_Search_Operation_Interface { /** * Return the reference to the server structure. * * @return Horde_Kolab_Server_Structure_Interface */ public function getStructure(); }Horde_Kolab_Server-2.0.5/lib/Horde/Kolab/Server/Search/Operation/Mailforuidormail.php0000664000175000017500000000552412653735542026625 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * Return the mail address of the KolabInetOrgPersons with the given uid or mail * address. * * Copyright 2008-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Search_Operation_Mailforuidormail extends Horde_Kolab_Server_Search_Operation_Base { /** * The base attribute search. * * @var Horde_Kolab_Server_Search_Operation */ private $_search; /** * Constructor * * @param Horde_Kolab_Server_Composite $composite A link to the composite * server handler. */ public function __construct(Horde_Kolab_Server_Composite $composite) { $this->_composite = $composite; $this->_search = new Horde_Kolab_Server_Search_Operation_Constraint_Strict( new Horde_Kolab_Server_Search_Operation_Attributes( $this->getComposite() ) ); } /** * Return the mail address of the KolabInetOrgPersons with the given uid or * mail address. * * @param string $uid The uid to search for. * @param string $mail The mail address to search for. * * @return array The GUID(s). * * @throws Horde_Kolab_Server_Exception */ public function searchMailForUidOrMail($uid, $mail) { $criteria = new Horde_Kolab_Server_Query_Element_And( new Horde_Kolab_Server_Query_Element_Equals( 'Objectclass', Horde_Kolab_Server_Object_Kolabinetorgperson::OBJECTCLASS_KOLABINETORGPERSON ), new Horde_Kolab_Server_Query_Element_Or( new Horde_Kolab_Server_Query_Element_Equals( 'Uid', $uid ), new Horde_Kolab_Server_Query_Element_Equals( 'Mail', $mail ) ) ); $data = $this->_search->searchAttributes($criteria, array('Mail')); $internal = $this->getComposite()->structure->getAttributeInternal( 'Mail' ); if (!empty($data)) { return $data[$internal][0]; } else { return false; } } }Horde_Kolab_Server-2.0.5/lib/Horde/Kolab/Server/Search/Operation/Restrictgroups.php0000664000175000017500000000310312653735542026354 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * Restrict a search to groupOfNames. * * Copyright 2008-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Search_Operation_Restrictgroups extends Horde_Kolab_Server_Search_Operation_Guid { /** * Restrict a search to groupOfNames. * * @param Horde_Kolab_Server_Query_Element $criteria The search criteria. * * @return array The GUID(s). * * @throws Horde_Kolab_Server_Exception */ public function searchRestrictGroups( Horde_Kolab_Server_Query_Element_Interface $criteria ) { $criteria = new Horde_Kolab_Server_Query_Element_And( array( new Horde_Kolab_Server_Query_Element_Equals( 'objectClass', Horde_Kolab_Server_Object_Groupofnames::OBJECTCLASS_GROUPOFNAMES ), $criteria ) ); return parent::searchGuid($criteria); } }Horde_Kolab_Server-2.0.5/lib/Horde/Kolab/Server/Search/Operation/Restrictkolab.php0000664000175000017500000000314212653735542026130 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * Restrict a search to KolabInetOrgPersons. * * Copyright 2008-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Search_Operation_Restrictkolab extends Horde_Kolab_Server_Search_Operation_Guid { /** * Restrict a search to KolabInetOrgPersons. * * @param Horde_Kolab_Server_Query_Element $criteria The search criteria. * * @return array The GUID(s). * * @throws Horde_Kolab_Server_Exception */ public function searchRestrictKolab( Horde_Kolab_Server_Query_Element_Interface $criteria ) { $criteria = new Horde_Kolab_Server_Query_Element_And( array( new Horde_Kolab_Server_Query_Element_Equals( 'objectClass', Horde_Kolab_Server_Object_Kolabinetorgperson::OBJECTCLASS_KOLABINETORGPERSON ), $criteria ) ); return parent::searchGuid($criteria); } }Horde_Kolab_Server-2.0.5/lib/Horde/Kolab/Server/Search/Base.php0000664000175000017500000000754312653735542022243 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * Handles search operations provided by the objects registered to the * server structure. * * Copyright 2008-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Search_Base implements Horde_Kolab_Server_Search_Interface { /** * A link to the composite server handler. * * @var Horde_Kolab_Server_Composite */ private $_composite; /** * The search methods offered by the object defined for this server. * * @var array */ private $_searches; /** * Set the composite server reference for this object. * * @param Horde_Kolab_Server_Composite $composite A link to the composite * server handler. * * @return NULL */ public function setComposite( Horde_Kolab_Server_Composite $composite ) { $this->_composite = $composite; $this->_searches = $this->_getSearchOperations(); } /** * Returns the set of search operations supported by this server type. * * @return array An array of supported search operations. */ private function _getSearchOperations() { $server_searches = array(); foreach ($this->_composite->structure->getSearchOperations() as $search_class) { if (!class_exists($search_class)) { throw new Horde_Kolab_Server_Exception( sprintf( "%s::getSearchOperations specified non-existing class \"%s\"!", get_class($this->_composite->structure), $search_class ) ); } $methods = get_class_methods($search_class); unset($methods['getComposite']); unset($methods['__construct']); foreach ($methods as $method) { $server_searches[$method] = array('class' => $search_class); } } return $server_searches; } /** * Returns the set of search operations supported by this server type. * * @return array An array of supported search operations. */ public function getSearchOperations() { return $this->_searches; } /** * Capture undefined calls and assume they refer to a search operation. * * @param string $method The name of the called method. * @param array $args Arguments of the call. * * @return NULL. * * @throws Horde_Kolab_Server_Exception */ public function __call($method, $args) { if (in_array($method, array_keys($this->_searches))) { $class = $this->_searches[$method]['class']; $search = new $class($this->_composite->structure); return call_user_func_array(array($search, $method), $args); } throw new Horde_Kolab_Server_Exception( sprintf( "The server type \"%s\" with structure \"%s\" does not support" . " method \"%s\"!", get_class($this->_composite->server), get_class($this->_composite->structure), $method ) ); } }Horde_Kolab_Server-2.0.5/lib/Horde/Kolab/Server/Search/Interface.php0000664000175000017500000000320612653735542023261 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * Defines the interface of the search handler for a Kolab Server. * * Copyright 2008-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ interface Horde_Kolab_Server_Search_Interface { /** * Set the composite server reference for this object. * * @param Horde_Kolab_Server_Composite $composite A link to the composite * server handler. */ public function setComposite( Horde_Kolab_Server_Composite $composite ); /** * Returns the set of search operations supported by this server type. * * @return array An array of supported search operations. */ public function getSearchOperations(); /** * Capture undefined calls. * * @param string $method The name of the called method. * @param array $args Arguments of the call. * * @return NULL. * * @throws Horde_Kolab_Server_Exception */ public function __call($method, $args); }Horde_Kolab_Server-2.0.5/lib/Horde/Kolab/Server/Structure/Attribute/Double.php0000664000175000017500000000502712653735542025334 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * An adapter for attributes that rely on two internal Kolab object attributes. * * Copyright 2009-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Structure_Attribute_Double implements Horde_Kolab_Server_Structure_Attribute_Interface { /** * The attribute names. * * @param array */ protected $names; /** * The object the attribute belongs to. * * @param Horde_Kolab_Server_Object_Interface */ protected $object; /** * Constructor * * @param Horde_Kolab_Server_Object_Interface $object The object * this attribute belongs to. * @param string $name The name of this attribute. */ public function __construct( Horde_Kolab_Server_Object_Interface $object, array $names ) { $this->object = $object; $this->names = $names; } /** * Return the internal attribute adapter. * * @return Horde_Kolab_Server_Object_Interface The object the attribute belongs to. */ public function getObject() { return $this->object; } /** * Return the name of this attribute. * * @return string The name of this attribute. */ public function getName() { return $this->names; } /** * Return the value of this attribute. * * @return array The value of the attribute */ public function value() { return $this->object->getInternal($this->names); } /** * Return the new internal state for this attribute. * * @param array $changes The object data that should be updated. * * @return array The resulting internal state. * * @throws Horde_Kolab_Server_Exception If storing the value failed. */ public function update(array $changes) { return array(); } }Horde_Kolab_Server-2.0.5/lib/Horde/Kolab/Server/Structure/Attribute/Interface.php0000664000175000017500000000322712653735542026022 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * The interface describing internal Kolab object attributes. * * Copyright 2009-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ interface Horde_Kolab_Server_Structure_Attribute_Interface { /** * Return the internal attribute adapter. * * @return Horde_Kolab_Server_Object_Interface The object the attribute belongs to. */ public function getObject(); /** * Return the name of this attribute. * * @return string The name of this attribute. */ public function getName(); /** * Return the value of this attribute. * * @return array The value of the attribute */ public function value(); /** * Return the new internal state for this attribute. * * @param array $changes The object data that should be updated. * * @return array The resulting internal state. * * @throws Horde_Kolab_Server_Exception If storing the value failed. */ public function update(array $changes); }Horde_Kolab_Server-2.0.5/lib/Horde/Kolab/Server/Structure/Attribute/Value.php0000664000175000017500000000476512653735542025206 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * The base class representing internal Kolab object attributes. * * Copyright 2009-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Structure_Attribute_Value implements Horde_Kolab_Server_Structure_Attribute_Interface { /** * The attribute name. * * @param string */ protected $name; /** * The object the attribute belongs to. * * @param Horde_Kolab_Server_Object_Interface */ protected $object; /** * Constructor * * @param Horde_Kolab_Server_Object_Interface $object The object * this attribute belongs to. * @param string $name The name of this attribute. */ public function __construct( Horde_Kolab_Server_Object_Interface $object, $name ) { $this->object = $object; $this->name = $name; } /** * Return the internal attribute adapter. * * @return Horde_Kolab_Server_Object_Interface The object the attribute belongs to. */ public function getObject() { return $this->object; } /** * Return the name of this attribute. * * @return string The name of this attribute. */ public function getName() { return $this->name; } /** * Return the value of this attribute. * * @return array The value of the attribute */ public function value() { return $this->object->getInternal((array) $this->name); } /** * Return the new internal state for this attribute. * * @param array $changes The object data that should be updated. * * @return array The resulting internal state. * * @throws Horde_Kolab_Server_Exception If storing the value failed. */ public function update(array $changes) { return array(); } }Horde_Kolab_Server-2.0.5/lib/Horde/Kolab/Server/Structure/Base.php0000664000175000017500000001207412653735542023031 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * An abstract class definiing methods to deal with an object tree structure. * * Copyright 2009-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ abstract class Horde_Kolab_Server_Structure_Base implements Horde_Kolab_Server_Structure_Interface { /** Maximum accepted level for the object class hierarchy */ const MAX_HIERARCHY = 100; /** * A link to the composite server handler. * * @var Horde_Kolab_Server_Composite */ private $_composite; /** * Finds object data matching a given set of criteria. * * @param Horde_Kolab_Server_Query_Element $criteria The criteria for the search. * @param array $params Additional search parameters. * * @return Horde_Kolab_Server_Result The result object. * * @throws Horde_Kolab_Server_Exception */ public function find( Horde_Kolab_Server_Query_Element_Interface $criteria, array $params = array() ) { $query = new Horde_Kolab_Server_Query_Ldap($criteria, $this); return $this->_composite->server->find( (string) $query, $params ); } /** * Finds all object data below a parent matching a given set of criteria. * * @param Horde_Kolab_Server_Query_Element $criteria The criteria for the search. * @param string $parent The parent to search below. * @param array $params Additional search parameters. * * @return Horde_Kolab_Server_Result The result object. * * @throws Horde_Kolab_Server_Exception */ public function findBelow( Horde_Kolab_Server_Query_Element_Interface $criteria, $parent, array $params = array() ) { $query = new Horde_Kolab_Server_Query_Ldap($criteria, $this); return $this->_composite->server->findBelow( (string) $query, $parent, $params ); } /** * Set the composite server reference for this object. * * @param Horde_Kolab_Server_Composite $composite A link to the composite * server handler. * * @return NULL */ public function setComposite( Horde_Kolab_Server_Composite $composite ) { $this->_composite = $composite; } /** * Get the composite server reference for this object. * * @return Horde_Kolab_Server_Composite A link to the composite server * handler. */ public function getComposite() { return $this->_composite; } /** * Return the attributes supported by the given object class. * * @param string $class Determine the attributes for this class. * * @return array The supported attributes. * * @throws Horde_Kolab_Server_Exception If the schema analysis fails. */ public function getExternalAttributes($class) { $childclass = get_class($class); $classes = array(); $level = 0; while ($childclass != 'Horde_Kolab_Server_Object_Top' && $level < self::MAX_HIERARCHY) { $classes[] = $childclass; $childclass = get_parent_class($childclass); $level++; } /** Finally add the basic object class */ $classes[] = $childclass; //@todo: Throw exception here if ($level == self::MAX_HIERARCHY) { if (isset($this->logger)) { $logger->err(sprintf('The maximal level of the object hierarchy has been exceeded for class \"%s\"!', $class)); } } /** * Collect attributes from bottom to top. */ $classes = array_reverse($classes); $attributes = array(); foreach ($classes as $childclass) { $vars = get_class_vars($childclass); if (isset($vars['attributes'])) { $attributes = array_merge($vars['attributes'], $attributes); } } return $attributes; } public function getInternalAttributes($class) { return $this->mapExternalToInternalAttributes( $this->getExternalAttributes($class) ); } public function getInternalAttributesForExternal($class, $external) { return $this->mapExternalToInternalAttributes((array) $external); } } Horde_Kolab_Server-2.0.5/lib/Horde/Kolab/Server/Structure/Interface.php0000664000175000017500000001135512653735542024060 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * The interface definition for the handlers dealing with the Kolab Server * object tree structure. * * Copyright 2009-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ interface Horde_Kolab_Server_Structure_Interface { /** * Finds object data matching a given set of criteria. * * @param Horde_Kolab_Server_Query_Element $criteria The criteria for the search. * @param array $params Additional search parameters. * * @return Horde_Kolab_Server_Result The result object. * * @throws Horde_Kolab_Server_Exception */ public function find( Horde_Kolab_Server_Query_Element_Interface $criteria, array $params = array() ); /** * Finds all object data below a parent matching a given set of criteria. * * @param Horde_Kolab_Server_Query_Element $criteria The criteria for the search. * @param string $parent The parent to search below. * @param array $params Additional search parameters. * * @return Horde_Kolab_Server_Result The result object. * * @throws Horde_Kolab_Server_Exception */ public function findBelow( Horde_Kolab_Server_Query_Element_Interface $criteria, $parent, array $params = array() ); /** * Set the composite server reference for this object. * * @param Horde_Kolab_Server_Composite $composite A link to the composite * server handler. * * @return NULL */ public function setComposite( Horde_Kolab_Server_Composite $composite ); /** * Returns the set of objects supported by this structure. * * @return array An array of supported objects. */ public function getSupportedObjects(); /** * Returns the set of search operations supported by this object type. * * @return array An array of supported search operations. */ public function getSearchOperations(); /** * Maps the external attribute name to its internal counterpart. * * @param string $external The external attribute name. * * @return string The internal attribute name. */ public function mapExternalToInternalAttribute($external); /** * Return the external attributes supported by the given object class. * * @param Horde_Kolab_Server_Object $object Determine the external * attributes for this class. * * @return array The supported attributes. * * @throws Horde_Kolab_Server_Exception If the schema analysis fails. */ public function getExternalAttributes($object); /** * Return the internal attributes supported by the given object class. * * @param Horde_Kolab_Server_Object $object Determine the internal * attributes for this class. * * @return array The supported attributes. * * @throws Horde_Kolab_Server_Exception If the schema analysis fails. */ public function getInternalAttributes($object); public function getExternalAttribute( $name, Horde_Kolab_Server_Object_Interface $object ); /** * Determine the type of an object by its tree position and other * parameters. * * @param string $guid The GUID of the object to examine. * * @return string The class name of the corresponding object type. * * @throws Horde_Kolab_Server_Exception If the object type is unknown. */ public function determineType($guid); /** * Generates a UID for the given information. * * @param string $type The class name of the object to create. * @param string $id The id of the object. * @param array $info Any additional information about the object to create. * * @return string The GUID. * * @throws Horde_Kolab_Server_Exception If the given type is unknown. */ public function generateServerGuid($type, $id, array $info); } Horde_Kolab_Server-2.0.5/lib/Horde/Kolab/Server/Structure/Kolab.php0000664000175000017500000001766412653735542023221 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * This class provides methods to deal with Kolab objects stored in * the standard Kolab LDAP db. * * Copyright 2008-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Structure_Kolab extends Horde_Kolab_Server_Structure_Ldap { /** * Returns the set of objects supported by this structure. * * @return array An array of supported objects. */ public function getSupportedObjects() { return array( 'Horde_Kolab_Server_Object', 'Horde_Kolab_Server_Object_Groupofnames', 'Horde_Kolab_Server_Object_Person', 'Horde_Kolab_Server_Object_Organizationalperson', 'Horde_Kolab_Server_Object_Inetorgperson', 'Horde_Kolab_Server_Object_Kolab', 'Horde_Kolab_Server_Object_Kolabinetorgperson', 'Horde_Kolab_Server_Object_Kolabgermanbankarrangement', 'Horde_Kolab_Server_Object_Kolabpop3account', 'Horde_Kolab_Server_Object_Kolabgroupofnames', 'Horde_Kolab_Server_Object_Kolabsharedfolder', 'Horde_Kolab_Server_Object_Kolab_Address', 'Horde_Kolab_Server_Object_Kolab_Administrator', 'Horde_Kolab_Server_Object_Kolab_Distlist', 'Horde_Kolab_Server_Object_Kolab_Domainmaintainer', 'Horde_Kolab_Server_Object_Kolab_Maintainer', 'Horde_Kolab_Server_Object_Kolab_User', ); } /** * Returns the set of search operations supported by this object type. * * @return array An array of supported search operations. */ public function getSearchOperations() { $searches = array( 'Horde_Kolab_Server_Search_Operation_Guid', 'Horde_Kolab_Server_Search_Operation_Attributes', 'Horde_Kolab_Server_Search_Operation_Children', 'Horde_Kolab_Server_Search_Operation_Guidforcn', 'Horde_Kolab_Server_Search_Operation_Guidforkolabusers', 'Horde_Kolab_Server_Search_Operation_Guidforuid', 'Horde_Kolab_Server_Search_Operation_Guidformail', 'Horde_Kolab_Server_Search_Operation_Guidforuidormail', 'Horde_Kolab_Server_Search_Operation_Guidforalias', 'Horde_Kolab_Server_Search_Operation_Guidformailoralias', 'Horde_Kolab_Server_Search_Operation_Guidforuidormailoralias', 'Horde_Kolab_Server_Search_Operation_Mailforuidormail', 'Horde_Kolab_Server_Search_Operation_Addressesforuidormail', 'Horde_Kolab_Server_Search_Operation_Groupsformember', ); return $searches; } /** * Determine the type of an object by its tree position and other * parameters. * * @param string $guid The GUID of the object to examine. * @param array $ocs The object classes of the object to examine. * * @return string The class name of the corresponding object type. * * @throws Horde_Kolab_Server_Exception If the object type is unknown. */ protected function _determineType($guid, array $ocs) { // Not a user type? if (!in_array('kolabinetorgperson', $ocs)) { // Is it a group? if (in_array('kolabgroupofnames', $ocs)) { return 'Horde_Kolab_Server_Object_Kolabgroupofnames'; } // Is it an external pop3 account? if (in_array('kolabexternalpop3account', $ocs)) { return 'Horde_Kolab_Server_Object_Kolabpop3account'; } // Is it a shared Folder? if (in_array('kolabsharedfolder', $ocs)) { return 'Horde_Kolab_Server_Object_Kolabsharedfolder'; } return parent::_determineType($guid, $ocs); } $groups = $this->getComposite()->search->searchGroupsForMember($guid); if (!empty($groups)) { $base = $this->getComposite()->server->getBaseGuid(); if (in_array('cn=admin,cn=internal,' . $base, $groups)) { return 'Horde_Kolab_Server_Object_Kolab_Administrator'; } if (in_array('cn=maintainer,cn=internal,' . $base, $groups)) { return 'Horde_Kolab_Server_Object_Kolab_Maintainer'; } if (in_array('cn=domain-maintainer,cn=internal,' . $base, $groups)) { return 'Horde_Kolab_Server_Object_Kolab_Domainmaintainer'; } } if (strpos($guid, 'cn=external') !== false) { return 'Horde_Kolab_Server_Object_Kolab_Address'; } return 'Horde_Kolab_Server_Object_Kolab_User'; } /** * Generates a UID for the given information. * * @param string $type The class name of the object to create. * @param string $id The id of the object. * @param array $info Any additional information about the object to create. * * @return string The UID. * * @throws Horde_Kolab_Server_Exception If the given type is unknown. */ public function generateServerGuid($type, $id, array $info) { switch ($type) { case 'Horde_Kolab_Server_Object_Kolab_User': if (empty($info['user_type'])) { return parent::generateServerGuid($type, $id, $info); } else if ($info['user_type'] == Horde_Kolab_Server_Object_Kolab_User::USERTYPE_INTERNAL) { return parent::generateServerGuid($type, sprintf('%s,cn=internal', $id), $info); } else if ($info['user_type'] == Horde_Kolab_Server_Object_Kolab_User::USERTYPE_GROUP) { return parent::generateServerGuid($type, sprintf('%s,cn=groups', $id), $info); } else if ($info['user_type'] == Horde_Kolab_Server_Object_Kolab_User::USERTYPE_RESOURCE) { return parent::generateServerGuid($type, sprintf('%s,cn=resources', $id), $info); } else { return parent::generateServerGuid($type, $id, $info); } case 'Horde_Kolab_Server_Object_Kolab_Address': return parent::generateServerGuid($type, sprintf('%s,cn=external', $id), $info); case 'Horde_Kolab_Server_Object_Kolabgroupofnames': case 'Horde_Kolab_Server_Object_Kolab_Distlist': if (!isset($info['visible']) || !empty($info['visible'])) { return parent::generateServerGuid($type, $id, $info); } else { return parent::generateServerGuid($type, sprintf('%s,cn=internal', $id), $info); } case 'Horde_Kolab_Server_Object_Kolabsharedfolder': case 'Horde_Kolab_Server_Object_Kolab_Administrator': case 'Horde_Kolab_Server_Object_Kolab_Maintainer': case 'Horde_Kolab_Server_Object_Kolab_Domainmaintainer': default: return parent::generateServerGuid($type, $id, $info); } } } Horde_Kolab_Server-2.0.5/lib/Horde/Kolab/Server/Structure/Ldap.php0000664000175000017500000002376312653735542023046 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * This class provides methods to deal with the LDAP tree structure. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Structure_Ldap extends Horde_Kolab_Server_Structure_Base { /** * Returns the set of objects supported by this structure. * * @return array An array of supported objects. */ public function getSupportedObjects() { return array( 'Horde_Kolab_Server_Object', ); } /** * Returns the set of search operations supported by this object type. * * @return array An array of supported search operations. */ public function getSearchOperations() { $searches = array( 'Horde_Kolab_Server_Search_Operation_Guid', 'Horde_Kolab_Server_Search_Operation_Attributes', 'Horde_Kolab_Server_Search_Operation_Children', 'Horde_Kolab_Server_Search_Operation_Guidforcn', ); return $searches; } /** * Determine the type of an object by its tree position and other * parameters. * * @param string $guid The GUID of the object to examine. * * @return string The class name of the corresponding object type. * * @throws Horde_Kolab_Server_Exception If the object type is unknown. */ public function determineType($guid) { $ocs = $this->getObjectClasses($guid); return $this->_determineType($guid, $ocs); } /** * Determine the type of an object by its tree position and other * parameters. * * @param string $guid The GUID of the object to examine. * @param array $ocs The object classes of the object to examine. * * @return string The class name of the corresponding object type. * * @throws Horde_Kolab_Server_Exception If the object type is unknown. */ protected function _determineType($guid, array $ocs) { $ocs = array_reverse($ocs); foreach ($ocs as $oc) { try { $class_name = 'Horde_Kolab_Server_Object_' . Horde_String::ucfirst(Horde_String::lower($oc)); Horde_Kolab_Server_Object_Factory::loadClass($class_name); return $class_name; } catch (Horde_Kolab_Server_Exception $e) { } } throw new Horde_Kolab_Server_Exception( sprintf("Unknown object type for GUID %s.", $guid), Horde_Kolab_Server_Exception::SYSTEM ); } /** * Generates a GUID for the given information. * * @param string $type The class name of the object to create. * @param string $id The id of the object. * @param array $info Any additional information about the object to create. * * @return string The GUID. */ public function generateServerGuid($type, $id, array $info) { return sprintf('%s,%s', $id, $this->getComposite()->server->getBaseGuid()); } /** * Get the LDAP object classes for the given GUID. * * This is meant to be a shortcut for the structure handler. It should be * used when determining the object type. * * @param string $guid GUID of the object. * * @return array An array of object classes. * * @throws Horde_Kolab_Server_Exception If the object has no * object classes. */ protected function getObjectClasses($guid) { $object = $this->getComposite()->server->read( $guid, array('objectClass') ); if (!isset($object['objectClass'])) { throw new Horde_Kolab_Server_Exception( sprintf( "The object %s has no %s attribute!", $guid, 'objectClass' ), Horde_Kolab_Server_Exception::SYSTEM ); } $result = array_map( 'Horde_String::lower', $object['objectClass'] ); return $result; } public function getExternalAttribute( $name, Horde_Kolab_Server_Object_Interface $object ) { $class = Horde_String::ucfirst(Horde_String::lower($name)); $object_attribute_class = 'Horde_Kolab_Server_Object_Attribute_' . $class; $structure_attribute_class = 'Horde_Kolab_Server_Structure_Attribute_' . $class; if (class_exists($structure_attribute_class)) { $structure_attribute = new $structure_attribute_class($object, $name); } else { switch ($name) { case 'Firstnamelastname': $structure_attribute = new Horde_Kolab_Server_Structure_Attribute_Double( $object, array('givenName', 'sn') ); break; default: $structure_attribute = new Horde_Kolab_Server_Structure_Attribute_Value( $object, $name ); break; } } switch ($name) { case 'objectClass': $structure_attribute = new Horde_Kolab_Server_Structure_Attribute_Locked( $structure_attribute ); default: break; } if (class_exists($object_attribute_class)) { $object_attribute = new $object_attribute_class($structure_attribute, $name); } else { switch ($name) { default: $object_attribute = new Horde_Kolab_Server_Object_Attribute_Value( $structure_attribute, $name ); break; } } /* case 'Guid': */ /* return 'dn'; */ /* case 'Uid': */ /* return 'uid'; */ /* case 'Mail': */ /* return 'mail'; */ /* case 'Alias': */ /* return 'alias'; */ /* case 'Delegate': */ /* return 'kolabDelegate'; */ /* case 'Firstnamelastname': */ /* return array('givenName', 'sn'); */ /* case 'Openldapaci': */ /* return 'openLDAPaci'; */ /* case 'Kolabhomeserver': */ /* return 'kolabHomeServer'; */ /* case 'Kolabfreebusyhost': */ /* //@todo: rename to kolabFreeBusyService(Url) */ /* return 'kolabFreeBusyServer'; */ /* case 'Createtimestamp': */ /* case 'Createtimestampdate': */ /* return 'createTimeStamp'; */ /* case 'Modifytimestamp': */ /* case 'Modifytimestampdate': */ /* return 'modifyTimeStamp'; */ /* case 'Id': */ /* return null; */ /* default: */ /* throw new Horde_Kolab_Server_Exception( */ /* sprintf('Undefined internal attribute "%s"', $external) */ /* ); */ /* } */ return $object_attribute; } /** * Maps the external attribute name to its internal counterpart(s). * * @param string $external The external attribute name. * * @return string The internal attribute name(s). */ private function _mapExternalToInternal($external) { switch ($external) { case 'Guid': return 'dn'; case 'Uid': return 'uid'; case 'Mail': return 'mail'; case 'Alias': return 'alias'; case 'Delegate': return 'kolabDelegate'; case 'Firstnamelastname': return array('givenName', 'sn'); case 'Openldapaci': return 'openLDAPaci'; case 'Kolabhomeserver': return 'kolabHomeServer'; case 'Kolabfreebusyhost': //@todo: rename to kolabFreeBusyService(Url) return 'kolabFreeBusyServer'; case 'Createtimestamp': case 'Createtimestampdate': return 'createTimeStamp'; case 'Modifytimestamp': case 'Modifytimestampdate': return 'modifyTimeStamp'; case 'Id': return null; default: return $external; } } /** * Maps the external attribute name to its internal counterpart. * * @param string $external The external attribute name. * * @return string The internal attribute name. */ public function mapExternalToInternalAttribute($external) { $internal = $this->_mapExternalToInternal($external); if (is_string($internal)) { return $internal; } else if (is_array($internal)) { throw new Horde_Kolab_Server_Exception('Multiple internal attributes!'); } else if ($internal === null) { throw new Horde_Kolab_Server_Exception('No internal attribute mapping!'); } throw new Horde_Kolab_Server_Exception( sprintf( 'Invalid internal attribute mapping: %s', print_r($internal, true) ) ); } /** * Maps the external attribute names to their internal counterparts. * * @param string $external The external attribute names. * * @return string The internal attribute names. */ public function mapExternalToInternalAttributes(array $external) { $result = array(); foreach ($external as $attribute) { $internal = $this->_mapExternalToInternal($attribute); $result = array_merge($result, (array) $internal); } $result = array_unique($result); return $result; } } Horde_Kolab_Server-2.0.5/lib/Horde/Kolab/Server/Composite.php0000664000175000017500000000670012653735542022120 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * A simple composition of server functionality. * * Copyright 2008-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Composite { /** * The server. * * @var Horde_Kolab_Server_Interface */ private $_server; /** * The structure handler for this server. * * @var Horde_Kolab_Server_Structure_Interface */ private $_structure; /** * The search handler for this server. * * @var Horde_Kolab_Server_Search_Interface */ private $_search; /** * The object handler for this server. * * @var Horde_Kolab_Server_Objects_Interface */ private $_objects; /** * The schema handler for this server. * * @var Horde_Kolab_Server_Schema_Interface */ private $_schema; /** * Construct a new Horde_Kolab_Server object. * * @param array $params Parameter array. */ public function __construct( Horde_Kolab_Server_Interface $server, Horde_Kolab_Server_Objects_Interface $objects, Horde_Kolab_Server_Structure_Interface $structure, Horde_Kolab_Server_Search_Interface $search, Horde_Kolab_Server_Schema_Interface $schema ) { $this->_server = $server; $this->_objects = $objects; $this->_structure = $structure; $this->_search = $search; $this->_schema = $schema; $structure->setComposite($this); $search->setComposite($this); $schema->setComposite($this); $objects->setComposite($this); } /** * Retrieve an object attribute. * * @param string $key The name of the attribute. * * @return mixed The atribute value. * * @throws Horde_Kolab_Server_Exception If the attribute does not exist. */ public function __get($key) { $public = array('server', 'objects', 'structure', 'search', 'schema'); if (in_array($key, $public)) { $priv_key = '_' . $key; return $this->$priv_key; } throw new Horde_Kolab_Server_Exception( sprintf('Attribute %s not supported!', $key) ); } /** * Connect to the server. Use this method if the user name you can provide * does not match a GUID. In this case it will be required to map this user * name first. * * @param string $user The user name. * @param string $pass The password. * * @return NULL. * * @throws Horde_Kolab_Server_Exception If the connection failed. */ public function connect($user = null, $pass = null) { /** Bind anonymously first. */ $this->server->connectGuid(); $guid = $this->search->searchGuidForUidOrMail($user); $this->server->connectGuid($guid, $pass); } } Horde_Kolab_Server-2.0.5/lib/Horde/Kolab/Server/Exception.php0000664000175000017500000000270712653735542022117 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * This class provides the standard error class for Kolab Server exceptions. * * Copyright 2009-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Exception extends Horde_Exception_Wrapped { /** * Constants to define the error type. */ /** Unknown error type */ const SYSTEM = 1; /** The LDAP extension is missing */ const MISSING_LDAP_EXTENSION = 2; /** Binding to the LDAP server failed */ const BIND_FAILED = 3; /** The resultset was empty */ const EMPTY_RESULT = 4; const INVALID_INFORMATION = 5; /** The query was invalid */ const INVALID_QUERY = 6; /** The search yielded too many results */ const SEARCH_CONSTRAINT_TOO_MANY = 7; } Horde_Kolab_Server-2.0.5/lib/Horde/Kolab/Server/Factory.php0000664000175000017500000001233612653735542021567 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * A based Horde_Kolab_Server:: factory. * * Copyright 2008-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Factory { /** * Return the suggested interface bindings for the Kolab Server components. * * @return array The bindings. */ public function getBindings() { return array( array( 'Horde_Kolab_Server_Objects_Interface', 'Horde_Kolab_Server_Objects_Base' ), array( 'Horde_Kolab_Server_Search_Interface', 'Horde_Kolab_Server_Search_Base' ), array( 'Horde_Kolab_Server_Schema_Interface', 'Horde_Kolab_Server_Schema_Base' ), ); } /** * Setup the machinery to create a Horde_Kolab_Server_Structure handler. * * @param array $configuration The configuration parameters for the * connection. (@todo: describe parameters) * * @return Horde_Kolab_Server_Structure_Interface */ private function getStructure(array $configuration) { if (!isset($configuration['driver'])) { $driver = 'Horde_Kolab_Server_Structure_Kolab'; } else { $driver = $configuration['driver']; } return new $driver(); } /** * Return the server connection that should be used. * * @param array $configuration The configuration parameters for the * connection. (@todo: describe parameters) * * @return Horde_Kolab_Server_Connection The connection to the server. */ public function getConnection(array $configuration) { if (empty($configuration['mock'])) { if (!isset($configuration['basedn'])) { throw new Horde_Exception('The parameter \'basedn\' is missing in the Kolab server configuration!'); } $ldap_read = new Horde_Ldap($configuration); if (isset($configuration['host_master'])) { $configuration['host'] = $configuration['host_master']; $ldap_write = new Horde_Ldap($configuration); $connection = new Horde_Kolab_Server_Connection_Splittedldap( $ldap_read, $ldap_write ); } else { $connection = new Horde_Kolab_Server_Connection_Simpleldap( $ldap_read ); } return $connection; } else { if (isset($configuration['data'])) { $data = $configuration['data']; } else { $data = array(); } $connection = new Horde_Kolab_Server_Connection_Mock( new Horde_Kolab_Server_Connection_Mock_Ldap( $configuration, $data ) ); return $connection; } } /** * Return the server connection that should be used. * * @param array $configuration The configuration parameters for the * server. (@todo: describe parameters) * @param mixed $logger The logger (@todo: which methods need to be provided?) * * @return Horde_Kolab_Server_Interface The Horde_Kolab_Server connection. */ public function getServer(array $configuration, $logger) { $connection = $this->getConnection($configuration); if (!isset($configuration['filter'])) { $server = new Horde_Kolab_Server_Ldap_Standard( $connection, $configuration['basedn'] ); } else { $server = new Horde_Kolab_Server_Ldap_Filtered( $connection, $configuration['basedn'], $configuration['filter'] ); } if (isset($configuration['map'])) { $server = new Horde_Kolab_Server_Decorator_Map( $server, $configuration['map'] ); } if (isset($configuration['debug']) || isset($configuration['log'])) { $server = new Horde_Kolab_Server_Decorator_Log( $server, $logger ); } if (isset($configuration['debug']) || isset($configuration['count'])) { $server = new Horde_Kolab_Server_Decorator_Count( $server, $logger ); } if (!empty($configuration['cleanup'])) { $server = new Horde_Kolab_Server_Decorator_Clean( $server ); } return $server; } }Horde_Kolab_Server-2.0.5/lib/Horde/Kolab/Server/Interface.php0000664000175000017500000001211412653735542022052 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * This class defines the interface of a generic Kolab user database. * * Copyright 2008-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ interface Horde_Kolab_Server_Interface { /** * Connect to the server. * * @param string $guid The global unique id of the user. * @param string $pass The password. * * @return NULL. * * @throws Horde_Kolab_Server_Exception If the connection failed. */ public function connectGuid($guid = '', $pass = ''); /** * Get the current GUID * * @return string The GUID of the currently connected user. */ public function getGuid(); /** * Get the base GUID of this server * * @return string The base GUID of this server. */ public function getBaseGuid(); /** * Low level access to reading object data. * * This function provides direct access to the Server data. * * Usually you should use * * * $object = $server->fetch('a server uid'); * $variable = $object['attribute'] * * * to access object attributes. This is slower but takes special object * handling into account (e.g. custom attribute parsing). * * @param string $guid The object to retrieve. * * @return array An array of attributes. * * @throws Horde_Kolab_Server_Exception */ public function read($guid); /** * Low level access to reading some object attributes. * * @param string $guid The object to retrieve. * @param string $attrs Restrict to these attributes. * * @return array An array of attributes. * * @throws Horde_Kolab_Server_Exception * * @see Horde_Kolab_Server::read */ public function readAttributes($guid, array $attrs); /** * Finds object data matching a given set of criteria. * * @param string $query The LDAP search query * @param array $params Additional search parameters. * * @return Horde_Kolab_Server_Result The result object. * * @throws Horde_Kolab_Server_Exception */ public function find($query, array $params = array()); /** * Finds all object data below a parent matching a given set of criteria. * * @param string $query The LDAP search query * @param string $parent The parent to search below. * @param array $params Additional search parameters. * * @return Horde_Kolab_Server_Result The result object. * * @throws Horde_Kolab_Server_Exception */ public function findBelow($query, $parent, array $params = array()); /** * Modify existing object data. * * @param Horde_Kolab_Server_Object $object The object to be modified. * @param array $data The attributes of the object * to be stored. * * @return NULL * * @throws Horde_Kolab_Server_Exception */ public function save( Horde_Kolab_Server_Object_Interface $object, array $data ); /** * Add new object data. * * @param Horde_Kolab_Server_Object $object The object to be added. * @param array $data The attributes of the object * to be added. * * @return NULL * * @throws Horde_Kolab_Server_Exception */ public function add( Horde_Kolab_Server_Object_Interface $object, array $data ); /** * Delete an object. * * @param string $guid The GUID of the object to be deleted. * * @return NULL * * @throws Horde_Kolab_Server_Exception */ public function delete($guid); /** * Rename an object. * * @param string $guid The GUID of the object to be renamed. * @param string $new The new GUID of the object. * * @return NULL * * @throws Horde_Kolab_Server_Exception */ public function rename($guid, $new); /** * Return the database schema description. * * @return array The schema. * * @throws Horde_Kolab_Server_Exception If retrieval of the schema failed. */ public function getSchema(); /** * Get the parent GUID of this object. * * @param string $guid The GUID of the child. * * @return string the parent GUID of this object. */ public function getParentGuid($guid); }Horde_Kolab_Server-2.0.5/lib/Horde/Kolab/Server/Ldap.php0000664000175000017500000002535112653735542021041 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * This class provides methods to deal with objects stored in * a LDAP db. * * Copyright 2008-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ abstract class Horde_Kolab_Server_Ldap implements Horde_Kolab_Server_Interface { /** * The GUID of the current user. * * @var string|boolean */ private $_guid = false; /** * LDAP connection handle. * * @var Horde_Kolab_Server_Connection */ private $_conn; /** * Base DN of the LDAP server. * * @var string */ private $_base_dn; /** * Constructor. * * @param Horde_Kolab_Server_Connection $connection The LDAP connection. * @param string $base_dn The LDAP server base DN. * @param string $filter A global filter to add * to all queries. */ public function __construct( Horde_Kolab_Server_Connection_Interface $connection, $base_dn ) { $this->_conn = $connection; $this->_base_dn = $base_dn; try { Horde_Ldap::checkLDAPExtension(); } catch (Horde_Ldap_Exception $e) { throw new Horde_Kolab_Server_Exception( $e->getMessage(), Horde_Kolab_Server_Exception::MISSING_LDAP_EXTENSION, $e ); } } /** * Connect to the server. * * @param string $guid The global unique id of the user. * @param string $pass The password. * * @return NULL. * * @throws Horde_Kolab_Server_Exception If the connection failed. */ public function connectGuid($guid = '', $pass = '') { /** Do we need to switch the user? */ if ($guid !== $this->_guid) { try { $this->_conn->getRead()->bind($guid, $pass); } catch (Horde_Ldap_Exception $e) { if ($e->getCode() == 49) { throw new Horde_Kolab_Server_Exception_Bindfailed( 'Invalid username/password!', Horde_Kolab_Server_Exception::BIND_FAILED, $e ); } else { throw new Horde_Kolab_Server_Exception( 'Bind failed!', Horde_Kolab_Server_Exception::SYSTEM, $e ); } } $this->_guid = $guid; } } /** * Get the current GUID * * @return string The GUID of the connected user. */ public function getGuid() { return $this->_guid; } /** * Get the base GUID of this server * * @return string The base GUID of this server. */ public function getBaseGuid() { return $this->_base_dn; } /** * Low level access to reading object data. * * @param string $guid The object to retrieve. * * @return array An array of attributes. * * @throws Horde_Kolab_Server_Exception If the search operation hit an error * or returned no result. */ public function read($guid) { $params = array('scope' => 'base'); $data = $this->_search(null, $params, $guid); if ($data->count() == 0) { throw new Horde_Kolab_Server_Exception( 'Empty result!', Horde_Kolab_Server_Exception::EMPTY_RESULT ); } $result = $data->asArray(); return array_pop($result); } /** * Low level access to reading some object attributes. * * @param string $guid The object to retrieve. * @param string $attrs Restrict to these attributes. * * @return array An array of attributes. * * @throws Horde_Kolab_Server_Exception If the search operation hit an error * or returned no result. */ public function readAttributes($guid, array $attrs) { $params = array( 'scope' => 'base', 'attributes' => $attrs ); $data = $this->_search(null, $params, $guid); if ($data->count() == 0) { throw new Horde_Kolab_Server_Exception( 'Empty result!', Horde_Kolab_Server_Exception::EMPTY_RESULT ); } $result = $data->asArray(); return array_pop($result); } /** * Finds object data matching a given set of criteria. * * @param string $query The LDAP search query * @param array $params Additional search parameters. * * @return Horde_Kolab_Server_Result The result object. * * @throws Horde_Kolab_Server_Exception */ public function find($query, array $params = array()) { return $this->findBelow($query, $this->_base_dn, $params); } /** * Modify existing object data. * * @param Horde_Kolab_Server_Object $object The object to be modified. * @param array $data The attributes of the object * to be stored. * * @return NULL * * @throws Horde_Kolab_Server_Exception */ public function save( Horde_Kolab_Server_Object_Interface $object, array $data ) { $changes = new Horde_Kolab_Server_Ldap_Changes($object, $data); try { $entry = $this->_conn->getWrite()->getEntry( $object->getGuid(), array_keys($data) ); $this->_conn->getWrite()->modify($entry, $changes->getChangeset()); } catch (Horde_Ldap_Exception $e) { throw new Horde_Kolab_Server_Exception( 'Saving failed!', Horde_Kolab_Server_Exception::SYSTEM, $e ); } } /** * Add new object data. * * @param Horde_Kolab_Server_Object $object The object to be added. * @param array $data The attributes of the object * to be added. * * @return NULL * * @throws Horde_Kolab_Server_Exception */ public function add( Horde_Kolab_Server_Object_Interface $object, array $data ) { try { $entry = Horde_Ldap_Entry::createFresh($object->getGuid(), $data); $this->_conn->getWrite()->add($entry); } catch (Horde_Ldap_Exception $e) { throw new Horde_Kolab_Server_Exception( 'Adding object failed!', Horde_Kolab_Server_Exception::SYSTEM, $e ); } } /** * Delete an object. * * @param string $guid The UID of the object to be deleted. * * @return NULL * * @throws Horde_Kolab_Server_Exception */ public function delete($guid) { try { $this->_conn->getWrite()->delete($guid); } catch (Horde_Ldap_Exception $e) { throw new Horde_Kolab_Server_Exception( 'Deleting object failed!', Horde_Kolab_Server_Exception::SYSTEM, $e ); } } /** * Rename an object. * * @param string $guid The UID of the object to be renamed. * @param string $new The new UID of the object. * * @return NULL * * @throws Horde_Kolab_Server_Exception */ public function rename($guid, $new) { try { $this->_conn->getWrite()->move($guid, $new); } catch (Horde_Ldap_Exception $e) { throw new Horde_Kolab_Server_Exception( 'Renaming object failed!', Horde_Kolab_Server_Exception::SYSTEM, $e ); } } /** * Return the ldap schema. * * @return Horde_Ldap_Schema The LDAP schema. * * @throws Horde_Kolab_Server_Exception If retrieval of the schema failed. */ public function getSchema() { try { return $this->_conn->getRead()->schema(); } catch (Horde_Ldap_Exception $e) { throw new Horde_Kolab_Server_Exception( 'Retrieving the schema failed!', Horde_Kolab_Server_Exception::SYSTEM, $e ); } } /** * Get the parent GUID of this object. * * @param string $guid The GUID of the child. * * @return string the parent GUID of this object. */ public function getParentGuid($guid) { try { $base = Horde_Ldap_Util::explodeDN( $guid, array( 'casefold' => 'none', 'reverse' => false, 'onlyvalues' => false ) ); $id = array_shift($base); $parent = Horde_Ldap_Util::canonicalDN( $base, array('casefold' => 'none') ); } catch (Horde_Ldap_Exception $e) { throw new Horde_Kolab_Server_Exception( 'Retrieving the parent object failed!', Horde_Kolab_Server_Exception::SYSTEM, $e ); } return $parent; } /** * Search for object data. * * @param string $filter The LDAP search filter. * @param array $params Additional search parameters. * @param string $base The search base * * @return array The result array. * * @throws Horde_Kolab_Server_Exception If the search operation encountered * a problem. */ protected function _search($filter, array $params, $base) { try { $search = $this->_conn->getRead()->search($base, $filter, $params); } catch (Horde_Ldap_Exception $e) { throw new Horde_Kolab_Server_Exception( 'Search failed!', Horde_Kolab_Server_Exception::SYSTEM, $e ); } return new Horde_Kolab_Server_Result_Ldap($search); } } Horde_Kolab_Server-2.0.5/test/Horde/Kolab/Server/Class/Server/Composite/BaseTest.php0000664000175000017500000000424012653735542026353 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * Prepare the test setup. */ require_once __DIR__ . '/../../../TestCase.php'; /** * Test the composite server. * * Copyright 2009-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Class_Server_Composite_BaseTest extends Horde_Kolab_Server_TestCase { public function testMethodGetReturnsServerElement() { $composite = $this->getMockedComposite(); $this->assertInstanceOf('Horde_Kolab_Server_Interface', $composite->server); $this->assertInstanceOf('Horde_Kolab_Server_Objects_Interface', $composite->objects); $this->assertInstanceOf('Horde_Kolab_Server_Structure_Interface', $composite->structure); $this->assertInstanceOf('Horde_Kolab_Server_Search_Interface', $composite->search); $this->assertInstanceOf('Horde_Kolab_Server_Schema_Interface', $composite->schema); try { $a = $composite->something; $this->fail('No exception!'); } catch (Horde_Kolab_Server_Exception $e) { $this->assertEquals( 'Attribute something not supported!', $e->getMessage() ); } } public function testMethodConnectHasPostconditionThatTheServerIsBound() { $composite = $this->getMockedComposite(); $composite->server->expects($this->exactly(2)) ->method('connectGuid'); $composite->search->expects($this->exactly(1)) ->method('__call') ->with('searchGuidForUidOrMail', array('user')); $composite->connect('user', 'pass'); } }Horde_Kolab_Server-2.0.5/test/Horde/Kolab/Server/Class/Server/Connection/Mock/LdapTest.php0000664000175000017500000004364612653735542027424 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * Require our basic test case definition */ require_once __DIR__ . '/../../../../LdapTestCase.php'; /** * Test the test backend. * * Copyright 2008-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Class_Server_Connection_Mock_LdapTest extends Horde_Kolab_Server_LdapTestCase { /** * Test parsing of LDAP filters. * * @return NULL */ public function testFilterParse() { $this->skipIfNoLdap(); $conn = new Horde_Kolab_Server_Connection_Mock_Ldap(array(), array()); $a = $conn->parse('(a=b)'); $this->assertEquals(array('att' => 'a', 'log' => '=', 'val' => 'b'), $a); $a = $conn->parse('(&(a=b)(c=d))'); $this->assertEquals(array('op' => '&', 'sub' => array( array('att' => 'a', 'log' => '=', 'val' => 'b'), array('att' => 'c', 'log' => '=', 'val' => 'd'), )), $a); $a = $conn->parse('(&(a=1)(|(b=2)(c=3)))'); $this->assertEquals(array('op' => '&', 'sub' => array( array('att' => 'a', 'log' => '=', 'val' => '1'), array('op' => '|', 'sub' => array( array('att' => 'b', 'log' => '=', 'val' => '2'), array('att' => 'c', 'log' => '=', 'val' => '3'), )))), $a); $a = $conn->parseSub('(!(x=2))(b=1)'); $this->assertEquals(array(array('op' => '!', 'sub' => array( array('att' => 'x', 'log' => '=', 'val' => '2'), ) ), array('att' => 'b', 'log' => '=', 'val' => '1'), ), $a); $a = $conn->parse('(&(!(x=2))(b=1))'); $this->assertEquals(array('op' => '&', 'sub' => array( array('op' => '!', 'sub' => array( array('att' => 'x', 'log' => '=', 'val' => '2'), ) ), array('att' => 'b', 'log' => '=', 'val' => '1'), )), $a); try { $a = $conn->parse('dummy'); $this->fail('No exception!'); } catch (Horde_Kolab_Server_Exception $e) { $this->assertEquals('Filter parsing error: dummy - filter components must be enclosed in round brackets', $e->getMessage()); } try { $a = $conn->parse('(a/b)'); $this->fail('No exception!'); } catch (Horde_Kolab_Server_Exception $e) { $this->assertEquals('Filter parsing error: invalid filter syntax - unknown matching rule used', $e->getMessage()); } try { $a = $conn->parse('(a=b)(c=d)'); $this->fail('No exception!'); } catch (Horde_Kolab_Server_Exception $e) { $this->assertEquals('Filter parsing error: invalid filter syntax - multiple leaf components detected!', $e->getMessage()); } } /** * Test searching in the simulated LDAP data. * * @return NULL */ public function testSearch() { $this->skipIfNoLdap(); $conn = new Horde_Kolab_Server_Connection_Mock_Ldap( array(), array( 'cn=a' => array( 'dn' => 'cn=a', 'data' => array( 'a' => '1', 'b' => '1', 'c' => '1', ) ), 'cn=b' => array( 'dn' => 'cn=b', 'data' => array( 'a' => '1', 'b' => '2', 'c' => '2', ) ), 'cn=c' => array( 'dn' => 'cn=c', 'data' => array( 'a' => '1', 'b' => '2', 'c' => '3', ) ), 'cn=d' => array( 'dn' => 'cn=d', 'data' => array( 'a' => '2', 'b' => '2', 'c' => '1', ) ), ) ); $conn->bind(); $a = $conn->search(null, '(c=1)'); $this->assertEquals( array( 'cn=a' => array( 'a' => '1', 'b' => '1', 'c' => '1', 'dn' => 'cn=a', ), 'cn=d' => array( 'a' => '2', 'b' => '2', 'c' => '1', 'dn' => 'cn=d', ), ), $a->asArray() ); $a = $conn->search(null, '(c=3)'); $this->assertEquals( array( 'cn=c' => array( 'a' => '1', 'b' => '2', 'c' => '3', 'dn' => 'cn=c', ), ), $a->asArray() ); $a = $conn->search(null, '(c=3)', array('attributes' => array('a'))); $this->assertEquals( array( 'cn=c' => array( 'a' => '1', 'dn' => 'cn=c', ), ), $a->asArray() ); $a = $conn->search(null, '(&(a=1)(b=2))', array('attributes' => array('a', 'b'))); $this->assertEquals( array( 'cn=b' => array( 'a' => '1', 'b' => '2', 'dn' => 'cn=b', ), 'cn=c' => array( 'a' => '1', 'b' => '2', 'dn' => 'cn=c', ), ), $a->asArray() ); $a = $conn->search(null, '(|(a=1)(b=2))', array('attributes' => array('a', 'b'))); $this->assertEquals( array( 'cn=a' => array( 'a' => '1', 'b' => '1', 'dn' => 'cn=a', ), 'cn=b' => array( 'a' => '1', 'b' => '2', 'dn' => 'cn=b', ), 'cn=c' => array( 'a' => '1', 'b' => '2', 'dn' => 'cn=c', ), 'cn=d' => array( 'a' => '2', 'b' => '2', 'dn' => 'cn=d', ) ), $a->asArray() ); $a = $conn->search(null, '(&(b=2))', array('attributes' => array('b'))); $this->assertEquals( array( 'cn=b' => array( 'b' => '2', 'dn' => 'cn=b', ), 'cn=c' => array( 'b' => '2', 'dn' => 'cn=c', ), 'cn=d' => array( 'b' => '2', 'dn' => 'cn=d', ), ), $a->asArray() ); $a = $conn->search(null, '(!(b=2))', array('attributes' => array('a', 'b'))); $this->assertEquals( array( 'cn=a' => array( 'a' => '1', 'b' => '1', 'dn' => 'cn=a', ), ), $a->asArray() ); $a = $conn->search(null, '(&(!(x=2))(b=1))', array('attributes' => array('b'))); $this->assertEquals( array( 'cn=a' => array( 'b' => '1', 'dn' => 'cn=a', ), ), $a->asArray() ); $a = $conn->search(null, '(c=t)', array('attributes' => array('a'))); $this->assertEquals( array(), $a->asArray() ); try { $a = $conn->search(null, '(c>t)', array('attributes' => array('a'))); $this->fail('No exception!'); } catch (Horde_Kolab_Server_Exception $e) { $this->assertEquals('Not implemented!', $e->getMessage()); } } public function testMethodBindHasPostconditionThatBindingOccursWithDefaultDnAndPwIfSpecified() { $conn = new Horde_Kolab_Server_Connection_Mock_Ldap( array('binddn' => 'test', 'bindpw' => 'test'), array() ); try { $conn->bind('', ''); $this->fail('No exception!'); } catch (Horde_Kolab_Server_Exception $e) { $this->assertEquals('User does not exist!', $e->getMessage()); } } public function testMethodBindThrowsExceptionIfTheUserDoesNotExist() { $this->testMethodBindHasPostconditionThatBindingOccursWithDefaultDnAndPwIfSpecified(); } public function testMethodBindThrowsExceptionIfTheUserHasNoPassword() { $conn = new Horde_Kolab_Server_Connection_Mock_Ldap( array('binddn' => 'test', 'bindpw' => 'test'), array('test' => array('data' => array() ) ) ); try { $conn->bind('', ''); $this->fail('No exception!'); } catch (Horde_Kolab_Server_Exception $e) { $this->assertEquals('User has no password entry!', $e->getMessage()); } } public function testMethodBindThrowsExceptionIfThePasswordWasIncorrect() { $conn = new Horde_Kolab_Server_Connection_Mock_Ldap( array('binddn' => 'test', 'bindpw' => 'test'), array('test' => array('data' => array( 'userPassword' => array('something') ) ) ) ); try { $conn->bind('', ''); $this->fail('No exception!'); } catch (Horde_Kolab_Server_Exception $e) { $this->assertEquals('Incorrect password!', $e->getMessage()); } } public function testMethodBindThrowsExceptionIfAnonymousLoginIsDisabledAndTheDnIsUnset() { $conn = new Horde_Kolab_Server_Connection_Mock_Ldap( array('no_anonymous_bind' => true), array() ); try { $conn->bind('', ''); $this->fail('No exception!'); } catch (Horde_Kolab_Server_Exception $e) { $this->assertEquals('Anonymous bind is not allowed!', $e->getMessage()); } } public function testMethodSearchHasResultMocksearchSingleElementIfNoFilterIsSetAndSearchScopeIsBase() { $this->skipIfNoLdap(); $conn = new Horde_Kolab_Server_Connection_Mock_Ldap( array(), array('test' => array('dn' => 'test', 'data' => array( 'userPassword' => array('something') ) ), 'testnot' => array('dn' => 'test', 'data' => array( 'userPassword' => array('something') ) ) ) ); $conn->bind('', ''); $result = $conn->search('test', null, array('scope' => 'base')); $this->assertEquals( array('test' => array( 'userPassword' => array('something'), 'dn' => 'test' ) ), $result->asArray() ); } public function testMethodSearchHasResultMocksearchEmptyIfNoFilterIsSetSearchScopeIsBaseAndTheSpecifiedBaseDoesNotExist() { $this->skipIfNoLdap(); $conn = new Horde_Kolab_Server_Connection_Mock_Ldap( array(), array() ); $conn->bind('', ''); $result = $conn->search('test', null, array('scope' => 'base')); $this->assertEquals( array(), $result->asArray() ); } public function testMethodSearchHasResultMocksearchSingleElementIfNoFilterIsSetSearchScopeIsSubAndOnlyOneElementMatchesBase() { $this->skipIfNoLdap(); $conn = new Horde_Kolab_Server_Connection_Mock_Ldap( array(), array('test' => array('dn' => 'test', 'data' => array( 'userPassword' => array('something') ) ), 'testnot' => array('dn' => 'test', 'data' => array( 'userPassword' => array('something') ) ) ) ); $conn->bind('', ''); $result = $conn->search('test', null, array('scope' => 'sub')); $this->assertEquals( array('test' => array( 'userPassword' => array('something'), 'dn' => 'test' ) ), $result->asArray() ); } public function testMethodSearchHasResultMocksearchWithMatchingElementsIfNoSearchScopeIsSet() { $this->skipIfNoLdap(); $conn = new Horde_Kolab_Server_Connection_Mock_Ldap( array(), array('test' => array('dn' => 'test', 'data' => array( 'userPassword' => array('something') ) ), 'yestest' => array('dn' => 'yestest', 'data' => array( 'userPassword' => array('something') ) ), 'testnot' => array('dn' => 'testnot', 'data' => array( 'userPassword' => array('something') ) ) ) ); $conn->bind('', ''); $result = $conn->search('test'); $this->assertEquals( array('test', 'yestest'), array_keys($result->asArray()) ); } public function testMethodSearchHasResultMocksearchWithSelectedAttributesIfSpecificAttributesWereSet() { $this->skipIfNoLdap(); $conn = new Horde_Kolab_Server_Connection_Mock_Ldap( array(), array('test' => array('dn' => 'test', 'data' => array( 'userPassword' => array('something'), 'name' => array('name1') ) ), 'yestest' => array('dn' => 'yestest', 'data' => array( 'userPassword' => array('something'), 'name' => array('name2') ) ), 'testnot' => array('dn' => 'testnot', 'data' => array( 'userPassword' => array('something'), 'name' => array('name2') ) ) ) ); $conn->bind('', ''); $result = $conn->search('test', null, array('attributes' => 'name')); $this->assertEquals( array( 'test' => array( 'name' => array('name1'), 'dn' => 'test' ), 'yestest' => array( 'name' => array('name2'), 'dn' => 'yestest' ), ), $result->asArray() ); } public function testMethodSearchThrowsExceptionIfSearchScopeIsOne() { $conn = new Horde_Kolab_Server_Connection_Mock_Ldap( array(), array() ); $conn->bind('', ''); try { $result = $conn->search('test', null, array('scope' => 'one')); $this->fail('No exception!'); } catch (Horde_Kolab_Server_Exception $e) { $this->assertEquals('Not implemented!', $e->getMessage()); } } public function testMethodSearchThrowsExceptionIfTheConnectionIsNotBound() { $conn = new Horde_Kolab_Server_Connection_Mock_Ldap( array(), array() ); try { $conn->search(); $this->fail('No exception!'); } catch (Horde_Kolab_Server_Exception $e) { $this->assertEquals('Unbound connection!', $e->getMessage()); } } } Horde_Kolab_Server-2.0.5/test/Horde/Kolab/Server/Class/Server/Connection/MockTest.php0000664000175000017500000000434412653735542026534 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * Test the handler for a mock connection. * * Copyright 2009-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Class_Server_Connection_MockTest extends PHPUnit_Framework_TestCase { public function testMethodConstructHasParameterMockldapConnection() { $ldap = $this->getMock( 'Horde_Kolab_Server_Connection_Mock_Ldap', array(), array(), '', false, false ); $conn = new Horde_Kolab_Server_Connection_Mock($ldap); } public function testMethodConstructHasPostconditionThatTheGivenServerWasStored() { $ldap = $this->getMock( 'Horde_Kolab_Server_Connection_Mock_Ldap', array(), array(), '', false, false ); $conn = new Horde_Kolab_Server_Connection_Mock($ldap); $this->assertSame($ldap, $conn->getRead()); } public function testMethodGetreadHasResultMockldapTheHandledConnection() { $ldap = $this->getMock( 'Horde_Kolab_Server_Connection_Mock_Ldap', array(), array(), '', false, false ); $conn = new Horde_Kolab_Server_Connection_Mock($ldap); $this->assertInstanceOf('Horde_Kolab_Server_Connection_Mock_Ldap', $conn->getRead()); } public function testMethodGetwriteHasResultMockldapTheHandledConnection() { $ldap = $this->getMock( 'Horde_Kolab_Server_Connection_Mock_Ldap', array(), array(), '', false, false ); $conn = new Horde_Kolab_Server_Connection_Mock($ldap); $this->assertSame($conn->getWrite(), $conn->getRead()); } } Horde_Kolab_Server-2.0.5/test/Horde/Kolab/Server/Class/Server/Connection/SimpleldapTest.php0000664000175000017500000000417012653735542027732 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * Require our basic test case definition */ require_once __DIR__ . '/../../../LdapTestCase.php'; /** * Test the handler for a simple LDAP setup without read-only slaves. * * Copyright 2009-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Class_Server_Connection_SimpleldapTest extends Horde_Kolab_Server_LdapTestCase { public function testMethodConstructHasParameterNetldap2Connection() { $this->skipIfNoLdap(); $ldap = $this->getMock('Horde_Ldap'); $conn = new Horde_Kolab_Server_Connection_Simpleldap($ldap); } public function testMethodConstructHasPostconditionThatTheGivenServerWasStored() { $this->skipIfNoLdap(); $ldap = $this->getMock('Horde_Ldap'); $conn = new Horde_Kolab_Server_Connection_Simpleldap($ldap); $this->assertSame($ldap, $conn->getRead()); } public function testMethodGetreadHasResultNetldap2TheHandledConnection() { $this->skipIfNoLdap(); $ldap = $this->getMock('Horde_Ldap'); $conn = new Horde_Kolab_Server_Connection_Simpleldap($ldap); $this->assertInstanceOf('Horde_Ldap', $conn->getRead()); } public function testMethodGetwriteHasResultNetldap2TheHandledConnection() { $this->skipIfNoLdap(); $ldap = $this->getMock('Horde_Ldap'); $conn = new Horde_Kolab_Server_Connection_Simpleldap($ldap); $this->assertSame($conn->getWrite(), $conn->getRead()); } } Horde_Kolab_Server-2.0.5/test/Horde/Kolab/Server/Class/Server/Connection/SplittedldapTest.php0000664000175000017500000000506712653735542030277 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * Require our basic test case definition */ require_once __DIR__ . '/../../../LdapTestCase.php'; /** * Test the handler for a LDAP master/slave setup. * * Copyright 2009-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Class_Server_Connection_SplittedldapTest extends Horde_Kolab_Server_LdapTestCase { public function testMethodConstructHasParameterNetldap2ReadConnectionAndParameterNetldap2WriteConnection() { $this->skipIfNoLdap(); $ldap_read = $this->getMock('Horde_Ldap'); $ldap_write = $this->getMock('Horde_Ldap'); $conn = new Horde_Kolab_Server_Connection_Splittedldap($ldap_read, $ldap_write); } public function testMethodConstructHasPostconditionThatTheGivenServersWereStored() { $this->skipIfNoLdap(); $ldap_read = $this->getMock('Horde_Ldap'); $ldap_write = $this->getMock('Horde_Ldap'); $conn = new Horde_Kolab_Server_Connection_Splittedldap($ldap_read, $ldap_write); $this->assertSame($ldap_read, $conn->getRead()); $this->assertSame($ldap_write, $conn->getWrite()); } public function testMethodGetreadHasResultNetldap2TheHandledConnection() { $this->skipIfNoLdap(); $ldap_read = $this->getMock('Horde_Ldap'); $ldap_write = $this->getMock('Horde_Ldap'); $conn = new Horde_Kolab_Server_Connection_Splittedldap($ldap_read, $ldap_write); $this->assertInstanceOf('Horde_Ldap', $conn->getRead()); $this->assertInstanceOf('Horde_Ldap', $conn->getWrite()); } public function testMethodGetwriteHasResultNetldap2TheHandledConnection() { $this->skipIfNoLdap(); $ldap_read = $this->getMock('Horde_Ldap'); $ldap_write = $this->getMock('Horde_Ldap'); $conn = new Horde_Kolab_Server_Connection_Splittedldap($ldap_read, $ldap_write); $this->assertFalse($conn->getWrite() === $conn->getRead()); } } Horde_Kolab_Server-2.0.5/test/Horde/Kolab/Server/Class/Server/Decorator/CleanTest.php0000664000175000017500000001555412653735542026515 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * Test the cleanup decorator for the server. * * Copyright 2009-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Class_Server_Decorator_CleanTest extends PHPUnit_Framework_TestCase { public function setUp() { parent::setUp(); $this->server = $this->getMock('Horde_Kolab_Server_Interface'); $this->cleaner = new Horde_Kolab_Server_Decorator_Clean($this->server); } public function testMethodGetbaseguidHasPostconditionThatTheCallWasDelegatedToTheServer() { $this->server->expects($this->exactly(1)) ->method('getBaseGuid') ->will($this->returnValue('base')); $this->assertEquals('base', $this->cleaner->getBaseGuid()); } public function testMethodGetuidHasPostconditionThatTheCallWasDelegatedToTheServer() { $this->server->expects($this->exactly(1)) ->method('getGuid') ->will($this->returnValue('guid')); $this->assertEquals('guid', $this->cleaner->getGuid()); } public function testMethodConnectguidHasPostconditionThatTheCallWasDelegatedToTheServer() { $this->server->expects($this->exactly(1)) ->method('connectGuid') ->with('user', 'pass'); $this->cleaner->connectGuid('user', 'pass'); } public function testMethodReadHasPostconditionThatTheCallWasDelegatedToTheServer() { $this->server->expects($this->exactly(1)) ->method('read') ->with('guid') ->will($this->returnValue(array())); $this->assertEquals(array(), $this->cleaner->read('guid')); } public function testMethodReadattributesHasPostconditionThatTheCallWasDelegatedToTheServer() { $this->server->expects($this->exactly(1)) ->method('readAttributes') ->with('guid', array('a')) ->will($this->returnValue(array())); $this->assertEquals( array(), $this->cleaner->readAttributes('guid', array('a')) ); } public function testMethodFindHasPostconditionThatTheCallWasDelegatedToTheServer() { $result = $this->getMock('Horde_Kolab_Server_Result_Interface'); $query = $this->getMock( 'Horde_Kolab_Server_Query_Element_Interface', array(), array(), '', false ); $this->server->expects($this->exactly(1)) ->method('find') ->with($query) ->will($this->returnValue($result)); $this->assertInstanceOf( 'Horde_Kolab_Server_Result_Interface', $this->cleaner->find($query) ); } public function testMethodFindbelowHasPostconditionThatTheCallWasDelegatedToTheServer() { $result = $this->getMock('Horde_Kolab_Server_Result_Interface'); $query = $this->getMock( 'Horde_Kolab_Server_Query_Element_Interface', array(), array(), '', false ); $this->server->expects($this->exactly(1)) ->method('findBelow') ->with($query, 'none') ->will($this->returnValue($result)); $this->assertInstanceOf( 'Horde_Kolab_Server_Result_Interface', $this->cleaner->findBelow($query, 'none') ); } public function testMethodSaveHasPostconditionThatTheCallWasDelegatedToTheServer() { $object = $this->getMock('Horde_Kolab_Server_Object_Interface'); $this->server->expects($this->exactly(1)) ->method('save') ->with($object, array('a' => 'a')); $this->cleaner->save($object, array('a' => 'a')); } public function testMethodAddHasPostconditionThatTheCallWasDelegatedToTheServer() { $object = $this->getMock('Horde_Kolab_Server_Object_Interface'); $this->server->expects($this->exactly(1)) ->method('add') ->with($object, array('a' => 'a')); $this->cleaner->add($object, array('a' => 'a')); } public function testMethodDeleteHasPostconditionThatTheCallWasDelegatedToTheServer() { $this->server->expects($this->exactly(1)) ->method('delete') ->with('a'); $this->cleaner->delete('a'); } public function testMethodRenameHasPostconditionThatTheCallWasDelegatedToTheServer() { $this->server->expects($this->exactly(1)) ->method('rename') ->with('a', 'b'); $this->cleaner->rename('a', 'b'); } public function testMethodGetschemaHasPostconditionThatTheCallWasDelegatedToTheServer() { $this->server->expects($this->exactly(1)) ->method('getSchema'); $this->cleaner->getSchema(); } public function testMethodGetparentguidHasPostconditionThatTheCallWasDelegatedToTheServer() { $this->server->expects($this->exactly(1)) ->method('getParentGuid') ->will($this->returnValue('parent')); $this->assertEquals('parent', $this->cleaner->getParentGuid('child')); } public function testMethodAddHasPostconditionThatTheGuidOfTheAddedObjectIsRememberedAndDeletedOnDestruction() { $object = $this->getMock('Horde_Kolab_Server_Object_Interface'); $object->expects($this->exactly(1)) ->method('getGuid') ->will($this->returnValue('a')); $this->server->expects($this->exactly(1)) ->method('add') ->with($object, array('a' => 'a')); $this->server->expects($this->exactly(1)) ->method('delete') ->with('a'); $this->cleaner->add($object, array('a' => 'a')); unset($this->cleaner); } public function testMethodAddHasPostconditionThatTheGuidOfTheAddedObjectIsNotDeletedOnDestructionIfItWasDeletedBefore() { $object = $this->getMock('Horde_Kolab_Server_Object_Interface'); $object->expects($this->exactly(1)) ->method('getGuid') ->will($this->returnValue('a')); $this->server->expects($this->exactly(1)) ->method('add') ->with($object, array('a' => 'a')); $this->server->expects($this->exactly(1)) ->method('delete') ->with('a'); $this->cleaner->add($object, array('a' => 'a')); $this->cleaner->delete('a'); unset($this->cleaner); } } Horde_Kolab_Server-2.0.5/test/Horde/Kolab/Server/Class/Server/Decorator/LogTest.php0000664000175000017500000001664312653735542026214 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * Test the log decorator for the server. * * Copyright 2009-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Class_Server_Decorator_LogTest extends PHPUnit_Framework_TestCase { public function setUp() { parent::setUp(); $this->logger = $this->getMock('Horde_Log_Logger'); $this->server = $this->getMock('Horde_Kolab_Server_Interface'); $this->logged = new Horde_Kolab_Server_Decorator_Log( $this->server, $this->logger ); } public function testMethodGetbaseguidHasPostconditionThatTheCallWasDelegatedToTheServer() { $this->server->expects($this->exactly(1)) ->method('getBaseGuid') ->will($this->returnValue('base')); $this->assertEquals('base', $this->logged->getBaseGuid()); } public function testMethodGetuidHasPostconditionThatTheCallWasDelegatedToTheServer() { $this->server->expects($this->exactly(1)) ->method('getGuid') ->will($this->returnValue('guid')); $this->assertEquals('guid', $this->logged->getGuid()); } public function testMethodConnectguidHasPostconditionThatTheCallWasDelegatedToTheServer() { $this->server->expects($this->exactly(1)) ->method('connectGuid') ->with('user', 'pass'); $this->logged->connectGuid('user', 'pass'); } public function testMethodReadHasPostconditionThatTheCallWasDelegatedToTheServer() { $this->server->expects($this->exactly(1)) ->method('read') ->with('guid') ->will($this->returnValue(array())); $this->assertEquals(array(), $this->logged->read('guid')); } public function testMethodReadattributesHasPostconditionThatTheCallWasDelegatedToTheServer() { $this->server->expects($this->exactly(1)) ->method('readAttributes') ->with('guid', array('a')) ->will($this->returnValue(array())); $this->assertEquals( array(), $this->logged->readAttributes('guid', array('a')) ); } public function testMethodFindHasPostconditionThatTheCallWasDelegatedToTheServer() { $result = $this->getMock('Horde_Kolab_Server_Result_Interface'); $query = $this->getMock( 'Horde_Kolab_Server_Query_Ldap', array(), array(), '', false, false ); $query->expects($this->once()) ->method('__toString') ->will($this->returnValue('filter')); $this->server->expects($this->exactly(1)) ->method('find') ->with($query) ->will($this->returnValue($result)); $this->assertInstanceOf( 'Horde_Kolab_Server_Result_Interface', $this->logged->find($query) ); } public function testMethodFindbelowHasPostconditionThatTheCallWasDelegatedToTheServer() { $result = $this->getMock('Horde_Kolab_Server_Result_Interface'); $query = $this->getMock( 'Horde_Kolab_Server_Query_Element_Interface', array(), array(), '', false ); $this->server->expects($this->exactly(1)) ->method('findBelow') ->with($query, 'none') ->will($this->returnValue($result)); $this->assertInstanceOf( 'Horde_Kolab_Server_Result_Interface', $this->logged->findBelow($query, 'none') ); } public function testMethodSaveHasPostconditionThatTheCallWasDelegatedToTheServer() { $object = $this->getMock('Horde_Kolab_Server_Object_Interface'); $this->server->expects($this->exactly(1)) ->method('save') ->with($object, array('a' => 'a')); $this->logged->save($object, array('a' => 'a')); } public function testMethodAddHasPostconditionThatTheCallWasDelegatedToTheServer() { $object = $this->getMock('Horde_Kolab_Server_Object_Interface'); $this->server->expects($this->exactly(1)) ->method('add') ->with($object, array('a' => 'a')); $this->logged->add($object, array('a' => 'a')); } public function testMethodDeleteHasPostconditionThatTheCallWasDelegatedToTheServer() { $this->server->expects($this->exactly(1)) ->method('delete') ->with('a'); $this->logged->delete('a'); } public function testMethodRenameHasPostconditionThatTheCallWasDelegatedToTheServer() { $this->server->expects($this->exactly(1)) ->method('rename') ->with('a', 'b'); $this->logged->rename('a', 'b'); } public function testMethodGetschemaHasPostconditionThatTheCallWasDelegatedToTheServer() { $this->server->expects($this->exactly(1)) ->method('getSchema'); $this->logged->getSchema(); } public function testMethodSaveHasPostconditionThatTheEventWasLogged() { $object = $this->getMock('Horde_Kolab_Server_Object_Interface'); $object->expects($this->once()) ->method('getGuid') ->will($this->returnValue('a')); $this->logger->expects($this->once()) ->method('__call') ->with( 'debug', array('The object "a" has been successfully saved!') ); $this->logged->save($object, array('a' => 'a')); } public function testMethodAddHasPostconditionThatTheEventWasLogged() { $object = $this->getMock('Horde_Kolab_Server_Object_Interface'); $object->expects($this->once()) ->method('getGuid') ->will($this->returnValue('a')); $this->logger->expects($this->once()) ->method('__call') ->with( 'debug', array('The object "a" has been successfully added!') ); $this->logged->add($object, array('a' => 'a')); } public function testMethodDeleteHasPostconditionThatTheEventWasLogged() { $this->logger->expects($this->once()) ->method('__call') ->with( 'debug', array('The object "a" has been successfully deleted!') ); $this->logged->delete('a'); } public function testMethodRenameHasPostconditionThatTheEventWasLogged() { $this->logger->expects($this->once()) ->method('__call') ->with( 'debug', array('The object "a" has been successfully renamed to "b"!') ); $this->logged->rename('a', 'b'); } public function testMethodGetparentguidHasPostconditionThatTheCallWasDelegatedToTheServer() { $this->server->expects($this->exactly(1)) ->method('getParentGuid') ->will($this->returnValue('parent')); $this->assertEquals('parent', $this->logged->getParentGuid('child')); } } Horde_Kolab_Server-2.0.5/test/Horde/Kolab/Server/Class/Server/Ldap/ChangesTest.php0000664000175000017500000001411412653735542025770 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * Test the LDAP changeset handler. * * Copyright 2009-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Class_Server_Ldap_ChangesTest extends PHPUnit_Framework_TestCase { public function testMethodConstructHasParameterServerobject() { $changes = new Horde_Kolab_Server_Ldap_Changes( $this->getMock('Horde_Kolab_Server_Object_Interface'), array() ); } public function testMethodConstructHasParameterArrayDataToBeStored() { $changes = new Horde_Kolab_Server_Ldap_Changes( $this->getMock('Horde_Kolab_Server_Object_Interface'), array('store' => 'value') ); } public function testMethodGetchangesetHasResultArrayEmptyIfOldAndNewDatasetsWereEmpty() { $object = $this->getMock('Horde_Kolab_Server_Object_Interface'); $object->expects($this->once()) ->method('readInternal') ->will($this->returnValue(array())); $changes = new Horde_Kolab_Server_Ldap_Changes( $object, array() ); $this->assertEquals(array(), $changes->getChangeset()); } public function testMethodGetchangesetHasResultArrayEmptyIfOldAndNewDatasetsWereEqual() { $object = $this->getMock('Horde_Kolab_Server_Object_Interface'); $object->expects($this->once()) ->method('readInternal') ->will($this->returnValue(array('a' => array('a')))); $changes = new Horde_Kolab_Server_Ldap_Changes( $object, array('a' => array('a')) ); $this->assertEquals(array(), $changes->getChangeset()); } public function testMethodGetchangesetHasResultArrayNewAttributesInNewDatasetAsAdded() { $object = $this->getMock('Horde_Kolab_Server_Object_Interface'); $object->expects($this->once()) ->method('readInternal') ->will($this->returnValue(array())); $changes = new Horde_Kolab_Server_Ldap_Changes( $object, array('new' => 'a') ); $this->assertEquals( array( 'add' => array( 'new' => 'a' ) ), $changes->getChangeset() ); } public function testMethodGetchangesetHasResultArrayMissingValuesInNewDatasetAsDeleted() { $object = $this->getMock('Horde_Kolab_Server_Object_Interface'); $object->expects($this->once()) ->method('readInternal') ->will($this->returnValue(array('old' => 'a'))); $changes = new Horde_Kolab_Server_Ldap_Changes( $object, array() ); $this->assertEquals( array( 'delete' => array( 'old' ) ), $changes->getChangeset() ); } public function testMethodGetchangesetHasResultArraySingleValuesWithDifferencesAsReplaced() { $object = $this->getMock('Horde_Kolab_Server_Object_Interface'); $object->expects($this->once()) ->method('readInternal') ->will($this->returnValue(array('value' => 'a'))); $changes = new Horde_Kolab_Server_Ldap_Changes( $object, array('value' => 'b') ); $this->assertEquals( array( 'replace' => array( 'value' => 'b' ) ), $changes->getChangeset() ); } public function testMethodGetchangesetHasResultArrayTheNewValuesAsAdded() { $object = $this->getMock('Horde_Kolab_Server_Object_Interface'); $object->expects($this->once()) ->method('readInternal') ->will($this->returnValue(array('value' => array('a', 'b', 'c')))); $changes = new Horde_Kolab_Server_Ldap_Changes( $object, array('value' => array('a', 'b', 'c', 'd')) ); $this->assertEquals( array( 'add' => array( 'value' => array('d') ) ), $changes->getChangeset() ); } public function testMethodGetchangesetHasResultArrayTheRemovedValuesAsDeleted() { $object = $this->getMock('Horde_Kolab_Server_Object_Interface'); $object->expects($this->once()) ->method('readInternal') ->will($this->returnValue(array('value' => array('a', 'b', 'c')))); $changes = new Horde_Kolab_Server_Ldap_Changes( $object, array('value' => array('b', 'c')) ); $this->assertEquals( array( 'delete' => array( 'value' => array('a') ) ), $changes->getChangeset() ); } public function testMethodGetchangesetHasResultArrayTheNewValuesAsAddedAndTheRemovedValuesAsDeleted() { $object = $this->getMock('Horde_Kolab_Server_Object_Interface'); $object->expects($this->once()) ->method('readInternal') ->will($this->returnValue(array('value' => array('a', 'b', 'c')))); $changes = new Horde_Kolab_Server_Ldap_Changes( $object, array('value' => array('b', 'c', 'd')) ); $this->assertEquals( array( 'add' => array( 'value' => array('d') ), 'delete' => array( 'value' => array('a') ) ), $changes->getChangeset() ); } } Horde_Kolab_Server-2.0.5/test/Horde/Kolab/Server/Class/Server/Ldap/FilteredTest.php0000664000175000017500000000776012653735542026167 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * Require our basic test case definition */ require_once __DIR__ . '/../../../LdapTestCase.php'; /** * Test the filtered LDAP driver. * * Copyright 2009-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Class_Server_Ldap_FilteredTest extends Horde_Kolab_Server_LdapTestCase { public function setUp() { $this->skipIfNoLdap(); $this->ldap_read = $this->getMock('Horde_Ldap'); $this->ldap_write = $this->getMock('Horde_Ldap'); $connection = new Horde_Kolab_Server_Connection_Splittedldap( $this->ldap_read, $this->ldap_write ); $this->server = new Horde_Kolab_Server_Ldap_Filtered( $connection, 'base', 'filter' ); } private function getSearchResultMock() { $result = $this->getMock( 'Horde_Ldap_Search', array('asArray', 'count'), array(), '', false ); $result->expects($this->any()) ->method('asArray') ->will($this->returnValue(array(array('dn' => 'test')))); $result->expects($this->any()) ->method('count') ->will($this->returnValue(1)); return $result; } public function testMethodFindbelowHasParameterQueryelementTheSearchCriteria() { $this->ldap_read->expects($this->exactly(1)) ->method('search') ->with('', '(&(filter)(equals=equals))', array()) ->will($this->returnValue($this->getSearchResultMock())); $this->server->findBelow('(equals=equals)', ''); } public function testMethodFindbelowHasParameterStringParent() { $this->ldap_read->expects($this->exactly(1)) ->method('search') ->with('parent', '(&(filter)(equals=equals))', array()) ->will($this->returnValue($this->getSearchResultMock())); $this->server->findBelow('(equals=equals)', 'parent', array()); } public function testMethodFindbelowHasParameterArrayAdditionalParameters() { $this->ldap_read->expects($this->exactly(1)) ->method('search') ->with('', '(&(filter)(equals=equals))', array()) ->will($this->returnValue($this->getSearchResultMock())); $this->server->findBelow('(equals=equals)', '', array()); } public function testMethodFindbelowReturnsArraySearchResult() { $this->ldap_read->expects($this->exactly(1)) ->method('search') ->with('parent', '(&(filter)(equals=equals))', array()) ->will($this->returnValue($this->getSearchResultMock())); $this->assertEquals( array(array('dn' => 'test')), $this->server->findBelow('(equals=equals)', 'parent')->asArray() ); } public function testMethodFindbelowThrowsExceptionIfTheSearchFailed() { $this->ldap_read->expects($this->exactly(1)) ->method('search') ->will($this->throwException(new Horde_Ldap_Exception('Search failed!'))); try { $this->assertEquals(array('dn' => 'test'), $this->server->findBelow('(equals=equals)', '')); $this->fail('No exception!'); } catch (Exception $e) { $this->assertEquals('Search failed!', $e->getMessage()); $this->assertEquals(Horde_Kolab_Server_Exception::SYSTEM, $e->getCode()); } } } Horde_Kolab_Server-2.0.5/test/Horde/Kolab/Server/Class/Server/Ldap/StandardTest.php0000664000175000017500000000765612653735542026175 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * Require our basic test case definition */ require_once __DIR__ . '/../../../LdapTestCase.php'; /** * Test the standard LDAP driver. * * Copyright 2009-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Class_Server_Ldap_StandardTest extends Horde_Kolab_Server_LdapTestCase { public function setUp() { $this->skipIfNoLdap(); $this->ldap_read = $this->getMock('Horde_Ldap'); $this->ldap_write = $this->getMock('Horde_Ldap'); $connection = new Horde_Kolab_Server_Connection_Splittedldap( $this->ldap_read, $this->ldap_write ); $this->server = new Horde_Kolab_Server_Ldap_Standard( $connection, 'base' ); } private function getSearchResultMock() { $result = $this->getMock( 'Horde_Ldap_Search', array('asArray', 'count'), array(), '', false ); $result->expects($this->any()) ->method('asArray') ->will($this->returnValue(array(array('dn' => 'test')))); $result->expects($this->any()) ->method('count') ->will($this->returnValue(1)); return $result; } public function testMethodFindbelowHasParameterQueryelementTheSearchCriteria() { $this->ldap_read->expects($this->exactly(1)) ->method('search') ->with('', '(equals=equals)', array()) ->will($this->returnValue($this->getSearchResultMock())); $this->server->findBelow('(equals=equals)', ''); } public function testMethodFindbelowHasParameterStringParent() { $this->ldap_read->expects($this->exactly(1)) ->method('search') ->with('parent', '(equals=equals)', array()) ->will($this->returnValue($this->getSearchResultMock())); $this->server->findBelow('(equals=equals)', 'parent', array()); } public function testMethodFindbelowHasParameterArrayAdditionalParameters() { $this->ldap_read->expects($this->exactly(1)) ->method('search') ->with('', '(equals=equals)', array()) ->will($this->returnValue($this->getSearchResultMock())); $this->server->findBelow('(equals=equals)', '', array()); } public function testMethodFindbelowReturnsArraySearchResult() { $this->ldap_read->expects($this->exactly(1)) ->method('search') ->with('parent', '(equals=equals)', array()) ->will($this->returnValue($this->getSearchResultMock())); $this->assertEquals( array(array('dn' => 'test')), $this->server->findBelow('(equals=equals)', 'parent')->asArray() ); } public function testMethodFindbelowThrowsExceptionIfTheSearchFailed() { $this->ldap_read->expects($this->exactly(1)) ->method('search') ->will($this->throwException(new Horde_Ldap_Exception('Search failed!'))); try { $this->assertEquals(array('dn' => 'test'), $this->server->findBelow('(equals=equals)', '')); $this->fail('No exception!'); } catch (Exception $e) { $this->assertEquals('Search failed!', $e->getMessage()); $this->assertEquals(Horde_Kolab_Server_Exception::SYSTEM, $e->getCode()); } } } Horde_Kolab_Server-2.0.5/test/Horde/Kolab/Server/Class/Server/Object/Attribute/BaseTest.php0000664000175000017500000000704712653735542027572 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * Prepare the test setup. */ require_once __DIR__ . '/../../../../TestCase.php'; /** * Test the base attribute. * * Copyright 2009-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Class_Server_Object_Attribute_BaseTest extends Horde_Kolab_Server_TestCase { public function setUp() { $this->attribute = $this->getMock( 'Horde_Kolab_Server_Structure_Attribute_Interface' ); } public function testMethodConstructHasParameterAttributeTheAdapterCoveringTheInternalSideOfTheAttribute() { $attribute = new Attribute_Mock($this->attribute, ''); } public function testMethodConstructHasParameterStringTheNameOfTheAttribute() { $attribute = new Attribute_Mock($this->attribute, 'name'); } public function testMethodGetattributeReturnsAttributeInteralAssociatedWithThisAttribute() { $attribute = new Attribute_Mock($this->attribute, ''); $this->assertInstanceOf( 'Horde_Kolab_Server_Structure_Attribute_Interface', $attribute->getAttribute() ); } public function testMethodGetnameReturnsStringTheNameOfTheAttribute() { $attribute = new Attribute_Mock($this->attribute, 'name'); $this->assertEquals('name', $attribute->getName()); } public function testMethodIsemptyHasParameterArrayDataValues() { $attribute = new Attribute_Mock($this->attribute, 'name'); $attribute->isEmpty(array()); } public function testMethodIsemptyReturnsFalseIfTheValueIndicatedByTheAttributeNameIsNotEmptyInTheDataArray() { $attribute = new Attribute_Mock($this->attribute, 'name', 'name'); $this->assertFalse($attribute->isEmpty(array('name' => 'HELLO'))); } public function testMethodIsemptyReturnsTrueIfTheValueIndicatedByTheAttributeNameIsMissingInTheDataArray() { $attribute = new Attribute_Mock($this->attribute, 'name'); $this->assertTrue($attribute->isEmpty(array())); } public function testMethodIsemptyReturnsTrueIfTheValueIndicatedByTheAttributeNameIsStringEmptyInTheDataArray() { $attribute = new Attribute_Mock($this->attribute, 'name'); $this->assertTrue($attribute->isEmpty(array('name' => ''))); } public function testMethodIsemptyReturnsTrueIfTheValueIndicatedByTheAttributeNameIsNullInTheDataArray() { $attribute = new Attribute_Mock($this->attribute, 'name'); $this->assertTrue($attribute->isEmpty(array('name' => null))); } public function testMethodIsemptyReturnsTrueIfTheValueIndicatedByTheAttributeNameIsEmptyArrayInTheDataArray() { $attribute = new Attribute_Mock($this->attribute, 'name'); $this->assertTrue($attribute->isEmpty(array('name' => array()))); } } class Attribute_Mock extends Horde_Kolab_Server_Object_Attribute_Base { public function value() {} public function update(array $changes) {} }Horde_Kolab_Server-2.0.5/test/Horde/Kolab/Server/Class/Server/Object/Attribute/ValueTest.php0000664000175000017500000002063012653735542027765 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * Test the value attribute. * * Copyright 2009-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Class_Server_Object_Attribute_ValueTest extends PHPUnit_Framework_TestCase { public function setUp() { $this->markTestIncomplete('Needs to be fixed'); $this->object = $this->getMock( 'Horde_Kolab_Server_Object_Interface', array(), array(), '', false ); $this->composite = $this->getMock( 'Horde_Kolab_Server_Composite', array(), array(), '', false ); } public function testMethodValueHasResultArrayTheValuesOfTheAttribute() { $attribute = new Horde_Kolab_Server_Object_Attribute_Value( $this->object, $this->composite, 'name' ); $this->object->expects($this->once()) ->method('getInternal') ->with('name') ->will($this->returnValue(array(1, 2))); $this->assertEquals(array(1, 2), $attribute->value()); } public function testMethodConsumeHasParameterArrayData() { $attribute = new Horde_Kolab_Server_Object_Attribute_Value( $this->object, $this->composite, 'name' ); $data = array(); $attribute->consume($data); } public function testMethodConsumeHasPostconditionThatTheAttributeValueHasBeenRemovedFromTheDataArray() { $attribute = new Horde_Kolab_Server_Object_Attribute_Value( $this->object, $this->composite, 'name', 'name' ); $data = array('name' => 'test'); $attribute->consume($data); $this->assertEquals(array(), $data); } public function testMethodChangesHasParameterArrayData() { $attribute = new Horde_Kolab_Server_Object_Attribute_Value( $this->object, $this->composite, 'name' ); $this->object->expects($this->once()) ->method('exists') ->with() ->will($this->returnValue(false)); $data = array(); $attribute->update($data); } public function testMethodChangesHasResultArrayEmptyIfTheObjectDoesNotExistAndThereAreNoChangesToTheAttribute() { $attribute = new Horde_Kolab_Server_Object_Attribute_Value( $this->object, $this->composite, 'name' ); $this->object->expects($this->once()) ->method('exists') ->with() ->will($this->returnValue(false)); $data = array(); $this->assertEquals(array(), $attribute->update($data)); } public function testMethodChangesHasResultArrayWithAddedValuesIfTheObjectDoesNotExistAndThereAreChangesToTheAttribute() { $attribute = new Horde_Kolab_Server_Object_Attribute_Value( $this->object, $this->composite, 'name', 'name' ); $this->object->expects($this->once()) ->method('exists') ->with() ->will($this->returnValue(false)); $data = array('name' => 'a'); $this->assertEquals( array(array('name' => array('a'))), $attribute->update($data) ); } public function testMethodChangesHasResultArrayWithAddedValuesIfTheObjectExistsButHadNoValueForTheAttributeAndThereAreNoChangesToTheAttribute() { $attribute = new Horde_Kolab_Server_Object_Attribute_Value( $this->object, $this->composite, 'name' ); $this->object->expects($this->once()) ->method('exists') ->with() ->will($this->returnValue(true)); $this->object->expects($this->once()) ->method('getInternal') ->with('name') ->will( $this->throwException( new Horde_Kolab_Server_Exception_Novalue('') ) ); $data = array(); $this->assertEquals(array(), $attribute->update($data)); } public function testMethodChangesHasResultArrayWithAddedValuesIfTheObjectExistsButHadNoValueForTheAttributeAndThereAreChangesToTheAttribute() { $attribute = new Horde_Kolab_Server_Object_Attribute_Value( $this->object, $this->composite, 'name' ); $this->object->expects($this->once()) ->method('exists') ->with() ->will($this->returnValue(true)); $this->object->expects($this->once()) ->method('getInternal') ->with('name') ->will( $this->throwException( new Horde_Kolab_Server_Exception_Novalue('') ) ); $data = array('name' => 'a'); $this->assertEquals( array('add' => array('name' => array('a'))), $attribute->update($data) ); } public function testMethodChangesHasResultArrayWithDeletedValuesIfTheObjectExistsAndHadAValueForTheAttributeAndTheNewValueIsEmpty() { $attribute = new Horde_Kolab_Server_Object_Attribute_Value( $this->object, $this->composite, 'name' ); $this->object->expects($this->once()) ->method('exists') ->with() ->will($this->returnValue(true)); $this->object->expects($this->once()) ->method('getInternal') ->with('name') ->will($this->returnValue(array('a'))); $data = array('name' => null); $this->assertEquals( array('delete' => array('name' => array('a'))), $attribute->update($data) ); } public function testMethodChangesHasResultArrayWithReplacedValuesIfTheObjectExistsAndHadASingleValueForTheAttributeAndTheNewValueHasASingleNewValue() { $attribute = new Horde_Kolab_Server_Object_Attribute_Value( $this->object, $this->composite, 'name' ); $this->object->expects($this->once()) ->method('exists') ->with() ->will($this->returnValue(true)); $this->object->expects($this->once()) ->method('getInternal') ->with('name') ->will($this->returnValue(array('a'))); $data = array('name' => array('b')); $this->assertEquals( array('replace' => array('name' => array('b'))), $attribute->update($data) ); } public function testMethodChangesHasResultArrayEmptyIfTheObjectExistsAndHadASingleValueForTheAttributeAndTheNewValueHasASingleNewValueAndBothAreEqual() { $attribute = new Horde_Kolab_Server_Object_Attribute_Value( $this->object, $this->composite, 'name' ); $this->object->expects($this->once()) ->method('exists') ->with() ->will($this->returnValue(true)); $this->object->expects($this->once()) ->method('getInternal') ->with('name') ->will($this->returnValue(array('a'))); $data = array('name' => array('a')); $this->assertEquals(array(), $attribute->update($data)); } public function testMethodChangesHasResultArrayWithAddedAndDeletedValuesIfTheObjectExistsAndHadValuesForTheAttributeAndNewValuesHaveBeenProvided() { $attribute = new Horde_Kolab_Server_Object_Attribute_Value( $this->object, $this->composite, 'name' ); $this->object->expects($this->once()) ->method('exists') ->with() ->will($this->returnValue(true)); $this->object->expects($this->once()) ->method('getInternal') ->with('name') ->will($this->returnValue(array('a', 'c'))); $data = array('name' => array('b', 'c', 'd')); $this->assertEquals( array( 'add' => array('name' => array('b', 'd')), 'delete' => array('name' => array('a')) ), $attribute->update($data) ); } } Horde_Kolab_Server-2.0.5/test/Horde/Kolab/Server/Class/Server/Object/BaseTest.php0000664000175000017500000003045612653735542025627 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * Prepare the test setup. */ require_once __DIR__ . '/../../../TestCase.php'; /** * Test the base object. * * Copyright 2008-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Class_Server_Object_BaseTest extends Horde_Kolab_Server_TestCase { public function setUp() { } public function testMethodConstructHasParameterCompositeWhichIsTheLinkToTheServer() { $composite = $this->getComposite(); $object = new Object_Mock($composite, ''); } public function testMethodConstructHasParameterStringTheGuidOfTheObject() { $composite = $this->getComposite(); $object = new Object_Mock($composite, 'guid'); } public function testMethodGetguidHasResultStringGuidTheObjectIdOnTheServer() { $composite = $this->getComposite(); $object = new Object_Mock($composite, 'guid'); $this->assertEquals('guid', $object->getGuid()); } public function testMethodGetguidThrowsExceptionIfGuidHasNotBeenSetYet() { $composite = $this->getComposite(); $object = new Object_Mock($composite); try { $this->assertEquals('newGuid', $object->getGuid()); $this->fail('No exception!'); } catch (Horde_Kolab_Server_Exception $e) { $this->assertEquals( 'Uninitialized object is missing GUID!', $e->getMessage() ); } } public function testMethodGetexternalattributesHasResultArrayTheExternalAttributesSupportedByTheObject() { $composite = $this->getMockedComposite(); $composite->structure->expects($this->once()) ->method('getExternalAttributes') ->with($this->isInstanceOf('Horde_Kolab_Server_Object_Interface')) ->will($this->returnValue(array('external'))); $object = new Object_Mock($composite, 'guid'); $this->assertEquals(array('external'), $object->getExternalAttributes()); } public function testMethodGetinternalattributesHasResultArrayTheInternalAttributesSupportedByTheObject() { $composite = $this->getMockedComposite(); $composite->structure->expects($this->once()) ->method('getInternalAttributes') ->with($this->isInstanceOf('Horde_Kolab_Server_Object_Interface')) ->will($this->returnValue(array('internal'))); $object = new Object_Mock($composite, 'guid'); $this->assertEquals(array('internal'), $object->getInternalAttributes()); } public function testMethodExistsHasResultBooleanFalseIfTheGuidIsNotSpecified() { $composite = $this->getMockedComposite(); $object = new Object_Mock($composite); $this->assertFalse($object->exists()); } public function testMethodExistsHasResultBooleanFalseIfTheServerReturnedAnError() { $composite = $this->getMockedComposite(); $composite->structure->expects($this->once()) ->method('getInternalAttributes') ->with($this->isInstanceOf('Horde_Kolab_Server_Object_Interface')) ->will($this->returnValue(array('internal'))); $composite->server->expects($this->once()) ->method('readAttributes') ->with('guid', array('internal')) ->will($this->throwException(new Horde_Kolab_Server_Exception(''))); $object = new Object_Mock($composite, 'guid'); $this->assertFalse($object->exists()); } public function testMethodExistsHasResultBooleanTrueIfTheServerReturnedData() { $composite = $this->getMockedComposite(); $composite->structure->expects($this->once()) ->method('getInternalAttributes') ->with($this->isInstanceOf('Horde_Kolab_Server_Object_Interface')) ->will($this->returnValue(array('internal'))); $composite->server->expects($this->once()) ->method('readAttributes') ->with('guid', array('internal')) ->will($this->returnValue(array('a' => 'a'))); $object = new Object_Mock($composite, 'guid'); $this->assertTrue($object->exists()); } public function testMethodReadinternalHasResultArrayDataTheInternalObjectData() { $composite = $this->getMockedComposite(); $composite->structure->expects($this->once()) ->method('getInternalAttributes') ->with($this->isInstanceOf('Horde_Kolab_Server_Object_Interface')) ->will($this->returnValue(array('internal'))); $composite->server->expects($this->once()) ->method('readAttributes') ->with('guid', array('internal')) ->will($this->returnValue(array('internal' => 'test'))); $object = new Object_Mock($composite, 'guid'); $this->assertEquals( array('internal' => 'test'), $object->readInternal() ); } public function testMethodGetinternalHasResultArrayTheDataOfTheRequestedAttribute() { $composite = $this->getMockedComposite(); $composite->structure->expects($this->exactly(1)) ->method('getInternalAttributes') ->with($this->isInstanceOf('Horde_Kolab_Server_Object_Interface')) ->will($this->returnValue(array('internal'))); $composite->server->expects($this->once()) ->method('readAttributes') ->with('guid', array('internal')) ->will($this->returnValue(array('internal' => array('test')))); $object = new Object_Mock($composite, 'guid'); $this->assertEquals( array('internal' => array('test')), $object->getInternal(array('internal')) ); } public function testMethodGetinternalThrowsExceptionIfTheRequestedAttributeIsNotSupported() { $composite = $this->getMockedComposite(); $composite->structure->expects($this->once()) ->method('getInternalAttributes') ->with($this->isInstanceOf('Horde_Kolab_Server_Object_Interface')) ->will($this->returnValue(array('internal'))); $object = new Object_Mock($composite, 'guid'); try { $object->getInternal(array('test')); $this->fail('No exception!'); } catch (Horde_Kolab_Server_Exception $e) { $this->assertEquals('No value for attribute "test"!', $e->getMessage()); } } public function testMethodGetinternalThrowsExceptionIfTheRequestedAttributeHasNoValue() { $composite = $this->getMockedComposite(); $composite->structure->expects($this->exactly(1)) ->method('getInternalAttributes') ->with($this->isInstanceOf('Horde_Kolab_Server_Object_Interface')) ->will( $this->returnValue( array('internal', 'test') ) ); $composite->server->expects($this->once()) ->method('readAttributes') ->with('guid', array('internal', 'test')) ->will($this->returnValue(array('internal' => array('test')))); $object = new Object_Mock($composite, 'guid'); try { $object->getInternal(array('test')); $this->fail('No exception!'); } catch (Horde_Kolab_Server_Exception_Novalue $e) { $this->assertEquals('No value for attribute "test"!', $e->getMessage()); } } public function testMethodGetexternalHasResultArrayTheDataOfTheRequestedAttribute() { $composite = $this->getMockedComposite(); $composite->structure->expects($this->exactly(1)) ->method('getExternalAttributes') ->with($this->isInstanceOf('Horde_Kolab_Server_Object_Interface')) ->will($this->returnValue(array('objectClass'))); $external = $this->getMock('Horde_Kolab_Server_Object_Attribute_Interface'); $external->expects($this->once()) ->method('value') ->will($this->returnValue(array('test'))); $composite->structure->expects($this->exactly(1)) ->method('getExternalAttribute') ->with('objectClass') ->will( $this->returnValue( $external ) ); $object = new Object_Mock($composite, 'guid'); $this->assertEquals( array('test'), $object->getExternal('objectClass') ); } public function testMethodGetexternalThrowsExceptionIfTheRequestedAttributeIsNotSupported() { $composite = $this->getMockedComposite(); $composite->structure->expects($this->once()) ->method('getExternalAttributes') ->with($this->isInstanceOf('Horde_Kolab_Server_Object_Interface')) ->will($this->returnValue(array('external'))); $object = new Object_Mock($composite, 'guid'); try { $object->getExternal('test'); $this->fail('No exception!'); } catch (Horde_Kolab_Server_Exception $e) { $this->assertEquals('Attribute "test" not supported!', $e->getMessage()); } } public function testMethodDeleteHasPostconditionThatTheObjectWasDeletedOnTheServer() { $composite = $this->getMockedComposite(); $composite->server->expects($this->once()) ->method('delete') ->with('guid'); $object = new Object_Mock($composite, 'guid'); $object->delete(); } public function testMethodSaveHasParameterArrayTheDataToSave() { $composite = $this->getMockedComposite(); $composite->structure->expects($this->exactly(1)) ->method('getInternalAttributes') ->with($this->isInstanceOf('Horde_Kolab_Server_Object_Interface')) ->will( $this->returnValue( array( 'objectClass' ) ) ); $composite->server->expects($this->exactly(1)) ->method('readAttributes') ->with('guid', array('objectClass')) ->will($this->returnValue(array('objectClass' => array('test')))); $object = new Object_Mock($composite, 'guid'); $object->save(array()); } public function testMethodSaveHasPostconditionThatTheObjectWasAddedToTheServerIfItDidNotExistBefore() { $composite = $this->getMockedComposite(); $composite->structure->expects($this->exactly(1)) ->method('generateServerGuid') ->with( 'Object_Mock', null, array('objectClass' => array('top'))) ->will( $this->returnValue( array( 'objectClass' => 'Horde_Kolab_Server_Object_Attribute_Objectclass' ) ) ); $external = $this->getMock('Horde_Kolab_Server_Object_Attribute_Interface'); $external->expects($this->exactly(1)) ->method('update') ->will($this->returnValue(array('objectClass' => array('top')))); $composite->structure->expects($this->exactly(1)) ->method('getExternalAttribute') ->with('objectClass') ->will( $this->returnValue( $external ) ); $composite->server->expects($this->exactly(1)) ->method('add') ->with($this->isInstanceOf('Horde_Kolab_Server_Object_Interface'), array('objectClass' => array('top'))); $object = new Object_Mock($composite); $object->save(array('objectClass' => 'top')); } } class Object_Mock extends Horde_Kolab_Server_Object_Base { public function getActions() {} public static function getFilter() {} public function generateId(array &$info) {} public function prepareObjectInformation(array &$info) {} }Horde_Kolab_Server-2.0.5/test/Horde/Kolab/Server/Class/Server/Query/Element/MappedTest.php0000664000175000017500000001222112653735542027441 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * Test the mapped query element. * * Copyright 2009-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Class_Server_Query_Element_MappedTest extends PHPUnit_Framework_TestCase { public function setUp() { $this->element = $this->getMock( 'Horde_Kolab_Server_Query_Element_Interface' ); $this->mapper = $this->getMock( 'Horde_Kolab_Server_Decorator_Map', array(), array(), '', false, false ); } public function testMethodConstructHasParameterElementTheDecoratedElement() { $element = new Horde_Kolab_Server_Query_Element_Mapped( $this->element, $this->mapper ); } public function testMethodConstructHasParameterMapper() { $this->testMethodConstructHasParameterElementTheDecoratedElement(); } public function testMethodGetnameHasResultStringTheMappedNameOfTheElement() { $this->element->expects($this->once()) ->method('getName') ->will($this->returnValue('test')); $this->mapper->expects($this->once()) ->method('mapField') ->with('test') ->will($this->returnValue('mapped')); $element = new Horde_Kolab_Server_Query_Element_Mapped( $this->element, $this->mapper ); $this->assertEquals('mapped', $element->getName()); } public function testMethodGetvalueHasResultTheValueOfTheMappedElement() { $this->element->expects($this->once()) ->method('getValue') ->will($this->returnValue('test')); $element = new Horde_Kolab_Server_Query_Element_Mapped( $this->element, $this->mapper ); $this->assertEquals('test', $element->getValue()); } public function testMethodGetelementsHasResultArrayOfMappedElements() { $elements = array( $this->getMock( 'Horde_Kolab_Server_Query_Element_Interface' ), $this->getMock( 'Horde_Kolab_Server_Query_Element_Interface' ), ); $this->element->expects($this->once()) ->method('getElements') ->will($this->returnValue($elements)); $element = new Horde_Kolab_Server_Query_Element_Mapped( $this->element, $this->mapper ); $elements = $element->getElements(); foreach ($elements as $element) { $this->assertInstanceOf( 'Horde_Kolab_Server_Query_Element_Mapped', $element ); } } public function testMethodConvertHasResultStringTheConvertedElement() { $this->element->expects($this->once()) ->method('convert') ->will($this->returnValue('test')); $element = new Horde_Kolab_Server_Query_Element_Mapped( $this->element, $this->mapper ); $query = $this->getMock('Horde_Kolab_Server_Query_Interface'); $this->assertEquals('test', $element->convert($query)); } public function testMethodGetnameHasPostconditionThatTheCallWasDelegated() { $this->element->expects($this->once()) ->method('getName'); $element = new Horde_Kolab_Server_Query_Element_Mapped( $this->element, $this->mapper ); $element->getName(); } public function testMethodGetvalueHasPostconditionThatTheCallWasDelegated() { $this->element->expects($this->once()) ->method('getValue'); $element = new Horde_Kolab_Server_Query_Element_Mapped( $this->element, $this->mapper ); $element->getValue(); } public function testMethodGetelementsHasPostconditionThatTheCallWasDelegated() { $elements = array(); $this->element->expects($this->once()) ->method('getElements') ->will($this->returnValue($elements)); $element = new Horde_Kolab_Server_Query_Element_Mapped( $this->element, $this->mapper ); $element->getElements(); } public function testMethodConvertHasPostconditionThatTheCallWasDelegated() { $this->element->expects($this->once()) ->method('convert'); $element = new Horde_Kolab_Server_Query_Element_Mapped( $this->element, $this->mapper ); $query = $this->getMock('Horde_Kolab_Server_Query_Interface'); $element->convert($query); } } Horde_Kolab_Server-2.0.5/test/Horde/Kolab/Server/Class/Server/Query/ElementTest.php0000664000175000017500000001662712653735542026251 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * Test the LDAP query elements. * * Copyright 2009-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Class_Server_Query_ElementTest extends PHPUnit_Framework_TestCase { public function setUp() { $this->writer = $this->getMock( 'Horde_Kolab_Server_Query_Ldap', array(), array(), '', false ); } public function testClassAndMethodConvertHasResultMixedTheConvertedElement() { $this->writer->expects($this->exactly(1)) ->method('convertAnd') ->will($this->returnValue('converted')); $and = new Horde_Kolab_Server_Query_Element_And(array()); $this->assertEquals('converted', $and->convert($this->writer)); } public function testClassApproxMethodConvertHasResultMixedTheConvertedElement() { $this->writer->expects($this->exactly(1)) ->method('convertApprox') ->will($this->returnValue('converted')); $approx = new Horde_Kolab_Server_Query_Element_Approx('', ''); $this->assertEquals('converted', $approx->convert($this->writer)); } public function testClassBeginsMethodConvertHasResultMixedTheConvertedElement() { $this->writer->expects($this->exactly(1)) ->method('convertBegins') ->will($this->returnValue('converted')); $begins = new Horde_Kolab_Server_Query_Element_Begins('', ''); $this->assertEquals('converted', $begins->convert($this->writer)); } public function testClassContainsMethodConvertHasResultMixedTheConvertedElement() { $this->writer->expects($this->exactly(1)) ->method('convertContains') ->will($this->returnValue('converted')); $contains = new Horde_Kolab_Server_Query_Element_Contains('', ''); $this->assertEquals('converted', $contains->convert($this->writer)); } public function testClassEndsMethodConvertHasResultMixedTheConvertedElement() { $this->writer->expects($this->exactly(1)) ->method('convertEnds') ->will($this->returnValue('converted')); $ends = new Horde_Kolab_Server_Query_Element_Ends('', ''); $this->assertEquals('converted', $ends->convert($this->writer)); } public function testClassEqualsMethodConvertHasResultMixedTheConvertedElement() { $this->writer->expects($this->exactly(1)) ->method('convertEquals') ->will($this->returnValue('converted')); $equals = new Horde_Kolab_Server_Query_Element_Equals('', ''); $this->assertEquals('converted', $equals->convert($this->writer)); } public function testClassGreaterMethodConvertHasResultMixedTheConvertedElement() { $this->writer->expects($this->exactly(1)) ->method('convertGreater') ->will($this->returnValue('converted')); $greater = new Horde_Kolab_Server_Query_Element_Greater('', ''); $this->assertEquals('converted', $greater->convert($this->writer)); } public function testClassLessMethodConvertHasResultMixedTheConvertedElement() { $this->writer->expects($this->exactly(1)) ->method('convertLess') ->will($this->returnValue('converted')); $less = new Horde_Kolab_Server_Query_Element_Less('', ''); $this->assertEquals('converted', $less->convert($this->writer)); } public function testClassNotMethodConstructHasPostconditionThatTheElementWasSavedAsArray() { $less = new Horde_Kolab_Server_Query_Element_Less('', ''); $not = new Horde_Kolab_Server_Query_Element_Not($less); $this->assertInternalType('array', $not->getElements()); } public function testClassNotMethodConvertHasResultMixedTheConvertedElement() { $this->writer->expects($this->exactly(1)) ->method('convertNot') ->will($this->returnValue('converted')); $less = new Horde_Kolab_Server_Query_Element_Less('', ''); $not = new Horde_Kolab_Server_Query_Element_Not($less); $this->assertEquals('converted', $not->convert($this->writer)); } public function testClassOrMethodConvertHasResultMixedTheConvertedElement() { $this->writer->expects($this->exactly(1)) ->method('convertOr') ->will($this->returnValue('converted')); $or = new Horde_Kolab_Server_Query_Element_Or(array()); $this->assertEquals('converted', $or->convert($this->writer)); } public function testClassGroupMethodConstructHasParameterArrayElements() { $or = new Horde_Kolab_Server_Query_Element_Or(array()); } public function testClassGroupMethodConstructHasPostconditionThatTheElementsWereSaved() { $or = new Horde_Kolab_Server_Query_Element_Or(array()); $this->assertEquals(array(), $or->getElements()); } /** * @expectedException Horde_Kolab_Server_Exception */ public function testClassGroupMethodGetnameThrowsException() { $or = new Horde_Kolab_Server_Query_Element_Or(array()); $or->getName(); } /** * @expectedException Horde_Kolab_Server_Exception */ public function testClassGroupMethodGetvalueThrowsException() { $or = new Horde_Kolab_Server_Query_Element_Or(array()); $or->getValue(); } public function testClassGroupMethodGetelementsHasResultArrayTheGroupElements() { $or = new Horde_Kolab_Server_Query_Element_Or(array()); $this->assertEquals(array(), $or->getElements()); } public function testClassSingleMethodConstructHasParameterStringName() { $equals = new Horde_Kolab_Server_Query_Element_Equals('name', ''); } public function testClassSingleMethodConstructHasParameterStringValue() { $equals = new Horde_Kolab_Server_Query_Element_Equals('', 'value'); } public function testClassSingleMethodConstructHasPostconditionThatNameAndValueWereSaved() { $equals = new Horde_Kolab_Server_Query_Element_Equals('name', 'value'); $this->assertEquals('name', $equals->getName()); $this->assertEquals('value', $equals->getValue()); } public function testClassSingleMethodGetnameHasResultStringTheName() { $equals = new Horde_Kolab_Server_Query_Element_Equals('name', ''); $this->assertEquals('name', $equals->getName()); } public function testClassSingleMethodGetvalueHasResultStringTheValue() { $equals = new Horde_Kolab_Server_Query_Element_Equals('', 'value'); $this->assertEquals('value', $equals->getValue()); } /** * @expectedException Horde_Kolab_Server_Exception */ public function testClassSingleMethodGetelementsThrowsException() { $equals = new Horde_Kolab_Server_Query_Element_Equals('', ''); $equals->getElements(); } } Horde_Kolab_Server-2.0.5/test/Horde/Kolab/Server/Class/Server/Query/LdapTest.php0000664000175000017500000002116012653735542025524 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * Require our basic test case definition */ require_once __DIR__ . '/../../../LdapTestCase.php'; /** * Test the LDAP query handler. * * Copyright 2009-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Class_Server_Query_LdapTest extends Horde_Kolab_Server_LdapTestCase { public function setUp() { $this->skipIfNoLdap(); $this->structure = $this->getMock( 'Horde_Kolab_Server_Structure_Interface' ); } public function testMethodConstructHasParameterQueryelementTheQueryCriteria() { $equals = new Horde_Kolab_Server_Query_Element_Equals('equals', 'equals'); $query = new Horde_Kolab_Server_Query_Ldap($equals, $this->structure); } public function testMethodConstructHasPostconditionThatTheQueryCriteriaWereSaved() { $this->structure->expects($this->once()) ->method('mapExternalToInternalAttribute') ->will($this->returnValue('equals')); $equals = new Horde_Kolab_Server_Query_Element_Equals('equals', 'equals'); $query = new Horde_Kolab_Server_Query_Ldap($equals, $this->structure); $this->assertEquals( '(equals=equals)', (string) $query ); } public function testMethodTostringHasResultStringTheQuery() { $this->structure->expects($this->exactly(2)) ->method('mapExternalToInternalAttribute') ->will($this->returnValue('internal')); $equals = new Horde_Kolab_Server_Query_Element_Equals('equals', 'equals'); $contains = new Horde_Kolab_Server_Query_Element_Equals('contains', 'contains'); $or = new Horde_Kolab_Server_Query_Element_Or(array($equals, $contains)); $query = new Horde_Kolab_Server_Query_Ldap($or, $this->structure); $this->assertEquals( '(|(internal=equals)(internal=contains))', (string) $query ); } public function testMethodConvertequealsHasResultNetldapfilter() { $this->structure->expects($this->once()) ->method('mapExternalToInternalAttribute') ->will($this->returnValue('equals')); $equals = new Horde_Kolab_Server_Query_Element_Equals('equals', 'equals'); $query = new Horde_Kolab_Server_Query_Ldap($equals, $this->structure); $this->assertEquals( '(equals=equals)', (string)$query->convertEquals($equals) ); } public function testMethodConvertbeginsHasResultNetldapfilter() { $this->structure->expects($this->once()) ->method('mapExternalToInternalAttribute') ->will($this->returnValue('begins')); $begins = new Horde_Kolab_Server_Query_Element_Begins('begins', 'begins'); $query = new Horde_Kolab_Server_Query_Ldap($begins, $this->structure); $this->assertEquals( '(begins=begins*)', (string)$query->convertBegins($begins) ); } public function testMethodConvertendsHasResultNetldapfilter() { $this->structure->expects($this->once()) ->method('mapExternalToInternalAttribute') ->will($this->returnValue('ends')); $ends = new Horde_Kolab_Server_Query_Element_Ends('ends', 'ends'); $query = new Horde_Kolab_Server_Query_Ldap($ends, $this->structure); $this->assertEquals( '(ends=*ends)', (string)$query->convertEnds($ends) ); } public function testMethodConvertcontainsHasResultNetldapfilter() { $this->structure->expects($this->once()) ->method('mapExternalToInternalAttribute') ->will($this->returnValue('contains')); $contains = new Horde_Kolab_Server_Query_Element_Contains('contains', 'contains'); $query = new Horde_Kolab_Server_Query_Ldap($contains, $this->structure); $this->assertEquals( '(contains=*contains*)', (string)$query->convertContains($contains) ); } public function testMethodConvertlessHasResultNetldapfilter() { $this->structure->expects($this->once()) ->method('mapExternalToInternalAttribute') ->will($this->returnValue('less')); $less = new Horde_Kolab_Server_Query_Element_Less('less', 'less'); $query = new Horde_Kolab_Server_Query_Ldap($less, $this->structure); $this->assertEquals( '(lessconvertLess($less) ); } public function testMethodConvertgreaterHasResultNetldapfilter() { $this->structure->expects($this->once()) ->method('mapExternalToInternalAttribute') ->will($this->returnValue('greater')); $greater = new Horde_Kolab_Server_Query_Element_Greater('greater', 'greater'); $query = new Horde_Kolab_Server_Query_Ldap($greater, $this->structure); $this->assertEquals( '(greater>greater)', (string)$query->convertGreater($greater) ); } public function testMethodConvertapproxHasResultNetldapfilter() { $this->structure->expects($this->once()) ->method('mapExternalToInternalAttribute') ->will($this->returnValue('approx')); $approx = new Horde_Kolab_Server_Query_Element_Approx('approx', 'approx'); $query = new Horde_Kolab_Server_Query_Ldap($approx, $this->structure); $this->assertEquals( '(approx~=approx)', (string)$query->convertApprox($approx) ); } public function testMethodConvertnotHasResultNetldapfilter() { $this->structure->expects($this->once()) ->method('mapExternalToInternalAttribute') ->will($this->returnValue('equals')); $equals = new Horde_Kolab_Server_Query_Element_Equals('equals', 'equals'); $not = new Horde_Kolab_Server_Query_Element_Not($equals, $this->structure); $query = new Horde_Kolab_Server_Query_Ldap($not, $this->structure); $this->assertEquals( '(!(equals=equals))', (string)$query->convertNot($not) ); } public function testMethodConvertandHasResultNetldapfilter() { $this->structure->expects($this->exactly(2)) ->method('mapExternalToInternalAttribute') ->will($this->returnValue('internal')); $equals = new Horde_Kolab_Server_Query_Element_Equals('equals', 'equals'); $contains = new Horde_Kolab_Server_Query_Element_Equals('contains', 'contains'); $and = new Horde_Kolab_Server_Query_Element_And(array($equals, $contains)); $query = new Horde_Kolab_Server_Query_Ldap($and, $this->structure); $this->assertEquals( '(&(internal=equals)(internal=contains))', (string)$query->convertAnd($and) ); } public function testMethodConvertorHasResultNetldapfilter() { $this->structure->expects($this->exactly(2)) ->method('mapExternalToInternalAttribute') ->will($this->returnValue('internal')); $equals = new Horde_Kolab_Server_Query_Element_Equals('equals', 'equals'); $contains = new Horde_Kolab_Server_Query_Element_Equals('contains', 'contains'); $or = new Horde_Kolab_Server_Query_Element_Or(array($equals, $contains)); $query = new Horde_Kolab_Server_Query_Ldap($or, $this->structure); $this->assertEquals( '(|(internal=equals)(internal=contains))', (string)$query->convertOr($or) ); } public function testMethodConvertorThrowsExceptionIfLessThanTwoElementsWereProvided() { $equals = new Horde_Kolab_Server_Query_Element_Equals('equals', 'equals'); $or = new Horde_Kolab_Server_Query_Element_Or(array($equals)); $query = new Horde_Kolab_Server_Query_Ldap($or, $this->structure); try { (string)$query->convertOr($or); $this->fail('No exception!'); } catch (Horde_Kolab_Server_Exception $e) { $this->assertEquals(Horde_Kolab_Server_Exception::INVALID_QUERY, $e->getCode()); } } } Horde_Kolab_Server-2.0.5/test/Horde/Kolab/Server/Class/Server/Result/LdapTest.php0000664000175000017500000000517012653735542025700 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * Require our basic test case definition */ require_once __DIR__ . '/../../../LdapTestCase.php'; /** * Test the LDAP result handler. * * Copyright 2009-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Class_Server_Result_LdapTest extends Horde_Kolab_Server_LdapTestCase { public function setUp() { $this->skipIfNoLdap(); } public function testMethodConstructHasParameterNetldap2searchSearchResult() { $search = $this->getMock( 'Horde_Ldap_Search', array(), array(), '', false ); $result = new Horde_Kolab_Server_Result_Ldap($search); } public function testMethodCountHasResultIntTheNumberOfElementsFound() { $search = $this->getMock( 'Horde_Ldap_Search', array('count'), array(), '', false ); $search->expects($this->exactly(1)) ->method('count') ->will($this->returnValue(1)); $result = new Horde_Kolab_Server_Result_Ldap($search); $this->assertEquals(1, $result->count()); } public function testMethodSizelimitexceededHasResultBooleanIndicatingIfTheSearchSizeLimitWasHit() { $search = $this->getMock( 'Horde_Ldap_Search', array('sizeLimitExceeded'), array(), '', false ); $search->expects($this->exactly(1)) ->method('sizeLimitExceeded') ->will($this->returnValue(true)); $result = new Horde_Kolab_Server_Result_Ldap($search); $this->assertTrue($result->sizeLimitExceeded()); } public function testMethodAsarrayHasResultArrayWithTheSearchResults() { $search = $this->getMock( 'Horde_Ldap_Search', array('asArray'), array(), '', false ); $search->expects($this->exactly(1)) ->method('asArray') ->will($this->returnValue(array('a' => 'a'))); $result = new Horde_Kolab_Server_Result_Ldap($search); $this->assertEquals(array('a' => 'a'), $result->asArray()); } } Horde_Kolab_Server-2.0.5/test/Horde/Kolab/Server/Class/Server/Search/Operation/GuidforaliasTest.php0000664000175000017500000000373712653735542031327 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * Require our basic test case definition */ require_once __DIR__ . '/../../../../TestCase.php'; /** * Test the search operations by alias. * * Copyright 2009-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Class_Server_Search_Operation_GuidforaliasTest extends Horde_Kolab_Server_TestCase { public function setUp() { $this->structure = $this->getMock('Horde_Kolab_Server_Structure_Interface'); } public function testMethodRestrictkolabHasResultRestrictedToKolabUsers() { $result = $this->getMock('Horde_Kolab_Server_Result_Interface'); $result->expects($this->once()) ->method('asArray') ->will($this->returnValue(array('a' => 'a'))); $this->structure->expects($this->once()) ->method('find') ->with( $this->logicalAnd( $this->isRestrictedToKolabUsers(), $this->isSearchingByAlias() ), array('attributes' => 'guid') ) ->will($this->returnValue($result)); $search = new Horde_Kolab_Server_Search_Operation_Guidforalias($this->structure); $criteria = $this->getMock('Horde_Kolab_Server_Query_Element_Interface'); $this->assertEquals(array('a'), $search->searchGuidForAlias('test')); } }Horde_Kolab_Server-2.0.5/test/Horde/Kolab/Server/Class/Server/Search/Operation/GuidforcnTest.php0000664000175000017500000000353512653735542030632 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * Require our basic test case definition */ require_once __DIR__ . '/../../../../TestCase.php'; /** * Test the search operations by cn. * * Copyright 2009-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Class_Server_Search_Operation_GuidforcnTest extends Horde_Kolab_Server_TestCase { public function setUp() { $this->structure = $this->getMock('Horde_Kolab_Server_Structure_Interface'); } public function testMethodRestrictkolabHasResultRestrictedToKolabUsers() { $result = $this->getMock('Horde_Kolab_Server_Result_Interface'); $result->expects($this->once()) ->method('asArray') ->will($this->returnValue(array('a' => 'a'))); $this->structure->expects($this->once()) ->method('find') ->with( $this->isSearchingByCn(), array('attributes' => 'guid') ) ->will($this->returnValue($result)); $search = new Horde_Kolab_Server_Search_Operation_Guidforcn($this->structure); $criteria = $this->getMock('Horde_Kolab_Server_Query_Element_Interface'); $this->assertEquals(array('a'), $search->searchGuidForCn('test')); } }Horde_Kolab_Server-2.0.5/test/Horde/Kolab/Server/Class/Server/Search/Operation/GuidformailTest.php0000664000175000017500000000373112653735542031152 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * Require our basic test case definition */ require_once __DIR__ . '/../../../../TestCase.php'; /** * Test the search operations by mail. * * Copyright 2009-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Class_Server_Search_Operation_GuidformailTest extends Horde_Kolab_Server_TestCase { public function setUp() { $this->structure = $this->getMock('Horde_Kolab_Server_Structure_Interface'); } public function testMethodRestrictkolabHasResultRestrictedToKolabUsers() { $result = $this->getMock('Horde_Kolab_Server_Result_Interface'); $result->expects($this->once()) ->method('asArray') ->will($this->returnValue(array('a' => 'a'))); $this->structure->expects($this->once()) ->method('find') ->with( $this->logicalAnd( $this->isRestrictedToKolabUsers(), $this->isSearchingByMail() ), array('attributes' => 'guid') ) ->will($this->returnValue($result)); $search = new Horde_Kolab_Server_Search_Operation_Guidformail($this->structure); $criteria = $this->getMock('Horde_Kolab_Server_Query_Element_Interface'); $this->assertEquals(array('a'), $search->searchGuidForMail('test')); } }Horde_Kolab_Server-2.0.5/test/Horde/Kolab/Server/Class/Server/Search/Operation/GuidforuidTest.php0000664000175000017500000000372312653735542031012 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * Require our basic test case definition */ require_once __DIR__ . '/../../../../TestCase.php'; /** * Test the search operations by uid. * * Copyright 2009-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Class_Server_Search_Operation_GuidforuidTest extends Horde_Kolab_Server_TestCase { public function setUp() { $this->structure = $this->getMock('Horde_Kolab_Server_Structure_Interface'); } public function testMethodRestrictkolabHasResultRestrictedToKolabUsers() { $result = $this->getMock('Horde_Kolab_Server_Result_Interface'); $result->expects($this->once()) ->method('asArray') ->will($this->returnValue(array('a' => 'a'))); $this->structure->expects($this->once()) ->method('find') ->with( $this->logicalAnd( $this->isRestrictedToKolabUsers(), $this->isSearchingByUid() ), array('attributes' => 'guid') ) ->will($this->returnValue($result)); $search = new Horde_Kolab_Server_Search_Operation_Guidforuid($this->structure); $criteria = $this->getMock('Horde_Kolab_Server_Query_Element_Interface'); $this->assertEquals(array('a'), $search->searchGuidForUid('test')); } }Horde_Kolab_Server-2.0.5/test/Horde/Kolab/Server/Class/Server/Search/Operation/GuidTest.php0000664000175000017500000000653012653735542027600 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * Test the guid search operation. * * Copyright 2009-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Class_Server_Search_Operation_GuidTest extends PHPUnit_Framework_TestCase { public function setUp() { $this->structure = $this->getMock('Horde_Kolab_Server_Structure_Interface'); } public function testMethodConstructHasParameterStructure() { $search = new Horde_Kolab_Server_Search_Operation_Guid($this->structure); } public function testMethodConstructHasPostconditionThatTheServerStructureGetsStored() { $search = new Horde_Kolab_Server_Search_Operation_Guid($this->structure); $this->assertSame($this->structure, $search->getStructure()); } public function testMethodGetStructureHasResultStructureTheStructureAssociatedWithThisSearch() { $search = new Horde_Kolab_Server_Search_Operation_Guid($this->structure); $this->assertInstanceOf('Horde_Kolab_Server_Structure_Interface', $search->getStructure()); } public function testMethodSearchguidHasResultArrayTheGuidsOfTheSearchResult() { $result = $this->getMock('Horde_Kolab_Server_Result_Interface'); $result->expects($this->once()) ->method('asArray') ->will($this->returnValue(array('a' => 'a'))); $this->structure->expects($this->once()) ->method('find') ->with( $this->isInstanceOf( 'Horde_Kolab_Server_Query_Element_Interface' ), array('attributes' => 'guid') ) ->will($this->returnValue($result)); $search = new Horde_Kolab_Server_Search_Operation_Guid($this->structure); $criteria = $this->getMock('Horde_Kolab_Server_Query_Element_Interface'); $this->assertEquals(array('a'), $search->searchGuid($criteria)); } public function testMethodSearchguidHasResultArrayEmptyIfTheSearchReturnedNoResults() { $result = $this->getMock('Horde_Kolab_Server_Result_Interface'); $result->expects($this->once()) ->method('asArray') ->will($this->returnValue(array())); $this->structure->expects($this->once()) ->method('find') ->with( $this->isInstanceOf( 'Horde_Kolab_Server_Query_Element_Interface' ), array('attributes' => 'guid') ) ->will($this->returnValue($result)); $search = new Horde_Kolab_Server_Search_Operation_Guid($this->structure); $criteria = $this->getMock('Horde_Kolab_Server_Query_Element_Interface'); $this->assertEquals(array(), $search->searchGuid($criteria)); } } ././@LongLink000 145 0003736 LHorde_Kolab_Server-2.0.5/test/Horde/Kolab/Server/Class/Server/Search/Operation/RestrictgroupsTest.phpHorde_Kolab_Server-2.0.5/test/Horde/Kolab/Server/Class/Server/Search/Operation/RestrictgroupsTest.ph0000664000175000017500000000362512653735542031571 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * Require our basic test case definition */ require_once __DIR__ . '/../../../../TestCase.php'; /** * Test the search operations restricted to groups. * * Copyright 2009-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Class_Server_Search_Operation_RestrictgroupsTest extends Horde_Kolab_Server_TestCase { public function setUp() { $this->structure = $this->getMock('Horde_Kolab_Server_Structure_Interface'); } public function testMethodSearchrestrictgroupsHasResultRestrictedToGroups() { $result = $this->getMock('Horde_Kolab_Server_Result_Interface'); $result->expects($this->once()) ->method('asArray') ->will($this->returnValue(array('a' => 'a'))); $this->structure->expects($this->once()) ->method('find') ->with( $this->isRestrictedToGroups(), array('attributes' => 'guid') ) ->will($this->returnValue($result)); $search = new Horde_Kolab_Server_Search_Operation_Restrictgroups($this->structure); $criteria = $this->getMock('Horde_Kolab_Server_Query_Element_Interface'); $this->assertEquals(array('a'), $search->searchRestrictGroups($criteria)); } }././@LongLink000 144 0003735 LHorde_Kolab_Server-2.0.5/test/Horde/Kolab/Server/Class/Server/Search/Operation/RestrictkolabTest.phpHorde_Kolab_Server-2.0.5/test/Horde/Kolab/Server/Class/Server/Search/Operation/RestrictkolabTest.php0000664000175000017500000000363512653735542031523 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * Require our basic test case definition */ require_once __DIR__ . '/../../../../TestCase.php'; /** * Test the search operations restricted to Kolab users. * * Copyright 2009-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Class_Server_Search_Operation_RestrictkolabTest extends Horde_Kolab_Server_TestCase { public function setUp() { $this->structure = $this->getMock('Horde_Kolab_Server_Structure_Interface'); } public function testMethodRestrictkolabHasResultRestrictedToKolabUsers() { $result = $this->getMock('Horde_Kolab_Server_Result_Interface'); $result->expects($this->once()) ->method('asArray') ->will($this->returnValue(array('a' => 'a'))); $this->structure->expects($this->once()) ->method('find') ->with( $this->isRestrictedToKolabUsers(), array('attributes' => 'guid') ) ->will($this->returnValue($result)); $search = new Horde_Kolab_Server_Search_Operation_Restrictkolab($this->structure); $criteria = $this->getMock('Horde_Kolab_Server_Query_Element_Interface'); $this->assertEquals(array('a'), $search->searchRestrictkolab($criteria)); } }Horde_Kolab_Server-2.0.5/test/Horde/Kolab/Server/Class/Server/Search/BaseTest.php0000664000175000017500000001154112653735542025620 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * Prepare the test setup. */ require_once __DIR__ . '/../../../TestCase.php'; /** * Test the search handler. * * Copyright 2009-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Class_Server_Search_BaseTest extends Horde_Kolab_Server_TestCase { public function testSetcompositeHasParameterServercomposite() { $composite = $this->getMockedComposite(); $composite->structure->expects($this->once()) ->method('getSearchOperations') ->will($this->returnValue(array())); $search = new Horde_Kolab_Server_Search_Base(); $search->setComposite($composite); } public function testSetcompositeHasPostconditionThatTheAvailableSearchOperationsAreSet() { $composite = $this->getMockedComposite(); $composite->structure->expects($this->once()) ->method('getSearchOperations') ->will($this->returnValue(array('Object_Search'))); $search = new Horde_Kolab_Server_Search_Base(); $search->setComposite($composite); $this->assertEquals( array( 'call' => array('class' => 'Object_Search'), 'reset' => array('class' => 'Object_Search') ), $search->getSearchOperations() ); } public function testSetcompositeThrowsExceptionIfADeclaredSearchClassDoesNotExist() { $composite = $this->getMockedComposite(); $composite->structure->expects($this->once()) ->method('getSearchOperations') ->will($this->returnValue(array('Object_Search_NoSuchClass'))); $search = new Horde_Kolab_Server_Search_Base(); try { $search->setComposite($composite); } catch (Horde_Kolab_Server_Exception $e) { $this->assertContains( 'getSearchOperations specified non-existing class "Object_Search_NoSuchClass"!', $e->getMessage() ); } } public function testGetsearchoperationsHasResultTheSearchOperationsSupportedByThisServer() { $this->testSetcompositeHasPostconditionThatTheAvailableSearchOperationsAreSet(); } public function testCallHasResultTheResultOfTheSearchOperation() { $composite = $this->getMockedComposite(); $composite->structure->expects($this->once()) ->method('getSearchOperations') ->will($this->returnValue(array('Object_Search'))); $search = new Horde_Kolab_Server_Search_Base(); $search->setComposite($composite); $this->assertEquals(1, $search->call()); } public function testCallHasPostConditionThatTheSearchWasCalledWithTheServerRepresentation() { $composite = $this->getMockedComposite(); $composite->structure->expects($this->once()) ->method('getSearchOperations') ->will($this->returnValue(array('Object_Search'))); $search = new Horde_Kolab_Server_Search_Base(); $search->setComposite($composite); $search->call('a'); $this->assertEquals(array('a'), Object_Search::$last_call); } public function testCallThrowsExceptionIfTheSearchOperationIsNotSupported() { $composite = $this->getMockedComposite(); $composite->structure->expects($this->once()) ->method('getSearchOperations') ->will($this->returnValue(array('Object_Search'))); $search = new Horde_Kolab_Server_Search_Base(); $search->setComposite($composite); try { $search->search(); $this->fail('No exception!'); } catch (Horde_Kolab_Server_Exception $e) { $this->assertContains( 'does not support method "search"', $e->getMessage() ); } } public function tearDown() { Object_Search::reset(); } } class Object_Dummy { public static function getSearchOperations() { return array('Object_Search'); } } class Object_Search { public static $calls = 0; public static $last_call; public static function call() { self::$last_call = func_get_args(); return ++self::$calls; } public static function reset() { self::$calls = 0; } }Horde_Kolab_Server-2.0.5/test/Horde/Kolab/Server/Class/Server/Structure/KolabTest.php0000664000175000017500000003072412653735542026575 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * Test the LDAP backend. * * Copyright 2009-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Class_Server_Structure_KolabTest extends PHPUnit_Framework_TestCase { public function setUp() { $server = $this->getMock('Horde_Kolab_Server_Interface'); $this->composite = new Horde_Kolab_Server_Composite( $server, $this->getMock('Horde_Kolab_Server_Objects_Interface'), new Horde_Kolab_Server_Structure_Kolab(), $this->getMock('Horde_Kolab_Server_Search_Interface'), $this->getMock('Horde_Kolab_Server_Schema_Interface') ); } public function testMethodGetsupportedobjectsHasResultArrayTheObjectTypesSupportedByThisStructure() { $this->assertInternalType('array', $this->composite->structure->getSupportedObjects()); } public function testMethodDeterminetypeHasResultStringTheObjectclassOfTheGivenGuid1() { $this->composite->server->expects($this->exactly(1)) ->method('read') ->with('guid') ->will($this->returnValue(array('objectClass' => array('kolabGroupOfNames')))); $this->assertEquals('Horde_Kolab_Server_Object_Kolabgroupofnames', $this->composite->structure->determineType('guid')); } public function testMethodDeterminetypeHasResultStringTheObjectclassOfTheGivenGuid2() { $this->composite->server->expects($this->exactly(1)) ->method('read') ->with('guid') ->will($this->returnValue(array('objectClass' => array('kolabExternalPop3Account')))); $this->assertEquals('Horde_Kolab_Server_Object_Kolabpop3account', $this->composite->structure->determineType('guid')); } public function testMethodDeterminetypeHasResultStringTheObjectclassOfTheGivenGuid3() { $this->composite->server->expects($this->exactly(1)) ->method('read') ->with('guid') ->will($this->returnValue(array('objectClass' => array('kolabSharedFolder')))); $this->assertEquals('Horde_Kolab_Server_Object_Kolabsharedfolder', $this->composite->structure->determineType('guid')); } public function testMethodDeterminetypeHasResultStringTheObjectclassOfTheGivenGuid4() { $this->composite->server->expects($this->exactly(1)) ->method('read') ->with('guid') ->will($this->returnValue(array('objectClass' => array('top')))); $this->assertEquals('Horde_Kolab_Server_Object_Top', $this->composite->structure->determineType('guid')); } public function testMethodDeterminetypeHasResultStringTheObjectclassOfTheGivenGuid5() { $this->composite->server->expects($this->exactly(1)) ->method('read') ->with('guid') ->will( $this->returnValue( array( 'objectClass' => array( 'kolabinetorgperson', ) ) ) ); $this->composite->search->expects($this->exactly(1)) ->method('__call') ->with('searchGroupsForMember', array('guid')) ->will( $this->returnValue( array( ) ) ); $this->assertEquals( 'Horde_Kolab_Server_Object_Kolab_User', $this->composite->structure->determineType('guid') ); } public function testMethodDeterminetypeHasResultStringTheObjectclassOfTheGivenGuid6() { $this->composite->server->expects($this->exactly(1)) ->method('read') ->with('guid') ->will( $this->returnValue( array( 'objectClass' => array( 'kolabinetorgperson', ) ) ) ); $this->composite->server->expects($this->exactly(1)) ->method('getBaseGuid') ->will($this->returnValue('base')); $this->composite->search->expects($this->exactly(1)) ->method('__call') ->with('searchGroupsForMember', array('guid')) ->will( $this->returnValue( array( 'cn=admin,cn=internal,base' ) ) ); $this->assertEquals( 'Horde_Kolab_Server_Object_Kolab_Administrator', $this->composite->structure->determineType('guid') ); } public function testMethodDeterminetypeHasResultStringTheObjectclassOfTheGivenGuid7() { $this->composite->server->expects($this->exactly(1)) ->method('read') ->with('guid') ->will( $this->returnValue( array( 'objectClass' => array( 'kolabinetorgperson', ) ) ) ); $this->composite->server->expects($this->exactly(1)) ->method('getBaseGuid') ->will($this->returnValue('base')); $this->composite->search->expects($this->exactly(1)) ->method('__call') ->with('searchGroupsForMember', array('guid')) ->will( $this->returnValue( array( 'cn=maintainer,cn=internal,base' ) ) ); $this->assertEquals( 'Horde_Kolab_Server_Object_Kolab_Maintainer', $this->composite->structure->determineType('guid') ); } public function testMethodDeterminetypeHasResultStringTheObjectclassOfTheGivenGuid8() { $this->composite->server->expects($this->exactly(1)) ->method('read') ->with('guid') ->will( $this->returnValue( array( 'objectClass' => array( 'kolabinetorgperson', ) ) ) ); $this->composite->server->expects($this->exactly(1)) ->method('getBaseGuid') ->will($this->returnValue('base')); $this->composite->search->expects($this->exactly(1)) ->method('__call') ->with('searchGroupsForMember', array('guid')) ->will( $this->returnValue( array( 'cn=domain-maintainer,cn=internal,base' ) ) ); $this->assertEquals( 'Horde_Kolab_Server_Object_Kolab_Domainmaintainer', $this->composite->structure->determineType('guid') ); } public function testMethodDeterminetypeHasResultStringTheObjectclassOfTheGivenGuid9() { $this->composite->server->expects($this->exactly(1)) ->method('read') ->with('guid,cn=external') ->will( $this->returnValue( array( 'objectClass' => array( 'kolabinetorgperson', ) ) ) ); $this->composite->search->expects($this->exactly(1)) ->method('__call') ->with('searchGroupsForMember', array('guid,cn=external')) ->will( $this->returnValue( array( 'unknown' ) ) ); $this->assertEquals( 'Horde_Kolab_Server_Object_Kolab_Address', $this->composite->structure->determineType('guid,cn=external') ); } public function testMethodGenerateserverguidHasResultStringTheGuid1() { $this->composite->server->expects($this->exactly(1)) ->method('getBaseGuid') ->will($this->returnValue('base')); $this->assertEquals('id,base', $this->composite->structure->generateServerGuid('Horde_Kolab_Server_Object_Kolabgroupofnames', 'id', array())); } public function testMethodGenerateserverguidHasResultStringTheGuid2() { $this->composite->server->expects($this->exactly(1)) ->method('getBaseGuid') ->will($this->returnValue('base')); $this->assertEquals('id,cn=internal,base', $this->composite->structure->generateServerGuid('Horde_Kolab_Server_Object_Kolabgroupofnames', 'id', array('visible' => false))); } public function testMethodGenerateserverguidHasResultStringTheGuid3() { $this->composite->server->expects($this->exactly(1)) ->method('getBaseGuid') ->will($this->returnValue('base')); $this->assertEquals('id,base', $this->composite->structure->generateServerGuid('Horde_Kolab_Server_Object_Kolabsharedfolder', 'id', array('visible' => false))); } public function testMethodGenerateserverguidHasResultStringTheGuid4() { $this->composite->server->expects($this->exactly(1)) ->method('getBaseGuid') ->will($this->returnValue('base')); $this->assertEquals('id,cn=external,base', $this->composite->structure->generateServerGuid('Horde_Kolab_Server_Object_Kolab_Address', 'id', array())); } public function testMethodGenerateserverguidHasResultStringTheGuid5() { $this->composite->server->expects($this->exactly(1)) ->method('getBaseGuid') ->will($this->returnValue('base')); $this->assertEquals( 'id,cn=internal,base', $this->composite->structure->generateServerGuid( 'Horde_Kolab_Server_Object_Kolab_User', 'id', array('user_type' => Horde_Kolab_Server_Object_Kolab_User::USERTYPE_INTERNAL) ) ); } public function testMethodGenerateserverguidHasResultStringTheGuid6() { $this->composite->server->expects($this->exactly(1)) ->method('getBaseGuid') ->will($this->returnValue('base')); $this->assertEquals( 'id,cn=groups,base', $this->composite->structure->generateServerGuid( 'Horde_Kolab_Server_Object_Kolab_User', 'id', array('user_type' => Horde_Kolab_Server_Object_Kolab_User::USERTYPE_GROUP) ) ); } public function testMethodGenerateserverguidHasResultStringTheGuid7() { $this->composite->server->expects($this->exactly(1)) ->method('getBaseGuid') ->will($this->returnValue('base')); $this->assertEquals( 'id,cn=resources,base', $this->composite->structure->generateServerGuid( 'Horde_Kolab_Server_Object_Kolab_User', 'id', array('user_type' => Horde_Kolab_Server_Object_Kolab_User::USERTYPE_RESOURCE) ) ); } public function testMethodGenerateserverguidHasResultStringTheGuid8() { $this->composite->server->expects($this->exactly(1)) ->method('getBaseGuid') ->will($this->returnValue('base')); $this->assertEquals('id,base', $this->composite->structure->generateServerGuid('Horde_Kolab_Server_Object_Kolab_User', 'id', array())); } public function testMethodGenerateserverguidHasResultStringTheGuid9() { $this->composite->server->expects($this->exactly(1)) ->method('getBaseGuid') ->will($this->returnValue('base')); $this->assertEquals( 'id,base', $this->composite->structure->generateServerGuid( 'Horde_Kolab_Server_Object_Kolab_User', 'id', array('user_type' => 'undefined') ) ); } } Horde_Kolab_Server-2.0.5/test/Horde/Kolab/Server/Class/Server/Structure/LdapTest.php0000664000175000017500000001460312653735542026423 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * Require our basic test case definition */ require_once __DIR__ . '/../../../LdapTestCase.php'; /** * Test the LDAP backend. * * Copyright 2009-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Class_Server_Structure_LdapTest extends Horde_Kolab_Server_LdapTestCase { public function setUp() { $server = $this->getMock('Horde_Kolab_Server_Interface'); $this->composite = new Horde_Kolab_Server_Composite( $server, $this->getMock('Horde_Kolab_Server_Objects_Interface'), new Horde_Kolab_Server_Structure_Ldap(), $this->getMock('Horde_Kolab_Server_Search_Interface'), $this->getMock('Horde_Kolab_Server_Schema_Interface') ); } public function testMethodFindHasResultServerResultTheSearchResult() { $this->skipIfNoLdap(); $result = $this->getMock('Horde_Kolab_Server_Result_Interface'); $this->composite->server->expects($this->exactly(1)) ->method('find') ->with('(objectClass=equals)', array()) ->will($this->returnValue($result)); $equals = new Horde_Kolab_Server_Query_Element_Equals('objectClass', 'equals'); $this->assertInstanceOf( 'Horde_Kolab_Server_Result_Interface', $this->composite->structure->find($equals, array()) ); } public function testMethodFindBelowHasResultServerResultTheSearchResult() { $this->skipIfNoLdap(); $result = $this->getMock('Horde_Kolab_Server_Result_Interface'); $this->composite->server->expects($this->exactly(1)) ->method('findBelow') ->with('(objectClass=equals)', 'base', array()) ->will($this->returnValue($result)); $equals = new Horde_Kolab_Server_Query_Element_Equals('objectClass', 'equals'); $this->assertInstanceOf( 'Horde_Kolab_Server_Result_Interface', $this->composite->structure->findBelow($equals, 'base', array()) ); } public function testMethodGetsupportedobjectsHasResultArrayTheObjectTypesSupportedByThisStructure() { $this->assertEquals(array('Horde_Kolab_Server_Object'), $this->composite->structure->getSupportedObjects()); } public function testMethodDeterminetypeHasParameterStringGuid() { $this->composite->server->expects($this->exactly(1)) ->method('read') ->with('guid') ->will($this->returnValue(array('objectClass' => array('TOP')))); $this->composite->structure->determineType('guid'); } public function testMethodDeterminetypeHasResultStringTheObjectclassOfTheGivenGuid() { $this->composite->server->expects($this->exactly(1)) ->method('read') ->with('guid') ->will($this->returnValue(array('objectClass' => array('TOP')))); $this->assertEquals('Horde_Kolab_Server_Object_Top', $this->composite->structure->determineType('guid')); } public function testMethodDeterminetypeHasResultStringTheObjectclassOfTheGivenGuid2() { $this->composite->server->expects($this->exactly(1)) ->method('read') ->with('guid') ->will($this->returnValue(array('objectClass' => array('person')))); $this->assertEquals('Horde_Kolab_Server_Object_Person', $this->composite->structure->determineType('guid')); } public function testMethodDeterminetypeThrowsExceptionIfTheGuidHasNoAttributeObjectclass() { $this->composite->server->expects($this->exactly(1)) ->method('read') ->with('guid') ->will($this->returnValue(array())); try { $this->composite->structure->determineType('guid'); } catch (Exception $e) { $this->assertEquals('The object guid has no objectClass attribute!', $e->getMessage()); $this->assertEquals(Horde_Kolab_Server_Exception::SYSTEM, $e->getCode()); } } public function testMethodDeterminetypeThrowsExceptionIfTheTypeIsUnknown() { $this->composite->server->expects($this->exactly(1)) ->method('read') ->with('guid') ->will($this->returnValue(array('objectClass' => array('UNKNOWN')))); try { $this->composite->structure->determineType('guid'); } catch (Exception $e) { $this->assertEquals('Unknown object type for GUID guid.', $e->getMessage()); $this->assertEquals(Horde_Kolab_Server_Exception::SYSTEM, $e->getCode()); } } public function testMethodGenerateserverguidHasParameterStringType() { $this->composite->server->expects($this->exactly(1)) ->method('getBaseGuid') ->will($this->returnValue('base')); $this->composite->structure->generateServerGuid('type', '', array()); } public function testMethodGenerateserverguidHasParameterStringId() { $this->composite->server->expects($this->exactly(1)) ->method('getBaseGuid') ->will($this->returnValue('base')); $this->composite->structure->generateServerGuid('', 'id', array()); } public function testMethodGenerateserverguidHasParameterArrayObjectData() { $this->composite->server->expects($this->exactly(1)) ->method('getBaseGuid') ->will($this->returnValue('base')); $this->composite->structure->generateServerGuid('', '', array('object' => 'data')); } public function testMethodGenerateserverguidHasResultStringTheGuid() { $this->composite->server->expects($this->exactly(1)) ->method('getBaseGuid') ->will($this->returnValue('base')); $this->assertEquals('id,base', $this->composite->structure->generateServerGuid('', 'id', array())); } }Horde_Kolab_Server-2.0.5/test/Horde/Kolab/Server/Class/Server/LdapTest.php0000664000175000017500000004534612653735542024433 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * Require our basic test case definition */ require_once __DIR__ . '/../../LdapTestCase.php'; /** * Test the LDAP backend. * * Copyright 2009-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Class_Server_LdapTest extends Horde_Kolab_Server_LdapTestCase { public function setUp() { $this->skipIfNoLdap(); $this->ldap_read = $this->getMock('Horde_Ldap'); $this->ldap_write = $this->getMock('Horde_Ldap'); $connection = new Horde_Kolab_Server_Connection_Splittedldap( $this->ldap_read, $this->ldap_write ); $this->server = new Horde_Kolab_Server_Ldap_Standard( $connection, 'base' ); } private function getSearchResultMock() { $result = $this->getMock( 'Horde_Ldap_Search', array('asArray', 'count'), array(), '', false ); $result->expects($this->any()) ->method('asArray') ->will($this->returnValue(array(array('dn' => 'test')))); $result->expects($this->any()) ->method('count') ->will($this->returnValue(1)); return $result; } public function testMethodGetbaseguidHasResultStringBaseGuid() { $this->assertEquals('base', $this->server->getBaseGuid()); } public function testMethodConnectguidHasStringParameterGuid() { $this->server->connectGuid('guid', ''); } public function testMethodConnectguidHasStringParameterPass() { $this->server->connectGuid('', 'pass'); } public function testMethodConnectguidHasPostconditionThatTheGuidIsSetIfTheConnectionWasSuccessful() { $this->ldap_read->expects($this->exactly(1)) ->method('bind') ->will($this->returnValue(true)); $this->server->connectGuid('test', 'test'); $this->assertEquals('test', $this->server->getGuid()); } public function testMethodConnectguidDoesNotCallBindAgainIfAlreadyConnectedWithThisGuid() { $this->ldap_read->expects($this->exactly(1)) ->method('bind') ->will($this->returnValue(true)); $this->server->connectGuid('test', 'test'); $this->server->connectGuid('test', 'test'); } public function testMethodConnectguidDoesNotCallBindAgainIfAlreadyConnectedWithThisGuidEvenIfTheGuidIsEmpty() { $this->ldap_read->expects($this->exactly(1)) ->method('bind') ->will($this->returnValue(true)); $this->server->connectGuid('', ''); $this->server->connectGuid('', ''); } public function testMethodConnectguidThrowsExceptionIfTheConnectionFailed() { $this->ldap_read->expects($this->exactly(1)) ->method('bind') ->will($this->throwException(new Horde_Ldap_Exception('Bind failed!'))); try { $this->server->connectGuid('test', 'test'); $this->fail('No exception!'); } catch (Exception $e) { $this->assertEquals('Bind failed!', $e->getMessage()); $this->assertEquals(Horde_Kolab_Server_Exception::SYSTEM, $e->getCode()); } } public function testMethodConnectguidThrowsExceptionIfTheCredentialsWereInvalid() { $this->ldap_read->expects($this->exactly(1)) ->method('bind') ->will($this->throwException(new Horde_Ldap_Exception('Credentials invalid!', 49))); try { $this->server->connectGuid('test', 'test'); $this->fail('No exception!'); } catch (Horde_Kolab_Server_Exception_Bindfailed $e) { $this->assertEquals('Invalid username/password!', $e->getMessage()); } } public function testMethodGetguidHasResultBooleanFalseIfNotConnected() { $this->assertSame(false, $this->server->getGuid()); } public function testMethodGetguidHasResultStringGuidIfNotConnected() { $this->server->connectGuid('guid', ''); $this->assertEquals('guid', $this->server->getGuid()); } public function testMethodReadHasParameterStringGuid() { $this->ldap_read->expects($this->exactly(1)) ->method('search') ->with('test', null, array('scope' => 'base')) ->will($this->returnValue($this->getSearchResultMock())); $this->server->read('test'); } public function testMethodReadReturnsArrayReadResult() { $this->ldap_read->expects($this->exactly(1)) ->method('search') ->with('test', null, array('scope' => 'base')) ->will($this->returnValue($this->getSearchResultMock())); $this->assertEquals(array('dn' => 'test'), $this->server->read('test')); } public function testMethodReadThrowsExceptionIfTheObjectWasNotFound() { $result = $this->getMock( 'Horde_Ldap_Search', array('asArray', 'count'), array(), '', false ); $result->expects($this->exactly(1)) ->method('count') ->will($this->returnValue(0)); $this->ldap_read->expects($this->exactly(1)) ->method('search') ->will($this->returnValue($result)); try { $this->assertEquals(array(), $this->server->read('test')); $this->fail('No exception!'); } catch (Exception $e) { $this->assertEquals('Empty result!', $e->getMessage()); $this->assertEquals(Horde_Kolab_Server_Exception::EMPTY_RESULT, $e->getCode()); } } public function testMethodReadAttributesHasParameterStringGuid() { $this->ldap_read->expects($this->exactly(1)) ->method('search') ->with('guid', null, array('scope' => 'base', 'attributes' => array())) ->will($this->returnValue($this->getSearchResultMock())); $this->server->readAttributes('guid', array()); } public function testMethodReadAttributesHasParameterArrayAttributes() { $this->ldap_read->expects($this->exactly(1)) ->method('search') ->with('', null, array('scope' => 'base', 'attributes' => array('a'))) ->will($this->returnValue($this->getSearchResultMock())); $this->server->readAttributes('', array('a')); } public function testMethodReadAttributesReturnsArrayReadResult() { $this->ldap_read->expects($this->exactly(1)) ->method('search') ->with('test', null, array('scope' => 'base', 'attributes' => array('a'))) ->will($this->returnValue($this->getSearchResultMock())); $this->assertEquals(array('dn' => 'test'), $this->server->readAttributes('test', array('a'))); } public function testMethodReadAttributesThrowsExceptionIfTheObjectWasNotFound() { $result = $this->getMock( 'Horde_Ldap_Search', array('asArray', 'count'), array(), '', false ); $result->expects($this->exactly(1)) ->method('count') ->will($this->returnValue(0)); $this->ldap_read->expects($this->exactly(1)) ->method('search') ->with('test', null, array('scope' => 'base', 'attributes' => array('a'))) ->will($this->returnValue($result)); try { $this->assertEquals(array(), $this->server->readAttributes('test', array('a'))); $this->fail('No exception!'); } catch (Exception $e) { $this->assertEquals('Empty result!', $e->getMessage()); $this->assertEquals(Horde_Kolab_Server_Exception::EMPTY_RESULT, $e->getCode()); } } public function testMethodFindHasParameterQueryelementTheSearchCriteria() { $this->ldap_read->expects($this->exactly(1)) ->method('search') ->with('base', '(equals=equals)', array()) ->will($this->returnValue($this->getSearchResultMock())); $this->server->find('(equals=equals)'); } public function testMethodFindHasParameterArrayAdditionalParameters() { $this->ldap_read->expects($this->exactly(1)) ->method('search') ->with('base', '(equals=equals)', array()) ->will($this->returnValue($this->getSearchResultMock())); $this->server->find('(equals=equals)', array()); } public function testMethodFindReturnsArraySearchResult() { $this->ldap_read->expects($this->exactly(1)) ->method('search') ->with('base', '(equals=equals)', array()) ->will($this->returnValue($this->getSearchResultMock())); $this->assertEquals( array(array('dn' => 'test')), $this->server->find('(equals=equals)')->asArray() ); } public function testMethodFindThrowsExceptionIfTheSearchFailed() { $this->ldap_read->expects($this->exactly(1)) ->method('search') ->will($this->throwException(new Horde_Ldap_Exception('Search failed!'))); try { $this->assertEquals(array('dn' => 'test'), $this->server->find('(equals=equals)')); $this->fail('No exception!'); } catch (Exception $e) { $this->assertEquals('Search failed!', $e->getMessage()); $this->assertEquals(Horde_Kolab_Server_Exception::SYSTEM, $e->getCode()); } } public function testMethodSaveHasParameterObjectTheObjectToModifyOnTheServer() { $entry = $this->getMock( 'Horde_Ldap_Entry', array(), array(), '', false ); $object = $this->getMock('Horde_Kolab_Server_Object_Interface'); $this->ldap_write->expects($this->exactly(1)) ->method('getEntry') ->will($this->returnValue($entry)); $this->ldap_write->expects($this->exactly(1)) ->method('modify') ->with(new PHPUnit_Framework_Constraint_IsInstanceOf('Horde_Ldap_Entry')); $object->expects($this->exactly(1)) ->method('readInternal') ->will($this->returnValue(array())); $this->server->save($object, array('attributes' => array('dn'))); } public function testMethodSaveHasParameterArrayData() { $entry = $this->getMock( 'Horde_Ldap_Entry', array(), array(), '', false ); $object = $this->getMock('Horde_Kolab_Server_Object_Interface'); $this->ldap_write->expects($this->exactly(1)) ->method('getEntry') ->will($this->returnValue($entry)); $this->ldap_write->expects($this->exactly(1)) ->method('modify') ->with(new PHPUnit_Framework_Constraint_IsInstanceOf('Horde_Ldap_Entry')); $object->expects($this->exactly(1)) ->method('readInternal') ->will($this->returnValue(array())); $this->server->save($object, array('dn' => 'test')); } public function testMethodSaveHasPostconditionThatTheEntryWasModified() { $entry = $this->getMock( 'Horde_Ldap_Entry', array(), array(), '', false ); $object = $this->getMock('Horde_Kolab_Server_Object_Interface'); $this->ldap_write->expects($this->exactly(1)) ->method('getEntry') ->will($this->returnValue($entry)); $this->ldap_write->expects($this->exactly(1)) ->method('modify') ->with(new PHPUnit_Framework_Constraint_IsInstanceOf('Horde_Ldap_Entry')); $object->expects($this->exactly(1)) ->method('readInternal') ->will($this->returnValue(array())); $this->server->save($object, array('dn' => 'test')); } public function testMethodSaveThrowsExceptionIfSavingDataFailed() { $object = $this->getMock('Horde_Kolab_Server_Object_Interface'); $this->ldap_write->expects($this->exactly(1)) ->method('modify') ->will($this->throwException(new Horde_Ldap_Exception('Saving failed!'))); $object->expects($this->exactly(1)) ->method('readInternal') ->will($this->returnValue(array())); try { $this->server->save($object, array('dn' => 'test')); $this->fail('No exception!'); } catch (Exception $e) { $this->assertEquals('Saving failed!', $e->getMessage()); $this->assertEquals(Horde_Kolab_Server_Exception::SYSTEM, $e->getCode()); } } public function testMethodAddHasParameterObjectTheObjectToAddToTheServer() { $object = $this->getMock('Horde_Kolab_Server_Object_Interface'); $this->ldap_write->expects($this->exactly(1)) ->method('add') ->with(new PHPUnit_Framework_Constraint_IsInstanceOf('Horde_Ldap_Entry')); $this->server->add($object, array('attributes' => array('dn'))); } public function testMethodAddHasParameterArrayData() { $object = $this->getMock('Horde_Kolab_Server_Object_Interface'); $this->ldap_write->expects($this->exactly(1)) ->method('add') ->with(new PHPUnit_Framework_Constraint_IsInstanceOf('Horde_Ldap_Entry')); $this->server->add($object, array('dn' => 'test')); } public function testMethodAddHasPostconditionThatTheEntryWasModified() { $object = $this->getMock('Horde_Kolab_Server_Object_Interface'); $this->ldap_write->expects($this->exactly(1)) ->method('add') ->with(new PHPUnit_Framework_Constraint_IsInstanceOf('Horde_Ldap_Entry')); $this->server->add($object, array('dn' => 'test')); } public function testMethodAddThrowsExceptionIfSavingDataFailed() { $object = $this->getMock('Horde_Kolab_Server_Object_Interface'); $this->ldap_write->expects($this->exactly(1)) ->method('add') ->will($this->throwException(new Horde_Ldap_Exception('Saving failed!'))); try { $this->server->add($object, array('add' => array('dn' => 'test'))); $this->fail('No exception!'); } catch (Exception $e) { $this->assertEquals('Adding object failed!', $e->getMessage()); $this->assertEquals(Horde_Kolab_Server_Exception::SYSTEM, $e->getCode()); } } public function testMethodDeleteHasParameterStringGuid() { $this->ldap_write->expects($this->exactly(1)) ->method('delete') ->with('guid'); $this->server->delete('guid'); } public function testMethodDeleteHasPostconditionThatTheEntryWasDeleted() { $this->ldap_write->expects($this->exactly(1)) ->method('delete') ->with('test'); $this->server->delete('test'); } public function testMethodDeleteThrowsExceptionIfDeletingDataFailed() { $this->ldap_write->expects($this->exactly(1)) ->method('delete') ->will($this->throwException(new Horde_Ldap_Exception('Deleting failed!'))); try { $this->server->delete('test'); $this->fail('No exception!'); } catch (Exception $e) { $this->assertEquals('Deleting object failed!', $e->getMessage()); $this->assertEquals(Horde_Kolab_Server_Exception::SYSTEM, $e->getCode()); } } public function testMethodRenameHasParameterStringOldGuid() { $this->ldap_write->expects($this->exactly(1)) ->method('move') ->with('oldguid', ''); $this->server->rename('oldguid', ''); } public function testMethodRenameHasParameterStringNewGuid() { $this->ldap_write->expects($this->exactly(1)) ->method('move') ->with('', 'newguid'); $this->server->rename('', 'newguid'); } public function testMethodRenameHasPostconditionThatTheEntryWasRenamed() { $this->ldap_write->expects($this->exactly(1)) ->method('move') ->with('test', 'new'); $this->server->rename('test', 'new'); } public function testMethodRenameThrowsExceptionIfRenamingDataFailed() { $this->ldap_write->expects($this->exactly(1)) ->method('move') ->will($this->throwException(new Horde_Ldap_Exception('Renaming failed!'))); try { $this->server->rename('test', 'new'); $this->fail('No exception!'); } catch (Exception $e) { $this->assertEquals('Renaming object failed!', $e->getMessage()); $this->assertEquals(Horde_Kolab_Server_Exception::SYSTEM, $e->getCode()); } } public function testMethodGetschemaReturnsArrayWithADescriptionOfAllObjectClasses() { $this->ldap_read->expects($this->exactly(1)) ->method('schema') ->will($this->returnValue(array('schema' => 'dummy'))); $this->assertEquals( array('schema' => 'dummy'), $this->server->getSchema() ); } public function testMethodGetschemaThrowsExceptionIfTheSchemaRetrievalFailed() { $this->ldap_read->expects($this->exactly(1)) ->method('schema') ->will($this->throwException(new Horde_Ldap_Exception('Schema failed!'))); try { $this->server->getSchema(); $this->fail('No exception!'); } catch (Exception $e) { $this->assertEquals('Retrieving the schema failed!', $e->getMessage()); $this->assertEquals(Horde_Kolab_Server_Exception::SYSTEM, $e->getCode()); } } public function testMethodGetparentguidHasResultStringParentGuid() { $this->assertEquals( 'cn=parent', $this->server->getParentGuid('cn=child,cn=parent') ); } /* public function testMethodSearchReturnsArrayMappedSearchResultIfMappingIsActivated() */ /* { */ /* $ldap = $this->getMock('Horde_Ldap', array('search')); */ /* $ldap->expects($this->exactly(1)) */ /* ->method('search') */ /* ->will($this->returnValue(new Search_Mock(array(array('dn2' => 'test'))))); */ /* $this->server->setLdap($ldap); */ /* $this->server->setParams(array('map' => array('dn' => 'dn2'))); */ /* $this->assertEquals( */ /* array(array('dn' => 'test')), */ /* $this->server->search( */ /* 'filter', */ /* array('attributes' => array('dn')) */ /* ) */ /* ); */ /* } */ } Horde_Kolab_Server-2.0.5/test/Horde/Kolab/Server/Constraints/Restrictgroups.php0000664000175000017500000000306312653735542025734 0ustar janjangetElements(); foreach ($elements as $element) { if ($this->evaluate($element)) { return true; } } return true; } else { if ($other->getName() == 'objectClass' && $other->getValue() == Horde_Kolab_Server_Object_Groupofnames::OBJECTCLASS_GROUPOFNAMES) { return true; } else { return false; } } } else { return false; } } public function fail($other, $description, \SebastianBergmann\Comparator\ComparisonFailure $comparisonFailure = NULL) { throw new PHPUnit_Framework_ExpectationFailedException( sprintf( '%sFailed asserting that %s contains a query element that restricts the search to groups', !empty($description) ? $description . "\n" : '', PHPUnit_Util_Type::toString($other, TRUE) ), NULL ); } public function toString() { return 'contains a query element that restricts the search to groups'; } } Horde_Kolab_Server-2.0.5/test/Horde/Kolab/Server/Constraints/Restrictkolabusers.php0000664000175000017500000000311712653735542026567 0ustar janjangetElements(); foreach ($elements as $element) { if ($this->evaluate($element)) { return true; } } return true; } else { if ($other->getName() == 'objectClass' && $other->getValue() == Horde_Kolab_Server_Object_Kolabinetorgperson::OBJECTCLASS_KOLABINETORGPERSON) { return true; } else { return false; } } } else { return false; } } public function fail($other, $description, \SebastianBergmann\Comparator\ComparisonFailure $comparisonFailure = NULL) { throw new PHPUnit_Framework_ExpectationFailedException( sprintf( '%sFailed asserting that %s contains a query element that restricts the search to Kolab users', !empty($description) ? $description . "\n" : '', PHPUnit_Util_Type::toString($other, TRUE) ), NULL ); } public function toString() { return 'contains a query element that restricts the search to Kolab users'; } } Horde_Kolab_Server-2.0.5/test/Horde/Kolab/Server/Constraints/Searchalias.php0000664000175000017500000000265212653735542025117 0ustar janjangetElements(); foreach ($elements as $element) { if ($this->evaluate($element)) { return true; } } return true; } else { if ($other->getName() == 'alias') { return true; } else { return false; } } } else { return false; } } public function fail($other, $description, \SebastianBergmann\Comparator\ComparisonFailure $comparisonFailure = NULL) { throw new PHPUnit_Framework_ExpectationFailedException( sprintf( '%sFailed asserting that %s contains a query element that is searching by alias', !empty($description) ? $description . "\n" : '', PHPUnit_Util_Type::toString($other, TRUE) ), NULL ); } public function toString() { return 'contains a query element that is searching by alias'; } } Horde_Kolab_Server-2.0.5/test/Horde/Kolab/Server/Constraints/Searchcn.php0000664000175000017500000000263612653735542024430 0ustar janjangetElements(); foreach ($elements as $element) { if ($this->evaluate($element)) { return true; } } return true; } else { if ($other->getName() == 'cn') { return true; } else { return false; } } } else { return false; } } public function fail($other, $description, \SebastianBergmann\Comparator\ComparisonFailure $comparisonFailure = NULL) { throw new PHPUnit_Framework_ExpectationFailedException( sprintf( '%sFailed asserting that %s contains a query element that is searching by cn', !empty($description) ? $description . "\n" : '', PHPUnit_Util_Type::toString($other, TRUE) ), NULL ); } public function toString() { return 'contains a query element that is searching by cn'; } } Horde_Kolab_Server-2.0.5/test/Horde/Kolab/Server/Constraints/Searchmail.php0000664000175000017500000000264612653735542024753 0ustar janjangetElements(); foreach ($elements as $element) { if ($this->evaluate($element)) { return true; } } return true; } else { if ($other->getName() == 'mail') { return true; } else { return false; } } } else { return false; } } public function fail($other, $description, \SebastianBergmann\Comparator\ComparisonFailure $comparisonFailure = NULL) { throw new PHPUnit_Framework_ExpectationFailedException( sprintf( '%sFailed asserting that %s contains a query element that is searching by mail', !empty($description) ? $description . "\n" : '', PHPUnit_Util_Type::toString($other, TRUE) ), NULL ); } public function toString() { return 'contains a query element that is searching by mail'; } } Horde_Kolab_Server-2.0.5/test/Horde/Kolab/Server/Constraints/Searchuid.php0000664000175000017500000000264212653735542024606 0ustar janjangetElements(); foreach ($elements as $element) { if ($this->evaluate($element)) { return true; } } return true; } else { if ($other->getName() == 'uid') { return true; } else { return false; } } } else { return false; } } public function fail($other, $description, \SebastianBergmann\Comparator\ComparisonFailure $comparisonFailure = NULL) { throw new PHPUnit_Framework_ExpectationFailedException( sprintf( '%sFailed asserting that %s contains a query element that is searching by uid', !empty($description) ? $description . "\n" : '', PHPUnit_Util_Type::toString($other, TRUE) ), NULL ); } public function toString() { return 'contains a query element that is searching by uid'; } } Horde_Kolab_Server-2.0.5/test/Horde/Kolab/Server/Integration/AddingObjectsTest.php0000664000175000017500000000264012653735542026211 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * Require our basic test case definition */ require_once __DIR__ . '/Scenario.php'; /** * Adding objects to the server. * * Copyright 2008-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Integration_AddingObjectsTest extends Horde_Kolab_Server_Integration_Scenario { /** * Test adding valid users. * * @param array $user The user to add. * * @scenario * @dataProvider validUsers * * @return NULL */ public function addingValidUser($user) { $this->given('several Kolab servers') ->when('adding a Kolab server object', $user) ->then( 'the result should be an object of type', 'Horde_Kolab_Server_Object_Kolab_User' ); } } Horde_Kolab_Server-2.0.5/test/Horde/Kolab/Server/Integration/AdminTest.php0000664000175000017500000000704312653735542024543 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * Require our basic test case definition */ require_once __DIR__ . '/Scenario.php'; /** * Test the admin object. * * Copyright 2008-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Integration_AdminTest extends Horde_Kolab_Server_Integration_Scenario { /** * Set up testing. * * @return NULL */ protected function setUp() { parent::setUp(); $this->server = $this->getKolabMockServer(); } /** * Add an administrator object. * * @return NULL */ private function _addValidAdmin() { $this->addToServers($this->provideBasicAdmin()); } /** * Test ID generation for an admin. * * @return NULL */ public function testGenerateId() { $admin = $this->provideBasicAdmin(); $user = new Horde_Kolab_Server_Object_Kolab_Administrator($this->server, null, $admin); $this->assertEquals( 'cn=The Administrator,dc=example,dc=org', $user->get(Horde_Kolab_Server_Object::ATTRIBUTE_UID) ); } /** * Test fetching an admin. * * @return NULL */ public function testFetchAdmin() { $this->_addValidAdmin(); $this->assertEquals(2, count($GLOBALS['KOLAB_SERVER_TEST_DATA'])); $this->assertContains( 'cn=admin,cn=internal,dc=example,dc=org', array_keys($GLOBALS['KOLAB_SERVER_TEST_DATA']) ); $administrators = $this->server->getGroups( 'cn=The Administrator,dc=example,dc=org' ); $admin_group = $this->server->fetch( 'cn=admin,cn=internal,dc=example,dc=org' ); $this->assertTrue($admin_group->exists()); $admin = $this->server->fetch('cn=The Administrator,dc=example,dc=org'); $this->assertEquals( 'Horde_Kolab_Server_Object_Kolab_Administrator', get_class($admin) ); } /** * Test listing the admins. * * @return NULL */ public function testToHash() { $this->_addValidAdmin(); $hash = $this->server->fetch( 'cn=The Administrator,dc=example,dc=org' )->toHash(); $this->assertContains('uid', array_keys($hash)); $this->assertContains('lnfn', array_keys($hash)); $this->assertEquals('admin', $hash['uid']); } /** * Test listing admins. * * @return NULL */ public function testListingGroups() { $this->_addValidAdmin(); $entries = $this->server->search( '(&(cn=*)(objectClass=inetOrgPerson)(!(uid=manager))(sn=*))' ); $this->assertEquals(1, count($entries)); $list = $this->server->listObjects( 'Horde_Kolab_Server_Object_Kolab_Administrator' ); $this->assertEquals(1, count($list)); } } Horde_Kolab_Server-2.0.5/test/Horde/Kolab/Server/Integration/DistListHandlingTest.php0000664000175000017500000000253012653735542026713 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * Require our basic test case definition */ require_once __DIR__ . '/Scenario.php'; /** * Handling distribution lists. * * Copyright 2008-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Integration_DistListHandlingTest extends Horde_Kolab_Server_Integration_Scenario { /** * Test adding a distribution list. * * @scenario * * @return NULL */ public function creatingDistributionList() { $this->given('several Kolab servers') ->when('adding a distribution list') ->then( 'the result should be an object of type', 'Horde_Kolab_Server_Object_Kolab_Distlist' ); } } Horde_Kolab_Server-2.0.5/test/Horde/Kolab/Server/Integration/GroupHandlingTestTodo.php0000664000175000017500000004350412653735542027104 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * Require our basic test case definition */ require_once __DIR__ . '/Scenario.php'; /** * Handling groups. * * Copyright 2008-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Integration_GroupHandlingTest extends Horde_Kolab_Server_Integration_Scenario { /** * Test listing groups if there are no groups. * * @scenario * * @return NULL */ public function listingGroupsOnEmptyServer() { $this->given('several Kolab servers') ->when( 'retrieving a hash list with all objects of type', 'Horde_Kolab_Server_Object_Kolabgroupofnames' ) ->then('the list is an empty array'); } /** * Test listing groups after adding some groups. * * @param array $group_list The groups to add. * * @scenario * @dataProvider groupLists * * @return NULL */ public function listingGroups($group_list) { $this->given('several Kolab servers') ->when('adding an object list', $group_list) ->and( 'retrieving a hash list with all objects of type', 'Horde_Kolab_Server_Object_Kolabgroupofnames' ) ->then('the result indicates success.') ->and( 'the list has a number of entries equal to', count($group_list) ); } /** * Test the list of groups for the group id. * * @param array $group_list The groups to add. * * @scenario * @dataProvider groupLists * * @return NULL */ public function listingGroupsHasAttributeId($group_list) { $this->given('several Kolab servers') ->when('adding an object list', $group_list) ->and( 'retrieving a hash list with all objects of type', 'Horde_Kolab_Server_Object_Kolabgroupofnames' ) ->then( 'the provided list and the result list match with regard to these attributes', 'mail', 'cn', $group_list ); } /** * Test the list of groups for the group mail address. * * @param array $group_list The groups to add. * * @scenario * @dataProvider groupLists * * @return NULL */ public function listingGroupsHasAttributeMail($group_list) { $this->given('several Kolab servers') ->when('adding an object list', $group_list) ->and( 'retrieving a hash list with all objects of type', 'Horde_Kolab_Server_Object_Kolabgroupofnames' ) ->then( 'the provided list and the result list match with regard to these attributes', 'mail', 'mail', $group_list ); } /** * Test the list of groups for the group visibility. * * @param array $group_list The groups to add. * * @scenario * @dataProvider groupLists * * @return NULL */ public function listingGroupsHasAttributeVisibility($group_list) { $this->given('several Kolab servers') ->when('adding an object list', $group_list) ->and( 'retrieving a hash list with all objects of type', 'Horde_Kolab_Server_Object_Kolabgroupofnames' ) ->then( 'each element in the result list has an attribute', 'visible' ); } /** * Test adding an invalid group. * * @scenario * * @return NULL */ public function creatingGroupsWithoutMailAddressFails() { $this->given('several Kolab servers') ->when('adding a group without a mail address') ->then( 'the result should indicate an error with', 'Adding object failed: The value for "mail" is missing!' ); } /** * Test adding a group without setting the visibility. * * @scenario * * @return NULL */ public function creatingGroupWithoutVisibilityCreatesVisibleGroup() { $this->given('several Kolab servers') ->when('adding an object', $this->provideGroupWithoutMembers()) ->and( 'retrieving a hash list with all objects of type', 'Horde_Kolab_Server_Object_Kolabgroupofnames' ) ->then( 'each element in the result list has an attribute set to a given value', 'visible', true ); } /** * Test modifying a group mail address. * * @scenario * * @return NULL */ public function modifyingGroupMailAddressIsNotAllowed() { $this->given('several Kolab servers') ->when('adding a group with the mail address "test@example.org"') ->and('modifying the mail address to "new@example.org"') ->then( 'the result should indicate an error with', 'The group cannot be modified: Changing the mail address from "test@example.org" to "new@example.org" is not allowed!' ); } /** * Test modifying a group mail address. * * @scenario * * @return NULL */ public function conflictBetweenGroupMailAndUserMailIsNotAllowed() { $this->given('several Kolab servers') ->when('adding a group with the mail address "test@example.org"') ->and('adding a user "Test Test" with the mail address "test@example.org"') ->then( 'the result should indicate an error with', 'The user cannot be added: Mail address "test@example.org" is already the mail address for the group "test@example.org"!' ); } /** * * @scenario * * @return NULL */ public function conflictBetweenUserMailAndGroupMailIsNotAllowed() { $this->given('several Kolab servers') ->when('adding a user "Test Test" with the mail address "test@example.org"') ->and('adding a group with the mail address "test@example.org"') ->then( 'the result should indicate an error with', 'The group cannot be added: Mail address "test@example.org" is already the mail address of the user "Test Test"!' ); } /** * @scenario */ public function conflictBetweenGroupMailAndUserAliasIsNotAllowed() { $this->given('several Kolab servers') ->when('adding a group with the mail address "test@example.org"') ->and('adding a user with the alias address "test@example.org"') ->then( 'the result should indicate an error with', 'The user cannot be added: Alias address "test@example.org" is already the mail address of the group "test@example.org"!' ); } /** * @scenario */ public function conflictBetweenUserAliasAndGroupMailIsNotAllowed() { $this->given('several Kolab servers') ->when('adding a user "Test Test" with the alias address "test@example.org"') ->and('adding a group with the mail address "test@example.org"') ->then( 'the result should indicate an error with', 'The group cannot be added: Mail address "test@example.org" is already the alias address of the user "Test Test"!' ); } /** * kolab/issue890 (Assigning multiple Distribution Lists to user during creation and modification) * * @scenario */ public function showGroupsWhenFetchingTheUser() { $this->given('several Kolab servers') ->when('adding a user "cn=Test Test" with the mail address "test@example.org"') ->and('adding a group with the mail address "testgroup@example.org" and the member "cn=Test Test"') ->and('fetching the user "test@example.org"') ->and('listing the groups of this user') ->then('the list should contain "testgroup@example.org"'); } /** * @scenario */ public function allowAddingUserToGroup() { $this->given('several Kolab servers') ->when('adding a group with the mail address "testgroup@example.org"') ->and('adding a user "cn=Test Test" with the mail address "test@example.org"') ->and('modifying group with the mail address "testgroup@example.org" to contain the member "cn=Test Test".') ->and('fetching the groups "group@example.org"') ->and('listing the members of this group') ->then('the list should contain "test@example.org"'); } /** * @scenario */ public function allowAddingUserToGroupWhenCreatingUser() { $this->given('several Kolab servers') ->when('adding a group with the mail address "testgroup@example.org"') ->and('adding a user "cn=Test Test" with the mail address "test@example.org" and member of "testgroup@example.org"') ->and('fetching the groups "group@example.org"') ->and('listing the members of this group') ->then('the list should contain "test@example.org"'); } /** * @scenario */ public function allowRemovingUserFromGroup() { $this->given('several Kolab servers') ->when('adding a user "cn=Test Test" with the mail address "test@example.org"') ->and('adding a group with the mail address "testgroup@example.org" and the member "cn=Test Test"') ->and('modifying group with the mail address "testgroup@example.org" to contain no members.') ->and('fetching the groups "group@example.org"') ->and('listing the members of this group') ->then('the list is empty'); } /** * @scenario */ public function deletingUserRemovesUserFromAllDistributionLists() { $this->given('several Kolab servers') ->when('adding a user "cn=Test Test" with the mail address "test@example.org"') ->and('adding a group with the mail address "testgroup@example.org" and the member "cn=Test Test"') ->and('adding a group with the mail address "testgroup2@example.org" and the member "cn=Test Test"') ->and('deleting user "cn=Test Test"') ->and('listing the members of group "testgroup@example.org"') ->and('listing the members of group "testgroup2@example.org"') ->then('the list of group "testgroup@example.org" is empty') ->and('the list of group "testgroup2@example.org" is empty'); } /** * @scenario */ public function modifyingUserIDDoesNotChangeGroupMembership() { $this->given('several Kolab servers') ->when('adding a user "cn=Test Test" with the mail address "test@example.org"') ->and('adding a group with the mail address "testgroup@example.org" and the member "cn=Test Test"') ->and('modifying user "cn=Test Test" to ID "cn=Test2 Test"') ->and('listing the members of group "testgroup@example.org"') ->then('the list of group "testgroup@example.org" contains "cn=Test2 Test"'); } /** * @scenario */ public function addingGroupInUndefinedDomainIsNotAllowed() { $this->given('several Kolab servers') ->and('the only served mail domain is "example.org"') ->when('adding a group with the mail address "test@doesnotexist.org"') ->then( 'the result should indicate an error with', 'The group cannot be added: Domain "doesnotexist.org" is not being handled by this server!' ); } /** * kolab/issue1368 (Webinterface allows to create email addresses with slash that cyrus cannot handle) * * @scenario * @dataProvider invalidMails */ public function disallowInvalidMailAddresses($address) { $this->given('several Kolab servers') ->when('adding a group with an invalid mail address', $address) ->then( 'the result should indicate an error with', "The group cannot be added: Address \"$address\" is not a valid mail address!" ); } /** * @scenario */ public function objectAttributeDescriptionsCanBeRetrieved() { $this->given('several Kolab servers') ->when('retrieving the supported attributes by the object type "group"') ->then('the result is an array of Horde attribute descriptions') ->and('contains the description of "members"'); } /** * @scenario */ public function removingGroupFailsIfGroupDoesNotExist() { $this->given('several Kolab servers') ->when('adding a group with the mail address "group@example.org"') ->and('deleting the group with the mail address "group@example.org"') ->then( 'the result should indicate an error with', 'The group cannot be deleted: Group "group@example.org" does not exist!' ); } /** * @scenario */ public function removingGroupByMailSucceeds() { $this->given('several Kolab servers') ->when('adding a group with the mail address "test@example.org"') ->and('deleting the group with mail address "test@example.org"') ->then('the result indicates success') ->and('listing all groups returns an empty list'); } /** * kolab/issue1189 (IMAP login fails on some specific uids) * * @scenario */ public function userUidsShouldNotResembleTheLocalPartOfMailAddresses() { $this->given('several Kolab servers') ->when('adding a group with the mail address "test@example.org"') ->and('adding a user with the uid "test"') ->then( 'the result should indicate an error with', 'The user cannot be added: The uid "test" matches the local part of the mail address "test@example.org" assigned to group "test@example.org"!' ); } /** * kolab/issue2207 (Make it possible to enable and disable users to be able to use the webclient.) * * @scenario */ public function addedUserCanLoginIfInAllowedGroup() { $this->given('several Kolab servers') ->and('Horde uses the Kolab auth driver') ->and('only members of group "testgroup@example.org" are allowed') ->when('adding a user "cn=Test Test" with the mail address "test@example.org" and password "test"') ->and('adding a group with the mail address "testgroup@example.org" and the member "cn=Test Test"') ->and('trying to login to Horde with "test@example.org" and passowrd "test"') ->then('the result indicates success') ->and('the session shows "test@example.org" as the current user'); } /** * kolab/issue2207 (Make it possible to enable and disable users to be able to use the webclient.) * * @scenario */ public function addedUserCannotLoginIfInNotInAllowedGroup() { $this->given('several Kolab servers') ->and('Horde uses the Kolab auth driver') ->and('only members of group "testgroup@example.org" are allowed') ->when('adding a user "cn=Test Test" with the mail address "test@example.org" and password "test"') ->and('adding a group with the mail address "testgroup@example.org" and no members') ->and('trying to login to Horde with "test@example.org" and passowrd "test"') ->then('the user may not login'); } /** * kolab/issue2207 (Make it possible to enable and disable users to be able to use the webclient.) * * @scenario */ public function addedUserCanLoginIfInNotInDisallowedGroup() { $this->given('several Kolab servers') ->and('Horde uses the Kolab auth driver') ->and('members of group "testgroup@example.org" may not login') ->when('adding a user "cn=Test Test" with the mail address "test@example.org" and password "test"') ->and('adding a group with the mail address "testgroup@example.org" and no members') ->and('trying to login to Horde with "test@example.org" and passowrd "test"') ->then('the result indicates success') ->and('the session shows "test@example.org" as the current user'); } /** * kolab/issue2207 (Make it possible to enable and disable users to be able to use the webclient.) * * @scenario */ public function addedUserCannotLoginIfInDisallowedGroup() { $this->given('several Kolab servers') ->and('Horde uses the Kolab auth driver') ->and('members of group "testgroup@example.org" may not login') ->when('adding a user "cn=Test Test" with the mail address "test@example.org" and password "test"') ->and('adding a group with the mail address "testgroup@example.org" and the member "cn=Test Test"') ->and('trying to login to Horde with "test@example.org" and passowrd "test"') ->then('the user may not login'); } } Horde_Kolab_Server-2.0.5/test/Horde/Kolab/Server/Integration/GroupTest.php0000664000175000017500000000766312653735542024617 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * Require our basic test case definition */ require_once __DIR__ . '/Scenario.php'; /** * Test the group object. * * Copyright 2008-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Integration_GroupTest extends Horde_Kolab_Server_Integration_Scenario { /** * Set up testing. * * @return NULL */ protected function setUp() { parent::setUp(); $this->ldap = $this->getKolabMockServer(); } /** * Add a group object. * * @return NULL */ private function _addValidGroups() { $groups = $this->validGroups(); foreach ($groups as $group) { $result = $this->ldap->add($group[0]); $this->assertNoError($result); } } /** * Test ID generation for a group. * * @return NULL */ public function testGenerateId() { $groups = $this->validGroups(); $user = new Horde_Kolab_Server_Object_Kolabgroupofnames($this->ldap, null, $groups[0][0]); $this->assertNoError($user); $this->assertEquals( 'cn=empty.group@example.org,dc=example,dc=org', $user->get(Horde_Kolab_Server_Object::ATTRIBUTE_UID) ); } /** * Test fetching a group. * * @return NULL */ public function testFetchGroup() { $this->_addValidGroups(); $group = $this->ldap->fetch('cn=empty.group@example.org,dc=example,dc=org'); $this->assertNoError($group); $this->assertEquals( 'Horde_Kolab_Server_Object_Kolabgroupofnames', get_class($group) ); } /** * Test fetching a group. * * @return NULL */ public function testToHash() { $this->_addValidGroups(); $group = $this->ldap->fetch('cn=empty.group@example.org,dc=example,dc=org'); $this->assertNoError($group); $hash = $group->toHash(); $this->assertNoError($hash); $this->assertContains('mail', array_keys($hash)); $this->assertContains('id', array_keys($hash)); $this->assertContains('visible', array_keys($hash)); $this->assertEquals('empty.group@example.org', $hash['mail']); $this->assertEquals('cn=empty.group@example.org', $hash['id']); $this->assertTrue($hash['visible']); } /** * Test listing groups. * * @return NULL */ public function testListingGroups() { $result = $this->ldap->search( '(&(!(cn=domains))(objectClass=kolabGroupOfNames))', array(), $this->ldap->getBaseUid() ); $this->assertEquals(0, count($result)); $this->_addValidGroups(); $this->assertEquals(3, count($GLOBALS['KOLAB_SERVER_TEST_DATA'])); $result = $this->ldap->search( '(&(!(cn=domains))(objectClass=kolabGroupOfNames))', array(), $this->ldap->getBaseUid() ); $this->assertEquals(3, count($result)); $list = $this->ldap->listObjects( 'Horde_Kolab_Server_Object_Kolabgroupofnames' ); $this->assertNoError($list); $this->assertEquals(3, count($list)); } } Horde_Kolab_Server-2.0.5/test/Horde/Kolab/Server/Integration/InetorgpersonTest.php0000664000175000017500000002511612653735542026352 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * Require our basic test case definition */ require_once __DIR__ . '/Scenario.php'; /** * Test the inetOrgPerson object. * * Copyright 2009-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Integration_InetorgpersonTest extends Horde_Kolab_Server_Integration_Scenario { /** * Objects used within this test * * @var array */ private $objects = array( /* Default inetOrgPerson */ array( 'type' => 'Horde_Kolab_Server_Object_Inetorgperson', 'givenName' => 'Frank', 'Sn' => 'Mustermann', 'Userpassword' => 'Kolab_Server_OrgPersonTest_123', ), /* Invalid person (no sn) */ array( 'type' => 'Horde_Kolab_Server_Object_Inetorgperson', 'Cn' => 'Kolab_Server_OrgPersonTest_123', 'Userpassword' => 'Kolab_Server_OrgPersonTest_123', ), /* Person with middle names */ array( 'type' => 'Horde_Kolab_Server_Object_Inetorgperson', 'givenName' => 'Frank', 'Middlenames' => 'Günter Eloic', 'Sn' => 'Mustermann', 'Userpassword' => 'Kolab_Server_OrgPersonTest_123', ), ); /** * Set up testing. * * @return NULL */ protected function setUp() { parent::setUp(); $this->initializeEnvironments(); $this->servers = $this->getKolabServers(); } /** * Test ID generation for a person. * * @return NULL */ public function testGenerateId() { foreach ($this->servers as $server) { $a = new Horde_Kolab_Server_Object_Inetorgperson($server, null, $this->objects[0]); $this->assertContains('Frank Mustermann', $a->get(Horde_Kolab_Server_Object_Person::ATTRIBUTE_UID)); } } /** * Test adding an invalid person. * * @expectedException Horde_Kolab_Server_Exception * * @return NULL */ public function testAddInvalidPerson() { $this->addToServers($this->objects[1]); } /** * Test a person with middle names. * * @return NULL */ public function testHandlePersonWithMiddleNames() { foreach ($this->servers as $server) { $person = $this->assertAdd($server, $this->objects[2], array('givenName' => $this->objects[2]['givenName'], 'Middlenames' => $this->objects[2]['Middlenames'])); $this->assertStoreFetch($person, $server, array('givenName' => 'Kolab_Server_InetorgpersonTest_123$123', 'Middlenames' => 'Kolab_Server_InetorgpersonTest_123$123'), array('givenName' => 'Kolab_Server_InetorgpersonTest_123$123', 'Middlenames' => 'Kolab_Server_InetorgpersonTest_123$123')); $this->assertStoreFetch($person, $server, array('givenName' => 'Kolab_Server_InetorgpersonTest_123$456', 'Middlenames' => ''), array('givenName' => 'Kolab_Server_InetorgpersonTest_123$456', 'Middlenames' => '')); $this->assertStoreFetch($person, $server, array('Middlenames' => 'Kolab_Server_InetorgpersonTest_789'), array('givenName' => 'Kolab_Server_InetorgpersonTest_123$456', 'Middlenames' => 'Kolab_Server_InetorgpersonTest_789')); $this->assertStoreFetch($person, $server, array('givenName' => '', 'Middlenames' => ''), array('givenName' => '', 'Middlenames' => '')); $this->assertStoreFetch($person, $server, array('Middlenames' => 'Kolab_Server_InetorgpersonTest_789'), array('givenName' => '', 'Middlenames' => 'Kolab_Server_InetorgpersonTest_789')); $this->assertStoreFetch($person, $server, array('givenName' => 'Frank', 'Middlenames' => ''), array('givenName' => 'Frank', 'Middlenames' => '')); } } /** * Test handling labeled URIs. * * @return NULL */ public function testHandleLabeledUris() { foreach ($this->servers as $server) { $person = $this->assertAdd($server, $this->objects[0], array('givenName' => $this->objects[0]['givenName'], 'labelledURI' => array())); $this->assertStoreFetch($person, $server, array('labelledURI' => array('a' => 'http://a.example.com', 'b' => 'http://b.example.com')), array('labelledURI' => array('a' => array('http://a.example.com'), 'b' => array('http://b.example.com')))); $this->assertStoreFetch($person, $server, array('labelledURI' => array('a' => 'http://a.example.com', 'b' => 'http://b.example.com', 'c' => 'http://c.example.com')), array('labelledURI' => array('a' => array('http://a.example.com'), 'b' => array('http://b.example.com'), 'c' => array('http://c.example.com')))); $this->assertStoreFetch($person, $server, array('labelledURI' => array()), array('labelledURI' => array())); $this->assertStoreFetch($person, $server, array('labelledURI' => array('a' => 'http://a.example.com')), array('labelledURI' => array('a' => array('http://a.example.com')))); } } /** * Test handling the home postal address. * * @return NULL */ public function testHandlingHomePostalAddress() { //@todo } /** * Test handling easy attributes. * * @return NULL */ public function testEasyAttributes() { foreach ($this->servers as $server) { $person = $this->assertAdd($server, $this->objects[0], array(Horde_Kolab_Server_Object_Inetorgperson::ATTRIBUTE_SID => '')); $this->assertEasyAttributes($person, $server, array( Horde_Kolab_Server_Object_Inetorgperson::ATTRIBUTE_SID => array( 'user', '0', 'somebody', null, '', array('he', 'she'), ), Horde_Kolab_Server_Object_Inetorgperson::ATTRIBUTE_ORGANIZATION => array( 'them', '0', 'somebody', null, '', array('they', 'we'), ), Horde_Kolab_Server_Object_Inetorgperson::ATTRIBUTE_BUSINESSCATEGORY => array( 'them', '0', 'somebody', null, '', array('they', 'we'), ), Horde_Kolab_Server_Object_Inetorgperson::ATTRIBUTE_HOMEPHONE => array( '123456789', '+1234567890', array('1', '2'), null, '0' ), Horde_Kolab_Server_Object_Inetorgperson::ATTRIBUTE_MOBILE => array( '123456789', '+1234567890', array('1', '2'), null, '0' ), ) ); } } } Horde_Kolab_Server-2.0.5/test/Horde/Kolab/Server/Integration/KolabgermanbankarrangementTest.php0000664000175000017500000001571212653735542031017 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * Require our basic test case definition */ require_once __DIR__ . '/Scenario.php'; /** * Test the kolabGermanBankArrangement object. * * Copyright 2009-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Integration_KolabgermanbankarrangementTest extends Horde_Kolab_Server_Integration_Scenario { /** * Objects used within this test * * @var array */ private $objects = array( /* Default bank account owner */ array( 'type' => 'Horde_Kolab_Server_Object_Kolabinetorgperson', 'givenName' => 'Frank', 'Sn' => 'Mustermann', 'Userpassword' => 'Kolab_Server_OrgPersonTest_123', ), /* Default account */ array( 'type' => 'Horde_Kolab_Server_Object_Kolabgermanbankarrangement', Horde_Kolab_Server_Object_Kolabgermanbankarrangement::ATTRIBUTE_NUMBER => '0123456789', Horde_Kolab_Server_Object_Kolabgermanbankarrangement::ATTRIBUTE_BANKCODE => '1111111', ), ); /** * Set up testing. * * @return NULL */ protected function setUp() { parent::setUp(); $this->initializeEnvironments(); $this->servers = $this->getKolabServers(); } /** * Test ID generation for a person. * * @return NULL */ public function testGenerateId() { foreach ($this->servers as $server) { $person = $this->assertAdd($server, $this->objects[0], array(Horde_Kolab_Server_Object_Kolabinetorgperson::ATTRIBUTE_SID => '')); $account_data = $this->objects[1]; $account_data[Horde_Kolab_Server_Object_Kolabgermanbankarrangement::ATTRIBUTE_OWNERUID] = $person->getUid(); $a = new Horde_Kolab_Server_Object_Kolabgermanbankarrangement($server, null, $account_data); $this->assertContains(Horde_Kolab_Server_Object_Kolabgermanbankarrangement::ATTRIBUTE_NUMBER . '=' . $this->objects[1][Horde_Kolab_Server_Object_Kolabgermanbankarrangement::ATTRIBUTE_NUMBER], $a->get(Horde_Kolab_Server_Object_Kolabgermanbankarrangement::ATTRIBUTE_UID)); } } /** * Test adding an invalid Account. * * @expectedException Horde_Kolab_Server_Exception * * @return NULL */ public function testAddInvalidAccount() { $this->addToServers($this->objects[1]); } /** * Test handling easy attributes. * * @return NULL */ public function testEasyAttributes() { foreach ($this->servers as $server) { $person = $this->assertAdd($server, $this->objects[0], array(Horde_Kolab_Server_Object_Kolabinetorgperson::ATTRIBUTE_SID => '')); $account_data = $this->objects[1]; $account_data[Horde_Kolab_Server_Object_Kolabgermanbankarrangement::ATTRIBUTE_OWNERUID] = $person->getUid(); $account = $this->assertAdd($server, $account_data, array(Horde_Kolab_Server_Object_Kolabgermanbankarrangement::ATTRIBUTE_OWNERUID => $person->getUid())); $this->assertEasyAttributes($account, $server, array( Horde_Kolab_Server_Object_Kolabgermanbankarrangement::ATTRIBUTE_HOLDER => array( 'something', 'somewhere', null, array('a', 'b'), '', ), Horde_Kolab_Server_Object_Kolabgermanbankarrangement::ATTRIBUTE_BANKNAME => array( 'something', 'somewhere', null, array('a', 'b'), '', ), Horde_Kolab_Server_Object_Kolabgermanbankarrangement::ATTRIBUTE_INFO => array( 'something', 'somewhere', null, array('a', 'b'), '', ), ) ); } } /** * Test modifying the account number of an account. This should have an * effect on the UID of the object and needs to rename the object. * * @return NULL */ public function testModifyAccountNumber() { foreach ($this->servers as $server) { $person = $this->assertAdd($server, $this->objects[0], array(Horde_Kolab_Server_Object_Kolabinetorgperson::ATTRIBUTE_SID => '')); $account_data = $this->objects[1]; $account_data[Horde_Kolab_Server_Object_Kolabgermanbankarrangement::ATTRIBUTE_OWNERUID] = $person->getUid(); $account = $server->add($account_data); $this->assertNoError($account); $account = $server->fetch($account->getUid()); $this->assertNoError($account); $this->assertEquals($this->objects[1][Horde_Kolab_Server_Object_Kolabgermanbankarrangement::ATTRIBUTE_NUMBER], $account->get(Horde_Kolab_Server_Object_Kolabgermanbankarrangement::ATTRIBUTE_NUMBER)); $result = $account->save(array(Horde_Kolab_Server_Object_Kolabgermanbankarrangement::ATTRIBUTE_NUMBER => '66666666')); $this->assertNoError($result); $account = $server->fetch($account->getUid()); $this->assertNoError($account); $this->assertEquals($account->get(Horde_Kolab_Server_Object_Kolabgermanbankarrangement::ATTRIBUTE_NUMBER), '66666666'); $result = $server->delete($account->getUid()); $this->assertNoError($result); } } } Horde_Kolab_Server-2.0.5/test/Horde/Kolab/Server/Integration/KolabinetorgpersonTest.php0000664000175000017500000004161612653735542027366 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * Require our basic test case definition */ require_once __DIR__ . '/Scenario.php'; /** * Test the kolabInetOrgPerson object. * * Copyright 2009-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Integration_KolabinetorgpersonTest extends Horde_Kolab_Server_Integration_Scenario { /** * Objects used within this test * * @var array */ private $objects = array( /* Default kolabInetOrgPerson */ array( 'type' => 'Horde_Kolab_Server_Object_Kolabinetorgperson', 'givenName' => 'Frank', 'Sn' => 'Mustermann', 'Userpassword' => 'Kolab_Server_OrgPersonTest_123', ), /* Invalid person (no sn) */ array( 'type' => 'Horde_Kolab_Server_Object_Kolabinetorgperson', 'Cn' => 'Kolab_Server_OrgPersonTest_123', 'Userpassword' => 'Kolab_Server_OrgPersonTest_123', ), ); /** * Set up testing. * * @return NULL */ protected function setUp() { parent::setUp(); $this->initializeEnvironments(); $this->servers = $this->getKolabServers(); } /** * Test ID generation for a person. * * @return NULL */ public function testGenerateId() { foreach ($this->servers as $server) { $a = new Horde_Kolab_Server_Object_Kolabinetorgperson($server, null, $this->objects[0]); $this->assertContains('Frank Mustermann', $a->get(Horde_Kolab_Server_Object_Person::ATTRIBUTE_UID)); } } /** * Test adding an invalid person. * * @expectedException Horde_Kolab_Server_Exception * * @return NULL */ public function testAddInvalidPerson() { $this->addToServers($this->objects[1]); } /** * Test handling easy attributes. * * @return NULL */ public function testEasyAttributes() { foreach ($this->servers as $server) { $person = $this->assertAdd($server, $this->objects[0], array(Horde_Kolab_Server_Object_Kolabinetorgperson::ATTRIBUTE_SID => '')); $this->assertEasyAttributes($person, $server, array( Horde_Kolab_Server_Object_Kolabinetorgperson::ATTRIBUTE_GERMANTAXID => array( '01234567890123456789', '0', '101', null, 'DE', array('101', '202'), ), Horde_Kolab_Server_Object_Kolabinetorgperson::ATTRIBUTE_HOMESERVER => array( 'a.b.c', '', 'jodeldodel', null, array('a.example.com', 'b.example.com'), ), Horde_Kolab_Server_Object_Kolabinetorgperson::ATTRIBUTE_QUOTA => array( '100', null, array('0', '1000'), ), Horde_Kolab_Server_Object_Kolabinetorgperson::ATTRIBUTE_ALLOWEDRECIPIENTS => array( '-a@example.com', '', array('a', 'b'), null, '0' ), Horde_Kolab_Server_Object_Kolabinetorgperson::ATTRIBUTE_ALLOWEDFROM => array( '-a@example.com', '', array('a', 'b'), null, '0' ), Horde_Kolab_Server_Object_Kolabinetorgperson::ATTRIBUTE_SALUTATION => array( 'Herr', 'Mrs.', null, array('Herr', 'Mrs.'), '0' ), Horde_Kolab_Server_Object_Kolabinetorgperson::ATTRIBUTE_GENDER => array( '1', null, '0', '2', ), Horde_Kolab_Server_Object_Kolabinetorgperson::ATTRIBUTE_BIRTHNAME => array( 'Adam', null, '', '0', ), Horde_Kolab_Server_Object_Kolabinetorgperson::ATTRIBUTE_PLACEOFBIRTH => array( 'Jotwede', null, '', ), Horde_Kolab_Server_Object_Kolabinetorgperson::ATTRIBUTE_COUNTRY => array( 'DE', 'SE', null, 'DE', ), Horde_Kolab_Server_Object_Kolabinetorgperson::ATTRIBUTE_COUNTRYCITIZENSHIP => array( 'DE', 'SE', //@todo: "null" does not work. Why? //null, 'DE', ), Horde_Kolab_Server_Object_Kolabinetorgperson::ATTRIBUTE_LEGALFORM => array( 'GmbH', 'Freelancer', null, 'Freelancer', ), // @todo: Undefined in object class /* Horde_Kolab_Server_Object_Kolabinetorgperson::ATTRIBUTE_REGISTEREDCAPITAL => array( */ /* '1212121211', */ /* '0', */ /* null, */ /* '' */ /* ), */ // @todo: Undefined in object class /* Horde_Kolab_Server_Object_Kolabinetorgperson::ATTRIBUTE_BYLAWURI => array( */ /* 'something', */ /* 'somewhere', */ /* null, */ /* array('a', 'b'), */ /* '', */ /* ), */ //@todo: Alias support /* Horde_Kolab_Server_Object_Kolabinetorgperson::ATTRIBUTE_DATEOFINCORPORATION => array( */ /* '199911220707Z', */ /* ), */ // @todo: Undefined in object class /* Horde_Kolab_Server_Object_Kolabinetorgperson::ATTRIBUTE_LEGALREPRESENTATIONPOLICY => array( */ /* 'something', */ /* 'somewhere', */ /* null, */ /* array('a', 'b'), */ /* '', */ /* ), */ Horde_Kolab_Server_Object_Kolabinetorgperson::ATTRIBUTE_VATNUMBER => array( 'something', 'somewhere', null, array('a', 'b'), ), //@todo: Undefined /* Horde_Kolab_Server_Object_Kolabinetorgperson::ATTRIBUTE_OTHERLEGAL => array( */ /* 'something', */ /* 'somewhere', */ /* null, */ /* array('a', 'b'), */ /* ), */ // @todo: Undefined in object class /* Horde_Kolab_Server_Object_Kolabinetorgperson::ATTRIBUTE_INLIQUIDATION => array( */ /* 'TRUE', */ /* 'FALSE', */ /* null, */ /* array('TRUE', 'FALSE'), */ /* ), */ // @todo: Undefined in object class /* Horde_Kolab_Server_Object_Kolabinetorgperson::ATTRIBUTE_TRTYPE => array( */ /* 'something', */ /* 'somewhere', */ /* null, */ /* array('a', 'b'), */ /* ), */ Horde_Kolab_Server_Object_Kolabinetorgperson::ATTRIBUTE_TRLOCATION => array( 'something', 'somewhere', null, 'somewhere', ), Horde_Kolab_Server_Object_Kolabinetorgperson::ATTRIBUTE_TRIDENTIFIER => array( 'something', 'somewhere', null, 'somewhere', ), // @todo: Undefined in object class /* Horde_Kolab_Server_Object_Kolabinetorgperson::ATTRIBUTE_TRURI => array( */ /* 'something', */ /* 'somewhere', */ /* null, */ /* array('a', 'b'), */ /* ), */ // @todo: Undefined in object class /* Horde_Kolab_Server_Object_Kolabinetorgperson::ATTRIBUTE_TRLASTCHANGED => array( */ /* 'something', */ /* 'somewhere', */ /* null, */ /* array('a', 'b'), */ /* ), */ // @todo: Undefined in object class /* Horde_Kolab_Server_Object_Kolabinetorgperson::ATTRIBUTE_DC => array( */ /* 'something', */ /* 'somewhere', */ /* null, */ /* array('a', 'b'), */ /* ), */ Horde_Kolab_Server_Object_Kolabinetorgperson::ATTRIBUTE_ALIAS => array( 'something', 'somewhere', null, array('a', 'b'), ), ) ); } } } Horde_Kolab_Server-2.0.5/test/Horde/Kolab/Server/Integration/Kolabpop3accountTest.php0000664000175000017500000002147512653735542026727 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * Require our basic test case definition */ require_once __DIR__ . '/Scenario.php'; /** * Test the kolabExternalPop3Account object. * * Copyright 2009-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Integration_Kolabpop3accountTest extends Horde_Kolab_Server_Integration_Scenario { /** * Objects used within this test * * @var array */ private $objects = array( /* Default bank account owner */ array( 'type' => 'Horde_Kolab_Server_Object_Kolabinetorgperson', 'givenName' => 'Frank', 'Sn' => 'Mustermann', 'Userpassword' => 'Kolab_Server_OrgPersonTest_123', ), /* Default account */ array( 'type' => 'Horde_Kolab_Server_Object_Kolabpop3account', Horde_Kolab_Server_Object_Kolabpop3account::ATTRIBUTE_MAIL => 'frank@example.com', Horde_Kolab_Server_Object_Kolabpop3account::ATTRIBUTE_SERVER => 'pop.example.com', Horde_Kolab_Server_Object_Kolabpop3account::ATTRIBUTE_LOGINNAME => 'frank', Horde_Kolab_Server_Object_Kolabpop3account::ATTRIBUTE_PASSWORD => 'test', ), ); /** * Set up testing. * * @return NULL */ protected function setUp() { parent::setUp(); $this->initializeEnvironments(); $this->servers = $this->getKolabServers(); } /** * Test ID generation for a person. * * @return NULL */ public function testGenerateId() { foreach ($this->servers as $server) { $person = $this->assertAdd($server, $this->objects[0], array(Horde_Kolab_Server_Object_Kolabinetorgperson::ATTRIBUTE_SID => '')); $account_data = $this->objects[1]; $account_data[Horde_Kolab_Server_Object_Kolabpop3account::ATTRIBUTE_OWNERUID] = $person->getUid(); $a = new Horde_Kolab_Server_Object_Kolabpop3account($server, null, $account_data); $this->assertContains(Horde_Kolab_Server_Object_Kolabpop3account::ATTRIBUTE_MAIL . '=' . $this->objects[1][Horde_Kolab_Server_Object_Kolabpop3account::ATTRIBUTE_MAIL], $a->get(Horde_Kolab_Server_Object_Kolabpop3account::ATTRIBUTE_UID)); } } /** * Test adding an invalid Account. * * @expectedException Horde_Kolab_Server_Exception * * @return NULL */ public function testAddInvalidAccount() { $this->addToServers($this->objects[1]); } /** * Test handling easy attributes. * * @return NULL */ public function testEasyAttributes() { foreach ($this->servers as $server) { $person = $this->assertAdd($server, $this->objects[0], array(Horde_Kolab_Server_Object_Kolabinetorgperson::ATTRIBUTE_SID => '')); $account_data = $this->objects[1]; $account_data[Horde_Kolab_Server_Object_Kolabpop3account::ATTRIBUTE_OWNERUID] = $person->getUid(); $account = $this->assertAdd($server, $account_data, array(Horde_Kolab_Server_Object_Kolabpop3account::ATTRIBUTE_OWNERUID => $person->getUid())); $this->assertEasyAttributes($account, $server, array( Horde_Kolab_Server_Object_Kolabpop3account::ATTRIBUTE_PASSWORD => array( 'something', 'somewhere', ), Horde_Kolab_Server_Object_Kolabpop3account::ATTRIBUTE_DESCRIPTION => array( 'something', 'somewhere', null, '', ), Horde_Kolab_Server_Object_Kolabpop3account::ATTRIBUTE_SERVER => array( 'something', 'somewhere', array('a', 'b'), ), Horde_Kolab_Server_Object_Kolabpop3account::ATTRIBUTE_PORT => array( '110', '111', null, '', ), Horde_Kolab_Server_Object_Kolabpop3account::ATTRIBUTE_USESSL => array( 'TRUE', 'FALSE', null, '', ), Horde_Kolab_Server_Object_Kolabpop3account::ATTRIBUTE_USETLS => array( 'TRUE', 'FALSE', null, '', ), Horde_Kolab_Server_Object_Kolabpop3account::ATTRIBUTE_LOGINMETHOD => array( 'something', 'somewhere', null, array('a', 'b'), '', ), Horde_Kolab_Server_Object_Kolabpop3account::ATTRIBUTE_CHECKCERTIFICATE => array( 'TRUE', 'FALSE', null, '', ), Horde_Kolab_Server_Object_Kolabpop3account::ATTRIBUTE_KEEPMAILONSERVER => array( 'TRUE', 'FALSE', null, '', ), ) ); } } /** * Test modifying the attributes required for the UID of the account. This * should lead to renaming object. * * @return NULL */ public function testModifyUidElements() { foreach ($this->servers as $server) { $person = $this->assertAdd($server, $this->objects[0], array(Horde_Kolab_Server_Object_Kolabinetorgperson::ATTRIBUTE_SID => '')); $account_data = $this->objects[1]; $account_data[Horde_Kolab_Server_Object_Kolabpop3account::ATTRIBUTE_OWNERUID] = $person->getUid(); $account = $server->add($account_data); $account = $server->fetch($account->getUid()); $this->assertEquals($this->objects[1][Horde_Kolab_Server_Object_Kolabpop3account::ATTRIBUTE_SERVER], $account->get(Horde_Kolab_Server_Object_Kolabpop3account::ATTRIBUTE_SERVER)); $result = $account->save(array(Horde_Kolab_Server_Object_Kolabpop3account::ATTRIBUTE_SERVER => 'pop3s.example.com')); $account = $server->fetch($account->getUid()); $this->assertContains( 'pop3s.example.com', $account->get(Horde_Kolab_Server_Object_Kolabpop3account::ATTRIBUTE_SERVER, false) ); $this->assertContains('frank@example.com', $account->getUid()); $result = $server->delete($account->getUid()); } } } Horde_Kolab_Server-2.0.5/test/Horde/Kolab/Server/Integration/MockTest.php0000664000175000017500000003513512653735542024407 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * Require our basic test case definition */ require_once __DIR__ . '/Scenario.php'; /** * Test the test backend. * * Copyright 2008-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Integration_MockTest extends Horde_Kolab_Server_Integration_Scenario { /** The file based mock environment */ const ENVIRONMENT_FILE = 'file'; /** * The environments we provide to the test. * * @var array */ protected $_environments = array( self::ENVIRONMENT_MOCK, self::ENVIRONMENT_FILE ); /** * Prepare the server configuration for the given environment. * * @param string $environment The name of the environment. * * @return NULL */ public function prepareKolabServerConfiguration($environment) { switch ($environment) { case self::ENVIRONMENT_FILE: /** Prepare a Kolab test server */ $config = new stdClass; $config->driver = 'file'; $config->params = array( 'file' => Horde::getTempFile('fileTest'), 'basedn' => 'dc=example,dc=org', 'hashtype' => 'plain' ); $this->world['injector'][$environment]->setInstance('Horde_Kolab_Server_Config', $config); break; default: return parent::prepareKolabServerConfiguration($environment); } } /** * Set up testing. * * @return NULL */ public function setUp() { parent::setUp(); if (!extension_loaded('ldap') && !@dl('ldap.' . PHP_SHLIB_SUFFIX)) { $this->markTestSuiteSkipped('Ldap extension is missing!'); }; if (!class_exists('Horde_Ldap')) { $this->markTestSuiteSkipped('PEAR package Horde_Ldap is not installed!'); } $this->markTestIncomplete('Needs to be fixed'); $this->initializeEnvironments(); $this->servers = $this->getKolabServers(); foreach ($this->servers as $server) { $this->addBasicUsersToServer($server); } } /** * Test search base. * * @return NULL */ public function testSearchBase() { foreach ($this->servers as $server) { $result = $server->search( '(' . Horde_Kolab_Server_Object::ATTRIBUTE_OC . '=' . Horde_Kolab_Server_Object::OBJECTCLASS_TOP . ')', array(Horde_Kolab_Server_Object::ATTRIBUTE_OC)); $this->assertEquals(13, count($result)); $result = $server->search( '(' . Horde_Kolab_Server_Object::ATTRIBUTE_OC . '=' . Horde_Kolab_Server_Object::OBJECTCLASS_TOP . ')', array(Horde_Kolab_Server_Object::ATTRIBUTE_OC), 'cn=internal,dc=example,dc=org'); $this->assertEquals(4, count($result)); } } /** * Test sorting. * * @return NULL */ public function testSorting() { foreach ($this->servers as $server) { /* $result = $server->search('(mail=*)', array('mail')); */ /* $this->assertEquals(5, count($result)); */ /* $server->sort($result, 'mail'); */ /* foreach ($result as $object) { */ /* if (isset($object['data']['dn'])) { */ /* switch ($object['data']['dn']) { */ /* case 'cn=Test Address,cn=external,dc=example,dc=org': */ /* $this->assertContains('address@example.org', $object['data']['mail']); */ /* break; */ /* case '': */ /* $this->assertContains('address@example.org', $object['data']['mail']); */ /* break; */ /* } */ /* } */ /* } */ } } /** * Test listing objects. * * @return NULL */ public function testListObjects() { foreach ($this->servers as $server) { $filter = '(&(objectClass=kolabInetOrgPerson)(uid=*)(mail=*)(sn=*))'; $attributes = array( 'Sn', 'Cn', Horde_Kolab_Server_Object_Kolabinetorgperson::ATTRIBUTE_UID, Horde_Kolab_Server_Object_Kolabinetorgperson::ATTRIBUTE_MAIL, Horde_Kolab_Server_Object_Kolabinetorgperson::ATTRIBUTE_DELETED, ); $sort = 'Sn'; $result = $server->search($filter); $this->assertEquals(2, count($result)); $result = $server->listObjects('Horde_Kolab_Server_Object_Kolab_User'); $this->assertEquals('Horde_Kolab_Server_Object_Kolab_User', get_class(array_shift($result))); $result = $server->listObjects('Horde_Kolab_Server_Object_Kolabsharedfolder'); $this->assertEquals(1, count($result)); $this->assertEquals('Horde_Kolab_Server_Object_Kolabsharedfolder', get_class(array_shift($result))); } } /** * Test handling of object classes. * * @return NULL */ public function testGetObjectClasses() { foreach ($this->servers as $server) { $classes = $server->getObjectClasses('cn=Gunnar Wrobel,dc=example,dc=org'); $this->assertContains('top', $classes); $this->assertContains('kolabinetorgperson', $classes); try { $classes = $server->getObjectClasses('cn=DOES NOT EXIST,dc=example,dc=org'); } catch (Horde_Kolab_Server_Exception $classes) { } $this->assertError($classes, 'No such object: cn=DOES NOT EXIST,dc=example,dc=org'); $classes = $server->getObjectClasses('cn=The Administrator,dc=example,dc=org'); $this->assertContains('kolabinetorgperson', $classes); } } /** * Test handling of object types. * * @return NULL */ public function testDetermineType() { foreach ($this->servers as $server) { $type = $server->determineType('cn=empty.group@example.org,dc=example,dc=org'); $this->assertEquals('Horde_Kolab_Server_Object_Kolabgroupofnames', $type); $type = $server->determineType('cn=shared@example.org,dc=example,dc=org'); $this->assertEquals('Horde_Kolab_Server_Object_Kolabsharedfolder', $type); $type = $server->determineType('cn=The Administrator,dc=example,dc=org'); $this->assertEquals('Horde_Kolab_Server_Object_Kolab_Administrator', $type); $type = $server->determineType('cn=Main Tainer,dc=example,dc=org'); $this->assertEquals('Horde_Kolab_Server_Object_Kolab_Maintainer', $type); $type = $server->determineType('cn=Domain Maintainer,dc=example,dc=org'); $this->assertEquals('Horde_Kolab_Server_Object_Kolab_Domainmaintainer', $type); $type = $server->determineType('cn=Test Address,cn=external,dc=example,dc=org'); $this->assertEquals('Horde_Kolab_Server_Object_Kolab_Address', $type); $type = $server->determineType('cn=Gunnar Wrobel,dc=example,dc=org'); $this->assertEquals('Horde_Kolab_Server_Object_Kolab_User', $type); } } /** * Test retrieving a primary mail for a mail or id. * * @return NULL */ public function testMailForIdOrMail() { foreach ($this->servers as $server) { $mail = $server->mailForIdOrMail('wrobel'); $this->assertEquals('wrobel@example.org', $mail); $mail = $server->mailForIdOrMail('wrobel@example.org'); $this->assertEquals('wrobel@example.org', $mail); $mail = $server->mailForIdOrMail('DOES NOT EXIST'); $this->assertSame(false, $mail); } } /** * Test retrieving a UID for a mail or id. * * @return NULL */ public function testUidForIdOrMail() { foreach ($this->servers as $server) { $uid = $server->uidForIdOrMail('wrobel'); $this->assertEquals('cn=Gunnar Wrobel,dc=example,dc=org', $uid); $uid = $server->uidForIdOrMail('wrobel@example.org'); $this->assertEquals('cn=Gunnar Wrobel,dc=example,dc=org', $uid); $uid = $server->uidForIdOrMail('DOES NOT EXIST'); $this->assertSame(false, $uid); } } /** * Test retrieving a UID for a mail or id. * * @return NULL */ public function testUidForMailOrIdOrAlias() { foreach ($this->servers as $server) { $uid = $server->uidForIdOrMailOrAlias('g.wrobel@example.org'); $this->assertEquals('cn=Gunnar Wrobel,dc=example,dc=org', $uid); $uid = $server->uidForIdOrMailOrAlias('wrobel@example.org'); $this->assertEquals('cn=Gunnar Wrobel,dc=example,dc=org', $uid); $uid = $server->uidForIdOrMailOrAlias('wrobel'); $this->assertEquals('cn=Gunnar Wrobel,dc=example,dc=org', $uid); $uid = $server->uidForIdOrMailOrAlias('DOES NOT EXIST'); $this->assertSame(false, $uid); } } /** * Test retrieving all addresses for a mail or id. * * @return NULL */ public function testAddrsForIdOrMail() { foreach ($this->servers as $server) { $addrs = $server->addrsForIdOrMail('wrobel'); $testuser = $server->fetch('cn=Test Test,dc=example,dc=org'); $this->assertContains('wrobel@example.org', $testuser->get(Horde_Kolab_Server_Object_Kolabinetorgperson::ATTRIBUTE_DELEGATE, false)); $this->assertContains('wrobel@example.org', $addrs); $this->assertContains('test@example.org', $addrs); $this->assertContains('t.test@example.org', $addrs); $this->assertContains('g.wrobel@example.org', $addrs); $this->assertContains('gunnar@example.org', $addrs); $addrs = $server->addrsForIdOrMail('test@example.org'); $this->assertContains('test@example.org', $addrs); $this->assertContains('t.test@example.org', $addrs); } } /** * Test retrieving a UID for a primary mail. * * @return NULL */ public function testUidForMailAddress() { foreach ($this->servers as $server) { $uid = $server->uidForIdOrMailOrAlias('wrobel@example.org'); $this->assertEquals('cn=Gunnar Wrobel,dc=example,dc=org', $uid); $uid = $server->uidForIdOrMailOrAlias('test@example.org'); $this->assertEquals('cn=Test Test,dc=example,dc=org', $uid); $uid = $server->uidForIdOrMailOrAlias('gunnar@example.org'); $this->assertEquals('cn=Gunnar Wrobel,dc=example,dc=org', $uid); $uid = $server->uidForIdOrMailOrAlias('wrobel'); $this->assertEquals('cn=Gunnar Wrobel,dc=example,dc=org', $uid); } } /** * Test retrieving a UID for an attribute. * * @return NULL */ public function testUidForAttr() { foreach ($this->servers as $server) { $uid = $server->uidForSearch(array('AND' => array(array('field' => 'alias', 'op' => '=', 'test' => 'g.wrobel@example.org')))); $this->assertEquals('cn=Gunnar Wrobel,dc=example,dc=org', $uid); } } /** * Test group membership testing. * * @return NULL */ public function testMemberOfGroupAddress() { foreach ($this->servers as $server) { $uid = $server->uidForIdOrMailOrAlias('g.wrobel@example.org'); $member = $server->memberOfGroupAddress($uid, 'group@example.org'); $this->assertTrue($member); $member = $server->memberOfGroupAddress( $server->uidForIdOrMailOrAlias('test@example.org'), 'group@example.org'); $this->assertTrue($member); $member = $server->memberOfGroupAddress( $server->uidForIdOrMailOrAlias('somebody@example.org'), 'group@example.org'); $this->assertFalse($member); } } /** * Test group fetching. * * @return NULL */ public function testGetGroups() { foreach ($this->servers as $server) { $filter = '(&(objectClass=kolabGroupOfNames)(member=' . Horde_Ldap_Util::escapeFilterValue('cn=The Administrator,dc=example,dc=org') . '))'; $result = $server->search($filter, array()); $this->assertTrue(!empty($result)); /* $entry = $server->_firstEntry($result); */ /* $this->assertTrue(!empty($entry)); */ /* $uid = $server->_getDn($entry); */ /* $this->assertTrue(!empty($uid)); */ /* $entry = $server->_nextEntry($entry); */ /* $this->assertTrue(empty($entry)); */ /* $entries = $server->_getDns($result); */ /* $this->assertTrue(!empty($entries)); */ $groups = $server->getGroups('cn=The Administrator,dc=example,dc=org'); $this->assertTrue(!empty($groups)); $groups = $server->getGroups($server->uidForIdOrMailOrAlias('g.wrobel@example.org')); $this->assertContains('cn=group@example.org,dc=example,dc=org', $groups); $groups = $server->getGroupAddresses($server->uidForIdOrMailOrAlias('g.wrobel@example.org')); $this->assertContains('group@example.org', $groups); $groups = $server->getGroups($server->uidForIdOrMailOrAlias('test@example.org')); $this->assertContains('cn=group@example.org,dc=example,dc=org', $groups); $groups = $server->getGroupAddresses($server->uidForIdOrMailOrAlias('test@example.org')); $this->assertContains('group@example.org', $groups); $groups = $server->getGroups('nobody'); $this->assertTrue(empty($groups)); } } } Horde_Kolab_Server-2.0.5/test/Horde/Kolab/Server/Integration/ObjectsTest.php0000664000175000017500000000775712653735542025120 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * Tests for the main server class. * * Copyright 2008-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Integration_ObjectsTest extends PHPUnit_Framework_TestCase { public function setUp() { $this->markTestIncomplete('Needs to be fixed'); } /** * Provide a mock server. * * @return Horde_Kolab_Server The mock server. */ protected function getMockServer() { $injector = new Horde_Injector(new Horde_Injector_TopLevel()); $config = new stdClass; $config->driver = 'none'; $injector->setInstance('Horde_Kolab_Server_Config', $config); $injector->bindFactory('Horde_Kolab_Server_Structure', 'Horde_Kolab_Server_Factory', 'getStructure'); $injector->bindFactory('Horde_Kolab_Server', 'Horde_Kolab_Server_Factory', 'getServer'); return $injector->getInstance('Horde_Kolab_Server'); } /** * The generating a uid for an object. * * @return NULL */ public function testGenerateUid() { $ks = $this->getMockServer(); $user = new Horde_Kolab_Server_Object($ks, null, null); $this->assertEquals(preg_replace('/[0-9a-f]*/', '', $user->get(Horde_Kolab_Server_Object::ATTRIBUTE_UID)), ''); } /** * Test creating the server object. * * @return NULL */ public function testCreation() { try { $injector = new Horde_Injector(new Horde_Injector_TopLevel()); $config = new stdClass; $config->driver = 'dummy'; $injector->setInstance('Horde_Kolab_Server_Config', $config); $injector->bindFactory('Horde_Kolab_Server_Structure', 'Horde_Kolab_Server_Factory', 'getStructure'); $injector->bindFactory('Horde_Kolab_Server', 'Horde_Kolab_Server_Factory', 'getServer'); Horde_Kolab_Server_Factory::getServer($injector); $this->assertFail('No error!'); } catch (Horde_Kolab_Server_Exception $e) { $this->assertEquals('Server type definition "Horde_Kolab_Server_Dummy" missing.', $e->getMessage()); } } /** * The base class provides no abilities for reading data. So it * should mainly return error. But it should be capable of * returning a dummy Kolab user object. * * @return NULL */ public function testFetch() { $ks = $this->getMockServer(); $user = $ks->fetch('test'); $this->assertEquals('Horde_Kolab_Server_Object_Kolab_User', get_class($user)); $ks = $this->getMockServer(); $user = $ks->fetch(); $this->assertEquals('Horde_Kolab_Server_Object_Kolab_User', get_class($user)); } /** * Test listing objects. * * @return NULL */ public function testList() { $ks = $this->getMockServer(); $hash = $ks->listHash('Horde_Kolab_Server_Object'); $this->assertEquals($hash, array()); $ks = $this->getMockServer(); $hash = $ks->listHash('Horde_Kolab_Server_Object'); $this->assertEquals($hash, array()); } } Horde_Kolab_Server-2.0.5/test/Horde/Kolab/Server/Integration/ObjectTest.php0000664000175000017500000001500012653735542024711 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * Require our basic test case definition */ require_once __DIR__ . '/Scenario.php'; /** * The the handling of objects. * * Copyright 2008-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Integration_ObjectTest extends Horde_Kolab_Server_Integration_Scenario { /** * Set up a dummy db object that will not be used during the * tests. We just need it so that PHP does not complain about the * inability to refernce the storage class. * * @return NULL */ protected function setUp() { parent::setUp(); $this->_dummydb = new DummyDB(); } /** * Provide test data for the ConstructDn test. * * @return array The test object data. */ public static function provideConstructDn() { return array( array('test', null, 'test'), array(false, array('dn' => 'test'), 'test'), array(false, array('dn' => array('test')), 'test'), array('test2', array('dn' => array('test')), 'test2'), ); } /** * Check a few DN values when constructing the object. * * @param string $dn The uid for the object. * @param string $data Object data. * @param string $expect Expect this uid. * * @dataProvider provideConstructDn * * @return NULL */ public function testConstructDn($dn, $data, $expect) { $ko = new Horde_Kolab_Server_Object($this->_dummydb, $dn, $data); $ndn = $ko->get(Horde_Kolab_Server_Object_Kolab_User::ATTRIBUTE_UID); $this->assertNoError($ndn); $this->assertEquals($expect, $ndn); } /** * Provide test data for the GetFn test. * * @return array The test object data. */ public static function provideGetFn() { return array( array( array( 'dn' => 'test', 'cn' => 'Frank Mustermann', 'sn' => 'Mustermann'), 'Frank')); } /** * Check the generating of the "First Name" attribute. * * @param string $data Object data. * @param string $expect Expect this full name. * * @dataProvider provideGetFn * * @return NULL */ public function testGetFn($data, $expect) { $ko = &Horde_Kolab_Server_Object::factory('Horde_Kolab_Server_Object_Kolab_User', null, $this->_dummydb, $data); $this->assertNoError($ko); $ndn = $ko->get(Horde_Kolab_Server_Object_Kolab_User::ATTRIBUTE_FN); $this->assertNoError($ndn); $this->assertEquals($expect, $ndn); } /** * Provide test data for the GetFn test. * * @return array The test object data. */ public static function provideGetArrayChanges() { return array( array( array( array( 'a', ), array( 'a', ), ), true, ), array( array( array( 'a', ), array( 'b', ), ), false, ), array( array( array( ), array( 'a' => 'b', ), ), false, ), array( array( array( ), array( 'b', ), ), false, ), ); } /** * Check the generating of the "First Name" attribute. * * @param string $data Object data. * @param string $expect Expect this full name. * * @dataProvider provideGetArrayChanges * * @return NULL */ public function testGetArrayChanges($data, $expect) { $ko = &Horde_Kolab_Server_Object::factory('Horde_Kolab_Server_Object_Kolab_User', null, $this->_dummydb, array( 'dn' => 'test', 'cn' => 'Frank Mustermann', 'sn' => 'Mustermann')); $this->assertNoError($ko); $c = $ko->getArrayChanges($data[0], $data[1]); $this->assertEquals($expect, empty($c)); } } /** * A dummy class for testing. * * Copyright 2008-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class DummyDB { public function getAttributes() { return array(array(Horde_Kolab_Server_Object_Kolab_User::ATTRIBUTE_UID => array( 'method' => 'getUid', ), Horde_Kolab_Server_Object_Kolab_User::ATTRIBUTE_FN => array( 'method' => 'getFn', )), array( 'derived' => array(Horde_Kolab_Server_Object_Kolab_User::ATTRIBUTE_UID, Horde_Kolab_Server_Object_Kolab_User::ATTRIBUTE_FN, ), 'locked' => array(), 'required' => array())); } public function read() { return false; } } Horde_Kolab_Server-2.0.5/test/Horde/Kolab/Server/Integration/OrgPersonTest.php0000664000175000017500000001674212653735542025437 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * Require our basic test case definition */ require_once __DIR__ . '/Scenario.php'; /** * Test the organizationalPerson object. * * Copyright 2009-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Integration_OrgPersonTest extends Horde_Kolab_Server_Integration_Scenario { /** * Objects used within this test * * @var array */ private $objects = array( /* Default organizationalPerson */ array( 'type' => 'Horde_Kolab_Server_Object_Organizationalperson', 'Cn' => 'Kolab_Server_OrgPersonTest_123', 'Sn' => 'Kolab_Server_OrgPersonTest_123', 'Userpassword' => 'Kolab_Server_OrgPersonTest_123', ), /* Invalid person (no sn) */ array( 'type' => 'Horde_Kolab_Server_Object_Organizationalperson', 'Cn' => 'Kolab_Server_OrgPersonTest_123', 'Userpassword' => 'Kolab_Server_OrgPersonTest_123', ), ); /** * Set up testing. * * @return NULL */ protected function setUp() { parent::setUp(); $this->initializeEnvironments(); $this->servers = $this->getKolabServers(); } /** * Test ID generation for a person. * * @return NULL */ public function testGenerateId() { foreach ($this->servers as $server) { $a = new Horde_Kolab_Server_Object_Organizationalperson($server, null, $this->objects[0]); $this->assertContains(Horde_Kolab_Server_Object_Person::ATTRIBUTE_CN . '=' . $this->objects[0][Horde_Kolab_Server_Object_Person::ATTRIBUTE_CN], $a->get(Horde_Kolab_Server_Object_Person::ATTRIBUTE_UID)); } } /** * Test adding an invalid person. * * @expectedException Horde_Kolab_Server_Exception * * @return NULL */ public function testAddInvalidPerson() { $this->addToServers($this->objects[1]); } /** * Test handling simple attributes. * * @return NULL */ public function testSimpleAttributes() { foreach ($this->servers as $server) { $person = $this->assertAdd($server, $this->objects[0], array(Horde_Kolab_Server_Object_Organizationalperson::ATTRIBUTE_JOBTITLE => '')); $this->assertSimpleAttributes($person, $server, array( )); } } /** * Test handling the postal address. * * @return NULL */ public function testHandlingAPostalAddress() { foreach ($this->servers as $server) { $person = $this->assertAdd($server, $this->objects[0], array(Horde_Kolab_Server_Object_Organizationalperson::ATTRIBUTE_POSTALADDRESS => 'Kolab_Server_OrgPersonTest_123$$ ')); $this->assertStoreFetch($person, $server, array('Sn' => 'Kolab_Server_OrgPersonTest_456'), array(Horde_Kolab_Server_Object_Organizationalperson::ATTRIBUTE_POSTALADDRESS => array('Kolab_Server_OrgPersonTest_456$$ '))); $this->assertStoreFetch($person, $server, array('Sn' => 'Kolab_Server_OrgPersonTest_123', Horde_Kolab_Server_Object_Organizationalperson::ATTRIBUTE_STREET => 'Street 1', Horde_Kolab_Server_Object_Organizationalperson::ATTRIBUTE_POSTALCODE => '12345', Horde_Kolab_Server_Object_Organizationalperson::ATTRIBUTE_CITY => 'Nowhere'), array(Horde_Kolab_Server_Object_Organizationalperson::ATTRIBUTE_POSTALADDRESS => array('Kolab_Server_OrgPersonTest_123$Street 1$12345 Nowhere'))); $this->assertStoreFetch($person, $server, array(Horde_Kolab_Server_Object_Organizationalperson::ATTRIBUTE_POSTOFFICEBOX => 'öäü/)(="§%$&§§$\'*', Horde_Kolab_Server_Object_Organizationalperson::ATTRIBUTE_STREET => null), array(Horde_Kolab_Server_Object_Organizationalperson::ATTRIBUTE_POSTALADDRESS => array('Kolab_Server_OrgPersonTest_123$öäü/)(="§%\24&§§\24\'*$12345 Nowhere'))); $this->assertStoreFetch($person, $server, array(Horde_Kolab_Server_Object_Organizationalperson::ATTRIBUTE_STREET => null, Horde_Kolab_Server_Object_Organizationalperson::ATTRIBUTE_POSTALCODE => null, //@todo: Why does this need a string? Horde_Kolab_Server_Object_Organizationalperson::ATTRIBUTE_POSTALADDRESS => '', Horde_Kolab_Server_Object_Organizationalperson::ATTRIBUTE_POSTOFFICEBOX => null, Horde_Kolab_Server_Object_Organizationalperson::ATTRIBUTE_CITY => null), array(Horde_Kolab_Server_Object_Organizationalperson::ATTRIBUTE_POSTALADDRESS => array('Kolab_Server_OrgPersonTest_123$$ '))); } } /** * Test handling easy attributes. * * @return NULL */ public function testEasyAttributes() { foreach ($this->servers as $server) { $person = $this->assertAdd($server, $this->objects[0], array(Horde_Kolab_Server_Object_Organizationalperson::ATTRIBUTE_JOBTITLE => '')); $this->assertEasyAttributes($person, $server, array( Horde_Kolab_Server_Object_Organizationalperson::ATTRIBUTE_JOBTITLE => array( 'Teacher', '0', 'Something', null, '', array('This', 'That'), ), Horde_Kolab_Server_Object_Organizationalperson::ATTRIBUTE_FAX => array( '123456789', '+1234567890', array('1', '2'), '0', //@todo: How to delete? //null ) ) ); } } } Horde_Kolab_Server-2.0.5/test/Horde/Kolab/Server/Integration/PersonTest.php0000664000175000017500000002342112653735542024757 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * Require our basic test case definition */ require_once __DIR__ . '/Scenario.php'; /** * Test the person object. * * Copyright 2009-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Integration_PersonTest extends Horde_Kolab_Server_Integration_Scenario { public $cn = 'Kolab_Server_PersonTest'; /** * Objects used within this test * * @var array */ private $objects = array( /* Default dummy person */ array( 'type' => 'Horde_Kolab_Server_Object_Person', 'Cn' => 'Kolab_Server_PersonTest_123', 'Sn' => 'Kolab_Server_PersonTest_123', 'Userpassword' => 'Kolab_Server_PersonTest_123', ), /* Invalid person (no sn) */ array( 'type' => 'Horde_Kolab_Server_Object_Person', 'Cn' => 'Kolab_Server_PersonTest_123', 'Userpassword' => 'Kolab_Server_PersonTest_123', ), /* Person with problematic characters */ array( 'type' => 'Horde_Kolab_Server_Object_Person', 'Cn' => 'Kolab_Server_PersonTest_!"$%&()=?', 'Sn' => 'Kolab_Server_PersonTest_!"$%&()=?', 'Userpassword' => 'Kolab_Server_PersonTest_!"$%&()=?', ), /* Person with difficult encoding */ array( 'type' => 'Horde_Kolab_Server_Object_Person', 'Cn' => 'Kolab_Server_PersonTest_ügöräß§', 'Sn' => 'Kolab_Server_PersonTest_ügöräß§', 'Userpassword' => 'Kolab_Server_PersonTest_ügöräß§', ), /* Person with forward slash */ array( 'type' => 'Horde_Kolab_Server_Object_Person', 'Cn' => 'Kolab_Server_PersonTest_/', 'Sn' => 'Kolab_Server_PersonTest_/', 'Userpassword' => 'Kolab_Server_PersonTest_/', ), /* Person with double cn */ array( 'type' => 'Horde_Kolab_Server_Object_Person', 'Cn' => array('Kolab_Server_PersonTest_cn1', 'Kolab_Server_PersonTest_cn2'), 'Sn' => 'Kolab_Server_PersonTest_cncn', 'Userpassword' => 'Kolab_Server_PersonTest_cncn', ), /* Person with name suffix*/ array( 'type' => 'Horde_Kolab_Server_Object_Person', 'Cn' => 'Kolab_Server_PersonTest_123', 'Sn' => 'Kolab_Server_PersonTest_123', 'Userpassword' => 'Kolab_Server_PersonTest_123', ), /* Person for telephone number handling*/ array( 'type' => 'Horde_Kolab_Server_Object_Person', 'Cn' => 'Kolab_Server_PersonTest_123456', 'Sn' => 'Kolab_Server_PersonTest_123456', 'Userpassword' => 'Kolab_Server_PersonTest_123456', ), /* Person with a creation date*/ array( 'type' => 'Horde_Kolab_Server_Object_Person', 'Cn' => 'Kolab_Server_PersonTest_123456', 'Sn' => 'Kolab_Server_PersonTest_123456', 'Userpassword' => 'Kolab_Server_PersonTest_123456', 'Creationdate' => '191008030000Z', ), ); /** * Set up testing. * * @return NULL */ protected function setUp() { parent::setUp(); $this->initializeEnvironments(); $this->servers = $this->getKolabServers(); } /** * Test ID generation for a person. * * @return NULL */ public function testGenerateId() { foreach ($this->servers as $server) { $a = new Horde_Kolab_Server_Object_Person($server, null, $this->objects[0]); $this->assertContains('Cn' . '=' . $this->objects[0]['Cn'], $a->get(Horde_Kolab_Server_Object_Person::ATTRIBUTE_UID)); } } /** * Test adding an invalid person. * * @expectedException Horde_Kolab_Server_Exception * * @return NULL */ public function testAddInvalidPerson() { $this->addToServers($this->objects[1]); } /** * Test adding a person. * * @return NULL */ public function testAddPerson() { foreach ($this->servers as $server) { $adds = array(0, 2, 3, 4); foreach ($adds as $add) { $result = $server->add($this->objects[$add]); $this->assertNoError($result); $cn_result = $server->uidForCn($this->objects[$add]['Cn']); $this->assertNoError($cn_result); $dn_parts = Horde_Ldap_Util::explodeDN($cn_result, array('casefold' => 'lower')); $dnpart = Horde_Ldap_Util::unescapeDNValue($dn_parts[0]); /** * @todo: I currently do not really understand why the forward slash * is not correctly converted back but I lack the time to analyse it * in detail. The server entry looks okay. */ $dnpart = str_replace('\/', '/', $dnpart); $this->assertContains('Cn' . '=' . $this->objects[$add]['Cn'], $dnpart[0]); $result = $server->delete($cn_result); $this->assertNoError($result); $cn_result = $server->uidForCn($this->objects[$add]['Cn']); $this->assertNoError($cn_result); $this->assertFalse($server->uidForCn($this->objects[$add]['Cn'])); } } } /** * Test modifying the surname of a person. * * @return NULL */ public function testModifyPersonSn() { foreach ($this->servers as $server) { $person = $this->assertAdd($server, $this->objects[2], array('Cn' => $this->objects[2]['Cn'])); $this->assertSimpleSequence($person, $server, 'Sn', array('modified', 'modified_again'), true); } } /** * Test modifying the cn of a person. This should have an effect on the UID * of the object and needs to rename the object. * * @return NULL */ public function testModifyPersonCn() { foreach ($this->servers as $server) { $person = $server->add($this->objects[2]); $this->assertNoError($person); $person = $server->fetch($person->getUid()); $this->assertEquals($this->objects[2]['Cn'], $person->get('Cn')); $result = $person->save(array('Cn' => 'Kolab_Server_PersonTest_äö')); $cn_result = $server->uidForCn('Kolab_Server_PersonTest_äö'); $person = $server->fetch($cn_result); $this->assertEquals($person->get('Cn'), 'Kolab_Server_PersonTest_äö'); $result = $server->delete($cn_result); $this->assertNoError($result); $cn_result = $server->uidForCn('Kolab_Server_PersonTest_äö'); $this->assertNoError($cn_result); $this->assertFalse($cn_result); } } /** * Test adding a person with two common names. * * @return NULL */ public function testAddDoubleCnPerson() { foreach ($this->servers as $server) { $person = $this->assertAdd($server, $this->objects[5], array()); $cn_result = $server->uidForCn($this->objects[5]['Cn'][0]); $this->assertNoError($cn_result); $dn_parts = Horde_Ldap_Util::explodeDN($cn_result, array('casefold' => 'lower')); $dnpart = Horde_Ldap_Util::unescapeDNValue($dn_parts[0]); $this->assertContains('Cn' . '=' . $this->objects[5]['Cn'][0], $dnpart[0]); } } /** * Test handling a phone number. * * @return NULL */ public function testHandlingAPhoneNumaber() { foreach ($this->servers as $server) { $person = $this->assertAdd($server, $this->objects[7], array(Horde_Kolab_Server_Object_Person::ATTRIBUTE_TELNO => '')); $this->assertSimpleSequence($person, $server, Horde_Kolab_Server_Object_Person::ATTRIBUTE_TELNO, array('123456789', '+1234567890', array('1', '2'), null, '0'), true); } } /** * Test retrrieving a date. * * @return NULL */ public function testGetDate() { foreach ($this->servers as $server) { $person = $this->assertAdd($server, $this->objects[8], array(Horde_Kolab_Server_Object_Person::ATTRIBUTE_TELNO => '')); $cdate = $person->get(Horde_Kolab_Server_Object_Person::ATTRDATE_CREATIONDATE); $this->assertEquals('Horde_Date', get_class($cdate)); $this->assertEquals('1910-08-03 01:00:00', (string) $cdate); } } } Horde_Kolab_Server-2.0.5/test/Horde/Kolab/Server/Integration/Scenario.php0000664000175000017500000010656212653735542024424 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Share */ /** * Base for PHPUnit scenarios. * * Copyright 2008-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Test * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Share */ class Horde_Kolab_Server_Integration_Scenario extends PHPUnit_Extensions_Story_TestCase { /** The mock environment */ const ENVIRONMENT_MOCK = 'mock'; /** The real server environment */ const ENVIRONMENT_REAL = 'real'; /** * The environments we provide to the test. * * @var array */ protected $_environments; /** * Uid of added objects. Should be removed on tearDown. * * @var array */ public $added; /** * Handle a "given" step. * * @param array &$world Joined "world" of variables. * @param string $action The description of the step. * @param array $arguments Additional arguments to the step. * * @return mixed The outcome of the step. */ public function runGiven(&$world, $action, $arguments) { switch($action) { case 'several injectors': foreach ($this->getEnvironments() as $environment) { $this->prepareInjector($environment); } break; case 'several Kolab servers': case 'the test environments': $this->initializeEnvironments(); break; case 'an empty Kolab server': $world['server'] = $this->prepareKolabServer(self::ENVIRONMENT_MOCK); break; case 'a basic Kolab server': $world['server'] = $this->prepareBasicKolabServer($world); break; default: return $this->notImplemented($action); } } /** * Handle a "when" step. * * @param array &$world Joined "world" of variables. * @param string $action The description of the step. * @param array $arguments Additional arguments to the step. * * @return mixed The outcome of the step. */ public function runWhen(&$world, $action, $arguments) { switch($action) { case 'adding a Kolab server object': $world['result']['add'] = $this->addToServers($arguments[0]); break; case 'adding an invalid Kolab server object': try { $world['result']['add'] = $this->addToServers($arguments[0]); } catch (Horde_Kolab_Server_Exception $e) { $world['result']['add'] = $e; } break; case 'adding an object list': foreach ($arguments[0] as $object) { try { $world['result']['add'][] = $this->addToServers($object); } catch (Horde_Kolab_Server_Exception $e) { $world['result']['add'] = $e; return; } } $world['result']['add'] = true; break; case 'adding a distribution list': $world['result']['add'] = $this->addToServers($this->provideDistributionList()); break; case 'listing all users': $world['list'] = $this->listObjectsOnServer('Horde_Kolab_Server_Object_Kolab_User'); break; case 'listing all groups': $world['list'] = $this->listObjectsOnServer('Horde_Kolab_Server_Object_Kolabgroupofnames'); break; case 'listing all objects of type': $world['list'] = $this->listObjectsOnServer($arguments[0]); break; case 'retrieving a hash list with all objects of type': $world['list'] = array(); foreach ($this->world['injector'] as $injector) { $server = $injector->getInstance('Horde_Kolab_Server'); $world['list'][] = $server->listHash($arguments[0]); } break; default: return $this->notImplemented($action); } } /** * Handle a "then" step. * * @param array &$world Joined "world" of variables. * @param string $action The description of the step. * @param array $arguments Additional arguments to the step. * * @return mixed The outcome of the step. */ public function runThen(&$world, $action, $arguments) { switch($action) { case 'the result should be an object of type': if (!isset($world['result'])) { $this->fail('Did not receive a result!'); } $this->assertRecursiveType($world['result'], $arguments[0]); break; case 'the result indicates success.': if (!isset($world['result'])) { $this->fail('Did not receive a result!'); } $this->assertNoError($world['result']); break; case 'the result should indicate an error with': if (!isset($world['result'])) { $this->fail('Did not receive a result!'); } foreach ($world['result'] as $result) { if ($result instanceof Horde_Kolab_Server_Exception) { $this->assertEquals($arguments[0], $result->getMessage()); } else { $this->assertEquals($arguments[0], 'Action succeeded without an error.'); } } break; case 'the list has a number of entries equal to': if ($world['list'] instanceof Horde_Kolab_Server_Exception) { $this->assertEquals('', $world['list']->getMessage()); } else { $this->assertEquals($arguments[0], count($world['list'])); } break; case 'the list is an empty array': if ($world['list'] instanceof Horde_Kolab_Server_Exception) { $this->assertEquals('', $world['list']->getMessage()); } else { $this->assertEquals(array(array()), $world['list']); } break; case 'the provided list and the result list match with regard to these attributes': if ($world['list'] instanceof Horde_Kolab_Server_Exception) { $this->assertEquals('', $world['list']->getMessage()); } else { $provided_vals = array(); foreach ($arguments[2] as $provided_element) { if (isset($provided_element[$arguments[0]])) { $provided_vals[] = $provided_element[$arguments[0]]; } else { $this->fail(sprintf('The provided element %s does have no value for %s.', print_r($provided_element, true), print_r($arguments[0]))); } } $result_vals = array(); foreach ($world['list'] as $result_set) { foreach ($result_set as $result_element) { if (isset($result_element[$arguments[1]])) { $result_vals[] = $result_element[$arguments[1]]; } else { $this->fail(sprintf('The result element %s does have no value for %s.', print_r($result_element, true), print_r($arguments[1]))); } } $this->assertEquals(array(), array_diff($provided_vals, $result_vals)); } } break; case 'each element in the result list has an attribute': if ($world['list'] instanceof Horde_Kolab_Server_Exception) { $this->assertEquals('', $world['list']->getMessage()); } else { $result_vals = array(); foreach ($world['list'] as $result_set) { foreach ($result_set as $result_element) { if (!isset($result_element[$arguments[0]])) { $this->fail(sprintf('The result element %s does have no value for %s.', print_r($result_element, true), print_r($arguments[0], true))); } } } } break; case 'each element in the result list has an attribute set to a given value': if ($world['list'] instanceof Horde_Kolab_Server_Exception) { $this->assertEquals('', $world['list']->getMessage()); } else { $result_vals = array(); foreach ($world['list'] as $result_set) { foreach ($result_set as $result_element) { if (!isset($result_element[$arguments[0]])) { $this->fail(sprintf('The result element %s does have no value for %s.', print_r($result_element, true), print_r($arguments[0], true))); } if ($result_element[$arguments[0]] != $arguments[1]) { $this->fail(sprintf('The result element %s has an unexpected value %s for %s.', print_r($result_element, true), print_r($result_element[$arguments[0]], true), print_r($arguments[0], true))); } } } } break; case 'the login was successful': $this->assertNoError($world['login']); $this->assertTrue($world['login']); break; case 'the list contains a number of elements equal to': $this->assertEquals($arguments[0], count($world['list'])); break; default: return $this->notImplemented($action); } } /** * Identify the environments we want to run our tests in. * * @return array The selected environments. */ public function getEnvironments() { if (empty($this->_environments)) { /** The mock environment provides our basic test scenario */ $this->_environments = array(self::ENVIRONMENT_MOCK); $testing = getenv('KOLAB_TEST'); if (!empty($testing)) { $this->_environments[] = array(self::ENVIRONMENT_REAL); } } return $this->_environments; } /** * Specifically set the environments we wish to support. * * @param array $environments The selected environments. * * @return NULL */ public function setEnvironments($environments) { $this->_environments = $environments; } /** * Initialize the environments. * * @param string $environment The name of the environment. * * @return NULL */ public function initializeEnvironments() { foreach ($this->getEnvironments() as $environment) { $this->initializeEnvironment($environment); } } /** * Prepare an injector for the given environment. * * @param string $environment The name of the environment. * * @return NULL */ public function prepareInjector($environment) { if (!isset($this->world['injector'][$environment])) { $this->world['injector'][$environment] = new Horde_Injector(new Horde_Injector_TopLevel()); } } /** * Prepare the log handler for the given environment. * * @param string $environment The name of the environment. * * @return NULL */ public function prepareLogger($environment) { $logger = new Horde_Log_Logger(); $handler = new Horde_Log_Handler_Mock(); $logger->addHandler($handler); $this->world['injector'][$environment]->setInstance('Horde_Log_Logger', $logger); } /** * Prepare the server configuration for the given environment. * * @param string $environment The name of the environment. * * @return NULL */ public function prepareKolabServerConfiguration($environment) { switch ($environment) { case self::ENVIRONMENT_MOCK: /** Prepare a Kolab test server */ $config = new stdClass; $config->driver = 'test'; $config->params = array( 'basedn' => 'dc=example,dc=org', 'hashtype' => 'plain' ); $this->world['injector'][$environment]->setInstance('Horde_Kolab_Server_Config', $config); break; default: throw new Horde_Exception('Not implemented!'); } } /** * Prepare the server for the given environment. * * @param string $environment The name of the environment. * * @return NULL */ public function prepareKolabServer($environment) { $this->world['injector'][$environment]->bindFactory('Horde_Kolab_Server_Structure', 'Horde_Kolab_Server_Factory', 'getStructure'); $this->world['injector'][$environment]->bindFactory('Horde_Kolab_Server', 'Horde_Kolab_Server_Factory', 'getServer'); } /** * Get a server from a specific environment. * * @param string $environment The name of the environment. * * @return Horde_Kolab_Server The server. */ public function getKolabServer($environment) { return $this->world['injector'][$environment]->getInstance('Horde_Kolab_Server'); } /** * Initialize the given environment. * * @param string $environment The name of the environment. * * @return NULL */ public function initializeEnvironment($environment) { $this->prepareInjector($environment); $this->prepareLogger($environment); $this->prepareKolabServerConfiguration($environment); $this->prepareKolabServer($environment); } /** * Shortcut to get a Kolab mock server. * * @return Horde_Kolab_Server The server. */ public function getKolabMockServer() { $this->initializeEnvironment(self::ENVIRONMENT_MOCK); return $this->getKolabServer(self::ENVIRONMENT_MOCK); } /** * Retrieves the available servers. This assumes all environments have been * initialied. * * @return array The list of test servers. */ public function getKolabServers() { $servers = array(); foreach ($this->getEnvironments() as $environment) { $servers[] = $this->getKolabServer($environment); } return $servers; } /** * Add an object to a server and remember it for the tear down method. * * @param Horde_Kolab_Server $server The server to add the object to. * @param array $object The object data to store. * * @return Horde_Kolab_Server_Object The resulting object. */ public function addToServer(Horde_Kolab_Server $server, array $object) { $object = $server->add($object); $this->added[] = array($server, $object->getUid()); return $object; } /** * Add an object to the registered servers. * * @param array $object The object data to store. * * @return array An array of objects. */ public function addToServers(array $object) { $result = array(); foreach ($this->world['injector'] as $injector) { $server = $injector->getInstance('Horde_Kolab_Server'); $result[] = $this->addToServer($server, $object); } return $result; } /** * Fill a Kolab Server with test users. * * @param Horde_Kolab_Server $server The server to fill. * * @return NULL */ public function addBasicUsersToServer($server) { $result = $this->addToServer($server, $this->provideBasicUserOne()); $this->assertNoError($result); $result = $this->addToServer($server, $this->provideBasicUserTwo()); $this->assertNoError($result); $result = $this->addToServer($server, $this->provideBasicAddress()); $this->assertNoError($result); $result = $this->addToServer($server, $this->provideBasicAdmin()); $this->assertNoError($result); $result = $this->addToServer($server, $this->provideBasicDomainMaintainer()); $this->assertNoError($result); $result = $this->addToServer($server, $this->provideGroupWithoutMembers()); $this->assertNoError($result); $result = $this->addToServer($server, $this->provideBasicGroupOne()); $this->assertNoError($result); $result = $this->addToServer($server, $this->provideBasicMaintainer()); $this->assertNoError($result); $result = $this->addToServer($server, $this->provideBasicSharedFolder()); $this->assertNoError($result); } /** * List objects on the registered servers. * * @param array $type The type of objects to list. * * @return array An array of objects. */ public function listObjectsOnServer($type) { $result = array(); foreach ($this->world['injector'] as $injector) { $server = $injector->getInstance('Horde_Kolab_Server'); $objects = $server->listObjects($type); $result[] = $objects; } return $result; } /** * Return a test user. * * @return array The test user. */ public function provideBasicUserOne() { return array('givenName' => 'Gunnar', 'sn' => 'Wrobel', 'type' => 'Horde_Kolab_Server_Object_Kolab_User', 'mail' => 'wrobel@example.org', 'uid' => 'wrobel', 'userPassword' => 'none', 'kolabHomeServer' => 'home.example.org', 'kolabImapServer' => 'imap.example.org', 'kolabFreeBusyServer' => 'https://fb.example.org/freebusy', 'kolabInvitationPolicy' => array('ACT_REJECT_IF_CONFLICTS'), 'alias' => array('gunnar@example.org', 'g.wrobel@example.org'), ); } /** * Return a test user. * * @return array The test user. */ public function provideBasicUserTwo() { return array('givenName' => 'Test', 'sn' => 'Test', 'type' => 'Horde_Kolab_Server_Object_Kolab_User', 'mail' => 'test@example.org', 'uid' => 'test', 'userPassword' => 'test', 'kolabHomeServer' => 'home.example.org', 'kolabImapServer' => 'home.example.org', 'kolabFreeBusyServer' => 'https://fb.example.org/freebusy', 'alias' => array('t.test@example.org'), 'kolabDelegate' => 'wrobel@example.org',); } /** * Return a test address. * * @return array The test address. */ public function provideBasicAddress() { return array('type' => 'Horde_Kolab_Server_Object_Kolab_Address', Horde_Kolab_Server_Object_Kolab_Administrator::ATTRIBUTE_GIVENNAME => 'Test', 'Sn' => 'Address', Horde_Kolab_Server_Object_Kolab_Administrator::ATTRIBUTE_MAIL => 'address@example.org', ); } /** * Return a test administrator. * * @return array The test administrator. */ public function provideBasicAdmin() { return array('type' => 'Horde_Kolab_Server_Object_Kolab_Administrator', Horde_Kolab_Server_Object_Kolab_Administrator::ATTRIBUTE_GIVENNAME => 'The', 'Sn' => 'Administrator', Horde_Kolab_Server_Object_Kolab_Administrator::ATTRIBUTE_SID => 'admin', 'Userpassword' => 'none', ); } /** * Return a test maintainer. * * @return array The test maintainer. */ public function provideBasicMaintainer() { return array('type' => 'Horde_Kolab_Server_Object_Kolab_Maintainer', Horde_Kolab_Server_Object_Kolab_Maintainer::ATTRIBUTE_GIVENNAME => 'Main', 'Sn' => 'Tainer', Horde_Kolab_Server_Object_Kolab_Maintainer::ATTRIBUTE_SID => 'maintainer', 'Userpassword' => 'none', ); } /** * Return a test domain maintainer. * * @return array The test domain maintainer. */ public function provideBasicDomainMaintainer() { return array('type' => 'Horde_Kolab_Server_Object_Kolab_Domainmaintainer', Horde_Kolab_Server_Object_Kolab_Domainmaintainer::ATTRIBUTE_GIVENNAME => 'Domain', 'Sn' => 'Maintainer', Horde_Kolab_Server_Object_Kolab_Domainmaintainer::ATTRIBUTE_SID => 'domainmaintainer', 'Userpassword' => 'none', Horde_Kolab_Server_Object_Kolab_Domainmaintainer::ATTRIBUTE_DOMAIN => array('example.com'), ); } /** * Return a test shared folder. * * @return array The test shared folder. */ public function provideBasicSharedFolder() { return array('type' => 'Horde_Kolab_Server_Object_Kolabsharedfolder', Horde_Kolab_Server_Object_Kolabsharedfolder::ATTRIBUTE_CN => 'shared@example.org', Horde_Kolab_Server_Object_Kolabsharedfolder::ATTRIBUTE_HOMESERVER => 'example.org', ); } /** * Provide a set of valid groups. * * @return array The array of groups. */ public function groupLists() { $groups = $this->validGroups(); $result = array(); foreach ($groups as $group) { $result[] = array($group); } return $result; } /** * Provide a set of valid groups. * * @return array The array of groups. */ public function validGroups() { return array( array( $this->provideGroupWithoutMembers(), ), array( $this->provideBasicGroupOne(), ), array( $this->provideBasicGroupTwo(), ), ); } /** * Return a test group. * * @return array The test group. */ public function provideGroupWithoutMembers() { return array('type' => 'Horde_Kolab_Server_Object_Kolabgroupofnames', Horde_Kolab_Server_Object_Kolab_Distlist::ATTRIBUTE_MAIL => 'empty.group@example.org', Horde_Kolab_Server_Object_Kolab_Distlist::ATTRIBUTE_MEMBER => array()); } /** * Return a test group. * * @return array The test group. */ public function provideBasicGroupOne() { return array('type' => 'Horde_Kolab_Server_Object_Kolabgroupofnames', Horde_Kolab_Server_Object_Kolab_Distlist::ATTRIBUTE_MAIL => 'group@example.org', Horde_Kolab_Server_Object_Kolab_Distlist::ATTRIBUTE_MEMBER => array('cn=Test Test,dc=example,dc=org', 'cn=Gunnar Wrobel,dc=example,dc=org') ); } /** * Return a test group. * * @return array The test group. */ public function provideBasicGroupTwo() { return array('type' => 'Horde_Kolab_Server_Object_Kolabgroupofnames', Horde_Kolab_Server_Object_Kolab_Distlist::ATTRIBUTE_MAIL => 'group2@example.org', Horde_Kolab_Server_Object_Kolab_Distlist::ATTRIBUTE_MEMBER => array('cn=Gunnar Wrobel,dc=example,dc=org') ); } public function provideDistributionList() { return array('type' => 'Horde_Kolab_Server_Object_Kolab_Distlist', Horde_Kolab_Server_Object_Kolab_Distlist::ATTRIBUTE_MAIL => 'distlist@example.org', Horde_Kolab_Server_Object_Kolab_Distlist::ATTRIBUTE_MEMBER => array('cn=Test Test,dc=example,dc=org', 'cn=Gunnar Wrobel,dc=example,dc=org') ); } public function provideInvalidUserWithoutPassword() { return array('givenName' => 'Test', 'sn' => 'Test', 'type' => 'Horde_Kolab_Server_Object_Kolab_User', 'mail' => 'test@example.org'); } public function provideInvalidUserWithoutGivenName() { return array('sn' => 'Test', 'userPassword' => 'none', 'type' => 'Horde_Kolab_Server_Object_Kolab_User', 'mail' => 'test@example.org'); } public function provideInvalidUserWithoutLastName() { return array('givenName' => 'Test', 'userPassword' => 'none', 'type' => 'Horde_Kolab_Server_Object_Kolab_User', 'mail' => 'test@example.org'); } public function provideInvalidUserWithoutMail() { return array('givenName' => 'Test', 'sn' => 'Test', 'userPassword' => 'none', 'type' => 'Horde_Kolab_Server_Object_Kolab_User'); } public function provideInvalidUsers() { return array( array( $this->provideInvalidUserWithoutPassword(), 'The value for "userPassword" is missing!' ), array( $this->provideInvalidUserWithoutGivenName(), 'Either the last name or the given name is missing!' ), array( $this->provideInvalidUserWithoutLastName(), 'Either the last name or the given name is missing!' ), array( $this->provideInvalidUserWithoutMail(), 'The value for "mail" is missing!' ), ); } /** @todo: Prefix the stuff below with provide...() */ public function validUsers() { return array( array( $this->provideBasicUserOne(), ), array( $this->provideBasicUserTwo(), ), ); } public function validAddresses() { return array( array( $this->provideBasicAddress(), ), ); } public function validAdmins() { return array( array( $this->provideBasicAdmin(), ), ); } public function validMaintainers() { return array( array( $this->provideBasicMaintainer(), ) ); } public function validDomainMaintainers() { return array( array( $this->provideBasicDomainMaintainer(), ) ); } public function validSharedFolders() { return array( array('cn' => 'Shared', 'type' => 'Horde_Kolab_Server_Object_Kolabsharedfolder' ), ); } public function userLists() { return array( ); } public function userListByLetter() { return array( ); } public function userListByAttribute() { return array( ); } public function userAdd() { return array( ); } public function invalidMails() { return array( ); } public function largeList() { return array( ); } protected function fetchByCn($server, $cn) { $cn_result = $server->uidForCn($cn); $this->assertNoError($cn_result); $object = $server->fetch($cn_result); $this->assertNoError($object); return $object; } /** * Ensure that the variable contains no Horde_Kolab_Server_Exception and * fail if it does. * * @param mixed $var The variable to check. * * @return NULL. */ public function assertNoError($var) { if (is_array($var)) { foreach ($var as $element) { $this->assertNoError($element); } } elseif ($var instanceof Exception) { $this->assertEquals('', $var->getMessage()); } else if ($var instanceof PEAR_Error) { $this->assertEquals('', $var->getMessage()); } } /** * Ensure that the variable contains a Horde_Kolab_Server_Exception and fail * if it does not. Optionally compare the error message with the provided * message and fail if both do not match. * * @param mixed $var The variable to check. * @param string $msg The expected error message. * * @return NULL. */ public function assertError($var, $msg = null) { if (!$var instanceof PEAR_Error) { $this->assertInstanceOf('Horde_Kolab_Server_Exception', $var); if (isset($msg)) { $this->assertEquals($msg, $var->getMessage()); } } else { if (isset($msg)) { $this->assertEquals($msg, $var->getMessage()); } } } /** * Assert that creating a new object operation yields some predictable * attribute results. * * @param Horde_Kolab_Server $server The server the object resides on. * @param array $store The information to save. * @param array $fetch The expected results. * * @return NULL. */ protected function assertAdd(Horde_Kolab_Server $server, array $store, array $fetch) { $object = $server->add($store); $this->assertNoError($object); $this->added[] = array($server, $object->getUid()); $object = $server->fetch($object->getUid()); foreach ($fetch as $attribute => $expect) { $this->assertEquals($expect, $object->get($attribute)); } return $object; } /** * Test simple attributes. * * @dataProvider provideServers * * @return NULL */ public function assertSimpleAttributes(Horde_Kolab_Server_Object $object, Horde_Kolab_Server $server, array $list) { foreach ($list as $item) { $this->assertSimpleSequence($object, $server, $item, array($item, 'öäü/)(="§%$&§§$\'*', '', array('a', 'b'), '0'), true); } } /** * Test easy attributes. * * @dataProvider provideServers * * @return NULL */ public function assertEasyAttributes(Horde_Kolab_Server_Object $object, Horde_Kolab_Server $server, array $list) { foreach ($list as $key => $items) { $this->assertSimpleSequence($object, $server, $key, $items, true); } } /** * Assert that a save() operation yields some predictable attribute results. * * @param Horde_Kolab_Server_Object $object The object to work on. * @param Horde_Kolab_Server $server The server the object resides on. * @param string $attribute The attribute to work on. * @param array $sequence The sequence of values to set and expect. * * @return NULL. */ protected function assertSimpleSequence(Horde_Kolab_Server_Object $object, Horde_Kolab_Server $server, $attribute, array $sequence, $pop_arrays = false) { foreach ($sequence as $value) { $this->assertStoreFetch($object, $server, array($attribute => $value), array($attribute => $value), $pop_arrays); } } /** * Assert that a save() operation yields some predictable attribute results. * * @param Horde_Kolab_Server_Object $object The object to work on. * @param Horde_Kolab_Server $server The server the object resides on. * @param array $store The information to save. * @param array $fetch The expected results. * * @return NULL. */ protected function assertStoreFetch(Horde_Kolab_Server_Object $object, Horde_Kolab_Server $server, array $store, array $fetch, $pop_arrays = false) { $result = $object->save($store); $this->assertNoError($result); $object = $server->fetch($object->getUid()); foreach ($fetch as $attribute => $expect) { $actual = $object->get($attribute, false); if ($pop_arrays && is_array($actual) && count($actual) == 1) { $actual = array_pop($actual); } $this->assertEquals($expect, $actual); } } public function assertRecursiveType($results, $type) { if (is_array($results)) { foreach ($results as $result) { $this->assertRecursiveType($result, $type); } } else { if ($results instanceof Exception) { $this->assertEquals('', $results->getMessage()); } else { $this->assertInstanceOf($type, $results); } } } /** * Setup function. * * @return NULL. */ protected function setUp() { $this->added = array(); $this->markTestIncomplete('Needs to be fixed'); } /** * Cleanup function. * * @return NULL. */ protected function tearDown() { if (isset($this->added)) { $added = array_reverse($this->added); foreach ($added as $add) { $result = $add[0]->delete($add[1]); $this->assertNoError($result); } } } } Horde_Kolab_Server-2.0.5/test/Horde/Kolab/Server/Integration/SearchguidforuidormailTest.php0000664000175000017500000000526512653735542030212 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * Require our basic test case definition */ require_once __DIR__ . '/../LdapTestCase.php'; /** * Test the "GuidForUidOrMail" search using the mock driver. * * Copyright 2008-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Integration_SearchguidforuidormailTest extends Horde_Kolab_Server_LdapTestCase { public function setUp() { $this->skipIfNoLdap(); $connection = new Horde_Kolab_Server_Connection_Mock( new Horde_Kolab_Server_Connection_Mock_Ldap( array('basedn' => 'dc=test'), array( 'dn=user,dc=test' => array( 'dn' => 'dn=user,dc=test', 'data' => array( 'uid' => array('user'), 'mail' => array('user@example.org'), 'objectClass' => array('top', 'kolabInetOrgPerson'), ) ) ) ) ); $this->composite = new Horde_Kolab_Server_Composite( new Horde_Kolab_Server_Ldap_Standard( $connection, 'dc=test' ), new Horde_Kolab_Server_Objects_Base(), new Horde_Kolab_Server_Structure_Kolab(), new Horde_Kolab_Server_Search_Base(), new Horde_Kolab_Server_Schema_Base() ); $this->composite->server->connectGuid(); } public function testSearchingForUnknownUserReturnsEmptyGuid() { $this->composite->search->searchGuidForUidOrMail('unknown'); } public function testSearchingForUserByMailReturnsTheGuid() { $this->assertEquals( 'dn=user,dc=test', $this->composite->search->searchGuidForUidOrMail('user@example.org') ); } public function testSearchingForUserByUidReturnsTheGuid() { $this->assertEquals( 'dn=user,dc=test', $this->composite->search->searchGuidForUidOrMail('user') ); } } Horde_Kolab_Server-2.0.5/test/Horde/Kolab/Server/Integration/SearchTest.php0000664000175000017500000002201012653735542024707 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * Require our basic test case definition */ require_once __DIR__ . '/../LdapTestCase.php'; /** * Test the search handler. * * Copyright 2008-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Integration_SearchTest extends Horde_Kolab_Server_LdapTestCase { public function setUp() { /* $injector = new Horde_Injector(new Horde_Injector_TopLevel()); */ /* Horde_Kolab_Server_Factory::setup(array(), $injector); */ /* $this->server = $injector->getInstance('Horde_Kolab_Server'); */ } public function testNothing() { } /** * Test retrieving a primary mail for a mail or uid. * * @return NULL */ /* public function testMailForUidOrMail() */ /* { */ /* $ldap = $this->getMock('Horde_Kolab_Server_ldap', array('getAttributes', */ /* 'search', 'count', */ /* 'firstEntry')); */ /* $ldap->expects($this->any()) */ /* ->method('_getAttributes') */ /* ->will($this->returnValue(array ( */ /* 'mail' => */ /* array ( */ /* 'count' => 1, */ /* 0 => 'wrobel@example.org', */ /* ), */ /* 0 => 'mail', */ /* 'count' => 1))); */ /* $ldap->expects($this->any()) */ /* ->method('_search') */ /* ->will($this->returnValue('cn=Gunnar Wrobel,dc=example,dc=org')); */ /* $ldap->expects($this->any()) */ /* ->method('_count') */ /* ->will($this->returnValue(1)); */ /* $ldap->expects($this->any()) */ /* ->method('_firstEntry') */ /* ->will($this->returnValue(1)); */ /* $mail = $ldap->mailForIdOrMail('wrobel'); */ /* $this->assertEquals('wrobel@example.org', $mail); */ /* $ldap = $this->getMock('Horde_Kolab_Server_ldap', array('_getAttributes', */ /* '_search', */ /* '_count', */ /* '_firstEntry', */ /* '_errno', */ /* '_error')); */ /* $ldap->expects($this->any()) */ /* ->method('_getAttributes') */ /* ->will($this->returnValue(false)); */ /* $ldap->expects($this->any()) */ /* ->method('_search') */ /* ->will($this->returnValue('cn=Gunnar Wrobel,dc=example,dc=org')); */ /* $ldap->expects($this->any()) */ /* ->method('_count') */ /* ->will($this->returnValue(1)); */ /* $ldap->expects($this->any()) */ /* ->method('_firstEntry') */ /* ->will($this->returnValue(1)); */ /* $ldap->expects($this->any()) */ /* ->method('_errno') */ /* ->will($this->returnValue(1)); */ /* $ldap->expects($this->any()) */ /* ->method('_error') */ /* ->will($this->returnValue('cn=DOES NOT EXIST,dc=example,dc=org: No such object')); */ /* $mail = $ldap->mailForIdOrMail('wrobel'); */ /* $this->assertEquals('Retrieving attributes failed. Error was: cn=DOES NOT EXIST,dc=example,dc=org: No such object', */ /* $mail->message); */ /* $ldap = $this->getMock('Horde_Kolab_Server_ldap', array('_getAttributes', */ /* '_search', */ /* '_count')); */ /* $ldap->expects($this->any()) */ /* ->method('_getAttributes') */ /* ->will($this->returnValue(false)); */ /* $ldap->expects($this->any()) */ /* ->method('_search') */ /* ->will($this->returnValue('cn=Gunnar Wrobel,dc=example,dc=org')); */ /* $ldap->expects($this->any()) */ /* ->method('_count') */ /* ->will($this->returnValue(4)); */ /* $mail = $ldap->mailForIdOrMail('wrobel'); */ /* $this->assertEquals('Found 4 results when expecting only one!', */ /* $mail->message); */ /* } */ /* /\** */ /* * Test retrieving a DN for a mail or uid. */ /* * */ /* * @return NULL */ /* *\/ */ /* public function testDnForUidOrMail() */ /* { */ /* $ldap = $this->getMock('Horde_Kolab_Server_ldap', array('_getDn', */ /* '_search', '_count', */ /* '_firstEntry')); */ /* $ldap->expects($this->any()) */ /* ->method('_getDn') */ /* ->will($this->returnValue('cn=Gunnar Wrobel,dc=example,dc=org')); */ /* $ldap->expects($this->any()) */ /* ->method('_search') */ /* ->will($this->returnValue('cn=Gunnar Wrobel,dc=example,dc=org')); */ /* $ldap->expects($this->any()) */ /* ->method('_count') */ /* ->will($this->returnValue(1)); */ /* $ldap->expects($this->any()) */ /* ->method('_firstEntry') */ /* ->will($this->returnValue(1)); */ /* $dn = $ldap->uidForIdOrMail('wrobel'); */ /* $this->assertEquals('cn=Gunnar Wrobel,dc=example,dc=org', $dn); */ /* $ldap = $this->getMock('Horde_Kolab_Server_ldap', array('_getDn', */ /* '_search', */ /* '_count', */ /* '_firstEntry', */ /* '_errno', */ /* '_error')); */ /* $ldap->expects($this->any()) */ /* ->method('_getDn') */ /* ->will($this->returnValue(false)); */ /* $ldap->expects($this->any()) */ /* ->method('_search') */ /* ->will($this->returnValue('cn=Gunnar Wrobel,dc=example,dc=org')); */ /* $ldap->expects($this->any()) */ /* ->method('_count') */ /* ->will($this->returnValue(1)); */ /* $ldap->expects($this->any()) */ /* ->method('_firstEntry') */ /* ->will($this->returnValue(1)); */ /* $ldap->expects($this->any()) */ /* ->method('_errno') */ /* ->will($this->returnValue(1)); */ /* $ldap->expects($this->any()) */ /* ->method('_error') */ /* ->will($this->returnValue('cn=DOES NOT EXIST,dc=example,dc=org: No such object')); */ /* $dn = $ldap->uidForIdOrMail('wrobel'); */ /* $this->assertEquals('Retrieving DN failed. Error was: cn=DOES NOT EXIST,dc=example,dc=org: No such object', */ /* $dn->message); */ /* $ldap = $this->getMock('Horde_Kolab_Server_ldap', array('_getDn', */ /* '_search', */ /* '_count')); */ /* $ldap->expects($this->any()) */ /* ->method('_getDn') */ /* ->will($this->returnValue(false)); */ /* $ldap->expects($this->any()) */ /* ->method('_search') */ /* ->will($this->returnValue('cn=Gunnar Wrobel,dc=example,dc=org')); */ /* $ldap->expects($this->any()) */ /* ->method('_count') */ /* ->will($this->returnValue(4)); */ /* $dn = $ldap->uidForIdOrMail('wrobel'); */ /* $this->assertEquals('Found 4 results when expecting only one!', */ /* $dn->message); */ /* } */ } class Search_Mock { public function __construct($result, $limit = false) { $this->result = $result; $this->limit = $limit; } public function asArray() { return $this->result; } public function sizeLimitExceeded() { return $this->limit; } }Horde_Kolab_Server-2.0.5/test/Horde/Kolab/Server/Integration/UserHandlingTestTodo.php0000664000175000017500000005522312653735542026727 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * Require our basic test case definition */ require_once __DIR__ . '/Scenario.php'; /** * Handling users. * * Copyright 2008-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Integration_UserHandlingTest extends Horde_Kolab_Server_Integration_Scenario { /** * Test listing userss if there are no users. * * @scenario * * @return NULL */ public function listingUsersOnEmptyServer() { $this->given('several Kolab servers') ->when('listing all users') ->then('the list is an empty array'); } /** * Test listing users after adding some users. * * @param array $user_list The users to add. * * @scenario * @dataProvider userLists * * @return NULL */ public function listingUsersAfterAddingUsers($user_list) { $this->given('several Kolab servers') ->when('adding an object list', $user_list) ->and('listing all users') ->then('the list has a number of entries equal to', count($user_list)); } /** * Test listing users after adding some users. * * @param array $user_list The users to add. * * @scenario * @dataProvider userLists * * @return NULL */ public function listingUserCount($user_list) { $this->given('several Kolab servers') ->when('adding an object list', $user_list) ->and('retriving the result count') ->then('the count equals to', count($user_list)); } /** * Test the list of users for the user id. * * @param array $user_list The users to add. * * @scenario * @dataProvider userLists * * @return NULL */ public function listingUsersHasAttributeId($user_list) { $this->given('several Kolab servers') ->when('adding a user list', $user_list) ->then('the user list contains the unique ID for each user') ->and('the user list contains the user type for each user'); } /** * Test the list of users for the user type. * * @param array $user_list The users to add. * * @scenario * @dataProvider userLists * * @return NULL */ public function listingUsersHasAttributeType($user_list) { $this->given('several Kolab servers') ->when('adding a user list', $user_list) ->then('the user list contains the user type for each user'); } /** * Test the list of users for the user full name. * * @param array $user_list The users to add. * * @scenario * @dataProvider userLists * * @return NULL */ public function listingUsersHasAttributeFullName($user_list) { $this->given('several Kolab servers') ->when('adding a user list', $user_list) ->then('the user list contains the full name for each user'); } /** * Test the list of users for the user mail. * * @param array $user_list The users to add. * * @scenario * @dataProvider userLists * * @return NULL */ public function listingUsersHasAttributeEmail($user_list) { $this->given('several Kolab servers') ->when('adding a user list', $user_list) ->then('the user list contains the email for each user'); } /** * Test the list of users for the user uid. * * @param array $user_list The users to add. * * @scenario * @dataProvider userLists * * @return NULL */ public function listingUsersHasAttributeUid($user_list) { $this->given('several Kolab servers') ->when('adding a user list', $user_list) ->then('the list contains the uid for each user'); } /** * @scenario * @dataProvider userListByLetter */ public function listingUsersCanBeRestrictedByStartLetterOfTheLastName($letter, $count) { $this->given('several Kolab servers') ->when('adding user list', $this->largeList()) ->and('retrieving the result count of a list restricted by the start letter of the last name', $letter) ->then('the list contains a correct amount of results', $count); } /** * @scenario * @dataProvider userListByLetter */ public function countingUsersCanBeRestrictedByStartLetterOfTheLastName($letter, $count) { $this->given('several Kolab servers') ->when('adding user list', $this->largeList()) ->and('retrieving the result count of a list restricted by the start letter of the last name', $letter) ->then('the count contains a correct number', $count); } /** * @scenario * @dataProvider userListByAttribute */ public function countingUsersCanBeRestrictedByContentsInAnAttribute($attribute, $content, $count) { $this->given('several Kolab servers') ->when('adding user list', $this->largeList()) ->and('retrieving the result count of a list restricted by content in an attribute', $attribute, $content) ->then('the count contains a correct number', $count); } /** * @scenario */ public function creatingUserWithoutTypeCreatesStandardUser() { $this->given('several Kolab servers') ->when('adding a user without user type') ->then('a standard user has been created'); } /** * @scenario */ public function creatingUserWithoutInvitationPolicySetsManualPolicy() { $this->given('several Kolab servers') ->when('adding a user without an invitation policy') ->then('the added user has a manual policy'); } /** * @scenario */ public function creatingUserWithoutHomeServerFails() { $this->given('several Kolab servers') ->when('adding a user without a home server') ->then('the result should indicate an error with', 'The user cannot be added: The home Kolab server (or network) has not been specified!'); } /** * @scenario */ public function creatingUserForDistributedKolabWithoutImapServerFails() { $this->given('several Kolab servers') ->and('distributed Kolab') ->when('adding a user without an imap server') ->then('the result should indicate an error with', 'The user cannot be added: The home imap server has not been specified!'); } /** * @scenario */ public function creatingUserWithImapServerFailsOnNonDistributedKolab() { $this->given('several Kolab servers') ->and('monolithic Kolab') ->when('adding a user with an imap server') ->then('the result should indicate an error with', 'The user cannot be added: A home imap server is only supported with a distributed Kolab setup!'); } /** * @scenario */ public function creatingUserWithFreeBusyServerFailsOnNonDistributedKolab() { $this->given('several Kolab servers') ->and('monolithic Kolab') ->when('adding a user with a free/busy server') ->then('the result should indicate an error with', 'The user cannot be added: A seperate free/busy server is only supported with a distributed Kolab setup!'); } /** * @scenario */ public function modifyingUserMailAddressIsNotAllowed() { $this->given('several Kolab servers') ->when('adding a user with the mail address "test@example.org"') ->and('modifying the mail address to "new@example.org"') ->then('the result should indicate an error with', 'The user cannot be modified: Changing the mail address from "test@example.org" to "new@example.org" is not allowed!'); } /** * @scenario */ public function modifyingUserHomeServerIsNotAllowd() { $this->given('several Kolab servers') ->when('adding a user with the home server "test.example.org"') ->and('modifying the home server to "new.example.org"') ->then('the result should indicate an error with', 'The user cannot be modified: Changing the home server from "test.example.org" to "new.example.org" is not allowed!'); } /** * @scenario */ public function modifyingUserImapServerIsNotAllowd() { $this->given('several Kolab servers') ->and('distributed Kolab') ->when('adding a user with the imap server "test.example.org"') ->and('modifying the imap server to "new.example.org"') ->then('the result should indicate an error with', 'The user cannot be modified: Changing the imap server from "test.example.org" to "new.example.org" is not allowed!'); } /** * @scenario */ public function conflictBetweenMailAndMailIsNotAllowed() { $this->given('several Kolab servers') ->when('adding a user "Test Test" with the mail address "test@example.org"') ->and('adding a user "Test2 Test2" with the mail address "test@example.org"') ->then('the result should indicate an error with', 'The user cannot be added: Mail address "test@example.org" is already the mail address of user "Test Test"!'); } /** * @scenario */ public function conflictBetweenMailAndAliasIsNotAllowed() { $this->given('several Kolab servers') ->when('adding a user "Test Test" with the mail address "test@example.org"') ->and('adding a user with the alias address "test@example.org"') ->then('the result should indicate an error with', 'The user cannot be added: Alias address "test@example.org" is already the mail address of user "Test Test"!'); } /** * @scenario */ public function conflictBetweenAliasAndAliasIsNotAllowed() { $this->given('several Kolab servers') ->when('adding a user "Test Test" with the alias address "test@example.org"') ->and('adding a user with the alias address "test@example.org"') ->then('the result should indicate an error with', 'The user cannot be added: Alias address "test@example.org" is already the alias address of user "Test Test"!'); } /** * @scenario */ public function conflictBetweenMailAndUidIsNotAllowed() { $this->given('several Kolab servers') ->when('adding a user "Test Test" with the mail address "test@example.org"') ->and('adding a user with the uid "test@example.org"') ->then('the result should indicate an error with', 'The user cannot be added: Uid "test@example.org" is already the mail address of user "Test Test"!'); } /** * @scenario */ public function conflictBetweenUidAndUidIsNotAllowed() { $this->given('several Kolab servers') ->when('adding a user "Test Test" with the uid "test"') ->and('adding a user with the uid "test"') ->then('the result should indicate an error with', 'The user cannot be added: Uid "test" is already the uid of user "Test Test"!'); } /** * @scenario */ public function nonExistingDelegateIsNotAllowed() { $this->given('several Kolab servers') ->when('adding a user with the delegate address "test@example.org"') ->then('the result should indicate an error with', 'The user cannot be added: Delegate address "test@example.org" does not exist!'); } /** * @scenario */ public function addingUserInUndefinedDomainIsNotAllowed() { $this->given('several Kolab servers') ->and('the only served mail domain is "example.org"') ->when('adding a user with the mail address "test@doesnotexist.org"') ->then('the result should indicate an error with', 'The user cannot be added: Domain "doesnotexist.org" is not being handled by this server!'); } /** * kolab/issue444 (a kolab user may delegate to an external user which should not be possible) * * @scenario */ public function addingUserWithDelegateInUndefinedDomainIsNotAllowed() { $this->given('several Kolab servers') ->and('the only served mail domain is "example.org"') ->when('adding a user with the delegate mail address "test@doesnotexist.org"') ->then('the result should indicate an error with', 'The user cannot be added: Domain "doesnotexist.org" is not being handled by this server!'); } /** * kolab/issue1368 (Webinterface allows to create email addresses with slash that cyrus cannot handle) * * @scenario * @dataProvider invalidMails */ public function disallowInvalidMailAddresses($address) { $this->given('several Kolab servers') ->when('adding a user with an invalid mail address', $address) ->then('the result should indicate an error with', "The user cannot be added: Address \"$address\" is not a valid mail address!"); } /** * @scenario */ public function addingUserOnUndefinedHomeServer() { $this->given('several Kolab servers') ->and('the only home server in the network is "example.org"') ->when('adding a user with the home server "doesnotexist.org"') ->then('the result should indicate an error with', 'The user cannot be added: Host "doesnotexist.org" is not part of the Kolab network!'); } /** * @scenario */ public function addingUserOnUndefinedImapServer() { $this->given('several Kolab servers') ->and('distributed Kolab') ->and('the only imap server in the network is "example.org"') ->when('adding a user with the imap server "doesnotexist.org"') ->then('the result should indicate an error with', 'The user cannot be added: Imap server "doesnotexist.org" is not part of the Kolab network!'); } /** * @scenario */ public function userAttributesCanBeExtended() { $this->given('several Kolab servers') ->and('an extended attribute "test" has been defined') ->when('adding a user with the attribute "test" set to "FIND ME"') ->then('the result indicates success') ->and('the user can be found using the "test" attribute with the value "FIND ME"'); } /** * @scenario */ public function extendedObjectAttributeDescriptionsCanBeRetrieved() { $this->given('several Kolab servers') ->and('an extended attribute "test" has been defined') ->when('retrieving the supported attributes by the object type "user"') ->then('the result is an array of Horde attribute descriptions') ->and('contains the description of "test"'); } /** * @scenario */ public function removingUserFailsIfUserDoesNotExist() { $this->given('several Kolab servers') ->when('adding a user with the ID "cn=Test Test"') ->and('deleting the user with the ID "cn=Dummy Dummy"') ->then('the result should indicate an error with', 'The user cannot be deleted: User "cn=Dummy Dummy" does not exist!'); } /** * @scenario */ public function removingUserByMailSucceeds() { $this->given('several Kolab servers') ->when('adding a user with the mail address "test@example.org"') ->and('deleting the user with mail address "test@example.org"') ->then('the result indicates success') ->and('listing all users returns an empty list'); } /** * @scenario */ public function removingUserByIdSucceeds() { $this->given('several Kolab servers') ->when('adding a user with the ID "cn=Test Test"') ->and('deleting the user with the ID "cn=Test Test"') ->then('the result indicates success') ->and('listing all users returns an empty list'); } /** * @scenario */ public function addedUserCanLogin() { $this->given('several Kolab servers') ->and('Horde uses the Kolab auth driver') ->when('adding a user with the mail address "test@example.org" and password "test"') ->and('trying to login to Horde with "test@example.org" and passowrd "test"') ->then('the result indicates success') ->and('the session shows "test@example.org" as the current user'); } /** * @scenario */ public function allowUserWithExtendedObjectClasses() { $this->given('several Kolab servers') ->and('an extended set of objectclasses') ->when('adding a user with the mail address "test@example.org"') ->and('fetching user "test@example.org"') ->then('has the additional object classes set'); } /** * @scenario */ public function allowToCheckUserPasswords() { $this->given('several Kolab servers') ->and('password check enabled') ->when('adding a user with the mail address "test@example.org" and password "tosimple"') ->then('the result should indicate an error with', 'The user cannot be added: The chosen password is not complex enough!'); } /** * @scenario */ public function allowToSetAttributeDefaults() { $this->given('several Kolab servers') ->and('an extended attribute "test" with the default value "test" has been defined') ->when('adding a user with the mail address "test@example.org" and an empty attribute "test"') ->and('fetching user "test@example.org"') ->then('the user object has the attribute "test" set to "test"'); } /** * kolab/issue2742 (Have a default quota value when creating new users via the web interface) * * @scenario */ public function allowToSetDomainSpecificAttributeDefaults() { $this->given('several Kolab servers') ->and('domain "example.org" is served by the Kolab server') ->and('domain "example2.org" is served by the Kolab server') ->and('an extended attribute "test" with the default value "test" has been defined') ->and('an extended attribute "test" with the default value "test2" has been defined for domain example2.org') ->when('adding a user with the mail address "test@example.org" and an empty attribute "test"') ->and('adding a user with the mail address "test@example2.org" and an empty attribute "test"') ->and('fetching user "test@example.org" and "test@example2.org"') ->then('the user "test@example.org" has the attribute "test" set to "test"') ->and('the user "test@example2.org" has the attribute "test" set to "test2"'); } /** * kolab/issue3035 (Initialise internal Horde parameters when creating a user) * * @scenario * @dataProvider userAdd */ public function addedUserHasPreferencesInitialized() { $this->given('several Kolab servers') ->and('Horde uses the Kolab auth driver') ->when('adding a user', $user) ->and('trying to login to Horde with "test@example.org" and passowrd "test"') ->then('the preferences are automatically set to the user information', $user); } /** * kolab/issue1189 (IMAP login fails on some specific uids) * * @scenario */ public function userUidsShouldNotResembleTheLocalPartOfMailAddresses() { $this->given('several Kolab servers') ->when('adding a user "cn=Test Test" with the mail address "test@example.org"') ->and('adding a user with the uid "test"') ->then('the result should indicate an error with', 'The user cannot be added: The uid "test" matches the local part of the mail address "test@example.org" assigned to user "cn=Test Test"!'); } /** * kolab/issue606 (It is not possible to register people with middlename correctly) * * @scenario */ public function allowToSetTheMiddleName() { $this->given('several Kolab servers') ->and('an extended attribute "middleName" has been defined') ->when('adding a user with the mail address "test@example.org" and the middle name "Middle"') ->and('fetching user "test@example.org"') ->then('the user object has the attribute "middleName" set to "Middle"'); } /** * kolab/issue1880 (Poor handling of apostrophes in ldap and admin webpages) * * @scenario */ public function correctlyEscapeApostrophesInNames() { $this->given('several Kolab servers') ->when('adding a user with the mail address "test@example.org" and the last name "O\'Donnell"') ->and('fetching user "test@example.org"') ->then('the user name has the attribute "sn" set to "O\'Donnell"'); } /** * kolab/issue1677 (Allow a user to use an external address as sender) * * @scenario */ public function allowUserToUseExternalAddressAsSender() { $this->given('several Kolab servers') ->when('adding a user with the mail address "test@example.org" and the external address "other@doesnotexist.org"') ->and('fetching user "test@example.org"') ->then('the user has the attribute external address "other@doesnotexist.org"'); } /** * kolab/issue3036 (cn = "givenName sn" ?) * * @scenario */ public function allowCustomFullnameHandling() { $this->given('several Kolab servers') ->and('an extended attribute "middleName" has been defined') ->and('custom full name handling has been set to "lastname, firstname middlename"') ->when('adding a user with the mail address "test@example.org", the last name "Test", the first name "Test", and the middle name "Middle"') ->and('fetching user "test@example.org"') ->then('the user has the attribute full name "Test, Test Middle"'); } } Horde_Kolab_Server-2.0.5/test/Horde/Kolab/Server/Integration/UserTest.php0000664000175000017500000000621212653735542024426 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * Require our basic test case definition */ require_once __DIR__ . '/Scenario.php'; /** * Test the user object. * * Copyright 2008-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_Integration_UserTest extends Horde_Kolab_Server_Integration_Scenario { /** * Set up testing. * * @return NULL */ protected function setUp() { parent::setUp(); $this->server = $this->getKolabMockServer(); $users = $this->validUsers(); foreach ($users as $user) { $result = $this->server->add($user[0]); } } /** * Test ID generation for a user. * * @return NULL */ public function testGenerateId() { $users = $this->validUsers(); $user = new Horde_Kolab_Server_Object_Kolab_User($this->server, null, $users[0][0]); $this->assertNoError($user); $this->assertEquals('cn=Gunnar Wrobel,dc=example,dc=org', $user->get(Horde_Kolab_Server_Object::ATTRIBUTE_UID)); } /** * Test adding invalid user. * * @expectedException Horde_Kolab_Server_Exception * * @return NULL */ public function testAddInvalidUser() { $user = $this->provideInvalidUserWithoutGivenName(); $result = $this->server->add($user); } /** * Test fetching a user. * * @return NULL */ public function testFetchUser() { $user = $this->server->fetch('cn=Gunnar Wrobel,dc=example,dc=org'); $this->assertEquals('Horde_Kolab_Server_Object_Kolab_User', get_class($user)); $this->assertEquals('Gunnar Wrobel', $user->get(Horde_Kolab_Server_Object_Kolab_User::ATTRIBUTE_FNLN)); } /** * Test fetching server information. * * @return NULL */ public function testGetServer() { $user = $this->server->fetch('cn=Gunnar Wrobel,dc=example,dc=org'); $imap = $user->getServer('imap'); $this->assertEquals('imap.example.org', $imap); $user = $this->server->fetch('cn=Test Test,dc=example,dc=org'); $imap = $user->getServer('imap'); $this->assertEquals('home.example.org', $imap); $user = $this->server->fetch('cn=Gunnar Wrobel,dc=example,dc=org'); $attr = $user->get(Horde_Kolab_Server_Object_Kolab_User::ATTRIBUTE_FREEBUSYHOST); $this->assertEquals('https://fb.example.org/freebusy', $attr); $imap = $user->getServer('freebusy'); $this->assertEquals('https://fb.example.org/freebusy', $imap); } } Horde_Kolab_Server-2.0.5/test/Horde/Kolab/Server/AllTests.php0000664000175000017500000000013212653735542022113 0ustar janjanrun(); Horde_Kolab_Server-2.0.5/test/Horde/Kolab/Server/bootstrap.php0000664000175000017500000000014312653735542022377 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * Prepare the test setup. */ require_once __DIR__ . '/TestCase.php'; /** * Skip LDAP based tests if we don't have ldap or Horde_Ldap. * * Copyright 2009-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_LdapTestCase extends Horde_Kolab_Server_TestCase { public function skipIfNoLdap() { if (!extension_loaded('ldap') && !@dl('ldap.' . PHP_SHLIB_SUFFIX)) { $this->markTestSkipped('Ldap extension is missing!'); }; if (!class_exists('Horde_Ldap')) { $this->markTestSkipped('Horde_Ldap is not installed!'); } } }Horde_Kolab_Server-2.0.5/test/Horde/Kolab/Server/phpunit.xml0000664000175000017500000000031112653735542022057 0ustar janjan ../../../../lib Horde_Kolab_Server-2.0.5/test/Horde/Kolab/Server/TestCase.php0000664000175000017500000000503312653735542022100 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ /** * Prepare the test setup. */ require_once __DIR__ . '/Constraints/Restrictkolabusers.php'; require_once __DIR__ . '/Constraints/Restrictgroups.php'; require_once __DIR__ . '/Constraints/Searchuid.php'; require_once __DIR__ . '/Constraints/Searchmail.php'; require_once __DIR__ . '/Constraints/Searchcn.php'; require_once __DIR__ . '/Constraints/Searchalias.php'; /** * Provides functions required by several Kolab_Server tests. * * Copyright 2009-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Server * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Kolab_Server */ class Horde_Kolab_Server_TestCase extends PHPUnit_Framework_TestCase { protected function getComposite() { return $this->getMock( 'Horde_Kolab_Server_Composite', array(), array(), '', false, false ); } protected function getMockedComposite() { return new Horde_Kolab_Server_Composite( $this->getMock('Horde_Kolab_Server_Interface'), $this->getMock('Horde_Kolab_Server_Objects_Interface'), $this->getMock('Horde_Kolab_Server_Structure_Interface'), $this->getMock('Horde_Kolab_Server_Search_Interface'), $this->getMock('Horde_Kolab_Server_Schema_Interface') ); } public function isRestrictedToGroups() { return new Horde_Kolab_Server_Constraint_Restrictgroups(); } public function isRestrictedToKolabUsers() { return new Horde_Kolab_Server_Constraint_Restrictedkolabusers(); } public function isSearchingByUid() { return new Horde_Kolab_Server_Constraint_Searchuid(); } public function isSearchingByMail() { return new Horde_Kolab_Server_Constraint_Searchmail(); } public function isSearchingByCn() { return new Horde_Kolab_Server_Constraint_Searchcn(); } public function isSearchingByAlias() { return new Horde_Kolab_Server_Constraint_Searchcn(); } }