Skip to content

Commit

Permalink
Create ErrorMissingAuthorizationHeaderTest.php
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasmatusiewicz committed Mar 5, 2024
1 parent cb2a002 commit fc3ce2e
Showing 1 changed file with 84 additions and 0 deletions.
84 changes: 84 additions & 0 deletions test/ErrorMissingAuthorizationHeaderTest.php
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";
}
}

0 comments on commit fc3ce2e

Please sign in to comment.