summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian Evans <grknight@gentoo.org>2020-10-06 11:22:15 -0400
committerBrian Evans <grknight@gentoo.org>2020-10-06 11:22:15 -0400
commit4a2d3a0b7596731e11ef9257138653bec81d6fd3 (patch)
tree0e33fdfd38e791cc9ffe46f11f954a7dce86d618 /OAuth/tests/phpunit/Lib/OAuthSignatureMethodHmacSha1Test.php
parentOpenIDConnect: Fix newly protected function (diff)
downloadextensions-4a2d3a0b7596731e11ef9257138653bec81d6fd3.tar.gz
extensions-4a2d3a0b7596731e11ef9257138653bec81d6fd3.tar.bz2
extensions-4a2d3a0b7596731e11ef9257138653bec81d6fd3.zip
Add OAuth for API access
Signed-off-by: Brian Evans <grknight@gentoo.org>
Diffstat (limited to 'OAuth/tests/phpunit/Lib/OAuthSignatureMethodHmacSha1Test.php')
-rw-r--r--OAuth/tests/phpunit/Lib/OAuthSignatureMethodHmacSha1Test.php90
1 files changed, 90 insertions, 0 deletions
diff --git a/OAuth/tests/phpunit/Lib/OAuthSignatureMethodHmacSha1Test.php b/OAuth/tests/phpunit/Lib/OAuthSignatureMethodHmacSha1Test.php
new file mode 100644
index 00000000..af01d1d4
--- /dev/null
+++ b/OAuth/tests/phpunit/Lib/OAuthSignatureMethodHmacSha1Test.php
@@ -0,0 +1,90 @@
+<?php
+
+namespace MediaWiki\Extensions\OAuth\Tests\Lib;
+
+use MediaWiki\Extensions\OAuth\Lib\OAuthConsumer;
+use MediaWiki\Extensions\OAuth\Lib\OAuthSignatureMethod_HMAC_SHA1;
+use MediaWiki\Extensions\OAuth\Lib\OAuthToken;
+
+/**
+ * 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 OAuthSignatureMethodHmacSha1Test extends \PHPUnit\Framework\TestCase {
+ private $method;
+
+ protected function setUp() : void {
+ $this->method = new OAuthSignatureMethod_HMAC_SHA1();
+ }
+
+ public function testIdentifyAsHmacSha1() {
+ $this->assertEquals('HMAC-SHA1', $this->method->get_name());
+ }
+
+ public function testBuildSignature() {
+ // Tests taken from http://wiki.oauth.net/TestCases section 9.2 ("HMAC-SHA1")
+ $request = new Mock_OAuthBaseStringRequest('bs');
+ $consumer = new OAuthConsumer('__unused__', 'cs');
+ $token = NULL;
+ $this->assertEquals('egQqG5AJep5sJ7anhXju1unge2I=', $this->method->build_signature( $request, $consumer, $token) );
+
+ $request = new Mock_OAuthBaseStringRequest('bs');
+ $consumer = new OAuthConsumer('__unused__', 'cs');
+ $token = new OAuthToken('__unused__', 'ts');
+ $this->assertEquals('VZVjXceV7JgPq/dOTnNmEfO0Fv8=', $this->method->build_signature( $request, $consumer, $token) );
+
+ $request = new Mock_OAuthBaseStringRequest('GET&http%3A%2F%2Fphotos.example.net%2Fphotos&file%3Dvacation.jpg%26'
+ . 'oauth_consumer_key%3Ddpf43f3p2l4k3l03%26oauth_nonce%3Dkllo9940pd9333jh%26oauth_signature_method%3DHMAC-SHA1%26'
+ . 'oauth_timestamp%3D1191242096%26oauth_token%3Dnnch734d00sl2jdk%26oauth_version%3D1.0%26size%3Doriginal');
+ $consumer = new OAuthConsumer('__unused__', 'kd94hf93k423kf44');
+ $token = new OAuthToken('__unused__', 'pfkkdhi9sl3r4s00');
+ $this->assertEquals('tR3+Ty81lMeYAr/Fid0kMTYa/WM=', $this->method->build_signature( $request, $consumer, $token) );
+ }
+
+ public function testVerifySignature() {
+ // Tests taken from http://wiki.oauth.net/TestCases section 9.2 ("HMAC-SHA1")
+ $request = new Mock_OAuthBaseStringRequest('bs');
+ $consumer = new OAuthConsumer('__unused__', 'cs');
+ $token = NULL;
+ $signature = 'egQqG5AJep5sJ7anhXju1unge2I=';
+ $this->assertTrue( $this->method->check_signature( $request, $consumer, $token, $signature) );
+
+ $request = new Mock_OAuthBaseStringRequest('bs');
+ $consumer = new OAuthConsumer('__unused__', 'cs');
+ $token = new OAuthToken('__unused__', 'ts');
+ $signature = 'VZVjXceV7JgPq/dOTnNmEfO0Fv8=';
+ $this->assertTrue($this->method->check_signature( $request, $consumer, $token, $signature) );
+
+ $request = new Mock_OAuthBaseStringRequest('GET&http%3A%2F%2Fphotos.example.net%2Fphotos&file%3Dvacation.jpg%26'
+ . 'oauth_consumer_key%3Ddpf43f3p2l4k3l03%26oauth_nonce%3Dkllo9940pd9333jh%26oauth_signature_method%3DHMAC-SHA1%26'
+ . 'oauth_timestamp%3D1191242096%26oauth_token%3Dnnch734d00sl2jdk%26oauth_version%3D1.0%26size%3Doriginal');
+ $consumer = new OAuthConsumer('__unused__', 'kd94hf93k423kf44');
+ $token = new OAuthToken('__unused__', 'pfkkdhi9sl3r4s00');
+ $signature = 'tR3+Ty81lMeYAr/Fid0kMTYa/WM=';
+ $this->assertTrue($this->method->check_signature( $request, $consumer, $token, $signature) );
+
+ }
+}