Skip to content

Commit

Permalink
Update code to use library-constants for errors
Browse files Browse the repository at this point in the history
  • Loading branch information
tvdijen committed Jul 10, 2024
1 parent cb666fd commit faf8ac3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions public/proxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,18 +98,18 @@

\SimpleSAML\Logger::debug('casserver:' . $message);

echo $protocol->getProxyFailureResponse('INVALID_REQUEST', $message);
echo $protocol->getProxyFailureResponse(C::ERR_INVALID_REQUEST, $message);
} elseif (!checkServiceURL(sanitize($_GET['targetService']), $legal_target_service_urls)) {
$message = 'Target service parameter not listed as a legal service: [targetService] = ' .
var_export($_GET['targetService'], true);

\SimpleSAML\Logger::debug('casserver:' . $message);

echo $protocol->getProxyFailureResponse('INVALID_REQUEST', $message);
echo $protocol->getProxyFailureResponse(C::ERR_INVALID_REQUEST, $message);
} else {
$message = 'Missing proxy granting ticket parameter: [pgt]';

\SimpleSAML\Logger::debug('casserver:' . $message);

echo $protocol->getProxyFailureResponse('INVALID_REQUEST', $message);
echo $protocol->getProxyFailureResponse(C::ERR_INVALID_REQUEST, $message);
}
8 changes: 4 additions & 4 deletions tests/src/TicketValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function testNonExistantTicket(): void
$this->ticketValidator->validateAndDeleteTicket($id, 'efg');
$this->fail('exception expected');
} catch (CasException $e) {
$this->assertEquals('INVALID_TICKET', $e->getCasCode());
$this->assertEquals(C::ERR_INVALID_TICKET, $e->getCasCode());
$this->assertEquals('Ticket \'' . $id . '\' not recognized', $e->getMessage());
}
}
Expand All @@ -77,7 +77,7 @@ public function testValidTicket(): void
$this->ticketValidator->validateAndDeleteTicket($id, $serviceUrl);
$this->fail('exception expected');
} catch (CasException $e) {
$this->assertEquals('INVALID_TICKET', $e->getCasCode());
$this->assertEquals(C::ERR_INVALID_TICKET, $e->getCasCode());
$this->assertEquals('Ticket \'' . $id . '\' not recognized', $e->getMessage());
}
}
Expand All @@ -95,7 +95,7 @@ public function testWrongServiceUrlTicket(): void
$this->ticketValidator->validateAndDeleteTicket($id, $serviceUrl);
$this->fail('exception expected');
} catch (CasException $e) {
$this->assertEquals('INVALID_SERVICE', $e->getCasCode());
$this->assertEquals(C::ERR_INVALID_SERVICE, $e->getCasCode());
$this->assertEquals(
"Mismatching service parameters: expected 'http://otherurl.com' but was: 'http://efh.com?a=b&'",
$e->getMessage()
Expand All @@ -118,7 +118,7 @@ public function testExpiredTicket(): void
$this->ticketValidator->validateAndDeleteTicket($id, $serviceUrl);
$this->fail('exception expected');
} catch (CasException $e) {
$this->assertEquals('INVALID_TICKET', $e->getCasCode());
$this->assertEquals(C::ERR_INVALID_TICKET, $e->getCasCode());
$this->assertEquals('Ticket \'' . $id . '\' has expired', $e->getMessage());
}
// ensure ticket deleted after validation
Expand Down

0 comments on commit faf8ac3

Please sign in to comment.