Commit 723c3251 authored by webchick's avatar webchick

Issue #1848054 by ACF: Added Change openid test variables to the state system.

parent a4e1315e
...@@ -75,9 +75,9 @@ function testDiscovery() { ...@@ -75,9 +75,9 @@ function testDiscovery() {
$identity = url('openid-test/yadis/xrds/dummy-user', array('absolute' => TRUE, 'fragment' => $this->randomName())); $identity = url('openid-test/yadis/xrds/dummy-user', array('absolute' => TRUE, 'fragment' => $this->randomName()));
// Tell openid_test.module to respond with this identifier. If the fragment // Tell openid_test.module to respond with this identifier. If the fragment
// part is present in the identifier, it should be retained. // part is present in the identifier, it should be retained.
variable_set('openid_test_response', array('openid.claimed_id' => $identity)); state()->set('openid_test.response', array('openid.claimed_id' => $identity));
$this->addIdentity(url('openid-test/yadis/xrds/server', array('absolute' => TRUE)), 2, 'http://specs.openid.net/auth/2.0/identifier_select', $identity); $this->addIdentity(url('openid-test/yadis/xrds/server', array('absolute' => TRUE)), 2, 'http://specs.openid.net/auth/2.0/identifier_select', $identity);
variable_set('openid_test_response', array()); state()->set('openid_test.response', array());
// Identifier is the URL of an HTML page that is sent with an HTTP header // Identifier is the URL of an HTML page that is sent with an HTTP header
// that contains the URL of an XRDS document. // that contains the URL of an XRDS document.
...@@ -94,7 +94,7 @@ function testDiscovery() { ...@@ -94,7 +94,7 @@ function testDiscovery() {
$this->addIdentity('@example*résumé;%25', 2, 'http://example.com/xrds', 'http://example.com/user'); $this->addIdentity('@example*résumé;%25', 2, 'http://example.com/xrds', 'http://example.com/user');
// Make sure that unverified CanonicalID are not trusted. // Make sure that unverified CanonicalID are not trusted.
variable_set('openid_test_canonical_id_status', 'bad value'); state()->set('openid_test.canonical_id_status', 'bad value');
$this->addIdentity('@example*résumé;%25', 2, FALSE, FALSE); $this->addIdentity('@example*résumé;%25', 2, FALSE, FALSE);
// HTML-based discovery: // HTML-based discovery:
...@@ -140,20 +140,20 @@ function testLogin() { ...@@ -140,20 +140,20 @@ function testLogin() {
// Use a User-supplied Identity that is the URL of an XRDS document. // Use a User-supplied Identity that is the URL of an XRDS document.
$identity = url('openid-test/yadis/xrds', array('absolute' => TRUE)); $identity = url('openid-test/yadis/xrds', array('absolute' => TRUE));
$this->addIdentity($identity); $this->addIdentity($identity);
$response = variable_get('openid_test_hook_openid_response_response'); $response = state()->get('openid_test.hook_openid_response_response');
$account = variable_get('openid_test_hook_openid_response_account'); $account = state()->get('openid_test.hook_openid_response_account');
$this->assertEqual($response['openid.claimed_id'], $identity, 'hook_openid_response() was invoked.'); $this->assertEqual($response['openid.claimed_id'], $identity, 'hook_openid_response() was invoked.');
$this->assertEqual($account->uid, $this->web_user->uid, 'Proper user object passed to hook_openid_response().'); $this->assertEqual($account->uid, $this->web_user->uid, 'Proper user object passed to hook_openid_response().');
$this->drupalLogout(); $this->drupalLogout();
// Test logging in via the login block on the front page. // Test logging in via the login block on the front page.
variable_del('openid_test_hook_openid_response_response'); state()->delete('openid_test.hook_openid_response_response');
variable_del('openid_test_hook_openid_response_account'); state()->delete('openid_test.hook_openid_response_account');
$this->submitLoginForm($identity); $this->submitLoginForm($identity);
$this->assertLink(t('Log out'), 0, 'User was logged in.'); $this->assertLink(t('Log out'), 0, 'User was logged in.');
$response = variable_get('openid_test_hook_openid_response_response'); $response = state()->get('openid_test.hook_openid_response_response');
$account = variable_get('openid_test_hook_openid_response_account'); $account = state()->get('openid_test.hook_openid_response_account');
$this->assertEqual($response['openid.claimed_id'], $identity, 'hook_openid_response() was invoked.'); $this->assertEqual($response['openid.claimed_id'], $identity, 'hook_openid_response() was invoked.');
$this->assertEqual($account->uid, $this->web_user->uid, 'Proper user object passed to hook_openid_response().'); $this->assertEqual($account->uid, $this->web_user->uid, 'Proper user object passed to hook_openid_response().');
...@@ -179,11 +179,11 @@ function testLogin() { ...@@ -179,11 +179,11 @@ function testLogin() {
// Tell openid_test.module to alter the checkid_setup request. // Tell openid_test.module to alter the checkid_setup request.
$new_identity = 'http://example.com/' . $this->randomName(); $new_identity = 'http://example.com/' . $this->randomName();
variable_set('openid_test_identity', $new_identity); state()->set('openid_test.identity', $new_identity);
variable_set('openid_test_request_alter', array('checkid_setup' => array('openid.identity' => $new_identity))); state()->set('openid_test.request_alter', array('checkid_setup' => array('openid.identity' => $new_identity)));
$this->submitLoginForm($identity); $this->submitLoginForm($identity);
$this->assertLink(t('Log out'), 0, 'User was logged in.'); $this->assertLink(t('Log out'), 0, 'User was logged in.');
$response = variable_get('openid_test_hook_openid_response_response'); $response = state()->get('openid_test.hook_openid_response_response');
$this->assertEqual($response['openid.identity'], $new_identity, 'hook_openid_request_alter() were invoked.'); $this->assertEqual($response['openid.identity'], $new_identity, 'hook_openid_request_alter() were invoked.');
$this->drupalLogout(); $this->drupalLogout();
...@@ -292,7 +292,7 @@ function testBlockedUserLogin() { ...@@ -292,7 +292,7 @@ function testBlockedUserLogin() {
*/ */
function addIdentity($identity, $version = 2, $local_id = 'http://example.com/xrds', $claimed_id = NULL) { function addIdentity($identity, $version = 2, $local_id = 'http://example.com/xrds', $claimed_id = NULL) {
// Tell openid_test.module to only accept this OP-Local Identifier. // Tell openid_test.module to only accept this OP-Local Identifier.
variable_set('openid_test_identity', $local_id); state()->set('openid_test.identity', $local_id);
$edit = array('openid_identifier' => $identity); $edit = array('openid_identifier' => $identity);
$this->drupalPost('user/' . $this->web_user->uid . '/openid', $edit, t('Add an OpenID')); $this->drupalPost('user/' . $this->web_user->uid . '/openid', $edit, t('Add an OpenID'));
...@@ -342,14 +342,14 @@ function addRedirectedIdentity($identity, $version = 2, $local_id = 'http://exam ...@@ -342,14 +342,14 @@ function addRedirectedIdentity($identity, $version = 2, $local_id = 'http://exam
// Identifier, we insert the same identifier also to the provider response, // Identifier, we insert the same identifier also to the provider response,
// but provider could further change the Claimed ID actually (e.g. it could // but provider could further change the Claimed ID actually (e.g. it could
// add unique fragment). // add unique fragment).
variable_set('openid_test_redirect_url', $identity); state()->set('openid_test.redirect_url', $identity);
variable_set('openid_test_response', array('openid.claimed_id' => $identity)); state()->set('openid_test.response', array('openid.claimed_id' => $identity));
$this->addIdentity(url('openid-test/redirect/' . $redirects, array('absolute' => TRUE)), $version, $local_id, $claimed_id); $this->addIdentity(url('openid-test/redirect/' . $redirects, array('absolute' => TRUE)), $version, $local_id, $claimed_id);
// Clean up. // Clean up.
variable_del('openid_test_redirect_url'); state()->delete('openid_test.redirect_url');
variable_del('openid_test_response'); state()->delete('openid_test.response');
} }
/** /**
...@@ -361,12 +361,12 @@ function testSignatureValidation() { ...@@ -361,12 +361,12 @@ function testSignatureValidation() {
$identity = url('openid-test/yadis/xrds', array('absolute' => TRUE)); $identity = url('openid-test/yadis/xrds', array('absolute' => TRUE));
// Respond with an invalid signature. // Respond with an invalid signature.
variable_set('openid_test_response', array('openid.sig' => 'this-is-an-invalid-signature')); state()->set('openid_test.response', array('openid.sig' => 'this-is-an-invalid-signature'));
$this->submitLoginForm($identity); $this->submitLoginForm($identity);
$this->assertRaw('OpenID login failed.'); $this->assertRaw('OpenID login failed.');
// Do not sign the mandatory field openid.assoc_handle. // Do not sign the mandatory field openid.assoc_handle.
variable_set('openid_test_response', array('openid.signed' => 'op_endpoint,claimed_id,identity,return_to,response_nonce')); state()->set('openid_test.response', array('openid.signed' => 'op_endpoint,claimed_id,identity,return_to,response_nonce'));
$this->submitLoginForm($identity); $this->submitLoginForm($identity);
$this->assertRaw('OpenID login failed.'); $this->assertRaw('OpenID login failed.');
...@@ -385,7 +385,7 @@ function testSignatureValidation() { ...@@ -385,7 +385,7 @@ function testSignatureValidation() {
'openid.signed' => implode(',', $keys_to_sign), 'openid.signed' => implode(',', $keys_to_sign),
); );
$response['openid.sig'] = _openid_signature($association, $response, $keys_to_sign); $response['openid.sig'] = _openid_signature($association, $response, $keys_to_sign);
variable_set('openid_test_response', $response); state()->set('openid_test.response', $response);
$this->submitLoginForm($identity); $this->submitLoginForm($identity);
$this->assertNoRaw('OpenID login failed.'); $this->assertNoRaw('OpenID login failed.');
$this->assertFieldByName('name', '', 'No username was supplied by provider.'); $this->assertFieldByName('name', '', 'No username was supplied by provider.');
...@@ -397,7 +397,7 @@ function testSignatureValidation() { ...@@ -397,7 +397,7 @@ function testSignatureValidation() {
'openid.sreg.nickname' => 'john', 'openid.sreg.nickname' => 'john',
'openid.sreg.email' => 'john@example.com', 'openid.sreg.email' => 'john@example.com',
); );
variable_set('openid_test_response', $response); state()->set('openid_test.response', $response);
$this->submitLoginForm($identity); $this->submitLoginForm($identity);
$this->assertNoRaw('OpenID login failed.'); $this->assertNoRaw('OpenID login failed.');
$this->assertFieldByName('name', 'john', 'Username was supplied by provider.'); $this->assertFieldByName('name', 'john', 'Username was supplied by provider.');
......
...@@ -48,7 +48,7 @@ function testRegisterUserWithEmailVerification() { ...@@ -48,7 +48,7 @@ function testRegisterUserWithEmailVerification() {
->save(); ->save();
// Tell openid_test.module to respond with these SREG fields. // Tell openid_test.module to respond with these SREG fields.
variable_set('openid_test_response', array( state()->set('openid_test.response', array(
'openid.sreg.nickname' => 'john', 'openid.sreg.nickname' => 'john',
'openid.sreg.email' => 'john@example.com', 'openid.sreg.email' => 'john@example.com',
'openid.sreg.language' => 'pt-BR', 'openid.sreg.language' => 'pt-BR',
...@@ -107,7 +107,7 @@ function testRegisterUserWithoutEmailVerification() { ...@@ -107,7 +107,7 @@ function testRegisterUserWithoutEmailVerification() {
->save(); ->save();
// Tell openid_test.module to respond with these SREG fields. // Tell openid_test.module to respond with these SREG fields.
variable_set('openid_test_response', array( state()->set('openid_test.response', array(
'openid.sreg.nickname' => 'john', 'openid.sreg.nickname' => 'john',
'openid.sreg.email' => 'john@example.com', 'openid.sreg.email' => 'john@example.com',
'openid.sreg.language' => 'pt-BR', 'openid.sreg.language' => 'pt-BR',
...@@ -150,7 +150,7 @@ function testRegisterUserWithInvalidSreg() { ...@@ -150,7 +150,7 @@ function testRegisterUserWithInvalidSreg() {
// Tell openid_test.module to respond with these SREG fields. // Tell openid_test.module to respond with these SREG fields.
$web_user = $this->drupalCreateUser(array()); $web_user = $this->drupalCreateUser(array());
variable_set('openid_test_response', array( state()->set('openid_test.response', array(
'openid.sreg.nickname' => $web_user->name, 'openid.sreg.nickname' => $web_user->name,
'openid.sreg.email' => 'mail@invalid#', 'openid.sreg.email' => 'mail@invalid#',
'openid.sreg.timezone' => 'Foo/Bar', 'openid.sreg.timezone' => 'Foo/Bar',
...@@ -164,11 +164,11 @@ function testRegisterUserWithInvalidSreg() { ...@@ -164,11 +164,11 @@ function testRegisterUserWithInvalidSreg() {
$this->assertRaw(t('Account registration using the information provided by your OpenID provider failed due to the reasons listed below. Complete the registration by filling out the form below. If you already have an account, you can <a href="@login">log in</a> now and add your OpenID under "My account".', array('@login' => url('user/login'))), 'User was asked to complete the registration process manually.'); $this->assertRaw(t('Account registration using the information provided by your OpenID provider failed due to the reasons listed below. Complete the registration by filling out the form below. If you already have an account, you can <a href="@login">log in</a> now and add your OpenID under "My account".', array('@login' => url('user/login'))), 'User was asked to complete the registration process manually.');
$this->assertRaw(t('The name %name is already taken.', array('%name' => $web_user->name)), 'Form validation error for username was displayed.'); $this->assertRaw(t('The name %name is already taken.', array('%name' => $web_user->name)), 'Form validation error for username was displayed.');
$this->assertRaw(t('The e-mail address %mail is not valid.', array('%mail' => 'mail@invalid#')), 'Form validation error for e-mail address was displayed.'); $this->assertRaw(t('The e-mail address %mail is not valid.', array('%mail' => 'mail@invalid#')), 'Form validation error for e-mail address was displayed.');
$this->assertTrue(variable_get('openid_test_hook_openid_response_response'), 'hook_openid_response() was invoked.'); $this->assertTrue(state()->get('openid_test.hook_openid_response_response'), 'hook_openid_response() was invoked.');
$this->assertFalse(variable_get('openid_test_hook_openid_response_account', TRUE), 'No user object passed to hook_openid_response().'); $this->assertFalse(state()->get('openid_test.hook_openid_response_account'), 'No user object passed to hook_openid_response().');
// Enter username and e-mail address manually. // Enter username and e-mail address manually.
variable_del('openid_test_hook_openid_response_response'); state()->delete('openid_test.hook_openid_response_response');
$edit = array('name' => 'john', 'mail' => 'john@example.com'); $edit = array('name' => 'john', 'mail' => 'john@example.com');
$this->drupalPost(NULL, $edit, t('Create new account')); $this->drupalPost(NULL, $edit, t('Create new account'));
$this->assertRaw(t('Once you have verified your e-mail address, you may log in via OpenID.'), 'User was asked to verify e-mail address.'); $this->assertRaw(t('Once you have verified your e-mail address, you may log in via OpenID.'), 'User was asked to verify e-mail address.');
...@@ -181,7 +181,7 @@ function testRegisterUserWithInvalidSreg() { ...@@ -181,7 +181,7 @@ function testRegisterUserWithInvalidSreg() {
// Follow the one-time login that was sent in the welcome e-mail. // Follow the one-time login that was sent in the welcome e-mail.
$this->drupalGet($reset_url); $this->drupalGet($reset_url);
$this->drupalPost(NULL, array(), t('Log in')); $this->drupalPost(NULL, array(), t('Log in'));
$this->assertFalse(variable_get('openid_test_hook_openid_response_response'), 'hook_openid_response() was not invoked.'); $this->assertFalse(state()->get('openid_test.hook_openid_response_response'), 'hook_openid_response() was not invoked.');
// The user is taken to user/%uid/edit. // The user is taken to user/%uid/edit.
$this->assertFieldByName('mail', 'john@example.com', 'User was registered with right e-mail address.'); $this->assertFieldByName('mail', 'john@example.com', 'User was registered with right e-mail address.');
...@@ -238,7 +238,7 @@ function testRegisterUserWithAXButNoSREG() { ...@@ -238,7 +238,7 @@ function testRegisterUserWithAXButNoSREG() {
->save(); ->save();
// Tell openid_test.module to respond with these AX fields. // Tell openid_test.module to respond with these AX fields.
variable_set('openid_test_response', array( state()->set('openid_test.response', array(
'openid.ns.ext123' => 'http://openid.net/srv/ax/1.0', 'openid.ns.ext123' => 'http://openid.net/srv/ax/1.0',
'openid.ext123.type.mail456' => 'http://axschema.org/contact/email', 'openid.ext123.type.mail456' => 'http://axschema.org/contact/email',
'openid.ext123.value.mail456' => 'john@example.com', 'openid.ext123.value.mail456' => 'john@example.com',
......
...@@ -108,7 +108,7 @@ function openid_test_yadis_xrds() { ...@@ -108,7 +108,7 @@ function openid_test_yadis_xrds() {
$output .= ' $output .= '
<xrds:XRDS xmlns:xrds="xri://$xrds" xmlns="xri://$xrd*($v*2.0)" xmlns:openid="http://openid.net/xmlns/1.0"> <xrds:XRDS xmlns:xrds="xri://$xrds" xmlns="xri://$xrd*($v*2.0)" xmlns:openid="http://openid.net/xmlns/1.0">
<XRD> <XRD>
<Status cid="' . check_plain(variable_get('openid_test_canonical_id_status', 'verified')) . '"/> <Status cid="' . check_plain(state()->get('openid_test.canonical_id_status') ?: 'verified') . '"/>
<ProviderID>xri://@</ProviderID> <ProviderID>xri://@</ProviderID>
<CanonicalID>http://example.com/user</CanonicalID> <CanonicalID>http://example.com/user</CanonicalID>
<Service> <Service>
...@@ -226,12 +226,12 @@ function openid_test_endpoint() { ...@@ -226,12 +226,12 @@ function openid_test_endpoint() {
*/ */
function openid_test_redirect($count = 0) { function openid_test_redirect($count = 0) {
if ($count == 0) { if ($count == 0) {
$url = variable_get('openid_test_redirect_url', ''); $url = state()->get('openid_test.redirect_url');
} }
else { else {
$url = url('openid-test/redirect/' . --$count, array('absolute' => TRUE)); $url = url('openid-test/redirect/' . --$count, array('absolute' => TRUE));
} }
$http_response_code = variable_get('openid_test_redirect_http_reponse_code', 301); $http_response_code = state()->get('openid_test.redirect_http_response_code') ?: 301;
return new RedirectResponse($url, $http_response_code); return new RedirectResponse($url, $http_response_code);
} }
...@@ -303,9 +303,10 @@ function _openid_test_endpoint_associate() { ...@@ -303,9 +303,10 @@ function _openid_test_endpoint_associate() {
function _openid_test_endpoint_authenticate() { function _openid_test_endpoint_authenticate() {
module_load_include('inc', 'openid'); module_load_include('inc', 'openid');
$expected_identity = variable_get('openid_test_identity'); $expected_identity = state()->get('openid_test.identity');
if ($expected_identity && $_REQUEST['openid_identity'] != $expected_identity) { if ($expected_identity && $_REQUEST['openid_identity'] != $expected_identity) {
$response = variable_get('openid_test_response', array()) + array( $response = state()->get('openid_test.response') ?: array();
$response += array(
'openid.ns' => OPENID_NS_2_0, 'openid.ns' => OPENID_NS_2_0,
'openid.mode' => 'error', 'openid.mode' => 'error',
'openid.error' => 'Unexpted identity', 'openid.error' => 'Unexpted identity',
...@@ -317,7 +318,8 @@ function _openid_test_endpoint_authenticate() { ...@@ -317,7 +318,8 @@ function _openid_test_endpoint_authenticate() {
$nonce = _openid_nonce(); $nonce = _openid_nonce();
// Generate response containing the user's identity. // Generate response containing the user's identity.
$response = variable_get('openid_test_response', array()) + array( $response = state()->get('openid_test.response') ?: array();
$response += array(
'openid.ns' => OPENID_NS_2_0, 'openid.ns' => OPENID_NS_2_0,
'openid.mode' => 'id_res', 'openid.mode' => 'id_res',
'openid.op_endpoint' => url('openid-test/endpoint', array('absolute' => TRUE)), 'openid.op_endpoint' => url('openid-test/endpoint', array('absolute' => TRUE)),
...@@ -357,7 +359,7 @@ function _openid_test_endpoint_authenticate() { ...@@ -357,7 +359,7 @@ function _openid_test_endpoint_authenticate() {
* Implements hook_openid_request_alter(). * Implements hook_openid_request_alter().
*/ */
function openid_test_openid_request_alter(&$request, $service) { function openid_test_openid_request_alter(&$request, $service) {
$parameters = variable_get('openid_test_request_alter', array()); $parameters = state()->get('openid_test.request_alter');
if (isset($parameters[$request['openid.mode']])) { if (isset($parameters[$request['openid.mode']])) {
$request = $parameters[$request['openid.mode']] + $request; $request = $parameters[$request['openid.mode']] + $request;
} }
...@@ -367,6 +369,6 @@ function openid_test_openid_request_alter(&$request, $service) { ...@@ -367,6 +369,6 @@ function openid_test_openid_request_alter(&$request, $service) {
* Implements hook_openid_response(). * Implements hook_openid_response().
*/ */
function openid_test_openid_response($response, $account) { function openid_test_openid_response($response, $account) {
variable_set('openid_test_hook_openid_response_response', $response); state()->set('openid_test.hook_openid_response_response', $response);
variable_set('openid_test_hook_openid_response_account', $account ? $account : FALSE); state()->set('openid_test.hook_openid_response_account', $account ? $account : FALSE);
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment