1
1
var OAuth = require ( "../src/authDataManager/OAuth1Client" ) ;
2
2
var request = require ( 'request' ) ;
3
+ var Config = require ( "../src/Config" ) ;
3
4
4
5
describe ( 'OAuth' , function ( ) {
5
6
@@ -28,7 +29,7 @@ describe('OAuth', function() {
28
29
29
30
it ( "Should properly generate request signature" , ( done ) => {
30
31
var request = {
31
- host : "dummy.com" ,
32
+ host : "dummy.com" ,
32
33
path : "path"
33
34
} ;
34
35
@@ -48,7 +49,7 @@ describe('OAuth', function() {
48
49
49
50
it ( "Should properly build request" , ( done ) => {
50
51
var options = {
51
- host : "dummy.com" ,
52
+ host : "dummy.com" ,
52
53
consumer_key : "hello" ,
53
54
consumer_secret : "world" ,
54
55
auth_token : "token" ,
@@ -86,7 +87,7 @@ describe('OAuth', function() {
86
87
87
88
it ( "Should fail a GET request" , ( done ) => {
88
89
var options = {
89
- host : "api.twitter.com" ,
90
+ host : "api.twitter.com" ,
90
91
consumer_key : "XXXXXXXXXXXXXXXXXXXXXXXXX" ,
91
92
consumer_secret : "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" ,
92
93
} ;
@@ -100,7 +101,7 @@ describe('OAuth', function() {
100
101
101
102
it ( "Should fail a POST request" , ( done ) => {
102
103
var options = {
103
- host : "api.twitter.com" ,
104
+ host : "api.twitter.com" ,
104
105
consumer_key : "XXXXXXXXXXXXXXXXXXXXXXXXX" ,
105
106
consumer_secret : "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" ,
106
107
} ;
@@ -117,7 +118,7 @@ describe('OAuth', function() {
117
118
118
119
it ( "Should fail a request" , ( done ) => {
119
120
var options = {
120
- host : "localhost" ,
121
+ host : "localhost" ,
121
122
consumer_key : "XXXXXXXXXXXXXXXXXXXXXXXXX" ,
122
123
consumer_secret : "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" ,
123
124
} ;
@@ -141,8 +142,8 @@ describe('OAuth', function() {
141
142
var provider = require ( "../src/authDataManager/" + providerName ) ;
142
143
jequal ( typeof provider . validateAuthData , "function" ) ;
143
144
jequal ( typeof provider . validateAppId , "function" ) ;
144
- jequal ( provider . validateAuthData ( { } , { } ) . constructor , Promise . prototype . constructor ) ;
145
- jequal ( provider . validateAppId ( "app" , "key" , { } ) . constructor , Promise . prototype . constructor ) ;
145
+ jequal ( provider . validateAuthData ( { } , { } ) . constructor , Promise . prototype . constructor ) ;
146
+ jequal ( provider . validateAppId ( "app" , "key" , { } ) . constructor , Promise . prototype . constructor ) ;
146
147
done ( ) ;
147
148
} ) ;
148
149
} ) ;
@@ -204,12 +205,12 @@ describe('OAuth', function() {
204
205
}
205
206
} ;
206
207
var headers = { 'X-Parse-Application-Id' : 'test' ,
207
- 'X-Parse-REST-API-Key' : 'rest' ,
208
+ 'X-Parse-REST-API-Key' : 'rest' ,
208
209
'Content-Type' : 'application/json' }
209
210
210
211
var options = {
211
212
headers : { 'X-Parse-Application-Id' : 'test' ,
212
- 'X-Parse-REST-API-Key' : 'rest' ,
213
+ 'X-Parse-REST-API-Key' : 'rest' ,
213
214
'Content-Type' : 'application/json' } ,
214
215
url : 'http://localhost:8378/1/users' ,
215
216
body : JSON . stringify ( jsonBody )
@@ -248,7 +249,7 @@ describe('OAuth', function() {
248
249
done ( ) ;
249
250
} ) ;
250
251
} ) ;
251
-
252
+
252
253
} ) ;
253
254
254
255
it ( "unlink and link with custom provider" , ( done ) => {
@@ -266,28 +267,38 @@ describe('OAuth', function() {
266
267
267
268
model . _unlinkFrom ( "myoauth" , {
268
269
success : function ( model ) {
270
+
269
271
ok ( ! model . _isLinked ( "myoauth" ) ,
270
272
"User should not be linked to myoauth" ) ;
271
273
ok ( ! provider . synchronizedUserId , "User id should be cleared" ) ;
272
274
ok ( ! provider . synchronizedAuthToken , "Auth token should be cleared" ) ;
273
275
ok ( ! provider . synchronizedExpiration ,
274
276
"Expiration should be cleared" ) ;
275
-
276
- model . _linkWith ( "myoauth" , {
277
- success : function ( model ) {
278
- ok ( provider . synchronizedUserId , "User id should have a value" ) ;
279
- ok ( provider . synchronizedAuthToken ,
280
- "Auth token should have a value" ) ;
281
- ok ( provider . synchronizedExpiration ,
282
- "Expiration should have a value" ) ;
283
- ok ( model . _isLinked ( "myoauth" ) ,
284
- "User should be linked to myoauth" ) ;
285
- done ( ) ;
286
- } ,
287
- error : function ( model , error ) {
288
- ok ( false , "linking again should succeed" ) ;
289
- done ( ) ;
290
- }
277
+ // make sure the auth data is properly deleted
278
+ var config = new Config ( Parse . applicationId ) ;
279
+ config . database . mongoFind ( '_User' , {
280
+ _id : model . id
281
+ } ) . then ( ( res ) => {
282
+ expect ( res . length ) . toBe ( 1 ) ;
283
+ expect ( res [ 0 ] . _auth_data_myoauth ) . toBeUndefined ( ) ;
284
+ expect ( res [ 0 ] . _auth_data_myoauth ) . not . toBeNull ( ) ;
285
+
286
+ model . _linkWith ( "myoauth" , {
287
+ success : function ( model ) {
288
+ ok ( provider . synchronizedUserId , "User id should have a value" ) ;
289
+ ok ( provider . synchronizedAuthToken ,
290
+ "Auth token should have a value" ) ;
291
+ ok ( provider . synchronizedExpiration ,
292
+ "Expiration should have a value" ) ;
293
+ ok ( model . _isLinked ( "myoauth" ) ,
294
+ "User should be linked to myoauth" ) ;
295
+ done ( ) ;
296
+ } ,
297
+ error : function ( model , error ) {
298
+ ok ( false , "linking again should succeed" ) ;
299
+ done ( ) ;
300
+ }
301
+ } ) ;
291
302
} ) ;
292
303
} ,
293
304
error : function ( model , error ) {
@@ -304,4 +315,4 @@ describe('OAuth', function() {
304
315
} ) ;
305
316
306
317
307
- } )
318
+ } )
0 commit comments