/[volute]/trunk/projects/grid/vospace/php_endpoint/tests/test_auth.php
ViewVC logotype

Contents of /trunk/projects/grid/vospace/php_endpoint/tests/test_auth.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 737 - (show annotations)
Thu Aug 21 19:31:18 2008 UTC (12 years, 2 months ago) by richard.p.wagner
File size: 3405 byte(s)
WS-Security header capturing
1 <?php
2
3 include('../config.inc');
4 // ini_set('soap.wsdl_cache_enabled', 0);
5 require_once(SIMPLE_TEST . 'unit_tester.php');
6 require_once(SIMPLE_TEST . 'reporter.php');
7
8 require_once('debug_funcs.php');
9
10 class UsernameT1 {
11 private $Username; //Name must be identical to corresponding XML tag in SOAP header
12 private $Password; // Name must be identical to corresponding XML tag in SOAP header
13 function __construct($username, $password) {
14 $this->Username=$username;
15 $this->Password=$password;
16 }
17 }
18
19 class UserNameT2 {
20 private $UsernameToken; //Name must be identical to corresponding XML tag in SOAP header
21 function __construct ($innerVal){
22 $this->UsernameToken = $innerVal;
23 }
24 }
25
26 function get_header($username = 'joe', $password = 'doe'){
27
28 $nameSpace = "http://schemas.xmlsoap.org/ws/2003/06/secext"; //WS-Security namespace
29 $userT = new SoapVar($username, XSD_STRING, NULL, $nameSpace, NULL, $nameSpace);
30 $passwT = new SoapVar($password, XSD_STRING, NULL, $nameSpace, NULL, $nameSpace);
31
32 $tmp = new UsernameT1($userT, $passwT);
33 $uuT = new SoapVar($tmp, SOAP_ENC_OBJECT, NULL, $nameSpace,
34 'UsernameToken', $nameSpace);
35
36 $tmp = new UsernameT2($uuT);
37 $userToken = new SoapVar($tmp, SOAP_ENC_OBJECT, NULL, $nameSpace, 'UsernameToken',
38 $nameSpace);
39 $secHeaderValue=new SoapVar($userToken, SOAP_ENC_OBJECT, NULL, $nameSpace, 'Security',
40 $nameSpace);
41 return new SoapHeader($nameSpace, 'Security', $secHeaderValue);
42
43 }
44
45 class TestVOSpaceAuthorization extends UnitTestCase {
46
47 function setUp(){
48
49 $this->secHeader = get_header();
50 $this->client = new
51 SoapClient('../vospace.wsdl',
52 array('location' => 'http://localhost/vospace/vospace_endpoint.php',
53 'uri' => 'http://www.ivoa.net/xml/VOSpaceContract-v1.1rc1',
54 'trace' => 1,
55 'exceptions' => 1));
56
57 }
58
59 function testGetProtocolsAuth() {
60 $this->client->__setSoapHeaders($this->secHeader);
61 $response = $this->client->GetProtocols();
62 // barf($this->client);
63
64 $accepts = $response->accepts;
65 $provides = $response->provides;
66
67 $this->assertNotNull($accepts);
68
69 $this->assertEqual($provides->protocol[0]->uri,
70 'ivo://net.ivoa.vospace/protocols#http-client');
71 }
72
73 function testGetProtocols() {
74 $response = $this->client->GetProtocols();
75 // barf($this->client);
76 $accepts = $response->accepts;
77 $provides = $response->provides;
78
79 $this->assertNotNull($accepts);
80
81 $this->assertEqual($provides->protocol[0]->uri,
82 'ivo://net.ivoa.vospace/protocols#http-client');
83 }
84
85 function testGetProtocolsCompare() {
86 $response_auth = $this->client->__soapCall('GetProtocols', array('GetProtocols'=>Null),
87 null, $this->secHeader );
88 $response = $this->client->GetProtocols();
89
90 $this->assertEqual($response_auth, $response);
91 }
92
93 function testUnauthorized(){
94 try {
95 $this->secHeader = get_header('jon', 'don');
96
97 $response_auth = $this->client->__soapCall('GetProtocols', array('GetProtocols'=>Null),
98 null, $this->secHeader );
99
100 $this->assertTrue(0, "Should have thrown not authenticated.");
101 }
102 catch (SoapFault $exp) {
103 $this->assertEqual($exp->faultstring, "Not authenticated.");
104 }
105
106 }
107 }
108
109 $test = new TestVOSpaceAuthorization();
110 $test->run(new HtmlReporter());
111
112 ?>

msdemlei@ari.uni-heidelberg.de
ViewVC Help
Powered by ViewVC 1.1.26