Skip to content
Permalink
Browse files

Changing authentication classes to use suffix Authentication instead …

…of Method.
  • Loading branch information...
jrbasso committed Nov 20, 2010
1 parent 7e0d349 commit 3056fbf680572fc63b2e53f7de5355fc60051c86
@@ -24,7 +24,7 @@
* @package cake
* @subpackage cake.cake.libs.http
*/
class BasicMethod {
class BasicAuthentication {
/**
* Authentication
@@ -24,7 +24,7 @@
* @package cake
* @subpackage cake.cake.libs.http
*/
class DigestMethod {
class DigestAuthentication {
/**
* Authentication
@@ -455,7 +455,7 @@ protected function _setAuth() {
return;
}
}
$authClass = Inflector::camelize($this->request['auth']['method']) . 'Method';
$authClass = Inflector::camelize($this->request['auth']['method']) . 'Authentication';
if (!App::import('Lib', 'http/' . $authClass)) {
throw new Exception(__('Unknown authentication method.'));
}
@@ -19,7 +19,7 @@
*/
App::import('Core', 'HttpSocket');
App::import('Lib', 'http/BasicMethod');
App::import('Lib', 'http/BasicAuthentication');
/**
* BasicMethodTest class
@@ -42,7 +42,7 @@ public function testAuthentication() {
'pass' => 'secret'
);
BasicMethod::authentication($http);
BasicAuthentication::authentication($http);
$this->assertEqual($http->request['header']['Authorization'], 'Basic bWFyazpzZWNyZXQ=');
}
@@ -1,6 +1,6 @@
<?php
/**
* DigestMethodTest file
* DigestAuthenticationTest file
*
* PHP 5
*
@@ -19,7 +19,7 @@
*/
App::import('Core', 'HttpSocket');
App::import('Lib', 'http/DigestMethod');
App::import('Lib', 'http/DigestAuthentication');
class DigestHttpSocket extends HttpSocket {
@@ -43,12 +43,12 @@ public function request($request) {
}
/**
* DigestMethodTest class
* DigestAuthenticationTest class
*
* @package cake
* @subpackage cake.tests.cases.libs.http
*/
class DigestMethodTest extends CakeTestCase {
class DigestAuthenticationTest extends CakeTestCase {
/**
* Socket property
@@ -91,7 +91,7 @@ public function testBasic() {
$this->HttpSocket->nextHeader = 'Digest realm="The batcave",nonce="4cded326c6c51"';
$this->HttpSocket->config['request']['auth'] = array();
$this->assertFalse(isset($this->HttpSocket->request['header']['Authorization']));
DigestMethod::authentication($this->HttpSocket);
DigestAuthentication::authentication($this->HttpSocket);
$this->assertTrue(isset($this->HttpSocket->request['header']['Authorization']));
$this->assertEqual($this->HttpSocket->config['request']['auth']['realm'], 'The batcave');
$this->assertEqual($this->HttpSocket->config['request']['auth']['nonce'], '4cded326c6c51');
@@ -105,15 +105,15 @@ public function testBasic() {
public function testQop() {
$this->HttpSocket->nextHeader = 'Digest realm="The batcave",nonce="4cded326c6c51"';
$this->HttpSocket->config['request']['auth'] = array();
DigestMethod::authentication($this->HttpSocket);
DigestAuthentication::authentication($this->HttpSocket);
$expected = 'Digest username="admin", realm="The batcave", nonce="4cded326c6c51", uri="/", response="da7e2a46b471d77f70a9bb3698c8902b"';
$this->assertEqual($expected, $this->HttpSocket->request['header']['Authorization']);
$this->assertFalse(isset($this->HttpSocket->config['request']['auth']['qop']));
$this->assertFalse(isset($this->HttpSocket->config['request']['auth']['nc']));
$this->HttpSocket->nextHeader = 'Digest realm="The batcave",nonce="4cded326c6c51",qop="auth"';
$this->HttpSocket->config['request']['auth'] = array();
DigestMethod::authentication($this->HttpSocket);
DigestAuthentication::authentication($this->HttpSocket);
$expected = '@Digest username="admin", realm="The batcave", nonce="4cded326c6c51", uri="/", response="[a-z0-9]{32}", qop="auth", nc=00000001, cnonce="[a-z0-9]+"@';
$this->assertPattern($expected, $this->HttpSocket->request['header']['Authorization']);
$this->assertEqual($this->HttpSocket->config['request']['auth']['qop'], 'auth');
@@ -128,12 +128,12 @@ public function testQop() {
public function testOpaque() {
$this->HttpSocket->nextHeader = 'Digest realm="The batcave",nonce="4cded326c6c51"';
$this->HttpSocket->config['request']['auth'] = array();
DigestMethod::authentication($this->HttpSocket);
DigestAuthentication::authentication($this->HttpSocket);
$this->assertFalse(strpos($this->HttpSocket->request['header']['Authorization'], 'opaque="d8ea7aa61a1693024c4cc3a516f49b3c"'));
$this->HttpSocket->nextHeader = 'Digest realm="The batcave",nonce="4cded326c6c51",opaque="d8ea7aa61a1693024c4cc3a516f49b3c"';
$this->HttpSocket->config['request']['auth'] = array();
DigestMethod::authentication($this->HttpSocket);
DigestAuthentication::authentication($this->HttpSocket);
$this->assertTrue(strpos($this->HttpSocket->request['header']['Authorization'], 'opaque="d8ea7aa61a1693024c4cc3a516f49b3c"') > 0);
}
@@ -145,18 +145,18 @@ public function testOpaque() {
public function testMultipleRequest() {
$this->HttpSocket->nextHeader = 'Digest realm="The batcave",nonce="4cded326c6c51",qop="auth"';
$this->HttpSocket->config['request']['auth'] = array();
DigestMethod::authentication($this->HttpSocket);
DigestAuthentication::authentication($this->HttpSocket);
$this->assertTrue(strpos($this->HttpSocket->request['header']['Authorization'], 'nc=00000001') > 0);
$this->assertEqual($this->HttpSocket->config['request']['auth']['nc'], 2);
DigestMethod::authentication($this->HttpSocket);
DigestAuthentication::authentication($this->HttpSocket);
$this->assertTrue(strpos($this->HttpSocket->request['header']['Authorization'], 'nc=00000002') > 0);
$this->assertEqual($this->HttpSocket->config['request']['auth']['nc'], 3);
$responsePos = strpos($this->HttpSocket->request['header']['Authorization'], 'response=');
$response = substr($this->HttpSocket->request['header']['Authorization'], $responsePos + 10, 32);
$this->HttpSocket->nextHeader = '';
DigestMethod::authentication($this->HttpSocket);
DigestAuthentication::authentication($this->HttpSocket);
$this->assertTrue(strpos($this->HttpSocket->request['header']['Authorization'], 'nc=00000003') > 0);
$this->assertEqual($this->HttpSocket->config['request']['auth']['nc'], 4);
$responsePos = strpos($this->HttpSocket->request['header']['Authorization'], 'response=');
@@ -173,7 +173,7 @@ public function testPathChanged() {
$this->HttpSocket->nextHeader = 'Digest realm="The batcave",nonce="4cded326c6c51"';
$this->HttpSocket->request['uri']['path'] = '/admin';
$this->HttpSocket->config['request']['auth'] = array();
DigestMethod::authentication($this->HttpSocket);
DigestAuthentication::authentication($this->HttpSocket);
$responsePos = strpos($this->HttpSocket->request['header']['Authorization'], 'response=');
$response = substr($this->HttpSocket->request['header']['Authorization'], $responsePos + 10, 32);
$this->assertNotEqual($response, 'da7e2a46b471d77f70a9bb3698c8902b');

0 comments on commit 3056fbf

Please sign in to comment.
You can’t perform that action at this time.