|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of the simplesamlphp-module-authchain. |
| 5 | + * |
| 6 | + * Copyright (C) 2018 by Sergio Gómez <sergio@uco.es> |
| 7 | + * |
| 8 | + * This code was developed by Universidad de Córdoba (UCO https://www.uco.es) |
| 9 | + * |
| 10 | + * For the full copyright and license information, please view the LICENSE |
| 11 | + * file that was distributed with this source code. |
| 12 | + */ |
| 13 | + |
| 14 | +namespace Tests\SimpleSAML\Modules\AuthChain\Auth\Source; |
| 15 | + |
| 16 | +use PHPUnit\Framework\TestCase; |
| 17 | +use SimpleSAML\Modules\AuthChain\Auth\Source\AuthChain; |
| 18 | + |
| 19 | +class AuthChainTest extends TestCase |
| 20 | +{ |
| 21 | + /** |
| 22 | + * @test |
| 23 | + */ |
| 24 | + public function it_does_chained_login() |
| 25 | + { |
| 26 | + \SimpleSAML_Configuration::setConfigDir(__DIR__.'/../../fixtures/config'); |
| 27 | + |
| 28 | + $authChain = new AuthChain([ |
| 29 | + 'AuthId' => 'chained', |
| 30 | + ], [ |
| 31 | + 'sources' => ['dummy-as', 'success-as'], |
| 32 | + ]); |
| 33 | + |
| 34 | + $login = function ($username, $password) { |
| 35 | + return $this->login($username, $password); |
| 36 | + }; |
| 37 | + $bindedAuthChain = $login->bindTo($authChain, $authChain); |
| 38 | + |
| 39 | + $this->assertArraySubset(['uid' => ['username']], $bindedAuthChain('username', 'password')); |
| 40 | + } |
| 41 | + |
| 42 | + /** |
| 43 | + * @test |
| 44 | + */ |
| 45 | + public function it_tries_all_auth_sources() |
| 46 | + { |
| 47 | + \SimpleSAML_Configuration::setConfigDir(__DIR__.'/../../fixtures/config'); |
| 48 | + |
| 49 | + $authChain = new AuthChain([ |
| 50 | + 'AuthId' => 'chained', |
| 51 | + ], [ |
| 52 | + 'sources' => ['failure-as', 'success-as'], |
| 53 | + ]); |
| 54 | + |
| 55 | + $login = function ($username, $password) { |
| 56 | + return $this->login($username, $password); |
| 57 | + }; |
| 58 | + $bindedAuthChain = $login->bindTo($authChain, $authChain); |
| 59 | + |
| 60 | + $this->assertArraySubset(['uid' => ['username']], $bindedAuthChain('username', 'password')); |
| 61 | + } |
| 62 | + |
| 63 | + /** |
| 64 | + * @test |
| 65 | + * @expectedException \SimpleSAML_Error_Error |
| 66 | + * @expectedExceptionMessage WRONGUSERPASS |
| 67 | + */ |
| 68 | + public function it_launch_exception_if_all_auth_sources_fail() |
| 69 | + { |
| 70 | + \SimpleSAML_Configuration::setConfigDir(__DIR__.'/../../fixtures/config'); |
| 71 | + |
| 72 | + $authChain = new AuthChain([ |
| 73 | + 'AuthId' => 'chained', |
| 74 | + ], [ |
| 75 | + 'sources' => ['failure-as', 'failure-as'], |
| 76 | + ]); |
| 77 | + |
| 78 | + $login = function ($username, $password) { |
| 79 | + return $this->login($username, $password); |
| 80 | + }; |
| 81 | + $bindedAuthChain = $login->bindTo($authChain, $authChain); |
| 82 | + $bindedAuthChain('username', 'password'); |
| 83 | + } |
| 84 | +} |
0 commit comments