MediaWiki  REL1_31
AbstractSecondaryAuthenticationProviderTest.php
Go to the documentation of this file.
1 <?php
2 
3 namespace MediaWiki\Auth;
4 
11  $user = \User::newFromName( 'UTSysop' );
12 
13  $provider = $this->getMockForAbstractClass( AbstractSecondaryAuthenticationProvider::class );
14 
15  try {
16  $provider->continueSecondaryAuthentication( $user, [] );
17  $this->fail( 'Expected exception not thrown' );
18  } catch ( \BadMethodCallException $ex ) {
19  }
20 
21  try {
22  $provider->continueSecondaryAccountCreation( $user, $user, [] );
23  $this->fail( 'Expected exception not thrown' );
24  } catch ( \BadMethodCallException $ex ) {
25  }
26 
27  $req = $this->getMockForAbstractClass( AuthenticationRequest::class );
28 
29  $this->assertTrue( $provider->providerAllowsPropertyChange( 'foo' ) );
30  $this->assertEquals(
31  \StatusValue::newGood( 'ignored' ),
32  $provider->providerAllowsAuthenticationDataChange( $req )
33  );
34  $this->assertEquals(
36  $provider->testForAccountCreation( $user, $user, [] )
37  );
38  $this->assertEquals(
40  $provider->testUserForCreation( $user, AuthManager::AUTOCREATE_SOURCE_SESSION )
41  );
42  $this->assertEquals(
44  $provider->testUserForCreation( $user, false )
45  );
46 
47  $provider->providerChangeAuthenticationData( $req );
48  $provider->autoCreatedAccount( $user, AuthManager::AUTOCREATE_SOURCE_SESSION );
49 
51  $provider->postAuthentication( $user, $res );
52  $provider->postAccountCreation( $user, $user, $res );
53  }
54 
55  public function testProviderRevokeAccessForUser() {
56  $reqs = [];
57  for ( $i = 0; $i < 3; $i++ ) {
58  $reqs[$i] = $this->createMock( AuthenticationRequest::class );
59  $reqs[$i]->done = false;
60  }
61 
62  $provider = $this->getMockBuilder( AbstractSecondaryAuthenticationProvider::class )
63  ->setMethods( [ 'providerChangeAuthenticationData' ] )
64  ->getMockForAbstractClass();
65  $provider->expects( $this->once() )->method( 'getAuthenticationRequests' )
66  ->with(
67  $this->identicalTo( AuthManager::ACTION_REMOVE ),
68  $this->identicalTo( [ 'username' => 'UTSysop' ] )
69  )
70  ->will( $this->returnValue( $reqs ) );
71  $provider->expects( $this->exactly( 3 ) )->method( 'providerChangeAuthenticationData' )
72  ->will( $this->returnCallback( function ( $req ) {
73  $this->assertSame( 'UTSysop', $req->username );
74  $this->assertFalse( $req->done );
75  $req->done = true;
76  } ) );
77 
78  $provider->providerRevokeAccessForUser( 'UTSysop' );
79 
80  foreach ( $reqs as $i => $req ) {
81  $this->assertTrue( $req->done, "#$i" );
82  }
83  }
84 }
$user
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a account $user
Definition: hooks.txt:247
MediaWiki\Auth\AuthManager\AUTOCREATE_SOURCE_SESSION
const AUTOCREATE_SOURCE_SESSION
Auto-creation is due to SessionManager.
Definition: AuthManager.php:114
User\newFromName
static newFromName( $name, $validate='valid')
Static factory method for creation from username.
Definition: User.php:591
$res
$res
Definition: database.txt:21
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:37
MediaWikiTestCase
Definition: MediaWikiTestCase.php:17
MediaWiki\Auth\AbstractSecondaryAuthenticationProviderTest\testProviderRevokeAccessForUser
testProviderRevokeAccessForUser()
Definition: AbstractSecondaryAuthenticationProviderTest.php:55
StatusValue\newGood
static newGood( $value=null)
Factory function for good results.
Definition: StatusValue.php:81
MediaWiki\Auth\AbstractSecondaryAuthenticationProviderTest\testAbstractSecondaryAuthenticationProvider
testAbstractSecondaryAuthenticationProvider()
Definition: AbstractSecondaryAuthenticationProviderTest.php:10
$req
this hook is for auditing only $req
Definition: hooks.txt:990
MediaWiki\Auth\AuthManager\ACTION_REMOVE
const ACTION_REMOVE
Remove a user's credentials.
Definition: AuthManager.php:102
MediaWiki\Auth\AbstractSecondaryAuthenticationProviderTest
AuthManager MediaWiki\Auth\AbstractSecondaryAuthenticationProvider.
Definition: AbstractSecondaryAuthenticationProviderTest.php:9
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:22
class
you have access to all of the normal MediaWiki so you can get a DB use the etc For full docs on the Maintenance class
Definition: maintenance.txt:56
MediaWiki\Auth
Definition: AbstractAuthenticationProvider.php:22
MediaWiki\Auth\AuthenticationResponse\newPass
static newPass( $username=null)
Definition: AuthenticationResponse.php:134