Aaron Schulz has uploaded a new change for review.
https://gerrit.wikimedia.org/r/81968
Change subject: Removed duplicate tests and easier to use TestOAuthConsumer
script
......................................................................
Removed duplicate tests and easier to use TestOAuthConsumer script
Change-Id: Ia4284afee13f8248def41027cbfb28c26d42f7bf
---
A maintenance/testOAuthConsumer.php
D tests/testClient.php
D tests/testClientHeaders.php
3 files changed, 102 insertions(+), 173 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/OAuth
refs/changes/68/81968/1
diff --git a/maintenance/testOAuthConsumer.php
b/maintenance/testOAuthConsumer.php
new file mode 100644
index 0000000..b6e96bf
--- /dev/null
+++ b/maintenance/testOAuthConsumer.php
@@ -0,0 +1,102 @@
+<?php
+/**
+ * @ingroup Maintenance
+ */
+if ( getenv( 'MW_INSTALL_PATH' ) ) {
+ $IP = getenv( 'MW_INSTALL_PATH' );
+} else {
+ $IP = dirname(__FILE__).'/../../..';
+}
+
+require( __DIR__ . '/../lib/OAuth.php' );
+require_once( "$IP/maintenance/Maintenance.php" );
+
+class TestOAuthConsumer extends Maintenance {
+ public function __construct() {
+ parent::__construct();
+ $this->mDescription = "Test an OAuth consumer";
+ $this->addOption( 'consumerKey', 'Consumer key', true, true );
+ $this->addOption( 'consumerSecret', 'Consumer secret', true,
true );
+ $this->addOption( 'useSSL', 'Use SSL' );
+ }
+
+ public function execute() {
+ global $wgServer, $wgScriptPath;
+
+ $consumerKey = $this->getOption( 'consumerKey' );
+ $consumerSecret = $this->getOption( 'consumerSecret' );
+ $baseurl =
"{$wgServer}{$wgScriptPath}/index.php?title=Special:MWOAuth";
+ $endpoint =
"{$baseurl}/initiate&format=json&oauth_callback=oob";
+
+ $endpoint_acc = "{$baseurl}/token&format=json";
+
+ $c = new OAuthConsumer( $consumerKey, $consumerSecret );
+ $parsed = parse_url( $endpoint );
+ $params = array();
+ parse_str( $parsed['query'], $params );
+ $req_req = OAuthRequest::from_consumer_and_token( $c, NULL,
"GET", $endpoint, $params );
+ $hmac_method = new OAuthSignatureMethod_HMAC_SHA1();
+ $sig_method = $hmac_method;
+ $req_req->sign_request( $sig_method, $c, NULL );
+
+ $this->output( "Calling: $req_req\n" );
+
+ $ch = curl_init();
+ curl_setopt( $ch, CURLOPT_URL, (string) $req_req );
+ if ( $this->hasOption( 'useSSL' ) ) {
+ curl_setopt( $ch, CURLOPT_PORT , 443 );
+ }
+ curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, 0 );
+ curl_setopt( $ch, CURLOPT_HEADER, 0 );
+ curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
+ $data = curl_exec( $ch );
+
+ if ( !$data ) {
+ $this->output( 'Curl error: ' . curl_error( $ch ) );
+ }
+
+ $this->output( "Returned: $data\n\n" );
+
+ $token = json_decode( $data );
+ if ( !$token || !isset( $token->key ) ) {
+ $this->error( 'Could not fetch token', 1 );
+ }
+
+ $this->output( "Visit $baseurl/authorize" .
+
"&oauth_token={$token->key}&oauth_consumer_key=$consumerKey\n" );
+
+ // ACCESS TOKEN
+ $this->output( "Enter the verification code:\n" );
+ $fh = fopen( "php://stdin", "r" );
+ $line = fgets( $fh );
+
+ $rc = new OAuthConsumer( $token->key, $token->secret );
+ $parsed = parse_url( $endpoint_acc );
+ parse_str( $parsed['query'], $params );
+ $params['oauth_verifier'] = trim( $line );
+
+ $acc_req = OAuthRequest::from_consumer_and_token( $c, $rc,
"GET", $endpoint_acc, $params );
+ $acc_req->sign_request( $sig_method, $c, $rc );
+
+ $this->output( "Calling: $acc_req\n" );
+
+ unset( $ch );
+ $ch = curl_init();
+ curl_setopt( $ch, CURLOPT_URL, (string) $acc_req );
+ if ( $this->hasOption( 'useSSL' ) ) {
+ curl_setopt( $ch, CURLOPT_PORT , 443 );
+ }
+ curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, 0 );
+ curl_setopt( $ch, CURLOPT_HEADER, 0 );
+ curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
+ $data = curl_exec( $ch );
+ if ( !$data ) {
+ $this->output( 'Curl error: ' . curl_error( $ch ) );
+ }
+
+ $this->output( "Returned: $data\n\n" );
+ }
+}
+
+$maintClass = "TestOAuthConsumer";
+require_once( RUN_MAINTENANCE_IF_MAIN );
diff --git a/tests/testClient.php b/tests/testClient.php
deleted file mode 100644
index 0ef9ad8..0000000
--- a/tests/testClient.php
+++ /dev/null
@@ -1,85 +0,0 @@
-<?php
-
-if ( PHP_SAPI !== 'cli' ) {
- die( "CLI-only test script\n" );
-}
-
-/**
- * A basic client for overall testing
- */
-
-function wfDebugLog( $method, $msg) {
- //echo "[$method] $msg\n";
-}
-
-
-require __DIR__ . '/../lib/OAuth.php';
-
-$consumerKey = 'dpf43f3p2l4k3l03';
-$consumerSecret = 'kd94hf93k423kf44';
-$baseurl = 'https://localhost/wiki/index.php?title=Special:MWOAuth';
-$endpoint = $baseurl . '/initiate&format=json&oauth_callback=oob';
-
-$endpoint_acc = $baseurl . '/token&format=json';
-
-$c = new OAuthConsumer( $consumerKey, $consumerSecret );
-$parsed = parse_url( $endpoint );
-$params = array();
-parse_str($parsed['query'], $params);
-$req_req = OAuthRequest::from_consumer_and_token($c, NULL, "GET", $endpoint,
$params);
-$hmac_method = new OAuthSignatureMethod_HMAC_SHA1();
-$sig_method = $hmac_method;
-$req_req->sign_request($sig_method, $c, NULL);
-
-echo "Calling: $req_req\n";
-
-$ch = curl_init();
-curl_setopt( $ch, CURLOPT_URL, (string) $req_req );
-curl_setopt( $ch, CURLOPT_PORT , 443 );
-curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, 0 );
-curl_setopt( $ch, CURLOPT_HEADER, 0 );
-curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
-$data = curl_exec( $ch );
-
-if( !$data ) {
- 'Curl error: ' . curl_error( $ch );
-}
-
-echo "Returned: $data\n\n";
-
-$token = json_decode( $data );
-
-print "Visit
$baseurl/authorize&oauth_token={$token->key}&oauth_consumer_key=$consumerKey\n";
-
-// ACCESS TOKEN
-print "Enter the verification code:\n";
-$fh = fopen( "php://stdin", "r" );
-$line = fgets( $fh );
-
-$rc = new OAuthConsumer( $token->key, $token->secret );
-$parsed = parse_url( $endpoint_acc );
-parse_str($parsed['query'], $params);
-$params['oauth_verifier'] = trim($line);
-
-$acc_req = OAuthRequest::from_consumer_and_token($c, $rc, "GET",
$endpoint_acc, $params);
-$acc_req->sign_request($sig_method, $c, $rc);
-
-echo "Calling: $acc_req\n";
-
-unset( $ch );
-$ch = curl_init();
-curl_setopt( $ch, CURLOPT_URL, (string) $acc_req );
-curl_setopt( $ch, CURLOPT_PORT , 443 );
-curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, 0 );
-curl_setopt( $ch, CURLOPT_HEADER, 0 );
-curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
-$data = curl_exec( $ch );
-if( !$data ) {
- 'Curl error: ' . curl_error( $ch );
-}
-
-echo "Returned: $data\n\n";
-
-
-
-
diff --git a/tests/testClientHeaders.php b/tests/testClientHeaders.php
deleted file mode 100644
index 9951763..0000000
--- a/tests/testClientHeaders.php
+++ /dev/null
@@ -1,88 +0,0 @@
-<?php
-
-if ( PHP_SAPI !== 'cli' ) {
- die( "CLI-only test script\n" );
-}
-
-/**
- * A basic client for overall testing
- */
-
-function wfDebugLog( $method, $msg) {
- //echo "[$method] $msg\n";
-}
-
-
-require '../lib/OAuth.php';
-
-$consumerKey = 'dpf43f3p2l4k3l03';
-$consumerSecret = 'kd94hf93k423kf44';
-$baseurl = 'https://localhost/wiki/index.php?title=Special:MWOAuth';
-$endpoint = $baseurl . '/initiate&format=json&oauth_callback=oob';
-
-$endpoint_acc = $baseurl . '/token&format=json';
-
-$c = new OAuthConsumer( $consumerKey, $consumerSecret );
-$parsed = parse_url( $endpoint );
-$params = array();
-parse_str($parsed['query'], $params);
-$req_req = OAuthRequest::from_consumer_and_token($c, NULL, "GET", $endpoint,
$params);
-$hmac_method = new OAuthSignatureMethod_HMAC_SHA1();
-$sig_method = $hmac_method;
-$req_req->sign_request($sig_method, $c, NULL);
-
-$headers = array( $req_req->to_header() );
-
-echo "Calling: $endpoint\nHeader: {$headers[0]}\n\n";
-
-$ch = curl_init();
-curl_setopt( $ch, CURLOPT_URL, $endpoint );
-curl_setopt( $ch, CURLOPT_PORT , 443 );
-curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, 0 );
-curl_setopt( $ch, CURLOPT_HEADER, 0 );
-curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
-curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
-$data = curl_exec( $ch );
-
-if( !$data ) {
- 'Curl error: ' . curl_error( $ch );
-}
-
-echo "Returned: $data\n\n";
-
-$token = json_decode( $data );
-
-print "Visit
$baseurl/authorize&oauth_token={$token->key}&oauth_consumer_key=$consumerKey\n";
-
-// ACCESS TOKEN
-print "Enter the verification code:\n";
-$fh = fopen( "php://stdin", "r" );
-$line = fgets( $fh );
-
-$rc = new OAuthConsumer( $token->key, $token->secret );
-$parsed = parse_url( $endpoint_acc );
-parse_str($parsed['query'], $params);
-$params['oauth_verifier'] = trim($line);
-
-$acc_req = OAuthRequest::from_consumer_and_token($c, $rc, "GET",
$endpoint_acc, $params);
-$acc_req->sign_request($sig_method, $c, $rc);
-
-echo "Calling: $acc_req\n";
-
-unset( $ch );
-$ch = curl_init();
-curl_setopt( $ch, CURLOPT_URL, (string) $acc_req );
-curl_setopt( $ch, CURLOPT_PORT , 443 );
-curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, 0 );
-curl_setopt( $ch, CURLOPT_HEADER, 0 );
-curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
-$data = curl_exec( $ch );
-if( !$data ) {
- 'Curl error: ' . curl_error( $ch );
-}
-
-echo "Returned: $data\n\n";
-
-
-
-
--
To view, visit https://gerrit.wikimedia.org/r/81968
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ia4284afee13f8248def41027cbfb28c26d42f7bf
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/OAuth
Gerrit-Branch: master
Gerrit-Owner: Aaron Schulz <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits