@@ -145,8 +145,20 @@ describe("Client _finishAuthentication", function () {
145
145
} ) ;
146
146
} ) ;
147
147
148
+ it ( "should return error when _renewSecret fails" , function ( done ) {
149
+ sinon . stub ( client . http , "request" ) . yields ( null , { success : true , dvsRegister : { test : 1 } } ) ;
150
+ var renewSecretStub = sinon . stub ( client , "_renewSecret" ) . yields ( new Error ( "Renew secret error" ) ) ;
151
+
152
+ client . _finishAuthentication ( "[email protected] " , 1234 , [ "dvs-auth" ] , "authOTT" , function ( err ) {
153
+ expect ( err ) . to . exist ;
154
+ expect ( err . message ) . to . equal ( "Renew secret error" ) ;
155
+ done ( ) ;
156
+ } ) ;
157
+ } ) ;
158
+
148
159
afterEach ( function ( ) {
149
160
client . http . request . restore && client . http . request . restore ( ) ;
161
+ client . _renewSecret . restore && client . _renewSecret . restore ( ) ;
150
162
client . _authentication . restore && client . _authentication . restore ( ) ;
151
163
} ) ;
152
164
} ) ;
@@ -159,21 +171,21 @@ describe("Client _renewSecret", function () {
159
171
} ) ;
160
172
161
173
it ( "should renew the identity secret" , function ( done ) {
162
- var getWaMSecret1Stub = sinon . stub ( client , "_getWaMSecret1 " ) . yields ( null , true ) ;
163
- var getSecret2Stub = sinon . stub ( client , "_getSecret2 " ) . yields ( null , true ) ;
174
+ var createMPinIDStub = sinon . stub ( client , "_createMPinID " ) . yields ( null , { pinLength : 4 , projectId : "projectID" , secretUrls : [ "http://example.com/secret1" , "http://example.com/secret2" ] } ) ;
175
+ var getSecretStub = sinon . stub ( client , "_getSecret " ) . yields ( null , true ) ;
164
176
var createIdentityStub = sinon . stub ( client , "_createIdentity" ) . yields ( null , true ) ;
165
177
166
178
client . _renewSecret ( "[email protected] " , "1234" , { token :
"token" , curve :
"BN254CX" } , function ( err ) {
167
179
expect ( err ) . to . be . null ;
168
- expect ( getWaMSecret1Stub . calledOnce ) . to . be . true ;
169
- expect ( getSecret2Stub . calledOnce ) . to . be . true ;
180
+ expect ( createMPinIDStub . calledOnce ) . to . be . true ;
181
+ expect ( getSecretStub . calledTwice ) . to . be . true ;
170
182
expect ( createIdentityStub . calledOnce ) . to . be . true ;
171
183
done ( ) ;
172
184
} ) ;
173
185
} ) ;
174
186
175
- it ( "should call error callback on _getWaMSecret1 failure" , function ( done ) {
176
- sinon . stub ( client , "_getWaMSecret1 " ) . yields ( new Error ( "Request error" ) ) ;
187
+ it ( "should call error callback on _createMPinID failure" , function ( done ) {
188
+ sinon . stub ( client , "_createMPinID " ) . yields ( new Error ( "Request error" ) ) ;
177
189
178
190
client . _renewSecret ( "[email protected] " , "1234" , { token :
"token" , curve :
"BN254CX" } , function ( err ) {
179
191
expect ( err ) . to . exist ;
@@ -182,9 +194,9 @@ describe("Client _renewSecret", function () {
182
194
} ) ;
183
195
} ) ;
184
196
185
- it ( "should call error callback on _getSecret2 failure" , function ( done ) {
186
- sinon . stub ( client , "_getWaMSecret1 " ) . yields ( null , true ) ;
187
- sinon . stub ( client , "_getSecret2 " ) . yields ( new Error ( "Request error" ) , null ) ;
197
+ it ( "should call error callback on first _getSecret failure" , function ( done ) {
198
+ sinon . stub ( client , "_createMPinID " ) . yields ( null , { pinLength : 4 , projectId : "projectID" , secretUrls : [ "http://example.com/secret1" , "http://example.com/secret2" ] } ) ;
199
+ sinon . stub ( client , "_getSecret " ) . yields ( new Error ( "Request error" ) ) ;
188
200
189
201
client . _renewSecret ( "[email protected] " , "1234" , { token :
"token" , curve :
"BN254CX" } , function ( err ) {
190
202
expect ( err ) . to . exist ;
@@ -193,10 +205,11 @@ describe("Client _renewSecret", function () {
193
205
} ) ;
194
206
} ) ;
195
207
196
- it ( "should call error callback on createIdentity error" , function ( done ) {
197
- sinon . stub ( client , "_getWaMSecret1" ) . yields ( null , true ) ;
198
- sinon . stub ( client , "_getSecret2" ) . yields ( null , true ) ;
199
- sinon . stub ( client , "_createIdentity" ) . yields ( new Error ( "Request error" ) ) ;
208
+ it ( "should call error callback on second _getSecret failure" , function ( done ) {
209
+ sinon . stub ( client , "_createMPinID" ) . yields ( null , { pinLength : 4 , projectId : "projectID" , secretUrls : [ "http://example.com/secret1" , "http://example.com/secret2" ] } ) ;
210
+ var getSecretStub = sinon . stub ( client , "_getSecret" ) ;
211
+ getSecretStub . onFirstCall ( ) . yields ( null ) ;
212
+ getSecretStub . onSecondCall ( ) . yields ( new Error ( "Request error" ) ) ;
200
213
201
214
client . _renewSecret ( "[email protected] " , "1234" , { token :
"token" , curve :
"BN254CX" } , function ( err ) {
202
215
expect ( err ) . to . exist ;
@@ -205,67 +218,23 @@ describe("Client _renewSecret", function () {
205
218
} ) ;
206
219
} ) ;
207
220
208
- afterEach ( function ( ) {
209
- client . _getWaMSecret1 . restore && client . _getWaMSecret1 . restore ( ) ;
210
- client . _getSecret2 . restore && client . _getSecret2 . restore ( ) ;
211
- client . _createIdentity . restore && client . _createIdentity . restore ( ) ;
212
- } )
213
- } ) ;
214
-
215
- describe ( "Client _getWaMSecret1" , function ( ) {
216
- var client ;
217
-
218
- before ( function ( ) {
219
- client = new Client ( testData . init ( ) ) ;
220
- } ) ;
221
-
222
- it ( "should call error callback when request fails" , function ( done ) {
223
- sinon . stub ( client . http , "request" ) . yields ( { } , null ) ;
221
+ it ( "should call error callback on createIdentity error" , function ( done ) {
222
+ sinon . stub ( client , "_createMPinID" ) . yields ( null , { pinLength : 4 , projectId : "projectID" , secretUrls : [ "http://example.com/secret1" , "http://example.com/secret2" ] } ) ;
223
+ sinon . stub ( client , "_getSecret" ) . yields ( null , true ) ;
224
+ sinon . stub ( client , "_createIdentity" ) . yields ( new Error ( "Request error" ) ) ;
224
225
225
- client . _getWaMSecret1 ( { publicKey : "public" } , "dvsRegisterToken" , function ( err , data ) {
226
+ client . _renewSecret ( "[email protected] " , "1234" , { token :
"token" , curve : "BN254CX" } , function ( err ) {
226
227
expect ( err ) . to . exist ;
227
- done ( ) ;
228
- } ) ;
229
- } ) ;
230
-
231
- it ( "should call success callback with data" , function ( done ) {
232
- sinon . stub ( client . http , "request" ) . yields ( null , { success : true } ) ;
233
-
234
- client . _getWaMSecret1 ( { publicKey : "public" } , "dvsRegisterToken" , function ( err , cs1Data ) {
235
- expect ( err ) . to . be . null ;
236
- expect ( cs1Data ) . to . exist ;
237
- expect ( cs1Data ) . to . have . property ( "success" ) ;
238
- expect ( cs1Data . success ) . to . be . true ;
239
- done ( ) ;
240
- } ) ;
241
- } ) ;
242
-
243
- it ( "should make request to dvs register endpoint" , function ( done ) {
244
- var requestStub = sinon . stub ( client . http , "request" ) . yields ( null , { success : true } ) ;
245
-
246
- client . _getWaMSecret1 ( { publicKey : "public" } , "dvsRegisterToken" , function ( err ) {
247
- expect ( err ) . to . be . null ;
248
- expect ( requestStub . calledOnce ) . to . be . true ;
249
- expect ( requestStub . firstCall . args [ 0 ] . url ) . to . equal ( "http://server.com/rps/v2/dvsregister" ) ;
250
- done ( ) ;
251
- } ) ;
252
- } ) ;
253
-
254
- it ( "should make request with public key" , function ( done ) {
255
- var requestStub = sinon . stub ( client . http , "request" ) . yields ( null , { success : true } ) ;
256
- sinon . stub ( client , "_getDeviceName" ) . returns ( "device" ) ;
257
-
258
- client . _getWaMSecret1 ( { publicKey : "public" } , "dvsRegisterToken" , function ( err ) {
259
- expect ( err ) . to . be . null ;
260
- expect ( requestStub . calledOnce ) . to . be . true ;
261
- expect ( requestStub . firstCall . args [ 0 ] . data ) . to . deep . equal ( { publicKey : "public" , dvsRegisterToken : "dvsRegisterToken" } ) ;
228
+ expect ( err . message ) . to . equal ( "Request error" ) ;
262
229
done ( ) ;
263
230
} ) ;
264
231
} ) ;
265
232
266
233
afterEach ( function ( ) {
267
- client . http . request . restore && client . http . request . restore ( ) ;
268
- } ) ;
234
+ client . _createMPinID . restore && client . _createMPinID . restore ( ) ;
235
+ client . _getSecret . restore && client . _getSecret . restore ( ) ;
236
+ client . _createIdentity . restore && client . _createIdentity . restore ( ) ;
237
+ } )
269
238
} ) ;
270
239
271
240
describe ( "Client _authentication" , function ( ) {
0 commit comments