From ee3fe367a97bbe65094fa195565cc87e7c0a5138 Mon Sep 17 00:00:00 2001 From: thomas Date: Tue, 28 Apr 2009 10:23:49 +0000 Subject: [PATCH 01/61] [DOCUMENTATION] English: - fixed title tags git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@15234 44c647ce-9c0f-0410-b52a-842ac1e357ba --- .coveralls.yml | 3 + .gitattributes | 6 ++ .gitignore | 14 +++ .php_cs | 43 +++++++++ .travis.yml | 35 +++++++ CONTRIBUTING.md | 229 +++++++++++++++++++++++++++++++++++++++++++++ LICENSE.txt | 27 ++++++ README.md | 8 ++ composer.json | 51 ++++++++++ phpunit.xml.dist | 49 ++++++++++ phpunit.xml.travis | 51 ++++++++++ test/bootstrap.php | 34 +++++++ 12 files changed, 550 insertions(+) create mode 100644 .coveralls.yml create mode 100644 .gitattributes create mode 100644 .gitignore create mode 100644 .php_cs create mode 100644 .travis.yml create mode 100644 CONTRIBUTING.md create mode 100644 LICENSE.txt create mode 100644 README.md create mode 100644 composer.json create mode 100644 phpunit.xml.dist create mode 100644 phpunit.xml.travis create mode 100644 test/bootstrap.php diff --git a/.coveralls.yml b/.coveralls.yml new file mode 100644 index 0000000..53bda82 --- /dev/null +++ b/.coveralls.yml @@ -0,0 +1,3 @@ +coverage_clover: clover.xml +json_path: coveralls-upload.json +src_dir: src diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..85dc9a8 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,6 @@ +/test export-ignore +/vendor export-ignore +.gitattributes export-ignore +.gitignore export-ignore +.travis.yml export-ignore +.php_cs export-ignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4cac0a2 --- /dev/null +++ b/.gitignore @@ -0,0 +1,14 @@ +.buildpath +.DS_Store +.idea +.project +.settings/ +.*.sw* +.*.un~ +nbproject +tmp/ + +clover.xml +coveralls-upload.json +phpunit.xml +vendor diff --git a/.php_cs b/.php_cs new file mode 100644 index 0000000..bf4b799 --- /dev/null +++ b/.php_cs @@ -0,0 +1,43 @@ +notPath('TestAsset') + ->notPath('_files') + ->filter(function (SplFileInfo $file) { + if (strstr($file->getPath(), 'compatibility')) { + return false; + } + }); +$config = Symfony\CS\Config\Config::create(); +$config->level(null); +$config->fixers( + array( + 'braces', + 'duplicate_semicolon', + 'elseif', + 'empty_return', + 'encoding', + 'eof_ending', + 'function_call_space', + 'function_declaration', + 'indentation', + 'join_function', + 'line_after_namespace', + 'linefeed', + 'lowercase_keywords', + 'parenthesis', + 'multiple_use', + 'method_argument_space', + 'object_operator', + 'php_closing_tag', + 'psr0', + 'remove_lines_between_uses', + 'short_tag', + 'standardize_not_equal', + 'trailing_spaces', + 'unused_use', + 'visibility', + 'whitespacy_lines', + ) +); +$config->finder($finder); +return $config; diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..fe909ec --- /dev/null +++ b/.travis.yml @@ -0,0 +1,35 @@ +sudo: false + +language: php + +matrix: + fast_finish: true + include: + - php: 5.5 + - php: 5.6 + env: + - EXECUTE_TEST_COVERALLS=true + - EXECUTE_CS_CHECK=true + - php: 7 + - php: hhvm + allow_failures: + - php: 7 + - php: hhvm + +notifications: + irc: "irc.freenode.org#zftalk.dev" + email: false + +before_install: + - if [[ $EXECUTE_TEST_COVERALLS != 'true' ]]; then phpenv config-rm xdebug.ini || return 0 ; fi + +install: + - composer install --no-interaction --prefer-source + +script: + - if [[ $EXECUTE_TEST_COVERALLS == 'true' ]]; then ./vendor/bin/phpunit -c phpunit.xml.travis --coverage-clover clover.xml ; fi + - if [[ $EXECUTE_TEST_COVERALLS != 'true' ]]; then ./vendor/bin/phpunit -c phpunit.xml.travis ; fi + - if [[ $EXECUTE_CS_CHECK == 'true' ]]; then ./vendor/bin/php-cs-fixer fix -v --diff --dry-run --config-file=.php_cs ; fi + +after_script: + - if [[ $EXECUTE_TEST_COVERALLS == 'true' ]]; then ./vendor/bin/coveralls ; fi diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..bea815d --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,229 @@ +# CONTRIBUTING + +## RESOURCES + +If you wish to contribute to Zend Framework, please be sure to +read/subscribe to the following resources: + + - [Coding Standards](https://github.com/zendframework/zf2/wiki/Coding-Standards) + - [Contributor's Guide](http://framework.zend.com/participate/contributor-guide) + - ZF Contributor's mailing list: + Archives: http://zend-framework-community.634137.n4.nabble.com/ZF-Contributor-f680267.html + Subscribe: zf-contributors-subscribe@lists.zend.com + - ZF Contributor's IRC channel: + #zftalk.dev on Freenode.net + +If you are working on new features or refactoring [create a proposal](https://github.com/zendframework/zend-authentication/issues/new). + +## Reporting Potential Security Issues + +If you have encountered a potential security vulnerability, please **DO NOT** report it on the public +issue tracker: send it to us at [zf-security@zend.com](mailto:zf-security@zend.com) instead. +We will work with you to verify the vulnerability and patch it as soon as possible. + +When reporting issues, please provide the following information: + +- Component(s) affected +- A description indicating how to reproduce the issue +- A summary of the security vulnerability and impact + +We request that you contact us via the email address above and give the project +contributors a chance to resolve the vulnerability and issue a new release prior +to any public exposure; this helps protect users and provides them with a chance +to upgrade and/or update in order to protect their applications. + +For sensitive email communications, please use [our PGP key](http://framework.zend.com/zf-security-pgp-key.asc). + +## RUNNING TESTS + +> ### Note: testing versions prior to 2.4 +> +> This component originates with Zend Framework 2. During the lifetime of ZF2, +> testing infrastructure migrated from PHPUnit 3 to PHPUnit 4. In most cases, no +> changes were necessary. However, due to the migration, tests may not run on +> versions < 2.4. As such, you may need to change the PHPUnit dependency if +> attempting a fix on such a version. + +To run tests: + +- Clone the repository: + + ```console + $ git clone git@github.com:zendframework/zend-authentication.git + $ cd + ``` + +- Install dependencies via composer: + + ```console + $ curl -sS https://getcomposer.org/installer | php -- + $ ./composer.phar install + ``` + + If you don't have `curl` installed, you can also download `composer.phar` from https://getcomposer.org/ + +- Run the tests via `phpunit` and the provided PHPUnit config, like in this example: + + ```console + $ ./vendor/bin/phpunit + ``` + +You can turn on conditional tests with the phpunit.xml file. +To do so: + + - Copy `phpunit.xml.dist` file to `phpunit.xml` + - Edit `phpunit.xml` to enable any specific functionality you + want to test, as well as to provide test values to utilize. + +## Running Coding Standards Checks + +This component uses [php-cs-fixer](http://cs.sensiolabs.org/) for coding +standards checks, and provides configuration for our selected checks. +`php-cs-fixer` is installed by default via Composer. + +To run checks only: + +```console +$ ./vendor/bin/php-cs-fixer fix . -v --diff --dry-run --config-file=.php_cs +``` + +To have `php-cs-fixer` attempt to fix problems for you, omit the `--dry-run` +flag: + +```console +$ ./vendor/bin/php-cs-fixer fix . -v --diff --config-file=.php_cs +``` + +If you allow php-cs-fixer to fix CS issues, please re-run the tests to ensure +they pass, and make sure you add and commit the changes after verification. + +## Recommended Workflow for Contributions + +Your first step is to establish a public repository from which we can +pull your work into the master repository. We recommend using +[GitHub](https://github.com), as that is where the component is already hosted. + +1. Setup a [GitHub account](http://github.com/), if you haven't yet +2. Fork the repository (http://github.com/zendframework/zend-authentication) +3. Clone the canonical repository locally and enter it. + + ```console + $ git clone git://github.com:zendframework/zend-authentication.git + $ cd zend-authentication + ``` + +4. Add a remote to your fork; substitute your GitHub username in the command + below. + + ```console + $ git remote add {username} git@github.com:{username}/zend-authentication.git + $ git fetch {username} + ``` + +### Keeping Up-to-Date + +Periodically, you should update your fork or personal repository to +match the canonical ZF repository. Assuming you have setup your local repository +per the instructions above, you can do the following: + + +```console +$ git checkout master +$ git fetch origin +$ git rebase origin/master +# OPTIONALLY, to keep your remote up-to-date - +$ git push {username} master:master +``` + +If you're tracking other branches -- for example, the "develop" branch, where +new feature development occurs -- you'll want to do the same operations for that +branch; simply substitute "develop" for "master". + +### Working on a patch + +We recommend you do each new feature or bugfix in a new branch. This simplifies +the task of code review as well as the task of merging your changes into the +canonical repository. + +A typical workflow will then consist of the following: + +1. Create a new local branch based off either your master or develop branch. +2. Switch to your new local branch. (This step can be combined with the + previous step with the use of `git checkout -b`.) +3. Do some work, commit, repeat as necessary. +4. Push the local branch to your remote repository. +5. Send a pull request. + +The mechanics of this process are actually quite trivial. Below, we will +create a branch for fixing an issue in the tracker. + +```console +$ git checkout -b hotfix/9295 +Switched to a new branch 'hotfix/9295' +``` + +... do some work ... + + +```console +$ git commit +``` + +... write your log message ... + + +```console +$ git push {username} hotfix/9295:hotfix/9295 +Counting objects: 38, done. +Delta compression using up to 2 threads. +Compression objects: 100% (18/18), done. +Writing objects: 100% (20/20), 8.19KiB, done. +Total 20 (delta 12), reused 0 (delta 0) +To ssh://git@github.com/{username}/zend-authentication.git + b5583aa..4f51698 HEAD -> master +``` + +To send a pull request, you have two options. + +If using GitHub, you can do the pull request from there. Navigate to +your repository, select the branch you just created, and then select the +"Pull Request" button in the upper right. Select the user/organization +"zendframework" as the recipient. + +If using your own repository - or even if using GitHub - you can use `git +format-patch` to create a patchset for us to apply; in fact, this is +**recommended** for security-related patches. If you use `format-patch`, please +send the patches as attachments to: + +- zf-devteam@zend.com for patches without security implications +- zf-security@zend.com for security patches + +#### What branch to issue the pull request against? + +Which branch should you issue a pull request against? + +- For fixes against the stable release, issue the pull request against the + "master" branch. +- For new features, or fixes that introduce new elements to the public API (such + as new public methods or properties), issue the pull request against the + "develop" branch. + +### Branch Cleanup + +As you might imagine, if you are a frequent contributor, you'll start to +get a ton of branches both locally and on your remote. + +Once you know that your changes have been accepted to the master +repository, we suggest doing some cleanup of these branches. + +- Local branch cleanup + + ```console + $ git branch -d + ``` + +- Remote branch removal + + ```console + $ git push {username} : + ``` diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 0000000..6eab5aa --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,27 @@ +Copyright (c) 2005-2015, Zend Technologies USA, Inc. +All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + * Neither the name of Zend Technologies USA, Inc. nor the names of its + contributors may be used to endorse or promote products derived from this + software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..f26184f --- /dev/null +++ b/README.md @@ -0,0 +1,8 @@ +# zend-authentication + +The `Zend\Authentication` component provides an API for authentication and +includes concrete authentication adapters for common use case scenarios. + + +- File issues at https://github.com/zendframework/zend-authentication/issues +- Documentation is at http://framework.zend.com/manual/current/en/index.html#zend-authentication diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..f908f59 --- /dev/null +++ b/composer.json @@ -0,0 +1,51 @@ +{ + "name": "zendframework/zend-authentication", + "description": "Zend\\Authentication component", + "license": "BSD-3-Clause", + "keywords": [ + "zf2", + "authentication" + ], + "homepage": "https://github.com/zendframework/zend-authentication", + "autoload": { + "psr-4": { + "Zend\\Authentication\\": "src/" + } + }, + "require": { + "php": ">=5.3.23", + "zendframework/zend-stdlib": "self.version" + }, + "require-dev": { + "zendframework/zend-db": "self.version", + "zendframework/zend-crypt": "self.version", + "zendframework/zend-http": "self.version", + "zendframework/zend-ldap": "self.version", + "zendframework/zend-session": "self.version", + "zendframework/zend-validator": "self.version", + "zendframework/zend-uri": "self.version", + "fabpot/php-cs-fixer": "1.7.*", + "satooshi/php-coveralls": "dev-master", + "phpunit/PHPUnit": "~4.0" + }, + "suggest": { + "zendframework/zend-db": "Zend\\Db component", + "zendframework/zend-crypt": "Zend\\Crypt component", + "zendframework/zend-http": "Zend\\Http component", + "zendframework/zend-ldap": "Zend\\Ldap component", + "zendframework/zend-session": "Zend\\Session component", + "zendframework/zend-uri": "Zend\\Uri component", + "zendframework/zend-validator": "Zend\\Validator component" + }, + "extra": { + "branch-alias": { + "dev-master": "2.4-dev", + "dev-develop": "2.5-dev" + } + }, + "autoload-dev": { + "psr-4": { + "ZendTest\\Authentication\\": "test/" + } + } +} \ No newline at end of file diff --git a/phpunit.xml.dist b/phpunit.xml.dist new file mode 100644 index 0000000..a319b49 --- /dev/null +++ b/phpunit.xml.dist @@ -0,0 +1,49 @@ + + + + + ./test/ + + + + + + disable + + + + + + ./src + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/phpunit.xml.travis b/phpunit.xml.travis new file mode 100644 index 0000000..f8dc08f --- /dev/null +++ b/phpunit.xml.travis @@ -0,0 +1,51 @@ + + + + + ./test/ + + + + + + disable + + + + + + ./src + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/bootstrap.php b/test/bootstrap.php new file mode 100644 index 0000000..51f9c3d --- /dev/null +++ b/test/bootstrap.php @@ -0,0 +1,34 @@ + Date: Fri, 26 Mar 2010 12:53:24 -0400 Subject: [PATCH 02/61] Added PHPTools submodule --- .gitmodules | 3 +++ tools/phptools | 1 + 2 files changed, 4 insertions(+) create mode 100644 .gitmodules create mode 160000 tools/phptools diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..21d57da --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "tools/phptools"] + path = tools/phptools + url = git://github.com/ralphschindler/PHPTools.git diff --git a/tools/phptools b/tools/phptools new file mode 160000 index 0000000..685f0e0 --- /dev/null +++ b/tools/phptools @@ -0,0 +1 @@ +Subproject commit 685f0e09aabbc45d82d3836aefc82be1efddb513 From 9af590523317b7f6aff90b2779b5ca6eaf211d7e Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Fri, 26 Mar 2010 13:49:44 -0400 Subject: [PATCH 03/61] Updated PHPTools --- tools/phptools | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/phptools b/tools/phptools index 685f0e0..d232cb3 160000 --- a/tools/phptools +++ b/tools/phptools @@ -1 +1 @@ -Subproject commit 685f0e09aabbc45d82d3836aefc82be1efddb513 +Subproject commit d232cb3e4f1448daccefc74882da1862cda7656f From 9e69b2be97ef981beb695db7b73f8ec23e66edff Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Tue, 20 Apr 2010 12:03:18 -0400 Subject: [PATCH 04/61] [auth] Migrated Zend_Auth to namespaces - Component renamed to Zend\Authentication - Renamed Zend_Auth to Zend\Authentication\AuthenticationService - Removed singleton - Modified several non-migrated dependencies to use code already migrated --- src/Adapter.php | 44 + src/Adapter/DbTable.php | 473 +++++++++++ src/Adapter/Digest.php | 224 +++++ src/Adapter/Exception.php | 37 + src/Adapter/HTTP.php | 793 ++++++++++++++++++ src/Adapter/HTTP/Exception.php | 39 + src/Adapter/HTTP/FileResolver.php | 143 ++++ src/Adapter/HTTP/Resolver.php | 51 ++ src/Adapter/InfoCard.php | 256 ++++++ src/Adapter/Ldap.php | 517 ++++++++++++ src/Adapter/OpenId.php | 282 +++++++ src/AuthenticationService.php | 144 ++++ src/Exception.php | 35 + src/Result.php | 152 ++++ src/Storage.php | 71 ++ src/Storage/Exception.php | 37 + src/Storage/NonPersistent.php | 93 ++ src/Storage/Session.php | 149 ++++ test/Adapter/DbTableTest.php | 367 ++++++++ test/Adapter/DigestTest.php | 246 ++++++ test/Adapter/HTTP/AuthTest.php | 470 +++++++++++ test/Adapter/HTTP/FileResolverTest.php | 247 ++++++ test/Adapter/HTTP/ObjectTest.php | 273 ++++++ test/Adapter/HTTP/ProxyTest.php | 463 ++++++++++ test/Adapter/HTTP/TestAsset/htbasic.1 | 3 + test/Adapter/HTTP/TestAsset/htdigest.3 | 2 + test/Adapter/Ldap/OfflineTest.php | 107 +++ test/Adapter/Ldap/OnlineTest.php | 209 +++++ test/Adapter/OpenIdTest.php | 505 +++++++++++ test/Adapter/TestAsset/Digest/htdigest.1 | 2 + test/Adapter/TestAsset/OpenId/.gitignore | 0 test/Adapter/TestAsset/OpenId/assoc.lock | 0 test/Adapter/TestAsset/OpenId/discovery.lock | 0 test/Adapter/TestAsset/OpenId/nonce.lock | 0 .../nonce_9f11599cc1f088b7c358f33610cb126c | 1 + .../TestAsset/OpenIdResponseHelper.php | 58 ++ test/AuthenticationServiceTest.php | 87 ++ test/TestAsset/SuccessAdapter.php | 14 + 38 files changed, 6594 insertions(+) create mode 100644 src/Adapter.php create mode 100644 src/Adapter/DbTable.php create mode 100644 src/Adapter/Digest.php create mode 100644 src/Adapter/Exception.php create mode 100644 src/Adapter/HTTP.php create mode 100644 src/Adapter/HTTP/Exception.php create mode 100644 src/Adapter/HTTP/FileResolver.php create mode 100644 src/Adapter/HTTP/Resolver.php create mode 100644 src/Adapter/InfoCard.php create mode 100644 src/Adapter/Ldap.php create mode 100644 src/Adapter/OpenId.php create mode 100644 src/AuthenticationService.php create mode 100644 src/Exception.php create mode 100644 src/Result.php create mode 100644 src/Storage.php create mode 100644 src/Storage/Exception.php create mode 100644 src/Storage/NonPersistent.php create mode 100644 src/Storage/Session.php create mode 100644 test/Adapter/DbTableTest.php create mode 100644 test/Adapter/DigestTest.php create mode 100644 test/Adapter/HTTP/AuthTest.php create mode 100644 test/Adapter/HTTP/FileResolverTest.php create mode 100644 test/Adapter/HTTP/ObjectTest.php create mode 100644 test/Adapter/HTTP/ProxyTest.php create mode 100644 test/Adapter/HTTP/TestAsset/htbasic.1 create mode 100644 test/Adapter/HTTP/TestAsset/htdigest.3 create mode 100644 test/Adapter/Ldap/OfflineTest.php create mode 100644 test/Adapter/Ldap/OnlineTest.php create mode 100644 test/Adapter/OpenIdTest.php create mode 100644 test/Adapter/TestAsset/Digest/htdigest.1 create mode 100644 test/Adapter/TestAsset/OpenId/.gitignore create mode 100644 test/Adapter/TestAsset/OpenId/assoc.lock create mode 100644 test/Adapter/TestAsset/OpenId/discovery.lock create mode 100644 test/Adapter/TestAsset/OpenId/nonce.lock create mode 100644 test/Adapter/TestAsset/OpenId/nonce_9f11599cc1f088b7c358f33610cb126c create mode 100644 test/Adapter/TestAsset/OpenIdResponseHelper.php create mode 100644 test/AuthenticationServiceTest.php create mode 100644 test/TestAsset/SuccessAdapter.php diff --git a/src/Adapter.php b/src/Adapter.php new file mode 100644 index 0000000..fad5de5 --- /dev/null +++ b/src/Adapter.php @@ -0,0 +1,44 @@ +_zendDb = $zendDb; + + if (null !== $tableName) { + $this->setTableName($tableName); + } + + if (null !== $identityColumn) { + $this->setIdentityColumn($identityColumn); + } + + if (null !== $credentialColumn) { + $this->setCredentialColumn($credentialColumn); + } + + if (null !== $credentialTreatment) { + $this->setCredentialTreatment($credentialTreatment); + } + } + + /** + * setTableName() - set the table name to be used in the select query + * + * @param string $tableName + * @return Zend\Authentication\Adapter\DbTable Provides a fluent interface + */ + public function setTableName($tableName) + { + $this->_tableName = $tableName; + return $this; + } + + /** + * setIdentityColumn() - set the column name to be used as the identity column + * + * @param string $identityColumn + * @return Zend\Authentication\Adapter\DbTable Provides a fluent interface + */ + public function setIdentityColumn($identityColumn) + { + $this->_identityColumn = $identityColumn; + return $this; + } + + /** + * setCredentialColumn() - set the column name to be used as the credential column + * + * @param string $credentialColumn + * @return Zend\Authentication\Adapter\DbTable Provides a fluent interface + */ + public function setCredentialColumn($credentialColumn) + { + $this->_credentialColumn = $credentialColumn; + return $this; + } + + /** + * setCredentialTreatment() - allows the developer to pass a parameterized string that is + * used to transform or treat the input credential data. + * + * In many cases, passwords and other sensitive data are encrypted, hashed, encoded, + * obscured, or otherwise treated through some function or algorithm. By specifying a + * parameterized treatment string with this method, a developer may apply arbitrary SQL + * upon input credential data. + * + * Examples: + * + * 'PASSWORD(?)' + * 'MD5(?)' + * + * @param string $treatment + * @return Zend\Authentication\Adapter\DbTable Provides a fluent interface + */ + public function setCredentialTreatment($treatment) + { + $this->_credentialTreatment = $treatment; + return $this; + } + + /** + * setIdentity() - set the value to be used as the identity + * + * @param string $value + * @return Zend\Authentication\Adapter\DbTable Provides a fluent interface + */ + public function setIdentity($value) + { + $this->_identity = $value; + return $this; + } + + /** + * setCredential() - set the credential value to be used, optionally can specify a treatment + * to be used, should be supplied in parameterized form, such as 'MD5(?)' or 'PASSWORD(?)' + * + * @param string $credential + * @return Zend\Authentication\Adapter\DbTable Provides a fluent interface + */ + public function setCredential($credential) + { + $this->_credential = $credential; + return $this; + } + + /** + * getDbSelect() - Return the preauthentication Db Select object for userland select query modification + * + * @return Zend_Db_Select + */ + public function getDbSelect() + { + if ($this->_dbSelect == null) { + $this->_dbSelect = $this->_zendDb->select(); + } + + return $this->_dbSelect; + } + + /** + * getResultRowObject() - Returns the result row as a stdClass object + * + * @param string|array $returnColumns + * @param string|array $omitColumns + * @return stdClass|boolean + */ + public function getResultRowObject($returnColumns = null, $omitColumns = null) + { + if (!$this->_resultRow) { + return false; + } + + $returnObject = new \stdClass(); + + if (null !== $returnColumns) { + + $availableColumns = array_keys($this->_resultRow); + foreach ( (array) $returnColumns as $returnColumn) { + if (in_array($returnColumn, $availableColumns)) { + $returnObject->{$returnColumn} = $this->_resultRow[$returnColumn]; + } + } + return $returnObject; + + } elseif (null !== $omitColumns) { + + $omitColumns = (array) $omitColumns; + foreach ($this->_resultRow as $resultColumn => $resultValue) { + if (!in_array($resultColumn, $omitColumns)) { + $returnObject->{$resultColumn} = $resultValue; + } + } + return $returnObject; + + } else { + + foreach ($this->_resultRow as $resultColumn => $resultValue) { + $returnObject->{$resultColumn} = $resultValue; + } + return $returnObject; + + } + } + + /** + * authenticate() - defined by Zend_Auth_Adapter_Interface. This method is called to + * attempt an authentication. Previous to this call, this adapter would have already + * been configured with all necessary information to successfully connect to a database + * table and attempt to find a record matching the provided identity. + * + * @throws Zend\Authentication\Adapter\Exception if answering the authentication query is impossible + * @return Zend\Authentication\Result + */ + public function authenticate() + { + $this->_authenticateSetup(); + $dbSelect = $this->_authenticateCreateSelect(); + $resultIdentities = $this->_authenticateQuerySelect($dbSelect); + + if ( ($authResult = $this->_authenticateValidateResultset($resultIdentities)) instanceof AuthenticationResult) { + return $authResult; + } + + $authResult = $this->_authenticateValidateResult(array_shift($resultIdentities)); + return $authResult; + } + + /** + * _authenticateSetup() - This method abstracts the steps involved with + * making sure that this adapter was indeed setup properly with all + * required pieces of information. + * + * @throws Zend\Authentication\Adapter\Exception - in the event that setup was not done properly + * @return true + */ + protected function _authenticateSetup() + { + $exception = null; + + if ($this->_tableName == '') { + $exception = 'A table must be supplied for the Zend_Auth_Adapter_DbTable authentication adapter.'; + } elseif ($this->_identityColumn == '') { + $exception = 'An identity column must be supplied for the Zend_Auth_Adapter_DbTable authentication adapter.'; + } elseif ($this->_credentialColumn == '') { + $exception = 'A credential column must be supplied for the Zend_Auth_Adapter_DbTable authentication adapter.'; + } elseif ($this->_identity == '') { + $exception = 'A value for the identity was not provided prior to authentication with Zend_Auth_Adapter_DbTable.'; + } elseif ($this->_credential === null) { + $exception = 'A credential value was not provided prior to authentication with Zend_Auth_Adapter_DbTable.'; + } + + if (null !== $exception) { + throw new Exception($exception); + } + + $this->_authenticateResultInfo = array( + 'code' => AuthenticationResult::FAILURE, + 'identity' => $this->_identity, + 'messages' => array() + ); + + return true; + } + + /** + * _authenticateCreateSelect() - This method creates a Zend_Db_Select object that + * is completely configured to be queried against the database. + * + * @return Zend_Db_Select + */ + protected function _authenticateCreateSelect() + { + // build credential expression + if (empty($this->_credentialTreatment) || (strpos($this->_credentialTreatment, '?') === false)) { + $this->_credentialTreatment = '?'; + } + + $credentialExpression = new \Zend_Db_Expr( + '(CASE WHEN ' . + $this->_zendDb->quoteInto( + $this->_zendDb->quoteIdentifier($this->_credentialColumn, true) + . ' = ' . $this->_credentialTreatment, $this->_credential + ) + . ' THEN 1 ELSE 0 END) AS ' + . $this->_zendDb->quoteIdentifier( + $this->_zendDb->foldCase('zend_auth_credential_match') + ) + ); + + // get select + $dbSelect = clone $this->getDbSelect(); + $dbSelect->from($this->_tableName, array('*', $credentialExpression)) + ->where($this->_zendDb->quoteIdentifier($this->_identityColumn, true) . ' = ?', $this->_identity); + + return $dbSelect; + } + + /** + * _authenticateQuerySelect() - This method accepts a Zend_Db_Select object and + * performs a query against the database with that object. + * + * @param Zend_Db_Select $dbSelect + * @throws \Zend\Authentication\Adapter\Exception - when an invalid select + * object is encountered + * @return array + */ + protected function _authenticateQuerySelect(\Zend_Db_Select $dbSelect) + { + try { + if ($this->_zendDb->getFetchMode() != \Zend_DB::FETCH_ASSOC) { + $origDbFetchMode = $this->_zendDb->getFetchMode(); + $this->_zendDb->setFetchMode(\Zend_DB::FETCH_ASSOC); + } + $resultIdentities = $this->_zendDb->fetchAll($dbSelect->__toString()); + if (isset($origDbFetchMode)) { + $this->_zendDb->setFetchMode($origDbFetchMode); + unset($origDbFetchMode); + } + } catch (\Exception $e) { + throw new Exception('The supplied parameters to Zend\\Authentication\\Adapter\\DbTable failed to ' + . 'produce a valid sql statement, please check table and column names ' + . 'for validity.', 0, $e); + } + return $resultIdentities; + } + + /** + * _authenticateValidateResultSet() - This method attempts to make + * certain that only one record was returned in the resultset + * + * @param array $resultIdentities + * @return true|Zend\Authentication\Result + */ + protected function _authenticateValidateResultSet(array $resultIdentities) + { + + if (count($resultIdentities) < 1) { + $this->_authenticateResultInfo['code'] = AuthenticationResult::FAILURE_IDENTITY_NOT_FOUND; + $this->_authenticateResultInfo['messages'][] = 'A record with the supplied identity could not be found.'; + return $this->_authenticateCreateAuthResult(); + } elseif (count($resultIdentities) > 1) { + $this->_authenticateResultInfo['code'] = AuthenticationResult::FAILURE_IDENTITY_AMBIGUOUS; + $this->_authenticateResultInfo['messages'][] = 'More than one record matches the supplied identity.'; + return $this->_authenticateCreateAuthResult(); + } + + return true; + } + + /** + * _authenticateValidateResult() - This method attempts to validate that + * the record in the resultset is indeed a record that matched the + * identity provided to this adapter. + * + * @param array $resultIdentity + * @return Zend\Authentication\Result + */ + protected function _authenticateValidateResult($resultIdentity) + { + $zendAuthCredentialMatchColumn = $this->_zendDb->foldCase('zend_auth_credential_match'); + + if ($resultIdentity[$zendAuthCredentialMatchColumn] != '1') { + $this->_authenticateResultInfo['code'] = AuthenticationResult::FAILURE_CREDENTIAL_INVALID; + $this->_authenticateResultInfo['messages'][] = 'Supplied credential is invalid.'; + return $this->_authenticateCreateAuthResult(); + } + + unset($resultIdentity[$zendAuthCredentialMatchColumn]); + $this->_resultRow = $resultIdentity; + + $this->_authenticateResultInfo['code'] = AuthenticationResult::SUCCESS; + $this->_authenticateResultInfo['messages'][] = 'Authentication successful.'; + return $this->_authenticateCreateAuthResult(); + } + + /** + * _authenticateCreateAuthResult() - Creates a Zend_Auth_Result object from + * the information that has been collected during the authenticate() attempt. + * + * @return \Zend\Authentication\Result + */ + protected function _authenticateCreateAuthResult() + { + return new AuthenticationResult( + $this->_authenticateResultInfo['code'], + $this->_authenticateResultInfo['identity'], + $this->_authenticateResultInfo['messages'] + ); + } + +} diff --git a/src/Adapter/Digest.php b/src/Adapter/Digest.php new file mode 100644 index 0000000..cd7bea4 --- /dev/null +++ b/src/Adapter/Digest.php @@ -0,0 +1,224 @@ +$methodName($$option); + } + } + } + + /** + * Returns the filename option value or null if it has not yet been set + * + * @return string|null + */ + public function getFilename() + { + return $this->_filename; + } + + /** + * Sets the filename option value + * + * @param mixed $filename + * @return Zend\Authentication\Adapter\Digest Provides a fluent interface + */ + public function setFilename($filename) + { + $this->_filename = (string) $filename; + return $this; + } + + /** + * Returns the realm option value or null if it has not yet been set + * + * @return string|null + */ + public function getRealm() + { + return $this->_realm; + } + + /** + * Sets the realm option value + * + * @param mixed $realm + * @return Zend\Authentication\Adapter\Digest Provides a fluent interface + */ + public function setRealm($realm) + { + $this->_realm = (string) $realm; + return $this; + } + + /** + * Returns the username option value or null if it has not yet been set + * + * @return string|null + */ + public function getUsername() + { + return $this->_username; + } + + /** + * Sets the username option value + * + * @param mixed $username + * @return Zend\Authentication\Adapter\Digest Provides a fluent interface + */ + public function setUsername($username) + { + $this->_username = (string) $username; + return $this; + } + + /** + * Returns the password option value or null if it has not yet been set + * + * @return string|null + */ + public function getPassword() + { + return $this->_password; + } + + /** + * Sets the password option value + * + * @param mixed $password + * @return Zend\Authentication\Adapter\Digest Provides a fluent interface + */ + public function setPassword($password) + { + $this->_password = (string) $password; + return $this; + } + + /** + * Defined by Zend_Auth_Adapter_Interface + * + * @throws Zend\Authentication\Adapter\Exception + * @return Zend\Authentication\Result + */ + public function authenticate() + { + $optionsRequired = array('filename', 'realm', 'username', 'password'); + foreach ($optionsRequired as $optionRequired) { + if (null === $this->{"_$optionRequired"}) { + throw new Exception("Option '$optionRequired' must be set before authentication"); + } + } + + if (false === ($fileHandle = @fopen($this->_filename, 'r'))) { + throw new Exception("Cannot open '$this->_filename' for reading"); + } + + $id = "$this->_username:$this->_realm"; + $idLength = strlen($id); + + $result = array( + 'code' => AuthenticationResult::FAILURE, + 'identity' => array( + 'realm' => $this->_realm, + 'username' => $this->_username, + ), + 'messages' => array() + ); + + while ($line = trim(fgets($fileHandle))) { + if (substr($line, 0, $idLength) === $id) { + if (substr($line, -32) === md5("$this->_username:$this->_realm:$this->_password")) { + $result['code'] = AuthenticationResult::SUCCESS; + } else { + $result['code'] = AuthenticationResult::FAILURE_CREDENTIAL_INVALID; + $result['messages'][] = 'Password incorrect'; + } + return new AuthenticationResult($result['code'], $result['identity'], $result['messages']); + } + } + + $result['code'] = AuthenticationResult::FAILURE_IDENTITY_NOT_FOUND; + $result['messages'][] = "Username '$this->_username' and realm '$this->_realm' combination not found"; + return new AuthenticationResult($result['code'], $result['identity'], $result['messages']); + } +} diff --git a/src/Adapter/Exception.php b/src/Adapter/Exception.php new file mode 100644 index 0000000..89fc208 --- /dev/null +++ b/src/Adapter/Exception.php @@ -0,0 +1,37 @@ + 'basic'|'digest'|'basic digest' + * 'realm' => + * 'digest_domains' => Space-delimited list of URIs + * 'nonce_timeout' => + * 'use_opaque' => Whether to send the opaque value in the header + * 'alogrithm' => See $_supportedAlgos. Default: MD5 + * 'proxy_auth' => Whether to do authentication as a Proxy + * @throws Zend\Authentication\Exception + * @return void + */ + public function __construct(array $config) + { + if (!extension_loaded('hash')) { + throw new Exception(__CLASS__ . ' requires the \'hash\' extension'); + } + + $this->_request = null; + $this->_response = null; + $this->_ieNoOpaque = false; + + + if (empty($config['accept_schemes'])) { + throw new Exception('Config key \'accept_schemes\' is required'); + } + + $schemes = explode(' ', $config['accept_schemes']); + $this->_acceptSchemes = array_intersect($schemes, $this->_supportedSchemes); + if (empty($this->_acceptSchemes)) { + throw new Exception('No supported schemes given in \'accept_schemes\'. Valid values: ' + . implode(', ', $this->_supportedSchemes)); + } + + // Double-quotes are used to delimit the realm string in the HTTP header, + // and colons are field delimiters in the password file. + if (empty($config['realm']) || + !ctype_print($config['realm']) || + strpos($config['realm'], ':') !== false || + strpos($config['realm'], '"') !== false) { + throw new Exception('Config key \'realm\' is required, and must contain only printable ' + . 'characters, excluding quotation marks and colons'); + } else { + $this->_realm = $config['realm']; + } + + if (in_array('digest', $this->_acceptSchemes)) { + if (empty($config['digest_domains']) || + !ctype_print($config['digest_domains']) || + strpos($config['digest_domains'], '"') !== false) { + throw new Exception('Config key \'digest_domains\' is required, and must contain ' + . 'only printable characters, excluding quotation marks'); + } else { + $this->_domains = $config['digest_domains']; + } + + if (empty($config['nonce_timeout']) || + !is_numeric($config['nonce_timeout'])) { + throw new Exception('Config key \'nonce_timeout\' is required, and must be an ' + . 'integer'); + } else { + $this->_nonceTimeout = (int) $config['nonce_timeout']; + } + + // We use the opaque value unless explicitly told not to + if (isset($config['use_opaque']) && false == (bool) $config['use_opaque']) { + $this->_useOpaque = false; + } else { + $this->_useOpaque = true; + } + + if (isset($config['algorithm']) && in_array($config['algorithm'], $this->_supportedAlgos)) { + $this->_algo = $config['algorithm']; + } else { + $this->_algo = 'MD5'; + } + } + + // Don't be a proxy unless explicitly told to do so + if (isset($config['proxy_auth']) && true == (bool) $config['proxy_auth']) { + $this->_imaProxy = true; // I'm a Proxy + } else { + $this->_imaProxy = false; + } + } + + /** + * Setter for the _basicResolver property + * + * @param Zend\Authentication\Adapter\HTTP\Resolver $resolver + * @return Zend\Authentication\Adapter\HTTP Provides a fluent interface + */ + public function setBasicResolver(HTTP\Resolver $resolver) + { + $this->_basicResolver = $resolver; + + return $this; + } + + /** + * Getter for the _basicResolver property + * + * @return Zend\Authentication\Adapter\HTTP\Resolver + */ + public function getBasicResolver() + { + return $this->_basicResolver; + } + + /** + * Setter for the _digestResolver property + * + * @param Zend\Authentication\Adapter\HTTP\Resolver $resolver + * @return Zend\Authentication\Adapter\HTTP Provides a fluent interface + */ + public function setDigestResolver(HTTP\Resolver $resolver) + { + $this->_digestResolver = $resolver; + + return $this; + } + + /** + * Getter for the _digestResolver property + * + * @return Zend\Authentication\Adapter\HTTP\Resolver + */ + public function getDigestResolver() + { + return $this->_digestResolver; + } + + /** + * Setter for the Request object + * + * @param Zend_Controller_Request_Http $request + * @return Zend\Authentication\Adapter\HTTP Provides a fluent interface + */ + public function setRequest(\Zend_Controller_Request_Http $request) + { + $this->_request = $request; + + return $this; + } + + /** + * Getter for the Request object + * + * @return Zend_Controller_Request_Http + */ + public function getRequest() + { + return $this->_request; + } + + /** + * Setter for the Response object + * + * @param Zend_Controller_Response_Http $response + * @return Zend\Authentication\Adapter\HTTP Provides a fluent interface + */ + public function setResponse(\Zend_Controller_Response_Http $response) + { + $this->_response = $response; + + return $this; + } + + /** + * Getter for the Response object + * + * @return Zend_Controller_Response_Http + */ + public function getResponse() + { + return $this->_response; + } + + /** + * Authenticate + * + * @throws Zend\Authentication\Exception + * @return Zend\Authentication\Result + */ + public function authenticate() + { + if (empty($this->_request) || + empty($this->_response)) { + throw new Exception('Request and Response objects must be set before calling ' + . 'authenticate()'); + } + + if ($this->_imaProxy) { + $getHeader = 'Proxy-Authorization'; + } else { + $getHeader = 'Authorization'; + } + + $authHeader = $this->_request->getHeader($getHeader); + if (!$authHeader) { + return $this->_challengeClient(); + } + + list($clientScheme) = explode(' ', $authHeader); + $clientScheme = strtolower($clientScheme); + + // The server can issue multiple challenges, but the client should + // answer with only the selected auth scheme. + if (!in_array($clientScheme, $this->_supportedSchemes)) { + $this->_response->setHttpResponseCode(400); + return new Authentication\Result( + Authentication\Result::FAILURE_UNCATEGORIZED, + array(), + array('Client requested an incorrect or unsupported authentication scheme') + ); + } + + // client sent a scheme that is not the one required + if (!in_array($clientScheme, $this->_acceptSchemes)) { + // challenge again the client + return $this->_challengeClient(); + } + + switch ($clientScheme) { + case 'basic': + $result = $this->_basicAuth($authHeader); + break; + case 'digest': + $result = $this->_digestAuth($authHeader); + break; + default: + throw new Exception('Unsupported authentication scheme'); + } + + return $result; + } + + /** + * Challenge Client + * + * Sets a 401 or 407 Unauthorized response code, and creates the + * appropriate Authenticate header(s) to prompt for credentials. + * + * @return Zend\Authentication\Result Always returns a non-identity Auth result + */ + protected function _challengeClient() + { + if ($this->_imaProxy) { + $statusCode = 407; + $headerName = 'Proxy-Authenticate'; + } else { + $statusCode = 401; + $headerName = 'WWW-Authenticate'; + } + + $this->_response->setHttpResponseCode($statusCode); + + // Send a challenge in each acceptable authentication scheme + if (in_array('basic', $this->_acceptSchemes)) { + $this->_response->setHeader($headerName, $this->_basicHeader()); + } + if (in_array('digest', $this->_acceptSchemes)) { + $this->_response->setHeader($headerName, $this->_digestHeader()); + } + return new Authentication\Result( + Authentication\Result::FAILURE_CREDENTIAL_INVALID, + array(), + array('Invalid or absent credentials; challenging client') + ); + } + + /** + * Basic Header + * + * Generates a Proxy- or WWW-Authenticate header value in the Basic + * authentication scheme. + * + * @return string Authenticate header value + */ + protected function _basicHeader() + { + return 'Basic realm="' . $this->_realm . '"'; + } + + /** + * Digest Header + * + * Generates a Proxy- or WWW-Authenticate header value in the Digest + * authentication scheme. + * + * @return string Authenticate header value + */ + protected function _digestHeader() + { + $wwwauth = 'Digest realm="' . $this->_realm . '", ' + . 'domain="' . $this->_domains . '", ' + . 'nonce="' . $this->_calcNonce() . '", ' + . ($this->_useOpaque ? 'opaque="' . $this->_calcOpaque() . '", ' : '') + . 'algorithm="' . $this->_algo . '", ' + . 'qop="' . implode(',', $this->_supportedQops) . '"'; + + return $wwwauth; + } + + /** + * Basic Authentication + * + * @param string $header Client's Authorization header + * @throws Zend\Authentication\Exception + * @return Zend\Authentication\Result + */ + protected function _basicAuth($header) + { + if (empty($header)) { + throw new Exception('The value of the client Authorization header is required'); + } + if (empty($this->_basicResolver)) { + throw new Exception('A basicResolver object must be set before doing Basic ' + . 'authentication'); + } + + // Decode the Authorization header + $auth = substr($header, strlen('Basic ')); + $auth = base64_decode($auth); + if (!$auth) { + throw new Exception('Unable to base64_decode Authorization header value'); + } + + // See ZF-1253. Validate the credentials the same way the digest + // implementation does. If invalid credentials are detected, + // re-challenge the client. + if (!ctype_print($auth)) { + return $this->_challengeClient(); + } + // Fix for ZF-1515: Now re-challenges on empty username or password + $creds = array_filter(explode(':', $auth)); + if (count($creds) != 2) { + return $this->_challengeClient(); + } + + $password = $this->_basicResolver->resolve($creds[0], $this->_realm); + if ($password && $password == $creds[1]) { + $identity = array('username'=>$creds[0], 'realm'=>$this->_realm); + return new Authentication\Result(Authentication\Result::SUCCESS, $identity); + } else { + return $this->_challengeClient(); + } + } + + /** + * Digest Authentication + * + * @param string $header Client's Authorization header + * @throws Zend\Authentication\Exception + * @return Zend\Authentication\Result Valid auth result only on successful auth + */ + protected function _digestAuth($header) + { + if (empty($header)) { + throw new Exception('The value of the client Authorization header is required'); + } + if (empty($this->_digestResolver)) { + throw new Exception('A digestResolver object must be set before doing Digest authentication'); + } + + $data = $this->_parseDigestAuth($header); + if ($data === false) { + $this->_response->setHttpResponseCode(400); + return new Authentication\Result( + Authentication\Result::FAILURE_UNCATEGORIZED, + array(), + array('Invalid Authorization header format') + ); + } + + // See ZF-1052. This code was a bit too unforgiving of invalid + // usernames. Now, if the username is bad, we re-challenge the client. + if ('::invalid::' == $data['username']) { + return $this->_challengeClient(); + } + + // Verify that the client sent back the same nonce + if ($this->_calcNonce() != $data['nonce']) { + return $this->_challengeClient(); + } + // The opaque value is also required to match, but of course IE doesn't + // play ball. + if (!$this->_ieNoOpaque && $this->_calcOpaque() != $data['opaque']) { + return $this->_challengeClient(); + } + + // Look up the user's password hash. If not found, deny access. + // This makes no assumptions about how the password hash was + // constructed beyond that it must have been built in such a way as + // to be recreatable with the current settings of this object. + $ha1 = $this->_digestResolver->resolve($data['username'], $data['realm']); + if ($ha1 === false) { + return $this->_challengeClient(); + } + + // If MD5-sess is used, a1 value is made of the user's password + // hash with the server and client nonce appended, separated by + // colons. + if ($this->_algo == 'MD5-sess') { + $ha1 = hash('md5', $ha1 . ':' . $data['nonce'] . ':' . $data['cnonce']); + } + + // Calculate h(a2). The value of this hash depends on the qop + // option selected by the client and the supported hash functions + switch ($data['qop']) { + case 'auth': + $a2 = $this->_request->getMethod() . ':' . $data['uri']; + break; + case 'auth-int': + // Should be REQUEST_METHOD . ':' . uri . ':' . hash(entity-body), + // but this isn't supported yet, so fall through to default case + default: + throw new Exception('Client requested an unsupported qop option'); + } + // Using hash() should make parameterizing the hash algorithm + // easier + $ha2 = hash('md5', $a2); + + + // Calculate the server's version of the request-digest. This must + // match $data['response']. See RFC 2617, section 3.2.2.1 + $message = $data['nonce'] . ':' . $data['nc'] . ':' . $data['cnonce'] . ':' . $data['qop'] . ':' . $ha2; + $digest = hash('md5', $ha1 . ':' . $message); + + // If our digest matches the client's let them in, otherwise return + // a 401 code and exit to prevent access to the protected resource. + if ($digest == $data['response']) { + $identity = array('username'=>$data['username'], 'realm'=>$data['realm']); + return new Authentication\Result(Authentication\Result::SUCCESS, $identity); + } else { + return $this->_challengeClient(); + } + } + + /** + * Calculate Nonce + * + * @return string The nonce value + */ + protected function _calcNonce() + { + // Once subtle consequence of this timeout calculation is that it + // actually divides all of time into _nonceTimeout-sized sections, such + // that the value of timeout is the point in time of the next + // approaching "boundary" of a section. This allows the server to + // consistently generate the same timeout (and hence the same nonce + // value) across requests, but only as long as one of those + // "boundaries" is not crossed between requests. If that happens, the + // nonce will change on its own, and effectively log the user out. This + // would be surprising if the user just logged in. + $timeout = ceil(time() / $this->_nonceTimeout) * $this->_nonceTimeout; + + $nonce = hash('md5', $timeout . ':' . $this->_request->getServer('HTTP_USER_AGENT') . ':' . __CLASS__); + return $nonce; + } + + /** + * Calculate Opaque + * + * The opaque string can be anything; the client must return it exactly as + * it was sent. It may be useful to store data in this string in some + * applications. Ideally, a new value for this would be generated each time + * a WWW-Authenticate header is sent (in order to reduce predictability), + * but we would have to be able to create the same exact value across at + * least two separate requests from the same client. + * + * @return string The opaque value + */ + protected function _calcOpaque() + { + return hash('md5', 'Opaque Data:' . __CLASS__); + } + + /** + * Parse Digest Authorization header + * + * @param string $header Client's Authorization: HTTP header + * @return array|false Data elements from header, or false if any part of + * the header is invalid + */ + protected function _parseDigestAuth($header) + { + $temp = null; + $data = array(); + + // See ZF-1052. Detect invalid usernames instead of just returning a + // 400 code. + $ret = preg_match('/username="([^"]+)"/', $header, $temp); + if (!$ret || empty($temp[1]) + || !ctype_print($temp[1]) + || strpos($temp[1], ':') !== false) { + $data['username'] = '::invalid::'; + } else { + $data['username'] = $temp[1]; + } + $temp = null; + + $ret = preg_match('/realm="([^"]+)"/', $header, $temp); + if (!$ret || empty($temp[1])) { + return false; + } + if (!ctype_print($temp[1]) || strpos($temp[1], ':') !== false) { + return false; + } else { + $data['realm'] = $temp[1]; + } + $temp = null; + + $ret = preg_match('/nonce="([^"]+)"/', $header, $temp); + if (!$ret || empty($temp[1])) { + return false; + } + if (!ctype_xdigit($temp[1])) { + return false; + } else { + $data['nonce'] = $temp[1]; + } + $temp = null; + + $ret = preg_match('/uri="([^"]+)"/', $header, $temp); + if (!$ret || empty($temp[1])) { + return false; + } + // Section 3.2.2.5 in RFC 2617 says the authenticating server must + // verify that the URI field in the Authorization header is for the + // same resource requested in the Request Line. + $rUri = @parse_url($this->_request->getRequestUri()); + $cUri = @parse_url($temp[1]); + if (false === $rUri || false === $cUri) { + return false; + } else { + // Make sure the path portion of both URIs is the same + if ($rUri['path'] != $cUri['path']) { + return false; + } + // Section 3.2.2.5 seems to suggest that the value of the URI + // Authorization field should be made into an absolute URI if the + // Request URI is absolute, but it's vague, and that's a bunch of + // code I don't want to write right now. + $data['uri'] = $temp[1]; + } + $temp = null; + + $ret = preg_match('/response="([^"]+)"/', $header, $temp); + if (!$ret || empty($temp[1])) { + return false; + } + if (32 != strlen($temp[1]) || !ctype_xdigit($temp[1])) { + return false; + } else { + $data['response'] = $temp[1]; + } + $temp = null; + + // The spec says this should default to MD5 if omitted. OK, so how does + // that square with the algo we send out in the WWW-Authenticate header, + // if it can easily be overridden by the client? + $ret = preg_match('/algorithm="?(' . $this->_algo . ')"?/', $header, $temp); + if ($ret && !empty($temp[1]) + && in_array($temp[1], $this->_supportedAlgos)) { + $data['algorithm'] = $temp[1]; + } else { + $data['algorithm'] = 'MD5'; // = $this->_algo; ? + } + $temp = null; + + // Not optional in this implementation + $ret = preg_match('/cnonce="([^"]+)"/', $header, $temp); + if (!$ret || empty($temp[1])) { + return false; + } + if (!ctype_print($temp[1])) { + return false; + } else { + $data['cnonce'] = $temp[1]; + } + $temp = null; + + // If the server sent an opaque value, the client must send it back + if ($this->_useOpaque) { + $ret = preg_match('/opaque="([^"]+)"/', $header, $temp); + if (!$ret || empty($temp[1])) { + + // Big surprise: IE isn't RFC 2617-compliant. + if (false !== strpos($this->_request->getHeader('User-Agent'), 'MSIE')) { + $temp[1] = ''; + $this->_ieNoOpaque = true; + } else { + return false; + } + } + // This implementation only sends MD5 hex strings in the opaque value + if (!$this->_ieNoOpaque && + (32 != strlen($temp[1]) || !ctype_xdigit($temp[1]))) { + return false; + } else { + $data['opaque'] = $temp[1]; + } + $temp = null; + } + + // Not optional in this implementation, but must be one of the supported + // qop types + $ret = preg_match('/qop="?(' . implode('|', $this->_supportedQops) . ')"?/', $header, $temp); + if (!$ret || empty($temp[1])) { + return false; + } + if (!in_array($temp[1], $this->_supportedQops)) { + return false; + } else { + $data['qop'] = $temp[1]; + } + $temp = null; + + // Not optional in this implementation. The spec says this value + // shouldn't be a quoted string, but apparently some implementations + // quote it anyway. See ZF-1544. + $ret = preg_match('/nc="?([0-9A-Fa-f]{8})"?/', $header, $temp); + if (!$ret || empty($temp[1])) { + return false; + } + if (8 != strlen($temp[1]) || !ctype_xdigit($temp[1])) { + return false; + } else { + $data['nc'] = $temp[1]; + } + $temp = null; + + return $data; + } +} diff --git a/src/Adapter/HTTP/Exception.php b/src/Adapter/HTTP/Exception.php new file mode 100644 index 0000000..975f019 --- /dev/null +++ b/src/Adapter/HTTP/Exception.php @@ -0,0 +1,39 @@ +setFile($path); + } + } + + /** + * Set the path to the credentials file + * + * @param string $path + * @return Zend\Authentication\Adapter\Http\FileResolver Provides a fluent interface + * @throws Zend\Authentication\Adapter\Http\Exception + */ + public function setFile($path) + { + if (empty($path) || !is_readable($path)) { + throw new Exception('Path not readable: ' . $path); + } + $this->_file = $path; + + return $this; + } + + /** + * Returns the path to the credentials file + * + * @return string + */ + public function getFile() + { + return $this->_file; + } + + /** + * Resolve credentials + * + * Only the first matching username/realm combination in the file is + * returned. If the file contains credentials for Digest authentication, + * the returned string is the password hash, or h(a1) from RFC 2617. The + * returned string is the plain-text password for Basic authentication. + * + * The expected format of the file is: + * username:realm:sharedSecret + * + * That is, each line consists of the user's username, the applicable + * authentication realm, and the password or hash, each delimited by + * colons. + * + * @param string $username Username + * @param string $realm Authentication Realm + * @return string|false User's shared secret, if the user is found in the + * realm, false otherwise. + * @throws Zend\Authentication\Adapter\Http\Exception + */ + public function resolve($username, $realm) + { + if (empty($username)) { + throw new Exception('Username is required'); + } else if (!ctype_print($username) || strpos($username, ':') !== false) { + throw new Exception('Username must consist only of printable characters, ' + . 'excluding the colon'); + } + if (empty($realm)) { + throw new Exception('Realm is required'); + } else if (!ctype_print($realm) || strpos($realm, ':') !== false) { + throw new Exception('Realm must consist only of printable characters, ' + . 'excluding the colon.'); + } + + // Open file, read through looking for matching credentials + $fp = @fopen($this->_file, 'r'); + if (!$fp) { + throw new Exception('Unable to open password file: ' . $this->_file); + } + + // No real validation is done on the contents of the password file. The + // assumption is that we trust the administrators to keep it secure. + while (($line = fgetcsv($fp, 512, ':')) !== false) { + if ($line[0] == $username && $line[1] == $realm) { + $password = $line[2]; + fclose($fp); + return $password; + } + } + + fclose($fp); + return false; + } +} diff --git a/src/Adapter/HTTP/Resolver.php b/src/Adapter/HTTP/Resolver.php new file mode 100644 index 0000000..408c1a9 --- /dev/null +++ b/src/Adapter/HTTP/Resolver.php @@ -0,0 +1,51 @@ +_xmlToken = $strXmlDocument; + $this->_infoCard = new \Zend_InfoCard(); + } + + /** + * Sets the InfoCard component Adapter to use + * + * @param Zend_InfoCard_Adapter_Interface $a + * @return Zend\Authentication\Adapter\InfoCard Provides a fluent interface + */ + public function setAdapter(\Zend_InfoCard_Adapter_Interface $a) + { + $this->_infoCard->setAdapter($a); + return $this; + } + + /** + * Retrieves the InfoCard component adapter being used + * + * @return Zend_InfoCard_Adapter_Interface + */ + public function getAdapter() + { + return $this->_infoCard->getAdapter(); + } + + /** + * Retrieves the InfoCard public key cipher object being used + * + * @return Zend_InfoCard_Cipher_Pki_Interface + */ + public function getPKCipherObject() + { + return $this->_infoCard->getPKCipherObject(); + } + + /** + * Sets the InfoCard public key cipher object to use + * + * @param Zend_InfoCard_Cipher_Pki_Interface $cipherObj + * @return \Zend\Authentication\Adapter\InfoCard Provides a fluent interface + */ + public function setPKICipherObject(\Zend_InfoCard_Cipher_Pki_Interface $cipherObj) + { + $this->_infoCard->setPKICipherObject($cipherObj); + return $this; + } + + /** + * Retrieves the Symmetric cipher object being used + * + * @return Zend_InfoCard_Cipher_Symmetric_Interface + */ + public function getSymCipherObject() + { + return $this->_infoCard->getSymCipherObject(); + } + + /** + * Sets the InfoCard symmetric cipher object to use + * + * @param Zend_InfoCard_Cipher_Symmetric_Interface $cipherObj + * @return Zend\Authentication\Adapter\InfoCard Provides a fluent interface + */ + public function setSymCipherObject(\Zend_InfoCard_Cipher_Symmetric_Interface $cipherObj) + { + $this->_infoCard->setSymCipherObject($cipherObj); + return $this; + } + + /** + * Remove a Certificate Pair by Key ID from the search list + * + * @param string $key_id The Certificate Key ID returned from adding the certificate pair + * @throws Zend\InfoCard\Exception + * @return Zend\Authentication\Adapter\InfoCard Provides a fluent interface + */ + public function removeCertificatePair($key_id) + { + $this->_infoCard->removeCertificatePair($key_id); + return $this; + } + + /** + * Add a Certificate Pair to the list of certificates searched by the component + * + * @param string $private_key_file The path to the private key file for the pair + * @param string $public_key_file The path to the certificate / public key for the pair + * @param string $type (optional) The URI for the type of key pair this is (default RSA with OAEP padding) + * @param string $password (optional) The password for the private key file if necessary + * @throws Zend_InfoCard_Exception + * @return string A key ID representing this key pair in the component + */ + public function addCertificatePair($private_key_file, $public_key_file, $type = \Zend_InfoCard_Cipher::ENC_RSA_OAEP_MGF1P, $password = null) + { + return $this->_infoCard->addCertificatePair($private_key_file, $public_key_file, $type, $password); + } + + /** + * Return a Certificate Pair from a key ID + * + * @param string $key_id The Key ID of the certificate pair in the component + * @throws Zend_InfoCard_Exception + * @return array An array containing the path to the private/public key files, + * the type URI and the password if provided + */ + public function getCertificatePair($key_id) + { + return $this->_infoCard->getCertificatePair($key_id); + } + + /** + * Set the XML Token to be processed + * + * @param string $strXmlToken The XML token to process + * @return \Zend\Authentication\Adapter\InfoCard Provides a fluent interface + */ + public function setXmlToken($strXmlToken) + { + $this->_xmlToken = $strXmlToken; + return $this; + } + + /** + * Get the XML Token being processed + * + * @return string The XML token to be processed + */ + public function getXmlToken() + { + return $this->_xmlToken; + } + + /** + * Authenticates the XML token + * + * @return Zend\Authentication\Result The result of the authentication + */ + public function authenticate() + { + try { + $claims = $this->_infoCard->process($this->getXmlToken()); + } catch(\Exception $e) { + return new AuthenticationResult(AuthenticationResult::FAILURE , null, array('Exception Thrown', + $e->getMessage(), + $e->getTraceAsString(), + serialize($e))); + } + + if(!$claims->isValid()) { + switch($claims->getCode()) { + case \Zend_InfoCard_Claims::RESULT_PROCESSING_FAILURE: + return new AuthenticationResult( + AuthenticationResult::FAILURE, + $claims, + array( + 'Processing Failure', + $claims->getErrorMsg() + ) + ); + break; + case \Zend_InfoCard_Claims::RESULT_VALIDATION_FAILURE: + return new AuthenticationResult( + AuthenticationResult::FAILURE_CREDENTIAL_INVALID, + $claims, + array( + 'Validation Failure', + $claims->getErrorMsg() + ) + ); + break; + default: + return new AuthenticationResult( + AuthenticationResult::FAILURE, + $claims, + array( + 'Unknown Failure', + $claims->getErrorMsg() + ) + ); + break; + } + } + + return new AuthenticationResult( + AuthenticationResult::SUCCESS, + $claims + ); + } +} diff --git a/src/Adapter/Ldap.php b/src/Adapter/Ldap.php new file mode 100644 index 0000000..463c148 --- /dev/null +++ b/src/Adapter/Ldap.php @@ -0,0 +1,517 @@ +setOptions($options); + if ($username !== null) { + $this->setUsername($username); + } + if ($password !== null) { + $this->setPassword($password); + } + } + + /** + * Returns the array of arrays of Zend_Ldap options of this adapter. + * + * @return array|null + */ + public function getOptions() + { + return $this->_options; + } + + /** + * Sets the array of arrays of Zend_Ldap options to be used by + * this adapter. + * + * @param array $options The array of arrays of Zend_Ldap options + * @return Zend\Authentication\Adapter\Ldap Provides a fluent interface + */ + public function setOptions($options) + { + $this->_options = is_array($options) ? $options : array(); + return $this; + } + + /** + * Returns the username of the account being authenticated, or + * NULL if none is set. + * + * @return string|null + */ + public function getUsername() + { + return $this->_username; + } + + /** + * Sets the username for binding + * + * @param string $username The username for binding + * @return Zend\Authentication\Adapter\Ldap Provides a fluent interface + */ + public function setUsername($username) + { + $this->_username = (string) $username; + return $this; + } + + /** + * Returns the password of the account being authenticated, or + * NULL if none is set. + * + * @return string|null + */ + public function getPassword() + { + return $this->_password; + } + + /** + * Sets the passwort for the account + * + * @param string $password The password of the account being authenticated + * @return Zend\Authentication\Adapter\Ldap Provides a fluent interface + */ + public function setPassword($password) + { + $this->_password = (string) $password; + return $this; + } + + /** + * setIdentity() - set the identity (username) to be used + * + * Proxies to {@see setUsername()} + * + * Closes ZF-6813 + * + * @param string $identity + * @return Zend\Authentication\Adapter\Ldap Provides a fluent interface + */ + public function setIdentity($identity) + { + return $this->setUsername($identity); + } + + /** + * setCredential() - set the credential (password) value to be used + * + * Proxies to {@see setPassword()} + * + * Closes ZF-6813 + * + * @param string $credential + * @return Zend\Authentication\Adapter\Ldap Provides a fluent interface + */ + public function setCredential($credential) + { + return $this->setPassword($credential); + } + + /** + * Returns the LDAP Object + * + * @return Zend_Ldap The Zend_Ldap object used to authenticate the credentials + */ + public function getLdap() + { + if ($this->_ldap === null) { + $this->_ldap = new \Zend_Ldap(); + } + + return $this->_ldap; + } + + /** + * Set an Ldap connection + * + * @param Zend_Ldap $ldap An existing Ldap object + * @return Zend\Authentication\Adapter\Ldap Provides a fluent interface + */ + public function setLdap(\Zend_Ldap $ldap) + { + $this->_ldap = $ldap; + + $this->setOptions(array($ldap->getOptions())); + + return $this; + } + + /** + * Returns a domain name for the current LDAP options. This is used + * for skipping redundant operations (e.g. authentications). + * + * @return string + */ + protected function _getAuthorityName() + { + $options = $this->getLdap()->getOptions(); + $name = $options['accountDomainName']; + if (!$name) + $name = $options['accountDomainNameShort']; + return $name ? $name : ''; + } + + /** + * Authenticate the user + * + * @throws Zend\Authentication\Adapter\Exception + * @return Zend\Authentication\Result + */ + public function authenticate() + { + $messages = array(); + $messages[0] = ''; // reserved + $messages[1] = ''; // reserved + + $username = $this->_username; + $password = $this->_password; + + if (!$username) { + $code = AuthenticationResult::FAILURE_IDENTITY_NOT_FOUND; + $messages[0] = 'A username is required'; + return new AuthenticationResult($code, '', $messages); + } + if (!$password) { + /* A password is required because some servers will + * treat an empty password as an anonymous bind. + */ + $code = AuthenticationResult::FAILURE_CREDENTIAL_INVALID; + $messages[0] = 'A password is required'; + return new AuthenticationResult($code, '', $messages); + } + + $ldap = $this->getLdap(); + + $code = AuthenticationResult::FAILURE; + $messages[0] = "Authority not found: $username"; + $failedAuthorities = array(); + + /* Iterate through each server and try to authenticate the supplied + * credentials against it. + */ + foreach ($this->_options as $name => $options) { + + if (!is_array($options)) { + throw new Exception('Adapter options array not an array'); + } + $adapterOptions = $this->_prepareOptions($ldap, $options); + $dname = ''; + + try { + if ($messages[1]) + $messages[] = $messages[1]; + $messages[1] = ''; + $messages[] = $this->_optionsToString($options); + + $dname = $this->_getAuthorityName(); + if (isset($failedAuthorities[$dname])) { + /* If multiple sets of server options for the same domain + * are supplied, we want to skip redundant authentications + * where the identity or credentials where found to be + * invalid with another server for the same domain. The + * $failedAuthorities array tracks this condition (and also + * serves to supply the original error message). + * This fixes issue ZF-4093. + */ + $messages[1] = $failedAuthorities[$dname]; + $messages[] = "Skipping previously failed authority: $dname"; + continue; + } + + $canonicalName = $ldap->getCanonicalAccountName($username); + $ldap->bind($canonicalName, $password); + /* + * Fixes problem when authenticated user is not allowed to retrieve + * group-membership information or own account. + * This requires that the user specified with "username" and optionally + * "password" in the Zend_Ldap options is able to retrieve the required + * information. + */ + $requireRebind = false; + if (isset($options['username'])) { + $ldap->bind(); + $requireRebind = true; + } + $dn = $ldap->getCanonicalAccountName($canonicalName, Ldap\Ldap::ACCTNAME_FORM_DN); + + $groupResult = $this->_checkGroupMembership($ldap, $canonicalName, $dn, $adapterOptions); + if ($groupResult === true) { + $this->_authenticatedDn = $dn; + $messages[0] = ''; + $messages[1] = ''; + $messages[] = "$canonicalName authentication successful"; + if ($requireRebind === true) { + // rebinding with authenticated user + $ldap->bind($dn, $password); + } + return new AuthenticationResult(AuthenticationResult::SUCCESS, $canonicalName, $messages); + } else { + $messages[0] = 'Account is not a member of the specified group'; + $messages[1] = $groupResult; + $failedAuthorities[$dname] = $groupResult; + } + } catch (\Zend_Ldap_Exception $zle) { + + /* LDAP based authentication is notoriously difficult to diagnose. Therefore + * we bend over backwards to capture and record every possible bit of + * information when something goes wrong. + */ + + $err = $zle->getCode(); + + if ($err == \Zend_Ldap_Exception::LDAP_X_DOMAIN_MISMATCH) { + /* This error indicates that the domain supplied in the + * username did not match the domains in the server options + * and therefore we should just skip to the next set of + * server options. + */ + continue; + } else if ($err == \Zend_Ldap_Exception::LDAP_NO_SUCH_OBJECT) { + $code = AuthenticationResult::FAILURE_IDENTITY_NOT_FOUND; + $messages[0] = "Account not found: $username"; + $failedAuthorities[$dname] = $zle->getMessage(); + } else if ($err == \Zend_Ldap_Exception::LDAP_INVALID_CREDENTIALS) { + $code = AuthenticationResult::FAILURE_CREDENTIAL_INVALID; + $messages[0] = 'Invalid credentials'; + $failedAuthorities[$dname] = $zle->getMessage(); + } else { + $line = $zle->getLine(); + $messages[] = $zle->getFile() . "($line): " . $zle->getMessage(); + $messages[] = str_replace($password, '*****', $zle->getTraceAsString()); + $messages[0] = 'An unexpected failure occurred'; + } + $messages[1] = $zle->getMessage(); + } + } + + $msg = isset($messages[1]) ? $messages[1] : $messages[0]; + $messages[] = "$username authentication failed: $msg"; + + return new AuthenticationResult($code, $username, $messages); + } + + /** + * Sets the LDAP specific options on the Zend_Ldap instance + * + * @param Zend_Ldap $ldap + * @param array $options + * @return array of auth-adapter specific options + */ + protected function _prepareOptions(\Zend_Ldap $ldap, array $options) + { + $adapterOptions = array( + 'group' => null, + 'groupDn' => $ldap->getBaseDn(), + 'groupScope' => \Zend_Ldap::SEARCH_SCOPE_SUB, + 'groupAttr' => 'cn', + 'groupFilter' => 'objectClass=groupOfUniqueNames', + 'memberAttr' => 'uniqueMember', + 'memberIsDn' => true + ); + foreach ($adapterOptions as $key => $value) { + if (array_key_exists($key, $options)) { + $value = $options[$key]; + unset($options[$key]); + switch ($key) { + case 'groupScope': + $value = (int)$value; + if (in_array($value, array(\Zend_Ldap::SEARCH_SCOPE_BASE, + \Zend_Ldap::SEARCH_SCOPE_ONE, \Zend_Ldap::SEARCH_SCOPE_SUB), true)) { + $adapterOptions[$key] = $value; + } + break; + case 'memberIsDn': + $adapterOptions[$key] = ($value === true || + $value === '1' || strcasecmp($value, 'true') == 0); + break; + default: + $adapterOptions[$key] = trim($value); + break; + } + } + } + $ldap->setOptions($options); + return $adapterOptions; + } + + /** + * Checks the group membership of the bound user + * + * @param Zend_Ldap $ldap + * @param string $canonicalName + * @param string $dn + * @param array $adapterOptions + * @return string|true + */ + protected function _checkGroupMembership(\Zend_Ldap $ldap, $canonicalName, $dn, array $adapterOptions) + { + if ($adapterOptions['group'] === null) { + return true; + } + + if ($adapterOptions['memberIsDn'] === false) { + $user = $canonicalName; + } else { + $user = $dn; + } + + $groupName = \Zend_Ldap_Filter::equals($adapterOptions['groupAttr'], $adapterOptions['group']); + $membership = \Zend_Ldap_Filter::equals($adapterOptions['memberAttr'], $user); + $group = \Zend_Ldap_Filter::andFilter($groupName, $membership); + $groupFilter = $adapterOptions['groupFilter']; + if (!empty($groupFilter)) { + $group = $group->addAnd($groupFilter); + } + + $result = $ldap->count($group, $adapterOptions['groupDn'], $adapterOptions['groupScope']); + + if ($result === 1) { + return true; + } else { + return 'Failed to verify group membership with ' . $group->toString(); + } + } + + /** + * getAccountObject() - Returns the result entry as a stdClass object + * + * This resembles the feature {@see Zend_Auth_Adapter_DbTable::getResultRowObject()}. + * Closes ZF-6813 + * + * @param array $returnAttribs + * @param array $omitAttribs + * @return stdClass|boolean + */ + public function getAccountObject(array $returnAttribs = array(), array $omitAttribs = array()) + { + if (!$this->_authenticatedDn) { + return false; + } + + $returnObject = new \stdClass(); + + $omitAttribs = array_map('strtolower', $omitAttribs); + + $entry = $this->getLdap()->getEntry($this->_authenticatedDn, $returnAttribs, true); + foreach ($entry as $attr => $value) { + if (in_array($attr, $omitAttribs)) { + // skip attributes marked to be omitted + continue; + } + if (is_array($value)) { + $returnObject->$attr = (count($value) > 1) ? $value : $value[0]; + } else { + $returnObject->$attr = $value; + } + } + return $returnObject; + } + + /** + * Converts options to string + * + * @param array $options + * @return string + */ + private function _optionsToString(array $options) + { + $str = ''; + foreach ($options as $key => $val) { + if ($key === 'password') + $val = '*****'; + if ($str) + $str .= ','; + $str .= $key . '=' . $val; + } + return $str; + } +} diff --git a/src/Adapter/OpenId.php b/src/Adapter/OpenId.php new file mode 100644 index 0000000..dc42046 --- /dev/null +++ b/src/Adapter/OpenId.php @@ -0,0 +1,282 @@ +_id = $id; + $this->_storage = $storage; + $this->_returnTo = $returnTo; + $this->_root = $root; + $this->_extensions = $extensions; + $this->_response = $response; + } + + /** + * Sets the value to be used as the identity + * + * @param string $id the identity value + * @return Zend\Authentication\Adapter\OpenId Provides a fluent interface + */ + public function setIdentity($id) + { + $this->_id = $id; + return $this; + } + + /** + * Sets the storage implementation which will be use by OpenId + * + * @param Zend_OpenId_Consumer_Storage $storage + * @return Zend\Authentication\Adapter\OpenId Provides a fluent interface + */ + public function setStorage(\Zend_OpenId_Consumer_Storage $storage) + { + $this->_storage = $storage; + return $this; + } + + /** + * Sets the HTTP URL to redirect response from server to + * + * @param string $returnTo + * @return \Zend\Authentication\Adapter\OpenId Provides a fluent interface + */ + public function setReturnTo($returnTo) + { + $this->_returnTo = $returnTo; + return $this; + } + + /** + * Sets HTTP URL to identify consumer on server + * + * @param string $root + * @return Zend\Authentication\Adapter\OpenId Provides a fluent interface + */ + public function setRoot($root) + { + $this->_root = $root; + return $this; + } + + /** + * Sets OpenID extension(s) + * + * @param mixed $extensions + * @return Zend\Authentication\Adapter\OpenId Provides a fluent interface + */ + public function setExtensions($extensions) + { + $this->_extensions = $extensions; + return $this; + } + + /** + * Sets an optional response object to perform HTTP or HTML form redirection + * + * @param string $root + * @return Zend\Authentication\Adapter\OpenId Provides a fluent interface + */ + public function setResponse($response) + { + $this->_response = $response; + return $this; + } + + /** + * Enables or disables interaction with user during authentication on + * OpenID provider. + * + * @param bool $check_immediate + * @return Zend\Authentication\Adapter\OpenId Provides a fluent interface + */ + public function setCheckImmediate($check_immediate) + { + $this->_check_immediate = $check_immediate; + return $this; + } + + /** + * Sets HTTP client object to make HTTP requests + * + * @param Zend\HTTP\Client $client HTTP client object to be used + */ + public function setHttpClient($client) + { + $this->_httpClient = $client; + } + + /** + * Authenticates the given OpenId identity. + * Defined by Zend_Auth_Adapter_Interface. + * + * @throws Zend\Authentication\Adapter\Exception If answering the authentication query is impossible + * @return Zend\Authentication\Result + */ + public function authenticate() { + $id = $this->_id; + if (!empty($id)) { + $consumer = new \Zend_OpenId_Consumer($this->_storage); + $consumer->setHttpClient($this->_httpClient); + /* login() is never returns on success */ + if (!$this->_check_immediate) { + if (!$consumer->login($id, + $this->_returnTo, + $this->_root, + $this->_extensions, + $this->_response)) { + return new AuthenticationResult( + AuthenticationResult::FAILURE, + $id, + array("Authentication failed", $consumer->getError())); + } + } else { + if (!$consumer->check($id, + $this->_returnTo, + $this->_root, + $this->_extensions, + $this->_response)) { + return new AuthenticationResult( + AuthenticationResult::FAILURE, + $id, + array("Authentication failed", $consumer->getError())); + } + } + } else { + $params = (isset($_SERVER['REQUEST_METHOD']) && + $_SERVER['REQUEST_METHOD']=='POST') ? $_POST: $_GET; + $consumer = new \Zend_OpenId_Consumer($this->_storage); + $consumer->setHttpClient($this->_httpClient); + if ($consumer->verify( + $params, + $id, + $this->_extensions)) { + return new AuthenticationResult( + AuthenticationResult::SUCCESS, + $id, + array("Authentication successful")); + } else { + return new AuthenticationResult( + AuthenticationResult::FAILURE, + $id, + array("Authentication failed", $consumer->getError())); + } + } + } +} diff --git a/src/AuthenticationService.php b/src/AuthenticationService.php new file mode 100644 index 0000000..0bae2e7 --- /dev/null +++ b/src/AuthenticationService.php @@ -0,0 +1,144 @@ +setStorage($storage); + } + } + + /** + * Returns the persistent storage handler + * + * Session storage is used by default unless a different storage adapter has been set. + * + * @return Zend\Authentication\Storage + */ + public function getStorage() + { + if (null === $this->_storage) { + $this->setStorage(new Storage\Session()); + } + + return $this->_storage; + } + + /** + * Sets the persistent storage handler + * + * @param Zend\Authentication\Storage $storage + * @return Zend\Authentication\AuthenticationService Provides a fluent interface + */ + public function setStorage(Storage $storage) + { + $this->_storage = $storage; + return $this; + } + + /** + * Authenticates against the supplied adapter + * + * @param Zend\Authentication\Adapter $adapter + * @return Zend\Authentication\Result + */ + public function authenticate(Adapter $adapter) + { + $result = $adapter->authenticate(); + + /** + * ZF-7546 - prevent multiple succesive calls from storing inconsistent results + * Ensure storage has clean state + */ + if ($this->hasIdentity()) { + $this->clearIdentity(); + } + + if ($result->isValid()) { + $this->getStorage()->write($result->getIdentity()); + } + + return $result; + } + + /** + * Returns true if and only if an identity is available from storage + * + * @return boolean + */ + public function hasIdentity() + { + return !$this->getStorage()->isEmpty(); + } + + /** + * Returns the identity from storage or null if no identity is available + * + * @return mixed|null + */ + public function getIdentity() + { + $storage = $this->getStorage(); + + if ($storage->isEmpty()) { + return null; + } + + return $storage->read(); + } + + /** + * Clears the identity from persistent storage + * + * @return void + */ + public function clearIdentity() + { + $this->getStorage()->clear(); + } +} diff --git a/src/Exception.php b/src/Exception.php new file mode 100644 index 0000000..8268399 --- /dev/null +++ b/src/Exception.php @@ -0,0 +1,35 @@ + self::SUCCESS ) { + $code = 1; + } + + $this->_code = $code; + $this->_identity = $identity; + $this->_messages = $messages; + } + + /** + * Returns whether the result represents a successful authentication attempt + * + * @return boolean + */ + public function isValid() + { + return ($this->_code > 0) ? true : false; + } + + /** + * getCode() - Get the result code for this authentication attempt + * + * @return int + */ + public function getCode() + { + return $this->_code; + } + + /** + * Returns the identity used in the authentication attempt + * + * @return mixed + */ + public function getIdentity() + { + return $this->_identity; + } + + /** + * Returns an array of string reasons why the authentication attempt was unsuccessful + * + * If authentication was successful, this method returns an empty array. + * + * @return array + */ + public function getMessages() + { + return $this->_messages; + } +} diff --git a/src/Storage.php b/src/Storage.php new file mode 100644 index 0000000..d8c2fc8 --- /dev/null +++ b/src/Storage.php @@ -0,0 +1,71 @@ +_data); + } + + /** + * Returns the contents of storage + * Behavior is undefined when storage is empty. + * + * @return mixed + */ + public function read() + { + return $this->_data; + } + + /** + * Writes $contents to storage + * + * @param mixed $contents + * @return void + */ + public function write($contents) + { + $this->_data = $contents; + } + + /** + * Clears contents from storage + * + * @return void + */ + public function clear() + { + $this->_data = null; + } +} diff --git a/src/Storage/Session.php b/src/Storage/Session.php new file mode 100644 index 0000000..6209315 --- /dev/null +++ b/src/Storage/Session.php @@ -0,0 +1,149 @@ +_namespace = $namespace; + $this->_member = $member; + $this->_session = new SessionContainer($this->_namespace, $manager); + } + + /** + * Returns the session namespace + * + * @return string + */ + public function getNamespace() + { + return $this->_namespace; + } + + /** + * Returns the name of the session object member + * + * @return string + */ + public function getMember() + { + return $this->_member; + } + + /** + * Defined by Zend\Auth\Storage + * + * @return boolean + */ + public function isEmpty() + { + return !isset($this->_session->{$this->_member}); + } + + /** + * Defined by Zend\Auth\Storage + * + * @return mixed + */ + public function read() + { + return $this->_session->{$this->_member}; + } + + /** + * Defined by Zend\Auth\Storage + * + * @param mixed $contents + * @return void + */ + public function write($contents) + { + $this->_session->{$this->_member} = $contents; + } + + /** + * Defined by Zend\Auth\Storage + * + * @return void + */ + public function clear() + { + unset($this->_session->{$this->_member}); + } +} diff --git a/test/Adapter/DbTableTest.php b/test/Adapter/DbTableTest.php new file mode 100644 index 0000000..c34cf0d --- /dev/null +++ b/test/Adapter/DbTableTest.php @@ -0,0 +1,367 @@ +markTestSkipped('Tests are not enabled in TestConfiguration.php'); + return; + } elseif (!extension_loaded('pdo')) { + $this->markTestSkipped('PDO extension is not loaded'); + return; + } elseif (!in_array('sqlite', \PDO::getAvailableDrivers())) { + $this->markTestSkipped('SQLite PDO driver is not available'); + return; + } + + $this->_setupDbAdapter(); + $this->_setupAuthAdapter(); + } + + public function tearDown() + { + $this->_adapter = null; + if ($this->_db instanceof \Zend_Db_Adapter_Abstract) { + $this->_db->query('DROP TABLE [users]'); + } + $this->_db = null; + } + + /** + * Ensures expected behavior for authentication success + * + * @return void + */ + public function testAuthenticateSuccess() + { + $this->_adapter->setIdentity('my_username'); + $this->_adapter->setCredential('my_password'); + $result = $this->_adapter->authenticate(); + $this->assertTrue($result->isValid()); + } + + /** + * Ensures expected behavior for authentication success + * + * @return void + */ + public function testAuthenticateSuccessWithTreatment() + { + $this->_adapter = new Adapter\DbTable($this->_db, 'users', 'username', 'password', '?'); + $this->_adapter->setIdentity('my_username'); + $this->_adapter->setCredential('my_password'); + $result = $this->_adapter->authenticate(); + $this->assertTrue($result->isValid()); + } + + /** + * Ensures expected behavior for for authentication failure + * reason: Identity not found. + * + */ + public function testAuthenticateFailureIdentityNotFound() + { + $this->_adapter->setIdentity('non_existent_username'); + $this->_adapter->setCredential('my_password'); + + try { + $result = $this->_adapter->authenticate(); + $this->assertEquals(Authentication\Result::FAILURE_IDENTITY_NOT_FOUND, $result->getCode()); + } catch (Authentication\Exception $e) { + $this->fail('Exception should have been thrown'); + } + } + + /** + * Ensures expected behavior for for authentication failure + * reason: Identity not found. + * + */ + public function testAuthenticateFailureIdentityAmbigious() + { + $sql_insert = 'INSERT INTO users (username, password, real_name) VALUES ("my_username", "my_password", "My Real Name")'; + $this->_db->query($sql_insert); + + $this->_adapter->setIdentity('my_username'); + $this->_adapter->setCredential('my_password'); + + try { + $result = $this->_adapter->authenticate(); + $this->assertEquals(Authentication\Result::FAILURE_IDENTITY_AMBIGUOUS, $result->getCode()); + } catch (Authentication\Exception $e) { + $this->fail('Exception should have been thrown'); + } + } + + /** + * Ensures expected behavior for authentication failure because of a bad password + * + * @return void + */ + public function testAuthenticateFailureInvalidCredential() + { + $this->_adapter->setIdentity('my_username'); + $this->_adapter->setCredential('my_password_bad'); + $result = $this->_adapter->authenticate(); + $this->assertFalse($result->isValid()); + } + + /** + * Ensures that getResultRowObject() works for successful authentication + * + * @return void + */ + public function testGetResultRow() + { + $this->_adapter->setIdentity('my_username'); + $this->_adapter->setCredential('my_password'); + $result = $this->_adapter->authenticate(); + $resultRow = $this->_adapter->getResultRowObject(); + $this->assertEquals($resultRow->username, 'my_username'); + } + + /** + * Ensure that ResultRowObject returns only what told to be included + * + */ + public function testGetSpecificResultRow() + { + $this->_adapter->setIdentity('my_username'); + $this->_adapter->setCredential('my_password'); + $result = $this->_adapter->authenticate(); + $resultRow = $this->_adapter->getResultRowObject(array('username', 'real_name')); + $this->assertEquals('O:8:"stdClass":2:{s:8:"username";s:11:"my_username";s:9:"real_name";s:12:"My Real Name";}', serialize($resultRow)); + } + + /** + * Ensure that ResultRowObject returns an object has specific omissions + * + */ + public function testGetOmittedResultRow() + { + $this->_adapter->setIdentity('my_username'); + $this->_adapter->setCredential('my_password'); + $result = $this->_adapter->authenticate(); + $resultRow = $this->_adapter->getResultRowObject(null, 'password'); + $this->assertEquals('O:8:"stdClass":3:{s:2:"id";s:1:"1";s:8:"username";s:11:"my_username";s:9:"real_name";s:12:"My Real Name";}', serialize($resultRow)); + } + + /** + * @group ZF-5957 + */ + public function testAdapterCanReturnDbSelectObject() + { + $this->assertTrue($this->_adapter->getDbSelect() instanceof \Zend_Db_Select); + } + + /** + * @group ZF-5957 + */ + public function testAdapterCanUseModifiedDbSelectObject() + { + $this->_db->getProfiler()->setEnabled(true); + $select = $this->_adapter->getDbSelect(); + $select->where('1 = 1'); + $this->_adapter->setIdentity('my_username'); + $this->_adapter->setCredential('my_password'); + $this->_adapter->authenticate(); + $profiler = $this->_db->getProfiler(); + $this->assertEquals( + 'SELECT "users".*, (CASE WHEN "password" = \'my_password\' THEN 1 ELSE 0 END) AS "zend_auth_credential_match" FROM "users" WHERE (1 = 1) AND ("username" = \'my_username\')', + $profiler->getLastQueryProfile()->getQuery() + ); + } + + /** + * @group ZF-5957 + */ + public function testAdapterReturnsASelectObjectWithoutAuthTimeModificationsAfterAuth() + { + $select = $this->_adapter->getDbSelect(); + $select->where('1 = 1'); + $this->_adapter->setIdentity('my_username'); + $this->_adapter->setCredential('my_password'); + $this->_adapter->authenticate(); + $selectAfterAuth = $this->_adapter->getDbSelect(); + $whereParts = $selectAfterAuth->getPart(\Zend_Db_Select::WHERE); + $this->assertEquals(1, count($whereParts)); + $this->assertEquals('(1 = 1)', array_pop($whereParts)); + } + + /** + * Ensure that exceptions are caught + * + * @expectedException Zend\Authentication\Exception + */ + public function testCatchExceptionNoTable() + { + $adapter = new Adapter\DbTable($this->_db); + $result = $adapter->authenticate(); + // $this->assertEquals($e->getMessage(), 'A table must be supplied for the Zend_Auth_Adapter_DbTable authentication adapter.'); + } + + /** + * Ensure that exceptions are caught + * + * @expectedException Zend\Authentication\Exception + */ + public function testCatchExceptionNoIdentityColumn() + { + $adapter = new Adapter\DbTable($this->_db, 'users'); + $result = $adapter->authenticate(); + // $this->assertEquals($e->getMessage(), 'An identity column must be supplied for the Zend_Auth_Adapter_DbTable authentication adapter.'); + } + + /** + * Ensure that exceptions are caught + * + * @expectedException Zend\Authentication\Exception + */ + public function testCatchExceptionNoCredentialColumn() + { + $adapter = new Adapter\DbTable($this->_db, 'users', 'username'); + $result = $adapter->authenticate(); + // $this->assertEquals($e->getMessage(), 'A credential column must be supplied for the Zend_Auth_Adapter_DbTable authentication adapter.'); + } + + /** + * Ensure that exceptions are caught + * + * @expectedException Zend\Authentication\Exception + */ + public function testCatchExceptionNoIdentity() + { + $result = $this->_adapter->authenticate(); + // $this->assertEquals($e->getMessage(), 'A value for the identity was not provided prior to authentication with Zend_Auth_Adapter_DbTable.'); + } + + /** + * Ensure that exceptions are caught + * + * @expectedException Zend\Authentication\Exception + */ + public function testCatchExceptionNoCredential() + { + $this->_adapter->setIdentity('my_username'); + $result = $this->_adapter->authenticate(); + // $this->assertEquals($e->getMessage(), 'A credential value was not provided prior to authentication with Zend_Auth_Adapter_DbTable.'); + } + + /** + * Ensure that exceptions are caught + * + * @expectedException Zend\Authentication\Exception + */ + public function testCatchExceptionBadSql() + { + $this->_adapter->setTableName('bad_table_name'); + $this->_adapter->setIdentity('value'); + $this->_adapter->setCredential('value'); + $result = $this->_adapter->authenticate(); + // $this->assertEquals($e->getMessage(), 'The supplied parameters to Zend_Auth_Adapter_DbTable failed to produce a valid sql statement, please check table and column names for validity.'); + } + + /** + * + * @group ZF-3068 + */ + public function testDbTableAdapterUsesCaseFolding() + { + $this->tearDown(); + $this->_setupDbAdapter(array(\Zend_Db::CASE_FOLDING => \Zend_Db::CASE_UPPER)); + $this->_setupAuthAdapter(); + + $this->_adapter->setIdentity('my_username'); + $this->_adapter->setCredential('my_password'); + $this->_db->foldCase(\Zend_Db::CASE_UPPER); + $this->_adapter->authenticate(); + } + + protected function _setupDbAdapter($optionalParams = array()) + { + $params = array('dbname' => TESTS_ZEND_AUTH_ADAPTER_DBTABLE_PDO_SQLITE_DATABASE); + + if (!empty($optionalParams)) { + $params['options'] = $optionalParams; + } + + $this->_db = new \Zend_Db_Adapter_Pdo_Sqlite($params); + + $sqlCreate = 'CREATE TABLE [users] ( ' + . '[id] INTEGER NOT NULL PRIMARY KEY, ' + . '[username] VARCHAR(50) NOT NULL, ' + . '[password] VARCHAR(32) NULL, ' + . '[real_name] VARCHAR(150) NULL)'; + $this->_db->query($sqlCreate); + + $sqlInsert = 'INSERT INTO users (username, password, real_name) ' + . 'VALUES ("my_username", "my_password", "My Real Name")'; + $this->_db->query($sqlInsert); + } + + protected function _setupAuthAdapter() + { + $this->_adapter = new Adapter\DbTable($this->_db, 'users', 'username', 'password'); + } +} diff --git a/test/Adapter/DigestTest.php b/test/Adapter/DigestTest.php new file mode 100644 index 0000000..9f2070e --- /dev/null +++ b/test/Adapter/DigestTest.php @@ -0,0 +1,246 @@ +_filesPath = __DIR__ . '/TestAsset/Digest'; + } + + /** + * Ensures that the adapter throws an exception when authentication is attempted before + * setting a required option + * + * @return void + */ + public function testOptionRequiredException() + { + $adapter = new Adapter\Digest(); + try { + $adapter->authenticate(); + $this->fail('Expected Zend_Auth_Adapter_Exception not thrown upon authentication attempt before setting ' + . 'a required option'); + } catch (Adapter\Exception $e) { + $this->assertContains('must be set before authentication', $e->getMessage()); + } + } + + /** + * Ensures that an exception is thrown upon authenticating against a nonexistent file + * + * @return void + */ + public function testFileNonExistentException() + { + $adapter = new Adapter\Digest('nonexistent', 'realm', 'username', 'password'); + try { + $adapter->authenticate(); + $this->fail('Expected Zend_Auth_Adapter_Exception not thrown upon authenticating against nonexistent ' + . 'file'); + } catch (Adapter\Exception $e) { + $this->assertContains('Cannot open', $e->getMessage()); + } + } + + /** + * Ensures expected behavior upon realm not found for existing user + * + * @return void + */ + public function testUserExistsRealmNonexistent() + { + $filename = "$this->_filesPath/htdigest.1"; + $realm = 'Nonexistent Realm'; + $username = 'someUser'; + $password = 'somePassword'; + + $adapter = new Adapter\Digest($filename, $realm, $username, $password); + + $result = $adapter->authenticate(); + + $this->assertFalse($result->isValid()); + + $messages = $result->getMessages(); + $this->assertEquals(1, count($messages)); + $this->assertEquals($result->getCode(), Authentication\Result::FAILURE_IDENTITY_NOT_FOUND); + $this->assertContains('combination not found', $messages[0]); + + $identity = $result->getIdentity(); + $this->assertEquals($identity['realm'], $realm); + $this->assertEquals($identity['username'], $username); + } + + /** + * Ensures expected behavior upon user not found in existing realm + * + * @return void + */ + public function testUserNonexistentRealmExists() + { + $filename = "$this->_filesPath/htdigest.1"; + $realm = 'Some Realm'; + $username = 'nonexistentUser'; + $password = 'somePassword'; + + $adapter = new Adapter\Digest($filename, $realm, $username, $password); + + $result = $adapter->authenticate(); + + $this->assertFalse($result->isValid()); + $this->assertEquals($result->getCode(), Authentication\Result::FAILURE_IDENTITY_NOT_FOUND); + + $messages = $result->getMessages(); + $this->assertEquals(1, count($messages)); + $this->assertContains('combination not found', $messages[0]); + + $identity = $result->getIdentity(); + $this->assertEquals($identity['realm'], $realm); + $this->assertEquals($identity['username'], $username); + } + + /** + * Ensures expected behavior upon incorrect password + * + * @return void + */ + public function testIncorrectPassword() + { + $filename = "$this->_filesPath/htdigest.1"; + $realm = 'Some Realm'; + $username = 'someUser'; + $password = 'incorrectPassword'; + + $adapter = new Adapter\Digest($filename, $realm, $username, $password); + + $result = $adapter->authenticate(); + + $this->assertFalse($result->isValid()); + $this->assertEquals($result->getCode(), Authentication\Result::FAILURE_CREDENTIAL_INVALID); + + $messages = $result->getMessages(); + $this->assertEquals(1, count($messages)); + $this->assertContains('Password incorrect', $messages[0]); + + $identity = $result->getIdentity(); + $this->assertEquals($identity['realm'], $realm); + $this->assertEquals($identity['username'], $username); + } + + /** + * Ensures that successful authentication works as expected + * + * @return void + */ + public function testAuthenticationSuccess() + { + $filename = "$this->_filesPath/htdigest.1"; + $realm = 'Some Realm'; + $username = 'someUser'; + $password = 'somePassword'; + + $adapter = new Adapter\Digest($filename, $realm, $username, $password); + + $result = $adapter->authenticate(); + + $this->assertTrue($result->isValid()); + $this->assertEquals($result->getCode(), Authentication\Result::SUCCESS); + + $this->assertEquals(array(), $result->getMessages()); + + $identity = $result->getIdentity(); + $this->assertEquals($identity['realm'], $realm); + $this->assertEquals($identity['username'], $username); + } + + /** + * Ensures that getFilename() returns expected default value + * + * @return void + */ + public function testGetFilename() + { + $adapter = new Adapter\Digest(); + $this->assertEquals(null, $adapter->getFilename()); + } + + /** + * Ensures that getRealm() returns expected default value + * + * @return void + */ + public function testGetRealm() + { + $adapter = new Adapter\Digest(); + $this->assertEquals(null, $adapter->getRealm()); + } + + /** + * Ensures that getUsername() returns expected default value + * + * @return void + */ + public function testGetUsername() + { + $adapter = new Adapter\Digest(); + $this->assertEquals(null, $adapter->getUsername()); + } + + /** + * Ensures that getPassword() returns expected default value + * + * @return void + */ + public function testGetPassword() + { + $adapter = new Adapter\Digest(); + $this->assertEquals(null, $adapter->getPassword()); + } +} diff --git a/test/Adapter/HTTP/AuthTest.php b/test/Adapter/HTTP/AuthTest.php new file mode 100644 index 0000000..51ae25e --- /dev/null +++ b/test/Adapter/HTTP/AuthTest.php @@ -0,0 +1,470 @@ +_filesPath = __DIR__ . '/TestAsset'; + $this->_basicResolver = new HTTP\FileResolver("{$this->_filesPath}/htbasic.1"); + $this->_digestResolver = new HTTP\FileResolver("{$this->_filesPath}/htdigest.3"); + $this->_basicConfig = array( + 'accept_schemes' => 'basic', + 'realm' => 'Test Realm' + ); + $this->_digestConfig = array( + 'accept_schemes' => 'digest', + 'realm' => 'Test Realm', + 'digest_domains' => '/ http://localhost/', + 'nonce_timeout' => 300 + ); + $this->_bothConfig = array( + 'accept_schemes' => 'basic digest', + 'realm' => 'Test Realm', + 'digest_domains' => '/ http://localhost/', + 'nonce_timeout' => 300 + ); + } + + public function testBasicChallenge() + { + // Trying to authenticate without sending an Authorization header + // should result in a 401 reply with a Www-Authenticate header, and a + // false result. + + // The expected Basic Www-Authenticate header value + $basic = 'Basic realm="' . $this->_bothConfig['realm'] . '"'; + + $data = $this->_doAuth('', 'basic'); + $this->_checkUnauthorized($data, $basic); + } + + public function testDigestChallenge() + { + // Trying to authenticate without sending an Authorization header + // should result in a 401 reply with a Www-Authenticate header, and a + // false result. + + // The expected Digest Www-Authenticate header value + $digest = $this->_digestChallenge(); + + $data = $this->_doAuth('', 'digest'); + $this->_checkUnauthorized($data, $digest); + } + + public function testBothChallenges() + { + // Trying to authenticate without sending an Authorization header + // should result in a 401 reply with at least one Www-Authenticate + // header, and a false result. + + $data = $this->_doAuth('', 'both'); + extract($data); // $result, $status, $headers + + // The expected Www-Authenticate header values + $basic = 'Basic realm="' . $this->_bothConfig['realm'] . '"'; + $digest = $this->_digestChallenge(); + + // Make sure the result is false + $this->assertType('Zend\\Authentication\\Result', $result); + $this->assertFalse($result->isValid()); + + // Verify the status code and the presence of both challenges + $this->assertEquals(401, $status); + $this->assertEquals('Www-Authenticate', $headers[0]['name']); + $this->assertEquals('Www-Authenticate', $headers[1]['name']); + + // Check to see if the expected challenges match the actual + $this->assertEquals($basic, $headers[0]['value']); + $this->assertEquals($digest, $headers[1]['value']); + } + + public function testBasicAuthValidCreds() + { + // Attempt Basic Authentication with a valid username and password + + $data = $this->_doAuth('Basic ' . base64_encode('Bryce:ThisIsNotMyPassword'), 'basic'); + $this->_checkOK($data); + } + + public function testBasicAuthBadCreds() + { + // Ensure that credentials containing invalid characters are treated as + // a bad username or password. + + // The expected Basic Www-Authenticate header value + $basic = 'Basic realm="' . $this->_basicConfig['realm'] . '"'; + + $data = $this->_doAuth('Basic ' . base64_encode("Bad\tChars:In:Creds"), 'basic'); + $this->_checkUnauthorized($data, $basic); + } + + public function testBasicAuthBadUser() + { + // Attempt Basic Authentication with a nonexistant username and + // password + + // The expected Basic Www-Authenticate header value + $basic = 'Basic realm="' . $this->_basicConfig['realm'] . '"'; + + $data = $this->_doAuth('Basic ' . base64_encode('Nobody:NotValid'), 'basic'); + $this->_checkUnauthorized($data, $basic); + } + + public function testBasicAuthBadPassword() + { + // Attempt Basic Authentication with a valid username, but invalid + // password + + // The expected Basic Www-Authenticate header value + $basic = 'Basic realm="' . $this->_basicConfig['realm'] . '"'; + + $data = $this->_doAuth('Basic ' . base64_encode('Bryce:Invalid'), 'basic'); + $this->_checkUnauthorized($data, $basic); + } + + public function testDigestAuthValidCreds() + { + // Attempt Digest Authentication with a valid username and password + + $data = $this->_doAuth($this->_digestReply('Bryce', 'ThisIsNotMyPassword'), 'digest'); + $this->_checkOK($data); + } + + public function testDigestAuthDefaultAlgo() + { + // If the client omits the aglorithm argument, it should default to MD5, + // and work just as above + + $cauth = $this->_digestReply('Bryce', 'ThisIsNotMyPassword'); + $cauth = preg_replace('/algorithm="MD5", /', '', $cauth); + + $data = $this->_doAuth($cauth, 'digest'); + $this->_checkOK($data); + } + + public function testDigestAuthQuotedNC() + { + // The nonce count isn't supposed to be quoted, but apparently some + // clients do anyway. + + $cauth = $this->_digestReply('Bryce', 'ThisIsNotMyPassword'); + $cauth = preg_replace('/nc=00000001/', 'nc="00000001"', $cauth); + + $data = $this->_doAuth($cauth, 'digest'); + $this->_checkOK($data); + } + + public function testDigestAuthBadCreds() + { + // Attempt Digest Authentication with a bad username and password + + // The expected Digest Www-Authenticate header value + $digest = $this->_digestChallenge(); + + $data = $this->_doAuth($this->_digestReply('Nobody', 'NotValid'), 'digest'); + $this->_checkUnauthorized($data, $digest); + } + + public function testDigestAuthBadCreds2() + { + // Formerly, a username with invalid characters would result in a 400 + // response, but now should result in 401 response. + + // The expected Digest Www-Authenticate header value + $digest = $this->_digestChallenge(); + + $data = $this->_doAuth($this->_digestReply('Bad:chars', 'NotValid'), 'digest'); + $this->_checkUnauthorized($data, $digest); + } + + public function testDigestTampered() + { + // Create the tampered header value + $tampered = $this->_digestReply('Bryce', 'ThisIsNotMyPassword'); + $tampered = preg_replace( + '/ nonce="[a-fA-F0-9]{32}", /', + ' nonce="'.str_repeat('0', 32).'", ', + $tampered + ); + + // The expected Digest Www-Authenticate header value + $digest = $this->_digestChallenge(); + + $data = $this->_doAuth($tampered, 'digest'); + $this->_checkUnauthorized($data, $digest); + } + + public function testBadSchemeRequest() + { + // Sending a request for an invalid authentication scheme should result + // in a 400 Bad Request response. + + $data = $this->_doAuth('Invalid ' . base64_encode('Nobody:NotValid'), 'basic'); + $this->_checkBadRequest($data); + } + + public function testBadDigestRequest() + { + // If any of the individual parts of the Digest Authorization header + // are bad, it results in a 400 Bad Request. But that's a lot of + // possibilities, so we're just going to pick one for now. + $bad = $this->_digestReply('Bryce', 'ThisIsNotMyPassword'); + $bad = preg_replace( + '/realm="([^"]+)"/', // cut out the realm + '', $bad + ); + + $data = $this->_doAuth($bad, 'digest'); + $this->_checkBadRequest($data); + } + + /** + * Acts like a client sending the given Authenticate header value. + * + * @param string $clientHeader Authenticate header value + * @param string $scheme Which authentication scheme to use + * @return array Containing the result, response headers, and the status + */ + protected function _doAuth($clientHeader, $scheme) + { + // Set up stub request and response objects + $request = $this->getMock('Zend_Controller_Request_Http'); + $response = new \Zend_Controller_Response_Http; + $response->setHttpResponseCode(200); + $response->headersSentThrowsException = false; + + // Set stub method return values + $request->expects($this->any()) + ->method('getRequestUri') + ->will($this->returnValue('/')); + $request->expects($this->any()) + ->method('getMethod') + ->will($this->returnValue('GET')); + $request->expects($this->any()) + ->method('getServer') + ->will($this->returnValue('PHPUnit')); + $request->expects($this->any()) + ->method('getHeader') + ->will($this->returnValue($clientHeader)); + + // Select an Authentication scheme + switch ($scheme) { + case 'basic': + $use = $this->_basicConfig; + break; + case 'digest': + $use = $this->_digestConfig; + break; + case 'both': + default: + $use = $this->_bothConfig; + } + + // Create the HTTP Auth adapter + $a = new HTTP($use); + $a->setBasicResolver($this->_basicResolver); + $a->setDigestResolver($this->_digestResolver); + + // Send the authentication request + $a->setRequest($request); + $a->setResponse($response); + $result = $a->authenticate(); + + $return = array( + 'result' => $result, + 'status' => $response->getHttpResponseCode(), + 'headers' => $response->getHeaders() + ); + return $return; + } + + /** + * Constructs a local version of the digest challenge we expect to receive + * + * @return string + */ + protected function _digestChallenge() + { + $timeout = ceil(time() / 300) * 300; + $nonce = md5($timeout . ':PHPUnit:Zend\\Authentication\\Adapter\\HTTP'); + $opaque = md5('Opaque Data:Zend\\Authentication\\Adapter\\HTTP'); + $wwwauth = 'Digest ' + . 'realm="' . $this->_digestConfig['realm'] . '", ' + . 'domain="' . $this->_digestConfig['digest_domains'] . '", ' + . 'nonce="' . $nonce . '", ' + . 'opaque="' . $opaque . '", ' + . 'algorithm="MD5", ' + . 'qop="auth"'; + + return $wwwauth; + } + + /** + * Constructs a client digest Authorization header + * + * @return string + */ + protected function _digestReply($user, $pass) + { + $nc = '00000001'; + $timeout = ceil(time() / 300) * 300; + $nonce = md5($timeout . ':PHPUnit:Zend\Authentication\Adapter\HTTP'); + $opaque = md5('Opaque Data:Zend\\Authentication\\Adapter\\HTTP'); + $cnonce = md5('cnonce'); + $response = md5(md5($user . ':' . $this->_digestConfig['realm'] . ':' . $pass) . ":$nonce:$nc:$cnonce:auth:" + . md5('GET:/')); + $cauth = 'Digest ' + . 'username="Bryce", ' + . 'realm="' . $this->_digestConfig['realm'] . '", ' + . 'nonce="' . $nonce . '", ' + . 'uri="/", ' + . 'response="' . $response . '", ' + . 'algorithm="MD5", ' + . 'cnonce="' . $cnonce . '", ' + . 'opaque="' . $opaque . '", ' + . 'qop="auth", ' + . 'nc=' . $nc; + + return $cauth; + } + + /** + * Checks for an expected 401 Unauthorized response + * + * @param array $data Authentication results + * @param string $expected Expected Www-Authenticate header value + * @return void + */ + protected function _checkUnauthorized($data, $expected) + { + extract($data); // $result, $status, $headers + + // Make sure the result is false + $this->assertType('Zend\\Authentication\\Result', $result); + $this->assertFalse($result->isValid()); + + // Verify the status code and the presence of the challenge + $this->assertEquals(401, $status); + $this->assertEquals('Www-Authenticate', $headers[0]['name']); + + // Check to see if the expected challenge matches the actual + $this->assertEquals($expected, $headers[0]['value']); + } + + /** + * Checks for an expected 200 OK response + * + * @param array $data Authentication results + * @return void + */ + protected function _checkOK($data) + { + extract($data); // $result, $status, $headers + + // Make sure the result is true + $this->assertType('Zend\\Authentication\\Result', $result); + $this->assertTrue($result->isValid(), var_export($result, 1)); + + // Verify we got a 200 response + $this->assertEquals(200, $status); + } + + /** + * Checks for an expected 400 Bad Request response + * + * @param array $data Authentication results + * @return void + */ + protected function _checkBadRequest($data) + { + extract($data); // $result, $status, $headers + + // Make sure the result is false + $this->assertType('Zend\\Authentication\\Result', $result); + $this->assertFalse($result->isValid()); + + // Make sure it set the right HTTP code + $this->assertEquals(400, $status); + } +} diff --git a/test/Adapter/HTTP/FileResolverTest.php b/test/Adapter/HTTP/FileResolverTest.php new file mode 100644 index 0000000..987c4b1 --- /dev/null +++ b/test/Adapter/HTTP/FileResolverTest.php @@ -0,0 +1,247 @@ +_filesPath = __DIR__ . '/TestAsset'; + $this->_validPath = "$this->_filesPath/htdigest.3"; + $this->_badPath = 'doesnotexist'; + $this->_resolver = new HTTP\FileResolver($this->_validPath); + } + + /** + * Ensures that setFile() works as expected for valid input + * + * @return void + */ + public function testSetFileValid() + { + $this->_resolver->setFile($this->_validPath); + $this->assertEquals($this->_validPath, $this->_resolver->getFile()); + } + + /** + * Ensures that setFile() works as expected for invalid input + * + * @return void + */ + public function testSetFileInvalid() + { + $this->setExpectedException('Zend\\Authentication\\Adapter\\HTTP\\Exception', 'Path not readable'); + $this->_resolver->setFile($this->_badPath); + } + + /** + * Ensures that __construct() works as expected for valid input + * + * @return void + */ + public function testConstructValid() + { + $v = new HTTP\FileResolver($this->_validPath); + $this->assertEquals($this->_validPath, $v->getFile()); + } + + /** + * Ensures that __construct() works as expected for invalid input + * + * @return void + */ + public function testConstructInvalid() + { + $this->setExpectedException('Zend\\Authentication\\Adapter\\HTTP\\Exception', 'Path not readable'); + $v = new HTTP\FileResolver($this->_badPath); + } + + /** + * Ensures that resolve() works as expected for empty username + * + * @return void + */ + public function testResolveUsernameEmpty() + { + $this->setExpectedException('Zend\\Authentication\\Adapter\\HTTP\\Exception', 'Username is required'); + $this->_resolver->resolve('', ''); + } + + /** + * Ensures that resolve() works as expected for empty realm + * + * @return void + */ + public function testResolveRealmEmpty() + { + $this->setExpectedException('Zend\\Authentication\\Adapter\\HTTP\\Exception', 'Realm is required'); + $this->_resolver->resolve('username', ''); + } + + /** + * Ensures that resolve() works as expected for invalid username + * + * @return void + */ + public function testResolveUsernameInvalid() + { + try { + $this->_resolver->resolve('bad:name', 'realm'); + $this->fail('Accepted malformed username with colon'); + } catch (HTTP\Exception $e) { + $this->assertContains('Username must consist', $e->getMessage()); + } + try { + $this->_resolver->resolve("badname\n", 'realm'); + $this->fail('Accepted malformed username with newline'); + } catch (HTTP\Exception $e) { + $this->assertContains('Username must consist', $e->getMessage()); + } + } + + /** + * Ensures that resolve() works as expected for invalid realm + * + * @return void + */ + public function testResolveRealmInvalid() + { + try { + $this->_resolver->resolve('username', 'bad:realm'); + $this->fail('Accepted malformed realm with colon'); + } catch (HTTP\Exception $e) { + $this->assertContains('Realm must consist', $e->getMessage()); + } + try { + $this->_resolver->resolve('username', "badrealm\n"); + $this->fail('Accepted malformed realm with newline'); + } catch (HTTP\Exception $e) { + $this->assertContains('Realm must consist', $e->getMessage()); + } + } + + /** + * Ensures that resolve() works as expected when a previously readable file becomes unreadable + * + * @return void + */ + public function testResolveFileDisappearsMystery() + { + if (rename("$this->_filesPath/htdigest.3", "$this->_filesPath/htdigest.3.renamed")) { + try { + $this->_resolver->resolve('username', 'realm'); + $this->fail('Expected thrown exception upon resolve() after moving valid file'); + } catch (HTTP\Exception $e) { + $this->assertContains('Unable to open password file', $e->getMessage()); + } + rename("$this->_filesPath/htdigest.3.renamed", "$this->_filesPath/htdigest.3"); + } + } + + /** + * Ensures that resolve() works as expected when provided valid credentials + * + * @return void + */ + public function testResolveValid() + { + $this->assertEquals( + $this->_resolver->resolve('Bryce', 'Test Realm'), + 'd5b7c330d5685beb782a9e22f0f20579', + 'Rejected valid credentials' + ); + } + + /** + * Ensures that resolve() works as expected when provided nonexistent realm + * + * @return void + */ + public function testResolveRealmNonexistent() + { + $this->assertFalse( + $this->_resolver->resolve('Bryce', 'nonexistent'), + 'Accepted a valid user in the wrong realm' + ); + } + + /** + * Ensures that resolve() works as expected when provided nonexistent user + * + * @return void + */ + public function testResolveUserNonexistent() + { + $this->assertFalse( + $this->_resolver->resolve('nonexistent', 'Test Realm'), + 'Accepted a nonexistent user from an existing realm' + ); + } +} diff --git a/test/Adapter/HTTP/ObjectTest.php b/test/Adapter/HTTP/ObjectTest.php new file mode 100644 index 0000000..71aed03 --- /dev/null +++ b/test/Adapter/HTTP/ObjectTest.php @@ -0,0 +1,273 @@ +_filesPath = __DIR__ . '/TestAsset'; + $this->_basicResolver = new HTTP\FileResolver("$this->_filesPath/htbasic.1"); + $this->_digestResolver = new HTTP\FileResolver("$this->_filesPath/htdigest.3"); + $this->_basicConfig = array( + 'accept_schemes' => 'basic', + 'realm' => 'Test Realm' + ); + $this->_digestConfig = array( + 'accept_schemes' => 'digest', + 'realm' => 'Test Realm', + 'digest_domains' => '/ http://localhost/', + 'nonce_timeout' => 300 + ); + $this->_bothConfig = array( + 'accept_schemes' => 'basic digest', + 'realm' => 'Test Realm', + 'digest_domains' => '/ http://localhost/', + 'nonce_timeout' => 300 + ); + } + + public function testValidConfigs() + { + try { + $t = new Adapter\HTTP($this->_basicConfig); + } catch (Adapter\Exception $e) { + $this->fail('Valid config deemed invalid'); + } + $this->assertFalse(empty($t)); + $this->assertType('Zend\\Authentication\\Adapter\\HTTP', $t); + unset($t); + + try { + $t = new Adapter\HTTP($this->_digestConfig); + } catch (Adapter\Exception $e) { + $this->fail('Valid config deemed invalid'); + } + $this->assertFalse(empty($t)); + $this->assertType('Zend\\Authentication\\Adapter\\HTTP', $t); + unset($t); + + try { + $t = new Adapter\HTTP($this->_bothConfig); + } catch (Adapter\Exception $e) { + $this->fail('Valid config deemed invalid'); + } + $this->assertFalse(empty($t)); + $this->assertType('Zend\\Authentication\\Adapter\\HTTP', $t); + unset($t); + } + + public function testInvalidConfigs() + { + $badConfigs = array( + 'bad1' => array( + 'auth_type' => 'bogus', + 'realm' => 'Test Realm' + ), + 'bad2' => array( + 'auth_type' => 'digest', + 'realm' => 'Bad: "Chars"'."\n", + 'digest_domains' => '/ /admin', + 'nonce_timeout' => 300 + ), + 'bad3' => array( + 'auth_type' => 'digest', + 'realm' => 'Test Realm', + 'digest_domains' => 'no"quotes'."\tor tabs", + 'nonce_timeout' => 300 + ), + 'bad4' => array( + 'auth_type' => 'digest', + 'realm' => 'Test Realm', + 'digest_domains' => '/ /admin', + 'nonce_timeout' => 'junk' + ) + ); + + foreach ($badConfigs as $cfg) { + $t = null; + try { + $t = new Adapter\HTTP($cfg); + $this->fail('Accepted an invalid config'); + } catch (Adapter\Exception $e) { + // Good, it threw an exception + } + } + } + + public function testAuthenticateArgs() + { + $a = new Adapter\HTTP($this->_basicConfig); + + try { + $a->authenticate(); + $this->fail('Attempted authentication without request/response objects'); + } catch (Adapter\Exception $e) { + // Good, it threw an exception + } + + $request = $this->getMock('Zend_Controller_Request_Http'); + $response = $this->getMock('Zend_Controller_Response_Http'); + + // If this throws an exception, it fails + $a->setRequest($request) + ->setResponse($response) + ->authenticate(); + } + + public function testNoResolvers() + { + $request = $this->getMock('Zend_Controller_Request_Http'); + $response = $this->getMock('Zend_Controller_Response_Http'); + + // Stub request for Basic auth + $request->expects($this->any()) + ->method('getHeader') + ->will($this->returnValue('Basic _basicConfig); + $a->setRequest($request) + ->setResponse($response); + $result = $a->authenticate(); + $this->fail("Tried Basic authentication without a resolver.\n" . \Zend\Debug::dump($result->getMessages(),null,false)); + } catch (Adapter\Exception $e) { + // Good, it threw an exception + unset($a); + } + + // Stub request for Digest auth, must be reseted (recreated) + $request = $this->getMock('Zend_Controller_Request_Http'); + $request->expects($this->any()) + ->method('getHeader') + ->will($this->returnValue('Digest _digestConfig); + $a->setRequest($request) + ->setResponse($response); + $result = $a->authenticate(); + $this->fail("Tried Digest authentication without a resolver.\n" . \Zend\Debug::dump($result->getMessages(),null,false)); + } catch (Adapter\Exception $e) { + // Good, it threw an exception + unset($a); + } + } + + public function testWrongResolverUsed() + { + $response = $this->getMock('Zend_Controller_Response_Http'); + $request = $this->getMock('Zend_Controller_Request_Http'); + $request->expects($this->any()) + ->method('getHeader') + ->will($this->returnValue('Basic _digestConfig); + $a->setDigestResolver($this->_digestResolver) + ->setRequest($request) + ->setResponse($response); + $result = $a->authenticate(); + $this->assertEquals($result->getCode(),Authentication\Result::FAILURE_CREDENTIAL_INVALID); + } + + public function testUnsupportedScheme() + { + $response = $this->getMock('Zend_Controller_Response_Http'); + $request = $this->getMock('Zend_Controller_Request_Http'); + $request->expects($this->any()) + ->method('getHeader') + ->will($this->returnValue('NotSupportedScheme _digestConfig); + $a->setDigestResolver($this->_digestResolver) + ->setRequest($request) + ->setResponse($response); + $result = $a->authenticate(); + $this->assertEquals($result->getCode(),Authentication\Result::FAILURE_UNCATEGORIZED); + } +} diff --git a/test/Adapter/HTTP/ProxyTest.php b/test/Adapter/HTTP/ProxyTest.php new file mode 100644 index 0000000..3103355 --- /dev/null +++ b/test/Adapter/HTTP/ProxyTest.php @@ -0,0 +1,463 @@ +_filesPath = __DIR__ . '/TestAsset'; + $this->_basicResolver = new HTTP\FileResolver("{$this->_filesPath}/htbasic.1"); + $this->_digestResolver = new HTTP\FileResolver("{$this->_filesPath}/htdigest.3"); + $this->_basicConfig = array( + 'accept_schemes' => 'basic', + 'realm' => 'Test Realm', + 'proxy_auth' => true + ); + $this->_digestConfig = array( + 'accept_schemes' => 'digest', + 'realm' => 'Test Realm', + 'digest_domains' => '/ http://localhost/', + 'nonce_timeout' => 300, + 'proxy_auth' => true + ); + $this->_bothConfig = array( + 'accept_schemes' => 'basic digest', + 'realm' => 'Test Realm', + 'digest_domains' => '/ http://localhost/', + 'nonce_timeout' => 300, + 'proxy_auth' => true + ); + } + + public function testBasicChallenge() + { + // Trying to authenticate without sending an Proxy-Authorization header + // should result in a 407 reply with a Proxy-Authenticate header, and a + // false result. + + // The expected Basic Proxy-Authenticate header value + $basic = 'Basic realm="' . $this->_bothConfig['realm'] . '"'; + + $data = $this->_doAuth('', 'basic'); + $this->_checkUnauthorized($data, $basic); + } + + public function testDigestChallenge() + { + // Trying to authenticate without sending an Proxy-Authorization header + // should result in a 407 reply with a Proxy-Authenticate header, and a + // false result. + + // The expected Digest Proxy-Authenticate header value + $digest = $this->_digestChallenge(); + + $data = $this->_doAuth('', 'digest'); + $this->_checkUnauthorized($data, $digest); + } + + public function testBothChallenges() + { + // Trying to authenticate without sending an Proxy-Authorization header + // should result in a 407 reply with at least one Proxy-Authenticate + // header, and a false result. + + $data = $this->_doAuth('', 'both'); + extract($data); // $result, $status, $headers + + // The expected Proxy-Authenticate header values + $basic = 'Basic realm="' . $this->_bothConfig['realm'] . '"'; + $digest = $this->_digestChallenge(); + + // Make sure the result is false + $this->assertType('Zend\\Authentication\\Result', $result); + $this->assertFalse($result->isValid()); + + // Verify the status code and the presence of both challenges + $this->assertEquals(407, $status); + $this->assertEquals('Proxy-Authenticate', $headers[0]['name']); + $this->assertEquals('Proxy-Authenticate', $headers[1]['name']); + + // Check to see if the expected challenges match the actual + $this->assertEquals($basic, $headers[0]['value']); + $this->assertEquals($digest, $headers[1]['value']); + } + + public function testBasicAuthValidCreds() + { + // Attempt Basic Authentication with a valid username and password + + $data = $this->_doAuth('Basic ' . base64_encode('Bryce:ThisIsNotMyPassword'), 'basic'); + $this->_checkOK($data); + } + + public function testBasicAuthBadCreds() + { + // Ensure that credentials containing invalid characters are treated as + // a bad username or password. + + // The expected Basic WWW-Authenticate header value + $basic = 'Basic realm="' . $this->_basicConfig['realm'] . '"'; + + $data = $this->_doAuth('Basic ' . base64_encode("Bad\tChars:In:Creds"), 'basic'); + $this->_checkUnauthorized($data, $basic); + } + + public function testBasicAuthBadUser() + { + // Attempt Basic Authentication with a bad username and password + + // The expected Basic Proxy-Authenticate header value + $basic = 'Basic realm="' . $this->_basicConfig['realm'] . '"'; + + $data = $this->_doAuth('Basic ' . base64_encode('Nobody:NotValid'), 'basic'); + $this->_checkUnauthorized($data, $basic); + } + + public function testBasicAuthBadPassword() + { + // Attempt Basic Authentication with a valid username, but invalid + // password + + // The expected Basic WWW-Authenticate header value + $basic = 'Basic realm="' . $this->_basicConfig['realm'] . '"'; + + $data = $this->_doAuth('Basic ' . base64_encode('Bryce:Invalid'), 'basic'); + $this->_checkUnauthorized($data, $basic); + } + + public function testDigestAuthValidCreds() + { + // Attempt Digest Authentication with a valid username and password + + $data = $this->_doAuth($this->_digestReply('Bryce', 'ThisIsNotMyPassword'), 'digest'); + $this->_checkOK($data); + } + + public function testDigestAuthDefaultAlgo() + { + // If the client omits the aglorithm argument, it should default to MD5, + // and work just as above + + $cauth = $this->_digestReply('Bryce', 'ThisIsNotMyPassword'); + $cauth = preg_replace('/algorithm="MD5", /', '', $cauth); + + $data = $this->_doAuth($cauth, 'digest'); + $this->_checkOK($data); + } + + public function testDigestAuthQuotedNC() + { + // The nonce count isn't supposed to be quoted, but apparently some + // clients do anyway. + + $cauth = $this->_digestReply('Bryce', 'ThisIsNotMyPassword'); + $cauth = preg_replace('/nc=00000001/', 'nc="00000001"', $cauth); + + $data = $this->_doAuth($cauth, 'digest'); + $this->_checkOK($data); + } + + public function testDigestAuthBadCreds() + { + // Attempt Digest Authentication with a bad username and password + + // The expected Digest Proxy-Authenticate header value + $digest = $this->_digestChallenge(); + + $data = $this->_doAuth($this->_digestReply('Nobody', 'NotValid'), 'digest'); + $this->_checkUnauthorized($data, $digest); + } + + public function testDigestTampered() + { + // Create the tampered header value + $tampered = $this->_digestReply('Bryce', 'ThisIsNotMyPassword'); + $tampered = preg_replace( + '/ nonce="[a-fA-F0-9]{32}", /', + ' nonce="' . str_repeat('0', 32).'", ', + $tampered + ); + + // The expected Digest Proxy-Authenticate header value + $digest = $this->_digestChallenge(); + + $data = $this->_doAuth($tampered, 'digest'); + $this->_checkUnauthorized($data, $digest); + } + + public function testBadSchemeRequest() + { + // Sending a request for an invalid authentication scheme should result + // in a 400 Bad Request response. + + $data = $this->_doAuth('Invalid ' . base64_encode('Nobody:NotValid'), 'basic'); + $this->_checkBadRequest($data); + } + + public function testBadDigestRequest() + { + // If any of the individual parts of the Digest Proxy-Authorization header + // are bad, it results in a 400 Bad Request. But that's a lot of + // possibilities, so we're just going to pick one for now. + $bad = $this->_digestReply('Bryce', 'ThisIsNotMyPassword'); + $bad = preg_replace( + '/realm="([^"]+)"/', // cut out the realm + '', $bad + ); + + $data = $this->_doAuth($bad, 'digest'); + $this->_checkBadRequest($data); + } + + /** + * Acts like a client sending the given Authenticate header value. + * + * @param string $clientHeader Authenticate header value + * @param string $scheme Which authentication scheme to use + * @return array Containing the result, the response headers, and the status + */ + public function _doAuth($clientHeader, $scheme) + { + // Set up stub request and response objects + $request = $this->getMock('Zend_Controller_Request_Http'); + $response = new \Zend_Controller_Response_Http; + $response->setHttpResponseCode(200); + $response->headersSentThrowsException = false; + + // Set stub method return values + $request->expects($this->any()) + ->method('getRequestUri') + ->will($this->returnValue('/')); + $request->expects($this->any()) + ->method('getMethod') + ->will($this->returnValue('GET')); + $request->expects($this->any()) + ->method('getServer') + ->will($this->returnValue('PHPUnit')); + $request->expects($this->any()) + ->method('getHeader') + ->will($this->returnValue($clientHeader)); + + // Select an Authentication scheme + switch ($scheme) { + case 'basic': + $use = $this->_basicConfig; + break; + case 'digest': + $use = $this->_digestConfig; + break; + case 'both': + default: + $use = $this->_bothConfig; + } + + // Create the HTTP Auth adapter + $a = new \Zend\Authentication\Adapter\HTTP($use); + $a->setBasicResolver($this->_basicResolver); + $a->setDigestResolver($this->_digestResolver); + + // Send the authentication request + $a->setRequest($request); + $a->setResponse($response); + $result = $a->authenticate(); + + $return = array( + 'result' => $result, + 'status' => $response->getHttpResponseCode(), + 'headers' => $response->getHeaders() + ); + return $return; + } + + /** + * Constructs a local version of the digest challenge we expect to receive + * + * @return string + */ + protected function _digestChallenge() + { + $timeout = ceil(time() / 300) * 300; + $nonce = md5($timeout . ':PHPUnit:Zend\\Authentication\\Adapter\\HTTP'); + $opaque = md5('Opaque Data:Zend\\Authentication\\Adapter\\HTTP'); + $wwwauth = 'Digest ' + . 'realm="' . $this->_digestConfig['realm'] . '", ' + . 'domain="' . $this->_digestConfig['digest_domains'] . '", ' + . 'nonce="' . $nonce . '", ' + . 'opaque="' . $opaque . '", ' + . 'algorithm="MD5", ' + . 'qop="auth"'; + + return $wwwauth; + } + + /** + * Constructs a client digest Proxy-Authorization header + * + * @param string $user + * @param string $pass + * @return string + */ + protected function _digestReply($user, $pass) + { + $nc = '00000001'; + $timeout = ceil(time() / 300) * 300; + $nonce = md5($timeout . ':PHPUnit:Zend\\Authentication\\Adapter\\HTTP'); + $opaque = md5('Opaque Data:Zend\\Authentication\\Adapter\\HTTP'); + $cnonce = md5('cnonce'); + $response = md5(md5($user . ':' . $this->_digestConfig['realm'] . ':' . $pass) . ":$nonce:$nc:$cnonce:auth:" + . md5('GET:/')); + $cauth = 'Digest ' + . 'username="Bryce", ' + . 'realm="' . $this->_digestConfig['realm'] . '", ' + . 'nonce="' . $nonce . '", ' + . 'uri="/", ' + . 'response="' . $response . '", ' + . 'algorithm="MD5", ' + . 'cnonce="' . $cnonce . '", ' + . 'opaque="' . $opaque . '", ' + . 'qop="auth", ' + . 'nc=' . $nc; + + return $cauth; + } + + /** + * Checks for an expected 407 Proxy-Unauthorized response + * + * @param array $data Authentication results + * @param string $expected Expected Proxy-Authenticate header value + * @return void + */ + protected function _checkUnauthorized($data, $expected) + { + extract($data); // $result, $status, $headers + + // Make sure the result is false + $this->assertType('Zend\\Authentication\\Result', $result); + $this->assertFalse($result->isValid()); + + // Verify the status code and the presence of the challenge + $this->assertEquals(407, $status); + $this->assertEquals('Proxy-Authenticate', $headers[0]['name']); + + // Check to see if the expected challenge matches the actual + $this->assertEquals($expected, $headers[0]['value']); + } + + /** + * Checks for an expected 200 OK response + * + * @param array $data Authentication results + * @return void + */ + protected function _checkOK($data) + { + extract($data); // $result, $status, $headers + + // Make sure the result is true + $this->assertType('Zend\\Authentication\\Result', $result); + $this->assertTrue($result->isValid()); + + // Verify we got a 200 response + $this->assertEquals(200, $status); + } + + /** + * Checks for an expected 400 Bad Request response + * + * @param array $data Authentication results + * @return void + */ + protected function _checkBadRequest($data) + { + extract($data); // $result, $status, $headers + + // Make sure the result is false + $this->assertType('Zend\\Authentication\\Result', $result); + $this->assertFalse($result->isValid()); + + // Make sure it set the right HTTP code + $this->assertEquals(400, $status); + } +} diff --git a/test/Adapter/HTTP/TestAsset/htbasic.1 b/test/Adapter/HTTP/TestAsset/htbasic.1 new file mode 100644 index 0000000..7f18f96 --- /dev/null +++ b/test/Adapter/HTTP/TestAsset/htbasic.1 @@ -0,0 +1,3 @@ +Bryce:Test Realm:ThisIsNotMyPassword +Mufasa:Test Realm:Circle Of Life +Bad Chars:In:Creds diff --git a/test/Adapter/HTTP/TestAsset/htdigest.3 b/test/Adapter/HTTP/TestAsset/htdigest.3 new file mode 100644 index 0000000..f9f4944 --- /dev/null +++ b/test/Adapter/HTTP/TestAsset/htdigest.3 @@ -0,0 +1,2 @@ +Bryce:Test Realm:d5b7c330d5685beb782a9e22f0f20579 +Mufasa:Test Realm:200dc292ecb68e04c95bb74ae2ce3c80 diff --git a/test/Adapter/Ldap/OfflineTest.php b/test/Adapter/Ldap/OfflineTest.php new file mode 100644 index 0000000..6d1ba30 --- /dev/null +++ b/test/Adapter/Ldap/OfflineTest.php @@ -0,0 +1,107 @@ +_adapter = new \Zend\Authentication\Adapter\Ldap(); + } + + public function testGetSetLdap() + { + if (!extension_loaded('ldap')) { + $this->markTestSkipped('LDAP is not enabled'); + } + $this->_adapter->setLdap(new \Zend\Ldap\Ldap()); + $this->assertType('Zend_Ldap', $this->_adapter->getLdap()); + } + + public function testUsernameIsNullIfNotSet() + { + $this->assertNull($this->_adapter->getUsername()); + } + + public function testPasswordIsNullIfNotSet() + { + $this->assertNull($this->_adapter->getPassword()); + } + + public function testSetAndGetUsername() + { + $usernameExpected = 'someUsername'; + $usernameActual = $this->_adapter->setUsername($usernameExpected) + ->getUsername(); + $this->assertSame($usernameExpected, $usernameActual); + } + + public function testSetAndGetPassword() + { + $passwordExpected = 'somePassword'; + $passwordActual = $this->_adapter->setPassword($passwordExpected) + ->getPassword(); + $this->assertSame($passwordExpected, $passwordActual); + } + + public function testSetIdentityProxiesToSetUsername() + { + $usernameExpected = 'someUsername'; + $usernameActual = $this->_adapter->setIdentity($usernameExpected) + ->getUsername(); + $this->assertSame($usernameExpected, $usernameActual); + } + + public function testSetCredentialProxiesToSetPassword() + { + $passwordExpected = 'somePassword'; + $passwordActual = $this->_adapter->setCredential($passwordExpected) + ->getPassword(); + $this->assertSame($passwordExpected, $passwordActual); + } +} diff --git a/test/Adapter/Ldap/OnlineTest.php b/test/Adapter/Ldap/OnlineTest.php new file mode 100644 index 0000000..f32601b --- /dev/null +++ b/test/Adapter/Ldap/OnlineTest.php @@ -0,0 +1,209 @@ +markTestSkipped('LDAP online tests are not enabled'); + } + $this->_options = array( + 'host' => TESTS_ZEND_LDAP_HOST, + 'username' => TESTS_ZEND_LDAP_USERNAME, + 'password' => TESTS_ZEND_LDAP_PASSWORD, + 'baseDn' => TESTS_ZEND_LDAP_BASE_DN, + ); + if (defined('TESTS_ZEND_LDAP_PORT')) + $this->_options['port'] = TESTS_ZEND_LDAP_PORT; + if (defined('TESTS_ZEND_LDAP_USE_START_TLS')) + $this->_options['useStartTls'] = TESTS_ZEND_LDAP_USE_START_TLS; + if (defined('TESTS_ZEND_LDAP_USE_SSL')) + $this->_options['useSsl'] = TESTS_ZEND_LDAP_USE_SSL; + if (defined('TESTS_ZEND_LDAP_BIND_REQUIRES_DN')) + $this->_options['bindRequiresDn'] = TESTS_ZEND_LDAP_BIND_REQUIRES_DN; + if (defined('TESTS_ZEND_LDAP_ACCOUNT_FILTER_FORMAT')) + $this->_options['accountFilterFormat'] = TESTS_ZEND_LDAP_ACCOUNT_FILTER_FORMAT; + if (defined('TESTS_ZEND_LDAP_ACCOUNT_DOMAIN_NAME')) + $this->_options['accountDomainName'] = TESTS_ZEND_LDAP_ACCOUNT_DOMAIN_NAME; + if (defined('TESTS_ZEND_LDAP_ACCOUNT_DOMAIN_NAME_SHORT')) + $this->_options['accountDomainNameShort'] = TESTS_ZEND_LDAP_ACCOUNT_DOMAIN_NAME_SHORT; + + if (defined('TESTS_ZEND_LDAP_ALT_USERNAME')) { + $this->_names[\Zend_Ldap::ACCTNAME_FORM_USERNAME] = TESTS_ZEND_LDAP_ALT_USERNAME; + if (defined('TESTS_ZEND_LDAP_ACCOUNT_DOMAIN_NAME')) { + $this->_names[\Zend_Ldap::ACCTNAME_FORM_PRINCIPAL] = + TESTS_ZEND_LDAP_ALT_USERNAME . '@' . TESTS_ZEND_LDAP_ACCOUNT_DOMAIN_NAME; + } + if (defined('TESTS_ZEND_LDAP_ACCOUNT_DOMAIN_NAME_SHORT')) { + $this->_names[\Zend_Ldap::ACCTNAME_FORM_BACKSLASH] = + TESTS_ZEND_LDAP_ACCOUNT_DOMAIN_NAME_SHORT . '\\' . TESTS_ZEND_LDAP_ALT_USERNAME; + } + } + } + + public function testSimpleAuth() + { + $adapter = new Adapter\Ldap( + array($this->_options), + TESTS_ZEND_LDAP_ALT_USERNAME, + TESTS_ZEND_LDAP_ALT_PASSWORD + ); + + $result = $adapter->authenticate(); + + $this->assertTrue($result instanceof Authentication\Result); + $this->assertTrue($result->isValid()); + $this->assertTrue($result->getCode() == Authentication\Result::SUCCESS); + } + + public function testCanonAuth() + { + /* This test authenticates with each of the account name forms + * (uname, uname@example.com, EXAMPLE\uname) AND it does so with + * the accountCanonicalForm set to each of the account name forms + * (e.g. authenticate with uname@example.com but getIdentity() returns + * EXAMPLE\uname). A total of 9 authentications are performed. + */ + foreach ($this->_names as $form => $formName) { + $options = $this->_options; + $options['accountCanonicalForm'] = $form; + $adapter = new Adapter\Ldap(array($options)); + $adapter->setPassword(TESTS_ZEND_LDAP_ALT_PASSWORD); + foreach ($this->_names as $username) { + $adapter->setUsername($username); + $result = $adapter->authenticate(); + $this->assertTrue($result instanceof Authentication\Result); + $this->assertTrue($result->isValid()); + $this->assertTrue($result->getCode() == Authentication\Result::SUCCESS); + $this->assertTrue($result->getIdentity() === $formName); + } + } + } + + public function testInvalidPassAuth() + { + $adapter = new Adapter\Ldap( + array($this->_options), + TESTS_ZEND_LDAP_ALT_USERNAME, + 'invalid' + ); + + $result = $adapter->authenticate(); + $this->assertTrue($result instanceof Authentication\Result); + $this->assertTrue($result->isValid() === false); + $this->assertTrue($result->getCode() == Authentication\Result::FAILURE_CREDENTIAL_INVALID); + } + + public function testInvalidUserAuth() + { + $adapter = new Adapter\Ldap( + array($this->_options), + 'invalid', + 'doesntmatter' + ); + + $result = $adapter->authenticate(); + $this->assertTrue($result instanceof Authentication\Result); + $this->assertTrue($result->isValid() === false); + $this->assertTrue( + $result->getCode() == Authentication\Result::FAILURE_IDENTITY_NOT_FOUND || + $result->getCode() == Authentication\Result::FAILURE_CREDENTIAL_INVALID + ); + } + + public function testMismatchDomainAuth() + { + $adapter = new Adapter\Ldap( + array($this->_options), + 'EXAMPLE\\doesntmatter', + 'doesntmatter' + ); + + $result = $adapter->authenticate(); + $this->assertTrue($result instanceof Authentication\Result); + $this->assertFalse($result->isValid()); + $this->assertThat($result->getCode(), $this->lessThanOrEqual(Authentication\Result::FAILURE)); + $messages = $result->getMessages(); + $this->assertContains('not found', $messages[0]); + } + + public function testAccountObjectRetrieval() + { + $adapter = new Adapter\Ldap( + array($this->_options), + TESTS_ZEND_LDAP_ALT_USERNAME, + TESTS_ZEND_LDAP_ALT_PASSWORD + ); + + $result = $adapter->authenticate(); + $account = $adapter->getAccountObject(); + + $this->assertTrue($result->isValid()); + $this->assertType('stdClass', $account); + $this->assertEquals(TESTS_ZEND_LDAP_ALT_DN, $account->dn); + } + + public function testAccountObjectRetrievalWithOmittedAttributes() + { + $adapter = new Adapter\Ldap( + array($this->_options), + TESTS_ZEND_LDAP_ALT_USERNAME, + TESTS_ZEND_LDAP_ALT_PASSWORD + ); + + $result = $adapter->authenticate(); + $account = $adapter->getAccountObject(array(), array('userPassword')); + + $this->assertType('stdClass', $account); + $this->assertFalse(isset($account->userpassword)); + } +} diff --git a/test/Adapter/OpenIdTest.php b/test/Adapter/OpenIdTest.php new file mode 100644 index 0000000..b1bb2b3 --- /dev/null +++ b/test/Adapter/OpenIdTest.php @@ -0,0 +1,505 @@ +authenticate(); + $this->assertFalse($ret->isValid()); + $this->assertSame("", $ret->getIdentity()); + $this->assertSame(0, $ret->getCode()); + $msgs = $ret->getMessages(); + $this->assertTrue(is_array($msgs)); + $this->assertSame(2, count($msgs)); + $this->assertSame("Authentication failed", $msgs[0]); + $this->assertSame("Missing openid.mode", $msgs[1]); + } + + public function testAuthenticateLoginInvalid() + { + $adapter = new Adapter\OpenId("%sd", new \Zend_OpenId_Consumer_Storage_File(__DIR__."/TestAsset/OpenId")); + $ret = $adapter->authenticate(); + $this->assertFalse($ret->isValid()); + $this->assertSame("%sd", $ret->getIdentity()); + $this->assertSame(0, $ret->getCode()); + $msgs = $ret->getMessages(); + $this->assertTrue(is_array($msgs)); + $this->assertSame(2, count($msgs)); + $this->assertSame("Authentication failed", $msgs[0]); + $this->assertSame("Normalisation failed", $msgs[1]); + } + + public function testAuthenticateLoginValid() + { + $expiresIn = time() + 600; + $storage = new \Zend_OpenId_Consumer_Storage_File(__DIR__."/TestAsset/OpenId"); + $storage->delDiscoveryInfo(self::ID); + $storage->addDiscoveryInfo(self::ID, self::REAL_ID, self::SERVER, 1.1, $expiresIn); + $storage->delAssociation(self::SERVER); + $storage->addAssociation(self::SERVER, self::HANDLE, self::MAC_FUNC, self::SECRET, $expiresIn); + + $response = new TestAsset\OpenIdResponseHelper(true); + + $_SERVER['SCRIPT_URI'] = "http://www.zf-test.com/test.php"; + + $adapter = new Adapter\OpenId(self::ID, $storage); + $this->assertSame($adapter, $adapter->setResponse($response)); + $ret = $adapter->authenticate(); + $this->assertTrue(is_null($ret)); + $headers = $response->getHeaders(); + $this->assertSame( '', $response->getBody() ); + $this->assertTrue( is_array($headers) ); + $this->assertSame( 1, count($headers) ); + $this->assertTrue( is_array($headers[0]) ); + $this->assertSame( 3, count($headers[0]) ); + $this->assertSame( 'Location', $headers[0]['name'] ); + $this->assertSame( true, $headers[0]['replace'] ); + $url = $headers[0]['value']; + $url = parse_url($url); + $this->assertSame( "http", $url['scheme'] ); + $this->assertSame( "www.myopenid.com", $url['host'] ); + $this->assertSame( "/", $url['path'] ); + $q = explode("&", $url['query']); + $query = array(); + foreach($q as $var) { + if (list($key, $val) = explode("=", $var, 2)) { + $query[$key] = $val; + } + } + $this->assertTrue( is_array($query) ); + $this->assertSame( 6, count($query) ); + $this->assertSame( 'checkid_setup', $query['openid.mode'] ); + $this->assertSame( 'http%3A%2F%2Freal_id.myopenid.com%2F', $query['openid.identity'] ); + $this->assertSame( 'http%3A%2F%2Fid.myopenid.com%2F', $query['openid.claimed_id'] ); + $this->assertSame( self::HANDLE, $query['openid.assoc_handle'] ); + $this->assertSame( 'http%3A%2F%2Fwww.zf-test.com%2Ftest.php', $query['openid.return_to'] ); + $this->assertSame( 'http%3A%2F%2Fwww.zf-test.com', $query['openid.trust_root'] ); + } + + public function testSetIdentity() + { + $expiresIn = time() + 600; + $storage = new \Zend_OpenId_Consumer_Storage_File(__DIR__."/TestAsset/OpenId"); + $storage->delDiscoveryInfo(self::ID); + $storage->addDiscoveryInfo(self::ID, self::REAL_ID, self::SERVER, 1.1, $expiresIn); + $storage->delAssociation(self::SERVER); + $storage->addAssociation(self::SERVER, self::HANDLE, self::MAC_FUNC, self::SECRET, $expiresIn); + + $response = new TestAsset\OpenIdResponseHelper(true); + + $_SERVER['SCRIPT_URI'] = "http://www.zf-test.com/test.php"; + + $adapter = new Adapter\OpenId(null, $storage); + $this->assertSame($adapter, $adapter->setIdentity(self::ID)); + $adapter->setResponse($response); + $ret = $adapter->authenticate(); + $this->assertTrue(is_null($ret)); + $headers = $response->getHeaders(); + $this->assertSame( '', $response->getBody() ); + $this->assertTrue( is_array($headers) ); + $this->assertSame( 1, count($headers) ); + $this->assertTrue( is_array($headers[0]) ); + $this->assertSame( 3, count($headers[0]) ); + $this->assertSame( 'Location', $headers[0]['name'] ); + $this->assertSame( true, $headers[0]['replace'] ); + $url = $headers[0]['value']; + $url = parse_url($url); + $this->assertSame( "http", $url['scheme'] ); + $this->assertSame( "www.myopenid.com", $url['host'] ); + $this->assertSame( "/", $url['path'] ); + $q = explode("&", $url['query']); + $query = array(); + foreach($q as $var) { + if (list($key, $val) = explode("=", $var, 2)) { + $query[$key] = $val; + } + } + $this->assertTrue( is_array($query) ); + $this->assertSame( 6, count($query) ); + $this->assertSame( 'checkid_setup', $query['openid.mode'] ); + $this->assertSame( 'http%3A%2F%2Freal_id.myopenid.com%2F', $query['openid.identity'] ); + $this->assertSame( 'http%3A%2F%2Fid.myopenid.com%2F', $query['openid.claimed_id'] ); + $this->assertSame( self::HANDLE, $query['openid.assoc_handle'] ); + $this->assertSame( 'http%3A%2F%2Fwww.zf-test.com%2Ftest.php', $query['openid.return_to'] ); + $this->assertSame( 'http%3A%2F%2Fwww.zf-test.com', $query['openid.trust_root'] ); + } + + public function testSetStorage() + { + $expiresIn = time() + 600; + $storage = new \Zend_OpenId_Consumer_Storage_File(__DIR__."/TestAsset/OpenId"); + $storage->delDiscoveryInfo(self::ID); + $storage->addDiscoveryInfo(self::ID, self::REAL_ID, self::SERVER, 1.1, $expiresIn); + $storage->delAssociation(self::SERVER); + $storage->addAssociation(self::SERVER, self::HANDLE, self::MAC_FUNC, self::SECRET, $expiresIn); + + $response = new TestAsset\OpenIdResponseHelper(true); + + $_SERVER['SCRIPT_URI'] = "http://www.zf-test.com/test.php"; + + $adapter = new Adapter\OpenId(self::ID); + $this->assertSame($adapter, $adapter->setStorage($storage)); + $adapter->setResponse($response); + $ret = $adapter->authenticate(); + $this->assertTrue(is_null($ret)); + $headers = $response->getHeaders(); + $this->assertSame( '', $response->getBody() ); + $this->assertTrue( is_array($headers) ); + $this->assertSame( 1, count($headers) ); + $this->assertTrue( is_array($headers[0]) ); + $this->assertSame( 3, count($headers[0]) ); + $this->assertSame( 'Location', $headers[0]['name'] ); + $this->assertSame( true, $headers[0]['replace'] ); + $url = $headers[0]['value']; + $url = parse_url($url); + $this->assertSame( "http", $url['scheme'] ); + $this->assertSame( "www.myopenid.com", $url['host'] ); + $this->assertSame( "/", $url['path'] ); + $q = explode("&", $url['query']); + $query = array(); + foreach($q as $var) { + if (list($key, $val) = explode("=", $var, 2)) { + $query[$key] = $val; + } + } + $this->assertTrue( is_array($query) ); + $this->assertSame( 6, count($query) ); + $this->assertSame( 'checkid_setup', $query['openid.mode'] ); + $this->assertSame( 'http%3A%2F%2Freal_id.myopenid.com%2F', $query['openid.identity'] ); + $this->assertSame( 'http%3A%2F%2Fid.myopenid.com%2F', $query['openid.claimed_id'] ); + $this->assertSame( self::HANDLE, $query['openid.assoc_handle'] ); + $this->assertSame( 'http%3A%2F%2Fwww.zf-test.com%2Ftest.php', $query['openid.return_to'] ); + $this->assertSame( 'http%3A%2F%2Fwww.zf-test.com', $query['openid.trust_root'] ); + } + + public function testSetReturnTo() + { + $expiresIn = time() + 600; + $storage = new \Zend_OpenId_Consumer_Storage_File(__DIR__."/TestAsset/OpenId"); + $storage->delDiscoveryInfo(self::ID); + $storage->addDiscoveryInfo(self::ID, self::REAL_ID, self::SERVER, 1.1, $expiresIn); + $storage->delAssociation(self::SERVER); + $storage->addAssociation(self::SERVER, self::HANDLE, self::MAC_FUNC, self::SECRET, $expiresIn); + + $response = new TestAsset\OpenIdResponseHelper(true); + + $_SERVER['SCRIPT_URI'] = "http://www.zf-test.com/test.php"; + + $adapter = new Adapter\OpenId(self::ID, $storage); + $adapter->setResponse($response); + $this->assertSame($adapter, $adapter->setReturnTo("http://www.zf-test.com/return.php")); + $ret = $adapter->authenticate(); + $this->assertTrue(is_null($ret)); + $headers = $response->getHeaders(); + $this->assertSame( '', $response->getBody() ); + $this->assertTrue( is_array($headers) ); + $this->assertSame( 1, count($headers) ); + $this->assertTrue( is_array($headers[0]) ); + $this->assertSame( 3, count($headers[0]) ); + $this->assertSame( 'Location', $headers[0]['name'] ); + $this->assertSame( true, $headers[0]['replace'] ); + $url = $headers[0]['value']; + $url = parse_url($url); + $this->assertSame( "http", $url['scheme'] ); + $this->assertSame( "www.myopenid.com", $url['host'] ); + $this->assertSame( "/", $url['path'] ); + $q = explode("&", $url['query']); + $query = array(); + foreach($q as $var) { + if (list($key, $val) = explode("=", $var, 2)) { + $query[$key] = $val; + } + } + $this->assertTrue( is_array($query) ); + $this->assertSame( 6, count($query) ); + $this->assertSame( 'checkid_setup', $query['openid.mode'] ); + $this->assertSame( 'http%3A%2F%2Freal_id.myopenid.com%2F', $query['openid.identity'] ); + $this->assertSame( 'http%3A%2F%2Fid.myopenid.com%2F', $query['openid.claimed_id'] ); + $this->assertSame( self::HANDLE, $query['openid.assoc_handle'] ); + $this->assertSame( 'http%3A%2F%2Fwww.zf-test.com%2Freturn.php', $query['openid.return_to'] ); + $this->assertSame( 'http%3A%2F%2Fwww.zf-test.com', $query['openid.trust_root'] ); + } + + public function testSetRoot() + { + $expiresIn = time() + 600; + $storage = new \Zend_OpenId_Consumer_Storage_File(__DIR__."/TestAsset/OpenId"); + $storage->delDiscoveryInfo(self::ID); + $storage->addDiscoveryInfo(self::ID, self::REAL_ID, self::SERVER, 1.1, $expiresIn); + $storage->delAssociation(self::SERVER); + $storage->addAssociation(self::SERVER, self::HANDLE, self::MAC_FUNC, self::SECRET, $expiresIn); + + $response = new TestAsset\OpenIdResponseHelper(true); + + $_SERVER['SCRIPT_URI'] = "http://www.zf-test.com/test.php"; + + $adapter = new Adapter\OpenId(self::ID, $storage); + $adapter->setResponse($response); + $this->assertSame($adapter, $adapter->setRoot("http://www.zf-test.com/root.php")); + $ret = $adapter->authenticate(); + $this->assertTrue(is_null($ret)); + $headers = $response->getHeaders(); + $this->assertSame( '', $response->getBody() ); + $this->assertTrue( is_array($headers) ); + $this->assertSame( 1, count($headers) ); + $this->assertTrue( is_array($headers[0]) ); + $this->assertSame( 3, count($headers[0]) ); + $this->assertSame( 'Location', $headers[0]['name'] ); + $this->assertSame( true, $headers[0]['replace'] ); + $url = $headers[0]['value']; + $url = parse_url($url); + $this->assertSame( "http", $url['scheme'] ); + $this->assertSame( "www.myopenid.com", $url['host'] ); + $this->assertSame( "/", $url['path'] ); + $q = explode("&", $url['query']); + $query = array(); + foreach($q as $var) { + if (list($key, $val) = explode("=", $var, 2)) { + $query[$key] = $val; + } + } + $this->assertTrue( is_array($query) ); + $this->assertSame( 6, count($query) ); + $this->assertSame( 'checkid_setup', $query['openid.mode'] ); + $this->assertSame( 'http%3A%2F%2Freal_id.myopenid.com%2F', $query['openid.identity'] ); + $this->assertSame( 'http%3A%2F%2Fid.myopenid.com%2F', $query['openid.claimed_id'] ); + $this->assertSame( self::HANDLE, $query['openid.assoc_handle'] ); + $this->assertSame( 'http%3A%2F%2Fwww.zf-test.com%2Ftest.php', $query['openid.return_to'] ); + $this->assertSame( 'http%3A%2F%2Fwww.zf-test.com%2Froot.php', $query['openid.trust_root'] ); + } + + public function testAuthenticateVerifyInvalid() + { + $_SERVER['SCRIPT_URI'] = "http://www.zf-test.com/test.php"; + unset($_SERVER['REQUEST_METHOD']); + $_GET = array('openid_mode'=>'id_res', + "openid_return_to" => "http://www.zf-test.com/test.php", + "openid_assoc_handle" => self::HANDLE, + "openid_claimed_id" => self::ID, + "openid_identity" => self::REAL_ID, + "openid_response_nonce" => "2007-08-14T12:52:33Z46c1a59124fff", + "openid_signed" => "assoc_handle,return_to,claimed_id,identity,response_nonce,mode,signed", + "openid_sig" => "h/5AFD25NpzSok5tzHEGCVUkQSw=" + ); + $storage = new \Zend_OpenId_Consumer_Storage_File(__DIR__."/TestAsset/OpenId"); + $adapter = new Adapter\OpenId(null, $storage); + $ret = $adapter->authenticate(); + $this->assertFalse($ret->isValid()); + $this->assertSame(self::ID, $ret->getIdentity()); + $this->assertSame(0, $ret->getCode()); + $msgs = $ret->getMessages(); + $this->assertTrue(is_array($msgs)); + $this->assertSame(2, count($msgs)); + $this->assertSame("Authentication failed", $msgs[0]); + $this->assertSame("Signature check failed", $msgs[1]); + } + + public function testAuthenticateVerifyGetValid() + { + $expiresIn = time() + 600; + $storage = new \Zend_OpenId_Consumer_Storage_File(__DIR__."/TestAsset/OpenId"); + $storage->delDiscoveryInfo(self::ID); + $storage->addDiscoveryInfo(self::ID, self::REAL_ID, self::SERVER, 1.1, $expiresIn); + $storage->delAssociation(self::SERVER); + $storage->addAssociation(self::SERVER, self::HANDLE, self::MAC_FUNC, self::SECRET, $expiresIn); + $storage->purgeNonces(); + + $_SERVER['SCRIPT_URI'] = "http://www.zf-test.com/test.php"; + unset($_SERVER['REQUEST_METHOD']); + $_GET = array( + "openid_return_to" => "http://www.zf-test.com/test.php", + "openid_assoc_handle" => self::HANDLE, + "openid_claimed_id" => self::ID, + "openid_identity" => self::REAL_ID, + "openid_response_nonce" => "2007-08-14T12:52:33Z46c1a59124ffe", + "openid_mode" => "id_res", + "openid_signed" => "assoc_handle,return_to,claimed_id,identity,response_nonce,mode,signed", + "openid_sig" => "h/5AFD25NpzSok5tzHEGCVUkQSw=" + ); + $adapter = new Adapter\OpenId(null, $storage); + $ret = $adapter->authenticate(); + $this->assertTrue($ret->isValid()); + } + + public function testAuthenticateVerifyPostValid() + { + $expiresIn = time() + 600; + $storage = new \Zend_OpenId_Consumer_Storage_File(__DIR__."/TestAsset/OpenId"); + $storage->delDiscoveryInfo(self::ID); + $storage->addDiscoveryInfo(self::ID, self::REAL_ID, self::SERVER, 1.1, $expiresIn); + $storage->delAssociation(self::SERVER); + $storage->addAssociation(self::SERVER, self::HANDLE, self::MAC_FUNC, self::SECRET, $expiresIn); + $storage->purgeNonces(); + + $_SERVER['SCRIPT_URI'] = "http://www.zf-test.com/test.php"; + $_SERVER['REQUEST_METHOD'] = 'POST'; + $_GET = array(); + $_POST = array( + "openid_return_to" => "http://www.zf-test.com/test.php", + "openid_assoc_handle" => self::HANDLE, + "openid_claimed_id" => self::ID, + "openid_identity" => self::REAL_ID, + "openid_response_nonce" => "2007-08-14T12:52:33Z46c1a59124ffe", + "openid_mode" => "id_res", + "openid_signed" => "assoc_handle,return_to,claimed_id,identity,response_nonce,mode,signed", + "openid_sig" => "h/5AFD25NpzSok5tzHEGCVUkQSw=" + ); + $adapter = new Adapter\OpenId(null, $storage); + $ret = $adapter->authenticate(); + $this->assertTrue($ret->isValid()); + } + + public function testSetExtensions() + { + $expiresIn = time() + 600; + $storage = new \Zend_OpenId_Consumer_Storage_File(__DIR__."/TestAsset/OpenId"); + $this->assertTrue( $storage->delDiscoveryInfo(self::ID) ); + $this->assertTrue( $storage->addDiscoveryInfo(self::ID, self::REAL_ID, self::SERVER, 2.0, $expiresIn) ); + $storage->delAssociation(self::SERVER); + $storage->addAssociation(self::SERVER, self::HANDLE, self::MAC_FUNC, self::SECRET, $expiresIn); + $storage->purgeNonces(); + + $_SERVER['SCRIPT_URI'] = "http://www.zf-test.com/test.php"; + $_SERVER['REQUEST_METHOD'] = 'GET'; + $_GET = array( + "openid_ns" => \Zend_OpenId::NS_2_0, + "openid_return_to" => "http://www.zf-test.com/test.php", + "openid_assoc_handle" => self::HANDLE, + "openid_claimed_id" => self::ID, + "openid_identity" => self::REAL_ID, + "openid_response_nonce" => "2007-08-14T12:52:33Z46c1a59124ffe", + "openid_op_endpoint" => self::SERVER, + "openid_mode" => "id_res", + "openid_ns_sreg" => "http://openid.net/extensions/sreg/1.1", + "openid_sreg_nickname" => "test", + "openid_signed" => "ns,assoc_handle,return_to,claimed_id,identity,response_nonce,mode,ns.sreg,sreg.nickname,signed", + "openid_sig" => "jcV5K517GrjOxjRzi0QNLX2D+1s=" + ); + $_POST = array(); + $adapter = new Adapter\OpenId(null, $storage); + $sreg= new \Zend_OpenId_Extension_Sreg(array("nickname"=>true,"email"=>false)); + $this->assertSame($adapter, $adapter->setExtensions($sreg)); + $ret = $adapter->authenticate(); + $this->assertTrue($ret->isValid()); + $sreg_data = $sreg->getProperties(); + $this->assertSame("test", $sreg_data['nickname']); + } + + function testSetCheckImmediate() + { + $expiresIn = time() + 600; + $storage = new \Zend_OpenId_Consumer_Storage_File(__DIR__."/TestAsset/OpenId"); + $storage->delDiscoveryInfo(self::ID); + $storage->addDiscoveryInfo(self::ID, self::REAL_ID, self::SERVER, 1.1, $expiresIn); + $storage->delAssociation(self::SERVER); + $storage->addAssociation(self::SERVER, self::HANDLE, self::MAC_FUNC, self::SECRET, $expiresIn); + + $response = new TestAsset\OpenIdResponseHelper(true); + + $_SERVER['SCRIPT_URI'] = "http://www.zf-test.com/test.php"; + + $adapter = new Adapter\OpenId(self::ID, $storage); + $adapter->setCheckImmediate(true); + $this->assertSame($adapter, $adapter->setResponse($response)); + $ret = $adapter->authenticate(); + $this->assertTrue(is_null($ret)); + $headers = $response->getHeaders(); + $this->assertSame( '', $response->getBody() ); + $this->assertTrue( is_array($headers) ); + $this->assertSame( 1, count($headers) ); + $this->assertTrue( is_array($headers[0]) ); + $this->assertSame( 3, count($headers[0]) ); + $this->assertSame( 'Location', $headers[0]['name'] ); + $this->assertSame( true, $headers[0]['replace'] ); + $url = $headers[0]['value']; + $url = parse_url($url); + $this->assertSame( "http", $url['scheme'] ); + $this->assertSame( "www.myopenid.com", $url['host'] ); + $this->assertSame( "/", $url['path'] ); + $q = explode("&", $url['query']); + $query = array(); + foreach($q as $var) { + if (list($key, $val) = explode("=", $var, 2)) { + $query[$key] = $val; + } + } + $this->assertTrue( is_array($query) ); + $this->assertSame( 6, count($query) ); + $this->assertSame( 'checkid_immediate', $query['openid.mode'] ); + $this->assertSame( 'http%3A%2F%2Freal_id.myopenid.com%2F', $query['openid.identity'] ); + $this->assertSame( 'http%3A%2F%2Fid.myopenid.com%2F', $query['openid.claimed_id'] ); + $this->assertSame( self::HANDLE, $query['openid.assoc_handle'] ); + $this->assertSame( 'http%3A%2F%2Fwww.zf-test.com%2Ftest.php', $query['openid.return_to'] ); + $this->assertSame( 'http%3A%2F%2Fwww.zf-test.com', $query['openid.trust_root'] ); + } + + function testSetHttpClient() + { + $storage = new \Zend_OpenId_Consumer_Storage_File(__DIR__."/TestAsset/OpenId"); + $storage->delDiscoveryInfo(self::ID); + $storage->delAssociation(self::SERVER); + $adapter = new Adapter\OpenId(self::ID, $storage); + $http = new \Zend\HTTP\Client(null, + array( + 'maxredirects' => 4, + 'timeout' => 15, + 'useragent' => 'Zend_OpenId' + )); + $test = new \Zend\HTTP\Client\Adapter\Test(); + $http->setAdapter($test); + $adapter->setHttpClient($http); + $ret = $adapter->authenticate(); + $this->assertSame("GET / HTTP/1.1\r\n". + "Host: id.myopenid.com\r\n". + "Connection: close\r\n". + "Accept-encoding: gzip, deflate\r\n". + "User-Agent: Zend_OpenId\r\n\r\n", + $http->getLastRequest()); + } + +} diff --git a/test/Adapter/TestAsset/Digest/htdigest.1 b/test/Adapter/TestAsset/Digest/htdigest.1 new file mode 100644 index 0000000..ff62927 --- /dev/null +++ b/test/Adapter/TestAsset/Digest/htdigest.1 @@ -0,0 +1,2 @@ +someUser:Some Realm:fde17b91c3a510ecbaf7dbd37f59d4f8 +someOtherUser:Some Other Realm:1911c62b21a85c85c4c1a57785893b94 diff --git a/test/Adapter/TestAsset/OpenId/.gitignore b/test/Adapter/TestAsset/OpenId/.gitignore new file mode 100644 index 0000000..e69de29 diff --git a/test/Adapter/TestAsset/OpenId/assoc.lock b/test/Adapter/TestAsset/OpenId/assoc.lock new file mode 100644 index 0000000..e69de29 diff --git a/test/Adapter/TestAsset/OpenId/discovery.lock b/test/Adapter/TestAsset/OpenId/discovery.lock new file mode 100644 index 0000000..e69de29 diff --git a/test/Adapter/TestAsset/OpenId/nonce.lock b/test/Adapter/TestAsset/OpenId/nonce.lock new file mode 100644 index 0000000..e69de29 diff --git a/test/Adapter/TestAsset/OpenId/nonce_9f11599cc1f088b7c358f33610cb126c b/test/Adapter/TestAsset/OpenId/nonce_9f11599cc1f088b7c358f33610cb126c new file mode 100644 index 0000000..83c598f --- /dev/null +++ b/test/Adapter/TestAsset/OpenId/nonce_9f11599cc1f088b7c358f33610cb126c @@ -0,0 +1 @@ +http://www.myopenid.com/;2007-08-14T12:52:33Z46c1a59124ffe \ No newline at end of file diff --git a/test/Adapter/TestAsset/OpenIdResponseHelper.php b/test/Adapter/TestAsset/OpenIdResponseHelper.php new file mode 100644 index 0000000..d23a4d9 --- /dev/null +++ b/test/Adapter/TestAsset/OpenIdResponseHelper.php @@ -0,0 +1,58 @@ +_canSendHeaders = $canSendHeaders; + } + + public function canSendHeaders($throw = false) + { + return $this->_canSendHeaders; + } + + public function sendResponse() + { + } +} diff --git a/test/AuthenticationServiceTest.php b/test/AuthenticationServiceTest.php new file mode 100644 index 0000000..108b6e3 --- /dev/null +++ b/test/AuthenticationServiceTest.php @@ -0,0 +1,87 @@ +auth = new AuthenticationService(); + } + + /** + * Ensures that getStorage() returns Zend_Auth_Storage_Session + * + * @return void + */ + public function testGetStorage() + { + $storage = $this->auth->getStorage(); + $this->assertTrue($storage instanceof Auth\Storage\Session); + } + + /** + * Ensures expected behavior for successful authentication + * + * @return void + */ + public function testAuthenticate() + { + $result = $this->_authenticate(); + $this->assertTrue($result instanceof Auth\Result); + $this->assertTrue($this->auth->hasIdentity()); + $this->assertEquals('someIdentity', $this->auth->getIdentity()); + } + + /** + * Ensures expected behavior for clearIdentity() + * + * @return void + */ + public function testClearIdentity() + { + $this->_authenticate(); + $this->auth->clearIdentity(); + $this->assertFalse($this->auth->hasIdentity()); + $this->assertEquals(null, $this->auth->getIdentity()); + } + + protected function _authenticate() + { + return $this->auth->authenticate(new TestAsset\SuccessAdapter()); + } +} diff --git a/test/TestAsset/SuccessAdapter.php b/test/TestAsset/SuccessAdapter.php new file mode 100644 index 0000000..1bc540e --- /dev/null +++ b/test/TestAsset/SuccessAdapter.php @@ -0,0 +1,14 @@ + Date: Tue, 29 Jun 2010 16:39:56 -0400 Subject: [PATCH 05/61] OpenID authentication consumer - Refactored OpenID authentication consumer so that it now passes tests --- src/Adapter/{OpenId.php => OpenID.php} | 15 +++-- .../{OpenIdTest.php => OpenIDTest.php} | 57 ++++++++++--------- .../TestAsset/OpenIdResponseHelper.php | 6 +- 3 files changed, 42 insertions(+), 36 deletions(-) rename src/Adapter/{OpenId.php => OpenID.php} (94%) rename test/Adapter/{OpenIdTest.php => OpenIDTest.php} (91%) diff --git a/src/Adapter/OpenId.php b/src/Adapter/OpenID.php similarity index 94% rename from src/Adapter/OpenId.php rename to src/Adapter/OpenID.php index dc42046..3052a80 100644 --- a/src/Adapter/OpenId.php +++ b/src/Adapter/OpenID.php @@ -25,7 +25,10 @@ */ namespace Zend\Authentication\Adapter; use Zend\Authentication\Adapter as AuthenticationAdapter, - Zend\Authentication\Result as AuthenticationResult; + Zend\Authentication\Result as AuthenticationResult, + Zend\Controller\Response\AbstractResponse, + Zend\OpenID\Consumer\GenericConsumer as GenericConsumer, + Zend\OpenID\Consumer\Storage\AbstractStorage as OpenIDStorage; /** * A Zend_Auth Authentication Adapter allowing the use of OpenID protocol as an @@ -113,11 +116,11 @@ class OpenId implements AuthenticationAdapter */ public function __construct( $id = null, - \Zend_OpenId_Consumer_Storage $storage = null, + OpenIDStorage $storage = null, $returnTo = null, $root = null, $extensions = null, - \Zend_Controller_Response_Abstract $response = null + AbstractResponse $response = null ) { $this->_id = $id; $this->_storage = $storage; @@ -145,7 +148,7 @@ public function setIdentity($id) * @param Zend_OpenId_Consumer_Storage $storage * @return Zend\Authentication\Adapter\OpenId Provides a fluent interface */ - public function setStorage(\Zend_OpenId_Consumer_Storage $storage) + public function setStorage(OpenIDStorage $storage) { $this->_storage = $storage; return $this; @@ -232,7 +235,7 @@ public function setHttpClient($client) public function authenticate() { $id = $this->_id; if (!empty($id)) { - $consumer = new \Zend_OpenId_Consumer($this->_storage); + $consumer = new GenericConsumer($this->_storage); $consumer->setHttpClient($this->_httpClient); /* login() is never returns on success */ if (!$this->_check_immediate) { @@ -261,7 +264,7 @@ public function authenticate() { } else { $params = (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD']=='POST') ? $_POST: $_GET; - $consumer = new \Zend_OpenId_Consumer($this->_storage); + $consumer = new GenericConsumer($this->_storage); $consumer->setHttpClient($this->_httpClient); if ($consumer->verify( $params, diff --git a/test/Adapter/OpenIdTest.php b/test/Adapter/OpenIDTest.php similarity index 91% rename from test/Adapter/OpenIdTest.php rename to test/Adapter/OpenIDTest.php index b1bb2b3..8b28146 100644 --- a/test/Adapter/OpenIdTest.php +++ b/test/Adapter/OpenIDTest.php @@ -25,8 +25,9 @@ */ namespace ZendTest\Authentication\Adapter; -use Zend\Authentication\Adapter, - Zend_OpenId_Consumer_Storage; +use Zend\Authentication\Adapter\OpenID as OpenIDAdapter, + Zend\OpenID\Consumer\Storage\File as OpenIDFileStorage, + Zend\OpenID\Extension\Sreg as OpenIDSregExtension; /** * @category Zend @@ -48,7 +49,7 @@ class OpenIdTest extends \PHPUnit_Framework_TestCase public function testAuthenticateInvalid() { - $adapter = new Adapter\OpenId(null, new \Zend_OpenId_Consumer_Storage_File(__DIR__."/TestAsset/OpenId")); + $adapter = new OpenIDAdapter(null, new OpenIDFileStorage(__DIR__ . "/TestAsset/OpenId")); $ret = $adapter->authenticate(); $this->assertFalse($ret->isValid()); $this->assertSame("", $ret->getIdentity()); @@ -62,7 +63,7 @@ public function testAuthenticateInvalid() public function testAuthenticateLoginInvalid() { - $adapter = new Adapter\OpenId("%sd", new \Zend_OpenId_Consumer_Storage_File(__DIR__."/TestAsset/OpenId")); + $adapter = new OpenIDAdapter("%sd", new OpenIDFileStorage(__DIR__."/TestAsset/OpenId")); $ret = $adapter->authenticate(); $this->assertFalse($ret->isValid()); $this->assertSame("%sd", $ret->getIdentity()); @@ -77,7 +78,7 @@ public function testAuthenticateLoginInvalid() public function testAuthenticateLoginValid() { $expiresIn = time() + 600; - $storage = new \Zend_OpenId_Consumer_Storage_File(__DIR__."/TestAsset/OpenId"); + $storage = new OpenIDFileStorage(__DIR__."/TestAsset/OpenId"); $storage->delDiscoveryInfo(self::ID); $storage->addDiscoveryInfo(self::ID, self::REAL_ID, self::SERVER, 1.1, $expiresIn); $storage->delAssociation(self::SERVER); @@ -87,7 +88,7 @@ public function testAuthenticateLoginValid() $_SERVER['SCRIPT_URI'] = "http://www.zf-test.com/test.php"; - $adapter = new Adapter\OpenId(self::ID, $storage); + $adapter = new OpenIDAdapter(self::ID, $storage); $this->assertSame($adapter, $adapter->setResponse($response)); $ret = $adapter->authenticate(); $this->assertTrue(is_null($ret)); @@ -124,7 +125,7 @@ public function testAuthenticateLoginValid() public function testSetIdentity() { $expiresIn = time() + 600; - $storage = new \Zend_OpenId_Consumer_Storage_File(__DIR__."/TestAsset/OpenId"); + $storage = new OpenIDFileStorage(__DIR__."/TestAsset/OpenId"); $storage->delDiscoveryInfo(self::ID); $storage->addDiscoveryInfo(self::ID, self::REAL_ID, self::SERVER, 1.1, $expiresIn); $storage->delAssociation(self::SERVER); @@ -134,7 +135,7 @@ public function testSetIdentity() $_SERVER['SCRIPT_URI'] = "http://www.zf-test.com/test.php"; - $adapter = new Adapter\OpenId(null, $storage); + $adapter = new OpenIDAdapter(null, $storage); $this->assertSame($adapter, $adapter->setIdentity(self::ID)); $adapter->setResponse($response); $ret = $adapter->authenticate(); @@ -172,7 +173,7 @@ public function testSetIdentity() public function testSetStorage() { $expiresIn = time() + 600; - $storage = new \Zend_OpenId_Consumer_Storage_File(__DIR__."/TestAsset/OpenId"); + $storage = new OpenIDFileStorage(__DIR__."/TestAsset/OpenId"); $storage->delDiscoveryInfo(self::ID); $storage->addDiscoveryInfo(self::ID, self::REAL_ID, self::SERVER, 1.1, $expiresIn); $storage->delAssociation(self::SERVER); @@ -182,7 +183,7 @@ public function testSetStorage() $_SERVER['SCRIPT_URI'] = "http://www.zf-test.com/test.php"; - $adapter = new Adapter\OpenId(self::ID); + $adapter = new OpenIDAdapter(self::ID); $this->assertSame($adapter, $adapter->setStorage($storage)); $adapter->setResponse($response); $ret = $adapter->authenticate(); @@ -220,7 +221,7 @@ public function testSetStorage() public function testSetReturnTo() { $expiresIn = time() + 600; - $storage = new \Zend_OpenId_Consumer_Storage_File(__DIR__."/TestAsset/OpenId"); + $storage = new OpenIDFileStorage(__DIR__."/TestAsset/OpenId"); $storage->delDiscoveryInfo(self::ID); $storage->addDiscoveryInfo(self::ID, self::REAL_ID, self::SERVER, 1.1, $expiresIn); $storage->delAssociation(self::SERVER); @@ -230,7 +231,7 @@ public function testSetReturnTo() $_SERVER['SCRIPT_URI'] = "http://www.zf-test.com/test.php"; - $adapter = new Adapter\OpenId(self::ID, $storage); + $adapter = new OpenIDAdapter(self::ID, $storage); $adapter->setResponse($response); $this->assertSame($adapter, $adapter->setReturnTo("http://www.zf-test.com/return.php")); $ret = $adapter->authenticate(); @@ -268,7 +269,7 @@ public function testSetReturnTo() public function testSetRoot() { $expiresIn = time() + 600; - $storage = new \Zend_OpenId_Consumer_Storage_File(__DIR__."/TestAsset/OpenId"); + $storage = new OpenIDFileStorage(__DIR__."/TestAsset/OpenId"); $storage->delDiscoveryInfo(self::ID); $storage->addDiscoveryInfo(self::ID, self::REAL_ID, self::SERVER, 1.1, $expiresIn); $storage->delAssociation(self::SERVER); @@ -278,7 +279,7 @@ public function testSetRoot() $_SERVER['SCRIPT_URI'] = "http://www.zf-test.com/test.php"; - $adapter = new Adapter\OpenId(self::ID, $storage); + $adapter = new OpenIDAdapter(self::ID, $storage); $adapter->setResponse($response); $this->assertSame($adapter, $adapter->setRoot("http://www.zf-test.com/root.php")); $ret = $adapter->authenticate(); @@ -326,8 +327,8 @@ public function testAuthenticateVerifyInvalid() "openid_signed" => "assoc_handle,return_to,claimed_id,identity,response_nonce,mode,signed", "openid_sig" => "h/5AFD25NpzSok5tzHEGCVUkQSw=" ); - $storage = new \Zend_OpenId_Consumer_Storage_File(__DIR__."/TestAsset/OpenId"); - $adapter = new Adapter\OpenId(null, $storage); + $storage = new OpenIDFileStorage(__DIR__."/TestAsset/OpenId"); + $adapter = new OpenIDAdapter(null, $storage); $ret = $adapter->authenticate(); $this->assertFalse($ret->isValid()); $this->assertSame(self::ID, $ret->getIdentity()); @@ -342,7 +343,7 @@ public function testAuthenticateVerifyInvalid() public function testAuthenticateVerifyGetValid() { $expiresIn = time() + 600; - $storage = new \Zend_OpenId_Consumer_Storage_File(__DIR__."/TestAsset/OpenId"); + $storage = new OpenIDFileStorage(__DIR__."/TestAsset/OpenId"); $storage->delDiscoveryInfo(self::ID); $storage->addDiscoveryInfo(self::ID, self::REAL_ID, self::SERVER, 1.1, $expiresIn); $storage->delAssociation(self::SERVER); @@ -361,7 +362,7 @@ public function testAuthenticateVerifyGetValid() "openid_signed" => "assoc_handle,return_to,claimed_id,identity,response_nonce,mode,signed", "openid_sig" => "h/5AFD25NpzSok5tzHEGCVUkQSw=" ); - $adapter = new Adapter\OpenId(null, $storage); + $adapter = new OpenIDAdapter(null, $storage); $ret = $adapter->authenticate(); $this->assertTrue($ret->isValid()); } @@ -369,7 +370,7 @@ public function testAuthenticateVerifyGetValid() public function testAuthenticateVerifyPostValid() { $expiresIn = time() + 600; - $storage = new \Zend_OpenId_Consumer_Storage_File(__DIR__."/TestAsset/OpenId"); + $storage = new OpenIDFileStorage(__DIR__."/TestAsset/OpenId"); $storage->delDiscoveryInfo(self::ID); $storage->addDiscoveryInfo(self::ID, self::REAL_ID, self::SERVER, 1.1, $expiresIn); $storage->delAssociation(self::SERVER); @@ -389,7 +390,7 @@ public function testAuthenticateVerifyPostValid() "openid_signed" => "assoc_handle,return_to,claimed_id,identity,response_nonce,mode,signed", "openid_sig" => "h/5AFD25NpzSok5tzHEGCVUkQSw=" ); - $adapter = new Adapter\OpenId(null, $storage); + $adapter = new OpenIDAdapter(null, $storage); $ret = $adapter->authenticate(); $this->assertTrue($ret->isValid()); } @@ -397,7 +398,7 @@ public function testAuthenticateVerifyPostValid() public function testSetExtensions() { $expiresIn = time() + 600; - $storage = new \Zend_OpenId_Consumer_Storage_File(__DIR__."/TestAsset/OpenId"); + $storage = new OpenIDFileStorage(__DIR__."/TestAsset/OpenId"); $this->assertTrue( $storage->delDiscoveryInfo(self::ID) ); $this->assertTrue( $storage->addDiscoveryInfo(self::ID, self::REAL_ID, self::SERVER, 2.0, $expiresIn) ); $storage->delAssociation(self::SERVER); @@ -407,7 +408,7 @@ public function testSetExtensions() $_SERVER['SCRIPT_URI'] = "http://www.zf-test.com/test.php"; $_SERVER['REQUEST_METHOD'] = 'GET'; $_GET = array( - "openid_ns" => \Zend_OpenId::NS_2_0, + "openid_ns" => \Zend\OpenID\OpenID::NS_2_0, "openid_return_to" => "http://www.zf-test.com/test.php", "openid_assoc_handle" => self::HANDLE, "openid_claimed_id" => self::ID, @@ -421,8 +422,8 @@ public function testSetExtensions() "openid_sig" => "jcV5K517GrjOxjRzi0QNLX2D+1s=" ); $_POST = array(); - $adapter = new Adapter\OpenId(null, $storage); - $sreg= new \Zend_OpenId_Extension_Sreg(array("nickname"=>true,"email"=>false)); + $adapter = new OpenIDAdapter(null, $storage); + $sreg= new OpenIDSregExtension(array("nickname"=>true,"email"=>false)); $this->assertSame($adapter, $adapter->setExtensions($sreg)); $ret = $adapter->authenticate(); $this->assertTrue($ret->isValid()); @@ -433,7 +434,7 @@ public function testSetExtensions() function testSetCheckImmediate() { $expiresIn = time() + 600; - $storage = new \Zend_OpenId_Consumer_Storage_File(__DIR__."/TestAsset/OpenId"); + $storage = new OpenIDFileStorage(__DIR__."/TestAsset/OpenId"); $storage->delDiscoveryInfo(self::ID); $storage->addDiscoveryInfo(self::ID, self::REAL_ID, self::SERVER, 1.1, $expiresIn); $storage->delAssociation(self::SERVER); @@ -443,7 +444,7 @@ function testSetCheckImmediate() $_SERVER['SCRIPT_URI'] = "http://www.zf-test.com/test.php"; - $adapter = new Adapter\OpenId(self::ID, $storage); + $adapter = new OpenIDAdapter(self::ID, $storage); $adapter->setCheckImmediate(true); $this->assertSame($adapter, $adapter->setResponse($response)); $ret = $adapter->authenticate(); @@ -480,10 +481,10 @@ function testSetCheckImmediate() function testSetHttpClient() { - $storage = new \Zend_OpenId_Consumer_Storage_File(__DIR__."/TestAsset/OpenId"); + $storage = new OpenIDFileStorage(__DIR__."/TestAsset/OpenId"); $storage->delDiscoveryInfo(self::ID); $storage->delAssociation(self::SERVER); - $adapter = new Adapter\OpenId(self::ID, $storage); + $adapter = new OpenIDAdapter(self::ID, $storage); $http = new \Zend\HTTP\Client(null, array( 'maxredirects' => 4, diff --git a/test/Adapter/TestAsset/OpenIdResponseHelper.php b/test/Adapter/TestAsset/OpenIdResponseHelper.php index d23a4d9..0939ba4 100644 --- a/test/Adapter/TestAsset/OpenIdResponseHelper.php +++ b/test/Adapter/TestAsset/OpenIdResponseHelper.php @@ -25,11 +25,13 @@ */ namespace ZendTest\Authentication\Adapter\TestAsset; +use Zend\Controller\Response\AbstractResponse; + /** * Zend_OpenId */ -\Zend_OpenId::$exitOnRedirect = false; +\Zend\OpenID\OpenID::$exitOnRedirect = false; /** * @category Zend @@ -38,7 +40,7 @@ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ -class OpenIdResponseHelper extends \Zend_Controller_Response_Abstract +class OpenIdResponseHelper extends AbstractResponse { private $_canSendHeaders; From e3814e65fee78b83940c2201dc8bd6fe77774b6a Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Tue, 29 Jun 2010 16:55:21 -0400 Subject: [PATCH 06/61] Zend_Authentication migration - DbTable adapter now works --- src/Adapter/DbTable.php | 24 ++++++++++++++---------- test/Adapter/DbTableTest.php | 21 +++++++++++---------- 2 files changed, 25 insertions(+), 20 deletions(-) diff --git a/src/Adapter/DbTable.php b/src/Adapter/DbTable.php index d8faa3c..17baec9 100644 --- a/src/Adapter/DbTable.php +++ b/src/Adapter/DbTable.php @@ -25,7 +25,11 @@ */ namespace Zend\Authentication\Adapter; use Zend\Authentication\Adapter as AuthenticationAdapter, - Zend\Authentication\Result as AuthenticationResult; + Zend\Authentication\Result as AuthenticationResult, + Zend\DB\DB, + Zend\DB\Adapter\AbstractAdapter as AbstractDBAdapter, + Zend\DB\Expr as DBExpr, + Zend\DB\Select\Select as DBSelect; /** * @uses Zend\Authentication\Adapter\Exception @@ -44,12 +48,12 @@ class DbTable implements AuthenticationAdapter /** * Database Connection * - * @var Zend_Db_Adapter_Abstract + * @var Zend\DB\Adapter\AbstractAdapter */ protected $_zendDb = null; /** - * @var Zend_Db_Select + * @var Zend\DB\Select */ protected $_dbSelect = null; @@ -112,14 +116,14 @@ class DbTable implements AuthenticationAdapter /** * __construct() - Sets configuration options * - * @param Zend_Db_Adapter_Abstract $zendDb + * @param Zend\DB\Adapter\AbstractAdapter $zendDb * @param string $tableName * @param string $identityColumn * @param string $credentialColumn * @param string $credentialTreatment * @return void */ - public function __construct(\Zend_Db_Adapter_Abstract $zendDb, $tableName = null, $identityColumn = null, + public function __construct(AbstractDBAdapter $zendDb, $tableName = null, $identityColumn = null, $credentialColumn = null, $credentialTreatment = null) { $this->_zendDb = $zendDb; @@ -228,7 +232,7 @@ public function setCredential($credential) /** * getDbSelect() - Return the preauthentication Db Select object for userland select query modification * - * @return Zend_Db_Select + * @return Zend\DB\Select */ public function getDbSelect() { @@ -357,7 +361,7 @@ protected function _authenticateCreateSelect() $this->_credentialTreatment = '?'; } - $credentialExpression = new \Zend_Db_Expr( + $credentialExpression = new DBExpr( '(CASE WHEN ' . $this->_zendDb->quoteInto( $this->_zendDb->quoteIdentifier($this->_credentialColumn, true) @@ -386,12 +390,12 @@ protected function _authenticateCreateSelect() * object is encountered * @return array */ - protected function _authenticateQuerySelect(\Zend_Db_Select $dbSelect) + protected function _authenticateQuerySelect(DBSelect $dbSelect) { try { - if ($this->_zendDb->getFetchMode() != \Zend_DB::FETCH_ASSOC) { + if ($this->_zendDb->getFetchMode() != DB::FETCH_ASSOC) { $origDbFetchMode = $this->_zendDb->getFetchMode(); - $this->_zendDb->setFetchMode(\Zend_DB::FETCH_ASSOC); + $this->_zendDb->setFetchMode(DB::FETCH_ASSOC); } $resultIdentities = $this->_zendDb->fetchAll($dbSelect->__toString()); if (isset($origDbFetchMode)) { diff --git a/test/Adapter/DbTableTest.php b/test/Adapter/DbTableTest.php index c34cf0d..9dc6da9 100644 --- a/test/Adapter/DbTableTest.php +++ b/test/Adapter/DbTableTest.php @@ -25,10 +25,11 @@ */ namespace ZendTest\Authentication\Adapter; -use Zend\Authentication\Adapter; -use Zend\Authentication; -use Zend_Db_Select; -use Zend_Db; +use Zend\Authentication\Adapter, + Zend\Authentication, + Zend\DB\DB, + Zend\DB\Adapter\PDO\SQLite as SQLiteAdapter, + Zend\DB\Select\Select as DBSelect; /** * @category Zend @@ -82,7 +83,7 @@ public function setUp() public function tearDown() { $this->_adapter = null; - if ($this->_db instanceof \Zend_Db_Adapter_Abstract) { + if ($this->_db instanceof DB\Adapter\AbstractAdapter) { $this->_db->query('DROP TABLE [users]'); } $this->_db = null; @@ -212,7 +213,7 @@ public function testGetOmittedResultRow() */ public function testAdapterCanReturnDbSelectObject() { - $this->assertTrue($this->_adapter->getDbSelect() instanceof \Zend_Db_Select); + $this->assertTrue($this->_adapter->getDbSelect() instanceof DBSelect); } /** @@ -244,7 +245,7 @@ public function testAdapterReturnsASelectObjectWithoutAuthTimeModificationsAfter $this->_adapter->setCredential('my_password'); $this->_adapter->authenticate(); $selectAfterAuth = $this->_adapter->getDbSelect(); - $whereParts = $selectAfterAuth->getPart(\Zend_Db_Select::WHERE); + $whereParts = $selectAfterAuth->getPart(DBSelect::WHERE); $this->assertEquals(1, count($whereParts)); $this->assertEquals('(1 = 1)', array_pop($whereParts)); } @@ -329,12 +330,12 @@ public function testCatchExceptionBadSql() public function testDbTableAdapterUsesCaseFolding() { $this->tearDown(); - $this->_setupDbAdapter(array(\Zend_Db::CASE_FOLDING => \Zend_Db::CASE_UPPER)); + $this->_setupDbAdapter(array(DB::CASE_FOLDING => DB::CASE_UPPER)); $this->_setupAuthAdapter(); $this->_adapter->setIdentity('my_username'); $this->_adapter->setCredential('my_password'); - $this->_db->foldCase(\Zend_Db::CASE_UPPER); + $this->_db->foldCase(DB::CASE_UPPER); $this->_adapter->authenticate(); } @@ -346,7 +347,7 @@ protected function _setupDbAdapter($optionalParams = array()) $params['options'] = $optionalParams; } - $this->_db = new \Zend_Db_Adapter_Pdo_Sqlite($params); + $this->_db = new SQLiteAdapter($params); $sqlCreate = 'CREATE TABLE [users] ( ' . '[id] INTEGER NOT NULL PRIMARY KEY, ' From 97f728fa6c776dc7d9c227c46dd730a7b98ccaf6 Mon Sep 17 00:00:00 2001 From: Stefan Gehrig Date: Wed, 30 Jun 2010 12:43:47 +0200 Subject: [PATCH 07/61] test --- src/Adapter/OpenID.php | 285 -------------------- test/Adapter/OpenIDTest.php | 506 ------------------------------------ 2 files changed, 791 deletions(-) delete mode 100644 src/Adapter/OpenID.php delete mode 100644 test/Adapter/OpenIDTest.php diff --git a/src/Adapter/OpenID.php b/src/Adapter/OpenID.php deleted file mode 100644 index 3052a80..0000000 --- a/src/Adapter/OpenID.php +++ /dev/null @@ -1,285 +0,0 @@ -_id = $id; - $this->_storage = $storage; - $this->_returnTo = $returnTo; - $this->_root = $root; - $this->_extensions = $extensions; - $this->_response = $response; - } - - /** - * Sets the value to be used as the identity - * - * @param string $id the identity value - * @return Zend\Authentication\Adapter\OpenId Provides a fluent interface - */ - public function setIdentity($id) - { - $this->_id = $id; - return $this; - } - - /** - * Sets the storage implementation which will be use by OpenId - * - * @param Zend_OpenId_Consumer_Storage $storage - * @return Zend\Authentication\Adapter\OpenId Provides a fluent interface - */ - public function setStorage(OpenIDStorage $storage) - { - $this->_storage = $storage; - return $this; - } - - /** - * Sets the HTTP URL to redirect response from server to - * - * @param string $returnTo - * @return \Zend\Authentication\Adapter\OpenId Provides a fluent interface - */ - public function setReturnTo($returnTo) - { - $this->_returnTo = $returnTo; - return $this; - } - - /** - * Sets HTTP URL to identify consumer on server - * - * @param string $root - * @return Zend\Authentication\Adapter\OpenId Provides a fluent interface - */ - public function setRoot($root) - { - $this->_root = $root; - return $this; - } - - /** - * Sets OpenID extension(s) - * - * @param mixed $extensions - * @return Zend\Authentication\Adapter\OpenId Provides a fluent interface - */ - public function setExtensions($extensions) - { - $this->_extensions = $extensions; - return $this; - } - - /** - * Sets an optional response object to perform HTTP or HTML form redirection - * - * @param string $root - * @return Zend\Authentication\Adapter\OpenId Provides a fluent interface - */ - public function setResponse($response) - { - $this->_response = $response; - return $this; - } - - /** - * Enables or disables interaction with user during authentication on - * OpenID provider. - * - * @param bool $check_immediate - * @return Zend\Authentication\Adapter\OpenId Provides a fluent interface - */ - public function setCheckImmediate($check_immediate) - { - $this->_check_immediate = $check_immediate; - return $this; - } - - /** - * Sets HTTP client object to make HTTP requests - * - * @param Zend\HTTP\Client $client HTTP client object to be used - */ - public function setHttpClient($client) - { - $this->_httpClient = $client; - } - - /** - * Authenticates the given OpenId identity. - * Defined by Zend_Auth_Adapter_Interface. - * - * @throws Zend\Authentication\Adapter\Exception If answering the authentication query is impossible - * @return Zend\Authentication\Result - */ - public function authenticate() { - $id = $this->_id; - if (!empty($id)) { - $consumer = new GenericConsumer($this->_storage); - $consumer->setHttpClient($this->_httpClient); - /* login() is never returns on success */ - if (!$this->_check_immediate) { - if (!$consumer->login($id, - $this->_returnTo, - $this->_root, - $this->_extensions, - $this->_response)) { - return new AuthenticationResult( - AuthenticationResult::FAILURE, - $id, - array("Authentication failed", $consumer->getError())); - } - } else { - if (!$consumer->check($id, - $this->_returnTo, - $this->_root, - $this->_extensions, - $this->_response)) { - return new AuthenticationResult( - AuthenticationResult::FAILURE, - $id, - array("Authentication failed", $consumer->getError())); - } - } - } else { - $params = (isset($_SERVER['REQUEST_METHOD']) && - $_SERVER['REQUEST_METHOD']=='POST') ? $_POST: $_GET; - $consumer = new GenericConsumer($this->_storage); - $consumer->setHttpClient($this->_httpClient); - if ($consumer->verify( - $params, - $id, - $this->_extensions)) { - return new AuthenticationResult( - AuthenticationResult::SUCCESS, - $id, - array("Authentication successful")); - } else { - return new AuthenticationResult( - AuthenticationResult::FAILURE, - $id, - array("Authentication failed", $consumer->getError())); - } - } - } -} diff --git a/test/Adapter/OpenIDTest.php b/test/Adapter/OpenIDTest.php deleted file mode 100644 index 8b28146..0000000 --- a/test/Adapter/OpenIDTest.php +++ /dev/null @@ -1,506 +0,0 @@ -authenticate(); - $this->assertFalse($ret->isValid()); - $this->assertSame("", $ret->getIdentity()); - $this->assertSame(0, $ret->getCode()); - $msgs = $ret->getMessages(); - $this->assertTrue(is_array($msgs)); - $this->assertSame(2, count($msgs)); - $this->assertSame("Authentication failed", $msgs[0]); - $this->assertSame("Missing openid.mode", $msgs[1]); - } - - public function testAuthenticateLoginInvalid() - { - $adapter = new OpenIDAdapter("%sd", new OpenIDFileStorage(__DIR__."/TestAsset/OpenId")); - $ret = $adapter->authenticate(); - $this->assertFalse($ret->isValid()); - $this->assertSame("%sd", $ret->getIdentity()); - $this->assertSame(0, $ret->getCode()); - $msgs = $ret->getMessages(); - $this->assertTrue(is_array($msgs)); - $this->assertSame(2, count($msgs)); - $this->assertSame("Authentication failed", $msgs[0]); - $this->assertSame("Normalisation failed", $msgs[1]); - } - - public function testAuthenticateLoginValid() - { - $expiresIn = time() + 600; - $storage = new OpenIDFileStorage(__DIR__."/TestAsset/OpenId"); - $storage->delDiscoveryInfo(self::ID); - $storage->addDiscoveryInfo(self::ID, self::REAL_ID, self::SERVER, 1.1, $expiresIn); - $storage->delAssociation(self::SERVER); - $storage->addAssociation(self::SERVER, self::HANDLE, self::MAC_FUNC, self::SECRET, $expiresIn); - - $response = new TestAsset\OpenIdResponseHelper(true); - - $_SERVER['SCRIPT_URI'] = "http://www.zf-test.com/test.php"; - - $adapter = new OpenIDAdapter(self::ID, $storage); - $this->assertSame($adapter, $adapter->setResponse($response)); - $ret = $adapter->authenticate(); - $this->assertTrue(is_null($ret)); - $headers = $response->getHeaders(); - $this->assertSame( '', $response->getBody() ); - $this->assertTrue( is_array($headers) ); - $this->assertSame( 1, count($headers) ); - $this->assertTrue( is_array($headers[0]) ); - $this->assertSame( 3, count($headers[0]) ); - $this->assertSame( 'Location', $headers[0]['name'] ); - $this->assertSame( true, $headers[0]['replace'] ); - $url = $headers[0]['value']; - $url = parse_url($url); - $this->assertSame( "http", $url['scheme'] ); - $this->assertSame( "www.myopenid.com", $url['host'] ); - $this->assertSame( "/", $url['path'] ); - $q = explode("&", $url['query']); - $query = array(); - foreach($q as $var) { - if (list($key, $val) = explode("=", $var, 2)) { - $query[$key] = $val; - } - } - $this->assertTrue( is_array($query) ); - $this->assertSame( 6, count($query) ); - $this->assertSame( 'checkid_setup', $query['openid.mode'] ); - $this->assertSame( 'http%3A%2F%2Freal_id.myopenid.com%2F', $query['openid.identity'] ); - $this->assertSame( 'http%3A%2F%2Fid.myopenid.com%2F', $query['openid.claimed_id'] ); - $this->assertSame( self::HANDLE, $query['openid.assoc_handle'] ); - $this->assertSame( 'http%3A%2F%2Fwww.zf-test.com%2Ftest.php', $query['openid.return_to'] ); - $this->assertSame( 'http%3A%2F%2Fwww.zf-test.com', $query['openid.trust_root'] ); - } - - public function testSetIdentity() - { - $expiresIn = time() + 600; - $storage = new OpenIDFileStorage(__DIR__."/TestAsset/OpenId"); - $storage->delDiscoveryInfo(self::ID); - $storage->addDiscoveryInfo(self::ID, self::REAL_ID, self::SERVER, 1.1, $expiresIn); - $storage->delAssociation(self::SERVER); - $storage->addAssociation(self::SERVER, self::HANDLE, self::MAC_FUNC, self::SECRET, $expiresIn); - - $response = new TestAsset\OpenIdResponseHelper(true); - - $_SERVER['SCRIPT_URI'] = "http://www.zf-test.com/test.php"; - - $adapter = new OpenIDAdapter(null, $storage); - $this->assertSame($adapter, $adapter->setIdentity(self::ID)); - $adapter->setResponse($response); - $ret = $adapter->authenticate(); - $this->assertTrue(is_null($ret)); - $headers = $response->getHeaders(); - $this->assertSame( '', $response->getBody() ); - $this->assertTrue( is_array($headers) ); - $this->assertSame( 1, count($headers) ); - $this->assertTrue( is_array($headers[0]) ); - $this->assertSame( 3, count($headers[0]) ); - $this->assertSame( 'Location', $headers[0]['name'] ); - $this->assertSame( true, $headers[0]['replace'] ); - $url = $headers[0]['value']; - $url = parse_url($url); - $this->assertSame( "http", $url['scheme'] ); - $this->assertSame( "www.myopenid.com", $url['host'] ); - $this->assertSame( "/", $url['path'] ); - $q = explode("&", $url['query']); - $query = array(); - foreach($q as $var) { - if (list($key, $val) = explode("=", $var, 2)) { - $query[$key] = $val; - } - } - $this->assertTrue( is_array($query) ); - $this->assertSame( 6, count($query) ); - $this->assertSame( 'checkid_setup', $query['openid.mode'] ); - $this->assertSame( 'http%3A%2F%2Freal_id.myopenid.com%2F', $query['openid.identity'] ); - $this->assertSame( 'http%3A%2F%2Fid.myopenid.com%2F', $query['openid.claimed_id'] ); - $this->assertSame( self::HANDLE, $query['openid.assoc_handle'] ); - $this->assertSame( 'http%3A%2F%2Fwww.zf-test.com%2Ftest.php', $query['openid.return_to'] ); - $this->assertSame( 'http%3A%2F%2Fwww.zf-test.com', $query['openid.trust_root'] ); - } - - public function testSetStorage() - { - $expiresIn = time() + 600; - $storage = new OpenIDFileStorage(__DIR__."/TestAsset/OpenId"); - $storage->delDiscoveryInfo(self::ID); - $storage->addDiscoveryInfo(self::ID, self::REAL_ID, self::SERVER, 1.1, $expiresIn); - $storage->delAssociation(self::SERVER); - $storage->addAssociation(self::SERVER, self::HANDLE, self::MAC_FUNC, self::SECRET, $expiresIn); - - $response = new TestAsset\OpenIdResponseHelper(true); - - $_SERVER['SCRIPT_URI'] = "http://www.zf-test.com/test.php"; - - $adapter = new OpenIDAdapter(self::ID); - $this->assertSame($adapter, $adapter->setStorage($storage)); - $adapter->setResponse($response); - $ret = $adapter->authenticate(); - $this->assertTrue(is_null($ret)); - $headers = $response->getHeaders(); - $this->assertSame( '', $response->getBody() ); - $this->assertTrue( is_array($headers) ); - $this->assertSame( 1, count($headers) ); - $this->assertTrue( is_array($headers[0]) ); - $this->assertSame( 3, count($headers[0]) ); - $this->assertSame( 'Location', $headers[0]['name'] ); - $this->assertSame( true, $headers[0]['replace'] ); - $url = $headers[0]['value']; - $url = parse_url($url); - $this->assertSame( "http", $url['scheme'] ); - $this->assertSame( "www.myopenid.com", $url['host'] ); - $this->assertSame( "/", $url['path'] ); - $q = explode("&", $url['query']); - $query = array(); - foreach($q as $var) { - if (list($key, $val) = explode("=", $var, 2)) { - $query[$key] = $val; - } - } - $this->assertTrue( is_array($query) ); - $this->assertSame( 6, count($query) ); - $this->assertSame( 'checkid_setup', $query['openid.mode'] ); - $this->assertSame( 'http%3A%2F%2Freal_id.myopenid.com%2F', $query['openid.identity'] ); - $this->assertSame( 'http%3A%2F%2Fid.myopenid.com%2F', $query['openid.claimed_id'] ); - $this->assertSame( self::HANDLE, $query['openid.assoc_handle'] ); - $this->assertSame( 'http%3A%2F%2Fwww.zf-test.com%2Ftest.php', $query['openid.return_to'] ); - $this->assertSame( 'http%3A%2F%2Fwww.zf-test.com', $query['openid.trust_root'] ); - } - - public function testSetReturnTo() - { - $expiresIn = time() + 600; - $storage = new OpenIDFileStorage(__DIR__."/TestAsset/OpenId"); - $storage->delDiscoveryInfo(self::ID); - $storage->addDiscoveryInfo(self::ID, self::REAL_ID, self::SERVER, 1.1, $expiresIn); - $storage->delAssociation(self::SERVER); - $storage->addAssociation(self::SERVER, self::HANDLE, self::MAC_FUNC, self::SECRET, $expiresIn); - - $response = new TestAsset\OpenIdResponseHelper(true); - - $_SERVER['SCRIPT_URI'] = "http://www.zf-test.com/test.php"; - - $adapter = new OpenIDAdapter(self::ID, $storage); - $adapter->setResponse($response); - $this->assertSame($adapter, $adapter->setReturnTo("http://www.zf-test.com/return.php")); - $ret = $adapter->authenticate(); - $this->assertTrue(is_null($ret)); - $headers = $response->getHeaders(); - $this->assertSame( '', $response->getBody() ); - $this->assertTrue( is_array($headers) ); - $this->assertSame( 1, count($headers) ); - $this->assertTrue( is_array($headers[0]) ); - $this->assertSame( 3, count($headers[0]) ); - $this->assertSame( 'Location', $headers[0]['name'] ); - $this->assertSame( true, $headers[0]['replace'] ); - $url = $headers[0]['value']; - $url = parse_url($url); - $this->assertSame( "http", $url['scheme'] ); - $this->assertSame( "www.myopenid.com", $url['host'] ); - $this->assertSame( "/", $url['path'] ); - $q = explode("&", $url['query']); - $query = array(); - foreach($q as $var) { - if (list($key, $val) = explode("=", $var, 2)) { - $query[$key] = $val; - } - } - $this->assertTrue( is_array($query) ); - $this->assertSame( 6, count($query) ); - $this->assertSame( 'checkid_setup', $query['openid.mode'] ); - $this->assertSame( 'http%3A%2F%2Freal_id.myopenid.com%2F', $query['openid.identity'] ); - $this->assertSame( 'http%3A%2F%2Fid.myopenid.com%2F', $query['openid.claimed_id'] ); - $this->assertSame( self::HANDLE, $query['openid.assoc_handle'] ); - $this->assertSame( 'http%3A%2F%2Fwww.zf-test.com%2Freturn.php', $query['openid.return_to'] ); - $this->assertSame( 'http%3A%2F%2Fwww.zf-test.com', $query['openid.trust_root'] ); - } - - public function testSetRoot() - { - $expiresIn = time() + 600; - $storage = new OpenIDFileStorage(__DIR__."/TestAsset/OpenId"); - $storage->delDiscoveryInfo(self::ID); - $storage->addDiscoveryInfo(self::ID, self::REAL_ID, self::SERVER, 1.1, $expiresIn); - $storage->delAssociation(self::SERVER); - $storage->addAssociation(self::SERVER, self::HANDLE, self::MAC_FUNC, self::SECRET, $expiresIn); - - $response = new TestAsset\OpenIdResponseHelper(true); - - $_SERVER['SCRIPT_URI'] = "http://www.zf-test.com/test.php"; - - $adapter = new OpenIDAdapter(self::ID, $storage); - $adapter->setResponse($response); - $this->assertSame($adapter, $adapter->setRoot("http://www.zf-test.com/root.php")); - $ret = $adapter->authenticate(); - $this->assertTrue(is_null($ret)); - $headers = $response->getHeaders(); - $this->assertSame( '', $response->getBody() ); - $this->assertTrue( is_array($headers) ); - $this->assertSame( 1, count($headers) ); - $this->assertTrue( is_array($headers[0]) ); - $this->assertSame( 3, count($headers[0]) ); - $this->assertSame( 'Location', $headers[0]['name'] ); - $this->assertSame( true, $headers[0]['replace'] ); - $url = $headers[0]['value']; - $url = parse_url($url); - $this->assertSame( "http", $url['scheme'] ); - $this->assertSame( "www.myopenid.com", $url['host'] ); - $this->assertSame( "/", $url['path'] ); - $q = explode("&", $url['query']); - $query = array(); - foreach($q as $var) { - if (list($key, $val) = explode("=", $var, 2)) { - $query[$key] = $val; - } - } - $this->assertTrue( is_array($query) ); - $this->assertSame( 6, count($query) ); - $this->assertSame( 'checkid_setup', $query['openid.mode'] ); - $this->assertSame( 'http%3A%2F%2Freal_id.myopenid.com%2F', $query['openid.identity'] ); - $this->assertSame( 'http%3A%2F%2Fid.myopenid.com%2F', $query['openid.claimed_id'] ); - $this->assertSame( self::HANDLE, $query['openid.assoc_handle'] ); - $this->assertSame( 'http%3A%2F%2Fwww.zf-test.com%2Ftest.php', $query['openid.return_to'] ); - $this->assertSame( 'http%3A%2F%2Fwww.zf-test.com%2Froot.php', $query['openid.trust_root'] ); - } - - public function testAuthenticateVerifyInvalid() - { - $_SERVER['SCRIPT_URI'] = "http://www.zf-test.com/test.php"; - unset($_SERVER['REQUEST_METHOD']); - $_GET = array('openid_mode'=>'id_res', - "openid_return_to" => "http://www.zf-test.com/test.php", - "openid_assoc_handle" => self::HANDLE, - "openid_claimed_id" => self::ID, - "openid_identity" => self::REAL_ID, - "openid_response_nonce" => "2007-08-14T12:52:33Z46c1a59124fff", - "openid_signed" => "assoc_handle,return_to,claimed_id,identity,response_nonce,mode,signed", - "openid_sig" => "h/5AFD25NpzSok5tzHEGCVUkQSw=" - ); - $storage = new OpenIDFileStorage(__DIR__."/TestAsset/OpenId"); - $adapter = new OpenIDAdapter(null, $storage); - $ret = $adapter->authenticate(); - $this->assertFalse($ret->isValid()); - $this->assertSame(self::ID, $ret->getIdentity()); - $this->assertSame(0, $ret->getCode()); - $msgs = $ret->getMessages(); - $this->assertTrue(is_array($msgs)); - $this->assertSame(2, count($msgs)); - $this->assertSame("Authentication failed", $msgs[0]); - $this->assertSame("Signature check failed", $msgs[1]); - } - - public function testAuthenticateVerifyGetValid() - { - $expiresIn = time() + 600; - $storage = new OpenIDFileStorage(__DIR__."/TestAsset/OpenId"); - $storage->delDiscoveryInfo(self::ID); - $storage->addDiscoveryInfo(self::ID, self::REAL_ID, self::SERVER, 1.1, $expiresIn); - $storage->delAssociation(self::SERVER); - $storage->addAssociation(self::SERVER, self::HANDLE, self::MAC_FUNC, self::SECRET, $expiresIn); - $storage->purgeNonces(); - - $_SERVER['SCRIPT_URI'] = "http://www.zf-test.com/test.php"; - unset($_SERVER['REQUEST_METHOD']); - $_GET = array( - "openid_return_to" => "http://www.zf-test.com/test.php", - "openid_assoc_handle" => self::HANDLE, - "openid_claimed_id" => self::ID, - "openid_identity" => self::REAL_ID, - "openid_response_nonce" => "2007-08-14T12:52:33Z46c1a59124ffe", - "openid_mode" => "id_res", - "openid_signed" => "assoc_handle,return_to,claimed_id,identity,response_nonce,mode,signed", - "openid_sig" => "h/5AFD25NpzSok5tzHEGCVUkQSw=" - ); - $adapter = new OpenIDAdapter(null, $storage); - $ret = $adapter->authenticate(); - $this->assertTrue($ret->isValid()); - } - - public function testAuthenticateVerifyPostValid() - { - $expiresIn = time() + 600; - $storage = new OpenIDFileStorage(__DIR__."/TestAsset/OpenId"); - $storage->delDiscoveryInfo(self::ID); - $storage->addDiscoveryInfo(self::ID, self::REAL_ID, self::SERVER, 1.1, $expiresIn); - $storage->delAssociation(self::SERVER); - $storage->addAssociation(self::SERVER, self::HANDLE, self::MAC_FUNC, self::SECRET, $expiresIn); - $storage->purgeNonces(); - - $_SERVER['SCRIPT_URI'] = "http://www.zf-test.com/test.php"; - $_SERVER['REQUEST_METHOD'] = 'POST'; - $_GET = array(); - $_POST = array( - "openid_return_to" => "http://www.zf-test.com/test.php", - "openid_assoc_handle" => self::HANDLE, - "openid_claimed_id" => self::ID, - "openid_identity" => self::REAL_ID, - "openid_response_nonce" => "2007-08-14T12:52:33Z46c1a59124ffe", - "openid_mode" => "id_res", - "openid_signed" => "assoc_handle,return_to,claimed_id,identity,response_nonce,mode,signed", - "openid_sig" => "h/5AFD25NpzSok5tzHEGCVUkQSw=" - ); - $adapter = new OpenIDAdapter(null, $storage); - $ret = $adapter->authenticate(); - $this->assertTrue($ret->isValid()); - } - - public function testSetExtensions() - { - $expiresIn = time() + 600; - $storage = new OpenIDFileStorage(__DIR__."/TestAsset/OpenId"); - $this->assertTrue( $storage->delDiscoveryInfo(self::ID) ); - $this->assertTrue( $storage->addDiscoveryInfo(self::ID, self::REAL_ID, self::SERVER, 2.0, $expiresIn) ); - $storage->delAssociation(self::SERVER); - $storage->addAssociation(self::SERVER, self::HANDLE, self::MAC_FUNC, self::SECRET, $expiresIn); - $storage->purgeNonces(); - - $_SERVER['SCRIPT_URI'] = "http://www.zf-test.com/test.php"; - $_SERVER['REQUEST_METHOD'] = 'GET'; - $_GET = array( - "openid_ns" => \Zend\OpenID\OpenID::NS_2_0, - "openid_return_to" => "http://www.zf-test.com/test.php", - "openid_assoc_handle" => self::HANDLE, - "openid_claimed_id" => self::ID, - "openid_identity" => self::REAL_ID, - "openid_response_nonce" => "2007-08-14T12:52:33Z46c1a59124ffe", - "openid_op_endpoint" => self::SERVER, - "openid_mode" => "id_res", - "openid_ns_sreg" => "http://openid.net/extensions/sreg/1.1", - "openid_sreg_nickname" => "test", - "openid_signed" => "ns,assoc_handle,return_to,claimed_id,identity,response_nonce,mode,ns.sreg,sreg.nickname,signed", - "openid_sig" => "jcV5K517GrjOxjRzi0QNLX2D+1s=" - ); - $_POST = array(); - $adapter = new OpenIDAdapter(null, $storage); - $sreg= new OpenIDSregExtension(array("nickname"=>true,"email"=>false)); - $this->assertSame($adapter, $adapter->setExtensions($sreg)); - $ret = $adapter->authenticate(); - $this->assertTrue($ret->isValid()); - $sreg_data = $sreg->getProperties(); - $this->assertSame("test", $sreg_data['nickname']); - } - - function testSetCheckImmediate() - { - $expiresIn = time() + 600; - $storage = new OpenIDFileStorage(__DIR__."/TestAsset/OpenId"); - $storage->delDiscoveryInfo(self::ID); - $storage->addDiscoveryInfo(self::ID, self::REAL_ID, self::SERVER, 1.1, $expiresIn); - $storage->delAssociation(self::SERVER); - $storage->addAssociation(self::SERVER, self::HANDLE, self::MAC_FUNC, self::SECRET, $expiresIn); - - $response = new TestAsset\OpenIdResponseHelper(true); - - $_SERVER['SCRIPT_URI'] = "http://www.zf-test.com/test.php"; - - $adapter = new OpenIDAdapter(self::ID, $storage); - $adapter->setCheckImmediate(true); - $this->assertSame($adapter, $adapter->setResponse($response)); - $ret = $adapter->authenticate(); - $this->assertTrue(is_null($ret)); - $headers = $response->getHeaders(); - $this->assertSame( '', $response->getBody() ); - $this->assertTrue( is_array($headers) ); - $this->assertSame( 1, count($headers) ); - $this->assertTrue( is_array($headers[0]) ); - $this->assertSame( 3, count($headers[0]) ); - $this->assertSame( 'Location', $headers[0]['name'] ); - $this->assertSame( true, $headers[0]['replace'] ); - $url = $headers[0]['value']; - $url = parse_url($url); - $this->assertSame( "http", $url['scheme'] ); - $this->assertSame( "www.myopenid.com", $url['host'] ); - $this->assertSame( "/", $url['path'] ); - $q = explode("&", $url['query']); - $query = array(); - foreach($q as $var) { - if (list($key, $val) = explode("=", $var, 2)) { - $query[$key] = $val; - } - } - $this->assertTrue( is_array($query) ); - $this->assertSame( 6, count($query) ); - $this->assertSame( 'checkid_immediate', $query['openid.mode'] ); - $this->assertSame( 'http%3A%2F%2Freal_id.myopenid.com%2F', $query['openid.identity'] ); - $this->assertSame( 'http%3A%2F%2Fid.myopenid.com%2F', $query['openid.claimed_id'] ); - $this->assertSame( self::HANDLE, $query['openid.assoc_handle'] ); - $this->assertSame( 'http%3A%2F%2Fwww.zf-test.com%2Ftest.php', $query['openid.return_to'] ); - $this->assertSame( 'http%3A%2F%2Fwww.zf-test.com', $query['openid.trust_root'] ); - } - - function testSetHttpClient() - { - $storage = new OpenIDFileStorage(__DIR__."/TestAsset/OpenId"); - $storage->delDiscoveryInfo(self::ID); - $storage->delAssociation(self::SERVER); - $adapter = new OpenIDAdapter(self::ID, $storage); - $http = new \Zend\HTTP\Client(null, - array( - 'maxredirects' => 4, - 'timeout' => 15, - 'useragent' => 'Zend_OpenId' - )); - $test = new \Zend\HTTP\Client\Adapter\Test(); - $http->setAdapter($test); - $adapter->setHttpClient($http); - $ret = $adapter->authenticate(); - $this->assertSame("GET / HTTP/1.1\r\n". - "Host: id.myopenid.com\r\n". - "Connection: close\r\n". - "Accept-encoding: gzip, deflate\r\n". - "User-Agent: Zend_OpenId\r\n\r\n", - $http->getLastRequest()); - } - -} From fe9f86a957a2fcc61be839b4b94d4d699727d3e8 Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Wed, 30 Jun 2010 09:59:33 -0400 Subject: [PATCH 08/61] Zend_Authentication migration - Updated HTTP adapter to use namespaced Controller components - Fixed HTTP adapter tests to run --- src/Adapter/HTTP.php | 9 ++++++--- test/Adapter/HTTP/AuthTest.php | 10 ++++++---- test/Adapter/HTTP/ObjectTest.php | 24 ++++++++++++------------ test/Adapter/HTTP/ProxyTest.php | 7 ++++--- 4 files changed, 28 insertions(+), 22 deletions(-) diff --git a/src/Adapter/HTTP.php b/src/Adapter/HTTP.php index fc34de2..462d2cd 100644 --- a/src/Adapter/HTTP.php +++ b/src/Adapter/HTTP.php @@ -24,8 +24,11 @@ * @namespace */ namespace Zend\Authentication\Adapter; + use Zend\Authentication\Adapter as AuthenticationAdapter, - Zend\Authentication; + Zend\Authentication, + Zend\Controller\Request\HTTP as HTTPRequest, + Zend\Controller\Response\HTTP as HTTPResponse; /** * HTTP Authentication Adapter @@ -293,7 +296,7 @@ public function getDigestResolver() * @param Zend_Controller_Request_Http $request * @return Zend\Authentication\Adapter\HTTP Provides a fluent interface */ - public function setRequest(\Zend_Controller_Request_Http $request) + public function setRequest(HTTPRequest $request) { $this->_request = $request; @@ -316,7 +319,7 @@ public function getRequest() * @param Zend_Controller_Response_Http $response * @return Zend\Authentication\Adapter\HTTP Provides a fluent interface */ - public function setResponse(\Zend_Controller_Response_Http $response) + public function setResponse(HTTPResponse $response) { $this->_response = $response; diff --git a/test/Adapter/HTTP/AuthTest.php b/test/Adapter/HTTP/AuthTest.php index 51ae25e..9eed51a 100644 --- a/test/Adapter/HTTP/AuthTest.php +++ b/test/Adapter/HTTP/AuthTest.php @@ -24,7 +24,9 @@ * @namespace */ namespace ZendTest\Auth\Adapter\HTTP; -use Zend\Authentication\Adapter\HTTP; + +use Zend\Authentication\Adapter\HTTP, + Zend\Controller\Response\HTTP as HTTPResponse; /** * @category Zend @@ -309,9 +311,9 @@ public function testBadDigestRequest() protected function _doAuth($clientHeader, $scheme) { // Set up stub request and response objects - $request = $this->getMock('Zend_Controller_Request_Http'); - $response = new \Zend_Controller_Response_Http; - $response->setHttpResponseCode(200); + $request = $this->getMock('Zend\Controller\Request\HTTP'); + $response = new HTTPResponse; + $response->setHTTPResponseCode(200); $response->headersSentThrowsException = false; // Set stub method return values diff --git a/test/Adapter/HTTP/ObjectTest.php b/test/Adapter/HTTP/ObjectTest.php index 71aed03..cefeaac 100644 --- a/test/Adapter/HTTP/ObjectTest.php +++ b/test/Adapter/HTTP/ObjectTest.php @@ -25,9 +25,9 @@ */ namespace ZendTest\Auth\Adapter\HTTP; -use Zend\Authentication\Adapter\HTTP; -use Zend\Authentication\Adapter; -use Zend\Authentication; +use Zend\Authentication\Adapter\HTTP, + Zend\Authentication\Adapter, + Zend\Authentication; /** * @category Zend @@ -188,8 +188,8 @@ public function testAuthenticateArgs() // Good, it threw an exception } - $request = $this->getMock('Zend_Controller_Request_Http'); - $response = $this->getMock('Zend_Controller_Response_Http'); + $request = $this->getMock('Zend\Controller\Request\HTTP'); + $response = $this->getMock('Zend\Controller\Response\HTTP'); // If this throws an exception, it fails $a->setRequest($request) @@ -199,8 +199,8 @@ public function testAuthenticateArgs() public function testNoResolvers() { - $request = $this->getMock('Zend_Controller_Request_Http'); - $response = $this->getMock('Zend_Controller_Response_Http'); + $request = $this->getMock('Zend\Controller\Request\HTTP'); + $response = $this->getMock('Zend\Controller\Response\HTTP'); // Stub request for Basic auth $request->expects($this->any()) @@ -220,7 +220,7 @@ public function testNoResolvers() } // Stub request for Digest auth, must be reseted (recreated) - $request = $this->getMock('Zend_Controller_Request_Http'); + $request = $this->getMock('Zend\Controller\Request\HTTP'); $request->expects($this->any()) ->method('getHeader') ->will($this->returnValue('Digest getMock('Zend_Controller_Response_Http'); - $request = $this->getMock('Zend_Controller_Request_Http'); + $response = $this->getMock('Zend\Controller\Response\HTTP'); + $request = $this->getMock('Zend\Controller\Request\HTTP'); $request->expects($this->any()) ->method('getHeader') ->will($this->returnValue('Basic getMock('Zend_Controller_Response_Http'); - $request = $this->getMock('Zend_Controller_Request_Http'); + $response = $this->getMock('Zend\Controller\Response\HTTP'); + $request = $this->getMock('Zend\Controller\Request\HTTP'); $request->expects($this->any()) ->method('getHeader') ->will($this->returnValue('NotSupportedScheme getMock('Zend_Controller_Request_Http'); - $response = new \Zend_Controller_Response_Http; + $request = $this->getMock('Zend\Controller\Request\HTTP'); + $response = new HTTPResponse; $response->setHttpResponseCode(200); $response->headersSentThrowsException = false; From d7c5283dc123a807db83a5817f7a601cff8408fa Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Fri, 2 Jul 2010 09:21:54 -0400 Subject: [PATCH 09/61] Zend\DB cleanup - Moved all subcomponents that consisted of a class and exception up one level - Consistency in interface and abstract class naming - updated all tests and code to reflect changes --- test/Adapter/DbTableTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Adapter/DbTableTest.php b/test/Adapter/DbTableTest.php index 9dc6da9..cdb38f7 100644 --- a/test/Adapter/DbTableTest.php +++ b/test/Adapter/DbTableTest.php @@ -29,7 +29,7 @@ Zend\Authentication, Zend\DB\DB, Zend\DB\Adapter\PDO\SQLite as SQLiteAdapter, - Zend\DB\Select\Select as DBSelect; + Zend\DB\Select as DBSelect; /** * @category Zend From 9fed3817afe0913a48d701ed28e49acfdc407394 Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Sat, 3 Jul 2010 10:03:14 -0400 Subject: [PATCH 10/61] Zend\DB cleanup - Moved all interfaces up a level - Flattened Zend\DB\Table class hierarchy - Cleaned up "orphaned" subcomponents - If they consisted of a class and an exception, moved them up a level - Updated dependent code to reflect the above changes --- src/Adapter/DbTable.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Adapter/DbTable.php b/src/Adapter/DbTable.php index 17baec9..81b60bf 100644 --- a/src/Adapter/DbTable.php +++ b/src/Adapter/DbTable.php @@ -29,7 +29,7 @@ Zend\DB\DB, Zend\DB\Adapter\AbstractAdapter as AbstractDBAdapter, Zend\DB\Expr as DBExpr, - Zend\DB\Select\Select as DBSelect; + Zend\DB\Select as DBSelect; /** * @uses Zend\Authentication\Adapter\Exception From bff08e419bd249a8678498e0343bb59c91306d98 Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Tue, 20 Jul 2010 08:19:13 -0400 Subject: [PATCH 11/61] HTTP -> Http - Found all instances of HTTP, in directory and filenames as well as namespace and classnames, and converted to Http --- src/Adapter/{HTTP.php => Http.php} | 32 ++++++------ src/Adapter/{HTTP => Http}/Exception.php | 2 +- src/Adapter/{HTTP => Http}/FileResolver.php | 8 +-- src/Adapter/{HTTP => Http}/Resolver.php | 6 +-- test/Adapter/{HTTP => Http}/AuthTest.php | 22 ++++---- .../{HTTP => Http}/FileResolverTest.php | 28 +++++------ test/Adapter/{HTTP => Http}/ObjectTest.php | 50 +++++++++---------- test/Adapter/{HTTP => Http}/ProxyTest.php | 22 ++++---- .../{HTTP => Http}/TestAsset/htbasic.1 | 0 .../{HTTP => Http}/TestAsset/htdigest.3 | 0 10 files changed, 85 insertions(+), 85 deletions(-) rename src/Adapter/{HTTP.php => Http.php} (96%) rename src/Adapter/{HTTP => Http}/Exception.php (96%) rename src/Adapter/{HTTP => Http}/FileResolver.php (95%) rename src/Adapter/{HTTP => Http}/Resolver.php (93%) rename test/Adapter/{HTTP => Http}/AuthTest.php (97%) rename test/Adapter/{HTTP => Http}/FileResolverTest.php (91%) rename test/Adapter/{HTTP => Http}/ObjectTest.php (83%) rename test/Adapter/{HTTP => Http}/ProxyTest.php (97%) rename test/Adapter/{HTTP => Http}/TestAsset/htbasic.1 (100%) rename test/Adapter/{HTTP => Http}/TestAsset/htdigest.3 (100%) diff --git a/src/Adapter/HTTP.php b/src/Adapter/Http.php similarity index 96% rename from src/Adapter/HTTP.php rename to src/Adapter/Http.php index 462d2cd..ea384b3 100644 --- a/src/Adapter/HTTP.php +++ b/src/Adapter/Http.php @@ -27,8 +27,8 @@ use Zend\Authentication\Adapter as AuthenticationAdapter, Zend\Authentication, - Zend\Controller\Request\HTTP as HTTPRequest, - Zend\Controller\Response\HTTP as HTTPResponse; + Zend\Controller\Request\Http as HTTPRequest, + Zend\Controller\Response\Http as HTTPResponse; /** * HTTP Authentication Adapter @@ -39,14 +39,14 @@ * @uses Zend\Authentication\Adapter * @category Zend * @package Zend_Authentication - * @subpackage Adapter_HTTP + * @subpackage Adapter_Http * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License * @todo Support auth-int * @todo Track nonces, nonce-count, opaque for replay protection and stale support * @todo Support Authentication-Info header */ -class HTTP implements AuthenticationAdapter +class Http implements AuthenticationAdapter { /** * Reference to the HTTP Request object @@ -65,14 +65,14 @@ class HTTP implements AuthenticationAdapter /** * Object that looks up user credentials for the Basic scheme * - * @var Zend\Authentication\Adapter\HTTP\Resolver + * @var Zend\Authentication\Adapter\Http\Resolver */ protected $_basicResolver; /** * Object that looks up user credentials for the Digest scheme * - * @var Zend\Authentication\Adapter\HTTP\Resolver + * @var Zend\Authentication\Adapter\Http\Resolver */ protected $_digestResolver; @@ -247,10 +247,10 @@ public function __construct(array $config) /** * Setter for the _basicResolver property * - * @param Zend\Authentication\Adapter\HTTP\Resolver $resolver - * @return Zend\Authentication\Adapter\HTTP Provides a fluent interface + * @param Zend\Authentication\Adapter\Http\Resolver $resolver + * @return Zend\Authentication\Adapter\Http Provides a fluent interface */ - public function setBasicResolver(HTTP\Resolver $resolver) + public function setBasicResolver(Http\Resolver $resolver) { $this->_basicResolver = $resolver; @@ -260,7 +260,7 @@ public function setBasicResolver(HTTP\Resolver $resolver) /** * Getter for the _basicResolver property * - * @return Zend\Authentication\Adapter\HTTP\Resolver + * @return Zend\Authentication\Adapter\Http\Resolver */ public function getBasicResolver() { @@ -270,10 +270,10 @@ public function getBasicResolver() /** * Setter for the _digestResolver property * - * @param Zend\Authentication\Adapter\HTTP\Resolver $resolver - * @return Zend\Authentication\Adapter\HTTP Provides a fluent interface + * @param Zend\Authentication\Adapter\Http\Resolver $resolver + * @return Zend\Authentication\Adapter\Http Provides a fluent interface */ - public function setDigestResolver(HTTP\Resolver $resolver) + public function setDigestResolver(Http\Resolver $resolver) { $this->_digestResolver = $resolver; @@ -283,7 +283,7 @@ public function setDigestResolver(HTTP\Resolver $resolver) /** * Getter for the _digestResolver property * - * @return Zend\Authentication\Adapter\HTTP\Resolver + * @return Zend\Authentication\Adapter\Http\Resolver */ public function getDigestResolver() { @@ -294,7 +294,7 @@ public function getDigestResolver() * Setter for the Request object * * @param Zend_Controller_Request_Http $request - * @return Zend\Authentication\Adapter\HTTP Provides a fluent interface + * @return Zend\Authentication\Adapter\Http Provides a fluent interface */ public function setRequest(HTTPRequest $request) { @@ -317,7 +317,7 @@ public function getRequest() * Setter for the Response object * * @param Zend_Controller_Response_Http $response - * @return Zend\Authentication\Adapter\HTTP Provides a fluent interface + * @return Zend\Authentication\Adapter\Http Provides a fluent interface */ public function setResponse(HTTPResponse $response) { diff --git a/src/Adapter/HTTP/Exception.php b/src/Adapter/Http/Exception.php similarity index 96% rename from src/Adapter/HTTP/Exception.php rename to src/Adapter/Http/Exception.php index 975f019..74c74d8 100644 --- a/src/Adapter/HTTP/Exception.php +++ b/src/Adapter/Http/Exception.php @@ -23,7 +23,7 @@ /** * @namespace */ -namespace Zend\Authentication\Adapter\HTTP; +namespace Zend\Authentication\Adapter\Http; /** * HTTP Auth Resolver Exception diff --git a/src/Adapter/HTTP/FileResolver.php b/src/Adapter/Http/FileResolver.php similarity index 95% rename from src/Adapter/HTTP/FileResolver.php rename to src/Adapter/Http/FileResolver.php index b8cb734..3131fd4 100644 --- a/src/Adapter/HTTP/FileResolver.php +++ b/src/Adapter/Http/FileResolver.php @@ -14,7 +14,7 @@ * * @category Zend * @package Zend_Authentication - * @subpackage Adapter_HTTP + * @subpackage Adapter_Http * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License * @version $Id$ @@ -23,13 +23,13 @@ /** * @namespace */ -namespace Zend\Authentication\Adapter\HTTP; +namespace Zend\Authentication\Adapter\Http; /** * HTTP Authentication File Resolver * - * @uses Zend\Authentication\Adapter\HTTP\Exception - * @uses Zend\Authentication\Adapter\HTTP\Resolver + * @uses Zend\Authentication\Adapter\Http\Exception + * @uses Zend\Authentication\Adapter\Http\Resolver * @category Zend * @package Zend_Authentication * @subpackage Adapter_Http diff --git a/src/Adapter/HTTP/Resolver.php b/src/Adapter/Http/Resolver.php similarity index 93% rename from src/Adapter/HTTP/Resolver.php rename to src/Adapter/Http/Resolver.php index 408c1a9..130ba2a 100644 --- a/src/Adapter/HTTP/Resolver.php +++ b/src/Adapter/Http/Resolver.php @@ -14,7 +14,7 @@ * * @category Zend * @package Zend_Authentication - * @subpackage Adapter_HTTP + * @subpackage Adapter_Http * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License * @version $Id$ @@ -23,7 +23,7 @@ /** * @namespace */ -namespace Zend\Authentication\Adapter\HTTP; +namespace Zend\Authentication\Adapter\Http; /** * Auth HTTP Resolver Interface @@ -33,7 +33,7 @@ * * @category Zend * @package Zend_Authentication - * @subpackage Adapter_HTTP + * @subpackage Adapter_Http * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ diff --git a/test/Adapter/HTTP/AuthTest.php b/test/Adapter/Http/AuthTest.php similarity index 97% rename from test/Adapter/HTTP/AuthTest.php rename to test/Adapter/Http/AuthTest.php index 9eed51a..7d4b8af 100644 --- a/test/Adapter/HTTP/AuthTest.php +++ b/test/Adapter/Http/AuthTest.php @@ -23,10 +23,10 @@ /** * @namespace */ -namespace ZendTest\Auth\Adapter\HTTP; +namespace ZendTest\Auth\Adapter\Http; -use Zend\Authentication\Adapter\HTTP, - Zend\Controller\Response\HTTP as HTTPResponse; +use Zend\Authentication\Adapter\Http, + Zend\Controller\Response\Http as HTTPResponse; /** * @category Zend @@ -88,8 +88,8 @@ class AuthTest extends \PHPUnit_Framework_TestCase public function setUp() { $this->_filesPath = __DIR__ . '/TestAsset'; - $this->_basicResolver = new HTTP\FileResolver("{$this->_filesPath}/htbasic.1"); - $this->_digestResolver = new HTTP\FileResolver("{$this->_filesPath}/htdigest.3"); + $this->_basicResolver = new Http\FileResolver("{$this->_filesPath}/htbasic.1"); + $this->_digestResolver = new Http\FileResolver("{$this->_filesPath}/htdigest.3"); $this->_basicConfig = array( 'accept_schemes' => 'basic', 'realm' => 'Test Realm' @@ -311,9 +311,9 @@ public function testBadDigestRequest() protected function _doAuth($clientHeader, $scheme) { // Set up stub request and response objects - $request = $this->getMock('Zend\Controller\Request\HTTP'); + $request = $this->getMock('Zend\Controller\Request\Http'); $response = new HTTPResponse; - $response->setHTTPResponseCode(200); + $response->setHttpResponseCode(200); $response->headersSentThrowsException = false; // Set stub method return values @@ -369,8 +369,8 @@ protected function _doAuth($clientHeader, $scheme) protected function _digestChallenge() { $timeout = ceil(time() / 300) * 300; - $nonce = md5($timeout . ':PHPUnit:Zend\\Authentication\\Adapter\\HTTP'); - $opaque = md5('Opaque Data:Zend\\Authentication\\Adapter\\HTTP'); + $nonce = md5($timeout . ':PHPUnit:Zend\\Authentication\\Adapter\\Http'); + $opaque = md5('Opaque Data:Zend\\Authentication\\Adapter\\Http'); $wwwauth = 'Digest ' . 'realm="' . $this->_digestConfig['realm'] . '", ' . 'domain="' . $this->_digestConfig['digest_domains'] . '", ' @@ -391,8 +391,8 @@ protected function _digestReply($user, $pass) { $nc = '00000001'; $timeout = ceil(time() / 300) * 300; - $nonce = md5($timeout . ':PHPUnit:Zend\Authentication\Adapter\HTTP'); - $opaque = md5('Opaque Data:Zend\\Authentication\\Adapter\\HTTP'); + $nonce = md5($timeout . ':PHPUnit:Zend\Authentication\Adapter\Http'); + $opaque = md5('Opaque Data:Zend\\Authentication\\Adapter\\Http'); $cnonce = md5('cnonce'); $response = md5(md5($user . ':' . $this->_digestConfig['realm'] . ':' . $pass) . ":$nonce:$nc:$cnonce:auth:" . md5('GET:/')); diff --git a/test/Adapter/HTTP/FileResolverTest.php b/test/Adapter/Http/FileResolverTest.php similarity index 91% rename from test/Adapter/HTTP/FileResolverTest.php rename to test/Adapter/Http/FileResolverTest.php index 987c4b1..df71e8c 100644 --- a/test/Adapter/HTTP/FileResolverTest.php +++ b/test/Adapter/Http/FileResolverTest.php @@ -23,9 +23,9 @@ /** * @namespace */ -namespace ZendTest\Auth\Adapter\HTTP; +namespace ZendTest\Auth\Adapter\Http; -use Zend\Authentication\Adapter\HTTP; +use Zend\Authentication\Adapter\Http; /** * @category Zend @@ -76,7 +76,7 @@ public function setUp() $this->_filesPath = __DIR__ . '/TestAsset'; $this->_validPath = "$this->_filesPath/htdigest.3"; $this->_badPath = 'doesnotexist'; - $this->_resolver = new HTTP\FileResolver($this->_validPath); + $this->_resolver = new Http\FileResolver($this->_validPath); } /** @@ -97,7 +97,7 @@ public function testSetFileValid() */ public function testSetFileInvalid() { - $this->setExpectedException('Zend\\Authentication\\Adapter\\HTTP\\Exception', 'Path not readable'); + $this->setExpectedException('Zend\\Authentication\\Adapter\\Http\\Exception', 'Path not readable'); $this->_resolver->setFile($this->_badPath); } @@ -108,7 +108,7 @@ public function testSetFileInvalid() */ public function testConstructValid() { - $v = new HTTP\FileResolver($this->_validPath); + $v = new Http\FileResolver($this->_validPath); $this->assertEquals($this->_validPath, $v->getFile()); } @@ -119,8 +119,8 @@ public function testConstructValid() */ public function testConstructInvalid() { - $this->setExpectedException('Zend\\Authentication\\Adapter\\HTTP\\Exception', 'Path not readable'); - $v = new HTTP\FileResolver($this->_badPath); + $this->setExpectedException('Zend\\Authentication\\Adapter\\Http\\Exception', 'Path not readable'); + $v = new Http\FileResolver($this->_badPath); } /** @@ -130,7 +130,7 @@ public function testConstructInvalid() */ public function testResolveUsernameEmpty() { - $this->setExpectedException('Zend\\Authentication\\Adapter\\HTTP\\Exception', 'Username is required'); + $this->setExpectedException('Zend\\Authentication\\Adapter\\Http\\Exception', 'Username is required'); $this->_resolver->resolve('', ''); } @@ -141,7 +141,7 @@ public function testResolveUsernameEmpty() */ public function testResolveRealmEmpty() { - $this->setExpectedException('Zend\\Authentication\\Adapter\\HTTP\\Exception', 'Realm is required'); + $this->setExpectedException('Zend\\Authentication\\Adapter\\Http\\Exception', 'Realm is required'); $this->_resolver->resolve('username', ''); } @@ -155,13 +155,13 @@ public function testResolveUsernameInvalid() try { $this->_resolver->resolve('bad:name', 'realm'); $this->fail('Accepted malformed username with colon'); - } catch (HTTP\Exception $e) { + } catch (Http\Exception $e) { $this->assertContains('Username must consist', $e->getMessage()); } try { $this->_resolver->resolve("badname\n", 'realm'); $this->fail('Accepted malformed username with newline'); - } catch (HTTP\Exception $e) { + } catch (Http\Exception $e) { $this->assertContains('Username must consist', $e->getMessage()); } } @@ -176,13 +176,13 @@ public function testResolveRealmInvalid() try { $this->_resolver->resolve('username', 'bad:realm'); $this->fail('Accepted malformed realm with colon'); - } catch (HTTP\Exception $e) { + } catch (Http\Exception $e) { $this->assertContains('Realm must consist', $e->getMessage()); } try { $this->_resolver->resolve('username', "badrealm\n"); $this->fail('Accepted malformed realm with newline'); - } catch (HTTP\Exception $e) { + } catch (Http\Exception $e) { $this->assertContains('Realm must consist', $e->getMessage()); } } @@ -198,7 +198,7 @@ public function testResolveFileDisappearsMystery() try { $this->_resolver->resolve('username', 'realm'); $this->fail('Expected thrown exception upon resolve() after moving valid file'); - } catch (HTTP\Exception $e) { + } catch (Http\Exception $e) { $this->assertContains('Unable to open password file', $e->getMessage()); } rename("$this->_filesPath/htdigest.3.renamed", "$this->_filesPath/htdigest.3"); diff --git a/test/Adapter/HTTP/ObjectTest.php b/test/Adapter/Http/ObjectTest.php similarity index 83% rename from test/Adapter/HTTP/ObjectTest.php rename to test/Adapter/Http/ObjectTest.php index cefeaac..13a3088 100644 --- a/test/Adapter/HTTP/ObjectTest.php +++ b/test/Adapter/Http/ObjectTest.php @@ -23,9 +23,9 @@ /** * @namespace */ -namespace ZendTest\Auth\Adapter\HTTP; +namespace ZendTest\Auth\Adapter\Http; -use Zend\Authentication\Adapter\HTTP, +use Zend\Authentication\Adapter\Http, Zend\Authentication\Adapter, Zend\Authentication; @@ -89,8 +89,8 @@ class ObjectTest extends \PHPUnit_Framework_TestCase public function setUp() { $this->_filesPath = __DIR__ . '/TestAsset'; - $this->_basicResolver = new HTTP\FileResolver("$this->_filesPath/htbasic.1"); - $this->_digestResolver = new HTTP\FileResolver("$this->_filesPath/htdigest.3"); + $this->_basicResolver = new Http\FileResolver("$this->_filesPath/htbasic.1"); + $this->_digestResolver = new Http\FileResolver("$this->_filesPath/htdigest.3"); $this->_basicConfig = array( 'accept_schemes' => 'basic', 'realm' => 'Test Realm' @@ -112,30 +112,30 @@ public function setUp() public function testValidConfigs() { try { - $t = new Adapter\HTTP($this->_basicConfig); + $t = new Adapter\Http($this->_basicConfig); } catch (Adapter\Exception $e) { $this->fail('Valid config deemed invalid'); } $this->assertFalse(empty($t)); - $this->assertType('Zend\\Authentication\\Adapter\\HTTP', $t); + $this->assertType('Zend\\Authentication\\Adapter\\Http', $t); unset($t); try { - $t = new Adapter\HTTP($this->_digestConfig); + $t = new Adapter\Http($this->_digestConfig); } catch (Adapter\Exception $e) { $this->fail('Valid config deemed invalid'); } $this->assertFalse(empty($t)); - $this->assertType('Zend\\Authentication\\Adapter\\HTTP', $t); + $this->assertType('Zend\\Authentication\\Adapter\\Http', $t); unset($t); try { - $t = new Adapter\HTTP($this->_bothConfig); + $t = new Adapter\Http($this->_bothConfig); } catch (Adapter\Exception $e) { $this->fail('Valid config deemed invalid'); } $this->assertFalse(empty($t)); - $this->assertType('Zend\\Authentication\\Adapter\\HTTP', $t); + $this->assertType('Zend\\Authentication\\Adapter\\Http', $t); unset($t); } @@ -169,7 +169,7 @@ public function testInvalidConfigs() foreach ($badConfigs as $cfg) { $t = null; try { - $t = new Adapter\HTTP($cfg); + $t = new Adapter\Http($cfg); $this->fail('Accepted an invalid config'); } catch (Adapter\Exception $e) { // Good, it threw an exception @@ -179,7 +179,7 @@ public function testInvalidConfigs() public function testAuthenticateArgs() { - $a = new Adapter\HTTP($this->_basicConfig); + $a = new Adapter\Http($this->_basicConfig); try { $a->authenticate(); @@ -188,8 +188,8 @@ public function testAuthenticateArgs() // Good, it threw an exception } - $request = $this->getMock('Zend\Controller\Request\HTTP'); - $response = $this->getMock('Zend\Controller\Response\HTTP'); + $request = $this->getMock('Zend\Controller\Request\Http'); + $response = $this->getMock('Zend\Controller\Response\Http'); // If this throws an exception, it fails $a->setRequest($request) @@ -199,8 +199,8 @@ public function testAuthenticateArgs() public function testNoResolvers() { - $request = $this->getMock('Zend\Controller\Request\HTTP'); - $response = $this->getMock('Zend\Controller\Response\HTTP'); + $request = $this->getMock('Zend\Controller\Request\Http'); + $response = $this->getMock('Zend\Controller\Response\Http'); // Stub request for Basic auth $request->expects($this->any()) @@ -209,7 +209,7 @@ public function testNoResolvers() // Once for Basic try { - $a = new Adapter\HTTP($this->_basicConfig); + $a = new Adapter\Http($this->_basicConfig); $a->setRequest($request) ->setResponse($response); $result = $a->authenticate(); @@ -220,14 +220,14 @@ public function testNoResolvers() } // Stub request for Digest auth, must be reseted (recreated) - $request = $this->getMock('Zend\Controller\Request\HTTP'); + $request = $this->getMock('Zend\Controller\Request\Http'); $request->expects($this->any()) ->method('getHeader') ->will($this->returnValue('Digest _digestConfig); + $a = new Adapter\Http($this->_digestConfig); $a->setRequest($request) ->setResponse($response); $result = $a->authenticate(); @@ -240,14 +240,14 @@ public function testNoResolvers() public function testWrongResolverUsed() { - $response = $this->getMock('Zend\Controller\Response\HTTP'); - $request = $this->getMock('Zend\Controller\Request\HTTP'); + $response = $this->getMock('Zend\Controller\Response\Http'); + $request = $this->getMock('Zend\Controller\Request\Http'); $request->expects($this->any()) ->method('getHeader') ->will($this->returnValue('Basic _digestConfig); + $a = new Adapter\Http($this->_digestConfig); $a->setDigestResolver($this->_digestResolver) ->setRequest($request) ->setResponse($response); @@ -257,13 +257,13 @@ public function testWrongResolverUsed() public function testUnsupportedScheme() { - $response = $this->getMock('Zend\Controller\Response\HTTP'); - $request = $this->getMock('Zend\Controller\Request\HTTP'); + $response = $this->getMock('Zend\Controller\Response\Http'); + $request = $this->getMock('Zend\Controller\Request\Http'); $request->expects($this->any()) ->method('getHeader') ->will($this->returnValue('NotSupportedScheme _digestConfig); + $a = new Adapter\Http($this->_digestConfig); $a->setDigestResolver($this->_digestResolver) ->setRequest($request) ->setResponse($response); diff --git a/test/Adapter/HTTP/ProxyTest.php b/test/Adapter/Http/ProxyTest.php similarity index 97% rename from test/Adapter/HTTP/ProxyTest.php rename to test/Adapter/Http/ProxyTest.php index 008bf2b..e1dcd31 100644 --- a/test/Adapter/HTTP/ProxyTest.php +++ b/test/Adapter/Http/ProxyTest.php @@ -23,10 +23,10 @@ /** * @namespace */ -namespace ZendTest\Auth\Adapter\HTTP; +namespace ZendTest\Auth\Adapter\Http; -use Zend\Authentication\Adapter\HTTP, - Zend\Controller\Response\HTTP as HTTPResponse; +use Zend\Authentication\Adapter\Http, + Zend\Controller\Response\Http as HTTPResponse; /** * @category Zend @@ -88,8 +88,8 @@ class ProxyTest extends \PHPUnit_Framework_TestCase public function setUp() { $this->_filesPath = __DIR__ . '/TestAsset'; - $this->_basicResolver = new HTTP\FileResolver("{$this->_filesPath}/htbasic.1"); - $this->_digestResolver = new HTTP\FileResolver("{$this->_filesPath}/htdigest.3"); + $this->_basicResolver = new Http\FileResolver("{$this->_filesPath}/htbasic.1"); + $this->_digestResolver = new Http\FileResolver("{$this->_filesPath}/htdigest.3"); $this->_basicConfig = array( 'accept_schemes' => 'basic', 'realm' => 'Test Realm', @@ -301,7 +301,7 @@ public function testBadDigestRequest() public function _doAuth($clientHeader, $scheme) { // Set up stub request and response objects - $request = $this->getMock('Zend\Controller\Request\HTTP'); + $request = $this->getMock('Zend\Controller\Request\Http'); $response = new HTTPResponse; $response->setHttpResponseCode(200); $response->headersSentThrowsException = false; @@ -334,7 +334,7 @@ public function _doAuth($clientHeader, $scheme) } // Create the HTTP Auth adapter - $a = new \Zend\Authentication\Adapter\HTTP($use); + $a = new \Zend\Authentication\Adapter\Http($use); $a->setBasicResolver($this->_basicResolver); $a->setDigestResolver($this->_digestResolver); @@ -359,8 +359,8 @@ public function _doAuth($clientHeader, $scheme) protected function _digestChallenge() { $timeout = ceil(time() / 300) * 300; - $nonce = md5($timeout . ':PHPUnit:Zend\\Authentication\\Adapter\\HTTP'); - $opaque = md5('Opaque Data:Zend\\Authentication\\Adapter\\HTTP'); + $nonce = md5($timeout . ':PHPUnit:Zend\\Authentication\\Adapter\\Http'); + $opaque = md5('Opaque Data:Zend\\Authentication\\Adapter\\Http'); $wwwauth = 'Digest ' . 'realm="' . $this->_digestConfig['realm'] . '", ' . 'domain="' . $this->_digestConfig['digest_domains'] . '", ' @@ -383,8 +383,8 @@ protected function _digestReply($user, $pass) { $nc = '00000001'; $timeout = ceil(time() / 300) * 300; - $nonce = md5($timeout . ':PHPUnit:Zend\\Authentication\\Adapter\\HTTP'); - $opaque = md5('Opaque Data:Zend\\Authentication\\Adapter\\HTTP'); + $nonce = md5($timeout . ':PHPUnit:Zend\\Authentication\\Adapter\\Http'); + $opaque = md5('Opaque Data:Zend\\Authentication\\Adapter\\Http'); $cnonce = md5('cnonce'); $response = md5(md5($user . ':' . $this->_digestConfig['realm'] . ':' . $pass) . ":$nonce:$nc:$cnonce:auth:" . md5('GET:/')); diff --git a/test/Adapter/HTTP/TestAsset/htbasic.1 b/test/Adapter/Http/TestAsset/htbasic.1 similarity index 100% rename from test/Adapter/HTTP/TestAsset/htbasic.1 rename to test/Adapter/Http/TestAsset/htbasic.1 diff --git a/test/Adapter/HTTP/TestAsset/htdigest.3 b/test/Adapter/Http/TestAsset/htdigest.3 similarity index 100% rename from test/Adapter/HTTP/TestAsset/htdigest.3 rename to test/Adapter/Http/TestAsset/htdigest.3 From 8e2795467fe0c5be04c65d94ca782bf5adca5213 Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Tue, 20 Jul 2010 11:08:54 -0400 Subject: [PATCH 12/61] LDAP -> Ldap - Renamed directories and filenames from LDAP to Ldap - Renamed namespaces and classnames from LDAP to Ldap - Renamed LDIF -> Ldif - Renamed RootDSE -> RootDse - Renamed DN -> Dn - Renamed OpenLDAP -> OpenLdap --- src/Adapter/Ldap.php | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/Adapter/Ldap.php b/src/Adapter/Ldap.php index cab31d4..655b4c6 100644 --- a/src/Adapter/Ldap.php +++ b/src/Adapter/Ldap.php @@ -204,7 +204,7 @@ public function setCredential($credential) public function getLdap() { if ($this->_ldap === null) { - $this->_ldap = new \Zend\LDAP\LDAP(); + $this->_ldap = new \Zend\Ldap\Ldap(); } return $this->_ldap; @@ -216,7 +216,7 @@ public function getLdap() * @param Zend_Ldap $ldap An existing Ldap object * @return Zend\Authentication\Adapter\Ldap Provides a fluent interface */ - public function setLdap(\Zend\LDAP\LDAP $ldap) + public function setLdap(\Zend\Ldap\Ldap $ldap) { $this->_ldap = $ldap; @@ -321,7 +321,7 @@ public function authenticate() $ldap->bind(); $requireRebind = true; } - $dn = $ldap->getCanonicalAccountName($canonicalName, \Zend\LDAP\LDAP::ACCTNAME_FORM_DN); + $dn = $ldap->getCanonicalAccountName($canonicalName, \Zend\Ldap\Ldap::ACCTNAME_FORM_DN); $groupResult = $this->_checkGroupMembership($ldap, $canonicalName, $dn, $adapterOptions); if ($groupResult === true) { @@ -339,7 +339,7 @@ public function authenticate() $messages[1] = $groupResult; $failedAuthorities[$dname] = $groupResult; } - } catch (\Zend\LDAP\Exception $zle) { + } catch (\Zend\Ldap\Exception $zle) { /* LDAP based authentication is notoriously difficult to diagnose. Therefore * we bend over backwards to capture and record every possible bit of @@ -348,18 +348,18 @@ public function authenticate() $err = $zle->getCode(); - if ($err == \Zend\LDAP\Exception::LDAP_X_DOMAIN_MISMATCH) { + if ($err == \Zend\Ldap\Exception::LDAP_X_DOMAIN_MISMATCH) { /* This error indicates that the domain supplied in the * username did not match the domains in the server options * and therefore we should just skip to the next set of * server options. */ continue; - } else if ($err == \Zend\LDAP\Exception::LDAP_NO_SUCH_OBJECT) { + } else if ($err == \Zend\Ldap\Exception::LDAP_NO_SUCH_OBJECT) { $code = AuthenticationResult::FAILURE_IDENTITY_NOT_FOUND; $messages[0] = "Account not found: $username"; $failedAuthorities[$dname] = $zle->getMessage(); - } else if ($err == \Zend\LDAP\Exception::LDAP_INVALID_CREDENTIALS) { + } else if ($err == \Zend\Ldap\Exception::LDAP_INVALID_CREDENTIALS) { $code = AuthenticationResult::FAILURE_CREDENTIAL_INVALID; $messages[0] = 'Invalid credentials'; $failedAuthorities[$dname] = $zle->getMessage(); @@ -386,12 +386,12 @@ public function authenticate() * @param array $options * @return array of auth-adapter specific options */ - protected function _prepareOptions(\Zend\LDAP\LDAP $ldap, array $options) + protected function _prepareOptions(\Zend\Ldap\Ldap $ldap, array $options) { $adapterOptions = array( 'group' => null, 'groupDn' => $ldap->getBaseDn(), - 'groupScope' => \Zend\LDAP\LDAP::SEARCH_SCOPE_SUB, + 'groupScope' => \Zend\Ldap\Ldap::SEARCH_SCOPE_SUB, 'groupAttr' => 'cn', 'groupFilter' => 'objectClass=groupOfUniqueNames', 'memberAttr' => 'uniqueMember', @@ -404,8 +404,8 @@ protected function _prepareOptions(\Zend\LDAP\LDAP $ldap, array $options) switch ($key) { case 'groupScope': $value = (int)$value; - if (in_array($value, array(\Zend\LDAP\LDAP::SEARCH_SCOPE_BASE, - \Zend\LDAP\LDAP::SEARCH_SCOPE_ONE, \Zend\LDAP\LDAP::SEARCH_SCOPE_SUB), true)) { + if (in_array($value, array(\Zend\Ldap\Ldap::SEARCH_SCOPE_BASE, + \Zend\Ldap\Ldap::SEARCH_SCOPE_ONE, \Zend\Ldap\Ldap::SEARCH_SCOPE_SUB), true)) { $adapterOptions[$key] = $value; } break; @@ -432,7 +432,7 @@ protected function _prepareOptions(\Zend\LDAP\LDAP $ldap, array $options) * @param array $adapterOptions * @return string|true */ - protected function _checkGroupMembership(\Zend\LDAP\LDAP $ldap, $canonicalName, $dn, array $adapterOptions) + protected function _checkGroupMembership(\Zend\Ldap\Ldap $ldap, $canonicalName, $dn, array $adapterOptions) { if ($adapterOptions['group'] === null) { return true; @@ -444,9 +444,9 @@ protected function _checkGroupMembership(\Zend\LDAP\LDAP $ldap, $canonicalName, $user = $dn; } - $groupName = \Zend\LDAP\Filter\Filter::equals($adapterOptions['groupAttr'], $adapterOptions['group']); - $membership = \Zend\LDAP\Filter\Filter::equals($adapterOptions['memberAttr'], $user); - $group = \Zend\LDAP\Filter\Filter::andFilter($groupName, $membership); + $groupName = \Zend\Ldap\Filter\Filter::equals($adapterOptions['groupAttr'], $adapterOptions['group']); + $membership = \Zend\Ldap\Filter\Filter::equals($adapterOptions['memberAttr'], $user); + $group = \Zend\Ldap\Filter\Filter::andFilter($groupName, $membership); $groupFilter = $adapterOptions['groupFilter']; if (!empty($groupFilter)) { $group = $group->addAnd($groupFilter); From 48f458a748ec3eea690a878f7a1ca9611c38a058 Mon Sep 17 00:00:00 2001 From: dragonbe Date: Sat, 17 Jul 2010 13:43:22 +0000 Subject: [PATCH 13/61] added extra validation, verification and unit tests for issue ZF-7289 git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@22613 44c647ce-9c0f-0410-b52a-842ac1e357ba --- src/Adapter/DbTable.php | 11 +++++++++++ test/Adapter/DbTableTest.php | 3 +++ 2 files changed, 14 insertions(+) diff --git a/src/Adapter/DbTable.php b/src/Adapter/DbTable.php index 867b8b1..df7eff0 100644 --- a/src/Adapter/DbTable.php +++ b/src/Adapter/DbTable.php @@ -369,6 +369,17 @@ public function authenticate() return $authResult; } + if (true === $this->getAmbiguityIdentity()) { + $validIdentities = array (); + $zendAuthCredentialMatchColumn = $this->_zendDb->foldCase('zend_auth_credential_match'); + foreach ($resultIdentities as $identity) { + if (1 === (int) $identity[$zendAuthCredentialMatchColumn]) { + $validIdentities[] = $identity; + } + } + $resultIdentities = $validIdentities; + } + $authResult = $this->_authenticateValidateResult(array_shift($resultIdentities)); return $authResult; } diff --git a/test/Adapter/DbTableTest.php b/test/Adapter/DbTableTest.php index 43d36b6..d42e96f 100644 --- a/test/Adapter/DbTableTest.php +++ b/test/Adapter/DbTableTest.php @@ -429,6 +429,9 @@ public function testEqualUsernamesDifferentPasswordShouldAuthenticateWhenFlagIsS $this->assertTrue($result->isValid()); $this->assertEquals('my_username', $result->getIdentity()); + $this->_adapter = null; + $this->_setupAuthAdapter(); + // test if user 2 can authenticate $this->_adapter->setIdentity('my_username') ->setCredential('my_otherpass') From b23eeead1536473ee370a9fba92d2f340285180f Mon Sep 17 00:00:00 2001 From: Ralph Schindler Date: Wed, 8 Sep 2010 18:19:35 -0500 Subject: [PATCH 14/61] Renamed Zend\Authentication exceptions to match SPL in full Altered ZendTest\Authentication to test for new exceptions and messages --- src/Adapter/DbTable.php | 10 +++---- src/Adapter/Digest.php | 4 +-- src/Adapter/Http.php | 22 +++++++------- src/Adapter/Http/Exception.php | 2 +- src/Adapter/Http/FileResolver.php | 12 ++++---- src/Adapter/Http/InvalidArgumentException.php | 9 ++++++ src/Adapter/Http/RuntimeException.php | 9 ++++++ ...encyException.php => RuntimeException.php} | 2 +- src/Adapter/UnsupportedRequestException.php | 10 ------- test/Adapter/DbTableTest.php | 30 ++++++------------- test/Adapter/Ldap/OfflineTest.php | 2 +- test/AuthenticationServiceTest.php | 2 +- 12 files changed, 54 insertions(+), 60 deletions(-) create mode 100644 src/Adapter/Http/InvalidArgumentException.php create mode 100644 src/Adapter/Http/RuntimeException.php rename src/Adapter/{MissingDependencyException.php => RuntimeException.php} (75%) delete mode 100644 src/Adapter/UnsupportedRequestException.php diff --git a/src/Adapter/DbTable.php b/src/Adapter/DbTable.php index c6186de..a933431 100644 --- a/src/Adapter/DbTable.php +++ b/src/Adapter/DbTable.php @@ -172,9 +172,9 @@ protected function _setDbAdapter(AbstractDBAdapter $zendDb = null) if(null === $this->_zendDb) { $this->_zendDb = AbstractTable::getDefaultAdapter(); if (null === $this->_zendDb) { - throw new MissingDependencyException( - 'A null adapter was provided but there is no default adatper ' - . 'registered with Zend\Db\Table to utilize.' + throw new RuntimeException( + 'Null was provided for the adapter but there is no default' + . ' adatper registered with Zend\Db\Table to utilize.' ); } } @@ -412,7 +412,7 @@ protected function _authenticateSetup() } if (null !== $exception) { - throw new Exception($exception); + throw new RuntimeException($exception); } $this->_authenticateResultInfo = array( @@ -479,7 +479,7 @@ protected function _authenticateQuerySelect(DBSelect $dbSelect) unset($origDbFetchMode); } } catch (\Exception $e) { - throw new Exception('The supplied parameters to Zend\\Authentication\\Adapter\\DbTable failed to ' + throw new RuntimeException('The supplied parameters to Zend\Authentication\Adapter\DbTable failed to ' . 'produce a valid sql statement, please check table and column names ' . 'for validity.', 0, $e); } diff --git a/src/Adapter/Digest.php b/src/Adapter/Digest.php index ac7205a..1ea754a 100644 --- a/src/Adapter/Digest.php +++ b/src/Adapter/Digest.php @@ -177,7 +177,7 @@ public function setPassword($password) /** * Defined by Zend_Auth_Adapter_Interface * - * @throws Zend\Authentication\Adapter\Exception + * @throws Zend\Authentication\Adapter\RuntimeException * @return Zend\Authentication\Result */ public function authenticate() @@ -185,7 +185,7 @@ public function authenticate() $optionsRequired = array('filename', 'realm', 'username', 'password'); foreach ($optionsRequired as $optionRequired) { if (null === $this->{"_$optionRequired"}) { - throw new MissingDependencyException("Option '$optionRequired' must be set before authentication"); + throw new RuntimeException("Option '$optionRequired' must be set before authentication"); } } diff --git a/src/Adapter/Http.php b/src/Adapter/Http.php index 2837ea5..720ffb0 100644 --- a/src/Adapter/Http.php +++ b/src/Adapter/Http.php @@ -167,14 +167,13 @@ class Http implements AuthenticationAdapter * 'use_opaque' => Whether to send the opaque value in the header * 'alogrithm' => See $_supportedAlgos. Default: MD5 * 'proxy_auth' => Whether to do authentication as a Proxy - * @throws Zend\Authentication\Adapter\MissingDependencyException * @throws Zend\Authentication\Adapter\InvalidArgumentException * @return void */ public function __construct(array $config) { if (!extension_loaded('hash')) { - throw new MissingDependencyException(__CLASS__ . ' requires the \'hash\' extension to be availabe in PHP'); + throw new InvalidArgumentException(__CLASS__ . ' requires the \'hash\' extension to be availabe in PHP'); } $this->_request = null; @@ -340,15 +339,14 @@ public function getResponse() /** * Authenticate * - * @throws Zend\Authentication\Adapter\MissingDependencyException - * @throws Zend\Authentication\Adapter\UnsupportedRequestException + * @throws Zend\Authentication\Adapter\RuntimeException * @return Zend\Authentication\Result */ public function authenticate() { if (empty($this->_request) || empty($this->_response)) { - throw new MissingDependencyException('Request and Response objects must be set before calling ' + throw new RuntimeException('Request and Response objects must be set before calling ' . 'authenticate()'); } @@ -391,7 +389,7 @@ public function authenticate() $result = $this->_digestAuth($authHeader); break; default: - throw new UnsupportedRequestException('Unsupported authentication scheme: ' . $clientScheme); + throw new RuntimeException('Unsupported authentication scheme: ' . $clientScheme); } return $result; @@ -474,10 +472,10 @@ protected function _digestHeader() protected function _basicAuth($header) { if (empty($header)) { - throw new UnexpectedValueException('The value of the client Authorization header is required'); + throw new RuntimeException('The value of the client Authorization header is required'); } if (empty($this->_basicResolver)) { - throw new MissingDependencyException( + throw new RuntimeException( 'A basicResolver object must be set before doing Basic ' . 'authentication'); } @@ -486,7 +484,7 @@ protected function _basicAuth($header) $auth = substr($header, strlen('Basic ')); $auth = base64_decode($auth); if (!$auth) { - throw new UnexpectedValueException('Unable to base64_decode Authorization header value'); + throw new RuntimeException('Unable to base64_decode Authorization header value'); } // See ZF-1253. Validate the credentials the same way the digest @@ -522,10 +520,10 @@ protected function _basicAuth($header) protected function _digestAuth($header) { if (empty($header)) { - throw new UnexpectedValueException('The value of the client Authorization header is required'); + throw new RuntimeException('The value of the client Authorization header is required'); } if (empty($this->_digestResolver)) { - throw new MissingDependencyException('A digestResolver object must be set before doing Digest authentication'); + throw new RuntimeException('A digestResolver object must be set before doing Digest authentication'); } $data = $this->_parseDigestAuth($header); @@ -580,7 +578,7 @@ protected function _digestAuth($header) // Should be REQUEST_METHOD . ':' . uri . ':' . hash(entity-body), // but this isn't supported yet, so fall through to default case default: - throw new UnsupportedRequestException('Client requested an unsupported qop option'); + throw new RuntimeException('Client requested an unsupported qop option'); } // Using hash() should make parameterizing the hash algorithm // easier diff --git a/src/Adapter/Http/Exception.php b/src/Adapter/Http/Exception.php index 74c74d8..b9f7308 100644 --- a/src/Adapter/Http/Exception.php +++ b/src/Adapter/Http/Exception.php @@ -35,5 +35,5 @@ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ -class Exception extends \Zend\Authentication\Exception +interface Exception extends \Zend\Authentication\Adapter\Exception {} diff --git a/src/Adapter/Http/FileResolver.php b/src/Adapter/Http/FileResolver.php index 3131fd4..3ed197a 100644 --- a/src/Adapter/Http/FileResolver.php +++ b/src/Adapter/Http/FileResolver.php @@ -68,7 +68,7 @@ public function __construct($path = '') public function setFile($path) { if (empty($path) || !is_readable($path)) { - throw new Exception('Path not readable: ' . $path); + throw new InvalidArgumentException('Path not readable: ' . $path); } $this->_file = $path; @@ -109,22 +109,22 @@ public function getFile() public function resolve($username, $realm) { if (empty($username)) { - throw new Exception('Username is required'); + throw new InvalidArgumentException('Username is required'); } else if (!ctype_print($username) || strpos($username, ':') !== false) { - throw new Exception('Username must consist only of printable characters, ' + throw new InvalidArgumentException('Username must consist only of printable characters, ' . 'excluding the colon'); } if (empty($realm)) { - throw new Exception('Realm is required'); + throw new InvalidArgumentException('Realm is required'); } else if (!ctype_print($realm) || strpos($realm, ':') !== false) { - throw new Exception('Realm must consist only of printable characters, ' + throw new InvalidArgumentException('Realm must consist only of printable characters, ' . 'excluding the colon.'); } // Open file, read through looking for matching credentials $fp = @fopen($this->_file, 'r'); if (!$fp) { - throw new Exception('Unable to open password file: ' . $this->_file); + throw new RuntimeException('Unable to open password file: ' . $this->_file); } // No real validation is done on the contents of the password file. The diff --git a/src/Adapter/Http/InvalidArgumentException.php b/src/Adapter/Http/InvalidArgumentException.php new file mode 100644 index 0000000..c49c382 --- /dev/null +++ b/src/Adapter/Http/InvalidArgumentException.php @@ -0,0 +1,9 @@ +_adapter->authenticate(); $this->assertEquals(Authentication\Result::FAILURE_IDENTITY_NOT_FOUND, $result->getCode()); - } catch (Authentication\Exception $e) { + } catch (Adapter\RuntimeException $e) { $this->fail('Exception should have been thrown'); } } @@ -150,7 +150,7 @@ public function testAuthenticateFailureIdentityAmbigious() try { $result = $this->_adapter->authenticate(); $this->assertEquals(Authentication\Result::FAILURE_IDENTITY_AMBIGUOUS, $result->getCode()); - } catch (Authentication\Exception $e) { + } catch (Adapter\RuntimeException $e) { $this->fail('Exception should have been thrown'); } } @@ -252,75 +252,63 @@ public function testAdapterReturnsASelectObjectWithoutAuthTimeModificationsAfter /** * Ensure that exceptions are caught - * - * @expectedException Zend\Authentication\Exception */ public function testCatchExceptionNoTable() { + $this->setExpectedException('Zend\Authentication\Adapter\RuntimeException', 'A table must be supplied for'); $adapter = new Adapter\DbTable($this->_db); $result = $adapter->authenticate(); - // $this->assertEquals($e->getMessage(), 'A table must be supplied for the Zend_Auth_Adapter_DbTable authentication adapter.'); } /** * Ensure that exceptions are caught - * - * @expectedException Zend\Authentication\Exception */ public function testCatchExceptionNoIdentityColumn() { + $this->setExpectedException('Zend\Authentication\Adapter\RuntimeException', 'An identity column must be supplied for the'); $adapter = new Adapter\DbTable($this->_db, 'users'); $result = $adapter->authenticate(); - // $this->assertEquals($e->getMessage(), 'An identity column must be supplied for the Zend_Auth_Adapter_DbTable authentication adapter.'); } /** * Ensure that exceptions are caught - * - * @expectedException Zend\Authentication\Exception */ public function testCatchExceptionNoCredentialColumn() { + $this->setExpectedException('Zend\Authentication\Adapter\RuntimeException', 'A credential column must be supplied'); $adapter = new Adapter\DbTable($this->_db, 'users', 'username'); $result = $adapter->authenticate(); - // $this->assertEquals($e->getMessage(), 'A credential column must be supplied for the Zend_Auth_Adapter_DbTable authentication adapter.'); } /** * Ensure that exceptions are caught - * - * @expectedException Zend\Authentication\Exception */ public function testCatchExceptionNoIdentity() { + $this->setExpectedException('Zend\Authentication\Adapter\RuntimeException', 'A value for the identity was not provided prior'); $result = $this->_adapter->authenticate(); - // $this->assertEquals($e->getMessage(), 'A value for the identity was not provided prior to authentication with Zend_Auth_Adapter_DbTable.'); } /** * Ensure that exceptions are caught - * - * @expectedException Zend\Authentication\Exception */ public function testCatchExceptionNoCredential() { + $this->setExpectedException('Zend\Authentication\Adapter\RuntimeException', 'A credential value was not provided prior'); $this->_adapter->setIdentity('my_username'); $result = $this->_adapter->authenticate(); - // $this->assertEquals($e->getMessage(), 'A credential value was not provided prior to authentication with Zend_Auth_Adapter_DbTable.'); } /** * Ensure that exceptions are caught - * - * @expectedException Zend\Authentication\Exception */ public function testCatchExceptionBadSql() { + $this->setExpectedException('Zend\Authentication\Adapter\RuntimeException', 'The supplied parameters to'); $this->_adapter->setTableName('bad_table_name'); $this->_adapter->setIdentity('value'); $this->_adapter->setCredential('value'); $result = $this->_adapter->authenticate(); - // $this->assertEquals($e->getMessage(), 'The supplied parameters to Zend_Auth_Adapter_DbTable failed to produce a valid sql statement, please check table and column names for validity.'); } /** @@ -347,7 +335,7 @@ public function testDbTableAdapterUsesCaseFolding() */ public function testAuthenticateWithDefaultDbAdapterNoAdapterException() { - $this->setExpectedException('Zend\Authentication\Adapter\Exception', "No database adapter present"); + $this->setExpectedException('Zend\Authentication\Adapter\RuntimeException', 'Null was provided'); // make sure that no default adapter exists \Zend\Db\Table\AbstractTable::setDefaultAdapter(null); diff --git a/test/Adapter/Ldap/OfflineTest.php b/test/Adapter/Ldap/OfflineTest.php index 6d1ba30..da254f2 100644 --- a/test/Adapter/Ldap/OfflineTest.php +++ b/test/Adapter/Ldap/OfflineTest.php @@ -60,7 +60,7 @@ public function testGetSetLdap() $this->markTestSkipped('LDAP is not enabled'); } $this->_adapter->setLdap(new \Zend\Ldap\Ldap()); - $this->assertType('Zend_Ldap', $this->_adapter->getLdap()); + $this->assertType('Zend\Ldap\Ldap', $this->_adapter->getLdap()); } public function testUsernameIsNullIfNotSet() diff --git a/test/AuthenticationServiceTest.php b/test/AuthenticationServiceTest.php index 108b6e3..5eae344 100644 --- a/test/AuthenticationServiceTest.php +++ b/test/AuthenticationServiceTest.php @@ -36,7 +36,7 @@ * @license http://framework.zend.com/license/new-bsd New BSD License * @group Zend_Auth */ -class AuthTest extends \PHPUnit_Framework_TestCase +class AuthenticationServiceTest extends \PHPUnit_Framework_TestCase { public function setUp() { From 0e0d9569aed8f68f83444d47e70144259171a586 Mon Sep 17 00:00:00 2001 From: Ralph Schindler Date: Thu, 9 Sep 2010 12:48:04 -0500 Subject: [PATCH 15/61] Removing superfluous Exception in Zend\Authentication\Storage --- src/Storage/Exception.php | 37 ------------------------------------- 1 file changed, 37 deletions(-) delete mode 100644 src/Storage/Exception.php diff --git a/src/Storage/Exception.php b/src/Storage/Exception.php deleted file mode 100644 index 99fc8a3..0000000 --- a/src/Storage/Exception.php +++ /dev/null @@ -1,37 +0,0 @@ - Date: Fri, 17 Sep 2010 14:26:45 -0500 Subject: [PATCH 16/61] Zend\Authentication & Zend\Acl: * Moved Exceptions into their own namespace as per new proposal requirements & consistency --- src/Adapter/DbTable.php | 6 ++-- src/Adapter/Digest.php | 6 ++-- .../Exception/InvalidArgumentException.php | 9 +++++ src/Adapter/Exception/RuntimeException.php | 10 ++++++ .../Exception/UnexpectedValueException.php | 9 +++++ src/Adapter/Http.php | 34 +++++++++---------- src/Adapter/InvalidArgumentException.php | 9 ----- src/Adapter/RuntimeException.php | 10 ------ src/Adapter/UnexpectedValueException.php | 9 ----- test/Adapter/DbTableTest.php | 18 +++++----- 10 files changed, 59 insertions(+), 61 deletions(-) create mode 100644 src/Adapter/Exception/InvalidArgumentException.php create mode 100644 src/Adapter/Exception/RuntimeException.php create mode 100644 src/Adapter/Exception/UnexpectedValueException.php delete mode 100644 src/Adapter/InvalidArgumentException.php delete mode 100644 src/Adapter/RuntimeException.php delete mode 100644 src/Adapter/UnexpectedValueException.php diff --git a/src/Adapter/DbTable.php b/src/Adapter/DbTable.php index a933431..3eb6ef1 100644 --- a/src/Adapter/DbTable.php +++ b/src/Adapter/DbTable.php @@ -172,7 +172,7 @@ protected function _setDbAdapter(AbstractDBAdapter $zendDb = null) if(null === $this->_zendDb) { $this->_zendDb = AbstractTable::getDefaultAdapter(); if (null === $this->_zendDb) { - throw new RuntimeException( + throw new Exception\RuntimeException( 'Null was provided for the adapter but there is no default' . ' adatper registered with Zend\Db\Table to utilize.' ); @@ -412,7 +412,7 @@ protected function _authenticateSetup() } if (null !== $exception) { - throw new RuntimeException($exception); + throw new Exception\RuntimeException($exception); } $this->_authenticateResultInfo = array( @@ -479,7 +479,7 @@ protected function _authenticateQuerySelect(DBSelect $dbSelect) unset($origDbFetchMode); } } catch (\Exception $e) { - throw new RuntimeException('The supplied parameters to Zend\Authentication\Adapter\DbTable failed to ' + throw new Exception\RuntimeException('The supplied parameters to Zend\Authentication\Adapter\DbTable failed to ' . 'produce a valid sql statement, please check table and column names ' . 'for validity.', 0, $e); } diff --git a/src/Adapter/Digest.php b/src/Adapter/Digest.php index 1ea754a..1a6314e 100644 --- a/src/Adapter/Digest.php +++ b/src/Adapter/Digest.php @@ -177,7 +177,7 @@ public function setPassword($password) /** * Defined by Zend_Auth_Adapter_Interface * - * @throws Zend\Authentication\Adapter\RuntimeException + * @throws Zend\Authentication\Adapter\Exception\RuntimeException * @return Zend\Authentication\Result */ public function authenticate() @@ -185,12 +185,12 @@ public function authenticate() $optionsRequired = array('filename', 'realm', 'username', 'password'); foreach ($optionsRequired as $optionRequired) { if (null === $this->{"_$optionRequired"}) { - throw new RuntimeException("Option '$optionRequired' must be set before authentication"); + throw new Exception\RuntimeException("Option '$optionRequired' must be set before authentication"); } } if (false === ($fileHandle = @fopen($this->_filename, 'r'))) { - throw new UnexpectedValueException("Cannot open '$this->_filename' for reading"); + throw new Exception\UnexpectedValueException("Cannot open '$this->_filename' for reading"); } $id = "$this->_username:$this->_realm"; diff --git a/src/Adapter/Exception/InvalidArgumentException.php b/src/Adapter/Exception/InvalidArgumentException.php new file mode 100644 index 0000000..78634bb --- /dev/null +++ b/src/Adapter/Exception/InvalidArgumentException.php @@ -0,0 +1,9 @@ +_request = null; @@ -182,13 +182,13 @@ public function __construct(array $config) if (empty($config['accept_schemes'])) { - throw new InvalidArgumentException('Config key \'accept_schemes\' is required'); + throw new Exception\InvalidArgumentException('Config key \'accept_schemes\' is required'); } $schemes = explode(' ', $config['accept_schemes']); $this->_acceptSchemes = array_intersect($schemes, $this->_supportedSchemes); if (empty($this->_acceptSchemes)) { - throw new InvalidArgumentException('No supported schemes given in \'accept_schemes\'. Valid values: ' + throw new Exception\InvalidArgumentException('No supported schemes given in \'accept_schemes\'. Valid values: ' . implode(', ', $this->_supportedSchemes)); } @@ -198,7 +198,7 @@ public function __construct(array $config) !ctype_print($config['realm']) || strpos($config['realm'], ':') !== false || strpos($config['realm'], '"') !== false) { - throw new InvalidArgumentException('Config key \'realm\' is required, and must contain only printable ' + throw new Exception\InvalidArgumentException('Config key \'realm\' is required, and must contain only printable ' . 'characters, excluding quotation marks and colons'); } else { $this->_realm = $config['realm']; @@ -208,7 +208,7 @@ public function __construct(array $config) if (empty($config['digest_domains']) || !ctype_print($config['digest_domains']) || strpos($config['digest_domains'], '"') !== false) { - throw new InvalidArgumentException('Config key \'digest_domains\' is required, and must contain ' + throw new Exception\InvalidArgumentException('Config key \'digest_domains\' is required, and must contain ' . 'only printable characters, excluding quotation marks'); } else { $this->_domains = $config['digest_domains']; @@ -216,7 +216,7 @@ public function __construct(array $config) if (empty($config['nonce_timeout']) || !is_numeric($config['nonce_timeout'])) { - throw new InvalidArgumentException('Config key \'nonce_timeout\' is required, and must be an ' + throw new Exception\InvalidArgumentException('Config key \'nonce_timeout\' is required, and must be an ' . 'integer'); } else { $this->_nonceTimeout = (int) $config['nonce_timeout']; @@ -339,14 +339,14 @@ public function getResponse() /** * Authenticate * - * @throws Zend\Authentication\Adapter\RuntimeException + * @throws Zend\Authentication\Adapter\Exception\RuntimeException * @return Zend\Authentication\Result */ public function authenticate() { if (empty($this->_request) || empty($this->_response)) { - throw new RuntimeException('Request and Response objects must be set before calling ' + throw new Exception\RuntimeException('Request and Response objects must be set before calling ' . 'authenticate()'); } @@ -389,7 +389,7 @@ public function authenticate() $result = $this->_digestAuth($authHeader); break; default: - throw new RuntimeException('Unsupported authentication scheme: ' . $clientScheme); + throw new Exception\RuntimeException('Unsupported authentication scheme: ' . $clientScheme); } return $result; @@ -472,10 +472,10 @@ protected function _digestHeader() protected function _basicAuth($header) { if (empty($header)) { - throw new RuntimeException('The value of the client Authorization header is required'); + throw new Exception\RuntimeException('The value of the client Authorization header is required'); } if (empty($this->_basicResolver)) { - throw new RuntimeException( + throw new Exception\RuntimeException( 'A basicResolver object must be set before doing Basic ' . 'authentication'); } @@ -484,7 +484,7 @@ protected function _basicAuth($header) $auth = substr($header, strlen('Basic ')); $auth = base64_decode($auth); if (!$auth) { - throw new RuntimeException('Unable to base64_decode Authorization header value'); + throw new Exception\RuntimeException('Unable to base64_decode Authorization header value'); } // See ZF-1253. Validate the credentials the same way the digest @@ -512,18 +512,16 @@ protected function _basicAuth($header) * Digest Authentication * * @param string $header Client's Authorization header - * @throws Zend\Authentication\Adapter\UnexpectedValueException - * @throws Zend\Authentication\Adapter\MissingDependencyException - * @throws Zend\Authentication\Adapter\UnsupportedRequestException + * @throws Zend\Authentication\Adapter\Exception\UnexpectedValueException * @return Zend\Authentication\Result Valid auth result only on successful auth */ protected function _digestAuth($header) { if (empty($header)) { - throw new RuntimeException('The value of the client Authorization header is required'); + throw new Exception\RuntimeException('The value of the client Authorization header is required'); } if (empty($this->_digestResolver)) { - throw new RuntimeException('A digestResolver object must be set before doing Digest authentication'); + throw new Exception\RuntimeException('A digestResolver object must be set before doing Digest authentication'); } $data = $this->_parseDigestAuth($header); @@ -578,7 +576,7 @@ protected function _digestAuth($header) // Should be REQUEST_METHOD . ':' . uri . ':' . hash(entity-body), // but this isn't supported yet, so fall through to default case default: - throw new RuntimeException('Client requested an unsupported qop option'); + throw new Exception\RuntimeException('Client requested an unsupported qop option'); } // Using hash() should make parameterizing the hash algorithm // easier diff --git a/src/Adapter/InvalidArgumentException.php b/src/Adapter/InvalidArgumentException.php deleted file mode 100644 index b05aefd..0000000 --- a/src/Adapter/InvalidArgumentException.php +++ /dev/null @@ -1,9 +0,0 @@ -_adapter->authenticate(); $this->assertEquals(Authentication\Result::FAILURE_IDENTITY_NOT_FOUND, $result->getCode()); - } catch (Adapter\RuntimeException $e) { + } catch (Adapter\Exception\RuntimeException $e) { $this->fail('Exception should have been thrown'); } } @@ -150,7 +150,7 @@ public function testAuthenticateFailureIdentityAmbigious() try { $result = $this->_adapter->authenticate(); $this->assertEquals(Authentication\Result::FAILURE_IDENTITY_AMBIGUOUS, $result->getCode()); - } catch (Adapter\RuntimeException $e) { + } catch (Adapter\Exception\RuntimeException $e) { $this->fail('Exception should have been thrown'); } } @@ -255,7 +255,7 @@ public function testAdapterReturnsASelectObjectWithoutAuthTimeModificationsAfter */ public function testCatchExceptionNoTable() { - $this->setExpectedException('Zend\Authentication\Adapter\RuntimeException', 'A table must be supplied for'); + $this->setExpectedException('Zend\Authentication\Adapter\Exception\RuntimeException', 'A table must be supplied for'); $adapter = new Adapter\DbTable($this->_db); $result = $adapter->authenticate(); } @@ -265,7 +265,7 @@ public function testCatchExceptionNoTable() */ public function testCatchExceptionNoIdentityColumn() { - $this->setExpectedException('Zend\Authentication\Adapter\RuntimeException', 'An identity column must be supplied for the'); + $this->setExpectedException('Zend\Authentication\Adapter\Exception\RuntimeException', 'An identity column must be supplied for the'); $adapter = new Adapter\DbTable($this->_db, 'users'); $result = $adapter->authenticate(); } @@ -275,7 +275,7 @@ public function testCatchExceptionNoIdentityColumn() */ public function testCatchExceptionNoCredentialColumn() { - $this->setExpectedException('Zend\Authentication\Adapter\RuntimeException', 'A credential column must be supplied'); + $this->setExpectedException('Zend\Authentication\Adapter\Exception\RuntimeException', 'A credential column must be supplied'); $adapter = new Adapter\DbTable($this->_db, 'users', 'username'); $result = $adapter->authenticate(); } @@ -285,7 +285,7 @@ public function testCatchExceptionNoCredentialColumn() */ public function testCatchExceptionNoIdentity() { - $this->setExpectedException('Zend\Authentication\Adapter\RuntimeException', 'A value for the identity was not provided prior'); + $this->setExpectedException('Zend\Authentication\Adapter\Exception\RuntimeException', 'A value for the identity was not provided prior'); $result = $this->_adapter->authenticate(); } @@ -294,7 +294,7 @@ public function testCatchExceptionNoIdentity() */ public function testCatchExceptionNoCredential() { - $this->setExpectedException('Zend\Authentication\Adapter\RuntimeException', 'A credential value was not provided prior'); + $this->setExpectedException('Zend\Authentication\Adapter\Exception\RuntimeException', 'A credential value was not provided prior'); $this->_adapter->setIdentity('my_username'); $result = $this->_adapter->authenticate(); } @@ -304,7 +304,7 @@ public function testCatchExceptionNoCredential() */ public function testCatchExceptionBadSql() { - $this->setExpectedException('Zend\Authentication\Adapter\RuntimeException', 'The supplied parameters to'); + $this->setExpectedException('Zend\Authentication\Adapter\Exception\RuntimeException', 'The supplied parameters to'); $this->_adapter->setTableName('bad_table_name'); $this->_adapter->setIdentity('value'); $this->_adapter->setCredential('value'); @@ -335,7 +335,7 @@ public function testDbTableAdapterUsesCaseFolding() */ public function testAuthenticateWithDefaultDbAdapterNoAdapterException() { - $this->setExpectedException('Zend\Authentication\Adapter\RuntimeException', 'Null was provided'); + $this->setExpectedException('Zend\Authentication\Adapter\Exception\RuntimeException', 'Null was provided'); // make sure that no default adapter exists \Zend\Db\Table\AbstractTable::setDefaultAdapter(null); From 5ee622b3456da1e796683e675a7eebd498b27f96 Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Mon, 3 Oct 2011 14:56:29 -0500 Subject: [PATCH 17/61] Updated tests to mock HTTP classes - instead of controller classes --- test/Adapter/Http/ObjectTest.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/test/Adapter/Http/ObjectTest.php b/test/Adapter/Http/ObjectTest.php index 30ff2bc..e22f286 100644 --- a/test/Adapter/Http/ObjectTest.php +++ b/test/Adapter/Http/ObjectTest.php @@ -187,8 +187,8 @@ public function testAuthenticateArgs() // Good, it threw an exception } - $request = $this->getMock('Zend\Controller\Request\Http'); - $response = $this->getMock('Zend\Controller\Response\Http'); + $request = $this->getMock('Zend\Http\Request'); + $response = $this->getMock('Zend\Http\Response'); // If this throws an exception, it fails $a->setRequest($request) @@ -198,8 +198,8 @@ public function testAuthenticateArgs() public function testNoResolvers() { - $request = $this->getMock('Zend\Controller\Request\Http'); - $response = $this->getMock('Zend\Controller\Response\Http'); + $request = $this->getMock('Zend\Http\Request'); + $response = $this->getMock('Zend\Http\Response'); // Stub request for Basic auth $request->expects($this->any()) @@ -219,7 +219,7 @@ public function testNoResolvers() } // Stub request for Digest auth, must be reseted (recreated) - $request = $this->getMock('Zend\Controller\Request\Http'); + $request = $this->getMock('Zend\Http\Request'); $request->expects($this->any()) ->method('getHeader') ->will($this->returnValue('Digest getMock('Zend\Controller\Response\Http'); - $request = $this->getMock('Zend\Controller\Request\Http'); + $response = $this->getMock('Zend\Http\Response'); + $request = $this->getMock('Zend\Http\Request'); $request->expects($this->any()) ->method('getHeader') ->will($this->returnValue('Basic getMock('Zend\Controller\Response\Http'); - $request = $this->getMock('Zend\Controller\Request\Http'); + $response = $this->getMock('Zend\Http\Response'); + $request = $this->getMock('Zend\Http\Request'); $request->expects($this->any()) ->method('getHeader') ->will($this->returnValue('NotSupportedScheme Date: Mon, 3 Oct 2011 15:14:20 -0500 Subject: [PATCH 18/61] Fixed HTTP-dependent tests - Removed mock objects, and replaced with Zend\Http equivalents --- test/Adapter/Http/ObjectTest.php | 49 +++++++++++++++++--------------- 1 file changed, 26 insertions(+), 23 deletions(-) diff --git a/test/Adapter/Http/ObjectTest.php b/test/Adapter/Http/ObjectTest.php index e22f286..719791a 100644 --- a/test/Adapter/Http/ObjectTest.php +++ b/test/Adapter/Http/ObjectTest.php @@ -26,7 +26,10 @@ use Zend\Authentication\Adapter\Http, Zend\Authentication\Adapter, - Zend\Authentication; + Zend\Authentication, + Zend\Http\Headers, + Zend\Http\Request, + Zend\Http\Response; /** * @category Zend @@ -187,8 +190,8 @@ public function testAuthenticateArgs() // Good, it threw an exception } - $request = $this->getMock('Zend\Http\Request'); - $response = $this->getMock('Zend\Http\Response'); + $request = new Request; + $response = new Response; // If this throws an exception, it fails $a->setRequest($request) @@ -198,13 +201,12 @@ public function testAuthenticateArgs() public function testNoResolvers() { - $request = $this->getMock('Zend\Http\Request'); - $response = $this->getMock('Zend\Http\Response'); - // Stub request for Basic auth - $request->expects($this->any()) - ->method('getHeader') - ->will($this->returnValue('Basic addHeaderLine('Authorization', 'Basic setHeaders($headers); + $response = new Response; // Once for Basic try { @@ -219,10 +221,10 @@ public function testNoResolvers() } // Stub request for Digest auth, must be reseted (recreated) - $request = $this->getMock('Zend\Http\Request'); - $request->expects($this->any()) - ->method('getHeader') - ->will($this->returnValue('Digest addHeaderLine('Authorization', 'Digest setHeaders($headers); // Once for Digest try { @@ -239,11 +241,12 @@ public function testNoResolvers() public function testWrongResolverUsed() { - $response = $this->getMock('Zend\Http\Response'); - $request = $this->getMock('Zend\Http\Request'); - $request->expects($this->any()) - ->method('getHeader') - ->will($this->returnValue('Basic addHeaderLine('Authorization', 'Basic setHeaders($headers); // Test a Digest auth process while the request is containing a Basic auth header $a = new Adapter\Http($this->_digestConfig); @@ -256,11 +259,11 @@ public function testWrongResolverUsed() public function testUnsupportedScheme() { - $response = $this->getMock('Zend\Http\Response'); - $request = $this->getMock('Zend\Http\Request'); - $request->expects($this->any()) - ->method('getHeader') - ->will($this->returnValue('NotSupportedScheme addHeaderLine('Authorization', 'NotSupportedScheme setHeaders($headers); $a = new Adapter\Http($this->_digestConfig); $a->setDigestResolver($this->_digestResolver) From f26922728328d89f66f99e6ba64397d851ae2f82 Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Mon, 3 Oct 2011 20:04:05 -0500 Subject: [PATCH 19/61] Zend\Authentication\Adapter\Http proxy tests - Made ProxyAuthenticate and WWWAuthenticate headers implement MultiHeaderDescription (to all for both basic and digest simultaneously) - Updated tests to use request, response, and headers directly instead of mocks --- test/Adapter/Http/ProxyTest.php | 112 +++++++++++++++++++------------- 1 file changed, 68 insertions(+), 44 deletions(-) diff --git a/test/Adapter/Http/ProxyTest.php b/test/Adapter/Http/ProxyTest.php index 4106e4a..89350a8 100644 --- a/test/Adapter/Http/ProxyTest.php +++ b/test/Adapter/Http/ProxyTest.php @@ -25,7 +25,10 @@ namespace ZendTest\Auth\Adapter\Http; use Zend\Authentication\Adapter\Http, - Zend\Controller\Response\Http as HTTPResponse; + Zend\Http\Headers, + Zend\Http\Request, + Zend\Http\Response, + Zend\Stdlib\Parameters; /** * @category Zend @@ -117,7 +120,10 @@ public function testBasicChallenge() // false result. // The expected Basic Proxy-Authenticate header value - $basic = 'Basic realm="' . $this->_bothConfig['realm'] . '"'; + $basic = array( + 'type' => 'Basic ', + 'realm' => 'realm="' . $this->_bothConfig['realm'] . '"', + ); $data = $this->_doAuth('', 'basic'); $this->_checkUnauthorized($data, $basic); @@ -155,12 +161,23 @@ public function testBothChallenges() // Verify the status code and the presence of both challenges $this->assertEquals(407, $status); - $this->assertEquals('Proxy-Authenticate', $headers[0]['name']); - $this->assertEquals('Proxy-Authenticate', $headers[1]['name']); + $this->assertTrue($headers->has('Proxy-Authenticate')); + $authHeader = $headers->get('Proxy-Authenticate'); + $this->assertEquals(2, count($authHeader), var_export($authHeader, 1)); // Check to see if the expected challenges match the actual - $this->assertEquals($basic, $headers[0]['value']); - $this->assertEquals($digest, $headers[1]['value']); + $basicFound = $digestFound = false; + foreach ($authHeader as $header) { + $value = $header->getFieldValue(); + if (preg_match('/^Basic/', $value)) { + $basicFound = true; + } + if (preg_match('/^Digest/', $value)) { + $digestFound = true; + } + } + $this->assertTrue($basicFound); + $this->assertTrue($digestFound); } public function testBasicAuthValidCreds() @@ -177,7 +194,10 @@ public function testBasicAuthBadCreds() // a bad username or password. // The expected Basic WWW-Authenticate header value - $basic = 'Basic realm="' . $this->_basicConfig['realm'] . '"'; + $basic = array( + 'type' => 'Basic ', + 'realm' => 'realm="' . $this->_basicConfig['realm'] . '"', + ); $data = $this->_doAuth('Basic ' . base64_encode("Bad\tChars:In:Creds"), 'basic'); $this->_checkUnauthorized($data, $basic); @@ -188,7 +208,10 @@ public function testBasicAuthBadUser() // Attempt Basic Authentication with a bad username and password // The expected Basic Proxy-Authenticate header value - $basic = 'Basic realm="' . $this->_basicConfig['realm'] . '"'; + $basic = array( + 'type' => 'Basic ', + 'realm' => 'realm="' . $this->_basicConfig['realm'] . '"', + ); $data = $this->_doAuth('Basic ' . base64_encode('Nobody:NotValid'), 'basic'); $this->_checkUnauthorized($data, $basic); @@ -200,7 +223,10 @@ public function testBasicAuthBadPassword() // password // The expected Basic WWW-Authenticate header value - $basic = 'Basic realm="' . $this->_basicConfig['realm'] . '"'; + $basic = array( + 'type' => 'Basic ', + 'realm' => 'realm="' . $this->_basicConfig['realm'] . '"', + ); $data = $this->_doAuth('Basic ' . base64_encode('Bryce:Invalid'), 'basic'); $this->_checkUnauthorized($data, $basic); @@ -300,24 +326,17 @@ public function testBadDigestRequest() public function _doAuth($clientHeader, $scheme) { // Set up stub request and response objects - $request = $this->getMock('Zend\Controller\Request\Http'); - $response = new HTTPResponse; - $response->setHttpResponseCode(200); - $response->headersSentThrowsException = false; - - // Set stub method return values - $request->expects($this->any()) - ->method('getRequestUri') - ->will($this->returnValue('/')); - $request->expects($this->any()) - ->method('getMethod') - ->will($this->returnValue('GET')); - $request->expects($this->any()) - ->method('getServer') - ->will($this->returnValue('PHPUnit')); - $request->expects($this->any()) - ->method('getHeader') - ->will($this->returnValue($clientHeader)); + $response = new Response; + $response->setStatusCode(200); + + $headers = new Headers(); + $headers->addHeaderLine('Proxy-Authorization', $clientHeader); + + $request = new Request(); + $request->setUri('http://localhost/'); + $request->setMethod('GET'); + $request->setServer(new Parameters(array('HTTP_USER_AGENT' => 'PHPUnit'))); + $request->setHeaders($headers); // Select an Authentication scheme switch ($scheme) { @@ -344,8 +363,8 @@ public function _doAuth($clientHeader, $scheme) $return = array( 'result' => $result, - 'status' => $response->getHttpResponseCode(), - 'headers' => $response->getHeaders() + 'status' => $response->getStatusCode(), + 'headers' => $response->headers(), ); return $return; } @@ -357,18 +376,11 @@ public function _doAuth($clientHeader, $scheme) */ protected function _digestChallenge() { - $timeout = ceil(time() / 300) * 300; - $nonce = md5($timeout . ':PHPUnit:Zend\\Authentication\\Adapter\\Http'); - $opaque = md5('Opaque Data:Zend\\Authentication\\Adapter\\Http'); - $wwwauth = 'Digest ' - . 'realm="' . $this->_digestConfig['realm'] . '", ' - . 'domain="' . $this->_digestConfig['digest_domains'] . '", ' - . 'nonce="' . $nonce . '", ' - . 'opaque="' . $opaque . '", ' - . 'algorithm="MD5", ' - . 'qop="auth"'; - - return $wwwauth; + return array( + 'type' => 'Digest ', + 'realm' => 'realm="' . $this->_digestConfig['realm'] . '"', + 'domain' => 'domain="' . $this->_bothConfig['digest_domains'] . '"', + ); } /** @@ -419,10 +431,22 @@ protected function _checkUnauthorized($data, $expected) // Verify the status code and the presence of the challenge $this->assertEquals(407, $status); - $this->assertEquals('Proxy-Authenticate', $headers[0]['name']); + $this->assertTrue($headers->has('Proxy-Authenticate')); // Check to see if the expected challenge matches the actual - $this->assertEquals($expected, $headers[0]['value']); + $headers = $headers->get('Proxy-Authenticate'); + $this->assertTrue($headers instanceof \ArrayIterator); + $this->assertEquals(1, count($headers)); + $header = $headers[0]->getFieldValue(); + $this->assertContains($expected['type'], $header, $header); + $this->assertContains($expected['realm'], $header, $header); + if (isset($expected['domain'])) { + $this->assertContains($expected['domain'], $header, $header); + $this->assertContains('algorithm="MD5"', $header, $header); + $this->assertContains('qop="auth"', $header, $header); + $this->assertRegExp('/nonce="[a-fA-F0-9]{32}"/', $header, $header); + $this->assertRegExp('/opaque="[a-fA-F0-9]{32}"/', $header, $header); + } } /** @@ -437,7 +461,7 @@ protected function _checkOK($data) // Make sure the result is true $this->assertInstanceOf('Zend\\Authentication\\Result', $result); - $this->assertTrue($result->isValid()); + $this->assertTrue($result->isValid(), var_export($result->getMessages(), 1)); // Verify we got a 200 response $this->assertEquals(200, $status); From 3cf8581addef720994731d26f2251418fbb46a8e Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Mon, 3 Oct 2011 20:16:55 -0500 Subject: [PATCH 20/61] Zend\Authentication\Adapter\Http tests - Refactored to use HTTP request, response, and headers directly - All tests pass --- test/Adapter/Http/AuthTest.php | 94 ++++++++++++++++++---------------- 1 file changed, 49 insertions(+), 45 deletions(-) diff --git a/test/Adapter/Http/AuthTest.php b/test/Adapter/Http/AuthTest.php index 5c236e5..365c25b 100644 --- a/test/Adapter/Http/AuthTest.php +++ b/test/Adapter/Http/AuthTest.php @@ -25,8 +25,9 @@ namespace ZendTest\Auth\Adapter\Http; use Zend\Authentication\Adapter\Http, - Zend\Http\Request as HTTPRequest, - Zend\Http\Response as HTTPResponse, + Zend\Http\Headers, + Zend\Http\Request, + Zend\Http\Response, Zend\Stdlib\Parameters; /** @@ -116,7 +117,10 @@ public function testBasicChallenge() // false result. // The expected Basic Www-Authenticate header value - $basic = 'Basic realm="' . $this->_bothConfig['realm'] . '"'; + $basic = array( + 'type' => 'Basic ', + 'realm' => 'realm="' . $this->_bothConfig['realm'] . '"', + ); $data = $this->_doAuth('', 'basic'); $this->_checkUnauthorized($data, $basic); @@ -156,26 +160,21 @@ public function testBothChallenges() $this->assertEquals(401, $status); $this->assertTrue($headers->has('Www-Authenticate')); $wwwAuthenticate = $headers->get('Www-Authenticate'); - $this->assertInstanceOf('Iterator', $wwwAuthenticate, $headers->toString()); $this->assertEquals(2, count($wwwAuthenticate)); - $this->assertEquals('Www-Authenticate', $headers[0]['name']); - $this->assertEquals('Www-Authenticate', $headers[1]['name']); // Check to see if the expected challenges match the actual - $i = 0; + $basicFound = $digestFound = false; foreach ($wwwAuthenticate as $header) { - switch ($i) { - case 0: - $this->assertEquals($basic, $header->getFieldValue()); - break; - case 1: - $this->assertEquals($digest, $header->getFieldValue()); - break; - default: - break; + $value = $header->getFieldValue(); + if (preg_match('/^Basic/', $value)) { + $basicFound = true; + } + if (preg_match('/^Digest/', $value)) { + $digestFound = true; } - $i++; } + $this->assertTrue($basicFound); + $this->assertTrue($digestFound); } public function testBasicAuthValidCreds() @@ -192,7 +191,10 @@ public function testBasicAuthBadCreds() // a bad username or password. // The expected Basic Www-Authenticate header value - $basic = 'Basic realm="' . $this->_basicConfig['realm'] . '"'; + $basic = array( + 'type' => 'Basic ', + 'realm' => 'realm="' . $this->_basicConfig['realm'] . '"', + ); $data = $this->_doAuth('Basic ' . base64_encode("Bad\tChars:In:Creds"), 'basic'); $this->_checkUnauthorized($data, $basic); @@ -204,7 +206,10 @@ public function testBasicAuthBadUser() // password // The expected Basic Www-Authenticate header value - $basic = 'Basic realm="' . $this->_basicConfig['realm'] . '"'; + $basic = array( + 'type' => 'Basic ', + 'realm' => 'realm="' . $this->_basicConfig['realm'] . '"', + ); $data = $this->_doAuth('Basic ' . base64_encode('Nobody:NotValid'), 'basic'); $this->_checkUnauthorized($data, $basic); @@ -216,7 +221,10 @@ public function testBasicAuthBadPassword() // password // The expected Basic Www-Authenticate header value - $basic = 'Basic realm="' . $this->_basicConfig['realm'] . '"'; + $basic = array( + 'type' => 'Basic ', + 'realm' => 'realm="' . $this->_basicConfig['realm'] . '"', + ); $data = $this->_doAuth('Basic ' . base64_encode('Bryce:Invalid'), 'basic'); $this->_checkUnauthorized($data, $basic); @@ -328,16 +336,15 @@ public function testBadDigestRequest() protected function _doAuth($clientHeader, $scheme) { // Set up stub request and response objects - $request = new HTTPRequest; - $response = new HTTPResponse; + $request = new Request; + $response = new Response; $response->setStatusCode(200); // Set stub method return values - $request->setUri('/'); + $request->setUri('http://localhost/'); $request->setMethod('GET'); - $request->setServer(new Parameters); + $request->setServer(new Parameters(array('HTTP_USER_AGENT' => 'PHPUnit'))); $headers = $request->headers(); - $headers->addHeaderLine('Proxy-Authorization', $clientHeader); $headers->addHeaderLine('Authorization', $clientHeader); // Select an Authentication scheme @@ -378,18 +385,11 @@ protected function _doAuth($clientHeader, $scheme) */ protected function _digestChallenge() { - $timeout = ceil(time() / 300) * 300; - $nonce = md5($timeout . ':PHPUnit:Zend\\Authentication\\Adapter\\Http'); - $opaque = md5('Opaque Data:Zend\\Authentication\\Adapter\\Http'); - $wwwauth = 'Digest ' - . 'realm="' . $this->_digestConfig['realm'] . '", ' - . 'domain="' . $this->_digestConfig['digest_domains'] . '", ' - . 'nonce="' . $nonce . '", ' - . 'opaque="' . $opaque . '", ' - . 'algorithm="MD5", ' - . 'qop="auth"'; - - return $wwwauth; + return array( + 'type' => 'Digest ', + 'realm' => 'realm="' . $this->_digestConfig['realm'] . '"', + 'domain' => 'domain="' . $this->_bothConfig['digest_domains'] . '"', + ); } /** @@ -441,15 +441,19 @@ protected function _checkUnauthorized($data, $expected) $this->assertTrue($headers->has('Www-Authenticate')); // Check to see if the expected challenge matches the actual - $header = $headers->get('Www-Authenticate'); - if ($header instanceof \Iterator) { -echo "We have multiple www-authenticate headers!\n"; - foreach ($header as $h) { - $header = $h; - break; - } + $headers = $headers->get('Www-Authenticate'); + $this->assertTrue($headers instanceof \ArrayIterator); + $this->assertEquals(1, count($headers)); + $header = $headers[0]->getFieldValue(); + $this->assertContains($expected['type'], $header, $header); + $this->assertContains($expected['realm'], $header, $header); + if (isset($expected['domain'])) { + $this->assertContains($expected['domain'], $header, $header); + $this->assertContains('algorithm="MD5"', $header, $header); + $this->assertContains('qop="auth"', $header, $header); + $this->assertRegExp('/nonce="[a-fA-F0-9]{32}"/', $header, $header); + $this->assertRegExp('/opaque="[a-fA-F0-9]{32}"/', $header, $header); } - $this->assertEquals($expected, $header->getFieldValue(), $headers->toString()); } /** From 3ec7791a0e5ad6b402fabf8a6674f40ae92c0b88 Mon Sep 17 00:00:00 2001 From: Stefan Gehrig Date: Mon, 24 Oct 2011 17:13:14 +0200 Subject: [PATCH 21/61] [ZF-11839] fixed security problem (possible password disclosure) --- src/Adapter/Ldap.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Adapter/Ldap.php b/src/Adapter/Ldap.php index d7f13dd..c93e3d1 100644 --- a/src/Adapter/Ldap.php +++ b/src/Adapter/Ldap.php @@ -365,7 +365,7 @@ public function authenticate() } else { $line = $zle->getLine(); $messages[] = $zle->getFile() . "($line): " . $zle->getMessage(); - $messages[] = str_replace($password, '*****', $zle->getTraceAsString()); + $messages[] = preg_replace('/\b'.preg_quote($password, '/').'\b/', '*****', $zle->getTraceAsString()); $messages[0] = 'An unexpected failure occurred'; } $messages[1] = $zle->getMessage(); From 1186cfcfcd96c3b69696384c38015086bc3fdd52 Mon Sep 17 00:00:00 2001 From: Mike Willbanks Date: Tue, 3 Apr 2012 14:33:05 -0500 Subject: [PATCH 22/61] added unit test for setAdapter / getAdapter --- test/AuthenticationServiceTest.php | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/test/AuthenticationServiceTest.php b/test/AuthenticationServiceTest.php index 2462c0b..f7cd3b1 100644 --- a/test/AuthenticationServiceTest.php +++ b/test/AuthenticationServiceTest.php @@ -50,6 +50,15 @@ public function testGetStorage() $this->assertTrue($storage instanceof Auth\Storage\Session); } + public function testAdapter() + { + $this->assertNull($this->auth->getAdapter()); + $successAdapter = new TestAsset\SuccessAdapter(); + $ret = $this->auth->setAdapter($successAdapter); + $this->assertSame($ret, $this->auth); + $this->assertSame($successAdapter, $this->auth->getAdapter()); + } + /** * Ensures expected behavior for successful authentication * @@ -63,6 +72,14 @@ public function testAuthenticate() $this->assertEquals('someIdentity', $this->auth->getIdentity()); } + public function testAuthenticateSetAdapter() + { + $result = $this->_authenticate(new TestAsset\SuccessAdapter()); + $this->assertTrue($result instanceof Auth\Result); + $this->assertTrue($this->auth->hasIdentity()); + $this->assertEquals('someIdentity', $this->auth->getIdentity()); + } + /** * Ensures expected behavior for clearIdentity() * @@ -76,8 +93,11 @@ public function testClearIdentity() $this->assertEquals(null, $this->auth->getIdentity()); } - protected function _authenticate() + protected function _authenticate($adapter = null) { - return $this->auth->authenticate(new TestAsset\SuccessAdapter()); + if ($adapter === null) { + $adapter = new TestAsset\SuccessAdapter(); + } + return $this->auth->authenticate($adapter); } } From 876c153fdd83320cd7fbc930862d346f984fbe45 Mon Sep 17 00:00:00 2001 From: Mike Willbanks Date: Tue, 3 Apr 2012 14:43:43 -0500 Subject: [PATCH 23/61] update the constructor signature --- src/AuthenticationService.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/AuthenticationService.php b/src/AuthenticationService.php index 2c0565f..0742f3c 100644 --- a/src/AuthenticationService.php +++ b/src/AuthenticationService.php @@ -48,11 +48,14 @@ class AuthenticationService * @param Storage $storage * @return void */ - public function __construct(Storage $storage = null) + public function __construct(Storage $storage = null, Adapter $adapter = null) { if (null !== $storage) { $this->setStorage($storage); } + if (null !== $adapter) { + $this->setAdapter($adapter); + } } /** From 87fe7fa4acba8b62e8ebeedf906259747dcceff5 Mon Sep 17 00:00:00 2001 From: Roger Hunwicks Date: Wed, 4 Apr 2012 16:45:06 +0300 Subject: [PATCH 24/61] Fix ZF2/199: Update Zend Authentication to work with new DB components Updated Zend\Authentication\Adapter\DbTable and associated tests. testAdapterCanUseModifiedDbSelectObject still fails because there is no Database Profiler yet, but the actual adapter works --- src/Adapter/DbTable.php | 168 +++++++++++++---------------------- test/Adapter/DbTableTest.php | 43 +++++---- 2 files changed, 88 insertions(+), 123 deletions(-) diff --git a/src/Adapter/DbTable.php b/src/Adapter/DbTable.php index f2858b9..a1ca0e0 100644 --- a/src/Adapter/DbTable.php +++ b/src/Adapter/DbTable.php @@ -22,17 +22,12 @@ namespace Zend\Authentication\Adapter; use Zend\Authentication\Adapter as AuthenticationAdapter, Zend\Authentication\Result as AuthenticationResult, - Zend\Db\Db, - Zend\Db\Adapter\AbstractAdapter as AbstractDBAdapter, - Zend\Db\Expr as DBExpr, - Zend\Db\Select as DBSelect, - Zend\Db\Table\AbstractTable; + Zend\Db\Adapter\Adapter as DbAdapter, + Zend\Db\Sql\Select as DbSelect, + Zend\Db\Sql\Expression, + Zend\Db\ResultSet\ResultSet; /** - * @uses Zend\Authentication\Adapter\Exception - * @uses Zend\Authentication\Adapter - * @uses Zend\Authentication\Result - * @uses Zend_Db_Adapter_Abstract * @category Zend * @package Zend_Authentication * @subpackage Adapter @@ -45,12 +40,12 @@ class DbTable implements AuthenticationAdapter /** * Database Connection * - * @var Zend\Db\Adapter\AbstractAdapter + * @var DbAdapter */ protected $_zendDb = null; /** - * @var Zend\Db\Select + * @var DbSelect */ protected $_dbSelect = null; @@ -109,12 +104,12 @@ class DbTable implements AuthenticationAdapter * @var array */ protected $_resultRow = null; - + /** - * $_ambiguityIdentity - Flag to indicate same Identity can be used with + * $_ambiguityIdentity - Flag to indicate same Identity can be used with * different credentials. Default is FALSE and need to be set to true to * allow ambiguity usage. - * + * * @var boolean */ protected $_ambiguityIdentity = false; @@ -122,17 +117,17 @@ class DbTable implements AuthenticationAdapter /** * __construct() - Sets configuration options * - * @param Zend\Db\Adapter\AbstractAdapter $zendDb + * @param DbAdapter $zendDb * @param string $tableName * @param string $identityColumn * @param string $credentialColumn * @param string $credentialTreatment * @return void */ - public function __construct(AbstractDBAdapter $zendDb = null, $tableName = null, $identityColumn = null, + public function __construct(DbAdapter $zendDb, $tableName = null, $identityColumn = null, $credentialColumn = null, $credentialTreatment = null) { - $this->_setDbAdapter($zendDb); + $this->_zendDb = $zendDb; if (null !== $tableName) { $this->setTableName($tableName); @@ -151,38 +146,11 @@ public function __construct(AbstractDBAdapter $zendDb = null, $tableName = null, } } - /** - * _setDbAdapter() - set the database adapter to be used for quering - * - * @param Zend_Db_Adapter_Abstract - * @throws Zend_Auth_Adapter_Exception - * @return Zend_Auth_Adapter_DbTable - */ - protected function _setDbAdapter(AbstractDBAdapter $zendDb = null) - { - $this->_zendDb = $zendDb; - - /** - * If no adapter is specified, fetch default database adapter. - */ - if(null === $this->_zendDb) { - $this->_zendDb = AbstractTable::getDefaultAdapter(); - if (null === $this->_zendDb) { - throw new Exception\RuntimeException( - 'Null was provided for the adapter but there is no default' - . ' adatper registered with Zend\Db\Table to utilize.' - ); - } - } - - return $this; - } - /** * setTableName() - set the table name to be used in the select query * * @param string $tableName - * @return Zend\Authentication\Adapter\DbTable Provides a fluent interface + * @return DbTable Provides a fluent interface */ public function setTableName($tableName) { @@ -194,7 +162,7 @@ public function setTableName($tableName) * setIdentityColumn() - set the column name to be used as the identity column * * @param string $identityColumn - * @return Zend\Authentication\Adapter\DbTable Provides a fluent interface + * @return DbTable Provides a fluent interface */ public function setIdentityColumn($identityColumn) { @@ -206,7 +174,7 @@ public function setIdentityColumn($identityColumn) * setCredentialColumn() - set the column name to be used as the credential column * * @param string $credentialColumn - * @return Zend\Authentication\Adapter\DbTable Provides a fluent interface + * @return DbTable Provides a fluent interface */ public function setCredentialColumn($credentialColumn) { @@ -229,7 +197,7 @@ public function setCredentialColumn($credentialColumn) * 'MD5(?)' * * @param string $treatment - * @return Zend\Authentication\Adapter\DbTable Provides a fluent interface + * @return DbTable Provides a fluent interface */ public function setCredentialTreatment($treatment) { @@ -241,7 +209,7 @@ public function setCredentialTreatment($treatment) * setIdentity() - set the value to be used as the identity * * @param string $value - * @return Zend\Authentication\Adapter\DbTable Provides a fluent interface + * @return DbTable Provides a fluent interface */ public function setIdentity($value) { @@ -254,21 +222,21 @@ public function setIdentity($value) * to be used, should be supplied in parameterized form, such as 'MD5(?)' or 'PASSWORD(?)' * * @param string $credential - * @return Zend\Authentication\Adapter\DbTable Provides a fluent interface + * @return DbTable Provides a fluent interface */ public function setCredential($credential) { $this->_credential = $credential; return $this; } - + /** * setAmbiguityIdentity() - sets a flag for usage of identical identities * with unique credentials. It accepts integers (0, 1) or boolean (true, * false) parameters. Default is false. - * + * * @param int|bool $flag - * @return Zend_Auth_Adapter_DbTable + * @return DbTable Provides a fluent interface */ public function setAmbiguityIdentity($flag) { @@ -279,10 +247,11 @@ public function setAmbiguityIdentity($flag) } return $this; } + /** - * getAmbiguityIdentity() - returns TRUE for usage of multiple identical + * getAmbiguityIdentity() - returns TRUE for usage of multiple identical * identies with different credentials, FALSE if not used. - * + * * @return bool */ public function getAmbiguityIdentity() @@ -293,14 +262,13 @@ public function getAmbiguityIdentity() /** * getDbSelect() - Return the preauthentication Db Select object for userland select query modification * - * @return Zend\Db\Select + * @return DbSelect */ public function getDbSelect() { if ($this->_dbSelect == null) { - $this->_dbSelect = $this->_zendDb->select(); + $this->_dbSelect = new DbSelect(); } - return $this->_dbSelect; } @@ -355,8 +323,8 @@ public function getResultRowObject($returnColumns = null, $omitColumns = null) * been configured with all necessary information to successfully connect to a database * table and attempt to find a record matching the provided identity. * - * @throws Zend\Authentication\Adapter\Exception if answering the authentication query is impossible - * @return Zend\Authentication\Result + * @throws Exception if answering the authentication query is impossible + * @return AuthenticationResult */ public function authenticate() { @@ -368,7 +336,7 @@ public function authenticate() return $authResult; } - // At this point, ambiguity is allready done. Loop, check and break on success. + // At this point, ambiguity is already done. Loop, check and break on success. foreach ($resultIdentities as $identity) { $authResult = $this->_authenticateValidateResult($identity); if ($authResult->isValid()) { @@ -384,7 +352,7 @@ public function authenticate() * making sure that this adapter was indeed setup properly with all * required pieces of information. * - * @throws Zend\Authentication\Adapter\Exception - in the event that setup was not done properly + * @throws Exception - in the event that setup was not done properly * @return true */ protected function _authenticateSetup() @@ -392,15 +360,15 @@ protected function _authenticateSetup() $exception = null; if ($this->_tableName == '') { - $exception = 'A table must be supplied for the Zend_Auth_Adapter_DbTable authentication adapter.'; + $exception = 'A table must be supplied for the DbTable authentication adapter.'; } elseif ($this->_identityColumn == '') { - $exception = 'An identity column must be supplied for the Zend_Auth_Adapter_DbTable authentication adapter.'; + $exception = 'An identity column must be supplied for the DbTable authentication adapter.'; } elseif ($this->_credentialColumn == '') { - $exception = 'A credential column must be supplied for the Zend_Auth_Adapter_DbTable authentication adapter.'; + $exception = 'A credential column must be supplied for the DbTable authentication adapter.'; } elseif ($this->_identity == '') { - $exception = 'A value for the identity was not provided prior to authentication with Zend_Auth_Adapter_DbTable.'; + $exception = 'A value for the identity was not provided prior to authentication with DbTable.'; } elseif ($this->_credential === null) { - $exception = 'A credential value was not provided prior to authentication with Zend_Auth_Adapter_DbTable.'; + $exception = 'A credential value was not provided prior to authentication with DbTable.'; } if (null !== $exception) { @@ -417,10 +385,10 @@ protected function _authenticateSetup() } /** - * _authenticateCreateSelect() - This method creates a Zend_Db_Select object that + * _authenticateCreateSelect() - This method creates a Zend\Db\Sql\Select object that * is completely configured to be queried against the database. * - * @return Zend_Db_Select + * @return DbSelect */ protected function _authenticateCreateSelect() { @@ -429,51 +397,45 @@ protected function _authenticateCreateSelect() $this->_credentialTreatment = '?'; } - $credentialExpression = new DBExpr( - '(CASE WHEN ' . - $this->_zendDb->quoteInto( - $this->_zendDb->quoteIdentifier($this->_credentialColumn, true) - . ' = ' . $this->_credentialTreatment, $this->_credential - ) + $credentialExpression = new Expression( + '(CASE WHEN ' + . $this->_zendDb->getPlatform()->quoteIdentifier($this->_credentialColumn) + . ' = ' . $this->_credentialTreatment . ' THEN 1 ELSE 0 END) AS ' - . $this->_zendDb->quoteIdentifier( - $this->_zendDb->foldCase('zend_auth_credential_match') - ) - ); + . $this->_zendDb->getPlatform()->quoteIdentifier('zend_auth_credential_match') + ); // get select $dbSelect = clone $this->getDbSelect(); - $dbSelect->from($this->_tableName, array('*', $credentialExpression)) - ->where($this->_zendDb->quoteIdentifier($this->_identityColumn, true) . ' = ?', $this->_identity); + $dbSelect->from($this->_tableName) + ->columns(array('*', $credentialExpression)) + ->where($this->_zendDb->getPlatform()->quoteIdentifier($this->_identityColumn) . ' = ?'); return $dbSelect; } /** - * _authenticateQuerySelect() - This method accepts a Zend_Db_Select object and + * _authenticateQuerySelect() - This method accepts a Zend\Db\Sql\Select object and * performs a query against the database with that object. * - * @param Zend_Db_Select $dbSelect - * @throws \Zend\Authentication\Adapter\Exception - when an invalid select - * object is encountered + * @param DbSelect $dbSelect + * @throws Exception - when an invalid select object is encountered * @return array */ protected function _authenticateQuerySelect(DBSelect $dbSelect) { + $statement = $this->_zendDb->createStatement(); + $dbSelect->prepareStatement($this->_zendDb, $statement); + $resultSet = new ResultSet(); try { - if ($this->_zendDb->getFetchMode() != Db::FETCH_ASSOC) { - $origDbFetchMode = $this->_zendDb->getFetchMode(); - $this->_zendDb->setFetchMode(Db::FETCH_ASSOC); - } - $resultIdentities = $this->_zendDb->fetchAll($dbSelect->__toString()); - if (isset($origDbFetchMode)) { - $this->_zendDb->setFetchMode($origDbFetchMode); - unset($origDbFetchMode); - } + $resultSet->setDataSource($statement->execute(array($this->_credential, $this->_identity))); + $resultIdentities = $resultSet->toArray(); } catch (\Exception $e) { - throw new Exception\RuntimeException('The supplied parameters to Zend\Authentication\Adapter\DbTable failed to ' - . 'produce a valid sql statement, please check table and column names ' - . 'for validity.', 0, $e); + throw new Exception\RuntimeException( + 'The supplied parameters to DbTable failed to ' + . 'produce a valid sql statement, please check table and column names ' + . 'for validity.', 0, $e + ); } return $resultIdentities; } @@ -507,19 +469,17 @@ protected function _authenticateValidateResultSet(array $resultIdentities) * identity provided to this adapter. * * @param array $resultIdentity - * @return Zend\Authentication\Result + * @return AuthenticationResult */ protected function _authenticateValidateResult($resultIdentity) { - $zendAuthCredentialMatchColumn = $this->_zendDb->foldCase('zend_auth_credential_match'); - - if ($resultIdentity[$zendAuthCredentialMatchColumn] != '1') { + if ($resultIdentity['zend_auth_credential_match'] != '1') { $this->_authenticateResultInfo['code'] = AuthenticationResult::FAILURE_CREDENTIAL_INVALID; $this->_authenticateResultInfo['messages'][] = 'Supplied credential is invalid.'; return $this->_authenticateCreateAuthResult(); } - unset($resultIdentity[$zendAuthCredentialMatchColumn]); + unset($resultIdentity['zend_auth_credential_match']); $this->_resultRow = $resultIdentity; $this->_authenticateResultInfo['code'] = AuthenticationResult::SUCCESS; @@ -531,7 +491,7 @@ protected function _authenticateValidateResult($resultIdentity) * _authenticateCreateAuthResult() - Creates a Zend_Auth_Result object from * the information that has been collected during the authenticate() attempt. * - * @return \Zend\Authentication\Result + * @return AuthenticationResult */ protected function _authenticateCreateAuthResult() { @@ -539,7 +499,7 @@ protected function _authenticateCreateAuthResult() $this->_authenticateResultInfo['code'], $this->_authenticateResultInfo['identity'], $this->_authenticateResultInfo['messages'] - ); + ); } } diff --git a/test/Adapter/DbTableTest.php b/test/Adapter/DbTableTest.php index add6aef..0f6338d 100644 --- a/test/Adapter/DbTableTest.php +++ b/test/Adapter/DbTableTest.php @@ -23,9 +23,8 @@ use Zend\Authentication\Adapter, Zend\Authentication, - Zend\Db\Db, - Zend\Db\Adapter\Pdo\Sqlite as SQLiteAdapter, - Zend\Db\Select as DBSelect; + Zend\Db\Adapter\Adapter as DbAdapter, + Zend\Db\Sql\Select as DBSelect; /** * @category Zend @@ -41,14 +40,14 @@ class DbTableTest extends \PHPUnit_Framework_TestCase /** * Sqlite database connection * - * @var Zend_Db_Adapter_Pdo_Sqlite + * @var Zend\Db\Adapter */ protected $_db = null; /** * Database table authentication adapter * - * @var Zend_Auth_Adapter_DbTable + * @var Zend\Authentication\Adapter\DbTable */ protected $_adapter = null; @@ -137,8 +136,8 @@ public function testAuthenticateFailureIdentityNotFound() */ public function testAuthenticateFailureIdentityAmbigious() { - $sql_insert = 'INSERT INTO users (username, password, real_name) VALUES ("my_username", "my_password", "My Real Name")'; - $this->_db->query($sql_insert); + $sqlInsert = 'INSERT INTO users (username, password, real_name) VALUES ("my_username", "my_password", "My Real Name")'; + $this->_db->query($sqlInsert, DbAdapter::QUERY_MODE_EXECUTE); $this->_adapter->setIdentity('my_username'); $this->_adapter->setCredential('my_password'); @@ -368,9 +367,9 @@ public function testAuthenticateWithDefaultDbAdapter() } /** * Test to see same usernames with different passwords can not authenticate - * when flag is not set. This is the current state of + * when flag is not set. This is the current state of * Zend_Auth_Adapter_DbTable (up to ZF 1.10.6) - * + * * @group ZF-7289 */ public function testEqualUsernamesDifferentPasswordShouldNotAuthenticateWhenFlagIsNotSet() @@ -380,7 +379,7 @@ public function testEqualUsernamesDifferentPasswordShouldNotAuthenticateWhenFlag 'password' => 'my_otherpass', 'real_name' => 'Test user 2', )); - + // test if user 1 can authenticate $this->_adapter->setIdentity('my_username') ->setCredential('my_password'); @@ -392,7 +391,7 @@ public function testEqualUsernamesDifferentPasswordShouldNotAuthenticateWhenFlag /** * Test to see same usernames with different passwords can authenticate when * a flag is set - * + * * @group ZF-7289 */ public function testEqualUsernamesDifferentPasswordShouldAuthenticateWhenFlagIsSet() @@ -402,7 +401,7 @@ public function testEqualUsernamesDifferentPasswordShouldAuthenticateWhenFlagIsS 'password' => 'my_otherpass', 'real_name' => 'Test user 2', )); - + // test if user 1 can authenticate $this->_adapter->setIdentity('my_username') ->setCredential('my_password') @@ -412,10 +411,10 @@ public function testEqualUsernamesDifferentPasswordShouldAuthenticateWhenFlagIsS $result->getMessages())); $this->assertTrue($result->isValid()); $this->assertEquals('my_username', $result->getIdentity()); - + $this->_adapter = null; $this->_setupAuthAdapter(); - + // test if user 2 can authenticate $this->_adapter->setIdentity('my_username') ->setCredential('my_otherpass') @@ -430,28 +429,34 @@ public function testEqualUsernamesDifferentPasswordShouldAuthenticateWhenFlagIsS protected function _setupDbAdapter($optionalParams = array()) { - $params = array('dbname' => TESTS_ZEND_AUTH_ADAPTER_DBTABLE_PDO_SQLITE_DATABASE); + $params = array('driver' => 'pdo_sqlite', + 'dbname' => TESTS_ZEND_AUTH_ADAPTER_DBTABLE_PDO_SQLITE_DATABASE); if (!empty($optionalParams)) { $params['options'] = $optionalParams; } - $this->_db = new SQLiteAdapter($params); + $this->_db = new DbAdapter($params); - $sqlCreate = 'CREATE TABLE [users] ( ' + $sqlCreate = 'CREATE TABLE IF NOT EXISTS [users] ( ' . '[id] INTEGER NOT NULL PRIMARY KEY, ' . '[username] VARCHAR(50) NOT NULL, ' . '[password] VARCHAR(32) NULL, ' . '[real_name] VARCHAR(150) NULL)'; - $this->_db->query($sqlCreate); + $this->_db->query($sqlCreate, DbAdapter::QUERY_MODE_EXECUTE); + + $sqlDelete = 'DELETE FROM users'; + $this->_db->query($sqlDelete, DbAdapter::QUERY_MODE_EXECUTE); $sqlInsert = 'INSERT INTO users (username, password, real_name) ' . 'VALUES ("my_username", "my_password", "My Real Name")'; - $this->_db->query($sqlInsert); + $this->_db->query($sqlInsert, DbAdapter::QUERY_MODE_EXECUTE); } protected function _setupAuthAdapter() { $this->_adapter = new Adapter\DbTable($this->_db, 'users', 'username', 'password'); } + } + From f70cc135fdd3e1377582f484340d58deb5a9e439 Mon Sep 17 00:00:00 2001 From: Mike Willbanks Date: Wed, 4 Apr 2012 09:04:59 -0500 Subject: [PATCH 25/61] make storage session not so stupid so i can configure it nicely through DI --- src/Storage/Session.php | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/src/Storage/Session.php b/src/Storage/Session.php index a2a25f3..b0c68cb 100644 --- a/src/Storage/Session.php +++ b/src/Storage/Session.php @@ -51,21 +51,21 @@ class Session implements AuthenticationStorage * * @var Zend\Session\Container */ - protected $_session; + protected $session; /** * Session namespace * * @var mixed */ - protected $_namespace; + protected $namespace = self::NAMESPACE_DEFAULT; /** * Session object member * * @var mixed */ - protected $_member; + protected $member = self::MEMBER_DEFAULT; /** * Sets session storage options and initializes session namespace object @@ -74,12 +74,17 @@ class Session implements AuthenticationStorage * @param mixed $member * @return void */ - public function __construct( - $namespace = self::NAMESPACE_DEFAULT, $member = self::MEMBER_DEFAULT, SessionManager $manager = null - ) { - $this->_namespace = $namespace; - $this->_member = $member; - $this->_session = new SessionContainer($this->_namespace, $manager); + public function __construct($namespace = null, $member = null, SessionManager $manager = null) + { + if ($namespace !== null) { + $this->namespace = $namespace; + } + if ($member !== null) { + $this->member = $member; + } + $this->namespace = $namespace; + $this->member = $member; + $this->session = new SessionContainer($this->_namespace, $manager); } /** @@ -89,7 +94,7 @@ public function __construct( */ public function getNamespace() { - return $this->_namespace; + return $this->namespace; } /** @@ -99,7 +104,7 @@ public function getNamespace() */ public function getMember() { - return $this->_member; + return $this->member; } /** @@ -109,7 +114,7 @@ public function getMember() */ public function isEmpty() { - return !isset($this->_session->{$this->_member}); + return !isset($this->session->{$this->member}); } /** @@ -119,7 +124,7 @@ public function isEmpty() */ public function read() { - return $this->_session->{$this->_member}; + return $this->session->{$this->member}; } /** @@ -130,7 +135,7 @@ public function read() */ public function write($contents) { - $this->_session->{$this->_member} = $contents; + $this->session->{$this->member} = $contents; } /** @@ -140,6 +145,6 @@ public function write($contents) */ public function clear() { - unset($this->_session->{$this->_member}); + unset($this->session->{$this->member}); } } From a6548723b4cb43ddfccb7920cf67a9865a11657f Mon Sep 17 00:00:00 2001 From: Mike Willbanks Date: Wed, 4 Apr 2012 09:07:33 -0500 Subject: [PATCH 26/61] basic fixes for storage session after i broke it --- src/Storage/Session.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Storage/Session.php b/src/Storage/Session.php index b0c68cb..4bcafde 100644 --- a/src/Storage/Session.php +++ b/src/Storage/Session.php @@ -82,9 +82,7 @@ public function __construct($namespace = null, $member = null, SessionManager $m if ($member !== null) { $this->member = $member; } - $this->namespace = $namespace; - $this->member = $member; - $this->session = new SessionContainer($this->_namespace, $manager); + $this->session = new SessionContainer($this->namespace, $manager); } /** From 158c94cbe0ef4ea54a7c30d68409ce726e2bf459 Mon Sep 17 00:00:00 2001 From: Mike Willbanks Date: Wed, 4 Apr 2012 09:12:08 -0500 Subject: [PATCH 27/61] updated test method authenticate for coding standard violation --- test/AuthenticationServiceTest.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/AuthenticationServiceTest.php b/test/AuthenticationServiceTest.php index f7cd3b1..3843fb9 100644 --- a/test/AuthenticationServiceTest.php +++ b/test/AuthenticationServiceTest.php @@ -66,7 +66,7 @@ public function testAdapter() */ public function testAuthenticate() { - $result = $this->_authenticate(); + $result = $this->authenticate(); $this->assertTrue($result instanceof Auth\Result); $this->assertTrue($this->auth->hasIdentity()); $this->assertEquals('someIdentity', $this->auth->getIdentity()); @@ -74,7 +74,7 @@ public function testAuthenticate() public function testAuthenticateSetAdapter() { - $result = $this->_authenticate(new TestAsset\SuccessAdapter()); + $result = $this->authenticate(new TestAsset\SuccessAdapter()); $this->assertTrue($result instanceof Auth\Result); $this->assertTrue($this->auth->hasIdentity()); $this->assertEquals('someIdentity', $this->auth->getIdentity()); @@ -87,13 +87,13 @@ public function testAuthenticateSetAdapter() */ public function testClearIdentity() { - $this->_authenticate(); + $this->authenticate(); $this->auth->clearIdentity(); $this->assertFalse($this->auth->hasIdentity()); $this->assertEquals(null, $this->auth->getIdentity()); } - protected function _authenticate($adapter = null) + protected function authenticate($adapter = null) { if ($adapter === null) { $adapter = new TestAsset\SuccessAdapter(); From 57be526adc1383ab87b388634db82fe1e8aaeafd Mon Sep 17 00:00:00 2001 From: Roger Hunwicks Date: Wed, 4 Apr 2012 17:39:40 +0300 Subject: [PATCH 28/61] Fix ZF2/199: Update Zend Authentication to work with new DB components Updated ZendTest\Authentication\Adapter\DbTableTest so that all tests pass; this included removing tests related to database case folding (not implemented in ZF2 database adapters) and default database adapters (an adapter must be injected) --- test/Adapter/DbTableTest.php | 97 +++++++----------------------------- 1 file changed, 18 insertions(+), 79 deletions(-) diff --git a/test/Adapter/DbTableTest.php b/test/Adapter/DbTableTest.php index 0f6338d..0f6647b 100644 --- a/test/Adapter/DbTableTest.php +++ b/test/Adapter/DbTableTest.php @@ -216,17 +216,16 @@ public function testAdapterCanReturnDbSelectObject() */ public function testAdapterCanUseModifiedDbSelectObject() { - $this->_db->getProfiler()->setEnabled(true); $select = $this->_adapter->getDbSelect(); - $select->where('1 = 1'); + $select->where('1 = 0'); $this->_adapter->setIdentity('my_username'); $this->_adapter->setCredential('my_password'); - $this->_adapter->authenticate(); - $profiler = $this->_db->getProfiler(); - $this->assertEquals( - 'SELECT "users".*, (CASE WHEN "password" = \'my_password\' THEN 1 ELSE 0 END) AS "zend_auth_credential_match" FROM "users" WHERE (1 = 1) AND ("username" = \'my_username\')', - $profiler->getLastQueryProfile()->getQuery() - ); + try { + $result = $this->_adapter->authenticate(); + $this->assertEquals(Authentication\Result::FAILURE_IDENTITY_NOT_FOUND, $result->getCode()); + } catch (Adapter\Exception\RuntimeException $e) { + $this->fail('Exception should have been thrown'); + } } /** @@ -240,9 +239,11 @@ public function testAdapterReturnsASelectObjectWithoutAuthTimeModificationsAfter $this->_adapter->setCredential('my_password'); $this->_adapter->authenticate(); $selectAfterAuth = $this->_adapter->getDbSelect(); - $whereParts = $selectAfterAuth->getPart(DBSelect::WHERE); + $whereParts = $selectAfterAuth->where->getPredicates(); $this->assertEquals(1, count($whereParts)); - $this->assertEquals('(1 = 1)', array_pop($whereParts)); + $lastWherePart = array_pop($whereParts); + $expressionData = $lastWherePart[1]->getExpressionData(); + $this->assertEquals('1 = 1', $expressionData[0][0]); } /** @@ -306,65 +307,6 @@ public function testCatchExceptionBadSql() $result = $this->_adapter->authenticate(); } - /** - * - * @group ZF-3068 - */ - public function testDbTableAdapterUsesCaseFolding() - { - $this->tearDown(); - $this->_setupDbAdapter(array(Db::CASE_FOLDING => Db::CASE_UPPER)); - $this->_setupAuthAdapter(); - - $this->_adapter->setIdentity('my_username'); - $this->_adapter->setCredential('my_password'); - $this->_db->foldCase(Db::CASE_UPPER); - $this->_adapter->authenticate(); - } - - - /** - * Test fallback to default database adapter, when no such adapter set - * - * @group ZF-7510 - */ - public function testAuthenticateWithDefaultDbAdapterNoAdapterException() - { - $this->setExpectedException('Zend\Authentication\Adapter\Exception\RuntimeException', 'Null was provided'); - - // make sure that no default adapter exists - \Zend\Db\Table\AbstractTable::setDefaultAdapter(null); - $this->_adapter = new Adapter\DbTable(); - } - - /** - * Test fallback to default database adapter - * - * @group ZF-7510 - */ - public function testAuthenticateWithDefaultDbAdapter() - { - // preserve default adapter between cases - $tmp = \Zend\Db\Table\AbstractTable::getDefaultAdapter(); - - // make sure that default db adapter exists - \Zend\Db\Table\AbstractTable::setDefaultAdapter($this->_db); - - // check w/o passing adapter - $this->_adapter = new Adapter\DbTable(); - $this->_adapter - ->setTableName('users') - ->setIdentityColumn('username') - ->setCredentialColumn('password') - ->setTableName('users') - ->setIdentity('my_username') - ->setCredential('my_password'); - $result = $this->_adapter->authenticate(); - $this->assertTrue($result->isValid()); - - // restore adapter - \Zend\Db\Table\AbstractTable::setDefaultAdapter($tmp); - } /** * Test to see same usernames with different passwords can not authenticate * when flag is not set. This is the current state of @@ -374,11 +316,9 @@ public function testAuthenticateWithDefaultDbAdapter() */ public function testEqualUsernamesDifferentPasswordShouldNotAuthenticateWhenFlagIsNotSet() { - $this->_db->insert('users', array ( - 'username' => 'my_username', - 'password' => 'my_otherpass', - 'real_name' => 'Test user 2', - )); + $sqlInsert = 'INSERT INTO users (username, password, real_name) ' + . 'VALUES ("my_username", "my_otherpass", "Test user 2")'; + $this->_db->query($sqlInsert, DbAdapter::QUERY_MODE_EXECUTE); // test if user 1 can authenticate $this->_adapter->setIdentity('my_username') @@ -388,6 +328,7 @@ public function testEqualUsernamesDifferentPasswordShouldNotAuthenticateWhenFlag $result->getMessages())); $this->assertFalse($result->isValid()); } + /** * Test to see same usernames with different passwords can authenticate when * a flag is set @@ -396,11 +337,9 @@ public function testEqualUsernamesDifferentPasswordShouldNotAuthenticateWhenFlag */ public function testEqualUsernamesDifferentPasswordShouldAuthenticateWhenFlagIsSet() { - $this->_db->insert('users', array ( - 'username' => 'my_username', - 'password' => 'my_otherpass', - 'real_name' => 'Test user 2', - )); + $sqlInsert = 'INSERT INTO users (username, password, real_name) ' + . 'VALUES ("my_username", "my_otherpass", "Test user 2")'; + $this->_db->query($sqlInsert, DbAdapter::QUERY_MODE_EXECUTE); // test if user 1 can authenticate $this->_adapter->setIdentity('my_username') From e554c57862ba29861b6a318a5c31ae52a6404619 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Wed, 4 Apr 2012 00:26:01 +0200 Subject: [PATCH 29/61] Adding list of features that have to be tested with Travis-CI or that are not yet ready to be tested --- .travis/skipped-components | 27 +++++++++++++++++++++++++ .travis/tested-components | 40 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+) create mode 100644 .travis/skipped-components create mode 100644 .travis/tested-components diff --git a/.travis/skipped-components b/.travis/skipped-components new file mode 100644 index 0000000..7d38e2d --- /dev/null +++ b/.travis/skipped-components @@ -0,0 +1,27 @@ +Zend/Amf +Zend/Barcode +Zend/Cache +Zend/Code +Zend/Date +Zend/Docbook +Zend/Feed +Zend/File +Zend/Filter +Zend/GData +Zend/Json +Zend/Locale +Zend/Mail +Zend/Mime +Zend/Navigation +Zend/OpenId +Zend/Paginator +Zend/Queue +Zend/RegistryTest.php +Zend/Service +Zend/Session +Zend/Soap +Zend/Test +Zend/Translator +Zend/Validator +Zend/Wildfire +Zend/XmlRpc diff --git a/.travis/tested-components b/.travis/tested-components new file mode 100644 index 0000000..34047ab --- /dev/null +++ b/.travis/tested-components @@ -0,0 +1,40 @@ +Zend/Mvc +Zend/View +Zend/Acl +Zend/Authentication +Zend/Captcha +Zend/Cloud +Zend/Config +Zend/Console +Zend/Crypt +Zend/Currency +Zend/Db +Zend/Di +Zend/Dojo +Zend/Dom +Zend/EventManager +Zend/Form +Zend/Http +Zend/InfoCard +Zend/Ldap +Zend/Loader +Zend/Log +Zend/Markup +Zend/Measure +Zend/Memory +Zend/Module +Zend/Mvc +Zend/OAuth +Zend/Pdf +Zend/ProgressBar +Zend/Rest +Zend/Search +Zend/Serializer +Zend/Server +Zend/Stdlib +Zend/Tag +Zend/Text +Zend/TimeSync +Zend/Uri +Zend/VersionTest.php +Zend/View From 8eaf09a63ce605b17db47bd55a75bc73efdecf10 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Wed, 4 Apr 2012 00:27:17 +0200 Subject: [PATCH 30/61] Adding shell script to run tests It iterates over tested components and runs phpunit for each of them --- .travis/run-tests.sh | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 .travis/run-tests.sh diff --git a/.travis/run-tests.sh b/.travis/run-tests.sh new file mode 100644 index 0000000..47d0c4a --- /dev/null +++ b/.travis/run-tests.sh @@ -0,0 +1,8 @@ +#!/bin/bash +travisdir=$(dirname $(readlink /proc/$$/fd/255)) +testdir="$travisdir/../tests" +testedcomponents=(`cat "$travisdir/tested-components"`) + +for tested in "${testedcomponents[@]}" + do phpunit -c $testdir/phpunit.xml $testdir/$tested +done From eb4d0f20d2c4483eb94f4f133bf1485a6d4f05ae Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Wed, 4 Apr 2012 00:29:10 +0200 Subject: [PATCH 31/61] Adding script used to configure the test suite --- .travis/TestConfiguration.php | 825 ++++++++++++++++++++++++++++++++++ 1 file changed, 825 insertions(+) create mode 100644 .travis/TestConfiguration.php diff --git a/.travis/TestConfiguration.php b/.travis/TestConfiguration.php new file mode 100644 index 0000000..fd89470 --- /dev/null +++ b/.travis/TestConfiguration.php @@ -0,0 +1,825 @@ + test disabling output buffering in + * dispatcher + */ +defined('TESTS_ZEND_CONTROLLER_DISPATCHER_OB') || define('TESTS_ZEND_CONTROLLER_DISPATCHER_OB', false); + +/** + * Zend_Crypt related constantes + * + * TESTS_ZEND_CRYPT_OPENSSL_CONF => location of an openssl.cnf file for use + * with RSA encryption + */ +defined('TESTS_ZEND_CRYPT_OPENSSL_CONF') || define('TESTS_ZEND_CRYPT_OPENSSL_CONF', false); + +/** + * Zend_Db_Adapter_Pdo_Mysql and Zend_Db_Adapter_Mysqli + * + * There are separate properties to enable tests for the PDO_MYSQL adapter and + * the native Mysqli adapters, but the other properties are shared between the + * two MySQL-related Zend_Db adapters. + */ +defined('TESTS_ZEND_DB_ADAPTER_PDO_MYSQL_ENABLED') || define('TESTS_ZEND_DB_ADAPTER_PDO_MYSQL_ENABLED', false); +defined('TESTS_ZEND_DB_ADAPTER_MYSQLI_ENABLED') || define('TESTS_ZEND_DB_ADAPTER_MYSQLI_ENABLED', false); +defined('TESTS_ZEND_DB_ADAPTER_MYSQL_HOSTNAME') || define('TESTS_ZEND_DB_ADAPTER_MYSQL_HOSTNAME', '127.0.0.1'); +defined('TESTS_ZEND_DB_ADAPTER_MYSQL_USERNAME') || define('TESTS_ZEND_DB_ADAPTER_MYSQL_USERNAME', null); +defined('TESTS_ZEND_DB_ADAPTER_MYSQL_PASSWORD') || define('TESTS_ZEND_DB_ADAPTER_MYSQL_PASSWORD', null); +defined('TESTS_ZEND_DB_ADAPTER_MYSQL_DATABASE') || define('TESTS_ZEND_DB_ADAPTER_MYSQL_DATABASE', 'test'); +defined('TESTS_ZEND_DB_ADAPTER_MYSQL_PORT') || define('TESTS_ZEND_DB_ADAPTER_MYSQL_PORT', 3306); + +/** + * Zend_Db_Adapter_Pdo_Sqlite + * + * Username and password are irrelevant for SQLite. + */ +defined('TESTS_ZEND_DB_ADAPTER_PDO_SQLITE_ENABLED') || define('TESTS_ZEND_DB_ADAPTER_PDO_SQLITE_ENABLED', false); +defined('TESTS_ZEND_DB_ADAPTER_PDO_SQLITE_DATABASE') || define('TESTS_ZEND_DB_ADAPTER_PDO_SQLITE_DATABASE', ':memory:'); + +/** + * Zend_Db_Adapter_Pdo_Mssql + * + * Note that you need to patch your ntwdblib.dll, the one that + * comes with PHP does not work. See user comments at + * http://us2.php.net/manual/en/ref.mssql.php + */ +defined('TESTS_ZEND_DB_ADAPTER_PDO_MSSQL_ENABLED') || define('TESTS_ZEND_DB_ADAPTER_PDO_MSSQL_ENABLED', false); +defined('TESTS_ZEND_DB_ADAPTER_PDO_MSSQL_HOSTNAME') || define('TESTS_ZEND_DB_ADAPTER_PDO_MSSQL_HOSTNAME', '127.0.0.1'); +defined('TESTS_ZEND_DB_ADAPTER_PDO_MSSQL_USERNAME') || define('TESTS_ZEND_DB_ADAPTER_PDO_MSSQL_USERNAME', null); +defined('TESTS_ZEND_DB_ADAPTER_PDO_MSSQL_PASSWORD') || define('TESTS_ZEND_DB_ADAPTER_PDO_MSSQL_PASSWORD', null); +defined('TESTS_ZEND_DB_ADAPTER_PDO_MSSQL_DATABASE') || define('TESTS_ZEND_DB_ADAPTER_PDO_MSSQL_DATABASE', 'test'); + +/** + * Zend_Db_Adapter_Pdo_Pgsql + */ +defined('TESTS_ZEND_DB_ADAPTER_PDO_PGSQL_ENABLED') || define('TESTS_ZEND_DB_ADAPTER_PDO_PGSQL_ENABLED', false); +defined('TESTS_ZEND_DB_ADAPTER_PDO_PGSQL_HOSTNAME') || define('TESTS_ZEND_DB_ADAPTER_PDO_PGSQL_HOSTNAME', '127.0.0.1'); +defined('TESTS_ZEND_DB_ADAPTER_PDO_PGSQL_USERNAME') || define('TESTS_ZEND_DB_ADAPTER_PDO_PGSQL_USERNAME', null); +defined('TESTS_ZEND_DB_ADAPTER_PDO_PGSQL_PASSWORD') || define('TESTS_ZEND_DB_ADAPTER_PDO_PGSQL_PASSWORD', null); +defined('TESTS_ZEND_DB_ADAPTER_PDO_PGSQL_DATABASE') || define('TESTS_ZEND_DB_ADAPTER_PDO_PGSQL_DATABASE', 'postgres'); + +/** + * Zend_Db_Adapter_Oracle and Zend_Db_Adapter_Pdo_Oci + * + * There are separate properties to enable tests for the PDO_OCI adapter and + * the native Oracle adapter, but the other properties are shared between the + * two Oracle-related Zend_Db adapters. + */ +defined('TESTS_ZEND_DB_ADAPTER_PDO_OCI_ENABLED') || define('TESTS_ZEND_DB_ADAPTER_PDO_OCI_ENABLED', false); +defined('TESTS_ZEND_DB_ADAPTER_ORACLE_ENABLED') || define('TESTS_ZEND_DB_ADAPTER_ORACLE_ENABLED', false); +defined('TESTS_ZEND_DB_ADAPTER_ORACLE_HOSTNAME') || define('TESTS_ZEND_DB_ADAPTER_ORACLE_HOSTNAME', '127.0.0.1'); +defined('TESTS_ZEND_DB_ADAPTER_ORACLE_USERNAME') || define('TESTS_ZEND_DB_ADAPTER_ORACLE_USERNAME', null); +defined('TESTS_ZEND_DB_ADAPTER_ORACLE_PASSWORD') || define('TESTS_ZEND_DB_ADAPTER_ORACLE_PASSWORD', null); +defined('TESTS_ZEND_DB_ADAPTER_ORACLE_SID') || define('TESTS_ZEND_DB_ADAPTER_ORACLE_SID', 'xe'); + +/** + * Zend_Db_Adapter_Db2 and Zend_Db_Adapter_Pdo_Ibm + * There are separate properties to enable tests for the PDO_IBM adapter and + * the native DB2 adapter, but the other properties are shared between the + * two related Zend_Db adapters. + */ +defined('TESTS_ZEND_DB_ADAPTER_PDO_IBM_ENABLED') || define('TESTS_ZEND_DB_ADAPTER_PDO_IBM_ENABLED', false); +defined('TESTS_ZEND_DB_ADAPTER_DB2_ENABLED') || define('TESTS_ZEND_DB_ADAPTER_DB2_ENABLED', false); +defined('TESTS_ZEND_DB_ADAPTER_DB2_HOSTNAME') || define('TESTS_ZEND_DB_ADAPTER_DB2_HOSTNAME', '127.0.0.1'); +defined('TESTS_ZEND_DB_ADAPTER_DB2_PORT') || define('TESTS_ZEND_DB_ADAPTER_DB2_PORT', 50000); +defined('TESTS_ZEND_DB_ADAPTER_DB2_USERNAME') || define('TESTS_ZEND_DB_ADAPTER_DB2_USERNAME', null); +defined('TESTS_ZEND_DB_ADAPTER_DB2_PASSWORD') || define('TESTS_ZEND_DB_ADAPTER_DB2_PASSWORD', null); +defined('TESTS_ZEND_DB_ADAPTER_DB2_DATABASE') || define('TESTS_ZEND_DB_ADAPTER_DB2_DATABASE', 'sample'); + +/** + * Zend_Db_Adapter_Sqlsrv + * Note: Make sure that you create the "test" database and set a + * username and password + * + */ +defined('TESTS_ZEND_DB_ADAPTER_SQLSRV_ENABLED') || define('TESTS_ZEND_DB_ADAPTER_SQLSRV_ENABLED', false); +defined('TESTS_ZEND_DB_ADAPTER_SQLSRV_HOSTNAME') || define('TESTS_ZEND_DB_ADAPTER_SQLSRV_HOSTNAME', 'localhost\SQLEXPRESS'); +defined('TESTS_ZEND_DB_ADAPTER_SQLSRV_USERNAME') || define('TESTS_ZEND_DB_ADAPTER_SQLSRV_USERNAME', null); +defined('TESTS_ZEND_DB_ADAPTER_SQLSRV_PASSWORD') || define('TESTS_ZEND_DB_ADAPTER_SQLSRV_PASSWORD', null); +defined('TESTS_ZEND_DB_ADAPTER_SQLSRV_DATABASE') || define('TESTS_ZEND_DB_ADAPTER_SQLSRV_DATABASE', 'test'); + +/** + * Zend_Feed_Reader tests + * + * If the ONLINE_ENABLED property is false, only tests that can be executed + * without network connectivity are run; when enabled, all tests will run. + */ +defined('TESTS_ZEND_FEED_READER_ONLINE_ENABLED') || define('TESTS_ZEND_FEED_READER_ONLINE_ENABLED', false); + +/** + * Zend_Gdata tests + * + * If the ONLINE_ENABLED property is false, only tests that can be executed with + * a mock HTTP client are run. No request is sent to the Google Gdata servers. + * If ONLINE_ENABLED is true, some tests may make requests to the remote + * servers. This does not work if you are running tests on a disconnected + * client host. Also, the tests may show as failures if the Google servers + * cannot be reached or if they do not respond for another reason. + * + * If the CLIENTLOGIN_ENABLED property below is false, the authenticated + * tests are reported Skipped in the test run. Set this property to true + * to enable tests that require ClientLogin authentication. Enter your + * Google login credentials in the EMAIL and PASSWORD properties below. + * + * Edit TestConfiguration.php, not TestConfiguration.php.dist. + * Never commit plaintext passwords to the source code repository. + * + * Note: the GData tests currently require that the TZID env variable + * be set or the timezone otherwise configured. You'll see errors from the + * tests if this is not the case. + */ +defined('TESTS_ZEND_GDATA_ONLINE_ENABLED') || define('TESTS_ZEND_GDATA_ONLINE_ENABLED', false); +defined('TESTS_ZEND_GDATA_CLIENTLOGIN_ENABLED') || define('TESTS_ZEND_GDATA_CLIENTLOGIN_ENABLED', false); + +/* + * The credentials provided here should be only for a TEST account. + * Data for various services in this account may be added to, updated, + * or deleted based upon the actions of these test accounts. + */ +defined('TESTS_ZEND_GDATA_CLIENTLOGIN_EMAIL') || define('TESTS_ZEND_GDATA_CLIENTLOGIN_EMAIL', 'example@example.com'); +defined('TESTS_ZEND_GDATA_CLIENTLOGIN_PASSWORD') || define('TESTS_ZEND_GDATA_CLIENTLOGIN_PASSWORD', 'password'); + +/* + * This is the ID of a blank blog. There is no need to have + * any content in this blog. Also, blogs can only be used + * several times for the purpose of these test cases before + * they must be deleted and recreated. Otherwise, the tests + * will start failing, as posts to Blogger will return a 201 Created + * response even though the entry was not posted to the blog. + * This problem is being investigated. + */ +defined('TESTS_ZEND_GDATA_BLOGGER_ONLINE_ENABLED') || define('TESTS_ZEND_GDATA_BLOGGER_ONLINE_ENABLED', false); +defined('TESTS_ZEND_GDATA_BLOG_ID') || define('TESTS_ZEND_GDATA_BLOG_ID', '1111111111111111111'); + +/* + * This is the key for a spreadsheet with data only in the first row of + * the spreadsheet. The strings 'a1', 'b1', 'c1', 'd1' should be in the + * corresponding cell locations. + */ +defined('TESTS_ZEND_GDATA_SPREADSHEETS_ONLINE_ENABLED') || define('TESTS_ZEND_GDATA_SPREADSHEETS_ONLINE_ENABLED', false); +defined('TESTS_ZEND_GDATA_SPREADSHEETS_SPREADSHEETKEY') || define('TESTS_ZEND_GDATA_SPREADSHEETS_SPREADSHEETKEY', 'o01111111111111111111.1111111111111111111'); +defined('TESTS_ZEND_GDATA_SPREADSHEETS_WORKSHEETID') || define('TESTS_ZEND_GDATA_SPREADSHEETS_WORKSHEETID', 'default'); + +/* + * This indicates that online tests for the Google Calendar API should + * be performed. The default calendar will be used. + */ +defined('TESTS_ZEND_GDATA_CALENDAR_ONLINE_ENABLED') || define('TESTS_ZEND_GDATA_CALENDAR_ONLINE_ENABLED', false); + +/* + * This is the fully-qualified domain name for a domiain hosted using + * Google Apps. This domain must be registered with Google Apps and + * have API access enabled. This should be a TEST domain only. + */ +defined('TESTS_ZEND_GDATA_GAPPS_ONLINE_ENABLED') || define('TESTS_ZEND_GDATA_GAPPS_ONLINE_ENABLED', false); +defined('TESTS_ZEND_GDATA_GAPPS_DOMAIN') || define('TESTS_ZEND_GDATA_GAPPS_DOMAIN', 'example.com.invalid'); +defined('TESTS_ZEND_GDATA_GAPPS_EMAIL') || define('TESTS_ZEND_GDATA_GAPPS_EMAIL', 'example@example.com'); +defined('TESTS_ZEND_GDATA_GAPPS_PASSWORD') || define('TESTS_ZEND_GDATA_GAPPS_PASSWORD', 'password'); + +/* + * This is the ONLINE_ENABLED property for Google Base. + */ +defined('TESTS_ZEND_GDATA_GBASE_ONLINE_ENABLED') || define('TESTS_ZEND_GDATA_GBASE_ONLINE_ENABLED', false); + +/* + * This indicates that online tests for the Books Search data API + * should be performed. + */ +defined('TESTS_ZEND_GDATA_BOOKS_ONLINE_ENABLED') || define('TESTS_ZEND_GDATA_BOOKS_ONLINE_ENABLED', false); + +/* + * This indicates that online tests for the YouTube data API should + * be performed. + */ +defined('TESTS_ZEND_GDATA_YOUTUBE_ONLINE_ENABLED') || define('TESTS_ZEND_GDATA_YOUTUBE_ONLINE_ENABLED', false); + +/* + * This is the username to use for retrieving subscriptions, etc + */ +defined('TESTS_ZEND_GDATA_YOUTUBE_ACCOUNT') || define('TESTS_ZEND_GDATA_YOUTUBE_ACCOUNT', 'zfgdata'); + +/* + * This is the developer key to access the YouTube API + */ +defined('TESTS_ZEND_GDATA_YOUTUBE_DEVELOPER_KEY') || define('TESTS_ZEND_GDATA_YOUTUBE_DEVELOPER_KEY', 'your_developer_key_here'); + +/* + * This is the client ID to access the YouTube API + */ +defined('TESTS_ZEND_GDATA_YOUTUBE_CLIENT_ID') || define('TESTS_ZEND_GDATA_YOUTUBE_CLIENT_ID', 'ZF_UnitTests_unknown'); + +/* + * This indicates that online tests for the Google Documents API should + * be performed. + */ +defined('TESTS_ZEND_GDATA_DOCS_ONLINE_ENABLED') || define('TESTS_ZEND_GDATA_DOCS_ONLINE_ENABLED', false); + +/* + * This indicates that online tests for the GData Photos API should + * be performed. + */ +defined('TESTS_ZEND_GDATA_PHOTOS_ONLINE_ENABLED') || define('TESTS_ZEND_GDATA_PHOTOS_ONLINE_ENABLED', false); + +/* + * This indicates that online tests for the Google Health API should + * be performed. + */ +defined('TESTS_ZEND_GDATA_HEALTH_ONLINE_ENABLED') || define('TESTS_ZEND_GDATA_HEALTH_ONLINE_ENABLED', false); + +/** + * Zend_Http_Client tests + * + * To enable the dynamic Zend_Http_Client tests, you will need to symbolically + * link or copy the files in tests/Zend/Http/Client/_files to a directory + * under your web server(s) document root and set this constant to point to the + * URL of this directory. + */ +defined('TESTS_ZEND_HTTP_CLIENT_BASEURI') || define('TESTS_ZEND_HTTP_CLIENT_BASEURI', false); + +/** + * Zend_Http_Client_Proxy tests + * + * HTTP proxy to be used for testing the Proxy adapter. Set to a string of + * the form 'host:port'. Set to null to skip HTTP proxy tests. + */ +defined('TESTS_ZEND_HTTP_CLIENT_HTTP_PROXY') || define('TESTS_ZEND_HTTP_CLIENT_HTTP_PROXY', false); +defined('TESTS_ZEND_HTTP_CLIENT_HTTP_PROXY_USER') || define('TESTS_ZEND_HTTP_CLIENT_HTTP_PROXY_USER', ''); +defined('TESTS_ZEND_HTTP_CLIENT_HTTP_PROXY_PASS') || define('TESTS_ZEND_HTTP_CLIENT_HTTP_PROXY_PASS', ''); + +/** + * Zend_Loader_Autoloader multi-version support tests + * + * ENABLED: whether or not to run the multi-version tests + * PATH: path to a directory containing multiple ZF version installs + * LATEST: most recent ZF version in the PATH + * e.g., "1.9.2" + * LATEST_MAJOR: most recent ZF major version in the PATH to test against + * e.g., "1.9.2" + * LATEST_MINOR: most recent ZF minor version in the PATH to test against + * e.g., "1.8.4PL1" + * SPECIFIC: specific ZF version in the PATH to test against + * e.g., "1.7.6" + * As an example, consider the following tree: + * ZendFramework/ + * |-- 1.9.2 + * |-- ZendFramework-1.9.1-minimal + * |-- 1.8.4PL1 + * |-- 1.8.4 + * |-- ZendFramework-1.8.3 + * |-- 1.7.8 + * |-- 1.7.7 + * |-- 1.7.6 + * You would then set the value of "LATEST" and "LATEST_MAJOR" to "1.9.2", and + * could choose between "1.9.2", "1.8.4PL1", and "1.7.8" for "LATEST_MINOR", + * and any version number for "SPECIFIC". "PATH" would point to the parent + * "ZendFramework" directory. + */ +defined('TESTS_ZEND_LOADER_AUTOLOADER_MULTIVERSION_ENABLED') || define('TESTS_ZEND_LOADER_AUTOLOADER_MULTIVERSION_ENABLED', false); +defined('TESTS_ZEND_LOADER_AUTOLOADER_MULTIVERSION_PATH') || define('TESTS_ZEND_LOADER_AUTOLOADER_MULTIVERSION_PATH', false); +defined('TESTS_ZEND_LOADER_AUTOLOADER_MULTIVERSION_LATEST') || define('TESTS_ZEND_LOADER_AUTOLOADER_MULTIVERSION_LATEST', false); +defined('TESTS_ZEND_LOADER_AUTOLOADER_MULTIVERSION_LATEST_MAJOR') || define('TESTS_ZEND_LOADER_AUTOLOADER_MULTIVERSION_LATEST_MAJOR', false); +defined('TESTS_ZEND_LOADER_AUTOLOADER_MULTIVERSION_LATEST_MINOR') || define('TESTS_ZEND_LOADER_AUTOLOADER_MULTIVERSION_LATEST_MINOR', false); +defined('TESTS_ZEND_LOADER_AUTOLOADER_MULTIVERSION_SPECIFIC') || define('TESTS_ZEND_LOADER_AUTOLOADER_MULTIVERSION_SPECIFIC', false); + +/** + * Zend_Ldap online tests + */ +defined('TESTS_ZEND_LDAP_ONLINE_ENABLED') || define('TESTS_ZEND_LDAP_ONLINE_ENABLED', false); + +/* These largely map to the options described in the Zend_Ldap and + * Zend_Auth_Adapter_Ldap documentation. + * + * Example Configuration for Active Directory: + * HOST: dc1.w.net + * USE_START_TLS: true + * USE_SSL: false + * USERNAME: CN=User 1,CN=Users,DC=w,DC=net + * PRINCIPAL_NAME: user1@w.net + * LDAP_PASSWORD: pass1 + * BASE_DN: CN=Users,DC=w,DC=net + * DOMAIN_NAME: w.net + * ACCOUNT_DOMAIN_NAME_SHORT: W + * ALT_USERNAME: user2 + * ALT_DN: CN=User 2,CN=Users,DC=w,DC=net + * ALT_PASSWORD: pass2 + * + * Example Configuration for OpenLDAP + * HOST: s0.foo.net + * USERNAME: CN=user1,DC=foo,DC=net + * PRINCIPAL_NAME: user1@foo.net + * LDAP_PASSWORD: pass1 + * BIND_REQUIRES_DN: true + * BASE_DN: OU=Sales,DC=w,DC=net + * DOMAIN_NAME: foo.net + * ACCOUNT_DOMAIN_NAME_SHORT: FOO + * ALT_USERNAME: abaker + * ALT_DN: CN=Alice Baker,OU=Sales,DC=foo,DC=net + * ALT_PASSWORD: apass + */ +defined('TESTS_ZEND_LDAP_HOST') || define('TESTS_ZEND_LDAP_HOST', 'localhost'); +//defined('TESTS_ZEND_LDAP_PORT') || define('TESTS_ZEND_LDAP_PORT', 389); +defined('TESTS_ZEND_LDAP_USE_START_TLS') || define('TESTS_ZEND_LDAP_USE_START_TLS', true); +//defined('TESTS_ZEND_LDAP_USE_SSL') || define('TESTS_ZEND_LDAP_USE_SSL', false); +defined('TESTS_ZEND_LDAP_USERNAME') || define('TESTS_ZEND_LDAP_USERNAME', 'CN=someUser,DC=example,DC=com'); +defined('TESTS_ZEND_LDAP_PRINCIPAL_NAME') || define('TESTS_ZEND_LDAP_PRINCIPAL_NAME', 'someUser@example.com'); +defined('TESTS_ZEND_LDAP_PASSWORD') || define('TESTS_ZEND_LDAP_PASSWORD', null); +defined('TESTS_ZEND_LDAP_BIND_REQUIRES_DN') || define('TESTS_ZEND_LDAP_BIND_REQUIRES_DN', true); +defined('TESTS_ZEND_LDAP_BASE_DN') || define('TESTS_ZEND_LDAP_BASE_DN', 'OU=Sales,DC=example,DC=com'); +//defined('TESTS_ZEND_LDAP_ACCOUNT_FILTER_FORMAT') || define('TESTS_ZEND_LDAP_ACCOUNT_FILTER_FORMAT', '(&(objectClass=posixAccount)(uid=%s))'); +defined('TESTS_ZEND_LDAP_ACCOUNT_DOMAIN_NAME') || define('TESTS_ZEND_LDAP_ACCOUNT_DOMAIN_NAME', 'example.com'); +defined('TESTS_ZEND_LDAP_ACCOUNT_DOMAIN_NAME_SHORT') || define('TESTS_ZEND_LDAP_ACCOUNT_DOMAIN_NAME_SHORT', 'EXAMPLE'); +defined('TESTS_ZEND_LDAP_ALT_USERNAME') || define('TESTS_ZEND_LDAP_ALT_USERNAME', 'anotherUser'); +defined('TESTS_ZEND_LDAP_ALT_DN') || define('TESTS_ZEND_LDAP_ALT_DN', 'CN=Another User,OU=Sales,DC=example,DC=com'); +defined('TESTS_ZEND_LDAP_ALT_PASSWORD') || define('TESTS_ZEND_LDAP_ALT_PASSWORD', null); // Used in Zend_Auth_Adapter_Ldap tests +//(defined('TESTS_ZEND_LDAP_WRITEABLE_SUBTREE') || define('TESTS_ZEND_LDAP_WRITEABLE_SUBTREE', 'OU=Test,OU=Sales,DC=example,DC=com'); + +/** + * Zend_Locale tests + * + * If the TESTS_ZEND_LOCALE_FORMAT_SETLOCALE property below is a valid, + * locally recognized locale (try "locale -a"), then all tests in + * tests/Zend/Locale/ test suites will execute *after* + * setlocale(LC_ALL, TESTS_ZEND_LOCALE_FORMAT_SETLOCALE); + * Primarily, this switches certain PHP functions to emit "localized" output, + * including the built-in "to string" for integer and float conversions. + * Thus, a locale of 'fr_FR' yields number-to-string conversions in a + * localized form with the decimal place separator chosen via: + * setlocale(LC_ALL, 'fr_FR@euro'); + */ +//define('TESTS_ZEND_LOCALE_FORMAT_SETLOCALE', 'fr'); +//define('TESTS_ZEND_LOCALE_FORMAT_SETLOCALE', 'fr_FR@euro'); +defined('TESTS_ZEND_LOCALE_FORMAT_SETLOCALE') || define('TESTS_ZEND_LOCALE_FORMAT_SETLOCALE', false); + +/** + * Zend_Date tests + * + * If the BCMATH_ENABLED property below is false, all arithmetic + * operations will use ordinary PHP math operators and functions. + * Otherwise, the bcmath functions will be used for unlimited precision. + * + * If the EXTENDED_COVERAGE property below is false, most of the I18N + * unit tests will not be computed... this speeds tests up to 80 minutes + * when doing reports. * + * Edit TestConfiguration.php, not TestConfiguration.php.dist. + */ +defined('TESTS_ZEND_LOCALE_BCMATH_ENABLED') || define('TESTS_ZEND_LOCALE_BCMATH_ENABLED', true); +defined('TESTS_ZEND_I18N_EXTENDED_COVERAGE') || define('TESTS_ZEND_I18N_EXTENDED_COVERAGE', true); + +/** + * Zend_Mail_Storage tests + * + * TESTS_ZEND_MAIL_SERVER_TESTDIR and TESTS_ZEND_MAIL_SERVER_FORMAT are used for POP3 and IMAP tests. + * TESTS_ZEND_MAIL_SERVER_FORMAT is the format your test mail server uses: 'mbox' or 'maildir'. The mail + * storage for the user specified in your POP3 or IMAP tests should be TESTS_ZEND_MAIL_SERVER_TESTDIR. Be + * careful: it's cleared before copying the files. If you want to copy the files manually set the dir + * to null (or anything == null). + * + * TESTS_ZEND_MAIL_TEMPDIR is used for testing write operations in local storages. If not set (== null) + * tempnam() is used. + */ +defined('TESTS_ZEND_MAIL_SERVER_TESTDIR') || define('TESTS_ZEND_MAIL_SERVER_TESTDIR', null); +defined('TESTS_ZEND_MAIL_SERVER_FORMAT') || define('TESTS_ZEND_MAIL_SERVER_FORMAT', 'mbox'); +defined('TESTS_ZEND_MAIL_TEMPDIR') || define('TESTS_ZEND_MAIL_TEMPDIR', null); + +/** + * Zend_Mail_Storage_Pop3 / Zend_Mail_Transport_Pop3 + * + * IMPORTANT: you need to copy tests/Zend/Mail/_files/test.mbox to your mail + * if you haven't set TESTS_ZEND_MAIL_SERVER_TESTDIR + */ +defined('TESTS_ZEND_MAIL_POP3_ENABLED') || define('TESTS_ZEND_MAIL_POP3_ENABLED', false); +defined('TESTS_ZEND_MAIL_POP3_HOST') || define('TESTS_ZEND_MAIL_POP3_HOST', 'localhost'); +defined('TESTS_ZEND_MAIL_POP3_USER') || define('TESTS_ZEND_MAIL_POP3_USER', 'test'); +defined('TESTS_ZEND_MAIL_POP3_PASSWORD') || define('TESTS_ZEND_MAIL_POP3_PASSWORD', ''); +// test SSL connections if enabled in your test server +defined('TESTS_ZEND_MAIL_POP3_SSL') || define('TESTS_ZEND_MAIL_POP3_SSL', true); +defined('TESTS_ZEND_MAIL_POP3_TLS') || define('TESTS_ZEND_MAIL_POP3_TLS', true); +// WRONG_PORT should be an existing server port, +// INVALID_PORT should be a non existing (each on defined host) +defined('TESTS_ZEND_MAIL_POP3_WRONG_PORT') || define('TESTS_ZEND_MAIL_POP3_WRONG_PORT', 80); +defined('TESTS_ZEND_MAIL_POP3_INVALID_PORT') || define('TESTS_ZEND_MAIL_POP3_INVALID_PORT', 3141); + +/** + * Zend_Mail_Storage_Imap / Zend_Mail_Transport_Imap + * + * IMPORTANT: you need to copy tests/Zend/Mail/_files/test.mbox to your mail + * if you haven't set TESTS_ZEND_MAIL_SERVER_TESTDIR + */ +defined('TESTS_ZEND_MAIL_IMAP_ENABLED') || define('TESTS_ZEND_MAIL_IMAP_ENABLED', false); +defined('TESTS_ZEND_MAIL_IMAP_HOST') || define('TESTS_ZEND_MAIL_IMAP_HOST', 'localhost'); +defined('TESTS_ZEND_MAIL_IMAP_USER') || define('TESTS_ZEND_MAIL_IMAP_USER', 'test'); +defined('TESTS_ZEND_MAIL_IMAP_PASSWORD') || define('TESTS_ZEND_MAIL_IMAP_PASSWORD', ''); +// test SSL connections if enabled in your test server +defined('TESTS_ZEND_MAIL_IMAP_SSL') || define('TESTS_ZEND_MAIL_IMAP_SSL', true); +defined('TESTS_ZEND_MAIL_IMAP_TLS') || define('TESTS_ZEND_MAIL_IMAP_TLS', true); +// WRONG_PORT should be an existing server port, +// INVALID_PORT should be a non-existing (each on defined host) +defined('TESTS_ZEND_MAIL_IMAP_WRONG_PORT') || define('TESTS_ZEND_MAIL_IMAP_WRONG_PORT', 80); +defined('TESTS_ZEND_MAIL_IMAP_INVALID_PORT') || define('TESTS_ZEND_MAIL_IMAP_INVALID_PORT', 3141); + + +/** + * Zend_Mail_Storage_Maildir test + * + * Before enabling this test you have to unpack messages.tar in + * Zend/Mail/_files/test.maildir/cur/ and remove the tar for this test to work. + * That's because the messages files have a colon in the filename and that's a + * forbidden character on Windows. + */ +defined('TESTS_ZEND_MAIL_MAILDIR_ENABLED') || define('TESTS_ZEND_MAIL_MAILDIR_ENABLED', false); + +/** + * Zend_Mail_Transport_Smtp + * + * @todo TO be implemented + */ +defined('TESTS_ZEND_MAIL_SMTP_ENABLED') || define('TESTS_ZEND_MAIL_SMTP_ENABLED', false); +defined('TESTS_ZEND_MAIL_SMTP_HOST') || define('TESTS_ZEND_MAIL_SMTP_HOST', 'localhost'); +defined('TESTS_ZEND_MAIL_SMTP_PORT') || define('TESTS_ZEND_MAIL_SMTP_PORT', 25); +defined('TESTS_ZEND_MAIL_SMTP_USER') || define('TESTS_ZEND_MAIL_SMTP_USER', 'testuser'); +defined('TESTS_ZEND_MAIL_SMTP_PASSWORD') || define('TESTS_ZEND_MAIL_SMTP_PASSWORD', 'testpassword'); +defined('TESTS_ZEND_MAIL_SMTP_AUTH') || define('TESTS_ZEND_MAIL_SMTP_AUTH', false); +// AUTH can be set to false or a string of AUTH method (e.g. LOGIN, PLAIN, CRAMMD5 or DIGESTMD5) + +/** + * Zend_Queue Test Configuration constants + * + * The Zend_Queue_Adapter_Db constant should be a JSON-encoded string + * representing a configuration object for Zend_Db::factory(). For example: + * { + * type: "pdo_mysql", + * host: "127.0.0.1", + * port: 3306, + * username: "queue", + * password: "queue", + * dbname: "queue" + * } + * + * The PlatformJobQueue adapter expects two parameters, the host and password. + * The HOST string should include both the host and port (typically 10003): + * 127.0.0.1:10003 + * When running tests against PlatformJobQueue, it's best to do so where + * Platform is installed on localhost and has maximum workers set to 20 + * (default is 5); do so with this zend.ini setting: + * zend_jq.max_num_of_request_workers=20 + * + * Selectively define the below in order to run tests for them. + */ +defined('TESTS_ZEND_QUEUE_ACTIVEMQ_ENABLED') || define('TESTS_ZEND_QUEUE_ACTIVEMQ_ENABLED', false); +defined('TESTS_ZEND_QUEUE_ACTIVEMQ_SCHEME') || define('TESTS_ZEND_QUEUE_ACTIVEMQ_SCHEME', false); +defined('TESTS_ZEND_QUEUE_ACTIVEMQ_HOST') || define('TESTS_ZEND_QUEUE_ACTIVEMQ_HOST', false); +defined('TESTS_ZEND_QUEUE_ACTIVEMQ_PORT') || define('TESTS_ZEND_QUEUE_ACTIVEMQ_PORT', false); +defined('TESTS_ZEND_QUEUE_DB_ENABLED') || define('TESTS_ZEND_QUEUE_DB_ENABLED', false); +defined('TESTS_ZEND_QUEUE_DB') || define('TESTS_ZEND_QUEUE_DB', false); +defined('TESTS_ZEND_QUEUE_MEMCACHEQ_ENABLED') || define('TESTS_ZEND_QUEUE_MEMCACHEQ_ENABLED', false); +defined('TESTS_ZEND_QUEUE_MEMCACHEQ_HOST') || define('TESTS_ZEND_QUEUE_MEMCACHEQ_HOST', false); +defined('TESTS_ZEND_QUEUE_MEMCACHEQ_PORT') || define('TESTS_ZEND_QUEUE_MEMCACHEQ_PORT', false); +defined('TESTS_ZEND_QUEUE_PLATFORMJQ_ENABLED') || define('TESTS_ZEND_QUEUE_PLATFORMJQ_ENABLED', false); +defined('TESTS_ZEND_QUEUE_PLATFORMJQ_HOST') || define('TESTS_ZEND_QUEUE_PLATFORMJQ_HOST', false); +defined('TESTS_ZEND_QUEUE_PLATFORMJQ_PASS') || define('TESTS_ZEND_QUEUE_PLATFORMJQ_PASS', false); + + +/** + * Zend\Service\AgileZen online tests + */ +define('TESTS_ZEND_SERVICE_AGILEZEN_ONLINE_ENABLED',false); +define('TESTS_ZEND_SERVICE_AGILEZEN_ONLINE_APIKEY','insert the API key'); +define('TESTS_ZEND_SERVICE_AGILEZEN_ONLINE_PROJECT_ID','insert the project id'); +define('TESTS_ZEND_SERVICE_AGILEZEN_ONLINE_STORY_ID','insert the story id'); +define('TESTS_ZEND_SERVICE_AGILEZEN_ONLINE_INVITE_EMAIL','insert email for invitation'); +define('TESTS_ZEND_SERVICE_AGILEZEN_ONLINE_INVITE_ROLE_ID','insert role id for invitation'); +define('TESTS_ZEND_SERVICE_AGILEZEN_ONLINE_MEMBER_NAME','insert the member name to add to the project'); + + +/** + * Zend_Service_Amazon online tests + */ +defined('TESTS_ZEND_SERVICE_AMAZON_ONLINE_ENABLED') || define('TESTS_ZEND_SERVICE_AMAZON_ONLINE_ENABLED', false); +defined('TESTS_ZEND_SERVICE_AMAZON_ONLINE_ACCESSKEYID') || define('TESTS_ZEND_SERVICE_AMAZON_ONLINE_ACCESSKEYID', 'Enter AWSAccessKeyId here'); +defined('TESTS_ZEND_SERVICE_AMAZON_ONLINE_SECRETKEY') || define('TESTS_ZEND_SERVICE_AMAZON_ONLINE_SECRETKEY', 'Enter AWSSecretKey here'); +defined('TESTS_ZEND_SERVICE_AMAZON_EC2_IMAGE_ID') || define('TESTS_ZEND_SERVICE_AMAZON_EC2_IMAGE_ID', 'zftestamazonimageid'); +defined('TESTS_ZEND_SERVICE_AMAZON_EC2_ZONE') || define('TESTS_ZEND_SERVICE_AMAZON_EC2_ZONE', 'us-east-1'); +defined('TESTS_ZEND_SERVICE_AMAZON_EC2_SECURITY_GROUP') || define('TESTS_ZEND_SERVICE_AMAZON_EC2_SECURITY_GROUP', 'default'); +defined('TESTS_ZEND_SERVICE_AMAZON_S3_BUCKET') || define('TESTS_ZEND_SERVICE_AMAZON_S3_BUCKET', 'zftestamazons3bucket'); +defined('TESTS_ZEND_SERVICE_AMAZON_SQS_QUEUE') || define('TESTS_ZEND_SERVICE_AMAZON_SQS_QUEUE', 'zftestamazonsqsqueuename'); + +/** + * Zend_Service_Delicious tests + */ +defined('TESTS_ZEND_SERVICE_DELICIOUS_ENABLED') || define('TESTS_ZEND_SERVICE_DELICIOUS_ENABLED', false); + +/** + * Zend_Service_DeveloperGarden tests + * Setup your Username and Password to test this Service + */ +defined('TESTS_ZEND_SERVICE_DEVELOPERGARDEN_ONLINE_ENABLED') || define('TESTS_ZEND_SERVICE_DEVELOPERGARDEN_ONLINE_ENABLED', false); +defined('TESTS_ZEND_SERVICE_DEVELOPERGARDEN_ONLINE_LOGIN') || define('TESTS_ZEND_SERVICE_DEVELOPERGARDEN_ONLINE_LOGIN', 'ZF_Username'); +defined('TESTS_ZEND_SERVICE_DEVELOPERGARDEN_ONLINE_PASSWORD') || define('TESTS_ZEND_SERVICE_DEVELOPERGARDEN_ONLINE_PASSWORD', 'ZF_Password'); + +/** + * Zend_Service_Flickr online tests + */ +defined('TESTS_ZEND_SERVICE_FLICKR_ONLINE_ENABLED') || define('TESTS_ZEND_SERVICE_FLICKR_ONLINE_ENABLED', false); +defined('TESTS_ZEND_SERVICE_FLICKR_ONLINE_APIKEY') || define('TESTS_ZEND_SERVICE_FLICKR_ONLINE_APIKEY', 'Enter API key here'); + +/** + * Zend_Service_GoGrid offline tests + */ + +defined('TESTS_ZEND_SERVICE_GOGRID_ONLINE_ENABLED') || define('TESTS_ZEND_SERVICE_GOGRID_ONLINE_ENABLED', false); +defined('TESTS_ZEND_SERVICE_GOGRID_ONLINE_KEY') || define('TESTS_ZEND_SERVICE_GOGRID_ONLINE_KEY','insert key here'); +defined('TESTS_ZEND_SERVICE_GOGRID_ONLINE_SECRET') || define('TESTS_ZEND_SERVICE_GOGRID_ONLINE_SECRET','insert secret here'); +defined('TESTS_ZEND_SERVICE_GOGRID_ONLINE_SERVER_NAME') || define('TESTS_ZEND_SERVICE_GOGRID_ONLINE_SERVER_NAME','test-zf'); +defined('TESTS_ZEND_SERVICE_GOGRID_ONLINE_SERVER_IMAGE') || define('TESTS_ZEND_SERVICE_GOGRID_ONLINE_SERVER_IMAGE','insert image name here'); +defined('TESTS_ZEND_SERVICE_GOGRID_ONLINE_SERVER_RAM') || define('TESTS_ZEND_SERVICE_GOGRID_ONLINE_SERVER_RAM','insert ram name here'); +defined('TESTS_ZEND_SERVICE_GOGRID_ONLINE_SERVER_IP') || define('TESTS_ZEND_SERVICE_GOGRID_ONLINE_SERVER_IP','insert ip here'); + +/** + * Zend\Service\LiveDocx configuration + * + * Define username and password in order to run unit tests for LiveDocx web services. + * + * phpunit/phpunit will typically work. + */ +defined('TESTS_ZEND_SERVICE_LIVEDOCX_USERNAME') || define('TESTS_ZEND_SERVICE_LIVEDOCX_USERNAME', false); +defined('TESTS_ZEND_SERVICE_LIVEDOCX_PASSWORD') || define('TESTS_ZEND_SERVICE_LIVEDOCX_PASSWORD', false); + +/** + * Zend\Service\LiveDocx premium configuration + * + * Define username, password, WSDL in order to run unit tests for premium LiveDocx web services. + */ +defined('TESTS_ZEND_SERVICE_LIVEDOCX_PREMIUM_USERNAME') || define('TESTS_ZEND_SERVICE_LIVEDOCX_PREMIUM_USERNAME', false); +defined('TESTS_ZEND_SERVICE_LIVEDOCX_PREMIUM_PASSWORD') || define('TESTS_ZEND_SERVICE_LIVEDOCX_PREMIUM_PASSWORD', false); +defined('TESTS_ZEND_SERVICE_LIVEDOCX_PREMIUM_WSDL') || define('TESTS_ZEND_SERVICE_LIVEDOCX_PREMIUM_WSDL', false); + +/** + * Zend_Service_Rackspace tests + */ +defined('TESTS_ZEND_SERVICE_RACKSPACE_ONLINE_ENABLED') || define('TESTS_ZEND_SERVICE_RACKSPACE_ONLINE_ENABLED', false); +defined('TESTS_ZEND_SERVICE_RACKSPACE_ONLINE_USER') || define('TESTS_ZEND_SERVICE_RACKSPACE_ONLINE_USER', 'Enter key here'); +defined('TESTS_ZEND_SERVICE_RACKSPACE_ONLINE_KEY') || define('TESTS_ZEND_SERVICE_RACKSPACE_ONLINE_KEY', 'Enter secret here'); +defined('TESTS_ZEND_SERVICE_RACKSPACE_ONLINE_REGION') || define('TESTS_ZEND_SERVICE_RACKSPACE_ONLINE_REGION', 'USA'); +defined('TESTS_ZEND_SERVICE_RACKSPACE_CONTAINER_NAME') || define('TESTS_ZEND_SERVICE_RACKSPACE_CONTAINER_NAME', 'zf-unit-test'); +defined('TESTS_ZEND_SERVICE_RACKSPACE_OBJECT_NAME') || define('TESTS_ZEND_SERVICE_RACKSPACE_OBJECT_NAME','zf-object-test'); +defined('TESTS_ZEND_SERVICE_RACKSPACE_SERVER_NAME') || define('TESTS_ZEND_SERVICE_RACKSPACE_SERVER_NAME', 'zf-unit-test'); +defined('TESTS_ZEND_SERVICE_RACKSPACE_SERVER_IMAGEID') || define('TESTS_ZEND_SERVICE_RACKSPACE_SERVER_IMAGEID', '49'); +defined('TESTS_ZEND_SERVICE_RACKSPACE_SERVER_NEW_IMAGEID') || define('TESTS_ZEND_SERVICE_RACKSPACE_SERVER_NEW_IMAGEID', '49'); +defined('TESTS_ZEND_SERVICE_RACKSPACE_SERVER_FLAVORID') || define('TESTS_ZEND_SERVICE_RACKSPACE_SERVER_FLAVORID', '1'); +defined('TESTS_ZEND_SERVICE_RACKSPACE_SERVER_IMAGE_NAME') || define('TESTS_ZEND_SERVICE_RACKSPACE_SERVER_IMAGE_NAME', 'ZFunitTestImage'); +defined('TESTS_ZEND_SERVICE_RACKSPACE_SERVER_SHARED_IP_GROUP_NAME') || define('TESTS_ZEND_SERVICE_RACKSPACE_SERVER_SHARED_IP_GROUP_NAME', 'ZFgroupIP'); +defined('TESTS_ZEND_SERVICE_RACKSPACE_TIMEOUT') || define('TESTS_ZEND_SERVICE_RACKSPACE_TIMEOUT', 60); + +/** + * Zend_Service_ReCaptcha tests + */ +defined('TESTS_ZEND_SERVICE_RECAPTCHA_ENABLED') || define('TESTS_ZEND_SERVICE_RECAPTCHA_ENABLED', false); +defined('TESTS_ZEND_SERVICE_RECAPTCHA_ONLINE_ENABLED') || define('TESTS_ZEND_SERVICE_RECAPTCHA_ONLINE_ENABLED', false); +defined('TESTS_ZEND_SERVICE_RECAPTCHA_PUBLIC_KEY') || define('TESTS_ZEND_SERVICE_RECAPTCHA_PUBLIC_KEY', 'public key'); +defined('TESTS_ZEND_SERVICE_RECAPTCHA_PRIVATE_KEY') || define('TESTS_ZEND_SERVICE_RECAPTCHA_PRIVATE_KEY', 'private key'); +defined('TESTS_ZEND_SERVICE_RECAPTCHA_MAILHIDE_PUBLIC_KEY') || define('TESTS_ZEND_SERVICE_RECAPTCHA_MAILHIDE_PUBLIC_KEY', 'public mailhide key'); +defined('TESTS_ZEND_SERVICE_RECAPTCHA_MAILHIDE_PRIVATE_KEY') || define('TESTS_ZEND_SERVICE_RECAPTCHA_MAILHIDE_PRIVATE_KEY', 'private mailhide key'); + +/** + * Zend_Service_Simpy tests + */ +defined('TESTS_ZEND_SERVICE_SIMPY_ENABLED') || define('TESTS_ZEND_SERVICE_SIMPY_ENABLED', false); +defined('TESTS_ZEND_SERVICE_SIMPY_USERNAME') || define('TESTS_ZEND_SERVICE_SIMPY_USERNAME', 'syapizend'); +defined('TESTS_ZEND_SERVICE_SIMPY_PASSWORD') || define('TESTS_ZEND_SERVICE_SIMPY_PASSWORD', 'mgt37ge'); + +/** + * Zend_Service_SlideShare tests + */ +defined('TESTS_ZEND_SERVICE_SLIDESHARE_USERNAME') || define('TESTS_ZEND_SERVICE_SLIDESHARE_USERNAME', ''); +defined('TESTS_ZEND_SERVICE_SLIDESHARE_PASSWORD') || define('TESTS_ZEND_SERVICE_SLIDESHARE_PASSWORD', ''); +defined('TESTS_ZEND_SERVICE_SLIDESHARE_SHAREDSECRET') || define('TESTS_ZEND_SERVICE_SLIDESHARE_SHAREDSECRET', ''); +defined('TESTS_ZEND_SERVICE_SLIDESHARE_APIKEY') || define('TESTS_ZEND_SERVICE_SLIDESHARE_APIKEY', ''); + +// The slide show ID to retrieve during tests +defined('TESTS_ZEND_SERVICE_SLIDESHARE_SLIDESHOWID') || define('TESTS_ZEND_SERVICE_SLIDESHARE_SLIDESHOWID', 0); + +// The tag to retrieve during tests +defined('TESTS_ZEND_SERVICE_SLIDESHARE_TAG') || define('TESTS_ZEND_SERVICE_SLIDESHARE_TAG', 'zend'); + +// The group to retrieve during tests +defined('TESTS_ZEND_SERVICE_SLIDESHARE_GROUP') || define('TESTS_ZEND_SERVICE_SLIDESHARE_GROUP', ''); + +/** + * Zend_Service_Twitter tests + * + * ONLINE_ENABLED indicates whether or not to run tests requiring a network + * connection. + * + * TWITTER_USER and TWITTER_PASS are valid Twitter credentials you wish to use + * when testing. + */ +defined('TESTS_ZEND_SERVICE_TWITTER_ONLINE_ENABLED') || define('TESTS_ZEND_SERVICE_TWITTER_ONLINE_ENABLED', false); +defined('TESTS_ZEND_SERVICE_TWITTER_USER') || define('TESTS_ZEND_SERVICE_TWITTER_USER', 'zftestuser'); +defined('TESTS_ZEND_SERVICE_TWITTER_PASS') || define('TESTS_ZEND_SERVICE_TWITTER_PASS', 'zftestuser'); + +/** + * Zend_Service_WindowsAzure tests + */ + +/** + * Online + */ + +define('TESTS_ZEND_SERVICE_WINDOWSAZURE_ONLINE_ACCOUNTNAME',''); +define('TESTS_ZEND_SERVICE_WINDOWSAZURE_ONLINE_ACCOUNTKEY',''); +define('TESTS_ZEND_SERVICE_WINDOWSAZURE_ONLINE_TABLE_HOST',''); +define('TESTS_ZEND_SERVICE_WINDOWSAZURE_ONLINE_STORAGE_PROXY_HOST',''); +define('TESTS_ZEND_SERVICE_WINDOWSAZURE_ONLINE_STORAGE_PROXY_PORT',''); +define('TESTS_ZEND_SERVICE_WINDOWSAZURE_ONLINE_STORAGE_PROXY_CREDENTIALS',''); + +/** + * Proxy settings + */ +defined('TESTS_ZEND_SERVICE_WINDOWSAZURE_STORAGE_USEPROXY') || define('TESTS_ZEND_SERVICE_WINDOWSAZURE_STORAGE_USEPROXY', false); +defined('TESTS_ZEND_SERVICE_WINDOWSAZURE_STORAGE_PROXY') || define('TESTS_ZEND_SERVICE_WINDOWSAZURE_STORAGE_PROXY', ''); +defined('TESTS_ZEND_SERVICE_WINDOWSAZURE_STORAGE_PROXY_PORT') || define('TESTS_ZEND_SERVICE_WINDOWSAZURE_STORAGE_PROXY_PORT', '8080'); +defined('TESTS_ZEND_SERVICE_WINDOWSAZURE_STORAGE_PROXY_CREDENTIALS') || define('TESTS_ZEND_SERVICE_WINDOWSAZURE_STORAGE_PROXY_CREDENTIALS', ''); + +/** + * Azure hosts + */ +defined('TESTS_ZEND_SERVICE_WINDOWSAZURE_BLOB_HOST_DEV') || define('TESTS_ZEND_SERVICE_WINDOWSAZURE_BLOB_HOST_DEV', '127.0.0.1:10000'); +defined('TESTS_ZEND_SERVICE_WINDOWSAZURE_QUEUE_HOST_DEV') || define('TESTS_ZEND_SERVICE_WINDOWSAZURE_QUEUE_HOST_DEV', '127.0.0.1:10001'); +defined('TESTS_ZEND_SERVICE_WINDOWSAZURE_TABLE_HOST_DEV') || define('TESTS_ZEND_SERVICE_WINDOWSAZURE_TABLE_HOST_DEV', '127.0.0.1:10002'); +defined('TESTS_ZEND_SERVICE_WINDOWSAZURE_BLOB_HOST_PROD') || define('TESTS_ZEND_SERVICE_WINDOWSAZURE_BLOB_HOST_PROD', 'blob.core.windows.net'); +defined('TESTS_ZEND_SERVICE_WINDOWSAZURE_QUEUE_HOST_PROD') || define('TESTS_ZEND_SERVICE_WINDOWSAZURE_QUEUE_HOST_PROD', 'queue.core.windows.net'); +defined('TESTS_ZEND_SERVICE_WINDOWSAZURE_TABLE_HOST_PROD') || define('TESTS_ZEND_SERVICE_WINDOWSAZURE_TABLE_HOST_PROD', 'table.core.windows.net'); + +/** + * Credentials + */ +defined('TESTS_ZEND_SERVICE_WINDOWSAZURE_STORAGE_ACCOUNT_DEV') || define('TESTS_ZEND_SERVICE_WINDOWSAZURE_STORAGE_ACCOUNT_DEV', 'devstoreaccount1'); +defined('TESTS_ZEND_SERVICE_WINDOWSAZURE_STORAGE_KEY_DEV') || define('TESTS_ZEND_SERVICE_WINDOWSAZURE_STORAGE_KEY_DEV', 'Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw=='); +defined('TESTS_ZEND_SERVICE_WINDOWSAZURE_STORAGE_ACCOUNT_PROD') || define('TESTS_ZEND_SERVICE_WINDOWSAZURE_STORAGE_ACCOUNT_PROD', 'phpazure'); +defined('TESTS_ZEND_SERVICE_WINDOWSAZURE_STORAGE_KEY_PROD') || define('TESTS_ZEND_SERVICE_WINDOWSAZURE_STORAGE_KEY_PROD', 'I+ebYPcIDB6BsmfAe6pJSpOw8oXA6jMBZv1BEZcSPRqTpldt44refCl65YpKJqcBOiD21Lxsj8d6Ah8Oc2/gKA=='); + +/** + * Blob storage tests + */ +// Enable this tests only when you have a working account +defined('TESTS_ZEND_SERVICE_WINDOWSAZURE_BLOB_RUNTESTS') || define('TESTS_ZEND_SERVICE_WINDOWSAZURE_BLOB_RUNTESTS', false); +defined('TESTS_ZEND_SERVICE_WINDOWSAZURE_BLOB_RUNONPROD') || define('TESTS_ZEND_SERVICE_WINDOWSAZURE_BLOB_RUNONPROD', false); +defined('TESTS_ZEND_SERVICE_WINDOWSAZURE_BLOB_RUNLARGEBLOB') || define('TESTS_ZEND_SERVICE_WINDOWSAZURE_BLOB_RUNLARGEBLOB', true); +defined('TESTS_ZEND_SERVICE_WINDOWSAZURE_BLOB_CONTAINER_PREFIX') || define('TESTS_ZEND_SERVICE_WINDOWSAZURE_BLOB_CONTAINER_PREFIX', 'phpazuretestblob'); +defined('TESTS_ZEND_SERVICE_WINDOWSAZURE_BLOBSTREAM_CONTAINER_PREFIX') || define('TESTS_ZEND_SERVICE_WINDOWSAZURE_BLOBSTREAM_CONTAINER_PREFIX', 'phpazureteststream'); +defined('TESTS_ZEND_SERVICE_WINDOWSAZURE_BLOBSA_CONTAINER_PREFIX') || define('TESTS_ZEND_SERVICE_WINDOWSAZURE_BLOBSA_CONTAINER_PREFIX', 'phpazuretestshared'); + +/** + * Table storage tests + */ +// Enable this tests only when you have a working account +defined('TESTS_ZEND_SERVICE_WINDOWSAZURE_TABLE_RUNTESTS') || define('TESTS_ZEND_SERVICE_WINDOWSAZURE_TABLE_RUNTESTS', false); +defined('TESTS_ZEND_SERVICE_WINDOWSAZURE_TABLE_RUNONPROD') || define('TESTS_ZEND_SERVICE_WINDOWSAZURE_TABLE_RUNONPROD', false); +defined('TESTS_ZEND_SERVICE_WINDOWSAZURE_TABLE_TABLENAME_PREFIX') || define('TESTS_ZEND_SERVICE_WINDOWSAZURE_TABLE_TABLENAME_PREFIX', 'phpazuretesttable'); + +/** + * Queue storage tests + */ +defined('TESTS_ZEND_SERVICE_WINDOWSAZURE_QUEUE_RUNTESTS') || define('TESTS_ZEND_SERVICE_WINDOWSAZURE_QUEUE_RUNTESTS', false); +defined('TESTS_ZEND_SERVICE_WINDOWSAZURE_QUEUE_RUNONPROD') || define('TESTS_ZEND_SERVICE_WINDOWSAZURE_QUEUE_RUNONPROD', false); +defined('TESTS_ZEND_SERVICE_WINDOWSAZURE_QUEUE_PREFIX') || define('TESTS_ZEND_SERVICE_WINDOWSAZURE_QUEUE_PREFIX', 'phpazuretestqueue'); + +/** + * SessionHandler tests + */ +defined('TESTS_ZEND_SERVICE_WINDOWSAZURE_SESSIONHANDLER_RUNTESTS') || define('TESTS_ZEND_SERVICE_WINDOWSAZURE_SESSIONHANDLER_RUNTESTS', false); +defined('TESTS_ZEND_SERVICE_WINDOWSAZURE_SESSIONHANDLER_RUNONPROD') || define('TESTS_ZEND_SERVICE_WINDOWSAZURE_SESSIONHANDLER_RUNONPROD', false); +defined('TESTS_ZEND_SERVICE_WINDOWSAZURE_SESSIONHANDLER_TABLENAME_PREFIX') || define('TESTS_ZEND_SERVICE_WINDOWSAZURE_SESSIONHANDLER_TABLENAME_PREFIX', 'phpazuretestsession'); + +/** + * Zend_Service_Yahoo online tests + */ +defined('TESTS_ZEND_SERVICE_YAHOO_ONLINE_ENABLED') || define('TESTS_ZEND_SERVICE_YAHOO_ONLINE_ENABLED', false); +defined('TESTS_ZEND_SERVICE_YAHOO_ONLINE_APPID') || define('TESTS_ZEND_SERVICE_YAHOO_ONLINE_APPID', 'Enter APPID here'); + +/** + * Zend_Soap_AutoDiscover scenario tests for complex objects and wsdl generation + * + * Copy all the files of zf/tests/Zend/Soap/_files/fulltests into a directory + * that can be reached by webserver and enter the base uri to this directory + * into the variable. The test "Zend_Soap_AutoDiscover_OnlineTest" makes use + * of the servers and AutoDiscover feature. + * + * NOTE: Make sure the servers are using the correct Zend Framework copy, + * when having more than one version installed and include paths are changing. + */ +defined('TESTS_ZEND_SOAP_AUTODISCOVER_ONLINE_SERVER_BASEURI') || define('TESTS_ZEND_SOAP_AUTODISCOVER_ONLINE_SERVER_BASEURI', false); + +/** + * Zend_Uri tests + * + * Setting CRASH_TEST_ENABLED to true will enable some tests that may + * potentially crash PHP on some systems, due to very deep-nesting regular + * expressions. + * + * Only do this if you know what you are doing! + */ +defined('TESTS_ZEND_URI_CRASH_TEST_ENABLED') || define('TESTS_ZEND_URI_CRASH_TEST_ENABLED', false); + +/** + * Zend_Validate tests + * + * Set ONLINE_ENABLED if you wish to run validators that require network + * connectivity. + */ +defined('TESTS_ZEND_VALIDATE_ONLINE_ENABLED') || define('TESTS_ZEND_VALIDATE_ONLINE_ENABLED', false); + +/** + * PHPUnit Code Coverage / Test Report + */ +defined('TESTS_GENERATE_REPORT') || define('TESTS_GENERATE_REPORT', false); +defined('TESTS_GENERATE_REPORT_TARGET') || define('TESTS_GENERATE_REPORT_TARGET', '/path/to/target'); + From bca21b3d950bebb74f8cc1467ad4a02674e32dd5 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Wed, 4 Apr 2012 00:32:21 +0200 Subject: [PATCH 32/61] Making the run-tests.sh script executable --- .travis/run-tests.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 .travis/run-tests.sh diff --git a/.travis/run-tests.sh b/.travis/run-tests.sh old mode 100644 new mode 100755 From f0158df2673593b12e40b0a3f80b16cd4e09de48 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Wed, 4 Apr 2012 20:56:26 +0200 Subject: [PATCH 33/61] Moving travis test configuration This way it is more obvious to the committer changing test configuration that also travis config should be changed --- .travis/TestConfiguration.php | 825 ---------------------------------- 1 file changed, 825 deletions(-) delete mode 100644 .travis/TestConfiguration.php diff --git a/.travis/TestConfiguration.php b/.travis/TestConfiguration.php deleted file mode 100644 index fd89470..0000000 --- a/.travis/TestConfiguration.php +++ /dev/null @@ -1,825 +0,0 @@ - test disabling output buffering in - * dispatcher - */ -defined('TESTS_ZEND_CONTROLLER_DISPATCHER_OB') || define('TESTS_ZEND_CONTROLLER_DISPATCHER_OB', false); - -/** - * Zend_Crypt related constantes - * - * TESTS_ZEND_CRYPT_OPENSSL_CONF => location of an openssl.cnf file for use - * with RSA encryption - */ -defined('TESTS_ZEND_CRYPT_OPENSSL_CONF') || define('TESTS_ZEND_CRYPT_OPENSSL_CONF', false); - -/** - * Zend_Db_Adapter_Pdo_Mysql and Zend_Db_Adapter_Mysqli - * - * There are separate properties to enable tests for the PDO_MYSQL adapter and - * the native Mysqli adapters, but the other properties are shared between the - * two MySQL-related Zend_Db adapters. - */ -defined('TESTS_ZEND_DB_ADAPTER_PDO_MYSQL_ENABLED') || define('TESTS_ZEND_DB_ADAPTER_PDO_MYSQL_ENABLED', false); -defined('TESTS_ZEND_DB_ADAPTER_MYSQLI_ENABLED') || define('TESTS_ZEND_DB_ADAPTER_MYSQLI_ENABLED', false); -defined('TESTS_ZEND_DB_ADAPTER_MYSQL_HOSTNAME') || define('TESTS_ZEND_DB_ADAPTER_MYSQL_HOSTNAME', '127.0.0.1'); -defined('TESTS_ZEND_DB_ADAPTER_MYSQL_USERNAME') || define('TESTS_ZEND_DB_ADAPTER_MYSQL_USERNAME', null); -defined('TESTS_ZEND_DB_ADAPTER_MYSQL_PASSWORD') || define('TESTS_ZEND_DB_ADAPTER_MYSQL_PASSWORD', null); -defined('TESTS_ZEND_DB_ADAPTER_MYSQL_DATABASE') || define('TESTS_ZEND_DB_ADAPTER_MYSQL_DATABASE', 'test'); -defined('TESTS_ZEND_DB_ADAPTER_MYSQL_PORT') || define('TESTS_ZEND_DB_ADAPTER_MYSQL_PORT', 3306); - -/** - * Zend_Db_Adapter_Pdo_Sqlite - * - * Username and password are irrelevant for SQLite. - */ -defined('TESTS_ZEND_DB_ADAPTER_PDO_SQLITE_ENABLED') || define('TESTS_ZEND_DB_ADAPTER_PDO_SQLITE_ENABLED', false); -defined('TESTS_ZEND_DB_ADAPTER_PDO_SQLITE_DATABASE') || define('TESTS_ZEND_DB_ADAPTER_PDO_SQLITE_DATABASE', ':memory:'); - -/** - * Zend_Db_Adapter_Pdo_Mssql - * - * Note that you need to patch your ntwdblib.dll, the one that - * comes with PHP does not work. See user comments at - * http://us2.php.net/manual/en/ref.mssql.php - */ -defined('TESTS_ZEND_DB_ADAPTER_PDO_MSSQL_ENABLED') || define('TESTS_ZEND_DB_ADAPTER_PDO_MSSQL_ENABLED', false); -defined('TESTS_ZEND_DB_ADAPTER_PDO_MSSQL_HOSTNAME') || define('TESTS_ZEND_DB_ADAPTER_PDO_MSSQL_HOSTNAME', '127.0.0.1'); -defined('TESTS_ZEND_DB_ADAPTER_PDO_MSSQL_USERNAME') || define('TESTS_ZEND_DB_ADAPTER_PDO_MSSQL_USERNAME', null); -defined('TESTS_ZEND_DB_ADAPTER_PDO_MSSQL_PASSWORD') || define('TESTS_ZEND_DB_ADAPTER_PDO_MSSQL_PASSWORD', null); -defined('TESTS_ZEND_DB_ADAPTER_PDO_MSSQL_DATABASE') || define('TESTS_ZEND_DB_ADAPTER_PDO_MSSQL_DATABASE', 'test'); - -/** - * Zend_Db_Adapter_Pdo_Pgsql - */ -defined('TESTS_ZEND_DB_ADAPTER_PDO_PGSQL_ENABLED') || define('TESTS_ZEND_DB_ADAPTER_PDO_PGSQL_ENABLED', false); -defined('TESTS_ZEND_DB_ADAPTER_PDO_PGSQL_HOSTNAME') || define('TESTS_ZEND_DB_ADAPTER_PDO_PGSQL_HOSTNAME', '127.0.0.1'); -defined('TESTS_ZEND_DB_ADAPTER_PDO_PGSQL_USERNAME') || define('TESTS_ZEND_DB_ADAPTER_PDO_PGSQL_USERNAME', null); -defined('TESTS_ZEND_DB_ADAPTER_PDO_PGSQL_PASSWORD') || define('TESTS_ZEND_DB_ADAPTER_PDO_PGSQL_PASSWORD', null); -defined('TESTS_ZEND_DB_ADAPTER_PDO_PGSQL_DATABASE') || define('TESTS_ZEND_DB_ADAPTER_PDO_PGSQL_DATABASE', 'postgres'); - -/** - * Zend_Db_Adapter_Oracle and Zend_Db_Adapter_Pdo_Oci - * - * There are separate properties to enable tests for the PDO_OCI adapter and - * the native Oracle adapter, but the other properties are shared between the - * two Oracle-related Zend_Db adapters. - */ -defined('TESTS_ZEND_DB_ADAPTER_PDO_OCI_ENABLED') || define('TESTS_ZEND_DB_ADAPTER_PDO_OCI_ENABLED', false); -defined('TESTS_ZEND_DB_ADAPTER_ORACLE_ENABLED') || define('TESTS_ZEND_DB_ADAPTER_ORACLE_ENABLED', false); -defined('TESTS_ZEND_DB_ADAPTER_ORACLE_HOSTNAME') || define('TESTS_ZEND_DB_ADAPTER_ORACLE_HOSTNAME', '127.0.0.1'); -defined('TESTS_ZEND_DB_ADAPTER_ORACLE_USERNAME') || define('TESTS_ZEND_DB_ADAPTER_ORACLE_USERNAME', null); -defined('TESTS_ZEND_DB_ADAPTER_ORACLE_PASSWORD') || define('TESTS_ZEND_DB_ADAPTER_ORACLE_PASSWORD', null); -defined('TESTS_ZEND_DB_ADAPTER_ORACLE_SID') || define('TESTS_ZEND_DB_ADAPTER_ORACLE_SID', 'xe'); - -/** - * Zend_Db_Adapter_Db2 and Zend_Db_Adapter_Pdo_Ibm - * There are separate properties to enable tests for the PDO_IBM adapter and - * the native DB2 adapter, but the other properties are shared between the - * two related Zend_Db adapters. - */ -defined('TESTS_ZEND_DB_ADAPTER_PDO_IBM_ENABLED') || define('TESTS_ZEND_DB_ADAPTER_PDO_IBM_ENABLED', false); -defined('TESTS_ZEND_DB_ADAPTER_DB2_ENABLED') || define('TESTS_ZEND_DB_ADAPTER_DB2_ENABLED', false); -defined('TESTS_ZEND_DB_ADAPTER_DB2_HOSTNAME') || define('TESTS_ZEND_DB_ADAPTER_DB2_HOSTNAME', '127.0.0.1'); -defined('TESTS_ZEND_DB_ADAPTER_DB2_PORT') || define('TESTS_ZEND_DB_ADAPTER_DB2_PORT', 50000); -defined('TESTS_ZEND_DB_ADAPTER_DB2_USERNAME') || define('TESTS_ZEND_DB_ADAPTER_DB2_USERNAME', null); -defined('TESTS_ZEND_DB_ADAPTER_DB2_PASSWORD') || define('TESTS_ZEND_DB_ADAPTER_DB2_PASSWORD', null); -defined('TESTS_ZEND_DB_ADAPTER_DB2_DATABASE') || define('TESTS_ZEND_DB_ADAPTER_DB2_DATABASE', 'sample'); - -/** - * Zend_Db_Adapter_Sqlsrv - * Note: Make sure that you create the "test" database and set a - * username and password - * - */ -defined('TESTS_ZEND_DB_ADAPTER_SQLSRV_ENABLED') || define('TESTS_ZEND_DB_ADAPTER_SQLSRV_ENABLED', false); -defined('TESTS_ZEND_DB_ADAPTER_SQLSRV_HOSTNAME') || define('TESTS_ZEND_DB_ADAPTER_SQLSRV_HOSTNAME', 'localhost\SQLEXPRESS'); -defined('TESTS_ZEND_DB_ADAPTER_SQLSRV_USERNAME') || define('TESTS_ZEND_DB_ADAPTER_SQLSRV_USERNAME', null); -defined('TESTS_ZEND_DB_ADAPTER_SQLSRV_PASSWORD') || define('TESTS_ZEND_DB_ADAPTER_SQLSRV_PASSWORD', null); -defined('TESTS_ZEND_DB_ADAPTER_SQLSRV_DATABASE') || define('TESTS_ZEND_DB_ADAPTER_SQLSRV_DATABASE', 'test'); - -/** - * Zend_Feed_Reader tests - * - * If the ONLINE_ENABLED property is false, only tests that can be executed - * without network connectivity are run; when enabled, all tests will run. - */ -defined('TESTS_ZEND_FEED_READER_ONLINE_ENABLED') || define('TESTS_ZEND_FEED_READER_ONLINE_ENABLED', false); - -/** - * Zend_Gdata tests - * - * If the ONLINE_ENABLED property is false, only tests that can be executed with - * a mock HTTP client are run. No request is sent to the Google Gdata servers. - * If ONLINE_ENABLED is true, some tests may make requests to the remote - * servers. This does not work if you are running tests on a disconnected - * client host. Also, the tests may show as failures if the Google servers - * cannot be reached or if they do not respond for another reason. - * - * If the CLIENTLOGIN_ENABLED property below is false, the authenticated - * tests are reported Skipped in the test run. Set this property to true - * to enable tests that require ClientLogin authentication. Enter your - * Google login credentials in the EMAIL and PASSWORD properties below. - * - * Edit TestConfiguration.php, not TestConfiguration.php.dist. - * Never commit plaintext passwords to the source code repository. - * - * Note: the GData tests currently require that the TZID env variable - * be set or the timezone otherwise configured. You'll see errors from the - * tests if this is not the case. - */ -defined('TESTS_ZEND_GDATA_ONLINE_ENABLED') || define('TESTS_ZEND_GDATA_ONLINE_ENABLED', false); -defined('TESTS_ZEND_GDATA_CLIENTLOGIN_ENABLED') || define('TESTS_ZEND_GDATA_CLIENTLOGIN_ENABLED', false); - -/* - * The credentials provided here should be only for a TEST account. - * Data for various services in this account may be added to, updated, - * or deleted based upon the actions of these test accounts. - */ -defined('TESTS_ZEND_GDATA_CLIENTLOGIN_EMAIL') || define('TESTS_ZEND_GDATA_CLIENTLOGIN_EMAIL', 'example@example.com'); -defined('TESTS_ZEND_GDATA_CLIENTLOGIN_PASSWORD') || define('TESTS_ZEND_GDATA_CLIENTLOGIN_PASSWORD', 'password'); - -/* - * This is the ID of a blank blog. There is no need to have - * any content in this blog. Also, blogs can only be used - * several times for the purpose of these test cases before - * they must be deleted and recreated. Otherwise, the tests - * will start failing, as posts to Blogger will return a 201 Created - * response even though the entry was not posted to the blog. - * This problem is being investigated. - */ -defined('TESTS_ZEND_GDATA_BLOGGER_ONLINE_ENABLED') || define('TESTS_ZEND_GDATA_BLOGGER_ONLINE_ENABLED', false); -defined('TESTS_ZEND_GDATA_BLOG_ID') || define('TESTS_ZEND_GDATA_BLOG_ID', '1111111111111111111'); - -/* - * This is the key for a spreadsheet with data only in the first row of - * the spreadsheet. The strings 'a1', 'b1', 'c1', 'd1' should be in the - * corresponding cell locations. - */ -defined('TESTS_ZEND_GDATA_SPREADSHEETS_ONLINE_ENABLED') || define('TESTS_ZEND_GDATA_SPREADSHEETS_ONLINE_ENABLED', false); -defined('TESTS_ZEND_GDATA_SPREADSHEETS_SPREADSHEETKEY') || define('TESTS_ZEND_GDATA_SPREADSHEETS_SPREADSHEETKEY', 'o01111111111111111111.1111111111111111111'); -defined('TESTS_ZEND_GDATA_SPREADSHEETS_WORKSHEETID') || define('TESTS_ZEND_GDATA_SPREADSHEETS_WORKSHEETID', 'default'); - -/* - * This indicates that online tests for the Google Calendar API should - * be performed. The default calendar will be used. - */ -defined('TESTS_ZEND_GDATA_CALENDAR_ONLINE_ENABLED') || define('TESTS_ZEND_GDATA_CALENDAR_ONLINE_ENABLED', false); - -/* - * This is the fully-qualified domain name for a domiain hosted using - * Google Apps. This domain must be registered with Google Apps and - * have API access enabled. This should be a TEST domain only. - */ -defined('TESTS_ZEND_GDATA_GAPPS_ONLINE_ENABLED') || define('TESTS_ZEND_GDATA_GAPPS_ONLINE_ENABLED', false); -defined('TESTS_ZEND_GDATA_GAPPS_DOMAIN') || define('TESTS_ZEND_GDATA_GAPPS_DOMAIN', 'example.com.invalid'); -defined('TESTS_ZEND_GDATA_GAPPS_EMAIL') || define('TESTS_ZEND_GDATA_GAPPS_EMAIL', 'example@example.com'); -defined('TESTS_ZEND_GDATA_GAPPS_PASSWORD') || define('TESTS_ZEND_GDATA_GAPPS_PASSWORD', 'password'); - -/* - * This is the ONLINE_ENABLED property for Google Base. - */ -defined('TESTS_ZEND_GDATA_GBASE_ONLINE_ENABLED') || define('TESTS_ZEND_GDATA_GBASE_ONLINE_ENABLED', false); - -/* - * This indicates that online tests for the Books Search data API - * should be performed. - */ -defined('TESTS_ZEND_GDATA_BOOKS_ONLINE_ENABLED') || define('TESTS_ZEND_GDATA_BOOKS_ONLINE_ENABLED', false); - -/* - * This indicates that online tests for the YouTube data API should - * be performed. - */ -defined('TESTS_ZEND_GDATA_YOUTUBE_ONLINE_ENABLED') || define('TESTS_ZEND_GDATA_YOUTUBE_ONLINE_ENABLED', false); - -/* - * This is the username to use for retrieving subscriptions, etc - */ -defined('TESTS_ZEND_GDATA_YOUTUBE_ACCOUNT') || define('TESTS_ZEND_GDATA_YOUTUBE_ACCOUNT', 'zfgdata'); - -/* - * This is the developer key to access the YouTube API - */ -defined('TESTS_ZEND_GDATA_YOUTUBE_DEVELOPER_KEY') || define('TESTS_ZEND_GDATA_YOUTUBE_DEVELOPER_KEY', 'your_developer_key_here'); - -/* - * This is the client ID to access the YouTube API - */ -defined('TESTS_ZEND_GDATA_YOUTUBE_CLIENT_ID') || define('TESTS_ZEND_GDATA_YOUTUBE_CLIENT_ID', 'ZF_UnitTests_unknown'); - -/* - * This indicates that online tests for the Google Documents API should - * be performed. - */ -defined('TESTS_ZEND_GDATA_DOCS_ONLINE_ENABLED') || define('TESTS_ZEND_GDATA_DOCS_ONLINE_ENABLED', false); - -/* - * This indicates that online tests for the GData Photos API should - * be performed. - */ -defined('TESTS_ZEND_GDATA_PHOTOS_ONLINE_ENABLED') || define('TESTS_ZEND_GDATA_PHOTOS_ONLINE_ENABLED', false); - -/* - * This indicates that online tests for the Google Health API should - * be performed. - */ -defined('TESTS_ZEND_GDATA_HEALTH_ONLINE_ENABLED') || define('TESTS_ZEND_GDATA_HEALTH_ONLINE_ENABLED', false); - -/** - * Zend_Http_Client tests - * - * To enable the dynamic Zend_Http_Client tests, you will need to symbolically - * link or copy the files in tests/Zend/Http/Client/_files to a directory - * under your web server(s) document root and set this constant to point to the - * URL of this directory. - */ -defined('TESTS_ZEND_HTTP_CLIENT_BASEURI') || define('TESTS_ZEND_HTTP_CLIENT_BASEURI', false); - -/** - * Zend_Http_Client_Proxy tests - * - * HTTP proxy to be used for testing the Proxy adapter. Set to a string of - * the form 'host:port'. Set to null to skip HTTP proxy tests. - */ -defined('TESTS_ZEND_HTTP_CLIENT_HTTP_PROXY') || define('TESTS_ZEND_HTTP_CLIENT_HTTP_PROXY', false); -defined('TESTS_ZEND_HTTP_CLIENT_HTTP_PROXY_USER') || define('TESTS_ZEND_HTTP_CLIENT_HTTP_PROXY_USER', ''); -defined('TESTS_ZEND_HTTP_CLIENT_HTTP_PROXY_PASS') || define('TESTS_ZEND_HTTP_CLIENT_HTTP_PROXY_PASS', ''); - -/** - * Zend_Loader_Autoloader multi-version support tests - * - * ENABLED: whether or not to run the multi-version tests - * PATH: path to a directory containing multiple ZF version installs - * LATEST: most recent ZF version in the PATH - * e.g., "1.9.2" - * LATEST_MAJOR: most recent ZF major version in the PATH to test against - * e.g., "1.9.2" - * LATEST_MINOR: most recent ZF minor version in the PATH to test against - * e.g., "1.8.4PL1" - * SPECIFIC: specific ZF version in the PATH to test against - * e.g., "1.7.6" - * As an example, consider the following tree: - * ZendFramework/ - * |-- 1.9.2 - * |-- ZendFramework-1.9.1-minimal - * |-- 1.8.4PL1 - * |-- 1.8.4 - * |-- ZendFramework-1.8.3 - * |-- 1.7.8 - * |-- 1.7.7 - * |-- 1.7.6 - * You would then set the value of "LATEST" and "LATEST_MAJOR" to "1.9.2", and - * could choose between "1.9.2", "1.8.4PL1", and "1.7.8" for "LATEST_MINOR", - * and any version number for "SPECIFIC". "PATH" would point to the parent - * "ZendFramework" directory. - */ -defined('TESTS_ZEND_LOADER_AUTOLOADER_MULTIVERSION_ENABLED') || define('TESTS_ZEND_LOADER_AUTOLOADER_MULTIVERSION_ENABLED', false); -defined('TESTS_ZEND_LOADER_AUTOLOADER_MULTIVERSION_PATH') || define('TESTS_ZEND_LOADER_AUTOLOADER_MULTIVERSION_PATH', false); -defined('TESTS_ZEND_LOADER_AUTOLOADER_MULTIVERSION_LATEST') || define('TESTS_ZEND_LOADER_AUTOLOADER_MULTIVERSION_LATEST', false); -defined('TESTS_ZEND_LOADER_AUTOLOADER_MULTIVERSION_LATEST_MAJOR') || define('TESTS_ZEND_LOADER_AUTOLOADER_MULTIVERSION_LATEST_MAJOR', false); -defined('TESTS_ZEND_LOADER_AUTOLOADER_MULTIVERSION_LATEST_MINOR') || define('TESTS_ZEND_LOADER_AUTOLOADER_MULTIVERSION_LATEST_MINOR', false); -defined('TESTS_ZEND_LOADER_AUTOLOADER_MULTIVERSION_SPECIFIC') || define('TESTS_ZEND_LOADER_AUTOLOADER_MULTIVERSION_SPECIFIC', false); - -/** - * Zend_Ldap online tests - */ -defined('TESTS_ZEND_LDAP_ONLINE_ENABLED') || define('TESTS_ZEND_LDAP_ONLINE_ENABLED', false); - -/* These largely map to the options described in the Zend_Ldap and - * Zend_Auth_Adapter_Ldap documentation. - * - * Example Configuration for Active Directory: - * HOST: dc1.w.net - * USE_START_TLS: true - * USE_SSL: false - * USERNAME: CN=User 1,CN=Users,DC=w,DC=net - * PRINCIPAL_NAME: user1@w.net - * LDAP_PASSWORD: pass1 - * BASE_DN: CN=Users,DC=w,DC=net - * DOMAIN_NAME: w.net - * ACCOUNT_DOMAIN_NAME_SHORT: W - * ALT_USERNAME: user2 - * ALT_DN: CN=User 2,CN=Users,DC=w,DC=net - * ALT_PASSWORD: pass2 - * - * Example Configuration for OpenLDAP - * HOST: s0.foo.net - * USERNAME: CN=user1,DC=foo,DC=net - * PRINCIPAL_NAME: user1@foo.net - * LDAP_PASSWORD: pass1 - * BIND_REQUIRES_DN: true - * BASE_DN: OU=Sales,DC=w,DC=net - * DOMAIN_NAME: foo.net - * ACCOUNT_DOMAIN_NAME_SHORT: FOO - * ALT_USERNAME: abaker - * ALT_DN: CN=Alice Baker,OU=Sales,DC=foo,DC=net - * ALT_PASSWORD: apass - */ -defined('TESTS_ZEND_LDAP_HOST') || define('TESTS_ZEND_LDAP_HOST', 'localhost'); -//defined('TESTS_ZEND_LDAP_PORT') || define('TESTS_ZEND_LDAP_PORT', 389); -defined('TESTS_ZEND_LDAP_USE_START_TLS') || define('TESTS_ZEND_LDAP_USE_START_TLS', true); -//defined('TESTS_ZEND_LDAP_USE_SSL') || define('TESTS_ZEND_LDAP_USE_SSL', false); -defined('TESTS_ZEND_LDAP_USERNAME') || define('TESTS_ZEND_LDAP_USERNAME', 'CN=someUser,DC=example,DC=com'); -defined('TESTS_ZEND_LDAP_PRINCIPAL_NAME') || define('TESTS_ZEND_LDAP_PRINCIPAL_NAME', 'someUser@example.com'); -defined('TESTS_ZEND_LDAP_PASSWORD') || define('TESTS_ZEND_LDAP_PASSWORD', null); -defined('TESTS_ZEND_LDAP_BIND_REQUIRES_DN') || define('TESTS_ZEND_LDAP_BIND_REQUIRES_DN', true); -defined('TESTS_ZEND_LDAP_BASE_DN') || define('TESTS_ZEND_LDAP_BASE_DN', 'OU=Sales,DC=example,DC=com'); -//defined('TESTS_ZEND_LDAP_ACCOUNT_FILTER_FORMAT') || define('TESTS_ZEND_LDAP_ACCOUNT_FILTER_FORMAT', '(&(objectClass=posixAccount)(uid=%s))'); -defined('TESTS_ZEND_LDAP_ACCOUNT_DOMAIN_NAME') || define('TESTS_ZEND_LDAP_ACCOUNT_DOMAIN_NAME', 'example.com'); -defined('TESTS_ZEND_LDAP_ACCOUNT_DOMAIN_NAME_SHORT') || define('TESTS_ZEND_LDAP_ACCOUNT_DOMAIN_NAME_SHORT', 'EXAMPLE'); -defined('TESTS_ZEND_LDAP_ALT_USERNAME') || define('TESTS_ZEND_LDAP_ALT_USERNAME', 'anotherUser'); -defined('TESTS_ZEND_LDAP_ALT_DN') || define('TESTS_ZEND_LDAP_ALT_DN', 'CN=Another User,OU=Sales,DC=example,DC=com'); -defined('TESTS_ZEND_LDAP_ALT_PASSWORD') || define('TESTS_ZEND_LDAP_ALT_PASSWORD', null); // Used in Zend_Auth_Adapter_Ldap tests -//(defined('TESTS_ZEND_LDAP_WRITEABLE_SUBTREE') || define('TESTS_ZEND_LDAP_WRITEABLE_SUBTREE', 'OU=Test,OU=Sales,DC=example,DC=com'); - -/** - * Zend_Locale tests - * - * If the TESTS_ZEND_LOCALE_FORMAT_SETLOCALE property below is a valid, - * locally recognized locale (try "locale -a"), then all tests in - * tests/Zend/Locale/ test suites will execute *after* - * setlocale(LC_ALL, TESTS_ZEND_LOCALE_FORMAT_SETLOCALE); - * Primarily, this switches certain PHP functions to emit "localized" output, - * including the built-in "to string" for integer and float conversions. - * Thus, a locale of 'fr_FR' yields number-to-string conversions in a - * localized form with the decimal place separator chosen via: - * setlocale(LC_ALL, 'fr_FR@euro'); - */ -//define('TESTS_ZEND_LOCALE_FORMAT_SETLOCALE', 'fr'); -//define('TESTS_ZEND_LOCALE_FORMAT_SETLOCALE', 'fr_FR@euro'); -defined('TESTS_ZEND_LOCALE_FORMAT_SETLOCALE') || define('TESTS_ZEND_LOCALE_FORMAT_SETLOCALE', false); - -/** - * Zend_Date tests - * - * If the BCMATH_ENABLED property below is false, all arithmetic - * operations will use ordinary PHP math operators and functions. - * Otherwise, the bcmath functions will be used for unlimited precision. - * - * If the EXTENDED_COVERAGE property below is false, most of the I18N - * unit tests will not be computed... this speeds tests up to 80 minutes - * when doing reports. * - * Edit TestConfiguration.php, not TestConfiguration.php.dist. - */ -defined('TESTS_ZEND_LOCALE_BCMATH_ENABLED') || define('TESTS_ZEND_LOCALE_BCMATH_ENABLED', true); -defined('TESTS_ZEND_I18N_EXTENDED_COVERAGE') || define('TESTS_ZEND_I18N_EXTENDED_COVERAGE', true); - -/** - * Zend_Mail_Storage tests - * - * TESTS_ZEND_MAIL_SERVER_TESTDIR and TESTS_ZEND_MAIL_SERVER_FORMAT are used for POP3 and IMAP tests. - * TESTS_ZEND_MAIL_SERVER_FORMAT is the format your test mail server uses: 'mbox' or 'maildir'. The mail - * storage for the user specified in your POP3 or IMAP tests should be TESTS_ZEND_MAIL_SERVER_TESTDIR. Be - * careful: it's cleared before copying the files. If you want to copy the files manually set the dir - * to null (or anything == null). - * - * TESTS_ZEND_MAIL_TEMPDIR is used for testing write operations in local storages. If not set (== null) - * tempnam() is used. - */ -defined('TESTS_ZEND_MAIL_SERVER_TESTDIR') || define('TESTS_ZEND_MAIL_SERVER_TESTDIR', null); -defined('TESTS_ZEND_MAIL_SERVER_FORMAT') || define('TESTS_ZEND_MAIL_SERVER_FORMAT', 'mbox'); -defined('TESTS_ZEND_MAIL_TEMPDIR') || define('TESTS_ZEND_MAIL_TEMPDIR', null); - -/** - * Zend_Mail_Storage_Pop3 / Zend_Mail_Transport_Pop3 - * - * IMPORTANT: you need to copy tests/Zend/Mail/_files/test.mbox to your mail - * if you haven't set TESTS_ZEND_MAIL_SERVER_TESTDIR - */ -defined('TESTS_ZEND_MAIL_POP3_ENABLED') || define('TESTS_ZEND_MAIL_POP3_ENABLED', false); -defined('TESTS_ZEND_MAIL_POP3_HOST') || define('TESTS_ZEND_MAIL_POP3_HOST', 'localhost'); -defined('TESTS_ZEND_MAIL_POP3_USER') || define('TESTS_ZEND_MAIL_POP3_USER', 'test'); -defined('TESTS_ZEND_MAIL_POP3_PASSWORD') || define('TESTS_ZEND_MAIL_POP3_PASSWORD', ''); -// test SSL connections if enabled in your test server -defined('TESTS_ZEND_MAIL_POP3_SSL') || define('TESTS_ZEND_MAIL_POP3_SSL', true); -defined('TESTS_ZEND_MAIL_POP3_TLS') || define('TESTS_ZEND_MAIL_POP3_TLS', true); -// WRONG_PORT should be an existing server port, -// INVALID_PORT should be a non existing (each on defined host) -defined('TESTS_ZEND_MAIL_POP3_WRONG_PORT') || define('TESTS_ZEND_MAIL_POP3_WRONG_PORT', 80); -defined('TESTS_ZEND_MAIL_POP3_INVALID_PORT') || define('TESTS_ZEND_MAIL_POP3_INVALID_PORT', 3141); - -/** - * Zend_Mail_Storage_Imap / Zend_Mail_Transport_Imap - * - * IMPORTANT: you need to copy tests/Zend/Mail/_files/test.mbox to your mail - * if you haven't set TESTS_ZEND_MAIL_SERVER_TESTDIR - */ -defined('TESTS_ZEND_MAIL_IMAP_ENABLED') || define('TESTS_ZEND_MAIL_IMAP_ENABLED', false); -defined('TESTS_ZEND_MAIL_IMAP_HOST') || define('TESTS_ZEND_MAIL_IMAP_HOST', 'localhost'); -defined('TESTS_ZEND_MAIL_IMAP_USER') || define('TESTS_ZEND_MAIL_IMAP_USER', 'test'); -defined('TESTS_ZEND_MAIL_IMAP_PASSWORD') || define('TESTS_ZEND_MAIL_IMAP_PASSWORD', ''); -// test SSL connections if enabled in your test server -defined('TESTS_ZEND_MAIL_IMAP_SSL') || define('TESTS_ZEND_MAIL_IMAP_SSL', true); -defined('TESTS_ZEND_MAIL_IMAP_TLS') || define('TESTS_ZEND_MAIL_IMAP_TLS', true); -// WRONG_PORT should be an existing server port, -// INVALID_PORT should be a non-existing (each on defined host) -defined('TESTS_ZEND_MAIL_IMAP_WRONG_PORT') || define('TESTS_ZEND_MAIL_IMAP_WRONG_PORT', 80); -defined('TESTS_ZEND_MAIL_IMAP_INVALID_PORT') || define('TESTS_ZEND_MAIL_IMAP_INVALID_PORT', 3141); - - -/** - * Zend_Mail_Storage_Maildir test - * - * Before enabling this test you have to unpack messages.tar in - * Zend/Mail/_files/test.maildir/cur/ and remove the tar for this test to work. - * That's because the messages files have a colon in the filename and that's a - * forbidden character on Windows. - */ -defined('TESTS_ZEND_MAIL_MAILDIR_ENABLED') || define('TESTS_ZEND_MAIL_MAILDIR_ENABLED', false); - -/** - * Zend_Mail_Transport_Smtp - * - * @todo TO be implemented - */ -defined('TESTS_ZEND_MAIL_SMTP_ENABLED') || define('TESTS_ZEND_MAIL_SMTP_ENABLED', false); -defined('TESTS_ZEND_MAIL_SMTP_HOST') || define('TESTS_ZEND_MAIL_SMTP_HOST', 'localhost'); -defined('TESTS_ZEND_MAIL_SMTP_PORT') || define('TESTS_ZEND_MAIL_SMTP_PORT', 25); -defined('TESTS_ZEND_MAIL_SMTP_USER') || define('TESTS_ZEND_MAIL_SMTP_USER', 'testuser'); -defined('TESTS_ZEND_MAIL_SMTP_PASSWORD') || define('TESTS_ZEND_MAIL_SMTP_PASSWORD', 'testpassword'); -defined('TESTS_ZEND_MAIL_SMTP_AUTH') || define('TESTS_ZEND_MAIL_SMTP_AUTH', false); -// AUTH can be set to false or a string of AUTH method (e.g. LOGIN, PLAIN, CRAMMD5 or DIGESTMD5) - -/** - * Zend_Queue Test Configuration constants - * - * The Zend_Queue_Adapter_Db constant should be a JSON-encoded string - * representing a configuration object for Zend_Db::factory(). For example: - * { - * type: "pdo_mysql", - * host: "127.0.0.1", - * port: 3306, - * username: "queue", - * password: "queue", - * dbname: "queue" - * } - * - * The PlatformJobQueue adapter expects two parameters, the host and password. - * The HOST string should include both the host and port (typically 10003): - * 127.0.0.1:10003 - * When running tests against PlatformJobQueue, it's best to do so where - * Platform is installed on localhost and has maximum workers set to 20 - * (default is 5); do so with this zend.ini setting: - * zend_jq.max_num_of_request_workers=20 - * - * Selectively define the below in order to run tests for them. - */ -defined('TESTS_ZEND_QUEUE_ACTIVEMQ_ENABLED') || define('TESTS_ZEND_QUEUE_ACTIVEMQ_ENABLED', false); -defined('TESTS_ZEND_QUEUE_ACTIVEMQ_SCHEME') || define('TESTS_ZEND_QUEUE_ACTIVEMQ_SCHEME', false); -defined('TESTS_ZEND_QUEUE_ACTIVEMQ_HOST') || define('TESTS_ZEND_QUEUE_ACTIVEMQ_HOST', false); -defined('TESTS_ZEND_QUEUE_ACTIVEMQ_PORT') || define('TESTS_ZEND_QUEUE_ACTIVEMQ_PORT', false); -defined('TESTS_ZEND_QUEUE_DB_ENABLED') || define('TESTS_ZEND_QUEUE_DB_ENABLED', false); -defined('TESTS_ZEND_QUEUE_DB') || define('TESTS_ZEND_QUEUE_DB', false); -defined('TESTS_ZEND_QUEUE_MEMCACHEQ_ENABLED') || define('TESTS_ZEND_QUEUE_MEMCACHEQ_ENABLED', false); -defined('TESTS_ZEND_QUEUE_MEMCACHEQ_HOST') || define('TESTS_ZEND_QUEUE_MEMCACHEQ_HOST', false); -defined('TESTS_ZEND_QUEUE_MEMCACHEQ_PORT') || define('TESTS_ZEND_QUEUE_MEMCACHEQ_PORT', false); -defined('TESTS_ZEND_QUEUE_PLATFORMJQ_ENABLED') || define('TESTS_ZEND_QUEUE_PLATFORMJQ_ENABLED', false); -defined('TESTS_ZEND_QUEUE_PLATFORMJQ_HOST') || define('TESTS_ZEND_QUEUE_PLATFORMJQ_HOST', false); -defined('TESTS_ZEND_QUEUE_PLATFORMJQ_PASS') || define('TESTS_ZEND_QUEUE_PLATFORMJQ_PASS', false); - - -/** - * Zend\Service\AgileZen online tests - */ -define('TESTS_ZEND_SERVICE_AGILEZEN_ONLINE_ENABLED',false); -define('TESTS_ZEND_SERVICE_AGILEZEN_ONLINE_APIKEY','insert the API key'); -define('TESTS_ZEND_SERVICE_AGILEZEN_ONLINE_PROJECT_ID','insert the project id'); -define('TESTS_ZEND_SERVICE_AGILEZEN_ONLINE_STORY_ID','insert the story id'); -define('TESTS_ZEND_SERVICE_AGILEZEN_ONLINE_INVITE_EMAIL','insert email for invitation'); -define('TESTS_ZEND_SERVICE_AGILEZEN_ONLINE_INVITE_ROLE_ID','insert role id for invitation'); -define('TESTS_ZEND_SERVICE_AGILEZEN_ONLINE_MEMBER_NAME','insert the member name to add to the project'); - - -/** - * Zend_Service_Amazon online tests - */ -defined('TESTS_ZEND_SERVICE_AMAZON_ONLINE_ENABLED') || define('TESTS_ZEND_SERVICE_AMAZON_ONLINE_ENABLED', false); -defined('TESTS_ZEND_SERVICE_AMAZON_ONLINE_ACCESSKEYID') || define('TESTS_ZEND_SERVICE_AMAZON_ONLINE_ACCESSKEYID', 'Enter AWSAccessKeyId here'); -defined('TESTS_ZEND_SERVICE_AMAZON_ONLINE_SECRETKEY') || define('TESTS_ZEND_SERVICE_AMAZON_ONLINE_SECRETKEY', 'Enter AWSSecretKey here'); -defined('TESTS_ZEND_SERVICE_AMAZON_EC2_IMAGE_ID') || define('TESTS_ZEND_SERVICE_AMAZON_EC2_IMAGE_ID', 'zftestamazonimageid'); -defined('TESTS_ZEND_SERVICE_AMAZON_EC2_ZONE') || define('TESTS_ZEND_SERVICE_AMAZON_EC2_ZONE', 'us-east-1'); -defined('TESTS_ZEND_SERVICE_AMAZON_EC2_SECURITY_GROUP') || define('TESTS_ZEND_SERVICE_AMAZON_EC2_SECURITY_GROUP', 'default'); -defined('TESTS_ZEND_SERVICE_AMAZON_S3_BUCKET') || define('TESTS_ZEND_SERVICE_AMAZON_S3_BUCKET', 'zftestamazons3bucket'); -defined('TESTS_ZEND_SERVICE_AMAZON_SQS_QUEUE') || define('TESTS_ZEND_SERVICE_AMAZON_SQS_QUEUE', 'zftestamazonsqsqueuename'); - -/** - * Zend_Service_Delicious tests - */ -defined('TESTS_ZEND_SERVICE_DELICIOUS_ENABLED') || define('TESTS_ZEND_SERVICE_DELICIOUS_ENABLED', false); - -/** - * Zend_Service_DeveloperGarden tests - * Setup your Username and Password to test this Service - */ -defined('TESTS_ZEND_SERVICE_DEVELOPERGARDEN_ONLINE_ENABLED') || define('TESTS_ZEND_SERVICE_DEVELOPERGARDEN_ONLINE_ENABLED', false); -defined('TESTS_ZEND_SERVICE_DEVELOPERGARDEN_ONLINE_LOGIN') || define('TESTS_ZEND_SERVICE_DEVELOPERGARDEN_ONLINE_LOGIN', 'ZF_Username'); -defined('TESTS_ZEND_SERVICE_DEVELOPERGARDEN_ONLINE_PASSWORD') || define('TESTS_ZEND_SERVICE_DEVELOPERGARDEN_ONLINE_PASSWORD', 'ZF_Password'); - -/** - * Zend_Service_Flickr online tests - */ -defined('TESTS_ZEND_SERVICE_FLICKR_ONLINE_ENABLED') || define('TESTS_ZEND_SERVICE_FLICKR_ONLINE_ENABLED', false); -defined('TESTS_ZEND_SERVICE_FLICKR_ONLINE_APIKEY') || define('TESTS_ZEND_SERVICE_FLICKR_ONLINE_APIKEY', 'Enter API key here'); - -/** - * Zend_Service_GoGrid offline tests - */ - -defined('TESTS_ZEND_SERVICE_GOGRID_ONLINE_ENABLED') || define('TESTS_ZEND_SERVICE_GOGRID_ONLINE_ENABLED', false); -defined('TESTS_ZEND_SERVICE_GOGRID_ONLINE_KEY') || define('TESTS_ZEND_SERVICE_GOGRID_ONLINE_KEY','insert key here'); -defined('TESTS_ZEND_SERVICE_GOGRID_ONLINE_SECRET') || define('TESTS_ZEND_SERVICE_GOGRID_ONLINE_SECRET','insert secret here'); -defined('TESTS_ZEND_SERVICE_GOGRID_ONLINE_SERVER_NAME') || define('TESTS_ZEND_SERVICE_GOGRID_ONLINE_SERVER_NAME','test-zf'); -defined('TESTS_ZEND_SERVICE_GOGRID_ONLINE_SERVER_IMAGE') || define('TESTS_ZEND_SERVICE_GOGRID_ONLINE_SERVER_IMAGE','insert image name here'); -defined('TESTS_ZEND_SERVICE_GOGRID_ONLINE_SERVER_RAM') || define('TESTS_ZEND_SERVICE_GOGRID_ONLINE_SERVER_RAM','insert ram name here'); -defined('TESTS_ZEND_SERVICE_GOGRID_ONLINE_SERVER_IP') || define('TESTS_ZEND_SERVICE_GOGRID_ONLINE_SERVER_IP','insert ip here'); - -/** - * Zend\Service\LiveDocx configuration - * - * Define username and password in order to run unit tests for LiveDocx web services. - * - * phpunit/phpunit will typically work. - */ -defined('TESTS_ZEND_SERVICE_LIVEDOCX_USERNAME') || define('TESTS_ZEND_SERVICE_LIVEDOCX_USERNAME', false); -defined('TESTS_ZEND_SERVICE_LIVEDOCX_PASSWORD') || define('TESTS_ZEND_SERVICE_LIVEDOCX_PASSWORD', false); - -/** - * Zend\Service\LiveDocx premium configuration - * - * Define username, password, WSDL in order to run unit tests for premium LiveDocx web services. - */ -defined('TESTS_ZEND_SERVICE_LIVEDOCX_PREMIUM_USERNAME') || define('TESTS_ZEND_SERVICE_LIVEDOCX_PREMIUM_USERNAME', false); -defined('TESTS_ZEND_SERVICE_LIVEDOCX_PREMIUM_PASSWORD') || define('TESTS_ZEND_SERVICE_LIVEDOCX_PREMIUM_PASSWORD', false); -defined('TESTS_ZEND_SERVICE_LIVEDOCX_PREMIUM_WSDL') || define('TESTS_ZEND_SERVICE_LIVEDOCX_PREMIUM_WSDL', false); - -/** - * Zend_Service_Rackspace tests - */ -defined('TESTS_ZEND_SERVICE_RACKSPACE_ONLINE_ENABLED') || define('TESTS_ZEND_SERVICE_RACKSPACE_ONLINE_ENABLED', false); -defined('TESTS_ZEND_SERVICE_RACKSPACE_ONLINE_USER') || define('TESTS_ZEND_SERVICE_RACKSPACE_ONLINE_USER', 'Enter key here'); -defined('TESTS_ZEND_SERVICE_RACKSPACE_ONLINE_KEY') || define('TESTS_ZEND_SERVICE_RACKSPACE_ONLINE_KEY', 'Enter secret here'); -defined('TESTS_ZEND_SERVICE_RACKSPACE_ONLINE_REGION') || define('TESTS_ZEND_SERVICE_RACKSPACE_ONLINE_REGION', 'USA'); -defined('TESTS_ZEND_SERVICE_RACKSPACE_CONTAINER_NAME') || define('TESTS_ZEND_SERVICE_RACKSPACE_CONTAINER_NAME', 'zf-unit-test'); -defined('TESTS_ZEND_SERVICE_RACKSPACE_OBJECT_NAME') || define('TESTS_ZEND_SERVICE_RACKSPACE_OBJECT_NAME','zf-object-test'); -defined('TESTS_ZEND_SERVICE_RACKSPACE_SERVER_NAME') || define('TESTS_ZEND_SERVICE_RACKSPACE_SERVER_NAME', 'zf-unit-test'); -defined('TESTS_ZEND_SERVICE_RACKSPACE_SERVER_IMAGEID') || define('TESTS_ZEND_SERVICE_RACKSPACE_SERVER_IMAGEID', '49'); -defined('TESTS_ZEND_SERVICE_RACKSPACE_SERVER_NEW_IMAGEID') || define('TESTS_ZEND_SERVICE_RACKSPACE_SERVER_NEW_IMAGEID', '49'); -defined('TESTS_ZEND_SERVICE_RACKSPACE_SERVER_FLAVORID') || define('TESTS_ZEND_SERVICE_RACKSPACE_SERVER_FLAVORID', '1'); -defined('TESTS_ZEND_SERVICE_RACKSPACE_SERVER_IMAGE_NAME') || define('TESTS_ZEND_SERVICE_RACKSPACE_SERVER_IMAGE_NAME', 'ZFunitTestImage'); -defined('TESTS_ZEND_SERVICE_RACKSPACE_SERVER_SHARED_IP_GROUP_NAME') || define('TESTS_ZEND_SERVICE_RACKSPACE_SERVER_SHARED_IP_GROUP_NAME', 'ZFgroupIP'); -defined('TESTS_ZEND_SERVICE_RACKSPACE_TIMEOUT') || define('TESTS_ZEND_SERVICE_RACKSPACE_TIMEOUT', 60); - -/** - * Zend_Service_ReCaptcha tests - */ -defined('TESTS_ZEND_SERVICE_RECAPTCHA_ENABLED') || define('TESTS_ZEND_SERVICE_RECAPTCHA_ENABLED', false); -defined('TESTS_ZEND_SERVICE_RECAPTCHA_ONLINE_ENABLED') || define('TESTS_ZEND_SERVICE_RECAPTCHA_ONLINE_ENABLED', false); -defined('TESTS_ZEND_SERVICE_RECAPTCHA_PUBLIC_KEY') || define('TESTS_ZEND_SERVICE_RECAPTCHA_PUBLIC_KEY', 'public key'); -defined('TESTS_ZEND_SERVICE_RECAPTCHA_PRIVATE_KEY') || define('TESTS_ZEND_SERVICE_RECAPTCHA_PRIVATE_KEY', 'private key'); -defined('TESTS_ZEND_SERVICE_RECAPTCHA_MAILHIDE_PUBLIC_KEY') || define('TESTS_ZEND_SERVICE_RECAPTCHA_MAILHIDE_PUBLIC_KEY', 'public mailhide key'); -defined('TESTS_ZEND_SERVICE_RECAPTCHA_MAILHIDE_PRIVATE_KEY') || define('TESTS_ZEND_SERVICE_RECAPTCHA_MAILHIDE_PRIVATE_KEY', 'private mailhide key'); - -/** - * Zend_Service_Simpy tests - */ -defined('TESTS_ZEND_SERVICE_SIMPY_ENABLED') || define('TESTS_ZEND_SERVICE_SIMPY_ENABLED', false); -defined('TESTS_ZEND_SERVICE_SIMPY_USERNAME') || define('TESTS_ZEND_SERVICE_SIMPY_USERNAME', 'syapizend'); -defined('TESTS_ZEND_SERVICE_SIMPY_PASSWORD') || define('TESTS_ZEND_SERVICE_SIMPY_PASSWORD', 'mgt37ge'); - -/** - * Zend_Service_SlideShare tests - */ -defined('TESTS_ZEND_SERVICE_SLIDESHARE_USERNAME') || define('TESTS_ZEND_SERVICE_SLIDESHARE_USERNAME', ''); -defined('TESTS_ZEND_SERVICE_SLIDESHARE_PASSWORD') || define('TESTS_ZEND_SERVICE_SLIDESHARE_PASSWORD', ''); -defined('TESTS_ZEND_SERVICE_SLIDESHARE_SHAREDSECRET') || define('TESTS_ZEND_SERVICE_SLIDESHARE_SHAREDSECRET', ''); -defined('TESTS_ZEND_SERVICE_SLIDESHARE_APIKEY') || define('TESTS_ZEND_SERVICE_SLIDESHARE_APIKEY', ''); - -// The slide show ID to retrieve during tests -defined('TESTS_ZEND_SERVICE_SLIDESHARE_SLIDESHOWID') || define('TESTS_ZEND_SERVICE_SLIDESHARE_SLIDESHOWID', 0); - -// The tag to retrieve during tests -defined('TESTS_ZEND_SERVICE_SLIDESHARE_TAG') || define('TESTS_ZEND_SERVICE_SLIDESHARE_TAG', 'zend'); - -// The group to retrieve during tests -defined('TESTS_ZEND_SERVICE_SLIDESHARE_GROUP') || define('TESTS_ZEND_SERVICE_SLIDESHARE_GROUP', ''); - -/** - * Zend_Service_Twitter tests - * - * ONLINE_ENABLED indicates whether or not to run tests requiring a network - * connection. - * - * TWITTER_USER and TWITTER_PASS are valid Twitter credentials you wish to use - * when testing. - */ -defined('TESTS_ZEND_SERVICE_TWITTER_ONLINE_ENABLED') || define('TESTS_ZEND_SERVICE_TWITTER_ONLINE_ENABLED', false); -defined('TESTS_ZEND_SERVICE_TWITTER_USER') || define('TESTS_ZEND_SERVICE_TWITTER_USER', 'zftestuser'); -defined('TESTS_ZEND_SERVICE_TWITTER_PASS') || define('TESTS_ZEND_SERVICE_TWITTER_PASS', 'zftestuser'); - -/** - * Zend_Service_WindowsAzure tests - */ - -/** - * Online - */ - -define('TESTS_ZEND_SERVICE_WINDOWSAZURE_ONLINE_ACCOUNTNAME',''); -define('TESTS_ZEND_SERVICE_WINDOWSAZURE_ONLINE_ACCOUNTKEY',''); -define('TESTS_ZEND_SERVICE_WINDOWSAZURE_ONLINE_TABLE_HOST',''); -define('TESTS_ZEND_SERVICE_WINDOWSAZURE_ONLINE_STORAGE_PROXY_HOST',''); -define('TESTS_ZEND_SERVICE_WINDOWSAZURE_ONLINE_STORAGE_PROXY_PORT',''); -define('TESTS_ZEND_SERVICE_WINDOWSAZURE_ONLINE_STORAGE_PROXY_CREDENTIALS',''); - -/** - * Proxy settings - */ -defined('TESTS_ZEND_SERVICE_WINDOWSAZURE_STORAGE_USEPROXY') || define('TESTS_ZEND_SERVICE_WINDOWSAZURE_STORAGE_USEPROXY', false); -defined('TESTS_ZEND_SERVICE_WINDOWSAZURE_STORAGE_PROXY') || define('TESTS_ZEND_SERVICE_WINDOWSAZURE_STORAGE_PROXY', ''); -defined('TESTS_ZEND_SERVICE_WINDOWSAZURE_STORAGE_PROXY_PORT') || define('TESTS_ZEND_SERVICE_WINDOWSAZURE_STORAGE_PROXY_PORT', '8080'); -defined('TESTS_ZEND_SERVICE_WINDOWSAZURE_STORAGE_PROXY_CREDENTIALS') || define('TESTS_ZEND_SERVICE_WINDOWSAZURE_STORAGE_PROXY_CREDENTIALS', ''); - -/** - * Azure hosts - */ -defined('TESTS_ZEND_SERVICE_WINDOWSAZURE_BLOB_HOST_DEV') || define('TESTS_ZEND_SERVICE_WINDOWSAZURE_BLOB_HOST_DEV', '127.0.0.1:10000'); -defined('TESTS_ZEND_SERVICE_WINDOWSAZURE_QUEUE_HOST_DEV') || define('TESTS_ZEND_SERVICE_WINDOWSAZURE_QUEUE_HOST_DEV', '127.0.0.1:10001'); -defined('TESTS_ZEND_SERVICE_WINDOWSAZURE_TABLE_HOST_DEV') || define('TESTS_ZEND_SERVICE_WINDOWSAZURE_TABLE_HOST_DEV', '127.0.0.1:10002'); -defined('TESTS_ZEND_SERVICE_WINDOWSAZURE_BLOB_HOST_PROD') || define('TESTS_ZEND_SERVICE_WINDOWSAZURE_BLOB_HOST_PROD', 'blob.core.windows.net'); -defined('TESTS_ZEND_SERVICE_WINDOWSAZURE_QUEUE_HOST_PROD') || define('TESTS_ZEND_SERVICE_WINDOWSAZURE_QUEUE_HOST_PROD', 'queue.core.windows.net'); -defined('TESTS_ZEND_SERVICE_WINDOWSAZURE_TABLE_HOST_PROD') || define('TESTS_ZEND_SERVICE_WINDOWSAZURE_TABLE_HOST_PROD', 'table.core.windows.net'); - -/** - * Credentials - */ -defined('TESTS_ZEND_SERVICE_WINDOWSAZURE_STORAGE_ACCOUNT_DEV') || define('TESTS_ZEND_SERVICE_WINDOWSAZURE_STORAGE_ACCOUNT_DEV', 'devstoreaccount1'); -defined('TESTS_ZEND_SERVICE_WINDOWSAZURE_STORAGE_KEY_DEV') || define('TESTS_ZEND_SERVICE_WINDOWSAZURE_STORAGE_KEY_DEV', 'Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw=='); -defined('TESTS_ZEND_SERVICE_WINDOWSAZURE_STORAGE_ACCOUNT_PROD') || define('TESTS_ZEND_SERVICE_WINDOWSAZURE_STORAGE_ACCOUNT_PROD', 'phpazure'); -defined('TESTS_ZEND_SERVICE_WINDOWSAZURE_STORAGE_KEY_PROD') || define('TESTS_ZEND_SERVICE_WINDOWSAZURE_STORAGE_KEY_PROD', 'I+ebYPcIDB6BsmfAe6pJSpOw8oXA6jMBZv1BEZcSPRqTpldt44refCl65YpKJqcBOiD21Lxsj8d6Ah8Oc2/gKA=='); - -/** - * Blob storage tests - */ -// Enable this tests only when you have a working account -defined('TESTS_ZEND_SERVICE_WINDOWSAZURE_BLOB_RUNTESTS') || define('TESTS_ZEND_SERVICE_WINDOWSAZURE_BLOB_RUNTESTS', false); -defined('TESTS_ZEND_SERVICE_WINDOWSAZURE_BLOB_RUNONPROD') || define('TESTS_ZEND_SERVICE_WINDOWSAZURE_BLOB_RUNONPROD', false); -defined('TESTS_ZEND_SERVICE_WINDOWSAZURE_BLOB_RUNLARGEBLOB') || define('TESTS_ZEND_SERVICE_WINDOWSAZURE_BLOB_RUNLARGEBLOB', true); -defined('TESTS_ZEND_SERVICE_WINDOWSAZURE_BLOB_CONTAINER_PREFIX') || define('TESTS_ZEND_SERVICE_WINDOWSAZURE_BLOB_CONTAINER_PREFIX', 'phpazuretestblob'); -defined('TESTS_ZEND_SERVICE_WINDOWSAZURE_BLOBSTREAM_CONTAINER_PREFIX') || define('TESTS_ZEND_SERVICE_WINDOWSAZURE_BLOBSTREAM_CONTAINER_PREFIX', 'phpazureteststream'); -defined('TESTS_ZEND_SERVICE_WINDOWSAZURE_BLOBSA_CONTAINER_PREFIX') || define('TESTS_ZEND_SERVICE_WINDOWSAZURE_BLOBSA_CONTAINER_PREFIX', 'phpazuretestshared'); - -/** - * Table storage tests - */ -// Enable this tests only when you have a working account -defined('TESTS_ZEND_SERVICE_WINDOWSAZURE_TABLE_RUNTESTS') || define('TESTS_ZEND_SERVICE_WINDOWSAZURE_TABLE_RUNTESTS', false); -defined('TESTS_ZEND_SERVICE_WINDOWSAZURE_TABLE_RUNONPROD') || define('TESTS_ZEND_SERVICE_WINDOWSAZURE_TABLE_RUNONPROD', false); -defined('TESTS_ZEND_SERVICE_WINDOWSAZURE_TABLE_TABLENAME_PREFIX') || define('TESTS_ZEND_SERVICE_WINDOWSAZURE_TABLE_TABLENAME_PREFIX', 'phpazuretesttable'); - -/** - * Queue storage tests - */ -defined('TESTS_ZEND_SERVICE_WINDOWSAZURE_QUEUE_RUNTESTS') || define('TESTS_ZEND_SERVICE_WINDOWSAZURE_QUEUE_RUNTESTS', false); -defined('TESTS_ZEND_SERVICE_WINDOWSAZURE_QUEUE_RUNONPROD') || define('TESTS_ZEND_SERVICE_WINDOWSAZURE_QUEUE_RUNONPROD', false); -defined('TESTS_ZEND_SERVICE_WINDOWSAZURE_QUEUE_PREFIX') || define('TESTS_ZEND_SERVICE_WINDOWSAZURE_QUEUE_PREFIX', 'phpazuretestqueue'); - -/** - * SessionHandler tests - */ -defined('TESTS_ZEND_SERVICE_WINDOWSAZURE_SESSIONHANDLER_RUNTESTS') || define('TESTS_ZEND_SERVICE_WINDOWSAZURE_SESSIONHANDLER_RUNTESTS', false); -defined('TESTS_ZEND_SERVICE_WINDOWSAZURE_SESSIONHANDLER_RUNONPROD') || define('TESTS_ZEND_SERVICE_WINDOWSAZURE_SESSIONHANDLER_RUNONPROD', false); -defined('TESTS_ZEND_SERVICE_WINDOWSAZURE_SESSIONHANDLER_TABLENAME_PREFIX') || define('TESTS_ZEND_SERVICE_WINDOWSAZURE_SESSIONHANDLER_TABLENAME_PREFIX', 'phpazuretestsession'); - -/** - * Zend_Service_Yahoo online tests - */ -defined('TESTS_ZEND_SERVICE_YAHOO_ONLINE_ENABLED') || define('TESTS_ZEND_SERVICE_YAHOO_ONLINE_ENABLED', false); -defined('TESTS_ZEND_SERVICE_YAHOO_ONLINE_APPID') || define('TESTS_ZEND_SERVICE_YAHOO_ONLINE_APPID', 'Enter APPID here'); - -/** - * Zend_Soap_AutoDiscover scenario tests for complex objects and wsdl generation - * - * Copy all the files of zf/tests/Zend/Soap/_files/fulltests into a directory - * that can be reached by webserver and enter the base uri to this directory - * into the variable. The test "Zend_Soap_AutoDiscover_OnlineTest" makes use - * of the servers and AutoDiscover feature. - * - * NOTE: Make sure the servers are using the correct Zend Framework copy, - * when having more than one version installed and include paths are changing. - */ -defined('TESTS_ZEND_SOAP_AUTODISCOVER_ONLINE_SERVER_BASEURI') || define('TESTS_ZEND_SOAP_AUTODISCOVER_ONLINE_SERVER_BASEURI', false); - -/** - * Zend_Uri tests - * - * Setting CRASH_TEST_ENABLED to true will enable some tests that may - * potentially crash PHP on some systems, due to very deep-nesting regular - * expressions. - * - * Only do this if you know what you are doing! - */ -defined('TESTS_ZEND_URI_CRASH_TEST_ENABLED') || define('TESTS_ZEND_URI_CRASH_TEST_ENABLED', false); - -/** - * Zend_Validate tests - * - * Set ONLINE_ENABLED if you wish to run validators that require network - * connectivity. - */ -defined('TESTS_ZEND_VALIDATE_ONLINE_ENABLED') || define('TESTS_ZEND_VALIDATE_ONLINE_ENABLED', false); - -/** - * PHPUnit Code Coverage / Test Report - */ -defined('TESTS_GENERATE_REPORT') || define('TESTS_GENERATE_REPORT', false); -defined('TESTS_GENERATE_REPORT_TARGET') || define('TESTS_GENERATE_REPORT_TARGET', '/path/to/target'); - From 91f68932fd04cc9be2f8557ce612fecc4b0ed5e0 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Wed, 4 Apr 2012 21:28:23 +0200 Subject: [PATCH 34/61] Re-enabling components as of @weierophinney suggestions --- .travis/skipped-components | 16 ---------------- .travis/tested-components | 18 ++++++++++++++++-- 2 files changed, 16 insertions(+), 18 deletions(-) diff --git a/.travis/skipped-components b/.travis/skipped-components index 7d38e2d..6ccd1be 100644 --- a/.travis/skipped-components +++ b/.travis/skipped-components @@ -1,27 +1,11 @@ Zend/Amf Zend/Barcode -Zend/Cache -Zend/Code Zend/Date -Zend/Docbook Zend/Feed -Zend/File -Zend/Filter -Zend/GData -Zend/Json -Zend/Locale -Zend/Mail -Zend/Mime -Zend/Navigation -Zend/OpenId Zend/Paginator Zend/Queue -Zend/RegistryTest.php Zend/Service Zend/Session -Zend/Soap Zend/Test Zend/Translator -Zend/Validator Zend/Wildfire -Zend/XmlRpc diff --git a/.travis/tested-components b/.travis/tested-components index 34047ab..da5b101 100644 --- a/.travis/tested-components +++ b/.travis/tested-components @@ -1,40 +1,54 @@ -Zend/Mvc -Zend/View Zend/Acl Zend/Authentication +Zend/Cache Zend/Captcha Zend/Cloud +Zend/Code Zend/Config Zend/Console Zend/Crypt Zend/Currency Zend/Db Zend/Di +Zend/Docbook Zend/Dojo Zend/Dom Zend/EventManager +Zend/File +Zend/Filter Zend/Form +Zend/GData Zend/Http Zend/InfoCard +Zend/Json Zend/Ldap Zend/Loader +Zend/Locale Zend/Log +Zend/Mail Zend/Markup Zend/Measure Zend/Memory +Zend/Mime Zend/Module Zend/Mvc +Zend/Navigation Zend/OAuth +Zend/OpenId Zend/Pdf Zend/ProgressBar +Zend/RegistryTest.php Zend/Rest Zend/Search Zend/Serializer Zend/Server +Zend/Soap Zend/Stdlib Zend/Tag Zend/Text Zend/TimeSync Zend/Uri +Zend/Validator Zend/VersionTest.php Zend/View +Zend/XmlRpc From f547e5e8fb9af3a9aadea72179182f7a5b3a072b Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Wed, 4 Apr 2012 22:16:58 +0200 Subject: [PATCH 35/61] Fixing exit code and output of test runner The test-runner will run all test suites and display their names anyway, then use an appropriate exit code in case of failures. Using the list of components to be tested (was using the skipped components list to be sure that the exit code of the test runner were correct). --- .travis/run-tests.sh | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.travis/run-tests.sh b/.travis/run-tests.sh index 47d0c4a..11d98cd 100755 --- a/.travis/run-tests.sh +++ b/.travis/run-tests.sh @@ -2,7 +2,13 @@ travisdir=$(dirname $(readlink /proc/$$/fd/255)) testdir="$travisdir/../tests" testedcomponents=(`cat "$travisdir/tested-components"`) +result=0 for tested in "${testedcomponents[@]}" - do phpunit -c $testdir/phpunit.xml $testdir/$tested + do + echo "$tested:" + phpunit -c $testdir/phpunit.xml $testdir/$tested + let "result = $result || $?" done + +exit $result \ No newline at end of file From 287247ff723a019059c63baf07d241976a43469e Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Mon, 9 Apr 2012 11:28:58 -0500 Subject: [PATCH 36/61] [zendframework/zf2#1008] Updated test lists - Moved Session, Paginator to tested-components - Added Zend/Feed/Reader, Writer to tested-components --- .travis/skipped-components | 2 -- .travis/tested-components | 4 ++++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.travis/skipped-components b/.travis/skipped-components index 6ccd1be..6847359 100644 --- a/.travis/skipped-components +++ b/.travis/skipped-components @@ -2,10 +2,8 @@ Zend/Amf Zend/Barcode Zend/Date Zend/Feed -Zend/Paginator Zend/Queue Zend/Service -Zend/Session Zend/Test Zend/Translator Zend/Wildfire diff --git a/.travis/tested-components b/.travis/tested-components index da5b101..330e5f1 100644 --- a/.travis/tested-components +++ b/.travis/tested-components @@ -14,6 +14,8 @@ Zend/Docbook Zend/Dojo Zend/Dom Zend/EventManager +Zend/Feed/Reader +Zend/Feed/Writer Zend/File Zend/Filter Zend/Form @@ -35,6 +37,7 @@ Zend/Mvc Zend/Navigation Zend/OAuth Zend/OpenId +Zend/Paginator Zend/Pdf Zend/ProgressBar Zend/RegistryTest.php @@ -42,6 +45,7 @@ Zend/Rest Zend/Search Zend/Serializer Zend/Server +Zend/Session Zend/Soap Zend/Stdlib Zend/Tag From 120e4d3c11128ad36acae8011e5405ff7f7d740d Mon Sep 17 00:00:00 2001 From: Evan Coury Date: Sat, 21 Apr 2012 01:22:19 -0700 Subject: [PATCH 37/61] Remaining references to old Authentication\Adapter interface name updated --- src/AuthenticationService.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/AuthenticationService.php b/src/AuthenticationService.php index f541382..8c78df6 100644 --- a/src/AuthenticationService.php +++ b/src/AuthenticationService.php @@ -38,7 +38,7 @@ class AuthenticationService /** * Authentication adapter * - * @var Zend\Authentication\Adapter + * @var Zend\Authentication\Adapter\AdapterInterface */ protected $adapter = null; @@ -46,6 +46,7 @@ class AuthenticationService * Constructor * * @param Storage\StorageInterface $storage + * @param Adapter\AdapterInterface $adapter * @return void */ public function __construct(Storage\StorageInterface $storage = null, Adapter\AdapterInterface $adapter = null) @@ -63,7 +64,7 @@ public function __construct(Storage\StorageInterface $storage = null, Adapter\Ad * * The adapter does not have a default if the storage adapter has not been set. * - * @return Zend\Authentication\Adapter|null + * @return Zend\Authentication\Adapter\AdapterInterface|null */ public function getAdapter() { @@ -73,10 +74,10 @@ public function getAdapter() /** * Sets the authentication adapter * - * @param Zend\Authentication\Adapter $adapter + * @param Zend\Authentication\Adapter\AdapterInterface $adapter * @return Zend\Authentication\AuthenticationService Provides a fluent interface */ - public function setAdapter(Adapter $adapter) + public function setAdapter(Adapter\AdapterInterface $adapter) { $this->adapter = $adapter; return $this; From a7618f5a0addf98c4f372b1987ed0454f485ff34 Mon Sep 17 00:00:00 2001 From: Maks3w Date: Wed, 2 May 2012 09:59:31 +0200 Subject: [PATCH 38/61] [Zend\Authentication] Fixing several incorrect classes --- src/Adapter/DbTable.php | 6 +- src/Adapter/Digest.php | 6 +- .../Exception/InvalidArgumentException.php | 2 +- src/Adapter/Exception/RuntimeException.php | 2 +- .../Exception/UnexpectedValueException.php | 2 +- src/Adapter/Http.php | 5 +- src/Adapter/InfoCard.php | 64 ++++++++++--------- src/Adapter/Ldap.php | 5 +- src/Exception/RuntimeException.php | 2 - src/Storage/NonPersistent.php | 2 - src/Storage/Session.php | 3 +- .../TestAsset/OpenIdResponseHelper.php | 15 ++--- 12 files changed, 54 insertions(+), 60 deletions(-) diff --git a/src/Adapter/DbTable.php b/src/Adapter/DbTable.php index 9a7172a..1a67ee5 100644 --- a/src/Adapter/DbTable.php +++ b/src/Adapter/DbTable.php @@ -20,8 +20,8 @@ */ namespace Zend\Authentication\Adapter; -use Zend\Authentication\Adapter\AdapterInterface as AuthenticationAdapter, - Zend\Authentication\Result as AuthenticationResult, + +use Zend\Authentication\Result as AuthenticationResult, Zend\Db\Adapter\Adapter as DbAdapter, Zend\Db\Sql\Select as DbSelect, Zend\Db\Sql\Expression, @@ -34,7 +34,7 @@ * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ -class DbTable implements AuthenticationAdapter +class DbTable implements AdapterInterface { /** diff --git a/src/Adapter/Digest.php b/src/Adapter/Digest.php index a98a900..6f6ad4e 100644 --- a/src/Adapter/Digest.php +++ b/src/Adapter/Digest.php @@ -20,8 +20,8 @@ */ namespace Zend\Authentication\Adapter; -use Zend\Authentication\Adapter\AdapterInterface as AuthenticationAdapter, - Zend\Authentication\Result as AuthenticationResult; + +use Zend\Authentication\Result as AuthenticationResult; /** * @category Zend @@ -30,7 +30,7 @@ * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ -class Digest implements AuthenticationAdapter +class Digest implements AdapterInterface { /** * Filename against which authentication queries are performed diff --git a/src/Adapter/Exception/InvalidArgumentException.php b/src/Adapter/Exception/InvalidArgumentException.php index 7a5027f..4e07490 100644 --- a/src/Adapter/Exception/InvalidArgumentException.php +++ b/src/Adapter/Exception/InvalidArgumentException.php @@ -4,6 +4,6 @@ class InvalidArgumentException extends \InvalidArgumentException - implements \Zend\Authentication\Adapter\Exception\ExceptionInterface + implements ExceptionInterface { } \ No newline at end of file diff --git a/src/Adapter/Exception/RuntimeException.php b/src/Adapter/Exception/RuntimeException.php index 1dc7d64..8ab09cb 100644 --- a/src/Adapter/Exception/RuntimeException.php +++ b/src/Adapter/Exception/RuntimeException.php @@ -4,7 +4,7 @@ class RuntimeException extends \RuntimeException - implements \Zend\Authentication\Adapter\Exception\ExceptionInterface + implements ExceptionInterface { } \ No newline at end of file diff --git a/src/Adapter/Exception/UnexpectedValueException.php b/src/Adapter/Exception/UnexpectedValueException.php index d4178a3..5cbf16c 100644 --- a/src/Adapter/Exception/UnexpectedValueException.php +++ b/src/Adapter/Exception/UnexpectedValueException.php @@ -4,6 +4,6 @@ class UnexpectedValueException extends \UnexpectedValueException - implements \Zend\Authentication\Adapter\Exception\ExceptionInterface + implements ExceptionInterface { } \ No newline at end of file diff --git a/src/Adapter/Http.php b/src/Adapter/Http.php index b5b5666..0454c9f 100644 --- a/src/Adapter/Http.php +++ b/src/Adapter/Http.php @@ -21,8 +21,7 @@ namespace Zend\Authentication\Adapter; -use Zend\Authentication\Adapter\AdapterInterface as AuthenticationAdapter, - Zend\Authentication, +use Zend\Authentication, Zend\Http\Request as HTTPRequest, Zend\Http\Response as HTTPResponse, Zend\Uri\UriFactory; @@ -41,7 +40,7 @@ * @todo Track nonces, nonce-count, opaque for replay protection and stale support * @todo Support Authentication-Info header */ -class Http implements AuthenticationAdapter +class Http implements AdapterInterface { /** * Reference to the HTTP Request object diff --git a/src/Adapter/InfoCard.php b/src/Adapter/InfoCard.php index 2d44ab8..2ec844f 100644 --- a/src/Adapter/InfoCard.php +++ b/src/Adapter/InfoCard.php @@ -20,8 +20,9 @@ */ namespace Zend\Authentication\Adapter; -use Zend\Authentication\Adapter\AdapterInterface as AuthenticationAdapter, - Zend\Authentication\Result as AuthenticationResult; + +use Zend\Authentication\Result as AuthenticationResult; +use Zend\InfoCard as ZendInfoCard; /** * A Zend_Auth Authentication Adapter allowing the use of Information Cards as an @@ -33,7 +34,7 @@ * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ -class InfoCard implements AuthenticationAdapter +class InfoCard implements AdapterInterface { /** * The XML Token being authenticated @@ -43,9 +44,9 @@ class InfoCard implements AuthenticationAdapter protected $_xmlToken; /** - * The instance of Zend_InfoCard + * The instance of Zend\InfoCard * - * @var \Zend\InfoCard + * @var \Zend\InfoCard\InfoCard */ protected $_infoCard; @@ -58,7 +59,7 @@ class InfoCard implements AuthenticationAdapter public function __construct($strXmlDocument) { $this->_xmlToken = $strXmlDocument; - $this->_infoCard = new \Zend_InfoCard(); + $this->_infoCard = new ZendInfoCard\InfoCard(); } /** @@ -67,7 +68,7 @@ public function __construct($strXmlDocument) * @param Zend\InfoCard\Adapter $a * @return Zend\Authentication\Adapter\InfoCard Provides a fluent interface */ - public function setAdapter(\Zend\InfoCard\Adapter $a) + public function setAdapter(ZendInfoCard\Adapter $a) { $this->_infoCard->setAdapter($a); return $this; @@ -76,7 +77,7 @@ public function setAdapter(\Zend\InfoCard\Adapter $a) /** * Retrieves the InfoCard component adapter being used * - * @return Zend_InfoCard_Adapter_Interface + * @return Zend\InfoCard\Adapter */ public function getAdapter() { @@ -86,7 +87,7 @@ public function getAdapter() /** * Retrieves the InfoCard public key cipher object being used * - * @return Zend_InfoCard_Cipher_Pki_Interface + * @return Zend\InfoCard\Cipher\PKI */ public function getPKCipherObject() { @@ -99,7 +100,7 @@ public function getPKCipherObject() * @param Zend\InfoCard\Cipher\PKI $cipherObj * @return \Zend\Authentication\Adapter\InfoCard Provides a fluent interface */ - public function setPKICipherObject(\Zend\InfoCard\Cipher\PKI $cipherObj) + public function setPKICipherObject(ZendInfoCard\Cipher\PKI $cipherObj) { $this->_infoCard->setPKICipherObject($cipherObj); return $this; @@ -108,7 +109,7 @@ public function setPKICipherObject(\Zend\InfoCard\Cipher\PKI $cipherObj) /** * Retrieves the Symmetric cipher object being used * - * @return Zend_InfoCard_Cipher_Symmetric_Interface + * @return Zend\InfoCard\Cipher\Symmetric */ public function getSymCipherObject() { @@ -121,7 +122,7 @@ public function getSymCipherObject() * @param Zend\InfoCard\Cipher\Symmetric $cipherObj * @return Zend\Authentication\Adapter\InfoCard Provides a fluent interface */ - public function setSymCipherObject(\Zend\InfoCard\Cipher\Symmetric $cipherObj) + public function setSymCipherObject(ZendInfoCard\Cipher\Symmetric $cipherObj) { $this->_infoCard->setSymCipherObject($cipherObj); return $this; @@ -130,42 +131,42 @@ public function setSymCipherObject(\Zend\InfoCard\Cipher\Symmetric $cipherObj) /** * Remove a Certificate Pair by Key ID from the search list * - * @param string $key_id The Certificate Key ID returned from adding the certificate pair + * @param string $keyId The Certificate Key ID returned from adding the certificate pair * @throws Zend\InfoCard\Exception * @return Zend\Authentication\Adapter\InfoCard Provides a fluent interface */ - public function removeCertificatePair($key_id) + public function removeCertificatePair($keyId) { - $this->_infoCard->removeCertificatePair($key_id); + $this->_infoCard->removeCertificatePair($keyId); return $this; } /** * Add a Certificate Pair to the list of certificates searched by the component * - * @param string $private_key_file The path to the private key file for the pair - * @param string $public_key_file The path to the certificate / public key for the pair + * @param string $privateKeyFile The path to the private key file for the pair + * @param string $publicKeyFile The path to the certificate / public key for the pair * @param string $type (optional) The URI for the type of key pair this is (default RSA with OAEP padding) * @param string $password (optional) The password for the private key file if necessary - * @throws Zend_InfoCard_Exception + * @throws Zend\InfoCard\Exception * @return string A key ID representing this key pair in the component */ - public function addCertificatePair($private_key_file, $public_key_file, $type = \Zend_InfoCard_Cipher::ENC_RSA_OAEP_MGF1P, $password = null) + public function addCertificatePair($privateKeyFile, $publicKeyFile, $type = ZendInfoCard\Cipher::ENC_RSA_OAEP_MGF1P, $password = null) { - return $this->_infoCard->addCertificatePair($private_key_file, $public_key_file, $type, $password); + return $this->_infoCard->addCertificatePair($privateKeyFile, $publicKeyFile, $type, $password); } /** * Return a Certificate Pair from a key ID * - * @param string $key_id The Key ID of the certificate pair in the component - * @throws Zend_InfoCard_Exception + * @param string $keyId The Key ID of the certificate pair in the component + * @throws Zend\InfoCard\Exception * @return array An array containing the path to the private/public key files, * the type URI and the password if provided */ - public function getCertificatePair($key_id) + public function getCertificatePair($keyId) { - return $this->_infoCard->getCertificatePair($key_id); + return $this->_infoCard->getCertificatePair($keyId); } /** @@ -200,15 +201,18 @@ public function authenticate() try { $claims = $this->_infoCard->process($this->getXmlToken()); } catch(\Exception $e) { - return new AuthenticationResult(AuthenticationResult::FAILURE, null, array('Exception Thrown', - $e->getMessage(), - $e->getTraceAsString(), - serialize($e))); + return new AuthenticationResult( + AuthenticationResult::FAILURE, + null, + array('Exception Thrown', + $e->getMessage(), + $e->getTraceAsString(), + serialize($e))); } if (!$claims->isValid()) { switch($claims->getCode()) { - case \Zend_InfoCard_Claims::RESULT_PROCESSING_FAILURE: + case ZendInfoCard\Claims::RESULT_PROCESSING_FAILURE: return new AuthenticationResult( AuthenticationResult::FAILURE, $claims, @@ -218,7 +222,7 @@ public function authenticate() ) ); break; - case \Zend_InfoCard_Claims::RESULT_VALIDATION_FAILURE: + case ZendInfoCard\Claims::RESULT_VALIDATION_FAILURE: return new AuthenticationResult( AuthenticationResult::FAILURE_CREDENTIAL_INVALID, $claims, diff --git a/src/Adapter/Ldap.php b/src/Adapter/Ldap.php index 5898004..519cda3 100644 --- a/src/Adapter/Ldap.php +++ b/src/Adapter/Ldap.php @@ -21,8 +21,7 @@ namespace Zend\Authentication\Adapter; -use Zend\Authentication\Adapter\AdapterInterface as AuthenticationAdapter, - Zend\Authentication\Result as AuthenticationResult, +use Zend\Authentication\Result as AuthenticationResult, Zend\Ldap as ZendLdap, Zend\Ldap\Exception\LdapException; @@ -33,7 +32,7 @@ * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ -class Ldap implements AuthenticationAdapter +class Ldap implements AdapterInterface { /** diff --git a/src/Exception/RuntimeException.php b/src/Exception/RuntimeException.php index 5f05358..08d6384 100755 --- a/src/Exception/RuntimeException.php +++ b/src/Exception/RuntimeException.php @@ -21,8 +21,6 @@ namespace Zend\Authentication\Exception; -use Zend\Authentication\Exception; - /** * @category Zend * @package Zend_Authentication diff --git a/src/Storage/NonPersistent.php b/src/Storage/NonPersistent.php index c0017c5..b8a4c6f 100644 --- a/src/Storage/NonPersistent.php +++ b/src/Storage/NonPersistent.php @@ -21,8 +21,6 @@ namespace Zend\Authentication\Storage; -use Zend\Authentication\Storage as AuthenticationStorage; - /** * Non-Persistent Authentication Storage * diff --git a/src/Storage/Session.php b/src/Storage/Session.php index 6e12d95..d205f08 100644 --- a/src/Storage/Session.php +++ b/src/Storage/Session.php @@ -21,8 +21,7 @@ namespace Zend\Authentication\Storage; -use Zend\Authentication\Storage\StorageInterface as AuthenticationStorage, - Zend\Session\Container as SessionContainer, +use Zend\Session\Container as SessionContainer, Zend\Session\Manager as SessionManager; /** diff --git a/test/Adapter/TestAsset/OpenIdResponseHelper.php b/test/Adapter/TestAsset/OpenIdResponseHelper.php index 7efd2cd..45929da 100644 --- a/test/Adapter/TestAsset/OpenIdResponseHelper.php +++ b/test/Adapter/TestAsset/OpenIdResponseHelper.php @@ -21,22 +21,19 @@ namespace ZendTest\Authentication\Adapter\TestAsset; -use Zend\Controller\Response\AbstractResponse; +use Zend\Http\Response; +use Zend\OpenId\OpenId; -/** - * Zend_OpenId - */ - -\Zend\OpenID\OpenID::$exitOnRedirect = false; +OpenId::$exitOnRedirect = false; /** * @category Zend - * @package Zend_OpenId + * @package Zend_Authentication * @subpackage UnitTests * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ -class OpenIdResponseHelper extends AbstractResponse +class ResponseHelper extends Response { private $_canSendHeaders; @@ -53,4 +50,4 @@ public function canSendHeaders($throw = false) public function sendResponse() { } -} +} \ No newline at end of file From 849c3e916a667c81a4e0a90c8ac9fe88ee043fc7 Mon Sep 17 00:00:00 2001 From: Maks3w Date: Wed, 2 May 2012 14:00:55 +0200 Subject: [PATCH 39/61] [Authentication] Fix some class references in comments --- src/Adapter/DbTable.php | 12 ++++++------ src/Adapter/Digest.php | 2 +- src/Storage/Session.php | 8 ++++---- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/Adapter/DbTable.php b/src/Adapter/DbTable.php index a328df3..c813e60 100644 --- a/src/Adapter/DbTable.php +++ b/src/Adapter/DbTable.php @@ -318,10 +318,10 @@ public function getResultRowObject($returnColumns = null, $omitColumns = null) } /** - * authenticate() - defined by Zend\Auth\Adapter\AdapterInterface. This method is called to - * attempt an authentication. Previous to this call, this adapter would have already - * been configured with all necessary information to successfully connect to a database - * table and attempt to find a record matching the provided identity. + * This method is called to attempt an authentication. Previous to this + * call, this adapter would have already been configured with all + * necessary information to successfully connect to a database table and + * attempt to find a record matching the provided identity. * * @throws Exception\RuntimeException if answering the authentication query is impossible * @return AuthenticationResult @@ -488,8 +488,8 @@ protected function _authenticateValidateResult($resultIdentity) } /** - * _authenticateCreateAuthResult() - Creates a Zend\Auth\Result object from - * the information that has been collected during the authenticate() attempt. + * Creates a Zend\Authentication\Result object from the information that + * has been collected during the authenticate() attempt. * * @return AuthenticationResult */ diff --git a/src/Adapter/Digest.php b/src/Adapter/Digest.php index a98a900..8e94930 100644 --- a/src/Adapter/Digest.php +++ b/src/Adapter/Digest.php @@ -169,7 +169,7 @@ public function setPassword($password) } /** - * Defined by Zend_Auth_Adapter_Interface + * Defined by Zend\Authentication\Adapter\AdapterInterface * * @throws Zend\Authentication\Adapter\Exception\ExceptionInterface * @return Zend\Authentication\Result diff --git a/src/Storage/Session.php b/src/Storage/Session.php index bf492e2..420f141 100644 --- a/src/Storage/Session.php +++ b/src/Storage/Session.php @@ -106,7 +106,7 @@ public function getMember() } /** - * Defined by Zend\Auth\Storage + * Defined by Zend\Authentication\Storage\StorageInterface * * @return boolean */ @@ -116,7 +116,7 @@ public function isEmpty() } /** - * Defined by Zend\Auth\Storage + * Defined by Zend\Authentication\Storage\StorageInterface * * @return mixed */ @@ -126,7 +126,7 @@ public function read() } /** - * Defined by Zend\Auth\Storage + * Defined by Zend\Authentication\Storage\StorageInterface * * @param mixed $contents * @return void @@ -137,7 +137,7 @@ public function write($contents) } /** - * Defined by Zend\Auth\Storage + * Defined by Zend\Authentication\Storage\StorageInterface * * @return void */ From 4bbe435ba349220c7c914d94aaf03e83f90872dc Mon Sep 17 00:00:00 2001 From: prolic Date: Sun, 6 May 2012 22:35:02 +0200 Subject: [PATCH 40/61] small fixes --- src/Storage/Session.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Storage/Session.php b/src/Storage/Session.php index 4ef237f..295d768 100644 --- a/src/Storage/Session.php +++ b/src/Storage/Session.php @@ -47,7 +47,7 @@ class Session implements AuthenticationStorage /** * Object to proxy $_SESSION storage * - * @var Zend\Session\Container + * @var SessionContainer */ protected $session; From 5742ba7021484af0d48767009cdea545b08ce06f Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Wed, 9 May 2012 11:28:05 -0500 Subject: [PATCH 41/61] Remove --stderr switch from Travis test runner - Appears that it may not be necessary --- .travis/run-tests.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis/run-tests.sh b/.travis/run-tests.sh index 1ba31be..9334e95 100755 --- a/.travis/run-tests.sh +++ b/.travis/run-tests.sh @@ -7,7 +7,7 @@ result=0 for tested in "${testedcomponents[@]}" do echo "$tested:" - phpunit -c $testdir/phpunit.xml --stderr $testdir/$tested + phpunit -c $testdir/phpunit.xml $testdir/$tested result=$(($result || $?)) done From 18fa7cb716073b9e8927103d1511bdfc474f5903 Mon Sep 17 00:00:00 2001 From: Maks3w Date: Fri, 11 May 2012 11:06:08 +0200 Subject: [PATCH 42/61] [Tests] Update Travis script --- .travis/run-tests.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis/run-tests.sh b/.travis/run-tests.sh index 9334e95..7e1baa3 100755 --- a/.travis/run-tests.sh +++ b/.travis/run-tests.sh @@ -7,7 +7,7 @@ result=0 for tested in "${testedcomponents[@]}" do echo "$tested:" - phpunit -c $testdir/phpunit.xml $testdir/$tested + phpunit -c $testdir/phpunit.xml.dist $testdir/$tested result=$(($result || $?)) done From 653631fa0657b52d44197888bb9ece38824d48c5 Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Fri, 11 May 2012 11:41:23 -0500 Subject: [PATCH 43/61] [zen-27][zendframework/zf2#1198] travis update - Remove Zend\Feed from skipped components list --- .travis/skipped-components | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis/skipped-components b/.travis/skipped-components index 6847359..0790ed2 100644 --- a/.travis/skipped-components +++ b/.travis/skipped-components @@ -1,7 +1,6 @@ Zend/Amf Zend/Barcode Zend/Date -Zend/Feed Zend/Queue Zend/Service Zend/Test From 7cef8176495309f9c97862a3552ab0a608c1c7b7 Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Fri, 11 May 2012 12:18:48 -0500 Subject: [PATCH 44/61] [zen-27][zendframework/zf2#1199] Fix Translator tests - Fixes log setup and usage in tests and code for Translator - Re-enabled Translator tests, as they now appear to work --- .travis/skipped-components | 1 - .travis/tested-components | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis/skipped-components b/.travis/skipped-components index c4cd706..31bcaa8 100644 --- a/.travis/skipped-components +++ b/.travis/skipped-components @@ -3,5 +3,4 @@ Zend/Date Zend/Queue Zend/Service Zend/Test -Zend/Translator Zend/Wildfire diff --git a/.travis/tested-components b/.travis/tested-components index d1d7133..b1f4a79 100644 --- a/.travis/tested-components +++ b/.travis/tested-components @@ -51,6 +51,7 @@ Zend/Stdlib Zend/Tag Zend/Text Zend/TimeSync +Zend/Translator Zend/Uri Zend/Validator Zend/VersionTest.php From 9f2c4896cb3ac6116943a568d0360a33385fa833 Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Fri, 11 May 2012 08:17:31 -0500 Subject: [PATCH 45/61] [zen-12] Removed Dojo from test suite - Dojo integration largely relied on integration with Zend\Form; removing from testing for now, as it has not been refactored to work with the new Zend\Form code. --- .travis/skipped-components | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis/skipped-components b/.travis/skipped-components index 31bcaa8..171dfe9 100644 --- a/.travis/skipped-components +++ b/.travis/skipped-components @@ -1,5 +1,6 @@ Zend/Amf Zend/Date +Zend/Dojo Zend/Queue Zend/Service Zend/Test From 855bdfe831939a7381715a6f8810187da2fcac78 Mon Sep 17 00:00:00 2001 From: Maks3w Date: Sun, 13 May 2012 09:42:04 +0200 Subject: [PATCH 46/61] [Authentication] Change namespaces Change some namespaces from ZendTest\Auth\ to ZenTest\Authentication\ --- test/Adapter/Http/AuthTest.php | 2 +- test/Adapter/Http/FileResolverTest.php | 2 +- test/Adapter/Http/ObjectTest.php | 2 +- test/Adapter/Http/ProxyTest.php | 2 +- test/Adapter/Ldap/OfflineTest.php | 2 +- test/Adapter/Ldap/OnlineTest.php | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/test/Adapter/Http/AuthTest.php b/test/Adapter/Http/AuthTest.php index f2d30fd..954ff92 100644 --- a/test/Adapter/Http/AuthTest.php +++ b/test/Adapter/Http/AuthTest.php @@ -19,7 +19,7 @@ * @license http://framework.zend.com/license/new-bsd New BSD License */ -namespace ZendTest\Auth\Adapter\Http; +namespace ZendTest\Authentication\Adapter\Http; use Zend\Authentication\Adapter\Http, Zend\Http\Headers, diff --git a/test/Adapter/Http/FileResolverTest.php b/test/Adapter/Http/FileResolverTest.php index d15bcbe..0d75554 100644 --- a/test/Adapter/Http/FileResolverTest.php +++ b/test/Adapter/Http/FileResolverTest.php @@ -19,7 +19,7 @@ * @license http://framework.zend.com/license/new-bsd New BSD License */ -namespace ZendTest\Auth\Adapter\Http; +namespace ZendTest\Authentication\Adapter\Http; use Zend\Authentication\Adapter\Http; diff --git a/test/Adapter/Http/ObjectTest.php b/test/Adapter/Http/ObjectTest.php index 8bea5d6..9bb86f1 100644 --- a/test/Adapter/Http/ObjectTest.php +++ b/test/Adapter/Http/ObjectTest.php @@ -19,7 +19,7 @@ * @license http://framework.zend.com/license/new-bsd New BSD License */ -namespace ZendTest\Auth\Adapter\Http; +namespace ZendTest\Authentication\Adapter\Http; use Zend\Authentication\Adapter\Http, Zend\Authentication\Adapter, diff --git a/test/Adapter/Http/ProxyTest.php b/test/Adapter/Http/ProxyTest.php index 618eee4..346bd07 100644 --- a/test/Adapter/Http/ProxyTest.php +++ b/test/Adapter/Http/ProxyTest.php @@ -19,7 +19,7 @@ * @license http://framework.zend.com/license/new-bsd New BSD License */ -namespace ZendTest\Auth\Adapter\Http; +namespace ZendTest\Authentication\Adapter\Http; use Zend\Authentication\Adapter\Http, Zend\Http\Headers, diff --git a/test/Adapter/Ldap/OfflineTest.php b/test/Adapter/Ldap/OfflineTest.php index 08a2446..4676c42 100644 --- a/test/Adapter/Ldap/OfflineTest.php +++ b/test/Adapter/Ldap/OfflineTest.php @@ -19,7 +19,7 @@ * @license http://framework.zend.com/license/new-bsd New BSD License */ -namespace ZendTest\Auth\Adapter\Ldap; +namespace ZendTest\Authentication\Adapter\Ldap; use Zend\Authentication\Adapter, Zend\Ldap; diff --git a/test/Adapter/Ldap/OnlineTest.php b/test/Adapter/Ldap/OnlineTest.php index c3d34bc..aaee997 100644 --- a/test/Adapter/Ldap/OnlineTest.php +++ b/test/Adapter/Ldap/OnlineTest.php @@ -19,7 +19,7 @@ * @license http://framework.zend.com/license/new-bsd New BSD License */ -namespace ZendTest\Auth\Adapter\Ldap; +namespace ZendTest\Authentication\Adapter\Ldap; use Zend\Authentication, Zend\Authentication\Adapter, From 6c3b6688c00659e5659187b4f25fad465a69cfde Mon Sep 17 00:00:00 2001 From: Nicholas Calugar Date: Wed, 16 May 2012 15:54:10 -0700 Subject: [PATCH 47/61] These interfaces were moved in dde7e64064d51dfe736593b220e65b2eda944537 --- src/Adapter/InfoCard.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Adapter/InfoCard.php b/src/Adapter/InfoCard.php index 2ec844f..985ef99 100644 --- a/src/Adapter/InfoCard.php +++ b/src/Adapter/InfoCard.php @@ -65,10 +65,10 @@ public function __construct($strXmlDocument) /** * Sets the InfoCard component Adapter to use * - * @param Zend\InfoCard\Adapter $a + * @param Zend\InfoCard\Adapter\AdapterInterface $a * @return Zend\Authentication\Adapter\InfoCard Provides a fluent interface */ - public function setAdapter(ZendInfoCard\Adapter $a) + public function setAdapter(ZendInfoCard\Adapter\AdapterInterface $a) { $this->_infoCard->setAdapter($a); return $this; @@ -77,7 +77,7 @@ public function setAdapter(ZendInfoCard\Adapter $a) /** * Retrieves the InfoCard component adapter being used * - * @return Zend\InfoCard\Adapter + * @return Zend\InfoCard\Adapter\AdapterInterface */ public function getAdapter() { @@ -87,7 +87,7 @@ public function getAdapter() /** * Retrieves the InfoCard public key cipher object being used * - * @return Zend\InfoCard\Cipher\PKI + * @return Zend\InfoCard\Cipher\PKI\PKIInterface */ public function getPKCipherObject() { @@ -97,10 +97,10 @@ public function getPKCipherObject() /** * Sets the InfoCard public key cipher object to use * - * @param Zend\InfoCard\Cipher\PKI $cipherObj + * @param Zend\InfoCard\Cipher\PKI\PKIInterface $cipherObj * @return \Zend\Authentication\Adapter\InfoCard Provides a fluent interface */ - public function setPKICipherObject(ZendInfoCard\Cipher\PKI $cipherObj) + public function setPKICipherObject(ZendInfoCard\Cipher\PKI\PKIInterface $cipherObj) { $this->_infoCard->setPKICipherObject($cipherObj); return $this; @@ -109,7 +109,7 @@ public function setPKICipherObject(ZendInfoCard\Cipher\PKI $cipherObj) /** * Retrieves the Symmetric cipher object being used * - * @return Zend\InfoCard\Cipher\Symmetric + * @return Zend\InfoCard\Cipher\Symmetric\AES128CBCInterface */ public function getSymCipherObject() { @@ -119,10 +119,10 @@ public function getSymCipherObject() /** * Sets the InfoCard symmetric cipher object to use * - * @param Zend\InfoCard\Cipher\Symmetric $cipherObj + * @param Zend\InfoCard\Cipher\Symmetric\AES128CBCInterface $cipherObj * @return Zend\Authentication\Adapter\InfoCard Provides a fluent interface */ - public function setSymCipherObject(ZendInfoCard\Cipher\Symmetric $cipherObj) + public function setSymCipherObject(ZendInfoCard\Cipher\Symmetric\AES128CBCInterface $cipherObj) { $this->_infoCard->setSymCipherObject($cipherObj); return $this; From cc934224300b71a41040d5a107c504077d876d14 Mon Sep 17 00:00:00 2001 From: Maks3w Date: Fri, 18 May 2012 00:22:37 +0200 Subject: [PATCH 48/61] [Travis] Enable Zend\Math tests --- .travis/tested-components | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis/tested-components b/.travis/tested-components index b1f4a79..9b33820 100644 --- a/.travis/tested-components +++ b/.travis/tested-components @@ -29,6 +29,7 @@ Zend/Locale Zend/Log Zend/Mail Zend/Markup +Zend/Math Zend/Measure Zend/Memory Zend/Mime From fdb149dd24b468439e530790a5a353e371cd2e18 Mon Sep 17 00:00:00 2001 From: prolic Date: Wed, 23 May 2012 21:56:07 +0200 Subject: [PATCH 49/61] fixed phpdoc in Zend\Auth --- src/Adapter/AdapterInterface.php | 4 +-- src/Adapter/DbTable.php | 10 ++++---- src/Adapter/Digest.php | 13 +++++----- src/Adapter/Http.php | 41 +++++++++++++++--------------- src/Adapter/Http/FileResolver.php | 7 +++-- src/Adapter/InfoCard.php | 29 ++++++++++----------- src/Adapter/Ldap.php | 13 +++++----- src/AuthenticationService.php | 23 ++++++++--------- src/Exception/RuntimeException.php | 5 ++-- src/Result.php | 1 - src/Storage/Session.php | 8 +++--- src/Storage/StorageInterface.php | 8 +++--- 12 files changed, 77 insertions(+), 85 deletions(-) diff --git a/src/Adapter/AdapterInterface.php b/src/Adapter/AdapterInterface.php index de6c431..d5584d5 100644 --- a/src/Adapter/AdapterInterface.php +++ b/src/Adapter/AdapterInterface.php @@ -33,8 +33,8 @@ interface AdapterInterface /** * Performs an authentication attempt * - * @return Zend\Authentication\Result - * @throws Zend\Authentication\Adapter\Exception\ExceptionInterface If authentication cannot be performed + * @return \Zend\Authentication\Result + * @throws \Zend\Authentication\Adapter\Exception\ExceptionInterface If authentication cannot be performed */ public function authenticate(); } diff --git a/src/Adapter/DbTable.php b/src/Adapter/DbTable.php index e2196ce..cc7b893 100644 --- a/src/Adapter/DbTable.php +++ b/src/Adapter/DbTable.php @@ -21,11 +21,11 @@ namespace Zend\Authentication\Adapter; -use Zend\Authentication\Result as AuthenticationResult, - Zend\Db\Adapter\Adapter as DbAdapter, - Zend\Db\Sql\Select as DbSelect, - Zend\Db\Sql\Expression, - Zend\Db\ResultSet\ResultSet; +use Zend\Authentication\Result as AuthenticationResult; +use Zend\Db\Adapter\Adapter as DbAdapter; +use Zend\Db\ResultSet\ResultSet; +use Zend\Db\Sql\Expression; +use Zend\Db\Sql\Select as DbSelect; /** * @category Zend diff --git a/src/Adapter/Digest.php b/src/Adapter/Digest.php index ad21cc8..ff2c403 100644 --- a/src/Adapter/Digest.php +++ b/src/Adapter/Digest.php @@ -67,7 +67,6 @@ class Digest implements AdapterInterface * @param mixed $realm * @param mixed $username * @param mixed $password - * @return void */ public function __construct($filename = null, $realm = null, $username = null, $password = null) { @@ -94,7 +93,7 @@ public function getFilename() * Sets the filename option value * * @param mixed $filename - * @return Zend\Authentication\Adapter\Digest Provides a fluent interface + * @return Digest Provides a fluent interface */ public function setFilename($filename) { @@ -116,7 +115,7 @@ public function getRealm() * Sets the realm option value * * @param mixed $realm - * @return Zend\Authentication\Adapter\Digest Provides a fluent interface + * @return Digest Provides a fluent interface */ public function setRealm($realm) { @@ -138,7 +137,7 @@ public function getUsername() * Sets the username option value * * @param mixed $username - * @return Zend\Authentication\Adapter\Digest Provides a fluent interface + * @return Digest Provides a fluent interface */ public function setUsername($username) { @@ -160,7 +159,7 @@ public function getPassword() * Sets the password option value * * @param mixed $password - * @return Zend\Authentication\Adapter\Digest Provides a fluent interface + * @return Digest Provides a fluent interface */ public function setPassword($password) { @@ -171,8 +170,8 @@ public function setPassword($password) /** * Defined by Zend\Authentication\Adapter\AdapterInterface * - * @throws Zend\Authentication\Adapter\Exception\ExceptionInterface - * @return Zend\Authentication\Result + * @throws Exception\ExceptionInterface + * @return AuthenticationResult */ public function authenticate() { diff --git a/src/Adapter/Http.php b/src/Adapter/Http.php index 0454c9f..7d56241 100644 --- a/src/Adapter/Http.php +++ b/src/Adapter/Http.php @@ -21,10 +21,10 @@ namespace Zend\Authentication\Adapter; -use Zend\Authentication, - Zend\Http\Request as HTTPRequest, - Zend\Http\Response as HTTPResponse, - Zend\Uri\UriFactory; +use Zend\Authentication; +use Zend\Http\Request as HTTPRequest; +use Zend\Http\Response as HTTPResponse; +use Zend\Uri\UriFactory; /** * HTTP Authentication Adapter @@ -59,14 +59,14 @@ class Http implements AdapterInterface /** * Object that looks up user credentials for the Basic scheme * - * @var Zend\Authentication\Adapter\Http\Resolver + * @var Http\ResolverInterface */ protected $_basicResolver; /** * Object that looks up user credentials for the Digest scheme * - * @var Zend\Authentication\Adapter\Http\Resolver + * @var Http\ResolverInterface */ protected $_digestResolver; @@ -161,8 +161,7 @@ class Http implements AdapterInterface * 'use_opaque' => Whether to send the opaque value in the header * 'alogrithm' => See $_supportedAlgos. Default: MD5 * 'proxy_auth' => Whether to do authentication as a Proxy - * @throws Zend\Authentication\Adapter\InvalidArgumentException - * @return void + * @throws Exception\InvalidArgumentException */ public function __construct(array $config) { @@ -241,8 +240,8 @@ public function __construct(array $config) /** * Setter for the _basicResolver property * - * @param Zend\Authentication\Adapter\Http\ResolverInterface $resolver - * @return Zend\Authentication\Adapter\Http Provides a fluent interface + * @param Http\ResolverInterface $resolver + * @return Http Provides a fluent interface */ public function setBasicResolver(Http\ResolverInterface $resolver) { @@ -254,7 +253,7 @@ public function setBasicResolver(Http\ResolverInterface $resolver) /** * Getter for the _basicResolver property * - * @return Zend\Authentication\Adapter\Http\ResolverInterface + * @return Http\ResolverInterface */ public function getBasicResolver() { @@ -264,8 +263,8 @@ public function getBasicResolver() /** * Setter for the _digestResolver property * - * @param Zend\Authentication\Adapter\Http\ResolverInterface $resolver - * @return Zend\Authentication\Adapter\Http Provides a fluent interface + * @param Http\ResolverInterface $resolver + * @return Http Provides a fluent interface */ public function setDigestResolver(Http\ResolverInterface $resolver) { @@ -277,7 +276,7 @@ public function setDigestResolver(Http\ResolverInterface $resolver) /** * Getter for the _digestResolver property * - * @return Zend\Authentication\Adapter\Http\ResolverInterface + * @return Http\ResolverInterface */ public function getDigestResolver() { @@ -333,8 +332,8 @@ public function getResponse() /** * Authenticate * - * @throws Zend\Authentication\Adapter\Exception\RuntimeException - * @return Zend\Authentication\Result + * @throws Exception\RuntimeException + * @return Authentication\Result */ public function authenticate() { @@ -398,7 +397,7 @@ public function authenticate() * Sets a 401 or 407 Unauthorized response code, and creates the * appropriate Authenticate header(s) to prompt for credentials. * - * @return Zend\Authentication\Result Always returns a non-identity Auth result + * @return Authentication\Result Always returns a non-identity Auth result */ protected function _challengeClient() { @@ -464,8 +463,8 @@ protected function _digestHeader() * Basic Authentication * * @param string $header Client's Authorization header - * @throws Zend\Authentication\Exception\ExceptionInterface - * @return Zend\Authentication\Result + * @throws Exception\ExceptionInterface + * @return Authentication\Result */ protected function _basicAuth($header) { @@ -511,8 +510,8 @@ protected function _basicAuth($header) * Digest Authentication * * @param string $header Client's Authorization header - * @throws Zend\Authentication\Adapter\Exception\ExceptionInterface - * @return Zend\Authentication\Result Valid auth result only on successful auth + * @throws Exception\ExceptionInterface + * @return Authentication\Result Valid auth result only on successful auth */ protected function _digestAuth($header) { diff --git a/src/Adapter/Http/FileResolver.php b/src/Adapter/Http/FileResolver.php index e0660eb..3dbf44c 100644 --- a/src/Adapter/Http/FileResolver.php +++ b/src/Adapter/Http/FileResolver.php @@ -43,7 +43,6 @@ class FileResolver implements ResolverInterface * Constructor * * @param string $path Complete filename where the credentials are stored - * @return void */ public function __construct($path = '') { @@ -56,8 +55,8 @@ public function __construct($path = '') * Set the path to the credentials file * * @param string $path - * @return Zend\Authentication\Adapter\Http\FileResolver Provides a fluent interface - * @throws Zend\Authentication\Adapter\Http\Exception\ExceptionInterface + * @return FileResolver Provides a fluent interface + * @throws Exception\ExceptionInterface */ public function setFile($path) { @@ -98,7 +97,7 @@ public function getFile() * @param string $realm Authentication Realm * @return string|false User's shared secret, if the user is found in the * realm, false otherwise. - * @throws Zend\Authentication\Adapter\Http\Exception\ExceptionInterface + * @throws Exception\ExceptionInterface */ public function resolve($username, $realm) { diff --git a/src/Adapter/InfoCard.php b/src/Adapter/InfoCard.php index 985ef99..6ae99ce 100644 --- a/src/Adapter/InfoCard.php +++ b/src/Adapter/InfoCard.php @@ -54,7 +54,6 @@ class InfoCard implements AdapterInterface * Constructor * * @param string $strXmlDocument The XML Token provided by the client - * @return void */ public function __construct($strXmlDocument) { @@ -65,8 +64,8 @@ public function __construct($strXmlDocument) /** * Sets the InfoCard component Adapter to use * - * @param Zend\InfoCard\Adapter\AdapterInterface $a - * @return Zend\Authentication\Adapter\InfoCard Provides a fluent interface + * @param ZendInfoCard\Adapter\AdapterInterface $a + * @return InfoCard Provides a fluent interface */ public function setAdapter(ZendInfoCard\Adapter\AdapterInterface $a) { @@ -77,7 +76,7 @@ public function setAdapter(ZendInfoCard\Adapter\AdapterInterface $a) /** * Retrieves the InfoCard component adapter being used * - * @return Zend\InfoCard\Adapter\AdapterInterface + * @return AdapterInterface */ public function getAdapter() { @@ -87,7 +86,7 @@ public function getAdapter() /** * Retrieves the InfoCard public key cipher object being used * - * @return Zend\InfoCard\Cipher\PKI\PKIInterface + * @return ZendInfoCard\Cipher\PKI\PKIInterface */ public function getPKCipherObject() { @@ -97,8 +96,8 @@ public function getPKCipherObject() /** * Sets the InfoCard public key cipher object to use * - * @param Zend\InfoCard\Cipher\PKI\PKIInterface $cipherObj - * @return \Zend\Authentication\Adapter\InfoCard Provides a fluent interface + * @param ZendInfoCard\Cipher\PKI\PKIInterface $cipherObj + * @return InfoCard Provides a fluent interface */ public function setPKICipherObject(ZendInfoCard\Cipher\PKI\PKIInterface $cipherObj) { @@ -109,7 +108,7 @@ public function setPKICipherObject(ZendInfoCard\Cipher\PKI\PKIInterface $cipherO /** * Retrieves the Symmetric cipher object being used * - * @return Zend\InfoCard\Cipher\Symmetric\AES128CBCInterface + * @return ZendInfoCard\Cipher\Symmetric\AES128CBCInterface */ public function getSymCipherObject() { @@ -119,8 +118,8 @@ public function getSymCipherObject() /** * Sets the InfoCard symmetric cipher object to use * - * @param Zend\InfoCard\Cipher\Symmetric\AES128CBCInterface $cipherObj - * @return Zend\Authentication\Adapter\InfoCard Provides a fluent interface + * @param ZendInfoCard\Cipher\Symmetric\AES128CBCInterface $cipherObj + * @return InfoCard Provides a fluent interface */ public function setSymCipherObject(ZendInfoCard\Cipher\Symmetric\AES128CBCInterface $cipherObj) { @@ -132,8 +131,8 @@ public function setSymCipherObject(ZendInfoCard\Cipher\Symmetric\AES128CBCInterf * Remove a Certificate Pair by Key ID from the search list * * @param string $keyId The Certificate Key ID returned from adding the certificate pair - * @throws Zend\InfoCard\Exception - * @return Zend\Authentication\Adapter\InfoCard Provides a fluent interface + * @throws ZendInfoCard\Exception\ExceptionInterface + * @return InfoCard Provides a fluent interface */ public function removeCertificatePair($keyId) { @@ -148,7 +147,7 @@ public function removeCertificatePair($keyId) * @param string $publicKeyFile The path to the certificate / public key for the pair * @param string $type (optional) The URI for the type of key pair this is (default RSA with OAEP padding) * @param string $password (optional) The password for the private key file if necessary - * @throws Zend\InfoCard\Exception + * @throws ZendInfoCard\Exception\ExceptionInterface * @return string A key ID representing this key pair in the component */ public function addCertificatePair($privateKeyFile, $publicKeyFile, $type = ZendInfoCard\Cipher::ENC_RSA_OAEP_MGF1P, $password = null) @@ -160,7 +159,7 @@ public function addCertificatePair($privateKeyFile, $publicKeyFile, $type = Zend * Return a Certificate Pair from a key ID * * @param string $keyId The Key ID of the certificate pair in the component - * @throws Zend\InfoCard\Exception + * @throws ZendInfoCard\Exception\ExceptionInterface * @return array An array containing the path to the private/public key files, * the type URI and the password if provided */ @@ -194,7 +193,7 @@ public function getXmlToken() /** * Authenticates the XML token * - * @return Zend\Authentication\Result The result of the authentication + * @return AuthenticationResult The result of the authentication */ public function authenticate() { diff --git a/src/Adapter/Ldap.php b/src/Adapter/Ldap.php index 519cda3..e248c6f 100644 --- a/src/Adapter/Ldap.php +++ b/src/Adapter/Ldap.php @@ -21,9 +21,9 @@ namespace Zend\Authentication\Adapter; -use Zend\Authentication\Result as AuthenticationResult, - Zend\Ldap as ZendLdap, - Zend\Ldap\Exception\LdapException; +use Zend\Authentication\Result as AuthenticationResult; +use Zend\Ldap as ZendLdap; +use Zend\Ldap\Exception\LdapException; /** * @category Zend @@ -76,7 +76,6 @@ class Ldap implements AdapterInterface * @param array $options An array of arrays of Zend\Ldap\Ldap options * @param string $username The username of the account being authenticated * @param string $password The password of the account being authenticated - * @return void */ public function __construct(array $options = array(), $username = null, $password = null) { @@ -235,8 +234,8 @@ protected function getAuthorityName() /** * Authenticate the user * - * @return Zend\Authentication\Result - * @throws Zend\Authentication\Adapter\Exception\ExceptionInterface + * @return AuthenticationResult + * @throws Exception\ExceptionInterface */ public function authenticate() { @@ -273,7 +272,7 @@ public function authenticate() foreach ($this->options as $name => $options) { if (!is_array($options)) { - throw new InvalidArgumentException('Adapter options array not an array'); + throw new Exception\InvalidArgumentException('Adapter options array not an array'); } $adapterOptions = $this->prepareOptions($ldap, $options); $dname = ''; diff --git a/src/AuthenticationService.php b/src/AuthenticationService.php index 8c78df6..26b9095 100644 --- a/src/AuthenticationService.php +++ b/src/AuthenticationService.php @@ -31,14 +31,14 @@ class AuthenticationService /** * Persistent storage handler * - * @var Zend\Authentication\Storage\StorageInterface + * @var Storage\StorageInterface */ protected $storage = null; /** * Authentication adapter * - * @var Zend\Authentication\Adapter\AdapterInterface + * @var Adapter\AdapterInterface */ protected $adapter = null; @@ -47,7 +47,6 @@ class AuthenticationService * * @param Storage\StorageInterface $storage * @param Adapter\AdapterInterface $adapter - * @return void */ public function __construct(Storage\StorageInterface $storage = null, Adapter\AdapterInterface $adapter = null) { @@ -64,7 +63,7 @@ public function __construct(Storage\StorageInterface $storage = null, Adapter\Ad * * The adapter does not have a default if the storage adapter has not been set. * - * @return Zend\Authentication\Adapter\AdapterInterface|null + * @return Adapter\AdapterInterface|null */ public function getAdapter() { @@ -74,8 +73,8 @@ public function getAdapter() /** * Sets the authentication adapter * - * @param Zend\Authentication\Adapter\AdapterInterface $adapter - * @return Zend\Authentication\AuthenticationService Provides a fluent interface + * @param Adapter\AdapterInterface $adapter + * @return AuthenticationService Provides a fluent interface */ public function setAdapter(Adapter\AdapterInterface $adapter) { @@ -88,7 +87,7 @@ public function setAdapter(Adapter\AdapterInterface $adapter) * * Session storage is used by default unless a different storage adapter has been set. * - * @return Zend\Authentication\Storage\StorageInterface + * @return Storage\StorageInterface */ public function getStorage() { @@ -102,8 +101,8 @@ public function getStorage() /** * Sets the persistent storage handler * - * @param Zend\Authentication\Storage\StorageInterface $storage - * @return Zend\Authentication\AuthenticationService Provides a fluent interface + * @param Storage\StorageInterface $storage + * @return AuthenticationService Provides a fluent interface */ public function setStorage(Storage\StorageInterface $storage) { @@ -114,9 +113,9 @@ public function setStorage(Storage\StorageInterface $storage) /** * Authenticates against the supplied adapter * - * @param Zend\Authentication\Adapter\AdapterInterface $adapter - * @return Zend\Authentication\Result - * @throws Zend\Authentication\Exception\RuntimeException + * @param Adapter\AdapterInterface $adapter + * @return Result + * @throws Exception\RuntimeException */ public function authenticate(Adapter\AdapterInterface $adapter = null) { diff --git a/src/Exception/RuntimeException.php b/src/Exception/RuntimeException.php index 08d6384..8a787d2 100755 --- a/src/Exception/RuntimeException.php +++ b/src/Exception/RuntimeException.php @@ -28,8 +28,7 @@ * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ -class RuntimeException - extends \RuntimeException - implements ExceptionInterface +class RuntimeException extends \RuntimeException implements + ExceptionInterface { } diff --git a/src/Result.php b/src/Result.php index 0e32f15..9d4a5f2 100644 --- a/src/Result.php +++ b/src/Result.php @@ -87,7 +87,6 @@ class Result * @param int $code * @param mixed $identity * @param array $messages - * @return void */ public function __construct($code, $identity, array $messages = array()) { diff --git a/src/Storage/Session.php b/src/Storage/Session.php index 1f6830a..8399775 100644 --- a/src/Storage/Session.php +++ b/src/Storage/Session.php @@ -21,9 +21,9 @@ namespace Zend\Authentication\Storage; -use Zend\Authentication\Storage\StorageInterface as AuthenticationStorage, - Zend\Session\Container as SessionContainer, - Zend\Session\ManagerInterface as SessionManager; +use Zend\Authentication\Storage\StorageInterface as AuthenticationStorage; +use Zend\Session\Container as SessionContainer; +use Zend\Session\ManagerInterface as SessionManager; /** * @category Zend @@ -70,7 +70,7 @@ class Session implements StorageInterface * * @param mixed $namespace * @param mixed $member - * @return void + * @param SessionManager $manager */ public function __construct($namespace = null, $member = null, SessionManager $manager = null) { diff --git a/src/Storage/StorageInterface.php b/src/Storage/StorageInterface.php index 8e52762..425e34f 100644 --- a/src/Storage/StorageInterface.php +++ b/src/Storage/StorageInterface.php @@ -33,7 +33,7 @@ interface StorageInterface /** * Returns true if and only if storage is empty * - * @throws Zend\Authentication\Storage\Exception\ExceptionInterface If it is impossible to determine whether storage is empty + * @throws \Zend\Authentication\Exception\ExceptionInterface If it is impossible to determine whether storage is empty * @return boolean */ public function isEmpty(); @@ -43,7 +43,7 @@ public function isEmpty(); * * Behavior is undefined when storage is empty. * - * @throws Zend\Authentication\Storage\Exception\ExceptionInterface If reading contents from storage is impossible + * @throws \Zend\Authentication\Exception\ExceptionInterface If reading contents from storage is impossible * @return mixed */ public function read(); @@ -52,7 +52,7 @@ public function read(); * Writes $contents to storage * * @param mixed $contents - * @throws Zend\Authentication\Storage\Exception\ExceptionInterface If writing $contents to storage is impossible + * @throws \Zend\Authentication\Exception\ExceptionInterface If writing $contents to storage is impossible * @return void */ public function write($contents); @@ -60,7 +60,7 @@ public function write($contents); /** * Clears contents from storage * - * @throws Zend\Authentication\Storage\Exception\ExceptionInterface If clearing contents from storage is impossible + * @throws \Zend\Authentication\Exception\ExceptionInterface If clearing contents from storage is impossible * @return void */ public function clear(); From 6fafc84a7519a623e530d41fa4015fe0e6fe3f2f Mon Sep 17 00:00:00 2001 From: David Windell Date: Tue, 3 Jul 2012 17:18:42 +0100 Subject: [PATCH 50/61] Made password optional in interface, CS fix --- src/Adapter/Http.php | 10 ++++++---- src/Adapter/Http/ResolverInterface.php | 4 ++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/Adapter/Http.php b/src/Adapter/Http.php index d34ae63..c76062c 100644 --- a/src/Adapter/Http.php +++ b/src/Adapter/Http.php @@ -497,9 +497,11 @@ protected function _basicAuth($header) } $result = $this->_basicResolver->resolve($creds[0], $this->_realm, $creds[1]); - if ($result && - !is_array($result) && - $this->_secureStringCompare($result, $creds[1])) { + + if ($result + && !is_array($result) + && $this->_secureStringCompare($result, $creds[1]) + ) { $identity = array('username'=>$creds[0], 'realm'=>$this->_realm); return new Authentication\Result(Authentication\Result::SUCCESS, $identity); } elseif (is_array($result)) { @@ -555,7 +557,7 @@ protected function _digestAuth($header) // This makes no assumptions about how the password hash was // constructed beyond that it must have been built in such a way as // to be recreatable with the current settings of this object. - $ha1 = $this->_digestResolver->resolve($data['username'], $data['realm'], null); + $ha1 = $this->_digestResolver->resolve($data['username'], $data['realm']); if ($ha1 === false) { return $this->_challengeClient(); } diff --git a/src/Adapter/Http/ResolverInterface.php b/src/Adapter/Http/ResolverInterface.php index 229249b..6bebf67 100644 --- a/src/Adapter/Http/ResolverInterface.php +++ b/src/Adapter/Http/ResolverInterface.php @@ -40,9 +40,9 @@ interface ResolverInterface * * @param string $username Username * @param string $realm Authentication Realm - * @param string $password Password + * @param string $password Password (optional) * @return string|array|false User's shared secret as string if found in realm, or User's identity as array * if resolved, false otherwise. */ - public function resolve($username, $realm, $password); + public function resolve($username, $realm, $password = null); } From 4e182e516aab4334fcbc42dd4eb4f6cf52be4301 Mon Sep 17 00:00:00 2001 From: Maks3w Date: Mon, 9 Jul 2012 16:19:42 +0200 Subject: [PATCH 51/61] [CS][Library] Set File Header http://framework.zend.com/wiki/display/ZFDEV2/Coding+Standards#CodingStandards-Files The following script replaces the content between PHP open tag and namespace declaration. for COMPONENT in $(ls -d *) do for FILE in $(find $COMPONENT -name "*.php") do BLOCK="\/\*\*\n \* Zend Framework \(http:\/\/framework\.zend\.com\/\)\n \*\n \* \@link http:\/\/github\.com\/zendframework\/zf2 for the canonical source repository\n \* \@copyright Copyright \(c\) 2005-2012 Zend Technologies USA Inc\. \(http:\/\/www\.zend\.com\)\n \* \@license http:\/\/framework\.zend\.com\/license\/new-bsd New BSD License\n \* \@package Zend_$COMPONENT\n \*\/" perl -0777 -i -pe "s/(<\?php(\s*.*)*\nn)/ Date: Mon, 9 Jul 2012 16:34:21 +0200 Subject: [PATCH 52/61] [CS][test] Remove @copyright & @license for fl in $(find . -name "*.php"); do mv $fl $fl.old; sed '/@copyright/d' $fl.old > $fl; rm -f $fl.old; done; for fl in $(find . -name "*.php"); do mv $fl $fl.old; sed '/@license/d' $fl.old > $fl; rm -f $fl.old; done; --- test/Adapter/DbTableTest.php | 4 ---- test/Adapter/DigestTest.php | 4 ---- test/Adapter/Http/AuthTest.php | 4 ---- test/Adapter/Http/FileResolverTest.php | 4 ---- test/Adapter/Http/ObjectTest.php | 4 ---- test/Adapter/Http/ProxyTest.php | 4 ---- test/Adapter/Ldap/OfflineTest.php | 4 ---- test/Adapter/Ldap/OnlineTest.php | 4 ---- test/Adapter/TestAsset/OpenIdResponseHelper.php | 4 ---- test/AuthenticationServiceTest.php | 4 ---- 10 files changed, 40 deletions(-) diff --git a/test/Adapter/DbTableTest.php b/test/Adapter/DbTableTest.php index 6582c07..900346a 100644 --- a/test/Adapter/DbTableTest.php +++ b/test/Adapter/DbTableTest.php @@ -15,8 +15,6 @@ * @category Zend * @package Zend_Auth * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License */ namespace ZendTest\Authentication\Adapter; @@ -30,8 +28,6 @@ * @category Zend * @package Zend_Auth * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License * @group Zend_Auth * @group Zend_Db_Table */ diff --git a/test/Adapter/DigestTest.php b/test/Adapter/DigestTest.php index 309abd8..f4d0b1c 100644 --- a/test/Adapter/DigestTest.php +++ b/test/Adapter/DigestTest.php @@ -15,8 +15,6 @@ * @category Zend * @package Zend_Auth * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License */ namespace ZendTest\Authentication\Adapter; @@ -28,8 +26,6 @@ * @category Zend * @package Zend_Auth * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License * @group Zend_Auth */ class DigestTest extends \PHPUnit_Framework_TestCase diff --git a/test/Adapter/Http/AuthTest.php b/test/Adapter/Http/AuthTest.php index ec13e7f..ccb128b 100644 --- a/test/Adapter/Http/AuthTest.php +++ b/test/Adapter/Http/AuthTest.php @@ -15,8 +15,6 @@ * @category Zend * @package Zend_Auth * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License */ namespace ZendTest\Authentication\Adapter\Http; @@ -31,8 +29,6 @@ * @category Zend * @package Zend_Auth * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License * @group Zend_Auth */ class AuthTest extends \PHPUnit_Framework_TestCase diff --git a/test/Adapter/Http/FileResolverTest.php b/test/Adapter/Http/FileResolverTest.php index 0d75554..378207c 100644 --- a/test/Adapter/Http/FileResolverTest.php +++ b/test/Adapter/Http/FileResolverTest.php @@ -15,8 +15,6 @@ * @category Zend * @package Zend_Auth * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License */ namespace ZendTest\Authentication\Adapter\Http; @@ -27,8 +25,6 @@ * @category Zend * @package Zend_Auth * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License * @group Zend_Auth */ class FileTest extends \PHPUnit_Framework_TestCase diff --git a/test/Adapter/Http/ObjectTest.php b/test/Adapter/Http/ObjectTest.php index bce9278..4a1c332 100644 --- a/test/Adapter/Http/ObjectTest.php +++ b/test/Adapter/Http/ObjectTest.php @@ -15,8 +15,6 @@ * @category Zend * @package Zend_Auth * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License */ namespace ZendTest\Authentication\Adapter\Http; @@ -32,8 +30,6 @@ * @category Zend * @package Zend_Auth * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License * @group Zend_Auth */ class ObjectTest extends \PHPUnit_Framework_TestCase diff --git a/test/Adapter/Http/ProxyTest.php b/test/Adapter/Http/ProxyTest.php index 9e4472d..c9f537c 100644 --- a/test/Adapter/Http/ProxyTest.php +++ b/test/Adapter/Http/ProxyTest.php @@ -15,8 +15,6 @@ * @category Zend * @package Zend_Auth * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License */ namespace ZendTest\Authentication\Adapter\Http; @@ -31,8 +29,6 @@ * @category Zend * @package Zend_Auth * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License * @group Zend_Auth */ class ProxyTest extends \PHPUnit_Framework_TestCase diff --git a/test/Adapter/Ldap/OfflineTest.php b/test/Adapter/Ldap/OfflineTest.php index 4676c42..e5fa142 100644 --- a/test/Adapter/Ldap/OfflineTest.php +++ b/test/Adapter/Ldap/OfflineTest.php @@ -15,8 +15,6 @@ * @category Zend * @package Zend_Auth * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License */ namespace ZendTest\Authentication\Adapter\Ldap; @@ -28,8 +26,6 @@ * @category Zend * @package Zend_Auth * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License * @group Zend_Auth */ class OfflineTest extends \PHPUnit_Framework_TestCase diff --git a/test/Adapter/Ldap/OnlineTest.php b/test/Adapter/Ldap/OnlineTest.php index aaee997..1eddfff 100644 --- a/test/Adapter/Ldap/OnlineTest.php +++ b/test/Adapter/Ldap/OnlineTest.php @@ -15,8 +15,6 @@ * @category Zend * @package Zend_Auth * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License */ namespace ZendTest\Authentication\Adapter\Ldap; @@ -29,8 +27,6 @@ * @category Zend * @package Zend_Auth * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License * @group Zend_Auth */ class OnlineTest extends \PHPUnit_Framework_TestCase diff --git a/test/Adapter/TestAsset/OpenIdResponseHelper.php b/test/Adapter/TestAsset/OpenIdResponseHelper.php index e213487..3fe25b6 100644 --- a/test/Adapter/TestAsset/OpenIdResponseHelper.php +++ b/test/Adapter/TestAsset/OpenIdResponseHelper.php @@ -15,8 +15,6 @@ * @category Zend * @package Zend_OpenId * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License */ namespace ZendTest\Authentication\Adapter\TestAsset; @@ -30,8 +28,6 @@ * @category Zend * @package Zend_Authentication * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License */ class ResponseHelper extends Response { diff --git a/test/AuthenticationServiceTest.php b/test/AuthenticationServiceTest.php index 3843fb9..8cbec1a 100644 --- a/test/AuthenticationServiceTest.php +++ b/test/AuthenticationServiceTest.php @@ -15,8 +15,6 @@ * @category Zend * @package Zend_Config * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License */ namespace ZendTest\Authentication; @@ -28,8 +26,6 @@ * @category Zend * @package Zend_Auth * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License * @group Zend_Auth */ class AuthenticationServiceTest extends \PHPUnit_Framework_TestCase From 5d7674ac7bc293b7022e1e916f89a98a1dd9c8e7 Mon Sep 17 00:00:00 2001 From: Maks3w Date: Mon, 9 Jul 2012 16:41:27 +0200 Subject: [PATCH 53/61] [CS][Tests] Set File Header http://framework.zend.com/wiki/display/ZFDEV2/Coding+Standards#CodingStandards-Files The following script replaces the content between PHP open tag and namespace declaration. for COMPONENT in $(ls -d *) do for FILE in $(find $COMPONENT -name "*.php") do BLOCK="\/\*\*\n \* Zend Framework \(http:\/\/framework\.zend\.com\/\)\n \*\n \* \@link http:\/\/github\.com\/zendframework\/zf2 for the canonical source repository\n \* \@copyright Copyright \(c\) 2005-2012 Zend Technologies USA Inc\. \(http:\/\/www\.zend\.com\)\n \* \@license http:\/\/framework\.zend\.com\/license\/new-bsd New BSD License\n \* \@package Zend_$COMPONENT\n \*\/" perl -0777 -i -pe "s/(<\?php(\s*.*)*\nn)/ Date: Thu, 12 Jul 2012 21:11:36 +0200 Subject: [PATCH 54/61] [PSR-2] fixers=braces,elseif,short_tag,php_closing_tag,trailing_spaces,linefeed Applied php-cs-fixer --fixers=braces,elseif,short_tag,php_closing_tag,trailing_spaces,linefeed --- src/Adapter/Exception/InvalidArgumentException.php | 2 +- src/Adapter/Exception/RuntimeException.php | 2 +- src/Adapter/Exception/UnexpectedValueException.php | 2 +- src/Adapter/Http.php | 2 +- src/Adapter/Http/Exception/InvalidArgumentException.php | 2 +- src/Adapter/Http/Exception/RuntimeException.php | 2 +- src/Adapter/Http/FileResolver.php | 4 ++-- src/Adapter/Ldap.php | 4 ++-- src/AuthenticationService.php | 6 +++--- src/Exception/InvalidArgumentException.php | 2 +- src/Exception/UnexpectedValueException.php | 2 +- 11 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/Adapter/Exception/InvalidArgumentException.php b/src/Adapter/Exception/InvalidArgumentException.php index 1fcab08..8c9f845 100644 --- a/src/Adapter/Exception/InvalidArgumentException.php +++ b/src/Adapter/Exception/InvalidArgumentException.php @@ -16,4 +16,4 @@ class InvalidArgumentException extends Exception\InvalidArgumentException implements ExceptionInterface { -} +} diff --git a/src/Adapter/Exception/RuntimeException.php b/src/Adapter/Exception/RuntimeException.php index 9b20a26..a4f2604 100644 --- a/src/Adapter/Exception/RuntimeException.php +++ b/src/Adapter/Exception/RuntimeException.php @@ -17,7 +17,7 @@ * @package Zend_Authentication * @subpackage Adapter */ -class RuntimeException extends Exception\RuntimeException implements +class RuntimeException extends Exception\RuntimeException implements ExceptionInterface { } diff --git a/src/Adapter/Exception/UnexpectedValueException.php b/src/Adapter/Exception/UnexpectedValueException.php index 1f64d86..2fab790 100644 --- a/src/Adapter/Exception/UnexpectedValueException.php +++ b/src/Adapter/Exception/UnexpectedValueException.php @@ -17,7 +17,7 @@ * @package Zend_Authentication * @subpackage Adapter */ -class UnexpectedValueException extends Exception\UnexpectedValueException implements +class UnexpectedValueException extends Exception\UnexpectedValueException implements ExceptionInterface { } diff --git a/src/Adapter/Http.php b/src/Adapter/Http.php index ff96803..3de0aac 100644 --- a/src/Adapter/Http.php +++ b/src/Adapter/Http.php @@ -484,7 +484,7 @@ protected function _basicAuth($header) } $result = $this->_basicResolver->resolve($creds[0], $this->_realm, $creds[1]); - + if ($result && !is_array($result) && $this->_secureStringCompare($result, $creds[1]) diff --git a/src/Adapter/Http/Exception/InvalidArgumentException.php b/src/Adapter/Http/Exception/InvalidArgumentException.php index 5191c5f..3567fe3 100644 --- a/src/Adapter/Http/Exception/InvalidArgumentException.php +++ b/src/Adapter/Http/Exception/InvalidArgumentException.php @@ -17,7 +17,7 @@ * @package Zend_Authentication * @subpackage Adapter_Http */ -class InvalidArgumentException extends Exception\InvalidArgumentException implements +class InvalidArgumentException extends Exception\InvalidArgumentException implements ExceptionInterface { } diff --git a/src/Adapter/Http/Exception/RuntimeException.php b/src/Adapter/Http/Exception/RuntimeException.php index 8bffcfa..f5ba6a4 100644 --- a/src/Adapter/Http/Exception/RuntimeException.php +++ b/src/Adapter/Http/Exception/RuntimeException.php @@ -17,7 +17,7 @@ * @package Zend_Authentication * @subpackage Adapter_Http */ -class RuntimeException extends Exception\RuntimeException implements +class RuntimeException extends Exception\RuntimeException implements ExceptionInterface { } diff --git a/src/Adapter/Http/FileResolver.php b/src/Adapter/Http/FileResolver.php index 72f1d0c..96ccf7f 100644 --- a/src/Adapter/Http/FileResolver.php +++ b/src/Adapter/Http/FileResolver.php @@ -90,13 +90,13 @@ public function resolve($username, $realm, $password = null) { if (empty($username)) { throw new Exception\InvalidArgumentException('Username is required'); - } else if (!ctype_print($username) || strpos($username, ':') !== false) { + } elseif (!ctype_print($username) || strpos($username, ':') !== false) { throw new Exception\InvalidArgumentException('Username must consist only of printable characters, ' . 'excluding the colon'); } if (empty($realm)) { throw new Exception\InvalidArgumentException('Realm is required'); - } else if (!ctype_print($realm) || strpos($realm, ':') !== false) { + } elseif (!ctype_print($realm) || strpos($realm, ':') !== false) { throw new Exception\InvalidArgumentException('Realm must consist only of printable characters, ' . 'excluding the colon.'); } diff --git a/src/Adapter/Ldap.php b/src/Adapter/Ldap.php index 4a79bd6..4c874b3 100644 --- a/src/Adapter/Ldap.php +++ b/src/Adapter/Ldap.php @@ -333,11 +333,11 @@ public function authenticate() * server options. */ continue; - } else if ($err == LdapException::LDAP_NO_SUCH_OBJECT) { + } elseif ($err == LdapException::LDAP_NO_SUCH_OBJECT) { $code = AuthenticationResult::FAILURE_IDENTITY_NOT_FOUND; $messages[0] = "Account not found: $username"; $failedAuthorities[$dname] = $zle->getMessage(); - } else if ($err == LdapException::LDAP_INVALID_CREDENTIALS) { + } elseif ($err == LdapException::LDAP_INVALID_CREDENTIALS) { $code = AuthenticationResult::FAILURE_CREDENTIAL_INVALID; $messages[0] = 'Invalid credentials'; $failedAuthorities[$dname] = $zle->getMessage(); diff --git a/src/AuthenticationService.php b/src/AuthenticationService.php index d788dbb..4a63f72 100644 --- a/src/AuthenticationService.php +++ b/src/AuthenticationService.php @@ -32,9 +32,9 @@ class AuthenticationService /** * Constructor - * - * @param Storage\StorageInterface $storage - * @param Adapter\AdapterInterface $adapter + * + * @param Storage\StorageInterface $storage + * @param Adapter\AdapterInterface $adapter */ public function __construct(Storage\StorageInterface $storage = null, Adapter\AdapterInterface $adapter = null) { diff --git a/src/Exception/InvalidArgumentException.php b/src/Exception/InvalidArgumentException.php index 1fe96fd..4dcd404 100644 --- a/src/Exception/InvalidArgumentException.php +++ b/src/Exception/InvalidArgumentException.php @@ -15,7 +15,7 @@ * @package Zend_Authentication * @subpackage Exception */ -class InvalidArgumentException extends \InvalidArgumentException implements +class InvalidArgumentException extends \InvalidArgumentException implements ExceptionInterface { } diff --git a/src/Exception/UnexpectedValueException.php b/src/Exception/UnexpectedValueException.php index 79d5a9e..8743506 100644 --- a/src/Exception/UnexpectedValueException.php +++ b/src/Exception/UnexpectedValueException.php @@ -15,7 +15,7 @@ * @package Zend_Authentication * @subpackage Exception */ -class UnexpectedValueException extends \UnexpectedValueException implements +class UnexpectedValueException extends \UnexpectedValueException implements ExceptionInterface { } From 992706d60dbaf60052d64a8830a05515955123ed Mon Sep 17 00:00:00 2001 From: Denis Portnov Date: Thu, 19 Jul 2012 08:33:35 +0400 Subject: [PATCH 55/61] fix Authentication and tests --- src/Adapter/Http.php | 44 ++++++++++++++++++++------------ test/Adapter/Http/AuthTest.php | 9 +++++-- test/Adapter/Http/ObjectTest.php | 18 +++++++------ test/Adapter/Http/ProxyTest.php | 2 +- 4 files changed, 45 insertions(+), 28 deletions(-) diff --git a/src/Adapter/Http.php b/src/Adapter/Http.php index 3de0aac..336ed38 100644 --- a/src/Adapter/Http.php +++ b/src/Adapter/Http.php @@ -152,24 +152,21 @@ class Http implements AdapterInterface */ public function __construct(array $config) { - if (!extension_loaded('hash')) { - throw new Exception\InvalidArgumentException(__CLASS__ . ' requires the \'hash\' extension to be availabe in PHP'); - } - $this->_request = null; $this->_response = null; $this->_ieNoOpaque = false; - if (empty($config['accept_schemes'])) { - throw new Exception\InvalidArgumentException('Config key \'accept_schemes\' is required'); + throw new Exception\InvalidArgumentException('Config key "accept_schemes" is required'); } $schemes = explode(' ', $config['accept_schemes']); $this->_acceptSchemes = array_intersect($schemes, $this->_supportedSchemes); if (empty($this->_acceptSchemes)) { - throw new Exception\InvalidArgumentException('No supported schemes given in \'accept_schemes\'. Valid values: ' - . implode(', ', $this->_supportedSchemes)); + throw new Exception\InvalidArgumentException(sprintf( + 'No supported schemes given in "accept_schemes". Valid values: %s', + implode(', ', $this->_supportedSchemes) + )); } // Double-quotes are used to delimit the realm string in the HTTP header, @@ -178,8 +175,10 @@ public function __construct(array $config) !ctype_print($config['realm']) || strpos($config['realm'], ':') !== false || strpos($config['realm'], '"') !== false) { - throw new Exception\InvalidArgumentException('Config key \'realm\' is required, and must contain only printable ' - . 'characters, excluding quotation marks and colons'); + throw new Exception\InvalidArgumentException( + 'Config key \'realm\' is required, and must contain only printable characters,' + . 'excluding quotation marks and colons' + ); } else { $this->_realm = $config['realm']; } @@ -188,16 +187,19 @@ public function __construct(array $config) if (empty($config['digest_domains']) || !ctype_print($config['digest_domains']) || strpos($config['digest_domains'], '"') !== false) { - throw new Exception\InvalidArgumentException('Config key \'digest_domains\' is required, and must contain ' - . 'only printable characters, excluding quotation marks'); + throw new Exception\InvalidArgumentException( + 'Config key \'digest_domains\' is required, and must contain ' + . 'only printable characters, excluding quotation marks' + ); } else { $this->_domains = $config['digest_domains']; } if (empty($config['nonce_timeout']) || !is_numeric($config['nonce_timeout'])) { - throw new Exception\InvalidArgumentException('Config key \'nonce_timeout\' is required, and must be an ' - . 'integer'); + throw new Exception\InvalidArgumentException( + 'Config key \'nonce_timeout\' is required, and must be an integer' + ); } else { $this->_nonceTimeout = (int) $config['nonce_timeout']; } @@ -606,7 +608,15 @@ protected function _calcNonce() // would be surprising if the user just logged in. $timeout = ceil(time() / $this->_nonceTimeout) * $this->_nonceTimeout; - $nonce = hash('md5', $timeout . ':' . $this->_request->getServer()->get('HTTP_USER_AGENT') . ':' . __CLASS__); + $userAgentHeader = $this->_request->getHeaders()->get('User-Agent'); + if ($userAgentHeader) { + $userAgent = $userAgentHeader->getFieldValue(); + } elseif (isset($_SERVER['HTTP_USER_AGENT'])) { + $userAgent = $_SERVER['HTTP_USER_AGENT']; + } else { + $userAgent = 'Zend_Authenticaion'; + } + $nonce = hash('md5', $timeout . ':' . $userAgent . ':' . __CLASS__); return $nonce; } @@ -631,8 +641,8 @@ protected function _calcOpaque() * Parse Digest Authorization header * * @param string $header Client's Authorization: HTTP header - * @return array|false Data elements from header, or false if any part of - * the header is invalid + * @return array|bool Data elements from header, or false if any part of + * the header is invalid */ protected function _parseDigestAuth($header) { diff --git a/test/Adapter/Http/AuthTest.php b/test/Adapter/Http/AuthTest.php index 2b1cc3e..8e41298 100644 --- a/test/Adapter/Http/AuthTest.php +++ b/test/Adapter/Http/AuthTest.php @@ -55,7 +55,7 @@ class AuthTest extends \PHPUnit_Framework_TestCase /** * File resolver setup against with HTTP Basic auth file * - * @var Zend_Auth_Adapter_Http_Resolver_File + * @var Http\FileResolver */ protected $_basicResolver; @@ -129,6 +129,7 @@ public function testBothChallenges() // should result in a 401 reply with at least one Www-Authenticate // header, and a false result. + $result = $status = $headers = null; $data = $this->_doAuth('', 'both'); extract($data); // $result, $status, $headers @@ -327,9 +328,10 @@ protected function _doAuth($clientHeader, $scheme) // Set stub method return values $request->setUri('http://localhost/'); $request->setMethod('GET'); - $request->setServer(new Parameters(array('HTTP_USER_AGENT' => 'PHPUnit'))); + $headers = $request->getHeaders(); $headers->addHeaderLine('Authorization', $clientHeader); + $headers->addHeaderLine('User-Agent', 'PHPUnit'); // Select an Authentication scheme switch ($scheme) { @@ -414,6 +416,7 @@ protected function _digestReply($user, $pass) */ protected function _checkUnauthorized($data, $expected) { + $result = $status = $headers = null; extract($data); // $result, $status, $headers // Make sure the result is false @@ -448,6 +451,7 @@ protected function _checkUnauthorized($data, $expected) */ protected function _checkOK($data) { + $result = $status = $headers = null; extract($data); // $result, $status, $headers // Make sure the result is true @@ -466,6 +470,7 @@ protected function _checkOK($data) */ protected function _checkBadRequest($data) { + $result = $status = $headers = null; extract($data); // $result, $status, $headers // Make sure the result is false diff --git a/test/Adapter/Http/ObjectTest.php b/test/Adapter/Http/ObjectTest.php index 7ebcf11..24f6321 100644 --- a/test/Adapter/Http/ObjectTest.php +++ b/test/Adapter/Http/ObjectTest.php @@ -56,14 +56,14 @@ class ObjectTest extends \PHPUnit_Framework_TestCase /** * File resolver setup against with HTTP Basic auth file * - * @var Zend_Auth_Adapter_Http_Resolver_File + * @var Http\FileResolver */ protected $_basicResolver; /** * File resolver setup against with HTTP Digest auth file * - * @var Zend_Auth_Adapter_Http_Resolver_File + * @var Http\FileResolver */ protected $_digestResolver; @@ -214,12 +214,13 @@ public function testWrongResolverUsed() $request->setHeaders($headers); // Test a Digest auth process while the request is containing a Basic auth header - $a = new Adapter\Http($this->_digestConfig); - $a->setDigestResolver($this->_digestResolver) - ->setRequest($request) - ->setResponse($response); - $result = $a->authenticate(); - $this->assertEquals($result->getCode(),Authentication\Result::FAILURE_CREDENTIAL_INVALID); + $adapter = new Adapter\Http($this->_digestConfig); + $adapter->setDigestResolver($this->_digestResolver) + ->setRequest($request) + ->setResponse($response); + $result = $adapter->authenticate(); + + $this->assertEquals($result->getCode(), Authentication\Result::FAILURE_CREDENTIAL_INVALID); } public function testUnsupportedScheme() @@ -227,6 +228,7 @@ public function testUnsupportedScheme() $response = new Response(); $headers = new Headers(); $request = new Request(); + $headers->addHeaderLine('Authorization', 'NotSupportedScheme setHeaders($headers); diff --git a/test/Adapter/Http/ProxyTest.php b/test/Adapter/Http/ProxyTest.php index 5bbdc5f..b3babf5 100644 --- a/test/Adapter/Http/ProxyTest.php +++ b/test/Adapter/Http/ProxyTest.php @@ -315,11 +315,11 @@ public function _doAuth($clientHeader, $scheme) $headers = new Headers(); $headers->addHeaderLine('Proxy-Authorization', $clientHeader); + $headers->addHeaderLine('User-Agent', 'PHPUnit'); $request = new Request(); $request->setUri('http://localhost/'); $request->setMethod('GET'); - $request->setServer(new Parameters(array('HTTP_USER_AGENT' => 'PHPUnit'))); $request->setHeaders($headers); // Select an Authentication scheme From ffe23375a80233579f39c27f9ce5faefa0e7bb95 Mon Sep 17 00:00:00 2001 From: David Windell Date: Thu, 2 Aug 2012 08:42:52 +0200 Subject: [PATCH 56/61] typofix --- src/Adapter/Http.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Adapter/Http.php b/src/Adapter/Http.php index 0b73a54..588f568 100644 --- a/src/Adapter/Http.php +++ b/src/Adapter/Http.php @@ -491,7 +491,7 @@ protected function _basicAuth($header) return $result; } - if (!$result instanceof Authentication\Result) + if (!$result instanceof Authentication\Result && !is_array($result) && $this->_secureStringCompare($result, $creds[1]) ) { From d5da77d668975f0282f39ae3440136fbae865fcd Mon Sep 17 00:00:00 2001 From: David Windell Date: Thu, 2 Aug 2012 17:02:28 +0100 Subject: [PATCH 57/61] added tests --- test/Adapter/Http/AuthTest.php | 24 ++++++++++++ .../TestAsset/BasicAuthObjectResolver.php | 37 +++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 test/Adapter/Http/TestAsset/BasicAuthObjectResolver.php diff --git a/test/Adapter/Http/AuthTest.php b/test/Adapter/Http/AuthTest.php index 8e41298..a2672f4 100644 --- a/test/Adapter/Http/AuthTest.php +++ b/test/Adapter/Http/AuthTest.php @@ -480,4 +480,28 @@ protected function _checkBadRequest($data) // Make sure it set the right HTTP code $this->assertEquals(400, $status); } + + public function testBasicAuthValidCredsWithCustomIdentityObjectResolverReturnsAuthResult() + { + $this->_basicResolver = new TestAsset\BasicAuthObjectResolver(); + + $result = $this->_doAuth('Basic ' . base64_encode('Bryce:ThisIsNotMyPassword'), 'basic'); + $result = $result['result']; + + $this->assertInstanceOf('Zend\\Authentication\\Result', $result); + $this->assertTrue($result->isValid()); + } + + public function testBasicAuthInvalidCredsWithCustomIdentityObjectResolverReturnsUnauthorizedResponse() + { + $this->_basicResolver = new TestAsset\BasicAuthObjectResolver(); + $data = $this->_doAuth('Basic ' . base64_encode('David:ThisIsNotMyPassword'), 'basic'); + + $expected = array( + 'type' => 'Basic ', + 'realm' => 'realm="' . $this->_bothConfig['realm'] . '"', + ); + + $this->_checkUnauthorized($data, $expected); + } } diff --git a/test/Adapter/Http/TestAsset/BasicAuthObjectResolver.php b/test/Adapter/Http/TestAsset/BasicAuthObjectResolver.php new file mode 100644 index 0000000..7b275c8 --- /dev/null +++ b/test/Adapter/Http/TestAsset/BasicAuthObjectResolver.php @@ -0,0 +1,37 @@ + Date: Fri, 3 Aug 2012 10:40:46 +0200 Subject: [PATCH 58/61] cs fixes (braces) --- test/Adapter/Http/TestAsset/BasicAuthObjectResolver.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/test/Adapter/Http/TestAsset/BasicAuthObjectResolver.php b/test/Adapter/Http/TestAsset/BasicAuthObjectResolver.php index 7b275c8..87e81fc 100644 --- a/test/Adapter/Http/TestAsset/BasicAuthObjectResolver.php +++ b/test/Adapter/Http/TestAsset/BasicAuthObjectResolver.php @@ -15,8 +15,8 @@ class BasicAuthObjectResolver implements ResolverInterface { - public function resolve($username, $realm, $password = null) { - + public function resolve($username, $realm, $password = null) + { if ($username == 'Bryce' && $password == 'ThisIsNotMyPassword') { $identity = new \stdClass(); @@ -32,6 +32,5 @@ public function resolve($username, $realm, $password = null) { null, array('Authentication failed.') ); - } } \ No newline at end of file From 00bb39e8cca86f042104df0476b968fb1894a3c0 Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Mon, 6 Aug 2012 13:34:35 -0500 Subject: [PATCH 59/61] [zendframework/zf2#2084] Cleanup - A few test assets had snuck into the tree since this PR was added; moved those under the ZendTest directory - phpunit.xml.dist needed to point to ZendTest directory - likewise with run-tests.sh - Also, if you have run a composer install, you still need access to TestAsset files under ZendTest -- as such, I've made autoloading of that namespace happen in all situations, and register the Zend namespace only if the composer autoloader is not present. --- test/Adapter/DbTableTest.php | 372 +++++++++++++ test/Adapter/DigestTest.php | 229 ++++++++ test/Adapter/Http/AuthTest.php | 507 ++++++++++++++++++ test/Adapter/Http/FileResolverTest.php | 230 ++++++++ test/Adapter/Http/ObjectTest.php | 242 +++++++++ test/Adapter/Http/ProxyTest.php | 471 ++++++++++++++++ test/Adapter/Http/TestAsset/htbasic.1 | 3 + test/Adapter/Http/TestAsset/htdigest.3 | 2 + test/Adapter/Ldap/OfflineTest.php | 93 ++++ test/Adapter/Ldap/OnlineTest.php | 192 +++++++ test/Adapter/TestAsset/Digest/htdigest.1 | 2 + test/Adapter/TestAsset/OpenId/.gitignore | 0 test/Adapter/TestAsset/OpenId/assoc.lock | 0 test/Adapter/TestAsset/OpenId/discovery.lock | 0 test/Adapter/TestAsset/OpenId/nonce.lock | 0 .../nonce_9f11599cc1f088b7c358f33610cb126c | 1 + .../TestAsset/OpenIdResponseHelper.php | 40 ++ test/AuthenticationServiceTest.php | 90 ++++ test/TestAsset/SuccessAdapter.php | 22 + 19 files changed, 2496 insertions(+) create mode 100644 test/Adapter/DbTableTest.php create mode 100644 test/Adapter/DigestTest.php create mode 100644 test/Adapter/Http/AuthTest.php create mode 100644 test/Adapter/Http/FileResolverTest.php create mode 100644 test/Adapter/Http/ObjectTest.php create mode 100644 test/Adapter/Http/ProxyTest.php create mode 100644 test/Adapter/Http/TestAsset/htbasic.1 create mode 100644 test/Adapter/Http/TestAsset/htdigest.3 create mode 100644 test/Adapter/Ldap/OfflineTest.php create mode 100644 test/Adapter/Ldap/OnlineTest.php create mode 100644 test/Adapter/TestAsset/Digest/htdigest.1 create mode 100644 test/Adapter/TestAsset/OpenId/.gitignore create mode 100644 test/Adapter/TestAsset/OpenId/assoc.lock create mode 100644 test/Adapter/TestAsset/OpenId/discovery.lock create mode 100644 test/Adapter/TestAsset/OpenId/nonce.lock create mode 100644 test/Adapter/TestAsset/OpenId/nonce_9f11599cc1f088b7c358f33610cb126c create mode 100644 test/Adapter/TestAsset/OpenIdResponseHelper.php create mode 100644 test/AuthenticationServiceTest.php create mode 100644 test/TestAsset/SuccessAdapter.php diff --git a/test/Adapter/DbTableTest.php b/test/Adapter/DbTableTest.php new file mode 100644 index 0000000..e58b47b --- /dev/null +++ b/test/Adapter/DbTableTest.php @@ -0,0 +1,372 @@ +markTestSkipped('Tests are not enabled in TestConfiguration.php'); + return; + } elseif (!extension_loaded('pdo')) { + $this->markTestSkipped('PDO extension is not loaded'); + return; + } elseif (!in_array('sqlite', \PDO::getAvailableDrivers())) { + $this->markTestSkipped('SQLite PDO driver is not available'); + return; + } + + $this->_setupDbAdapter(); + $this->_setupAuthAdapter(); + } + + public function tearDown() + { + $this->_adapter = null; + if ($this->_db instanceof DbAdapter) { + $this->_db->query('DROP TABLE [users]'); + } + $this->_db = null; + } + + /** + * Ensures expected behavior for authentication success + */ + public function testAuthenticateSuccess() + { + $this->_adapter->setIdentity('my_username'); + $this->_adapter->setCredential('my_password'); + $result = $this->_adapter->authenticate(); + $this->assertTrue($result->isValid()); + } + + /** + * Ensures expected behavior for authentication success + */ + public function testAuthenticateSuccessWithTreatment() + { + $this->_adapter = new Adapter\DbTable($this->_db, 'users', 'username', 'password', '?'); + $this->_adapter->setIdentity('my_username'); + $this->_adapter->setCredential('my_password'); + $result = $this->_adapter->authenticate(); + $this->assertTrue($result->isValid()); + } + + /** + * Ensures expected behavior for for authentication failure + * reason: Identity not found. + */ + public function testAuthenticateFailureIdentityNotFound() + { + $this->_adapter->setIdentity('non_existent_username'); + $this->_adapter->setCredential('my_password'); + + $result = $this->_adapter->authenticate(); + $this->assertEquals(Authentication\Result::FAILURE_IDENTITY_NOT_FOUND, $result->getCode()); + } + + /** + * Ensures expected behavior for for authentication failure + * reason: Identity not found. + */ + public function testAuthenticateFailureIdentityAmbiguous() + { + $sqlInsert = 'INSERT INTO users (username, password, real_name) VALUES ("my_username", "my_password", "My Real Name")'; + $this->_db->query($sqlInsert, DbAdapter::QUERY_MODE_EXECUTE); + + $this->_adapter->setIdentity('my_username'); + $this->_adapter->setCredential('my_password'); + + $result = $this->_adapter->authenticate(); + $this->assertEquals(Authentication\Result::FAILURE_IDENTITY_AMBIGUOUS, $result->getCode()); + } + + /** + * Ensures expected behavior for authentication failure because of a bad password + */ + public function testAuthenticateFailureInvalidCredential() + { + $this->_adapter->setIdentity('my_username'); + $this->_adapter->setCredential('my_password_bad'); + $result = $this->_adapter->authenticate(); + $this->assertFalse($result->isValid()); + } + + /** + * Ensures that getResultRowObject() works for successful authentication + */ + public function testGetResultRow() + { + $this->_adapter->setIdentity('my_username'); + $this->_adapter->setCredential('my_password'); + $this->_adapter->authenticate(); + $resultRow = $this->_adapter->getResultRowObject(); + $this->assertEquals($resultRow->username, 'my_username'); + } + + /** + * Ensure that ResultRowObject returns only what told to be included + */ + public function testGetSpecificResultRow() + { + $this->_adapter->setIdentity('my_username'); + $this->_adapter->setCredential('my_password'); + $this->_adapter->authenticate(); + $resultRow = $this->_adapter->getResultRowObject(array('username', 'real_name')); + $this->assertEquals('O:8:"stdClass":2:{s:8:"username";s:11:"my_username";s:9:"real_name";s:12:"My Real Name";}', + serialize($resultRow)); + } + + /** + * Ensure that ResultRowObject returns an object has specific omissions + */ + public function testGetOmittedResultRow() + { + $this->_adapter->setIdentity('my_username'); + $this->_adapter->setCredential('my_password'); + $this->_adapter->authenticate(); + $resultRow = $this->_adapter->getResultRowObject(null, 'password'); + $this->assertEquals('O:8:"stdClass":3:{s:2:"id";s:1:"1";s:8:"username";s:11:"my_username";s:9:"real_name";s:12:"My Real Name";}', + serialize($resultRow)); + } + + /** + * @group ZF-5957 + */ + public function testAdapterCanReturnDbSelectObject() + { + $this->assertTrue($this->_adapter->getDbSelect() instanceof DBSelect); + } + + /** + * @group ZF-5957 + */ + public function testAdapterCanUseModifiedDbSelectObject() + { + $select = $this->_adapter->getDbSelect(); + $select->where('1 = 0'); + $this->_adapter->setIdentity('my_username'); + $this->_adapter->setCredential('my_password'); + + $result = $this->_adapter->authenticate(); + $this->assertEquals(Authentication\Result::FAILURE_IDENTITY_NOT_FOUND, $result->getCode()); + } + + /** + * @group ZF-5957 + */ + public function testAdapterReturnsASelectObjectWithoutAuthTimeModificationsAfterAuth() + { + $select = $this->_adapter->getDbSelect(); + $select->where('1 = 1'); + $this->_adapter->setIdentity('my_username'); + $this->_adapter->setCredential('my_password'); + $this->_adapter->authenticate(); + $selectAfterAuth = $this->_adapter->getDbSelect(); + $whereParts = $selectAfterAuth->where->getPredicates(); + $this->assertEquals(1, count($whereParts)); + + $lastWherePart = array_pop($whereParts); + $expressionData = $lastWherePart[1]->getExpressionData(); + $this->assertEquals('1 = 1', $expressionData[0][0]); + } + + /** + * Ensure that exceptions are caught + */ + public function testCatchExceptionNoTable() + { + $this->setExpectedException('Zend\Authentication\Adapter\Exception\RuntimeException', + 'A table must be supplied for'); + $adapter = new Adapter\DbTable($this->_db); + $adapter->authenticate(); + } + + /** + * Ensure that exceptions are caught + */ + public function testCatchExceptionNoIdentityColumn() + { + $this->setExpectedException('Zend\Authentication\Adapter\Exception\RuntimeException', + 'An identity column must be supplied for the'); + $adapter = new Adapter\DbTable($this->_db, 'users'); + $adapter->authenticate(); + } + + /** + * Ensure that exceptions are caught + */ + public function testCatchExceptionNoCredentialColumn() + { + $this->setExpectedException('Zend\Authentication\Adapter\Exception\RuntimeException', + 'A credential column must be supplied'); + $adapter = new Adapter\DbTable($this->_db, 'users', 'username'); + $adapter->authenticate(); + } + + /** + * Ensure that exceptions are caught + */ + public function testCatchExceptionNoIdentity() + { + $this->setExpectedException('Zend\Authentication\Adapter\Exception\RuntimeException', + 'A value for the identity was not provided prior'); + $this->_adapter->authenticate(); + } + + /** + * Ensure that exceptions are caught + */ + public function testCatchExceptionNoCredential() + { + $this->setExpectedException('Zend\Authentication\Adapter\Exception\RuntimeException', + 'A credential value was not provided prior'); + $this->_adapter->setIdentity('my_username'); + $this->_adapter->authenticate(); + } + + /** + * Ensure that exceptions are caught + */ + public function testCatchExceptionBadSql() + { + $this->setExpectedException('Zend\Authentication\Adapter\Exception\RuntimeException', + 'The supplied parameters to'); + $this->_adapter->setTableName('bad_table_name'); + $this->_adapter->setIdentity('value'); + $this->_adapter->setCredential('value'); + $this->_adapter->authenticate(); + } + + /** + * Test to see same usernames with different passwords can not authenticate + * when flag is not set. This is the current state of + * Zend_Auth_Adapter_DbTable (up to ZF 1.10.6) + * + * @group ZF-7289 + */ + public function testEqualUsernamesDifferentPasswordShouldNotAuthenticateWhenFlagIsNotSet() + { + $sqlInsert = 'INSERT INTO users (username, password, real_name) ' + . 'VALUES ("my_username", "my_otherpass", "Test user 2")'; + $this->_db->query($sqlInsert, DbAdapter::QUERY_MODE_EXECUTE); + + // test if user 1 can authenticate + $this->_adapter->setIdentity('my_username') + ->setCredential('my_password'); + $result = $this->_adapter->authenticate(); + $this->assertTrue(in_array('More than one record matches the supplied identity.', + $result->getMessages())); + $this->assertFalse($result->isValid()); + } + + /** + * Test to see same usernames with different passwords can authenticate when + * a flag is set + * + * @group ZF-7289 + */ + public function testEqualUsernamesDifferentPasswordShouldAuthenticateWhenFlagIsSet() + { + $sqlInsert = 'INSERT INTO users (username, password, real_name) ' + . 'VALUES ("my_username", "my_otherpass", "Test user 2")'; + $this->_db->query($sqlInsert, DbAdapter::QUERY_MODE_EXECUTE); + + // test if user 1 can authenticate + $this->_adapter->setIdentity('my_username') + ->setCredential('my_password') + ->setAmbiguityIdentity(true); + $result = $this->_adapter->authenticate(); + $this->assertFalse(in_array('More than one record matches the supplied identity.', + $result->getMessages())); + $this->assertTrue($result->isValid()); + $this->assertEquals('my_username', $result->getIdentity()); + + $this->_adapter = null; + $this->_setupAuthAdapter(); + + // test if user 2 can authenticate + $this->_adapter->setIdentity('my_username') + ->setCredential('my_otherpass') + ->setAmbiguityIdentity(true); + $result2 = $this->_adapter->authenticate(); + $this->assertFalse(in_array('More than one record matches the supplied identity.', + $result->getMessages())); + $this->assertTrue($result2->isValid()); + $this->assertEquals('my_username', $result2->getIdentity()); + } + + + protected function _setupDbAdapter($optionalParams = array()) + { + $params = array('driver' => 'pdo_sqlite', + 'dbname' => TESTS_ZEND_AUTH_ADAPTER_DBTABLE_PDO_SQLITE_DATABASE); + + if (!empty($optionalParams)) { + $params['options'] = $optionalParams; + } + + $this->_db = new DbAdapter($params); + + $sqlCreate = 'CREATE TABLE IF NOT EXISTS [users] ( ' + . '[id] INTEGER NOT NULL PRIMARY KEY, ' + . '[username] VARCHAR(50) NOT NULL, ' + . '[password] VARCHAR(32) NULL, ' + . '[real_name] VARCHAR(150) NULL)'; + $this->_db->query($sqlCreate, DbAdapter::QUERY_MODE_EXECUTE); + + $sqlDelete = 'DELETE FROM users'; + $this->_db->query($sqlDelete, DbAdapter::QUERY_MODE_EXECUTE); + + $sqlInsert = 'INSERT INTO users (username, password, real_name) ' + . 'VALUES ("my_username", "my_password", "My Real Name")'; + $this->_db->query($sqlInsert, DbAdapter::QUERY_MODE_EXECUTE); + } + + protected function _setupAuthAdapter() + { + $this->_adapter = new Adapter\DbTable($this->_db, 'users', 'username', 'password'); + } + +} + diff --git a/test/Adapter/DigestTest.php b/test/Adapter/DigestTest.php new file mode 100644 index 0000000..5352c9d --- /dev/null +++ b/test/Adapter/DigestTest.php @@ -0,0 +1,229 @@ +_filesPath = __DIR__ . '/TestAsset/Digest'; + } + + /** + * Ensures that the adapter throws an exception when authentication is attempted before + * setting a required option + * + * @return void + */ + public function testOptionRequiredException() + { + $adapter = new Adapter\Digest(); + try { + $adapter->authenticate(); + $this->fail('Expected Zend_Auth_Adapter_Exception not thrown upon authentication attempt before setting ' + . 'a required option'); + } catch (Adapter\Exception\ExceptionInterface $e) { + $this->assertContains('must be set before authentication', $e->getMessage()); + } + } + + /** + * Ensures that an exception is thrown upon authenticating against a nonexistent file + * + * @return void + */ + public function testFileNonExistentException() + { + $adapter = new Adapter\Digest('nonexistent', 'realm', 'username', 'password'); + try { + $adapter->authenticate(); + $this->fail('Expected Zend_Auth_Adapter_Exception not thrown upon authenticating against nonexistent ' + . 'file'); + } catch (Adapter\Exception\ExceptionInterface $e) { + $this->assertContains('Cannot open', $e->getMessage()); + } + } + + /** + * Ensures expected behavior upon realm not found for existing user + * + * @return void + */ + public function testUserExistsRealmNonexistent() + { + $filename = "$this->_filesPath/htdigest.1"; + $realm = 'Nonexistent Realm'; + $username = 'someUser'; + $password = 'somePassword'; + + $adapter = new Adapter\Digest($filename, $realm, $username, $password); + + $result = $adapter->authenticate(); + + $this->assertFalse($result->isValid()); + + $messages = $result->getMessages(); + $this->assertEquals(1, count($messages)); + $this->assertEquals($result->getCode(), Authentication\Result::FAILURE_IDENTITY_NOT_FOUND); + $this->assertContains('combination not found', $messages[0]); + + $identity = $result->getIdentity(); + $this->assertEquals($identity['realm'], $realm); + $this->assertEquals($identity['username'], $username); + } + + /** + * Ensures expected behavior upon user not found in existing realm + * + * @return void + */ + public function testUserNonexistentRealmExists() + { + $filename = "$this->_filesPath/htdigest.1"; + $realm = 'Some Realm'; + $username = 'nonexistentUser'; + $password = 'somePassword'; + + $adapter = new Adapter\Digest($filename, $realm, $username, $password); + + $result = $adapter->authenticate(); + + $this->assertFalse($result->isValid()); + $this->assertEquals($result->getCode(), Authentication\Result::FAILURE_IDENTITY_NOT_FOUND); + + $messages = $result->getMessages(); + $this->assertEquals(1, count($messages)); + $this->assertContains('combination not found', $messages[0]); + + $identity = $result->getIdentity(); + $this->assertEquals($identity['realm'], $realm); + $this->assertEquals($identity['username'], $username); + } + + /** + * Ensures expected behavior upon incorrect password + * + * @return void + */ + public function testIncorrectPassword() + { + $filename = "$this->_filesPath/htdigest.1"; + $realm = 'Some Realm'; + $username = 'someUser'; + $password = 'incorrectPassword'; + + $adapter = new Adapter\Digest($filename, $realm, $username, $password); + + $result = $adapter->authenticate(); + + $this->assertFalse($result->isValid()); + $this->assertEquals($result->getCode(), Authentication\Result::FAILURE_CREDENTIAL_INVALID); + + $messages = $result->getMessages(); + $this->assertEquals(1, count($messages)); + $this->assertContains('Password incorrect', $messages[0]); + + $identity = $result->getIdentity(); + $this->assertEquals($identity['realm'], $realm); + $this->assertEquals($identity['username'], $username); + } + + /** + * Ensures that successful authentication works as expected + * + * @return void + */ + public function testAuthenticationSuccess() + { + $filename = "$this->_filesPath/htdigest.1"; + $realm = 'Some Realm'; + $username = 'someUser'; + $password = 'somePassword'; + + $adapter = new Adapter\Digest($filename, $realm, $username, $password); + + $result = $adapter->authenticate(); + + $this->assertTrue($result->isValid()); + $this->assertEquals($result->getCode(), Authentication\Result::SUCCESS); + + $this->assertEquals(array(), $result->getMessages()); + + $identity = $result->getIdentity(); + $this->assertEquals($identity['realm'], $realm); + $this->assertEquals($identity['username'], $username); + } + + /** + * Ensures that getFilename() returns expected default value + * + * @return void + */ + public function testGetFilename() + { + $adapter = new Adapter\Digest(); + $this->assertEquals(null, $adapter->getFilename()); + } + + /** + * Ensures that getRealm() returns expected default value + * + * @return void + */ + public function testGetRealm() + { + $adapter = new Adapter\Digest(); + $this->assertEquals(null, $adapter->getRealm()); + } + + /** + * Ensures that getUsername() returns expected default value + * + * @return void + */ + public function testGetUsername() + { + $adapter = new Adapter\Digest(); + $this->assertEquals(null, $adapter->getUsername()); + } + + /** + * Ensures that getPassword() returns expected default value + * + * @return void + */ + public function testGetPassword() + { + $adapter = new Adapter\Digest(); + $this->assertEquals(null, $adapter->getPassword()); + } +} diff --git a/test/Adapter/Http/AuthTest.php b/test/Adapter/Http/AuthTest.php new file mode 100644 index 0000000..a2672f4 --- /dev/null +++ b/test/Adapter/Http/AuthTest.php @@ -0,0 +1,507 @@ +_filesPath = __DIR__ . '/TestAsset'; + $this->_basicResolver = new Http\FileResolver("{$this->_filesPath}/htbasic.1"); + $this->_digestResolver = new Http\FileResolver("{$this->_filesPath}/htdigest.3"); + $this->_basicConfig = array( + 'accept_schemes' => 'basic', + 'realm' => 'Test Realm' + ); + $this->_digestConfig = array( + 'accept_schemes' => 'digest', + 'realm' => 'Test Realm', + 'digest_domains' => '/ http://localhost/', + 'nonce_timeout' => 300 + ); + $this->_bothConfig = array( + 'accept_schemes' => 'basic digest', + 'realm' => 'Test Realm', + 'digest_domains' => '/ http://localhost/', + 'nonce_timeout' => 300 + ); + } + + public function testBasicChallenge() + { + // Trying to authenticate without sending an Authorization header + // should result in a 401 reply with a Www-Authenticate header, and a + // false result. + + // The expected Basic Www-Authenticate header value + $basic = array( + 'type' => 'Basic ', + 'realm' => 'realm="' . $this->_bothConfig['realm'] . '"', + ); + + $data = $this->_doAuth('', 'basic'); + $this->_checkUnauthorized($data, $basic); + } + + public function testDigestChallenge() + { + // Trying to authenticate without sending an Authorization header + // should result in a 401 reply with a Www-Authenticate header, and a + // false result. + + // The expected Digest Www-Authenticate header value + $digest = $this->_digestChallenge(); + + $data = $this->_doAuth('', 'digest'); + $this->_checkUnauthorized($data, $digest); + } + + public function testBothChallenges() + { + // Trying to authenticate without sending an Authorization header + // should result in a 401 reply with at least one Www-Authenticate + // header, and a false result. + + $result = $status = $headers = null; + $data = $this->_doAuth('', 'both'); + extract($data); // $result, $status, $headers + + // The expected Www-Authenticate header values + $basic = 'Basic realm="' . $this->_bothConfig['realm'] . '"'; + $digest = $this->_digestChallenge(); + + // Make sure the result is false + $this->assertInstanceOf('Zend\\Authentication\\Result', $result); + $this->assertFalse($result->isValid()); + + // Verify the status code and the presence of both challenges + $this->assertEquals(401, $status); + $this->assertTrue($headers->has('Www-Authenticate')); + $wwwAuthenticate = $headers->get('Www-Authenticate'); + $this->assertEquals(2, count($wwwAuthenticate)); + + // Check to see if the expected challenges match the actual + $basicFound = $digestFound = false; + foreach ($wwwAuthenticate as $header) { + $value = $header->getFieldValue(); + if (preg_match('/^Basic/', $value)) { + $basicFound = true; + } + if (preg_match('/^Digest/', $value)) { + $digestFound = true; + } + } + $this->assertTrue($basicFound); + $this->assertTrue($digestFound); + } + + public function testBasicAuthValidCreds() + { + // Attempt Basic Authentication with a valid username and password + + $data = $this->_doAuth('Basic ' . base64_encode('Bryce:ThisIsNotMyPassword'), 'basic'); + $this->_checkOK($data); + } + + public function testBasicAuthBadCreds() + { + // Ensure that credentials containing invalid characters are treated as + // a bad username or password. + + // The expected Basic Www-Authenticate header value + $basic = array( + 'type' => 'Basic ', + 'realm' => 'realm="' . $this->_basicConfig['realm'] . '"', + ); + + $data = $this->_doAuth('Basic ' . base64_encode("Bad\tChars:In:Creds"), 'basic'); + $this->_checkUnauthorized($data, $basic); + } + + public function testBasicAuthBadUser() + { + // Attempt Basic Authentication with a nonexistant username and + // password + + // The expected Basic Www-Authenticate header value + $basic = array( + 'type' => 'Basic ', + 'realm' => 'realm="' . $this->_basicConfig['realm'] . '"', + ); + + $data = $this->_doAuth('Basic ' . base64_encode('Nobody:NotValid'), 'basic'); + $this->_checkUnauthorized($data, $basic); + } + + public function testBasicAuthBadPassword() + { + // Attempt Basic Authentication with a valid username, but invalid + // password + + // The expected Basic Www-Authenticate header value + $basic = array( + 'type' => 'Basic ', + 'realm' => 'realm="' . $this->_basicConfig['realm'] . '"', + ); + + $data = $this->_doAuth('Basic ' . base64_encode('Bryce:Invalid'), 'basic'); + $this->_checkUnauthorized($data, $basic); + } + + public function testDigestAuthValidCreds() + { + // Attempt Digest Authentication with a valid username and password + + $data = $this->_doAuth($this->_digestReply('Bryce', 'ThisIsNotMyPassword'), 'digest'); + $this->_checkOK($data); + } + + public function testDigestAuthDefaultAlgo() + { + // If the client omits the aglorithm argument, it should default to MD5, + // and work just as above + + $cauth = $this->_digestReply('Bryce', 'ThisIsNotMyPassword'); + $cauth = preg_replace('/algorithm="MD5", /', '', $cauth); + + $data = $this->_doAuth($cauth, 'digest'); + $this->_checkOK($data); + } + + public function testDigestAuthQuotedNC() + { + // The nonce count isn't supposed to be quoted, but apparently some + // clients do anyway. + + $cauth = $this->_digestReply('Bryce', 'ThisIsNotMyPassword'); + $cauth = preg_replace('/nc=00000001/', 'nc="00000001"', $cauth); + + $data = $this->_doAuth($cauth, 'digest'); + $this->_checkOK($data); + } + + public function testDigestAuthBadCreds() + { + // Attempt Digest Authentication with a bad username and password + + // The expected Digest Www-Authenticate header value + $digest = $this->_digestChallenge(); + + $data = $this->_doAuth($this->_digestReply('Nobody', 'NotValid'), 'digest'); + $this->_checkUnauthorized($data, $digest); + } + + public function testDigestAuthBadCreds2() + { + // Formerly, a username with invalid characters would result in a 400 + // response, but now should result in 401 response. + + // The expected Digest Www-Authenticate header value + $digest = $this->_digestChallenge(); + + $data = $this->_doAuth($this->_digestReply('Bad:chars', 'NotValid'), 'digest'); + $this->_checkUnauthorized($data, $digest); + } + + public function testDigestTampered() + { + // Create the tampered header value + $tampered = $this->_digestReply('Bryce', 'ThisIsNotMyPassword'); + $tampered = preg_replace( + '/ nonce="[a-fA-F0-9]{32}", /', + ' nonce="'.str_repeat('0', 32).'", ', + $tampered + ); + + // The expected Digest Www-Authenticate header value + $digest = $this->_digestChallenge(); + + $data = $this->_doAuth($tampered, 'digest'); + $this->_checkUnauthorized($data, $digest); + } + + public function testBadSchemeRequest() + { + // Sending a request for an invalid authentication scheme should result + // in a 400 Bad Request response. + + $data = $this->_doAuth('Invalid ' . base64_encode('Nobody:NotValid'), 'basic'); + $this->_checkBadRequest($data); + } + + public function testBadDigestRequest() + { + // If any of the individual parts of the Digest Authorization header + // are bad, it results in a 400 Bad Request. But that's a lot of + // possibilities, so we're just going to pick one for now. + $bad = $this->_digestReply('Bryce', 'ThisIsNotMyPassword'); + $bad = preg_replace( + '/realm="([^"]+)"/', // cut out the realm + '', $bad + ); + + $data = $this->_doAuth($bad, 'digest'); + $this->_checkBadRequest($data); + } + + /** + * Acts like a client sending the given Authenticate header value. + * + * @param string $clientHeader Authenticate header value + * @param string $scheme Which authentication scheme to use + * @return array Containing the result, response headers, and the status + */ + protected function _doAuth($clientHeader, $scheme) + { + // Set up stub request and response objects + $request = new Request; + $response = new Response; + $response->setStatusCode(200); + + // Set stub method return values + $request->setUri('http://localhost/'); + $request->setMethod('GET'); + + $headers = $request->getHeaders(); + $headers->addHeaderLine('Authorization', $clientHeader); + $headers->addHeaderLine('User-Agent', 'PHPUnit'); + + // Select an Authentication scheme + switch ($scheme) { + case 'basic': + $use = $this->_basicConfig; + break; + case 'digest': + $use = $this->_digestConfig; + break; + case 'both': + default: + $use = $this->_bothConfig; + } + + // Create the HTTP Auth adapter + $a = new HTTP($use); + $a->setBasicResolver($this->_basicResolver); + $a->setDigestResolver($this->_digestResolver); + + // Send the authentication request + $a->setRequest($request); + $a->setResponse($response); + $result = $a->authenticate(); + + $return = array( + 'result' => $result, + 'status' => $response->getStatusCode(), + 'headers' => $response->getHeaders(), + ); + return $return; + } + + /** + * Constructs a local version of the digest challenge we expect to receive + * + * @return string + */ + protected function _digestChallenge() + { + return array( + 'type' => 'Digest ', + 'realm' => 'realm="' . $this->_digestConfig['realm'] . '"', + 'domain' => 'domain="' . $this->_bothConfig['digest_domains'] . '"', + ); + } + + /** + * Constructs a client digest Authorization header + * + * @return string + */ + protected function _digestReply($user, $pass) + { + $nc = '00000001'; + $timeout = ceil(time() / 300) * 300; + $nonce = md5($timeout . ':PHPUnit:Zend\Authentication\Adapter\Http'); + $opaque = md5('Opaque Data:Zend\\Authentication\\Adapter\\Http'); + $cnonce = md5('cnonce'); + $response = md5(md5($user . ':' . $this->_digestConfig['realm'] . ':' . $pass) . ":$nonce:$nc:$cnonce:auth:" + . md5('GET:/')); + $cauth = 'Digest ' + . 'username="Bryce", ' + . 'realm="' . $this->_digestConfig['realm'] . '", ' + . 'nonce="' . $nonce . '", ' + . 'uri="/", ' + . 'response="' . $response . '", ' + . 'algorithm="MD5", ' + . 'cnonce="' . $cnonce . '", ' + . 'opaque="' . $opaque . '", ' + . 'qop="auth", ' + . 'nc=' . $nc; + + return $cauth; + } + + /** + * Checks for an expected 401 Unauthorized response + * + * @param array $data Authentication results + * @param string $expected Expected Www-Authenticate header value + * @return void + */ + protected function _checkUnauthorized($data, $expected) + { + $result = $status = $headers = null; + extract($data); // $result, $status, $headers + + // Make sure the result is false + $this->assertInstanceOf('Zend\\Authentication\\Result', $result); + $this->assertFalse($result->isValid()); + + // Verify the status code and the presence of the challenge + $this->assertEquals(401, $status); + $this->assertTrue($headers->has('Www-Authenticate')); + + // Check to see if the expected challenge matches the actual + $headers = $headers->get('Www-Authenticate'); + $this->assertTrue($headers instanceof \ArrayIterator); + $this->assertEquals(1, count($headers)); + $header = $headers[0]->getFieldValue(); + $this->assertContains($expected['type'], $header, $header); + $this->assertContains($expected['realm'], $header, $header); + if (isset($expected['domain'])) { + $this->assertContains($expected['domain'], $header, $header); + $this->assertContains('algorithm="MD5"', $header, $header); + $this->assertContains('qop="auth"', $header, $header); + $this->assertRegExp('/nonce="[a-fA-F0-9]{32}"/', $header, $header); + $this->assertRegExp('/opaque="[a-fA-F0-9]{32}"/', $header, $header); + } + } + + /** + * Checks for an expected 200 OK response + * + * @param array $data Authentication results + * @return void + */ + protected function _checkOK($data) + { + $result = $status = $headers = null; + extract($data); // $result, $status, $headers + + // Make sure the result is true + $this->assertInstanceOf('Zend\\Authentication\\Result', $result); + $this->assertTrue($result->isValid(), var_export($result, 1)); + + // Verify we got a 200 response + $this->assertEquals(200, $status); + } + + /** + * Checks for an expected 400 Bad Request response + * + * @param array $data Authentication results + * @return void + */ + protected function _checkBadRequest($data) + { + $result = $status = $headers = null; + extract($data); // $result, $status, $headers + + // Make sure the result is false + $this->assertInstanceOf('Zend\\Authentication\\Result', $result); + $this->assertFalse($result->isValid()); + + // Make sure it set the right HTTP code + $this->assertEquals(400, $status); + } + + public function testBasicAuthValidCredsWithCustomIdentityObjectResolverReturnsAuthResult() + { + $this->_basicResolver = new TestAsset\BasicAuthObjectResolver(); + + $result = $this->_doAuth('Basic ' . base64_encode('Bryce:ThisIsNotMyPassword'), 'basic'); + $result = $result['result']; + + $this->assertInstanceOf('Zend\\Authentication\\Result', $result); + $this->assertTrue($result->isValid()); + } + + public function testBasicAuthInvalidCredsWithCustomIdentityObjectResolverReturnsUnauthorizedResponse() + { + $this->_basicResolver = new TestAsset\BasicAuthObjectResolver(); + $data = $this->_doAuth('Basic ' . base64_encode('David:ThisIsNotMyPassword'), 'basic'); + + $expected = array( + 'type' => 'Basic ', + 'realm' => 'realm="' . $this->_bothConfig['realm'] . '"', + ); + + $this->_checkUnauthorized($data, $expected); + } +} diff --git a/test/Adapter/Http/FileResolverTest.php b/test/Adapter/Http/FileResolverTest.php new file mode 100644 index 0000000..098fc45 --- /dev/null +++ b/test/Adapter/Http/FileResolverTest.php @@ -0,0 +1,230 @@ +_filesPath = __DIR__ . '/TestAsset'; + $this->_validPath = "$this->_filesPath/htdigest.3"; + $this->_badPath = 'doesnotexist'; + $this->_resolver = new Http\FileResolver($this->_validPath); + } + + /** + * Ensures that setFile() works as expected for valid input + * + * @return void + */ + public function testSetFileValid() + { + $this->_resolver->setFile($this->_validPath); + $this->assertEquals($this->_validPath, $this->_resolver->getFile()); + } + + /** + * Ensures that setFile() works as expected for invalid input + * + * @return void + */ + public function testSetFileInvalid() + { + $this->setExpectedException('Zend\\Authentication\\Adapter\\Http\\Exception\\ExceptionInterface', 'Path not readable'); + $this->_resolver->setFile($this->_badPath); + } + + /** + * Ensures that __construct() works as expected for valid input + * + * @return void + */ + public function testConstructValid() + { + $v = new Http\FileResolver($this->_validPath); + $this->assertEquals($this->_validPath, $v->getFile()); + } + + /** + * Ensures that __construct() works as expected for invalid input + * + * @return void + */ + public function testConstructInvalid() + { + $this->setExpectedException('Zend\\Authentication\\Adapter\\Http\\Exception\\ExceptionInterface', 'Path not readable'); + $v = new Http\FileResolver($this->_badPath); + } + + /** + * Ensures that resolve() works as expected for empty username + * + * @return void + */ + public function testResolveUsernameEmpty() + { + $this->setExpectedException('Zend\\Authentication\\Adapter\\Http\\Exception\\ExceptionInterface', 'Username is required'); + $this->_resolver->resolve('', ''); + } + + /** + * Ensures that resolve() works as expected for empty realm + * + * @return void + */ + public function testResolveRealmEmpty() + { + $this->setExpectedException('Zend\\Authentication\\Adapter\\Http\\Exception\\ExceptionInterface', 'Realm is required'); + $this->_resolver->resolve('username', ''); + } + + /** + * Ensures that resolve() works as expected for invalid username + * + * @return void + */ + public function testResolveUsernameInvalid() + { + try { + $this->_resolver->resolve('bad:name', 'realm'); + $this->fail('Accepted malformed username with colon'); + } catch (Http\Exception\ExceptionInterface $e) { + $this->assertContains('Username must consist', $e->getMessage()); + } + try { + $this->_resolver->resolve("badname\n", 'realm'); + $this->fail('Accepted malformed username with newline'); + } catch (Http\Exception\ExceptionInterface $e) { + $this->assertContains('Username must consist', $e->getMessage()); + } + } + + /** + * Ensures that resolve() works as expected for invalid realm + * + * @return void + */ + public function testResolveRealmInvalid() + { + try { + $this->_resolver->resolve('username', 'bad:realm'); + $this->fail('Accepted malformed realm with colon'); + } catch (Http\Exception\ExceptionInterface $e) { + $this->assertContains('Realm must consist', $e->getMessage()); + } + try { + $this->_resolver->resolve('username', "badrealm\n"); + $this->fail('Accepted malformed realm with newline'); + } catch (Http\Exception\ExceptionInterface $e) { + $this->assertContains('Realm must consist', $e->getMessage()); + } + } + + /** + * Ensures that resolve() works as expected when a previously readable file becomes unreadable + * + * @return void + */ + public function testResolveFileDisappearsMystery() + { + if (rename("$this->_filesPath/htdigest.3", "$this->_filesPath/htdigest.3.renamed")) { + try { + $this->_resolver->resolve('username', 'realm'); + $this->fail('Expected thrown exception upon resolve() after moving valid file'); + } catch (Http\Exception\ExceptionInterface $e) { + $this->assertContains('Unable to open password file', $e->getMessage()); + } + rename("$this->_filesPath/htdigest.3.renamed", "$this->_filesPath/htdigest.3"); + } + } + + /** + * Ensures that resolve() works as expected when provided valid credentials + * + * @return void + */ + public function testResolveValid() + { + $this->assertEquals( + $this->_resolver->resolve('Bryce', 'Test Realm'), + 'd5b7c330d5685beb782a9e22f0f20579', + 'Rejected valid credentials' + ); + } + + /** + * Ensures that resolve() works as expected when provided nonexistent realm + * + * @return void + */ + public function testResolveRealmNonexistent() + { + $this->assertFalse( + $this->_resolver->resolve('Bryce', 'nonexistent'), + 'Accepted a valid user in the wrong realm' + ); + } + + /** + * Ensures that resolve() works as expected when provided nonexistent user + * + * @return void + */ + public function testResolveUserNonexistent() + { + $this->assertFalse( + $this->_resolver->resolve('nonexistent', 'Test Realm'), + 'Accepted a nonexistent user from an existing realm' + ); + } +} diff --git a/test/Adapter/Http/ObjectTest.php b/test/Adapter/Http/ObjectTest.php new file mode 100644 index 0000000..24f6321 --- /dev/null +++ b/test/Adapter/Http/ObjectTest.php @@ -0,0 +1,242 @@ +_filesPath = __DIR__ . '/TestAsset'; + $this->_basicResolver = new Http\FileResolver("$this->_filesPath/htbasic.1"); + $this->_digestResolver = new Http\FileResolver("$this->_filesPath/htdigest.3"); + $this->_basicConfig = array( + 'accept_schemes' => 'basic', + 'realm' => 'Test Realm' + ); + $this->_digestConfig = array( + 'accept_schemes' => 'digest', + 'realm' => 'Test Realm', + 'digest_domains' => '/ http://localhost/', + 'nonce_timeout' => 300 + ); + $this->_bothConfig = array( + 'accept_schemes' => 'basic digest', + 'realm' => 'Test Realm', + 'digest_domains' => '/ http://localhost/', + 'nonce_timeout' => 300 + ); + } + + public function testValidConfigs() + { + $configs = array ( + $this->_basicConfig, + $this->_digestConfig, + $this->_bothConfig, + ); + foreach($configs as $config) + new Adapter\Http($config); + } + + public function testInvalidConfigs() + { + $badConfigs = array( + 'bad1' => array( + 'auth_type' => 'bogus', + 'realm' => 'Test Realm' + ), + 'bad2' => array( + 'auth_type' => 'digest', + 'realm' => 'Bad: "Chars"'."\n", + 'digest_domains' => '/ /admin', + 'nonce_timeout' => 300 + ), + 'bad3' => array( + 'auth_type' => 'digest', + 'realm' => 'Test Realm', + 'digest_domains' => 'no"quotes'."\tor tabs", + 'nonce_timeout' => 300 + ), + 'bad4' => array( + 'auth_type' => 'digest', + 'realm' => 'Test Realm', + 'digest_domains' => '/ /admin', + 'nonce_timeout' => 'junk' + ) + ); + + foreach ($badConfigs as $cfg) { + $t = null; + try { + $t = new Adapter\Http($cfg); + $this->fail('Accepted an invalid config'); + } catch (Adapter\Exception\ExceptionInterface $e) { + // Good, it threw an exception + } + } + } + + public function testAuthenticateArgs() + { + $a = new Adapter\Http($this->_basicConfig); + + try { + $a->authenticate(); + $this->fail('Attempted authentication without request/response objects'); + } catch (Adapter\Exception\ExceptionInterface $e) { + // Good, it threw an exception + } + + $request = new Request; + $response = new Response; + + // If this throws an exception, it fails + $a->setRequest($request) + ->setResponse($response) + ->authenticate(); + } + + public function testNoResolvers() + { + // Stub request for Basic auth + $headers = new Headers; + $headers->addHeaderLine('Authorization', 'Basic setHeaders($headers); + $response = new Response; + + // Once for Basic + try { + $a = new Adapter\Http($this->_basicConfig); + $a->setRequest($request) + ->setResponse($response); + $result = $a->authenticate(); + $this->fail("Tried Basic authentication without a resolver.\n" . \Zend\Debug::dump($result->getMessages(),null,false)); + } catch (Adapter\Exception\ExceptionInterface $e) { + // Good, it threw an exception + unset($a); + } + + // Stub request for Digest auth, must be reseted (recreated) + $headers = new Headers; + $headers->addHeaderLine('Authorization', 'Digest setHeaders($headers); + + // Once for Digest + try { + $a = new Adapter\Http($this->_digestConfig); + $a->setRequest($request) + ->setResponse($response); + $result = $a->authenticate(); + $this->fail("Tried Digest authentication without a resolver.\n" . \Zend\Debug::dump($result->getMessages(),null,false)); + } catch (Adapter\Exception\ExceptionInterface $e) { + // Good, it threw an exception + unset($a); + } + } + + public function testWrongResolverUsed() + { + $response = new Response(); + $headers = new Headers(); + $request = new Request(); + + $headers->addHeaderLine('Authorization', 'Basic setHeaders($headers); + + // Test a Digest auth process while the request is containing a Basic auth header + $adapter = new Adapter\Http($this->_digestConfig); + $adapter->setDigestResolver($this->_digestResolver) + ->setRequest($request) + ->setResponse($response); + $result = $adapter->authenticate(); + + $this->assertEquals($result->getCode(), Authentication\Result::FAILURE_CREDENTIAL_INVALID); + } + + public function testUnsupportedScheme() + { + $response = new Response(); + $headers = new Headers(); + $request = new Request(); + + $headers->addHeaderLine('Authorization', 'NotSupportedScheme setHeaders($headers); + + $a = new Adapter\Http($this->_digestConfig); + $a->setDigestResolver($this->_digestResolver) + ->setRequest($request) + ->setResponse($response); + $result = $a->authenticate(); + $this->assertEquals($result->getCode(),Authentication\Result::FAILURE_UNCATEGORIZED); + } +} diff --git a/test/Adapter/Http/ProxyTest.php b/test/Adapter/Http/ProxyTest.php new file mode 100644 index 0000000..b3babf5 --- /dev/null +++ b/test/Adapter/Http/ProxyTest.php @@ -0,0 +1,471 @@ +_filesPath = __DIR__ . '/TestAsset'; + $this->_basicResolver = new Http\FileResolver("{$this->_filesPath}/htbasic.1"); + $this->_digestResolver = new Http\FileResolver("{$this->_filesPath}/htdigest.3"); + $this->_basicConfig = array( + 'accept_schemes' => 'basic', + 'realm' => 'Test Realm', + 'proxy_auth' => true + ); + $this->_digestConfig = array( + 'accept_schemes' => 'digest', + 'realm' => 'Test Realm', + 'digest_domains' => '/ http://localhost/', + 'nonce_timeout' => 300, + 'proxy_auth' => true + ); + $this->_bothConfig = array( + 'accept_schemes' => 'basic digest', + 'realm' => 'Test Realm', + 'digest_domains' => '/ http://localhost/', + 'nonce_timeout' => 300, + 'proxy_auth' => true + ); + } + + public function testBasicChallenge() + { + // Trying to authenticate without sending an Proxy-Authorization header + // should result in a 407 reply with a Proxy-Authenticate header, and a + // false result. + + // The expected Basic Proxy-Authenticate header value + $basic = array( + 'type' => 'Basic ', + 'realm' => 'realm="' . $this->_bothConfig['realm'] . '"', + ); + + $data = $this->_doAuth('', 'basic'); + $this->_checkUnauthorized($data, $basic); + } + + public function testDigestChallenge() + { + // Trying to authenticate without sending an Proxy-Authorization header + // should result in a 407 reply with a Proxy-Authenticate header, and a + // false result. + + // The expected Digest Proxy-Authenticate header value + $digest = $this->_digestChallenge(); + + $data = $this->_doAuth('', 'digest'); + $this->_checkUnauthorized($data, $digest); + } + + public function testBothChallenges() + { + // Trying to authenticate without sending an Proxy-Authorization header + // should result in a 407 reply with at least one Proxy-Authenticate + // header, and a false result. + + $data = $this->_doAuth('', 'both'); + extract($data); // $result, $status, $headers + + // The expected Proxy-Authenticate header values + $basic = 'Basic realm="' . $this->_bothConfig['realm'] . '"'; + $digest = $this->_digestChallenge(); + + // Make sure the result is false + $this->assertInstanceOf('Zend\\Authentication\\Result', $result); + $this->assertFalse($result->isValid()); + + // Verify the status code and the presence of both challenges + $this->assertEquals(407, $status); + $this->assertTrue($headers->has('Proxy-Authenticate')); + $authHeader = $headers->get('Proxy-Authenticate'); + $this->assertEquals(2, count($authHeader), var_export($authHeader, 1)); + + // Check to see if the expected challenges match the actual + $basicFound = $digestFound = false; + foreach ($authHeader as $header) { + $value = $header->getFieldValue(); + if (preg_match('/^Basic/', $value)) { + $basicFound = true; + } + if (preg_match('/^Digest/', $value)) { + $digestFound = true; + } + } + $this->assertTrue($basicFound); + $this->assertTrue($digestFound); + } + + public function testBasicAuthValidCreds() + { + // Attempt Basic Authentication with a valid username and password + + $data = $this->_doAuth('Basic ' . base64_encode('Bryce:ThisIsNotMyPassword'), 'basic'); + $this->_checkOK($data); + } + + public function testBasicAuthBadCreds() + { + // Ensure that credentials containing invalid characters are treated as + // a bad username or password. + + // The expected Basic WWW-Authenticate header value + $basic = array( + 'type' => 'Basic ', + 'realm' => 'realm="' . $this->_basicConfig['realm'] . '"', + ); + + $data = $this->_doAuth('Basic ' . base64_encode("Bad\tChars:In:Creds"), 'basic'); + $this->_checkUnauthorized($data, $basic); + } + + public function testBasicAuthBadUser() + { + // Attempt Basic Authentication with a bad username and password + + // The expected Basic Proxy-Authenticate header value + $basic = array( + 'type' => 'Basic ', + 'realm' => 'realm="' . $this->_basicConfig['realm'] . '"', + ); + + $data = $this->_doAuth('Basic ' . base64_encode('Nobody:NotValid'), 'basic'); + $this->_checkUnauthorized($data, $basic); + } + + public function testBasicAuthBadPassword() + { + // Attempt Basic Authentication with a valid username, but invalid + // password + + // The expected Basic WWW-Authenticate header value + $basic = array( + 'type' => 'Basic ', + 'realm' => 'realm="' . $this->_basicConfig['realm'] . '"', + ); + + $data = $this->_doAuth('Basic ' . base64_encode('Bryce:Invalid'), 'basic'); + $this->_checkUnauthorized($data, $basic); + } + + public function testDigestAuthValidCreds() + { + // Attempt Digest Authentication with a valid username and password + + $data = $this->_doAuth($this->_digestReply('Bryce', 'ThisIsNotMyPassword'), 'digest'); + $this->_checkOK($data); + } + + public function testDigestAuthDefaultAlgo() + { + // If the client omits the aglorithm argument, it should default to MD5, + // and work just as above + + $cauth = $this->_digestReply('Bryce', 'ThisIsNotMyPassword'); + $cauth = preg_replace('/algorithm="MD5", /', '', $cauth); + + $data = $this->_doAuth($cauth, 'digest'); + $this->_checkOK($data); + } + + public function testDigestAuthQuotedNC() + { + // The nonce count isn't supposed to be quoted, but apparently some + // clients do anyway. + + $cauth = $this->_digestReply('Bryce', 'ThisIsNotMyPassword'); + $cauth = preg_replace('/nc=00000001/', 'nc="00000001"', $cauth); + + $data = $this->_doAuth($cauth, 'digest'); + $this->_checkOK($data); + } + + public function testDigestAuthBadCreds() + { + // Attempt Digest Authentication with a bad username and password + + // The expected Digest Proxy-Authenticate header value + $digest = $this->_digestChallenge(); + + $data = $this->_doAuth($this->_digestReply('Nobody', 'NotValid'), 'digest'); + $this->_checkUnauthorized($data, $digest); + } + + public function testDigestTampered() + { + // Create the tampered header value + $tampered = $this->_digestReply('Bryce', 'ThisIsNotMyPassword'); + $tampered = preg_replace( + '/ nonce="[a-fA-F0-9]{32}", /', + ' nonce="' . str_repeat('0', 32).'", ', + $tampered + ); + + // The expected Digest Proxy-Authenticate header value + $digest = $this->_digestChallenge(); + + $data = $this->_doAuth($tampered, 'digest'); + $this->_checkUnauthorized($data, $digest); + } + + public function testBadSchemeRequest() + { + // Sending a request for an invalid authentication scheme should result + // in a 400 Bad Request response. + + $data = $this->_doAuth('Invalid ' . base64_encode('Nobody:NotValid'), 'basic'); + $this->_checkBadRequest($data); + } + + public function testBadDigestRequest() + { + // If any of the individual parts of the Digest Proxy-Authorization header + // are bad, it results in a 400 Bad Request. But that's a lot of + // possibilities, so we're just going to pick one for now. + $bad = $this->_digestReply('Bryce', 'ThisIsNotMyPassword'); + $bad = preg_replace( + '/realm="([^"]+)"/', // cut out the realm + '', $bad + ); + + $data = $this->_doAuth($bad, 'digest'); + $this->_checkBadRequest($data); + } + + /** + * Acts like a client sending the given Authenticate header value. + * + * @param string $clientHeader Authenticate header value + * @param string $scheme Which authentication scheme to use + * @return array Containing the result, the response headers, and the status + */ + public function _doAuth($clientHeader, $scheme) + { + // Set up stub request and response objects + $response = new Response; + $response->setStatusCode(200); + + $headers = new Headers(); + $headers->addHeaderLine('Proxy-Authorization', $clientHeader); + $headers->addHeaderLine('User-Agent', 'PHPUnit'); + + $request = new Request(); + $request->setUri('http://localhost/'); + $request->setMethod('GET'); + $request->setHeaders($headers); + + // Select an Authentication scheme + switch ($scheme) { + case 'basic': + $use = $this->_basicConfig; + break; + case 'digest': + $use = $this->_digestConfig; + break; + case 'both': + default: + $use = $this->_bothConfig; + } + + // Create the HTTP Auth adapter + $a = new \Zend\Authentication\Adapter\Http($use); + $a->setBasicResolver($this->_basicResolver); + $a->setDigestResolver($this->_digestResolver); + + // Send the authentication request + $a->setRequest($request); + $a->setResponse($response); + $result = $a->authenticate(); + + $return = array( + 'result' => $result, + 'status' => $response->getStatusCode(), + 'headers' => $response->getHeaders(), + ); + return $return; + } + + /** + * Constructs a local version of the digest challenge we expect to receive + * + * @return string + */ + protected function _digestChallenge() + { + return array( + 'type' => 'Digest ', + 'realm' => 'realm="' . $this->_digestConfig['realm'] . '"', + 'domain' => 'domain="' . $this->_bothConfig['digest_domains'] . '"', + ); + } + + /** + * Constructs a client digest Proxy-Authorization header + * + * @param string $user + * @param string $pass + * @return string + */ + protected function _digestReply($user, $pass) + { + $nc = '00000001'; + $timeout = ceil(time() / 300) * 300; + $nonce = md5($timeout . ':PHPUnit:Zend\\Authentication\\Adapter\\Http'); + $opaque = md5('Opaque Data:Zend\\Authentication\\Adapter\\Http'); + $cnonce = md5('cnonce'); + $response = md5(md5($user . ':' . $this->_digestConfig['realm'] . ':' . $pass) . ":$nonce:$nc:$cnonce:auth:" + . md5('GET:/')); + $cauth = 'Digest ' + . 'username="Bryce", ' + . 'realm="' . $this->_digestConfig['realm'] . '", ' + . 'nonce="' . $nonce . '", ' + . 'uri="/", ' + . 'response="' . $response . '", ' + . 'algorithm="MD5", ' + . 'cnonce="' . $cnonce . '", ' + . 'opaque="' . $opaque . '", ' + . 'qop="auth", ' + . 'nc=' . $nc; + + return $cauth; + } + + /** + * Checks for an expected 407 Proxy-Unauthorized response + * + * @param array $data Authentication results + * @param string $expected Expected Proxy-Authenticate header value + * @return void + */ + protected function _checkUnauthorized($data, $expected) + { + extract($data); // $result, $status, $headers + + // Make sure the result is false + $this->assertInstanceOf('Zend\\Authentication\\Result', $result); + $this->assertFalse($result->isValid()); + + // Verify the status code and the presence of the challenge + $this->assertEquals(407, $status); + $this->assertTrue($headers->has('Proxy-Authenticate')); + + // Check to see if the expected challenge matches the actual + $headers = $headers->get('Proxy-Authenticate'); + $this->assertTrue($headers instanceof \ArrayIterator); + $this->assertEquals(1, count($headers)); + $header = $headers[0]->getFieldValue(); + $this->assertContains($expected['type'], $header, $header); + $this->assertContains($expected['realm'], $header, $header); + if (isset($expected['domain'])) { + $this->assertContains($expected['domain'], $header, $header); + $this->assertContains('algorithm="MD5"', $header, $header); + $this->assertContains('qop="auth"', $header, $header); + $this->assertRegExp('/nonce="[a-fA-F0-9]{32}"/', $header, $header); + $this->assertRegExp('/opaque="[a-fA-F0-9]{32}"/', $header, $header); + } + } + + /** + * Checks for an expected 200 OK response + * + * @param array $data Authentication results + * @return void + */ + protected function _checkOK($data) + { + extract($data); // $result, $status, $headers + + // Make sure the result is true + $this->assertInstanceOf('Zend\\Authentication\\Result', $result); + $this->assertTrue($result->isValid(), var_export($result->getMessages(), 1)); + + // Verify we got a 200 response + $this->assertEquals(200, $status); + } + + /** + * Checks for an expected 400 Bad Request response + * + * @param array $data Authentication results + * @return void + */ + protected function _checkBadRequest($data) + { + extract($data); // $result, $status, $headers + + // Make sure the result is false + $this->assertInstanceOf('Zend\\Authentication\\Result', $result); + $this->assertFalse($result->isValid()); + + // Make sure it set the right HTTP code + $this->assertEquals(400, $status); + } +} diff --git a/test/Adapter/Http/TestAsset/htbasic.1 b/test/Adapter/Http/TestAsset/htbasic.1 new file mode 100644 index 0000000..7f18f96 --- /dev/null +++ b/test/Adapter/Http/TestAsset/htbasic.1 @@ -0,0 +1,3 @@ +Bryce:Test Realm:ThisIsNotMyPassword +Mufasa:Test Realm:Circle Of Life +Bad Chars:In:Creds diff --git a/test/Adapter/Http/TestAsset/htdigest.3 b/test/Adapter/Http/TestAsset/htdigest.3 new file mode 100644 index 0000000..f9f4944 --- /dev/null +++ b/test/Adapter/Http/TestAsset/htdigest.3 @@ -0,0 +1,2 @@ +Bryce:Test Realm:d5b7c330d5685beb782a9e22f0f20579 +Mufasa:Test Realm:200dc292ecb68e04c95bb74ae2ce3c80 diff --git a/test/Adapter/Ldap/OfflineTest.php b/test/Adapter/Ldap/OfflineTest.php new file mode 100644 index 0000000..55696b1 --- /dev/null +++ b/test/Adapter/Ldap/OfflineTest.php @@ -0,0 +1,93 @@ +adapter = new Adapter\Ldap(); + } + + public function testGetSetLdap() + { + if (!extension_loaded('ldap')) { + $this->markTestSkipped('LDAP is not enabled'); + } + $this->adapter->setLdap(new Ldap\Ldap()); + $this->assertInstanceOf('Zend\Ldap\Ldap', $this->adapter->getLdap()); + } + + public function testUsernameIsNullIfNotSet() + { + $this->assertNull($this->adapter->getUsername()); + } + + public function testPasswordIsNullIfNotSet() + { + $this->assertNull($this->adapter->getPassword()); + } + + public function testSetAndGetUsername() + { + $usernameExpected = 'someUsername'; + $usernameActual = $this->adapter->setUsername($usernameExpected) + ->getUsername(); + $this->assertSame($usernameExpected, $usernameActual); + } + + public function testSetAndGetPassword() + { + $passwordExpected = 'somePassword'; + $passwordActual = $this->adapter->setPassword($passwordExpected) + ->getPassword(); + $this->assertSame($passwordExpected, $passwordActual); + } + + public function testSetIdentityProxiesToSetUsername() + { + $usernameExpected = 'someUsername'; + $usernameActual = $this->adapter->setIdentity($usernameExpected) + ->getUsername(); + $this->assertSame($usernameExpected, $usernameActual); + } + + public function testSetCredentialProxiesToSetPassword() + { + $passwordExpected = 'somePassword'; + $passwordActual = $this->adapter->setCredential($passwordExpected) + ->getPassword(); + $this->assertSame($passwordExpected, $passwordActual); + } +} diff --git a/test/Adapter/Ldap/OnlineTest.php b/test/Adapter/Ldap/OnlineTest.php new file mode 100644 index 0000000..67c9ab1 --- /dev/null +++ b/test/Adapter/Ldap/OnlineTest.php @@ -0,0 +1,192 @@ +markTestSkipped('LDAP online tests are not enabled'); + } + $this->options = array( + 'host' => TESTS_ZEND_LDAP_HOST, + 'username' => TESTS_ZEND_LDAP_USERNAME, + 'password' => TESTS_ZEND_LDAP_PASSWORD, + 'baseDn' => TESTS_ZEND_LDAP_BASE_DN, + ); + if (defined('TESTS_ZEND_LDAP_PORT')) + $this->options['port'] = TESTS_ZEND_LDAP_PORT; + if (defined('TESTS_ZEND_LDAP_USE_START_TLS')) + $this->options['useStartTls'] = TESTS_ZEND_LDAP_USE_START_TLS; + if (defined('TESTS_ZEND_LDAP_USE_SSL')) + $this->options['useSsl'] = TESTS_ZEND_LDAP_USE_SSL; + if (defined('TESTS_ZEND_LDAP_BIND_REQUIRES_DN')) + $this->options['bindRequiresDn'] = TESTS_ZEND_LDAP_BIND_REQUIRES_DN; + if (defined('TESTS_ZEND_LDAP_ACCOUNT_FILTER_FORMAT')) + $this->options['accountFilterFormat'] = TESTS_ZEND_LDAP_ACCOUNT_FILTER_FORMAT; + if (defined('TESTS_ZEND_LDAP_ACCOUNT_DOMAIN_NAME')) + $this->options['accountDomainName'] = TESTS_ZEND_LDAP_ACCOUNT_DOMAIN_NAME; + if (defined('TESTS_ZEND_LDAP_ACCOUNT_DOMAIN_NAME_SHORT')) + $this->options['accountDomainNameShort'] = TESTS_ZEND_LDAP_ACCOUNT_DOMAIN_NAME_SHORT; + + if (defined('TESTS_ZEND_LDAP_ALT_USERNAME')) { + $this->names[Ldap\Ldap::ACCTNAME_FORM_USERNAME] = TESTS_ZEND_LDAP_ALT_USERNAME; + if (defined('TESTS_ZEND_LDAP_ACCOUNT_DOMAIN_NAME')) { + $this->names[Ldap\Ldap::ACCTNAME_FORM_PRINCIPAL] = + TESTS_ZEND_LDAP_ALT_USERNAME . '@' . TESTS_ZEND_LDAP_ACCOUNT_DOMAIN_NAME; + } + if (defined('TESTS_ZEND_LDAP_ACCOUNT_DOMAIN_NAME_SHORT')) { + $this->names[Ldap\Ldap::ACCTNAME_FORM_BACKSLASH] = + TESTS_ZEND_LDAP_ACCOUNT_DOMAIN_NAME_SHORT . '\\' . TESTS_ZEND_LDAP_ALT_USERNAME; + } + } + } + + public function testSimpleAuth() + { + $adapter = new Adapter\Ldap( + array($this->options), + TESTS_ZEND_LDAP_ALT_USERNAME, + TESTS_ZEND_LDAP_ALT_PASSWORD + ); + + $result = $adapter->authenticate(); + + $this->assertTrue($result instanceof Authentication\Result); + $this->assertTrue($result->isValid()); + $this->assertTrue($result->getCode() == Authentication\Result::SUCCESS); + } + + public function testCanonAuth() + { + /* This test authenticates with each of the account name forms + * (uname, uname@example.com, EXAMPLE\uname) AND it does so with + * the accountCanonicalForm set to each of the account name forms + * (e.g. authenticate with uname@example.com but getIdentity() returns + * EXAMPLE\uname). A total of 9 authentications are performed. + */ + foreach ($this->names as $form => $formName) { + $options = $this->options; + $options['accountCanonicalForm'] = $form; + $adapter = new Adapter\Ldap(array($options)); + $adapter->setPassword(TESTS_ZEND_LDAP_ALT_PASSWORD); + foreach ($this->names as $username) { + $adapter->setUsername($username); + $result = $adapter->authenticate(); + $this->assertTrue($result instanceof Authentication\Result); + $this->assertTrue($result->isValid()); + $this->assertTrue($result->getCode() == Authentication\Result::SUCCESS); + $this->assertTrue($result->getIdentity() === $formName); + } + } + } + + public function testInvalidPassAuth() + { + $adapter = new Adapter\Ldap( + array($this->options), + TESTS_ZEND_LDAP_ALT_USERNAME, + 'invalid' + ); + + $result = $adapter->authenticate(); + $this->assertTrue($result instanceof Authentication\Result); + $this->assertTrue($result->isValid() === false); + $this->assertTrue($result->getCode() == Authentication\Result::FAILURE_CREDENTIAL_INVALID); + } + + public function testInvalidUserAuth() + { + $adapter = new Adapter\Ldap( + array($this->options), + 'invalid', + 'doesntmatter' + ); + + $result = $adapter->authenticate(); + $this->assertTrue($result instanceof Authentication\Result); + $this->assertTrue($result->isValid() === false); + $this->assertTrue( + $result->getCode() == Authentication\Result::FAILURE_IDENTITY_NOT_FOUND || + $result->getCode() == Authentication\Result::FAILURE_CREDENTIAL_INVALID + ); + } + + public function testMismatchDomainAuth() + { + $adapter = new Adapter\Ldap( + array($this->options), + 'EXAMPLE\\doesntmatter', + 'doesntmatter' + ); + + $result = $adapter->authenticate(); + $this->assertTrue($result instanceof Authentication\Result); + $this->assertFalse($result->isValid()); + $this->assertThat($result->getCode(), $this->lessThanOrEqual(Authentication\Result::FAILURE)); + $messages = $result->getMessages(); + $this->assertContains('not found', $messages[0]); + } + + public function testAccountObjectRetrieval() + { + $adapter = new Adapter\Ldap( + array($this->options), + TESTS_ZEND_LDAP_ALT_USERNAME, + TESTS_ZEND_LDAP_ALT_PASSWORD + ); + + $result = $adapter->authenticate(); + $account = $adapter->getAccountObject(); + + //$this->assertTrue($result->isValid()); + $this->assertInternalType('object', $account); + $this->assertEquals(TESTS_ZEND_LDAP_ALT_DN, $account->dn); + } + + public function testAccountObjectRetrievalWithOmittedAttributes() + { + $adapter = new Adapter\Ldap( + array($this->options), + TESTS_ZEND_LDAP_ALT_USERNAME, + TESTS_ZEND_LDAP_ALT_PASSWORD + ); + + $result = $adapter->authenticate(); + $account = $adapter->getAccountObject(array(), array('userPassword')); + + $this->assertInternalType('object', $account); + $this->assertFalse(isset($account->userpassword)); + } +} diff --git a/test/Adapter/TestAsset/Digest/htdigest.1 b/test/Adapter/TestAsset/Digest/htdigest.1 new file mode 100644 index 0000000..ff62927 --- /dev/null +++ b/test/Adapter/TestAsset/Digest/htdigest.1 @@ -0,0 +1,2 @@ +someUser:Some Realm:fde17b91c3a510ecbaf7dbd37f59d4f8 +someOtherUser:Some Other Realm:1911c62b21a85c85c4c1a57785893b94 diff --git a/test/Adapter/TestAsset/OpenId/.gitignore b/test/Adapter/TestAsset/OpenId/.gitignore new file mode 100644 index 0000000..e69de29 diff --git a/test/Adapter/TestAsset/OpenId/assoc.lock b/test/Adapter/TestAsset/OpenId/assoc.lock new file mode 100644 index 0000000..e69de29 diff --git a/test/Adapter/TestAsset/OpenId/discovery.lock b/test/Adapter/TestAsset/OpenId/discovery.lock new file mode 100644 index 0000000..e69de29 diff --git a/test/Adapter/TestAsset/OpenId/nonce.lock b/test/Adapter/TestAsset/OpenId/nonce.lock new file mode 100644 index 0000000..e69de29 diff --git a/test/Adapter/TestAsset/OpenId/nonce_9f11599cc1f088b7c358f33610cb126c b/test/Adapter/TestAsset/OpenId/nonce_9f11599cc1f088b7c358f33610cb126c new file mode 100644 index 0000000..83c598f --- /dev/null +++ b/test/Adapter/TestAsset/OpenId/nonce_9f11599cc1f088b7c358f33610cb126c @@ -0,0 +1 @@ +http://www.myopenid.com/;2007-08-14T12:52:33Z46c1a59124ffe \ No newline at end of file diff --git a/test/Adapter/TestAsset/OpenIdResponseHelper.php b/test/Adapter/TestAsset/OpenIdResponseHelper.php new file mode 100644 index 0000000..6a39bb6 --- /dev/null +++ b/test/Adapter/TestAsset/OpenIdResponseHelper.php @@ -0,0 +1,40 @@ +_canSendHeaders = $canSendHeaders; + } + + public function canSendHeaders($throw = false) + { + return $this->_canSendHeaders; + } + + public function sendResponse() + { + } +} diff --git a/test/AuthenticationServiceTest.php b/test/AuthenticationServiceTest.php new file mode 100644 index 0000000..edbf926 --- /dev/null +++ b/test/AuthenticationServiceTest.php @@ -0,0 +1,90 @@ +auth = new AuthenticationService(); + } + + /** + * Ensures that getStorage() returns Zend_Auth_Storage_Session + * + * @return void + */ + public function testGetStorage() + { + $storage = $this->auth->getStorage(); + $this->assertTrue($storage instanceof Auth\Storage\Session); + } + + public function testAdapter() + { + $this->assertNull($this->auth->getAdapter()); + $successAdapter = new TestAsset\SuccessAdapter(); + $ret = $this->auth->setAdapter($successAdapter); + $this->assertSame($ret, $this->auth); + $this->assertSame($successAdapter, $this->auth->getAdapter()); + } + + /** + * Ensures expected behavior for successful authentication + * + * @return void + */ + public function testAuthenticate() + { + $result = $this->authenticate(); + $this->assertTrue($result instanceof Auth\Result); + $this->assertTrue($this->auth->hasIdentity()); + $this->assertEquals('someIdentity', $this->auth->getIdentity()); + } + + public function testAuthenticateSetAdapter() + { + $result = $this->authenticate(new TestAsset\SuccessAdapter()); + $this->assertTrue($result instanceof Auth\Result); + $this->assertTrue($this->auth->hasIdentity()); + $this->assertEquals('someIdentity', $this->auth->getIdentity()); + } + + /** + * Ensures expected behavior for clearIdentity() + * + * @return void + */ + public function testClearIdentity() + { + $this->authenticate(); + $this->auth->clearIdentity(); + $this->assertFalse($this->auth->hasIdentity()); + $this->assertEquals(null, $this->auth->getIdentity()); + } + + protected function authenticate($adapter = null) + { + if ($adapter === null) { + $adapter = new TestAsset\SuccessAdapter(); + } + return $this->auth->authenticate($adapter); + } +} diff --git a/test/TestAsset/SuccessAdapter.php b/test/TestAsset/SuccessAdapter.php new file mode 100644 index 0000000..e0b5f71 --- /dev/null +++ b/test/TestAsset/SuccessAdapter.php @@ -0,0 +1,22 @@ + Date: Tue, 21 Aug 2012 11:13:05 -0500 Subject: [PATCH 60/61] [zendframework/zf2#2210] Pass ErrorHandler::stop() result as previous exception - Per @mark-mabe - Any place where an exception is throw immediately following an ErrorHandler::stop() call should pass the result of that call as the previous exception. --- src/Adapter/Digest.php | 4 ++-- src/Adapter/Http/FileResolver.php | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Adapter/Digest.php b/src/Adapter/Digest.php index 9c1f570..332fce8 100644 --- a/src/Adapter/Digest.php +++ b/src/Adapter/Digest.php @@ -172,9 +172,9 @@ public function authenticate() ErrorHandler::start(E_WARNING); $fileHandle = fopen($this->filename, 'r'); - ErrorHandler::stop(); + $error = ErrorHandler::stop(); if (false === $fileHandle) { - throw new Exception\UnexpectedValueException("Cannot open '$this->filename' for reading"); + throw new Exception\UnexpectedValueException("Cannot open '$this->filename' for reading", 0, $error); } $id = "$this->username:$this->realm"; diff --git a/src/Adapter/Http/FileResolver.php b/src/Adapter/Http/FileResolver.php index 00731b5..9abaa5a 100644 --- a/src/Adapter/Http/FileResolver.php +++ b/src/Adapter/Http/FileResolver.php @@ -105,10 +105,10 @@ public function resolve($username, $realm, $password = null) // Open file, read through looking for matching credentials ErrorHandler::start(E_WARNING); - $fp = fopen($this->file, 'r'); - ErrorHandler::stop(); + $fp = fopen($this->file, 'r'); + $error = ErrorHandler::stop(); if (!$fp) { - throw new Exception\RuntimeException('Unable to open password file: ' . $this->file); + throw new Exception\RuntimeException('Unable to open password file: ' . $this->file, 0, $error); } // No real validation is done on the contents of the password file. The From 216e55a20fe86d1c719ea3e4aca372b0248832c8 Mon Sep 17 00:00:00 2001 From: Michel Hunziker Date: Fri, 31 Aug 2012 19:52:32 +0200 Subject: [PATCH 61/61] Resolve undefined classes in phpDoc --- src/Adapter/DbTable.php | 3 ++- src/Adapter/Ldap.php | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Adapter/DbTable.php b/src/Adapter/DbTable.php index f53e3a0..618289d 100644 --- a/src/Adapter/DbTable.php +++ b/src/Adapter/DbTable.php @@ -10,6 +10,7 @@ namespace Zend\Authentication\Adapter; +use stdClass; use Zend\Authentication\Result as AuthenticationResult; use Zend\Db\Adapter\Adapter as DbAdapter; use Zend\Db\ResultSet\ResultSet; @@ -272,7 +273,7 @@ public function getResultRowObject($returnColumns = null, $omitColumns = null) return false; } - $returnObject = new \stdClass(); + $returnObject = new stdClass(); if (null !== $returnColumns) { diff --git a/src/Adapter/Ldap.php b/src/Adapter/Ldap.php index 4c874b3..0e2c1ad 100644 --- a/src/Adapter/Ldap.php +++ b/src/Adapter/Ldap.php @@ -10,6 +10,7 @@ namespace Zend\Authentication\Adapter; +use stdClass; use Zend\Authentication\Result as AuthenticationResult; use Zend\Ldap as ZendLdap; use Zend\Ldap\Exception\LdapException; @@ -459,7 +460,7 @@ public function getAccountObject(array $returnAttribs = array(), array $omitAttr return false; } - $returnObject = new \stdClass(); + $returnObject = new stdClass(); $omitAttribs = array_map('strtolower', $omitAttribs);