Révision a2baadd1
Ajouté par Assos Assos il y a environ 10 ans
drupal7/sites/all/modules/cas/cas.test | ||
---|---|---|
35 | 35 |
$this->admin_user = $this->drupalCreateUser(array('administer users', 'administer cas')); |
36 | 36 |
|
37 | 37 |
// Download and extract in PHPCAS. |
38 |
$this->downloadExtractPhpCas('1.2.2');
|
|
38 |
$this->downloadExtractPhpCas('1.3.1');
|
|
39 | 39 |
} |
40 | 40 |
|
41 | 41 |
/** |
... | ... | |
77 | 77 |
// Extract the files. |
78 | 78 |
$archiver = archiver_get_archiver($local_archive); |
79 | 79 |
$archiver->extract($simpletest_cache); |
80 |
// Work around issue https://issues.jasig.org/browse/PHPCAS-105. |
|
81 |
// @see http://drupal.org/node/1120034 |
|
82 |
switch ($version) { |
|
83 |
case '1.1.3': |
|
84 |
system_retrieve_file('http://drupal.org/files/issues/CAS-1.1.3-CAS-client.txt', $cas_library_dir . '/CAS/client.php', FALSE, FILE_EXISTS_REPLACE); |
|
85 |
break; |
|
86 |
case '1.2.1': |
|
87 |
system_retrieve_file('http://drupal.org/files/issues/CAS-1.2.1-CAS-client_0.txt', $cas_library_dir . '/CAS/client.php', FALSE, FILE_EXISTS_REPLACE); |
|
88 |
break; |
|
89 |
} |
|
90 | 80 |
} |
91 | 81 |
if (function_exists('sem_get')) { |
92 | 82 |
sem_release($semaphore); |
... | ... | |
145 | 135 |
} |
146 | 136 |
|
147 | 137 |
// Log in the user. |
148 |
$cas_name = is_object($account) ? $account->cas_name : $account; |
|
149 |
$cas_user = array('name' => $cas_name, 'attributes' => $attributes); |
|
150 |
variable_set('cas_test_cas_user', $cas_user); |
|
138 |
$cas_name = $this->setCasUser($account, $attributes); |
|
151 | 139 |
$this->drupalGet('cas'); |
152 | 140 |
|
153 | 141 |
$pass = $this->assertLink(t('Log out'), 0, t('CAS user %cas_name successfully logged in.', array('%cas_name' => $cas_name)), t('User login')); |
154 | 142 |
if ($pass) { |
155 |
$this->loggedInUser = cas_user_load_by_name($cas_name, TRUE); |
|
143 |
$this->loggedInUser = cas_user_load_by_name($cas_name, TRUE, TRUE);
|
|
156 | 144 |
} |
157 | 145 |
} |
158 | 146 |
|
147 |
/** |
|
148 |
* Set the CAS username and attributes for the next CAS login request. |
|
149 |
* |
|
150 |
* @param $account |
|
151 |
* A user object with a valid CAS username field, or the CAS username as a |
|
152 |
* string. |
|
153 |
* @param $attributes |
|
154 |
* Additional attributes for the CAS user. |
|
155 |
* |
|
156 |
* @return |
|
157 |
* The CAS username. |
|
158 |
*/ |
|
159 |
function setCasUser($account, $attributes = array()) { |
|
160 |
$cas_name = is_object($account) ? $account->cas_name : $account; |
|
161 |
$cas_user = array('name' => $cas_name, 'attributes' => $attributes); |
|
162 |
variable_set('cas_test_cas_user', $cas_user); |
|
163 |
return $cas_name; |
|
164 |
} |
|
165 |
|
|
166 |
/** |
|
167 |
* Clear the CAS username and attributes for the next CAS login request. |
|
168 |
*/ |
|
169 |
function clearCasUser() { |
|
170 |
variable_del('cas_test_cas_user'); |
|
171 |
} |
|
172 |
|
|
159 | 173 |
/** |
160 | 174 |
* Assert that the user has logged in. |
161 | 175 |
* |
... | ... | |
353 | 367 |
*/ |
354 | 368 |
function testCasAutoRegister() { |
355 | 369 |
$cas_name = $this->randomName(); |
356 |
variable_set('cas_test_cas_user', array('name' => $cas_name));
|
|
370 |
$this->setCasUser($cas_name);
|
|
357 | 371 |
|
358 | 372 |
// Test that the user is not automatically registered. |
359 | 373 |
variable_set('cas_user_register', FALSE); |
... | ... | |
370 | 384 |
// Create a new user. |
371 | 385 |
$user2 = $this->drupalCreateUser(); |
372 | 386 |
$cas_name = $user2->name; |
373 |
variable_set('cas_test_cas_user', array('name' => $cas_name));
|
|
387 |
$this->setCasUser($cas_name);
|
|
374 | 388 |
|
375 | 389 |
// Test that CAS does not hijack an existing username. |
376 | 390 |
$this->drupalGet('cas'); |
... | ... | |
423 | 437 |
|
424 | 438 |
$this->assertToken('[cas:name]', $account->cas_name); |
425 | 439 |
} |
440 |
|
|
441 |
function testCaseInsensitiveLogin() { |
|
442 |
$account = $this->casCreateUser(); |
|
443 |
$this->casLogin(strtoupper($account->cas_name)); |
|
444 |
$this->assertLoggedIn($account); |
|
445 |
} |
|
446 |
|
|
426 | 447 |
} |
427 | 448 |
|
428 | 449 |
/** |
... | ... | |
510 | 531 |
// Create a CAS user. |
511 | 532 |
$account = $this->casCreateUser(); |
512 | 533 |
$cas_name = $account->cas_name; |
513 |
variable_set('cas_test_cas_user', array('name' => $cas_name));
|
|
534 |
$this->setCasUser($cas_name);
|
|
514 | 535 |
|
515 | 536 |
// Test going to 'cas' |
516 | 537 |
$this->drupalGet('cas'); |
... | ... | |
572 | 593 |
variable_set('cas_first_login_destination', "node/$node->nid"); |
573 | 594 |
$cas_name = $this->randomName(); |
574 | 595 |
$account = $this->casLogin($cas_name); |
575 |
$this->assertUrl("node/$node->nid"); |
|
596 |
$this->assertUrl("node/$node->nid", array('query' => array('destination' => '')));
|
|
576 | 597 |
$this->drupalLogout(); |
577 | 598 |
|
578 | 599 |
// The second login should not be redirected. |
... | ... | |
584 | 605 |
// destination. |
585 | 606 |
$account = $this->casCreateUser(); |
586 | 607 |
$this->casLogin($account); |
587 |
$this->assertUrl("node/$node->nid"); |
|
608 |
$this->assertUrl("node/$node->nid", array('query' => array('destination' => '')));
|
|
588 | 609 |
$this->drupalLogout(); |
589 | 610 |
|
590 | 611 |
// The second login should not be redirected. |
... | ... | |
619 | 640 |
// @todo: Add additional tests for other methods of logging in (especially |
620 | 641 |
// methods coming from cas_pages). |
621 | 642 |
} |
643 |
|
|
644 |
function testSingleSignOutDoubleEncode() { |
|
645 |
// Create a user, and log in. |
|
646 |
$cas_name = $this->randomName(); |
|
647 |
$account = $this->casCreateUser($cas_name); |
|
648 |
$this->casLogin($account); |
|
649 |
|
|
650 |
cas_test_single_sign_out($cas_name, TRUE); |
|
651 |
$this->assertLoggedOut(); |
|
652 |
|
|
653 |
// @todo: Add additional tests for other methods of logging in (especially |
|
654 |
// methods coming from cas_pages). |
|
655 |
} |
|
622 | 656 |
} |
623 | 657 |
|
624 | 658 |
/** |
... | ... | |
658 | 692 |
// Create a user. |
659 | 693 |
$cas_name = $this->randomName(); |
660 | 694 |
$account = $this->casCreateUser($cas_name); |
661 |
variable_set('cas_test_cas_user', array('name' => $cas_name));
|
|
695 |
$this->setCasUser($cas_name);
|
|
662 | 696 |
|
663 | 697 |
$this->drupalGet('node'); |
664 | 698 |
$this->assertLoggedIn($account); |
... | ... | |
685 | 719 |
$node1 = $this->drupalCreateNode(); |
686 | 720 |
$node2 = $this->drupalCreateNode(); |
687 | 721 |
$account = $this->casCreateUser(); |
688 |
variable_set('cas_test_cas_user', array('name' => $account->cas_name));
|
|
722 |
$this->setCasUser($account);
|
|
689 | 723 |
|
690 | 724 |
$this->drupalGet("node/$node2->nid"); |
691 | 725 |
|
... | ... | |
707 | 741 |
$this->assertField('pass', t('Password field found.'), t('Logout')); |
708 | 742 |
|
709 | 743 |
// Verify that accessing any other page redirects to the login page. |
710 |
variable_del('cas_test_cas_user');
|
|
744 |
$this->clearCasUser();
|
|
711 | 745 |
$this->drupalGet('node'); |
712 | 746 |
$this->assertText('No CAS name provided.'); |
713 | 747 |
} |
... | ... | |
718 | 752 |
function testCasExclude() { |
719 | 753 |
$node = $this->drupalCreateNode(); |
720 | 754 |
$account = $this->casCreateUser(); |
721 |
variable_set('cas_test_cas_user', array('name' => $account->cas_name));
|
|
755 |
$this->setCasUser($account);
|
|
722 | 756 |
|
723 | 757 |
variable_set('cas_check_first', TRUE); |
724 | 758 |
variable_set('cas_exclude', "node/$node->nid"); |
... | ... | |
786 | 820 |
*/ |
787 | 821 |
function testCasLoginBlock() { |
788 | 822 |
$account = $this->casCreateUser(); |
789 |
variable_set('cas_test_cas_user', array('name' => $account->cas_name));
|
|
823 |
$this->setCasUser($account);
|
|
790 | 824 |
|
791 | 825 |
// Verify that the block is shown on some pages, but not on others. |
792 | 826 |
$this->drupalGet(''); |
Formats disponibles : Unified diff
Weekly update of contrib modules