-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create ErrorMissingAuthorizationHeaderTest.php
- Loading branch information
1 parent
cb2a002
commit fc3ce2e
Showing
1 changed file
with
84 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
<?php | ||
|
||
//require_once(__DIR__ . '/../src/Client-Autoloader.php'); | ||
require_once(__DIR__ . '/../vendor/autoload.php'); | ||
require_once('utils/Utils.php'); | ||
|
||
use InterNations\Component\HttpMock\PHPUnit\HttpMockTrait; | ||
use PHPUnit\Framework\TestCase; | ||
use utils\Utils; | ||
|
||
class ErrorMissingAuthorizationHeaderTest extends TestCase implements PILog | ||
{ | ||
private $pi; | ||
|
||
use HttpMockTrait; | ||
|
||
public static function setUpBeforeClass(): void | ||
{ | ||
static::setUpHttpMockBeforeClass('8082', 'localhost'); | ||
} | ||
|
||
public static function tearDownAfterClass(): void | ||
{ | ||
static::tearDownHttpMockAfterClass(); | ||
} | ||
|
||
public function setUp(): void | ||
{ | ||
$this->setUpHttpMock(); | ||
$this->pi = new PrivacyIDEA('testUserAgent', "localhost:8082"); | ||
$this->pi->logger = $this; | ||
$this->pi->realm = "testRealm"; | ||
} | ||
|
||
public function tearDown(): void | ||
{ | ||
$this->tearDownHttpMock(); | ||
} | ||
|
||
/** | ||
* @throws PIBadRequestException | ||
*/ | ||
public function testErrorMissingAuthorizationHeader() | ||
{ | ||
$this->http->mock | ||
->when() | ||
->methodIs('POST') | ||
->pathIs('/validate/triggerchallenge') | ||
->then() | ||
->body(Utils::errorMissingAuthorizationHeaderResponseBody()) | ||
->end(); | ||
$this->http->setUp(); | ||
|
||
$this->http->mock | ||
->when() | ||
->methodIs('POST') | ||
->pathIs('/auth') | ||
->then() | ||
->body(Utils::postAuthNoRoleAdminResponseBody()) | ||
->end(); | ||
$this->http->setUp(); | ||
|
||
$this->pi->serviceAccountName = "testServiceAccount"; | ||
$this->pi->serviceAccountPass = "testServicePass"; | ||
$this->pi->serviceAccountRealm = "testServiceRealm"; | ||
|
||
$response = $this->pi->triggerchallenge("testUser"); | ||
|
||
$this->assertEquals("4033", $response->errorCode); | ||
$this->assertEquals("Authentication failure. Missing Authorization header.", $response->errorMessage); | ||
$this->assertFalse($response->status); | ||
$this->assertEquals("", $response->otpMessage()); | ||
} | ||
|
||
public function piDebug($message) | ||
{ | ||
echo $message . "\n"; | ||
} | ||
|
||
public function piError($message) | ||
{ | ||
echo "error: " . $message . "\n"; | ||
} | ||
} |