|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 /** |
|
5 * By their nature, these tests duplicate some of the functionality of |
|
6 * other tests for Identity, RelyingParty, and IdentityProvider. |
|
7 * |
|
8 * In particular, "identity-auth-complete" and |
|
9 * "identity-login-state-changed" are tested in test_authentication.js |
|
10 */ |
|
11 |
|
12 "use strict"; |
|
13 |
|
14 XPCOMUtils.defineLazyModuleGetter(this, "IDService", |
|
15 "resource://gre/modules/identity/Identity.jsm", |
|
16 "IdentityService"); |
|
17 |
|
18 function test_smoke() { |
|
19 do_check_neq(IDService, null); |
|
20 run_next_test(); |
|
21 } |
|
22 |
|
23 function test_identity_request() { |
|
24 // In response to navigator.id.request(), initiate a login with user |
|
25 // interaction by notifying observers of 'identity-request' |
|
26 |
|
27 do_test_pending(); |
|
28 |
|
29 IDService.reset(); |
|
30 |
|
31 let id = "landru@mockmyid.com"; |
|
32 setup_test_identity(id, TEST_CERT, function() { |
|
33 // deliberately adding a trailing final slash on the domain |
|
34 // to test path composition |
|
35 let mockedDoc = mock_doc(null, "http://jed.gov/", function() {}); |
|
36 |
|
37 // by calling watch() we create an rp flow. |
|
38 IDService.RP.watch(mockedDoc); |
|
39 |
|
40 // register the request UX observer |
|
41 makeObserver("identity-request", function (aSubject, aTopic, aData) { |
|
42 do_check_eq(aTopic, "identity-request"); |
|
43 do_check_eq(aData, null); |
|
44 |
|
45 // check that all the URLs are properly resolved |
|
46 let subj = aSubject.wrappedJSObject; |
|
47 do_check_eq(subj.privacyPolicy, "http://jed.gov/pp.html"); |
|
48 do_check_eq(subj.termsOfService, "http://jed.gov/tos.html"); |
|
49 |
|
50 do_test_finished(); |
|
51 run_next_test(); |
|
52 }); |
|
53 |
|
54 let requestOptions = { |
|
55 privacyPolicy: "/pp.html", |
|
56 termsOfService: "/tos.html" |
|
57 }; |
|
58 IDService.RP.request(mockedDoc.id, requestOptions); |
|
59 }); |
|
60 |
|
61 } |
|
62 |
|
63 function test_identity_auth() { |
|
64 // see test_authentication.js for "identity-auth-complete" |
|
65 // and "identity-login-state-changed" |
|
66 |
|
67 do_test_pending(); |
|
68 let _provId = "bogus"; |
|
69 |
|
70 // Simulate what would be returned by IDService._fetchWellKnownFile |
|
71 // for a given domain. |
|
72 let idpParams = { |
|
73 domain: "myfavoriteflan.com", |
|
74 idpParams: { |
|
75 authentication: "/foo/authenticate.html", |
|
76 provisioning: "/foo/provision.html" |
|
77 } |
|
78 }; |
|
79 |
|
80 // Create an RP flow |
|
81 let mockedDoc = mock_doc(null, TEST_URL, function(action, params) {}); |
|
82 IDService.RP.watch(mockedDoc); |
|
83 |
|
84 // The identity-auth notification is sent up to the UX from the |
|
85 // _doAuthentication function. Be ready to receive it and call |
|
86 // beginAuthentication |
|
87 makeObserver("identity-auth", function (aSubject, aTopic, aData) { |
|
88 do_check_neq(aSubject, null); |
|
89 do_check_eq(aTopic, "identity-auth"); |
|
90 do_check_eq(aData, "https://myfavoriteflan.com/foo/authenticate.html"); |
|
91 |
|
92 do_check_eq(aSubject.wrappedJSObject.provId, _provId); |
|
93 do_test_finished(); |
|
94 run_next_test(); |
|
95 }); |
|
96 |
|
97 // Even though our provisioning flow id is bogus, IdentityProvider |
|
98 // won't look at it until farther along in the authentication |
|
99 // process. So this test can pass with a fake provId. |
|
100 IDService.IDP._doAuthentication(_provId, idpParams); |
|
101 } |
|
102 |
|
103 let TESTS = [ |
|
104 test_smoke, |
|
105 test_identity_request, |
|
106 test_identity_auth, |
|
107 ]; |
|
108 |
|
109 |
|
110 TESTS.forEach(add_test); |
|
111 |
|
112 function run_test() { |
|
113 run_next_test(); |
|
114 } |