summaryrefslogtreecommitdiffstats
path: root/Tests/Auth/OpenID
diff options
context:
space:
mode:
authorJosh Hoyt <josh@janrain.com>2006-01-24 23:14:56 +0000
committerJosh Hoyt <josh@janrain.com>2006-01-24 23:14:56 +0000
commite868ff9c5e5d987389411c7b40bae6856f3be410 (patch)
tree8eb4e20c9fa29892922fa16437a664409b901a9f /Tests/Auth/OpenID
parentd551e9c89cce69abf5782c70616d3b3236968c78 (diff)
downloadphp-openid-e868ff9c5e5d987389411c7b40bae6856f3be410.zip
php-openid-e868ff9c5e5d987389411c7b40bae6856f3be410.tar.gz
php-openid-e868ff9c5e5d987389411c7b40bae6856f3be410.tar.bz2
[project @ Add memstore for testing]
Diffstat (limited to 'Tests/Auth/OpenID')
-rw-r--r--Tests/Auth/OpenID/MemStore.php110
-rw-r--r--Tests/Auth/OpenID/StoreTest.php8
2 files changed, 118 insertions, 0 deletions
diff --git a/Tests/Auth/OpenID/MemStore.php b/Tests/Auth/OpenID/MemStore.php
new file mode 100644
index 0000000..03c9eb2
--- /dev/null
+++ b/Tests/Auth/OpenID/MemStore.php
@@ -0,0 +1,110 @@
+<?php
+
+/**
+ * In-memory OpenID store implementation for testing only
+ */
+require_once "Auth/OpenID/Store/Interface.php";
+
+class Tests_Auth_OpenID_MemStore extends Auth_OpenID_OpenIDStore {
+ var $assocs = null;
+ var $nonces = null;
+
+ function Tests_Auth_OpenID_MemStore($auth_key=null)
+ {
+ $this->assocs = array();
+ $this->nonces = array();
+ $this->auth_key = $auth_key;
+ }
+
+ function getKey($server_url, $handle)
+ {
+ return serialize(array($server_url, $handle));
+ }
+
+ function getAssocPairs()
+ {
+ $pairs = array();
+ foreach ($this->assocs as $key => $assoc) {
+ list($assoc_url, $_) = unserialize($key);
+ $pairs[] = array($assoc_url, $assoc);
+ }
+ return $pairs;
+ }
+
+ function getServerAssocs($server_url)
+ {
+ $matches = array();
+ foreach ($this->getAssocPairs() as $pair) {
+ list($assoc_url, $assoc) = $pair;
+ if ($assoc_url == $server_url) {
+ $matches[] = $assoc;
+ }
+ }
+ return $matches;
+ }
+
+ function getAssociation($server_url, $handle=null)
+ {
+ $assocs = $this->getServerAssocs($server_url);
+ if ($handle === null) {
+ $best = null;
+ foreach ($assocs as $assoc) {
+ if (!isset($best) ||
+ $best->issued < $assoc->issued) {
+
+ $best = $assoc;
+ }
+ }
+ return $best;
+ } else {
+ foreach ($assocs as $assoc) {
+ if ($assoc->handle == $handle) {
+ return $assoc;
+ }
+ }
+ return null;
+ }
+ }
+
+ function storeAssociation($server_url, $association)
+ {
+ $key = $this->getKey($server_url, $association->handle);
+ $this->assocs[$key] = $association;
+ }
+
+ function removeAssociation($server_url, $handle)
+ {
+ $key = $this->getKey($server_url, $handle);
+ $present = isset($this->assocs[$key]);
+ unset($this->assocs[$key]);
+ return $present;
+ }
+
+ function storeNonce($nonce)
+ {
+ if (!in_array($nonce, $this->nonces)) {
+ $this->nonces[] = $nonce;
+ }
+ }
+
+ function useNonce($nonce)
+ {
+ $index = array_search($nonce, $this->nonces);
+ $present = $index !== false;
+ if ($present) {
+ unset($this->nonces[$index]);
+ }
+ return $present;
+ }
+
+ function reset()
+ {
+ $this->assocs = array();
+ $this->nonces = array();
+ }
+
+ function getAuthKey()
+ {
+ return $this->auth_key;
+ }
+} \ No newline at end of file
diff --git a/Tests/Auth/OpenID/StoreTest.php b/Tests/Auth/OpenID/StoreTest.php
index 1ab562b..aeacedc 100644
--- a/Tests/Auth/OpenID/StoreTest.php
+++ b/Tests/Auth/OpenID/StoreTest.php
@@ -299,6 +299,14 @@ explicitly');
"Key length not equals AUTH_KEY_LEN");
}
+ function test_memstore()
+ {
+ require_once 'Tests/Auth/OpenID/MemStore.php';
+ $store = new Tests_Auth_OpenID_MemStore('Bogus auth key ');
+ $this->_testStore(&$store);
+ $this->_testNonce(&$store);
+ }
+
function test_filestore()
{
require_once 'Auth/OpenID/Store/FileStore.php';