1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
|
<?php
require_once "PHPUnit.php";
require_once "Tests/Auth/OpenID/TestUtil.php";
require_once "Tests/Auth/OpenID/MemStore.php";
require_once "Auth/OpenID/Message.php";
require_once "Auth/OpenID/Consumer.php";
class Tests_Auth_OpenID_VerifyDisco extends OpenIDTestMixin {
var $consumer_class = 'Auth_OpenID_GenericConsumer';
function setUp()
{
$this->store = new Tests_Auth_OpenID_MemStore();
$cl = $this->consumer_class;
$this->consumer = new $cl($this->store);
$this->return_to = "http://some.host/path";
$this->endpoint = new Auth_OpenID_ServiceEndpoint();
$this->server_id = "sirod";
$this->server_url = "serlie";
$this->consumer_id = "consu";
$this->endpoint->claimed_id = $this->consumer_id;
$this->endpoint->server_url = $this->server_url;
$this->endpoint->local_id = $this->server_id;
$this->endpoint->type_uris = array(Auth_OpenID_TYPE_1_1);
}
function failUnlessProtocolError($thing)
{
$this->assertTrue(Auth_OpenID::isFailure($thing));
}
function test_openID1NoLocalID()
{
$endpoint = new Auth_OpenID_ServiceEndpoint();
$endpoint->claimed_id = 'bogus';
$msg = Auth_OpenID_Message::fromOpenIDArgs(array());
// 'Missing required field openid.identity'
$this->failUnlessProtocolError($this->consumer->_verifyDiscoveryResults($msg, $endpoint));
}
function test_openID1NoEndpoint()
{
$msg = Auth_OpenID_Message::fromOpenIDArgs(array('identity' => 'snakes on a plane'));
$this->failUnlessProtocolError($this->consumer->_verifyDiscoveryResults($msg));
}
function test_openID2NoOPEndpointArg()
{
$msg = Auth_OpenID_Message::fromOpenIDArgs(array('ns' => Auth_OpenID_OPENID2_NS));
$this->failUnlessProtocolError($this->consumer->_verifyDiscoveryResults($msg, null));
}
function test_openID2LocalIDNoClaimed()
{
$msg = Auth_OpenID_Message::fromOpenIDArgs(array('ns' => Auth_OpenID_OPENID2_NS,
'op_endpoint' => 'Phone Home',
'identity' => 'Jose Lius Borges'));
// 'openid.identity is present without',
$this->failUnlessProtocolError($this->consumer->_verifyDiscoveryResults($msg));
}
function test_openID2NoLocalIDClaimed()
{
$msg = Auth_OpenID_Message::fromOpenIDArgs(array('ns' => Auth_OpenID_OPENID2_NS,
'op_endpoint' => 'Phone Home',
'claimed_id' => 'Manuel Noriega'));
// 'openid.claimed_id is present without',
$this->failUnlessProtocolError(
$this->consumer->_verifyDiscoveryResults($msg));
}
function test_openID2NoIdentifiers()
{
$op_endpoint = 'Phone Home';
$msg = Auth_OpenID_Message::fromOpenIDArgs(array('ns' => Auth_OpenID_OPENID2_NS,
'op_endpoint' => $op_endpoint));
$result_endpoint = $this->consumer->_verifyDiscoveryResults($msg);
$this->assertTrue($result_endpoint->isOPIdentifier());
$this->assertEquals($op_endpoint, $result_endpoint->server_url);
$this->assertEquals(null, $result_endpoint->claimed_id);
}
function test_openid2UsePreDiscovered()
{
$endpoint = new Auth_OpenID_ServiceEndpoint();
$endpoint->local_id = 'my identity';
$endpoint->claimed_id = 'i am sam';
$endpoint->server_url = 'Phone Home';
$endpoint->type_uris = array(Auth_OpenID_TYPE_2_0);
$msg = Auth_OpenID_Message::fromOpenIDArgs(
array('ns' => Auth_OpenID_OPENID2_NS,
'identity' => $endpoint->local_id,
'claimed_id' => $endpoint->claimed_id,
'op_endpoint' => $endpoint->server_url));
$result = $this->consumer->_verifyDiscoveryResults($msg, $endpoint);
$this->assertTrue($result === $endpoint);
}
function test_openid2UsePreDiscoveredWrongType()
{
$endpoint = new Auth_OpenID_ServiceEndpoint();
$endpoint->local_id = 'my identity';
$endpoint->claimed_id = 'i am sam';
$endpoint->server_url = 'Phone Home';
$endpoint->type_uris = array(Auth_OpenID_TYPE_1_1);
$msg = Auth_OpenID_Message::fromOpenIDArgs(
array('ns' => Auth_OpenID_OPENID2_NS,
'identity' => $endpoint->local_id,
'claimed_id' => $endpoint->claimed_id,
'op_endpoint' => $endpoint->server_url));
$this->failUnlessProtocolError(
$this->consumer->_verifyDiscoveryResults($msg, $endpoint));
}
function test_openid1UsePreDiscovered()
{
$endpoint = new Auth_OpenID_ServiceEndpoint();
$endpoint->local_id = 'my identity';
$endpoint->claimed_id = 'i am sam';
$endpoint->server_url = 'Phone Home';
$endpoint->type_uris = array(Auth_OpenID_TYPE_1_1);
$msg = Auth_OpenID_Message::fromOpenIDArgs(
array('ns' => Auth_OpenID_OPENID1_NS,
'identity' => $endpoint->local_id));
$result = $this->consumer->_verifyDiscoveryResults($msg, $endpoint);
$this->assertTrue($result == $endpoint);
}
function test_openid1UsePreDiscoveredWrongType()
{
$endpoint = new Auth_OpenID_ServiceEndpoint();
$endpoint->local_id = 'my identity';
$endpoint->claimed_id = 'i am sam';
$endpoint->server_url = 'Phone Home';
$endpoint->type_uris = array(Auth_OpenID_TYPE_2_0);
$msg = Auth_OpenID_Message::fromOpenIDArgs(
array('ns' => Auth_OpenID_OPENID1_NS,
'identity' => $endpoint->local_id));
$this->failUnlessProtocolError(
$this->consumer->_verifyDiscoveryResults($msg, $endpoint));
}
}
// XXX: test the implementation of _discoverAndVerify
class Tests_openID2NoEndpointDoesDisco_sentinel extends Auth_OpenID_GenericConsumer {
var $sentinel = 'blah';
function _discoverAndVerify($to_match)
{
return $this->sentinel;
}
}
class Tests_openID2NoEndpointDoesDisco extends Tests_Auth_OpenID_VerifyDisco {
var $consumer_class = 'Tests_openID2NoEndpointDoesDisco_sentinel';
function test_openID2NoEndpointDoesDisco()
{
$op_endpoint = 'Phone Home';
$sentinel = 'thing';
$msg = Auth_OpenID_Message::fromOpenIDArgs(
array('ns' => Auth_OpenID_OPENID2_NS,
'identity' => 'sour grapes',
'claimed_id' => 'monkeysoft',
'op_endpoint' => $op_endpoint));
$result = $this->consumer->_verifyDiscoveryResults($msg);
$this->assertEquals($this->consumer->sentinel, $result);
}
}
class Tests_openID2MismatchedDoesDisco extends Tests_Auth_OpenID_VerifyDisco {
var $consumer_class = 'Tests_openID2NoEndpointDoesDisco_sentinel';
function test_openID2MismatchedDoesDisco()
{
$mismatched = new Auth_OpenID_ServiceEndpoint();
$mismatched->identity = 'nothing special, but different';
$mismatched->local_id = 'green cheese';
$op_endpoint = 'Phone Home';
$msg = Auth_OpenID_Message::fromOpenIDArgs(
array('ns' => Auth_OpenID_OPENID2_NS,
'identity' => 'sour grapes',
'claimed_id' => 'monkeysoft',
'op_endpoint' => $op_endpoint));
$result = $this->consumer->_verifyDiscoveryResults($msg, $mismatched);
$this->assertEquals($this->consumer->sentinel, $result);
}
}
class TestVerifyDiscoverySingle extends OpenIDTestMixin {
var $consumer_class = 'Auth_OpenID_GenericConsumer';
function setUp()
{
$this->store = new Tests_Auth_OpenID_MemStore();
$cl = $this->consumer_class;
$this->consumer = new $cl($this->store);
$this->return_to = "http://some.host/path";
$this->endpoint = new Auth_OpenID_ServiceEndpoint();
$this->server_id = "sirod";
$this->server_url = "serlie";
$this->consumer_id = "consu";
$this->endpoint->claimed_id = $this->consumer_id;
$this->endpoint->server_url = $this->server_url;
$this->endpoint->local_id = $this->server_id;
$this->endpoint->type_uris = array(Auth_OpenID_TYPE_1_1);
}
function test_endpointWithoutLocalID()
{
// An endpoint like this with no local_id is generated as a
// result of e.g. Yadis discovery with no LocalID tag.
$endpoint = new Auth_OpenID_ServiceEndpoint();
$endpoint->server_url = "http://localhost:8000/openidserver";
$endpoint->claimed_id = "http://localhost:8000/id/id-jo";
$to_match = new Auth_OpenID_ServiceEndpoint();
$to_match->server_url = "http://localhost:8000/openidserver";
$to_match->claimed_id = "http://localhost:8000/id/id-jo";
$to_match->local_id = "http://localhost:8000/id/id-jo";
$result = $this->consumer->_verifyDiscoverySingle($endpoint, $to_match);
// result should always be None, raises exception on failure.
$this->assertEquals($result, null);
}
}
global $Tests_Auth_OpenID_VerifyDisco_other;
$Tests_Auth_OpenID_VerifyDisco_other = array(
new Tests_openID2MismatchedDoesDisco(),
new Tests_openID2NoEndpointDoesDisco()
);
?>
|