MediaWiki REL1_33
TokenTest.php
Go to the documentation of this file.
1<?php
2
3namespace MediaWiki\Session;
4
7
13
14 public function testBasics() {
15 $token = $this->getMockBuilder( Token::class )
16 ->setMethods( [ 'toStringAtTimestamp' ] )
17 ->setConstructorArgs( [ 'sekret', 'salty', true ] )
18 ->getMock();
19 $token->expects( $this->any() )->method( 'toStringAtTimestamp' )
20 ->will( $this->returnValue( 'faketoken+\\' ) );
21
22 $this->assertSame( 'faketoken+\\', $token->toString() );
23 $this->assertSame( 'faketoken+\\', (string)$token );
24 $this->assertTrue( $token->wasNew() );
25
26 $token = new Token( 'sekret', 'salty', false );
27 $this->assertFalse( $token->wasNew() );
28 }
29
30 public function testToStringAtTimestamp() {
31 $token = TestingAccessWrapper::newFromObject( new Token( 'sekret', 'salty', false ) );
32
33 $this->assertSame(
34 'd9ade0c7d4349e9df9094e61c33a5a0d5644fde2+\\',
35 $token->toStringAtTimestamp( 1447362018 )
36 );
37 $this->assertSame(
38 'ee2f7a2488dea9176c224cfb400d43be5644fdea+\\',
39 $token->toStringAtTimestamp( 1447362026 )
40 );
41 }
42
43 public function testGetTimestamp() {
44 $this->assertSame(
45 1447362018, Token::getTimestamp( 'd9ade0c7d4349e9df9094e61c33a5a0d5644fde2+\\' )
46 );
47 $this->assertSame(
48 1447362026, Token::getTimestamp( 'ee2f7a2488dea9176c224cfb400d43be5644fdea+\\' )
49 );
50 $this->assertNull( Token::getTimestamp( 'ee2f7a2488dea9176c224cfb400d43be5644fdea-\\' ) );
51 $this->assertNull( Token::getTimestamp( 'ee2f7a2488dea9176c224cfb400d43be+\\' ) );
52
53 $this->assertNull( Token::getTimestamp( 'ee2f7a2488dea9x76c224cfb400d43be5644fdea+\\' ) );
54 }
55
56 public function testMatch() {
57 $token = TestingAccessWrapper::newFromObject( new Token( 'sekret', 'salty', false ) );
58
59 $test = $token->toStringAtTimestamp( time() - 10 );
60 $this->assertTrue( $token->match( $test ) );
61 $this->assertTrue( $token->match( $test, 12 ) );
62 $this->assertFalse( $token->match( $test, 8 ) );
63
64 $this->assertFalse( $token->match( 'ee2f7a2488dea9176c224cfb400d43be5644fdea-\\' ) );
65 }
66
67}
and that you know you can do these things To protect your we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights These restrictions translate to certain responsibilities for you if you distribute copies of the or if you modify it For if you distribute copies of such a whether gratis or for a you must give the recipients all the rights that you have You must make sure that receive or can get the source code And you must show them these terms so they know their rights We protect your rights with two and(2) offer you this license which gives you legal permission to copy
they could even be mouse clicks or menu items whatever suits your program You should also get your if any
Definition COPYING.txt:326
Session MediaWiki\Session\Token.
Definition TokenTest.php:12
Value object representing a CSRF token.
Definition Token.php:32
static getTimestamp( $token)
Decode the timestamp from a token string.
Definition Token.php:66