Diffstat (limited to 'frontend/gamma/tests/tests/Clipperz/PM/Connection.test.js') (more/less context) (ignore whitespace changes)
-rw-r--r-- | frontend/gamma/tests/tests/Clipperz/PM/Connection.test.js | 255 |
1 files changed, 255 insertions, 0 deletions
diff --git a/frontend/gamma/tests/tests/Clipperz/PM/Connection.test.js b/frontend/gamma/tests/tests/Clipperz/PM/Connection.test.js new file mode 100644 index 0000000..e4d0d15 --- a/dev/null +++ b/frontend/gamma/tests/tests/Clipperz/PM/Connection.test.js | |||
@@ -0,0 +1,255 @@ | |||
1 | /* | ||
2 | |||
3 | Copyright 2008-2011 Clipperz Srl | ||
4 | |||
5 | This file is part of Clipperz's Javascript Crypto Library. | ||
6 | Javascript Crypto Library provides web developers with an extensive | ||
7 | and efficient set of cryptographic functions. The library aims to | ||
8 | obtain maximum execution speed while preserving modularity and | ||
9 | reusability. | ||
10 | For further information about its features and functionalities please | ||
11 | refer to http://www.clipperz.com | ||
12 | |||
13 | * Javascript Crypto Library is free software: you can redistribute | ||
14 | it and/or modify it under the terms of the GNU Affero General Public | ||
15 | License as published by the Free Software Foundation, either version | ||
16 | 3 of the License, or (at your option) any later version. | ||
17 | |||
18 | * Javascript Crypto Library is distributed in the hope that it will | ||
19 | be useful, but WITHOUT ANY WARRANTY; without even the implied | ||
20 | warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
21 | See the GNU Affero General Public License for more details. | ||
22 | |||
23 | * You should have received a copy of the GNU Affero General Public | ||
24 | License along with Javascript Crypto Library. If not, see | ||
25 | <http://www.gnu.org/licenses/>. | ||
26 | |||
27 | */ | ||
28 | |||
29 | Clipperz.Crypto.PRNG.defaultRandomGenerator().fastEntropyAccumulationForTestingPurpose(); | ||
30 | |||
31 | var tests = { | ||
32 | |||
33 | //------------------------------------------------------------------------- | ||
34 | |||
35 | 'simple_tests': function () { | ||
36 | vardeferredResult; | ||
37 | |||
38 | deferredResult = new Clipperz.Async.Deferred("simple_tests", {trace:false}); | ||
39 | deferredResult.addCallback(function() { | ||
40 | var connection; | ||
41 | |||
42 | SimpleTest.is(Clipperz.PM.Connection.communicationProtocol.versions['current'], Clipperz.PM.Connection.SRP['1.1'], "the current connection is 1.1"); | ||
43 | |||
44 | connection = new Clipperz.PM.Connection.communicationProtocol.versions['current'](); | ||
45 | SimpleTest.ok(connection != null, "can create a connection with the 'current' communication protocol"); | ||
46 | |||
47 | SimpleTest.is(connection.proxy(), Clipperz.PM.Proxy.defaultProxy, "the connection uses the defaultProxy if no proxy is specified on the constructor"); | ||
48 | }); | ||
49 | |||
50 | deferredResult.callback(); | ||
51 | |||
52 | return deferredResult; | ||
53 | }, | ||
54 | |||
55 | //------------------------------------------------------------------------- | ||
56 | |||
57 | 'simpleProxy_tests': function () { | ||
58 | vardeferredResult; | ||
59 | |||
60 | deferredResult = new Clipperz.Async.Deferred("simple_tests", {trace:false}); | ||
61 | deferredResult.addCallback(function() { | ||
62 | var connection; | ||
63 | var proxy; | ||
64 | |||
65 | proxy = new Clipperz.PM.Proxy(); | ||
66 | connection = new Clipperz.PM.Connection.communicationProtocol.versions['current']({proxy:proxy}); | ||
67 | SimpleTest.is(connection.proxy(), proxy, "the connection uses the specified proxy, when present"); | ||
68 | }); | ||
69 | |||
70 | deferredResult.callback(); | ||
71 | |||
72 | return deferredResult; | ||
73 | }, | ||
74 | |||
75 | //------------------------------------------------------------------------- | ||
76 | |||
77 | 'login_test': function () { | ||
78 | var deferredResult; | ||
79 | var connection; | ||
80 | var proxy; | ||
81 | |||
82 | proxy = new Clipperz.PM.Proxy.Test({shouldPayTolls:false, shouldCheckExpectedRequests:true}); | ||
83 | connection = new Clipperz.PM.Connection.communicationProtocol.versions['current']({ | ||
84 | proxy: proxy, | ||
85 | getCredentialsFunction: function() { return {username:'joe', password:'clipperz'}; } | ||
86 | }); | ||
87 | |||
88 | deferredResult = new Clipperz.Async.Deferred("login_tests", {trace:false}); | ||
89 | deferredResult.addMethod(proxy.dataStore(), 'setupWithEncryptedData', testData['joe_clipperz_offline_copy_data']); | ||
90 | deferredResult.addCallback(function() { | ||
91 | proxy.expectedRequests().unshift({ | ||
92 | name: "First handshake step", | ||
93 | functionName: 'handshake', | ||
94 | parameters: { | ||
95 | parameters: { | ||
96 | message: MochiKit.Base.partial(MochiKit.Base.operator.eq, "connect"), | ||
97 | version: MochiKit.Base.partial(MochiKit.Base.operator.eq, "0.2"), | ||
98 | parameters: { | ||
99 | C: MochiKit.Base.partial(MochiKit.Base.operator.eq, "f527cdd90d0d47f8524b4e165398ad1455eba515d04abd101d1e93b3c6ae0674"), | ||
100 | A: MochiKit.Base.operator.truth | ||
101 | } | ||
102 | } | ||
103 | } | ||
104 | }); | ||
105 | }); | ||
106 | deferredResult.addCallback(function() { | ||
107 | proxy.expectedRequests().unshift({ | ||
108 | name: "Second handshake step", | ||
109 | functionName: 'handshake', | ||
110 | parameters: { | ||
111 | parameters: { | ||
112 | message: MochiKit.Base.partial(MochiKit.Base.operator.eq, "credentialCheck"), | ||
113 | version: MochiKit.Base.partial(MochiKit.Base.operator.eq, "0.2"), | ||
114 | parameters: { | ||
115 | M1: MochiKit.Base.operator.truth | ||
116 | } | ||
117 | } | ||
118 | } | ||
119 | }); | ||
120 | }); | ||
121 | deferredResult.addMethod(connection, 'login'/*, 'joe', 'clipperz'*/); | ||
122 | deferredResult.addCallback(function(aResult) { | ||
123 | SimpleTest.is(aResult.result, 'done', "successfully logged in"); | ||
124 | }) | ||
125 | deferredResult.addErrback(SimpleTest.ok, false, "the login procedure should succeed, and NOT going through this code path"); | ||
126 | deferredResult.callback(); | ||
127 | |||
128 | return deferredResult; | ||
129 | }, | ||
130 | |||
131 | //------------------------------------------------------------------------- | ||
132 | |||
133 | 'login_with_toll_test': function () { | ||
134 | var deferredResult; | ||
135 | var connection; | ||
136 | var proxy; | ||
137 | |||
138 | proxy = new Clipperz.PM.Proxy.Test({shouldPayTolls:true, shouldCheckExpectedRequests:true}); | ||
139 | connection = new Clipperz.PM.Connection.communicationProtocol.versions['current']({ | ||
140 | proxy:proxy, | ||
141 | getCredentialsFunction: function() { return {username:'joe', password:'clipperz'}; } | ||
142 | }); | ||
143 | |||
144 | deferredResult = new Clipperz.Async.Deferred("login_with_toll_test", {trace:false}); | ||
145 | deferredResult.addMethod(proxy.dataStore(), 'setupWithEncryptedData', testData['joe_clipperz_offline_copy_data']); | ||
146 | deferredResult.addCallback(function() { | ||
147 | proxy.expectedRequests().unshift({ | ||
148 | name: "knock step", | ||
149 | functionName: 'knock', | ||
150 | parameters: { | ||
151 | requestType: MochiKit.Base.partial(MochiKit.Base.operator.eq, "CONNECT") | ||
152 | } | ||
153 | }); | ||
154 | }); | ||
155 | deferredResult.addCallback(function() { | ||
156 | proxy.expectedRequests().unshift({ | ||
157 | name: "First handshake step", | ||
158 | functionName: 'handshake', | ||
159 | parameters: { | ||
160 | parameters: { | ||
161 | message: MochiKit.Base.partial(MochiKit.Base.operator.eq, "connect"), | ||
162 | version: MochiKit.Base.partial(MochiKit.Base.operator.eq, "0.2"), | ||
163 | parameters: { | ||
164 | C: MochiKit.Base.partial(MochiKit.Base.operator.eq, "f527cdd90d0d47f8524b4e165398ad1455eba515d04abd101d1e93b3c6ae0674"), | ||
165 | A: MochiKit.Base.operator.truth | ||
166 | } | ||
167 | }, | ||
168 | toll: { | ||
169 | targetValue: MochiKit.Base.operator.truth, | ||
170 | toll: MochiKit.Base.operator.truth | ||
171 | } | ||
172 | } | ||
173 | }); | ||
174 | }); | ||
175 | deferredResult.addCallback(function() { | ||
176 | proxy.expectedRequests().unshift({ | ||
177 | name: "Second handshake step", | ||
178 | functionName: 'handshake', | ||
179 | parameters: { | ||
180 | parameters: { | ||
181 | message: MochiKit.Base.partial(MochiKit.Base.operator.eq, "credentialCheck"), | ||
182 | version: MochiKit.Base.partial(MochiKit.Base.operator.eq, "0.2"), | ||
183 | parameters: { | ||
184 | M1: MochiKit.Base.operator.truth | ||
185 | } | ||
186 | }, | ||
187 | toll: { | ||
188 | targetValue: MochiKit.Base.operator.truth, | ||
189 | toll: MochiKit.Base.operator.truth | ||
190 | } | ||
191 | } | ||
192 | }); | ||
193 | }); | ||
194 | deferredResult.addMethod(connection, 'login'/*, 'joe', 'clipperz'*/); | ||
195 | deferredResult.addCallback(function(aResult) { | ||
196 | SimpleTest.is(aResult.result, 'done', "successfully logged in"); | ||
197 | }) | ||
198 | deferredResult.callback(); | ||
199 | |||
200 | return deferredResult; | ||
201 | }, | ||
202 | |||
203 | //------------------------------------------------------------------------- | ||
204 | |||
205 | 'getUserDetails_test': function () { | ||
206 | var deferredResult; | ||
207 | var connection; | ||
208 | var proxy; | ||
209 | |||
210 | proxy = new Clipperz.PM.Proxy.Test({shouldPayTolls:true, shouldCheckExpectedRequests:false}); | ||
211 | connection = new Clipperz.PM.Connection.communicationProtocol.versions['current']({ | ||
212 | proxy:proxy, | ||
213 | getCredentialsFunction: function() { return {username:'joe', password:'clipperz'}; } | ||
214 | }); | ||
215 | |||
216 | deferredResult = new Clipperz.Async.Deferred("getUserDetails_test", {trace:false}); | ||
217 | deferredResult.addMethod(proxy.dataStore(), 'setupWithEncryptedData', testData['joe_clipperz_offline_copy_data']); | ||
218 | deferredResult.addMethod(connection, 'login'/*, 'joe', 'clipperz'*/); | ||
219 | deferredResult.addCallback(function(aResult) { | ||
220 | SimpleTest.is(aResult.result, 'done', "successfully logged in"); | ||
221 | }); | ||
222 | deferredResult.addMethod(proxy, 'setShouldCheckExpectedRequests', [ | ||
223 | { | ||
224 | name: "Get user details", | ||
225 | functionName: 'message', | ||
226 | parameters: { | ||
227 | parameters: { | ||
228 | message: MochiKit.Base.partial(MochiKit.Base.operator.eq, "getUserDetails"), | ||
229 | srpSharedSecret: MochiKit.Base.operator.truth | ||
230 | }, | ||
231 | toll: { | ||
232 | targetValue: MochiKit.Base.operator.truth, | ||
233 | toll: MochiKit.Base.operator.truth | ||
234 | } | ||
235 | } | ||
236 | } | ||
237 | ]); | ||
238 | deferredResult.addMethod(connection, 'message', 'getUserDetails'); | ||
239 | deferredResult.addCallback(function(aResult) { | ||
240 | SimpleTest.ok(aResult['header'] != null, "got user details - header"); | ||
241 | SimpleTest.ok(aResult['statistics'] != null, "got user details - statistics"); | ||
242 | SimpleTest.ok(aResult['version'] == '0.3', "got user details - version"); | ||
243 | }); | ||
244 | deferredResult.callback(); | ||
245 | |||
246 | return deferredResult; | ||
247 | }, | ||
248 | |||
249 | //------------------------------------------------------------------------- | ||
250 | 'syntaxFix': MochiKit.Base.noop | ||
251 | }; | ||
252 | |||
253 | //############################################################################# | ||
254 | |||
255 | SimpleTest.runDeferredTests("Clipperz.PM.Connection", tests, {trace:false}); | ||