Skip to content

Commit c8e5e4b

Browse files
committed
PHPCAS-102 The cas server should always return attributes in utf-8. If we don't tell the xml parser it might choke on international characters in some instances.
The examples config.php has to set the proper header so that international characters are displayed correctly in the examples git-svn-id: https://source.jasig.org/cas-clients/phpcas/trunk@25046 f5dbab47-78f9-eb45-b975-e544023573eb
1 parent 68c50e7 commit c8e5e4b

File tree

3 files changed

+57
-0
lines changed

3 files changed

+57
-0
lines changed

docs/examples/config.php.example

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,6 @@ $cas_url = $cas_url.$cas_context;
8181
// doesn't share its session with a proxied script.
8282
// This is just useful when running the example code, but not normally.
8383
session_name('session_for:'.preg_replace('/[^a-z0-9-]/i', '_', basename($_SERVER['SCRIPT_NAME'])));
84+
// Set an UTF-8 encoding header for internation characters (User attributes)
85+
header('Content-Type: text/html; charset=utf-8');
8486
?>

source/CAS/Client.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2499,6 +2499,8 @@ public function validateCAS20(&$validate_url,&$text_response,&$tree_response)
24992499
$dom = new DOMDocument();
25002500
// Fix possible whitspace problems
25012501
$dom->preserveWhiteSpace = false;
2502+
// CAS servers should only return data in utf-8
2503+
$dom->encoding = "utf-8";
25022504
// read the response of the CAS server into a DOMDocument object
25032505
if ( !($dom->loadXML($text_response))) {
25042506
// read failed

test/tests/Cas20AttributesTest.php

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,59 @@ public function test_jasig_attributes() {
163163

164164
}
165165

166+
167+
168+
public function test_jasig_attributes_international() {
169+
// Set up our response.
170+
$response = new CAS_TestHarness_BasicResponse('https', 'cas.example.edu', '/cas/serviceValidate');
171+
$response->setResponseHeaders(array(
172+
'HTTP/1.1 200 OK',
173+
'Date: Wed, 29 Sep 2010 19:20:57 GMT',
174+
'Server: Apache-Coyote/1.1',
175+
'Pragma: no-cache',
176+
'Expires: Thu, 01 Jan 1970 00:00:00 GMT',
177+
'Cache-Control: no-cache, no-store',
178+
'Content-Type: text/html;charset=UTF-8',
179+
'Content-Language: en-US',
180+
'Via: 1.1 cas.example.edu',
181+
'Connection: close',
182+
'Transfer-Encoding: chunked',
183+
));
184+
$response->setResponseBody(
185+
"<cas:serviceResponse xmlns:cas='http://www.yale.edu/tp/cas'>
186+
<cas:authenticationSuccess>
187+
<cas:user>Iñtërnâtiônàlizætiøn</cas:user>
188+
<cas:attributes>
189+
<cas:attraStyle>Jasig</cas:attraStyle>
190+
<cas:givenName>Iñtërnâtiônàlizætiøn</cas:givenName>
191+
</cas:attributes>
192+
<cas:proxyGrantingTicket>PGTIOU-84678-8a9d2sfa23casd</cas:proxyGrantingTicket>
193+
</cas:authenticationSuccess>
194+
</cas:serviceResponse>
195+
");
196+
CAS_TestHarness_DummyRequest::addResponse($response);
197+
198+
$this->object->setTicket('ST-123456-asdfasdfasgww2323radf3');
199+
$this->object->isAuthenticated();
200+
201+
// Verify that we have attributes from this response
202+
$attras = $this->object->getAttributes();
203+
$this->assertTrue($this->object->hasAttribute('attraStyle'));
204+
// direct access
205+
$this->assertEquals('Jasig', $this->object->getAttribute('attraStyle'));
206+
// array access
207+
$this->assertArrayHasKey('attraStyle', $attras);
208+
$this->assertEquals('Jasig', $attras['attraStyle']);
209+
210+
$this->assertTrue($this->object->hasAttribute('givenName'));
211+
// direct access
212+
$this->assertEquals('Iñtërnâtiônàlizætiøn', $this->object->getAttribute('givenName'));
213+
// array access
214+
$this->assertArrayHasKey('givenName', $attras);
215+
$this->assertEquals('Iñtërnâtiônàlizætiøn', $attras['givenName']);
216+
217+
}
218+
166219
/**
167220
* Verify that phpCAS will successfully fetch name-value-style attributes:
168221
*

0 commit comments

Comments
 (0)