1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
<?php
namespace MediaWiki\Extensions\OAuth\Tests\Lib;
use MediaWiki\Extensions\OAuth\Lib\OAuthConsumer;
/**
* The MIT License
*
* Copyright (c) 2007 Andy Smith
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files ( the "Software" ), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
/**
* @group OAuth
*/
class OAuthSignatureMethodRsaSha1Test extends \PHPUnit\Framework\TestCase {
private $method;
protected function setUp() : void {
$this->method = new Mock_OAuthSignatureMethod_RSA_SHA1();
}
public function testIdentifyAsRsaSha1() {
$this->assertEquals('RSA-SHA1', $this->method->get_name());
}
public function testBuildSignature() {
if( ! function_exists('openssl_get_privatekey') ) {
$this->markTestSkipped('OpenSSL not available, can\'t test RSA-SHA1 functionality');
}
// Tests taken from http://wiki.oauth.net/TestCases section 9.3 ("RSA-SHA1")
$request = new Mock_OAuthBaseStringRequest('GET&http%3A%2F%2Fphotos.example.net%2Fphotos&file%3Dvacaction.jpg%26oauth_consumer_key%3Ddpf43f3p2l4k3l03%26oauth_nonce%3D13917289812797014437%26oauth_signature_method%3DRSA-SHA1%26oauth_timestamp%3D1196666512%26oauth_version%3D1.0%26size%3Doriginal');
$consumer = new OAuthConsumer('dpf43f3p2l4k3l03', '__unused__');
$token = NULL;
$signature = 'jvTp/wX1TYtByB1m+Pbyo0lnCOLIsyGCH7wke8AUs3BpnwZJtAuEJkvQL2/9n4s5wUmUl4aCI4BwpraNx4RtEXMe5qg5T1LVTGliMRpKasKsW//e+RinhejgCuzoH26dyF8iY2ZZ/5D1ilgeijhV/vBka5twt399mXwaYdCwFYE=';
$this->assertEquals($signature, $this->method->build_signature( $request, $consumer, $token) );
}
public function testVerifySignature() {
if( ! function_exists('openssl_get_privatekey') ) {
$this->markTestSkipped('OpenSSL not available, can\'t test RSA-SHA1 functionality');
}
// Tests taken from http://wiki.oauth.net/TestCases section 9.3 ("RSA-SHA1")
$request = new Mock_OAuthBaseStringRequest('GET&http%3A%2F%2Fphotos.example.net%2Fphotos&file%3Dvacaction.jpg%26oauth_consumer_key%3Ddpf43f3p2l4k3l03%26oauth_nonce%3D13917289812797014437%26oauth_signature_method%3DRSA-SHA1%26oauth_timestamp%3D1196666512%26oauth_version%3D1.0%26size%3Doriginal');
$consumer = new OAuthConsumer('dpf43f3p2l4k3l03', '__unused__');
$token = NULL;
$signature = 'jvTp/wX1TYtByB1m+Pbyo0lnCOLIsyGCH7wke8AUs3BpnwZJtAuEJkvQL2/9n4s5wUmUl4aCI4BwpraNx4RtEXMe5qg5T1LVTGliMRpKasKsW//e+RinhejgCuzoH26dyF8iY2ZZ/5D1ilgeijhV/vBka5twt399mXwaYdCwFYE=';
$this->assertTrue($this->method->check_signature( $request, $consumer, $token, $signature) );
}
}
|