'admin', 'password' => 'pw'); check('hashed, plain name', $hashed(), 'auth=0123456789abcdef0123456789abcdef&user=admin'); check('plain, plain name', $plain(), 'username=admin&password=pw'); check('none, plain name', $none(), 'username=admin'); // A name with the query string's own delimiters comes back whole. $name = 'a&user=admin=x'; $_SESSION = array('username' => $name, 'password' => 'p&w=1 +%'); $p = relay_params($hashed()); check('hashed: user is the session name', $p['user'], $name); check('hashed: auth is the hash', $p['auth'], '0123456789abcdef0123456789abcdef'); check('hashed: no extra parameters', array_keys($p), array('auth', 'user')); $p = relay_params($plain()); check('plain: username is the session name', $p['username'], $name); check('plain: password is the session password', $p['password'], 'p&w=1 +%'); check('plain: no extra parameters', array_keys($p), array('username', 'password')); $p = relay_params($none()); check('none: username is the session name', $p['username'], $name); check('none: no extra parameters', array_keys($p), array('username')); // A space, which urlencode() writes as + and both receivers read back. $_SESSION = array('username' => 'front door'); check('none: a space round-trips', relay_params($none())['username'], 'front door'); echo "\n$passes passed, $failures failed\n"; exit($failures ? 1 : 0); }