My favorites | Sign in
Project Home Wiki Issues Source
Checkout   Browse   Changes    
 
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
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
/**
*
*/
package org.openiaml.model.tests.codegen.model0_5_1;

import org.eclipse.core.resources.IFile;
import org.openiaml.model.tests.CodegenTestCase;
import org.openiaml.model.tests.PhpRuntimeExceptionException;


/**
* @example InputTextField
* A {@model InputTextField} of type <code>iamlOpenIDURL</code>
* will have functionality to authenticate the URL with an
* <a href="http://openid.net/">OpenID</a> server.
*/
public class OpenIDAsAuthor extends CodegenTestCase {

/**
* This page will provide a openid.server to the same host.
*/
public static final String OPENID_PAGE_SERVER = "http://openiaml.org/openid/";

/**
* This page will provide an openid.server and openid.delegate.
* The delegate actually just points to the {@link #OPENID_PAGE_SERVER} above.
*/
public static final String OPENID_PAGE_DELEGATE = "http://openiaml.org/openid/delegate/";

/**
* This page will provide a openid.server to the same host, but
* it requires login as 'test'.
*/
public static final String OPENID_PAGE_SERVER_PASS = "http://openiaml.org/openid/password/";

/**
* This page will provide an openid.server and openid.delegate, but
* it requires login as 'test'.
* The delegate actually just points to the {@link #OPENID_PAGE_SERVER} above.
*/
public static final String OPENID_PAGE_DELEGATE_PASS = "http://openiaml.org/openid/delegate-password/";

@Override
protected void setUp() throws Exception {
super.setUp();
root = loadAndCodegen(OpenIDAsAuthor.class);
}

/**
* The home page can be accessed.
*
* @throws Exception
*/
public void testHome() throws Exception {
beginAtSitemapThenPage("Home");
assertNoProblem();
}

/**
* If we go to the View Posts page, we will get an exception:
* there are no posts currently.
*
* @throws Exception
*/
public void testViewPosts() throws Exception {
try {
beginAtSitemapThenPage("View Posts");
fail("Should have failed");
} catch (PhpRuntimeExceptionException e) {
assertContains("No results found for query ", e.getMessage());
}
}

/**
* Create a new post. Because the OpenID field is
* required, we cannot create a new post without authenticating it.
*
* @throws Exception
*/
public void testCreateNewPost() throws Exception {
IFile sitemap = beginAtSitemapThenPage("Create New Post");
assertNoProblem();

// edit the title
{
String target = getLabelIDForText("title");
assertLabeledFieldEquals(target, "");
setLabeledFormElementField(target, "Created Title");
}

// we don't set the URL
assertLabelTextNotPresent("Error: Could not save instance successfully.");

// we try clicking on the button
clickButtonWithText("Save");
assertLabelTextPresent("Error: Could not save instance successfully.");

// and we can't view the news page
viewNewsPageUnsuccessfully(sitemap);

}

/**
* We try create a new post now, but provide a valid OpenID
* url; but we don't try and authenticate. It should still fail.
*
* @throws Exception
*/
public void testCreateNewPostWithOpenID() throws Exception {
IFile sitemap = beginAtSitemapThenPage("Create New Post");
assertNoProblem();

// it is not present
assertLabelTextNotPresent("Error: Could not save instance successfully.");

// edit the title
{
String target = getLabelIDForText("title");
assertLabeledFieldEquals(target, "");
setLabeledFormElementField(target, "Created Title");
}

// set the URL
{
String target = getLabelIDForText("author");
assertLabeledFieldEquals(target, "");
setLabeledFormElementField(target, OPENID_PAGE_SERVER);
}

// we try clicking on the button
clickButtonWithText("Save");

// there should be a problem
assertProblem();

// the warning has now shown
assertLabelTextExactlyPresent("Error: Could not save instance successfully.");

// and we can't view the news page
viewNewsPageUnsuccessfully(sitemap);

// TODO: add a test case to check that the Warning label disappears
// when we authenticate successfully
}

/**
* Check that the page we are looking for actually contains the <link> we are looking for.
*
* @throws Exception
*/
public void testPageServerHasLink() throws Exception {
beginAt(OPENID_PAGE_SERVER);
String source = getPageSource();
assertContains("link rel=\"openid.server\" href=\"" + OPENID_PAGE_SERVER + "\"", source);
}

/**
* Check that the page we are looking for actually contains the <link> we are looking for.
*
* @throws Exception
*/
public void testPageDelegateHasLink() throws Exception {
beginAt(OPENID_PAGE_DELEGATE);
String source = getPageSource();
assertContains("link rel=\"openid.server\" href=\"" + OPENID_PAGE_SERVER + "\"", source);
assertContains("link rel=\"openid.delegate\" href=\"" + OPENID_PAGE_DELEGATE + "\"", source);
}

/**
* Check that the page we are looking for actually contains the <link> we are looking for.
*
* @throws Exception
*/
public void testPageServerPassHasLink() throws Exception {
beginAt(OPENID_PAGE_SERVER_PASS);
String source = getPageSource();
assertContains("link rel=\"openid.server\" href=\"" + OPENID_PAGE_SERVER_PASS + "\"", source);
}

/**
* Check that the page we are looking for actually contains the <link> we are looking for.
*
* @throws Exception
*/
public void testPageDelegatePassHasLink() throws Exception {
beginAt(OPENID_PAGE_DELEGATE_PASS);
String source = getPageSource();
assertContains("link rel=\"openid.server\" href=\"" + OPENID_PAGE_SERVER_PASS + "\"", source);
assertContains("link rel=\"openid.delegate\" href=\"" + OPENID_PAGE_DELEGATE_PASS + "\"", source);
}

/**
* Provide the correct OpenID URL, and actually go through authentication.
* Should allow instant login, and then we can actually save the
* post and view it.
*
* @throws Exception
*/
public void testWithServer() throws Exception {
doSuccessfulOpenID("testWithServer", OPENID_PAGE_SERVER, false);
}

/**
* This will use a delegate, but we still don't need to provide
* anything as the user-agent.
*
* @throws Exception
*/
public void testWithDelegate() throws Exception {
doSuccessfulOpenID("testWithDelegate", OPENID_PAGE_DELEGATE, false);
}

/**
* We need to provide a password.
*
* @throws Exception
*/
public void testWithServerPassword() throws Exception {
doSuccessfulOpenID("testWithServerPassword", OPENID_PAGE_SERVER_PASS, true);
}

/**
* We need to provide a password.
*
* @throws Exception
*/
public void testWithDelegatePassword() throws Exception {
doSuccessfulOpenID("testWithDelegatePassword", OPENID_PAGE_DELEGATE_PASS, true);
}

/**
* Try {@link #OPENID_PAGE_DELEGATE_PASS}, but provide the wrong password,
* so we have to login again.
*
* @throws Exception
*/
public void testWithIncorrectPassword() throws Exception {
IFile sitemap = beginAtSitemapThenPage("Create New Post");
assertNoProblem();

// edit the title
{
String target = getLabelIDForText("title");
assertLabeledFieldEquals(target, "");
setLabeledFormElementField(target, "Created Title");
}

// set the URL
{
String target = getLabelIDForText("author");
assertLabeledFieldEquals(target, "");
setLabeledFormElementField(target, OPENID_PAGE_DELEGATE_PASS);
}

// there should be a button "Authenticate"
clickButtonWithText("Authenticate");

// we are now on another page, and need to provide a password
setTextField("password", "wrong"); // the wrong password!
submit();

// we are still on the same page
setTextField("password", "test"); // set it right
submit();

// carry on as normal

// we should be directed back to our own page
{
String target = getLabelIDForText("title");
assertLabeledFieldEquals(target, "Created Title");
}
{
String target = getLabelIDForText("author");
assertLabeledFieldEquals(target, OPENID_PAGE_DELEGATE_PASS);
}

// we try clicking on the button
clickButtonWithText("Save");

// there should NOT be a problem
assertNoProblem();

// now if we try and view the news page, we will succeed
viewNewsPageSuccessfully(sitemap, "Created Title", OPENID_PAGE_DELEGATE_PASS);
}

/**
* Try and use an invalid URL.
*
*/
public void testUseInvalidURL() throws Exception {

IFile sitemap = beginAtSitemapThenPage("Create New Post");
assertNoProblem();

// edit the title
{
String target = getLabelIDForText("title");
assertLabeledFieldEquals(target, "");
setLabeledFormElementField(target, "Created Title");
}

// set the URL (invalid)
String invalid = "invalid";
{
String target = getLabelIDForText("author");
assertLabeledFieldEquals(target, "");
setLabeledFormElementField(target, invalid);
}

// there should be a button "Authenticate"
assertTextNotPresent("Could not load authentication from invalid");
clickButtonWithText("Authenticate");

// but we should get an error
assertTextPresent("Could not load authentication from invalid");

// and we can't view the news page
viewNewsPageUnsuccessfully(sitemap);

}

/**
* Actually does the authentication, etc.
*
* @param title the news post title to use
* @param openid the OpenID URL to use
* @param needPass if true, we need to provide a password to the
* openID server (assumed above)
* @throws Exception
*/
protected void doSuccessfulOpenID(String title, String openid, boolean needPass) throws Exception {

IFile sitemap = beginAtSitemapThenPage("Create New Post");
assertNoProblem();

// edit the title
{
String target = getLabelIDForText("title");
assertLabeledFieldEquals(target, "");
setLabeledFormElementField(target, "Created Title");
}

// set the URL
{
String target = getLabelIDForText("author");
assertLabeledFieldEquals(target, "");
setLabeledFormElementField(target, openid);
}

// there should be a button "Authenticate"
clickButtonWithText("Authenticate");

if (needPass) {
// we are now on another page, and need to provide a password
System.out.println(getPageSource());
setTextField("password", "test");
submit();
}

// we should be directed back to our own page
{
String target = getLabelIDForText("title");
assertLabeledFieldEquals(target, "Created Title");
}
{
String target = getLabelIDForText("author");
assertLabeledFieldEquals(target, openid);
}

// we try clicking on the button
clickButtonWithText("Save");

// there should NOT be a problem
assertNoProblem();

// now if we try and view the news page, we will succeed
viewNewsPageSuccessfully(sitemap, "Created Title", openid);

}

/**
* Try and view the news page successfully, with the given
* expected title, and openID server URL.
*
* @param sitemap
* @param title
* @param openidPageServer
* @throws Exception
*/
protected void viewNewsPageSuccessfully(IFile sitemap, String title,
String openidPageServer) throws Exception {

// TODO there is some weird synchrony issues going on. this resolves
// it temporarily. check with HtmlUnit 2.8 and see if the issue is fixed.
Thread.sleep(1000);

gotoSitemapThenPage(sitemap, "View Posts");
assertNoProblem();

// check the content
assertLabelTextExactlyPresent(title);

// and the URL is also included
assertLabelTextExactlyPresent(openidPageServer);

}

/**
* Try and view the news page unsuccessfully.
*
* @param sitemap
* @throws Exception
*/
protected void viewNewsPageUnsuccessfully(IFile sitemap) throws Exception {

try {
gotoSitemapThenPage(sitemap, "View Posts");
fail("Should have failed");
} catch (PhpRuntimeExceptionException e) {
assertContains("No results found for query ", e.getMessage());
}

}

}

Change log

r2349 by soundasleep on Jun 17, 2010   Diff
using Thread.sleep to resolve the test
cases failing only in HtmlUnit for
OpenIDAsAuthor
Go to: 
Project members, sign in to write a code review

Older revisions

r2020 by soundasleep on Apr 25, 2010   Diff
OpenID can now handle if an
invalid/incorrect URL is used
updating codegen test case
r2019 by soundasleep on Apr 25, 2010   Diff
implementing 'can save?'
DomainObjectInstance primitive
operation
has_domain_instance() methods will no
longer crash if they cannot be cast
...
r2017 by soundasleep on Apr 25, 2010   Diff
adding support for calling Conditions
from within an Operation (using a
ConditionEdge to a DecisionNode)
DecisionNode is now a
ConditionEdgeDestination
All revisions of this file

File info

Size: 12289 bytes, 427 lines
Powered by Google Project Hosting