123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800 |
- <?php
- abstract class OpenIDWebTestCase extends DrupalWebTestCase {
-
- function submitLoginForm($identity) {
-
- $edit = array('openid_identifier' => $identity);
- $this->drupalPost('', $edit, t('Log in'));
-
- $this->assertTitle(t('OpenID redirect'), t('OpenID redirect page was displayed.'));
-
- $this->drupalPost(NULL, array(), t('Send'));
- }
-
- function getPasswordResetURLFromMail() {
- $mails = $this->drupalGetMails();
- $mail = end($mails);
- preg_match('@.+user/reset/.+@', $mail['body'], $matches);
- return $matches[0];
- }
- }
- class OpenIDFunctionalTestCase extends OpenIDWebTestCase {
- protected $web_user;
- public static function getInfo() {
- return array(
- 'name' => 'OpenID discovery and login',
- 'description' => "Adds an identity to a user's profile and uses it to log in.",
- 'group' => 'OpenID'
- );
- }
- function setUp() {
- parent::setUp('openid', 'openid_test');
-
- $this->web_user = $this->drupalCreateUser(array());
- }
-
- function testDiscovery() {
- $this->drupalLogin($this->web_user);
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- $identity = url('openid-test/yadis/xrds', array('absolute' => TRUE));
- $this->addIdentity(preg_replace('@^https?://@', '', $identity), 2, 'http://example.com/xrds', $identity);
- $identity = url('openid-test/yadis/xrds/delegate', array('absolute' => TRUE));
- $this->addIdentity(preg_replace('@^https?://@', '', $identity), 2, 'http://example.com/xrds-delegate', $identity);
-
-
-
-
-
- $identity = url('openid-test/yadis/xrds/dummy-user', array('absolute' => TRUE, 'fragment' => $this->randomName()));
-
-
- variable_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);
- variable_set('openid_test_response', array());
-
-
- $this->addIdentity(url('openid-test/yadis/x-xrds-location', array('absolute' => TRUE)), 2);
-
-
- $this->addIdentity(url('openid-test/yadis/http-equiv', array('absolute' => TRUE)), 2);
-
- variable_set('xri_proxy_resolver', url('openid-test/yadis/xrds/xri', array('absolute' => TRUE)) . '/');
- $this->addIdentity('@example*résumé;%25', 2, 'http://example.com/xrds', 'http://example.com/user');
-
- variable_set('openid_test_canonical_id_status', 'bad value');
- $this->addIdentity('@example*résumé;%25', 2, FALSE, FALSE);
-
-
-
-
-
- $this->addIdentity(url('openid-test/html/openid1', array('absolute' => TRUE)), 1, 'http://example.com/html-openid1');
-
- $this->addIdentity(url('openid-test/html/openid2', array('absolute' => TRUE)), 2, 'http://example.com/html-openid2');
-
-
-
-
-
-
-
- $identity = $expected_claimed_id = url('openid-test/redirected/yadis/xrds/1', array('absolute' => TRUE));
- $this->addRedirectedIdentity($identity, 2, 'http://example.com/xrds', $expected_claimed_id, 0);
-
-
- $identity = $expected_claimed_id = url('openid-test/redirected/yadis/xrds/2', array('absolute' => TRUE));
- $this->addRedirectedIdentity($identity, 2, 'http://example.com/xrds', $expected_claimed_id, 2);
-
-
- $identity = url('openid-test/redirected/yadis/xrds/3', array('absolute' => TRUE));
- $expected_claimed_id = FALSE;
- $this->addRedirectedIdentity($identity, 2, 'http://example.com/xrds', $expected_claimed_id, 3);
- }
-
- function testLogin() {
- $this->drupalLogin($this->web_user);
-
- $identity = url('openid-test/yadis/xrds', array('absolute' => TRUE));
- $this->addIdentity($identity);
- $this->drupalLogout();
-
- $this->submitLoginForm($identity);
- $this->assertLink(t('Log out'), 0, t('User was logged in.'));
- $this->drupalLogout();
-
- $edit = array('openid_identifier' => $identity);
- $this->drupalPost('user/login', $edit, t('Log in'));
-
- $this->assertTitle(t('OpenID redirect'), t('OpenID redirect page was displayed.'));
-
- $this->drupalPost(NULL, array(), t('Send'));
- $this->assertLink(t('Log out'), 0, t('User was logged in.'));
-
- $this->assertResponse(200);
- }
-
- function testLoginMaintenanceMode() {
- $this->web_user = $this->drupalCreateUser(array('access site in maintenance mode'));
- $this->drupalLogin($this->web_user);
-
- $identity = url('openid-test/yadis/xrds', array('absolute' => TRUE));
- $this->addIdentity($identity);
- $this->drupalLogout();
-
- variable_set('maintenance_mode', 1);
-
- $edit = array('openid_identifier' => $identity);
- $this->drupalPost('user/login', $edit, t('Log in'));
-
- $this->assertTitle(t('OpenID redirect'), t('OpenID redirect page was displayed.'));
-
- $this->drupalPost(NULL, array(), t('Send'));
- $this->assertLink(t('Log out'), 0, t('User was logged in.'));
-
- $this->assertText(t('Operating in maintenance mode.'));
- $this->assertResponse(200);
- }
-
- function testDelete() {
- $this->drupalLogin($this->web_user);
-
- $identity = url('openid-test/yadis/xrds', array('absolute' => TRUE));
- $this->addIdentity($identity);
- $this->assertText($identity, t('Identity appears in list.'));
-
- $this->clickLink(t('Delete'));
- $this->drupalPost(NULL, array(), t('Confirm'));
- $this->assertText(t('OpenID deleted.'), t('Identity deleted'));
- $this->assertNoText($identity, t('Identity no longer appears in list.'));
- }
-
- function testBlockedUserLogin() {
-
- $identity = url('openid-test/yadis/xrds', array('absolute' => TRUE));
-
- $this->drupalLogin($this->web_user);
- $this->addIdentity($identity);
- $this->drupalLogout();
-
- $admin_user = $this->drupalCreateUser(array('administer users'));
- $this->drupalLogin($admin_user);
- $this->drupalGet('admin/people');
- $edit = array(
- 'operation' => 'block',
- 'accounts[' . $this->web_user->uid . ']' => TRUE,
- );
- $this->drupalPost('admin/people', $edit, t('Update'));
- $this->assertRaw('The update has been performed.', t('Account was blocked.'));
- $this->drupalLogout();
- $this->submitLoginForm($identity);
- $this->assertRaw(t('The username %name has not been activated or is blocked.', array('%name' => $this->web_user->name)), t('User login was blocked.'));
- }
-
- function addIdentity($identity, $version = 2, $local_id = 'http://example.com/xrds', $claimed_id = NULL) {
-
- variable_set('openid_test_identity', $local_id);
- $edit = array('openid_identifier' => $identity);
- $this->drupalPost('user/' . $this->web_user->uid . '/openid', $edit, t('Add an OpenID'));
- if ($claimed_id === FALSE) {
- $this->assertRaw(t('Sorry, that is not a valid OpenID. Ensure you have spelled your ID correctly.'), t('Invalid identity was rejected.'));
- return;
- }
-
- if ($version == 2) {
-
- $this->assertTitle(t('OpenID redirect'), t('OpenID redirect page was displayed.'));
-
- $this->drupalPost(NULL, array(), t('Send'));
- }
- if (!isset($claimed_id)) {
- $claimed_id = $identity;
- }
- $this->assertRaw(t('Successfully added %identity', array('%identity' => $claimed_id)), t('Identity %identity was added.', array('%identity' => $identity)));
- }
-
- function addRedirectedIdentity($identity, $version = 2, $local_id = 'http://example.com/xrds', $claimed_id = NULL, $redirects = 0) {
-
-
-
-
- variable_set('openid_test_redirect_url', $identity);
- variable_set('openid_test_response', array('openid.claimed_id' => $identity));
- $this->addIdentity(url('openid-test/redirect/' . $redirects, array('absolute' => TRUE)), $version, $local_id, $claimed_id);
-
- variable_del('openid_test_redirect_url');
- variable_del('openid_test_response');
- }
-
- function testSignatureValidation() {
-
- $identity = url('openid-test/yadis/xrds', array('absolute' => TRUE));
-
- variable_set('openid_test_response', array('openid.sig' => 'this-is-an-invalid-signature'));
- $this->submitLoginForm($identity);
- $this->assertRaw('OpenID login failed.');
-
- variable_set('openid_test_response', array('openid.signed' => 'op_endpoint,claimed_id,identity,return_to,response_nonce'));
- $this->submitLoginForm($identity);
- $this->assertRaw('OpenID login failed.');
-
- $keys_to_sign = array('op_endpoint', 'claimed_id', 'identity', 'return_to', 'response_nonce', 'assoc_handle', 'foo');
- $association = new stdClass();
- $association->mac_key = variable_get('mac_key');
- $response = array(
- 'openid.op_endpoint' => url('openid-test/endpoint', array('absolute' => TRUE)),
- 'openid.claimed_id' => $identity,
- 'openid.identity' => $identity,
- 'openid.return_to' => url('openid/authenticate', array('absolute' => TRUE)),
- 'openid.response_nonce' => _openid_nonce(),
- 'openid.assoc_handle' => 'openid-test',
- 'openid.foo' => 123,
- 'openid.signed' => implode(',', $keys_to_sign),
- );
- $response['openid.sig'] = _openid_signature($association, $response, $keys_to_sign);
- variable_set('openid_test_response', $response);
- $this->submitLoginForm($identity);
- $this->assertNoRaw('OpenID login failed.');
- $this->assertFieldByName('name', '', t('No username was supplied by provider.'));
- $this->assertFieldByName('mail', '', t('No e-mail address was supplied by provider.'));
-
- $response = array(
- 'openid.signed' => 'op_endpoint,claimed_id,identity,return_to,response_nonce,assoc_handle,sreg.nickname',
- 'openid.sreg.nickname' => 'john',
- 'openid.sreg.email' => 'john@example.com',
- );
- variable_set('openid_test_response', $response);
- $this->submitLoginForm($identity);
- $this->assertNoRaw('OpenID login failed.');
- $this->assertFieldByName('name', 'john', t('Username was supplied by provider.'));
- $this->assertFieldByName('mail', '', t('E-mail address supplied by provider was ignored.'));
- }
- }
- class OpenIDRegistrationTestCase extends OpenIDWebTestCase {
- public static function getInfo() {
- return array(
- 'name' => 'OpenID account registration',
- 'description' => 'Creates a user account using auto-registration.',
- 'group' => 'OpenID'
- );
- }
- function setUp() {
- parent::setUp('openid', 'openid_test');
- variable_set('user_register', USER_REGISTER_VISITORS);
- }
-
- function testRegisterUserWithEmailVerification() {
- variable_set('user_email_verification', TRUE);
-
- variable_set('openid_test_response', array('openid.sreg.nickname' => 'john', 'openid.sreg.email' => 'john@example.com'));
-
- $identity = url('openid-test/yadis/xrds', array('absolute' => TRUE));
- $this->submitLoginForm($identity);
- $this->assertRaw(t('Once you have verified your e-mail address, you may log in via OpenID.'), t('User was asked to verify e-mail address.'));
- $this->assertRaw(t('A welcome message with further instructions has been sent to your e-mail address.'), t('A welcome message was sent to the user.'));
- $reset_url = $this->getPasswordResetURLFromMail();
- $user = user_load_by_name('john');
- $this->assertTrue($user, t('User was registered with right username.'));
- $this->assertEqual($user->mail, 'john@example.com', t('User was registered with right email address.'));
- $this->assertFalse($user->data, t('No additional user info was saved.'));
- $this->submitLoginForm($identity);
- $this->assertRaw(t('You must validate your email address for this account before logging in via OpenID.'));
-
- $this->drupalGet($reset_url);
- $this->drupalPost(NULL, array(), t('Log in'));
- $this->drupalLogout();
-
- $this->submitLoginForm($identity);
- $this->assertLink(t('Log out'), 0, t('User was logged in.'));
- }
-
- function testRegisterUserWithoutEmailVerification() {
- variable_set('user_email_verification', FALSE);
-
- variable_set('openid_test_response', array('openid.sreg.nickname' => 'john', 'openid.sreg.email' => 'john@example.com'));
-
- $identity = url('openid-test/yadis/xrds', array('absolute' => TRUE));
- $this->submitLoginForm($identity);
- $this->assertLink(t('Log out'), 0, t('User was logged in.'));
- $user = user_load_by_name('john');
- $this->assertTrue($user, t('User was registered with right username.'));
- $this->assertEqual($user->mail, 'john@example.com', t('User was registered with right email address.'));
- $this->assertFalse($user->data, t('No additional user info was saved.'));
- $this->drupalLogout();
- $this->submitLoginForm($identity);
- $this->assertLink(t('Log out'), 0, t('User was logged in.'));
- }
-
- function testRegisterUserWithInvalidSreg() {
-
- $web_user = $this->drupalCreateUser(array());
- variable_set('openid_test_response', array('openid.sreg.nickname' => $web_user->name, 'openid.sreg.email' => 'mail@invalid#'));
-
- $identity = url('openid-test/yadis/xrds', array('absolute' => TRUE));
- $this->submitLoginForm($identity);
- $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'))), t('User was asked to complete the registration process manually.'));
- $this->assertRaw(t('The name %name is already taken.', array('%name' => $web_user->name)), t('Form validation error for username was displayed.'));
- $this->assertRaw(t('The e-mail address %mail is not valid.', array('%mail' => 'mail@invalid#')), t('Form validation error for e-mail address was displayed.'));
-
- $edit = array('name' => 'john', 'mail' => 'john@example.com');
- $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.'), t('User was asked to verify e-mail address.'));
- $reset_url = $this->getPasswordResetURLFromMail();
- $user = user_load_by_name('john');
- $this->assertTrue($user, t('User was registered with right username.'));
- $this->assertFalse($user->data, t('No additional user info was saved.'));
-
- $this->drupalGet($reset_url);
- $this->drupalPost(NULL, array(), t('Log in'));
-
- $this->assertFieldByName('mail', 'john@example.com', t('User was registered with right e-mail address.'));
- $this->clickLink(t('OpenID identities'));
- $this->assertRaw($identity, t('OpenID identity was registered.'));
- }
-
- function testRegisterUserWithoutSreg() {
-
- $this->drupalGet('');
-
- $identity = url('openid-test/yadis/xrds', array('absolute' => TRUE));
- $this->submitLoginForm($identity);
- $this->assertRaw(t('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'))), t('User was asked to complete the registration process manually.'));
- $this->assertNoRaw(t('You must enter a username.'), t('Form validation error for username was not displayed.'));
- $this->assertNoRaw(t('You must enter an e-mail address.'), t('Form validation error for e-mail address was not displayed.'));
-
- $edit = array('name' => 'john', 'mail' => 'john@example.com');
- $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.'), t('User was asked to verify e-mail address.'));
- $reset_url = $this->getPasswordResetURLFromMail();
- $user = user_load_by_name('john');
- $this->assertTrue($user, t('User was registered with right username.'));
- $this->assertFalse($user->data, t('No additional user info was saved.'));
-
- $this->drupalGet($reset_url);
- $this->drupalPost(NULL, array(), t('Log in'));
-
- $this->assertFieldByName('mail', 'john@example.com', t('User was registered with right e-mail address.'));
- $this->clickLink(t('OpenID identities'));
- $this->assertRaw($identity, t('OpenID identity was registered.'));
- }
-
- function testRegisterUserWithAXButNoSREG() {
- variable_set('user_email_verification', FALSE);
-
- variable_set('openid_test_response', array(
- 'openid.ns.ext123' => 'http://openid.net/srv/ax/1.0',
- 'openid.ext123.type.mail456' => 'http://axschema.org/contact/email',
- 'openid.ext123.value.mail456' => 'john@example.com',
- 'openid.ext123.type.name789' => 'http://schema.openid.net/namePerson/friendly',
- 'openid.ext123.count.name789' => '1',
- 'openid.ext123.value.name789.1' => 'john',
- ));
-
- $identity = url('openid-test/yadis/xrds', array('absolute' => TRUE));
- $this->submitLoginForm($identity);
- $this->assertLink(t('Log out'), 0, t('User was logged in.'));
- $user = user_load_by_name('john');
- $this->assertTrue($user, t('User was registered with right username.'));
- $this->assertEqual($user->mail, 'john@example.com', t('User was registered with right email address.'));
- }
- }
- class OpenIDInvalidIdentifierTransitionTestCase extends OpenIDFunctionalTestCase {
- public static function getInfo() {
- return array(
- 'name' => 'OpenID account update',
- 'description' => 'Tries to correct OpenID identifiers attached to accounts if their identifiers were stripped.',
- 'group' => 'OpenID',
- );
- }
- function setUp() {
- parent::setUp('openid', 'openid_test');
- variable_set('user_register', USER_REGISTER_VISITORS);
- variable_set('openid_less_obtrusive_transition', TRUE);
- }
-
- function testStrippedFragmentAccountEmailMismatch() {
- $this->drupalLogin($this->web_user);
-
- $identity = url('openid-test/yadis/xrds', array('absolute' => TRUE, 'fragment' => $this->randomName()));
- $identity_stripped = preg_replace('/#.*/', '', $identity);
-
- $this->addIdentity($identity_stripped);
- $this->drupalLogout();
-
-
-
- variable_set('openid_test_response', array(
- 'openid.claimed_id' => $identity,
- 'openid.sreg.nickname' => $this->web_user->name,
- 'openid.sreg.email' => 'invalid-' . $this->web_user->mail));
- $edit = array('openid_identifier' => $identity_stripped);
- $this->submitLoginForm($identity_stripped);
-
- $this->assertResponse(200);
-
- $this->assertRaw(t('There is already an existing account associated with the OpenID identifier that you have provided.'), t('Message that OpenID identifier must be updated manually was displayed.'));
- }
-
- function testStrippedFragmentAccountAutoUpdateSreg() {
- $this->drupalLogin($this->web_user);
-
- $identity = url('openid-test/yadis/xrds', array('absolute' => TRUE, 'fragment' => $this->randomName()));
- $identity_stripped = preg_replace('/#.*/', '', $identity);
-
- $this->addIdentity($identity_stripped);
- $this->drupalLogout();
-
-
-
- variable_set('openid_test_response', array(
- 'openid.claimed_id' => $identity,
- 'openid.sreg.nickname' => $this->web_user->name,
- 'openid.sreg.email' => $this->web_user->mail));
- $this->submitLoginForm($identity_stripped);
-
- $this->assertResponse(200);
-
- $this->assertRaw(t('New OpenID identifier %identity was added as a replacement for invalid identifier %invalid_identity.', array('%invalid_identity' => $identity_stripped, '%identity' => $identity)), t('Message that OpenID identifier was added automatically was displayed.'));
- }
- }
- class OpenIDTestCase extends DrupalWebTestCase {
- public static function getInfo() {
- return array(
- 'name' => 'OpenID helper functions',
- 'description' => 'Test OpenID helper functions.',
- 'group' => 'OpenID'
- );
- }
- function setUp() {
- parent::setUp('openid');
- module_load_include('inc', 'openid');
- }
-
- function testConversion() {
- $this->assertEqual(_openid_dh_long_to_base64('12345678901234567890123456789012345678901234567890'), 'CHJ/Y2mq+DyhUCZ0evjH8ZbOPwrS', t('_openid_dh_long_to_base64() returned expected result.'));
- $this->assertEqual(_openid_dh_base64_to_long('BsH/g8Nrpn2dtBSdu/sr1y8hxwyx'), '09876543210987654321098765432109876543210987654321', t('_openid_dh_base64_to_long() returned expected result.'));
- $this->assertEqual(_openid_dh_long_to_binary('12345678901234567890123456789012345678901234567890'), "\x08r\x7fci\xaa\xf8<\xa1P&tz\xf8\xc7\xf1\x96\xce?\x0a\xd2", t('_openid_dh_long_to_binary() returned expected result.'));
- $this->assertEqual(_openid_dh_binary_to_long("\x06\xc1\xff\x83\xc3k\xa6}\x9d\xb4\x14\x9d\xbb\xfb+\xd7/!\xc7\x0c\xb1"), '09876543210987654321098765432109876543210987654321', t('_openid_dh_binary_to_long() returned expected result.'));
- }
-
- function testOpenidDhXorsecret() {
- $this->assertEqual(_openid_dh_xorsecret('123456790123456790123456790', "abc123ABC\x00\xFF"), "\xa4'\x06\xbe\xf1.\x00y\xff\xc2\xc1", t('_openid_dh_xorsecret() returned expected result.'));
- }
-
- function testOpenidGetBytes() {
- $this->assertEqual(strlen(_openid_get_bytes(20)), 20, t('_openid_get_bytes() returned expected result.'));
- }
-
- function testOpenidSignature() {
-
-
-
-
-
- $response = array(
- 'openid.foo' => 'abc1',
- 'openid.bar' => 'abc2',
- 'openid.baz' => 'abc3',
- 'foobar.foo' => 'abc4',
- );
- $association = new stdClass();
- $association->mac_key = "1234567890abcdefghij\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\xF0\xF1\xF2\xF3\xF4\xF5\xF6\xF7\xF8\xF9";
- $this->assertEqual(_openid_signature($association, $response, array('foo', 'bar')), 'QnKZQzSFstT+GNiJDFOptdcZjrc=', t('Expected signature calculated.'));
- }
-
- function testOpenidXRITest() {
-
-
-
-
- $this->assertTrue(_openid_is_xri('xri://=foo'), t('_openid_is_xri() returned expected result for an xri identifier with xri scheme.'));
- $this->assertTrue(_openid_is_xri('xri://@foo'), t('_openid_is_xri() returned expected result for an xri identifier with xri scheme.'));
- $this->assertTrue(_openid_is_xri('xri://+foo'), t('_openid_is_xri() returned expected result for an xri identifier with xri scheme.'));
- $this->assertTrue(_openid_is_xri('xri://$foo'), t('_openid_is_xri() returned expected result for an xri identifier with xri scheme.'));
- $this->assertTrue(_openid_is_xri('xri://!foo'), t('_openid_is_xri() returned expected result for an xri identifier with xri scheme..'));
- $this->assertTrue(_openid_is_xri('xri://(foo'), t('_openid_is_xri() returned expected result for an xri identifier with xri scheme..'));
- $this->assertTrue(_openid_is_xri('=foo'), t('_openid_is_xri() returned expected result for an xri identifier.'));
- $this->assertTrue(_openid_is_xri('@foo'), t('_openid_is_xri() returned expected result for an xri identifier.'));
- $this->assertTrue(_openid_is_xri('+foo'), t('_openid_is_xri() returned expected result for an xri identifier.'));
- $this->assertTrue(_openid_is_xri('$foo'), t('_openid_is_xri() returned expected result for an xri identifier.'));
- $this->assertTrue(_openid_is_xri('!foo'), t('_openid_is_xri() returned expected result for an xri identifier.'));
- $this->assertTrue(_openid_is_xri('(foo'), t('_openid_is_xri() returned expected result for an xri identifier.'));
- $this->assertFalse(_openid_is_xri('foo'), t('_openid_is_xri() returned expected result for an http URL.'));
- $this->assertFalse(_openid_is_xri('xri://foo'), t('_openid_is_xri() returned expected result for an http URL.'));
- $this->assertFalse(_openid_is_xri('http://foo/'), t('_openid_is_xri() returned expected result for an http URL.'));
- $this->assertFalse(_openid_is_xri('http://example.com/'), t('_openid_is_xri() returned expected result for an http URL.'));
- $this->assertFalse(_openid_is_xri('user@example.com/'), t('_openid_is_xri() returned expected result for an http URL.'));
- $this->assertFalse(_openid_is_xri('http://user@example.com/'), t('_openid_is_xri() returned expected result for an http URL.'));
- }
-
- function testOpenidNormalize() {
-
-
- $this->assertEqual(openid_normalize('$foo'), '$foo', t('openid_normalize() correctly normalized an XRI.'));
- $this->assertEqual(openid_normalize('xri://$foo'), '$foo', t('openid_normalize() correctly normalized an XRI with an xri:// scheme.'));
- $this->assertEqual(openid_normalize('example.com/'), 'http://example.com/', t('openid_normalize() correctly normalized a URL with a missing scheme.'));
- $this->assertEqual(openid_normalize('example.com'), 'http://example.com/', t('openid_normalize() correctly normalized a URL with a missing scheme and empty path.'));
- $this->assertEqual(openid_normalize('http://example.com'), 'http://example.com/', t('openid_normalize() correctly normalized a URL with an empty path.'));
- $this->assertEqual(openid_normalize('http://example.com/path'), 'http://example.com/path', t('openid_normalize() correctly normalized a URL with a path.'));
- $this->assertEqual(openid_normalize('http://example.com/path#fragment'), 'http://example.com/path', t('openid_normalize() correctly normalized a URL with a fragment.'));
- }
-
- function testOpenidExtractNamespace() {
- $response = array(
- 'openid.sreg.nickname' => 'john',
- 'openid.ns.ext1' => OPENID_NS_SREG,
- 'openid.ext1.nickname' => 'george',
- 'openid.ext1.email' => 'george@example.com',
- 'openid.ns.ext2' => 'http://example.com/ns/ext2',
- 'openid.ext2.foo' => '123',
- 'openid.ext2.bar' => '456',
- 'openid.signed' => 'sreg.nickname,ns.ext1,ext1.email,ext2.foo',
- );
- $values = openid_extract_namespace($response, 'http://example.com/ns/dummy', NULL, FALSE);
- $this->assertEqual($values, array(), t('Nothing found for unused namespace.'));
- $values = openid_extract_namespace($response, 'http://example.com/ns/dummy', 'sreg', FALSE);
- $this->assertEqual($values, array('nickname' => 'john'), t('Value found for fallback prefix.'));
- $values = openid_extract_namespace($response, OPENID_NS_SREG, 'sreg', FALSE);
- $this->assertEqual($values, array('nickname' => 'george', 'email' => 'george@example.com'), t('Namespace takes precedence over fallback prefix.'));
-
- $values = openid_extract_namespace($response, OPENID_NS_SREG, 'sreg', TRUE);
- $this->assertEqual($values, array('email' => 'george@example.com'), t('Unsigned namespaced fields ignored.'));
- $values = openid_extract_namespace($response, 'http://example.com/ns/ext2', 'sreg', FALSE);
- $this->assertEqual($values, array('foo' => '123', 'bar' => '456'), t('Unsigned fields found.'));
-
-
- $values = openid_extract_namespace($response, 'http://example.com/ns/ext2', 'sreg', TRUE);
- $this->assertEqual($values, array(), t('Unsigned fields ignored.'));
- }
- }
|