@@ -3224,4 +3224,166 @@ describe('Parse.User testing', () => {
32243224 . then ( done )
32253225 . catch ( done . fail ) ;
32263226 } ) ;
3227+
3228+ it ( 'can login with email' , ( done ) => {
3229+ const user = new Parse . User ( ) ;
3230+ user . save ( {
3231+ username : 'yolo' ,
3232+ password : 'yolopass' ,
3233+ 3234+ } ) . then ( ( ) => {
3235+ const options = {
3236+ url : `http://localhost:8378/1/login` ,
3237+ headers : {
3238+ 'X-Parse-Application-Id' : Parse . applicationId ,
3239+ 'X-Parse-REST-API-Key' : 'rest' ,
3240+ } ,
3241+ json :
{ email :
"[email protected] " , password :
'yolopass' } 3242+ }
3243+ return rp . get ( options ) ;
3244+ } ) . then ( done ) . catch ( done . fail ) ;
3245+ } ) ;
3246+
3247+ it ( 'cannot login with email and invalid password' , ( done ) => {
3248+ const user = new Parse . User ( ) ;
3249+ user . save ( {
3250+ username : 'yolo' ,
3251+ password : 'yolopass' ,
3252+ 3253+ } ) . then ( ( ) => {
3254+ const options = {
3255+ url : `http://localhost:8378/1/login` ,
3256+ headers : {
3257+ 'X-Parse-Application-Id' : Parse . applicationId ,
3258+ 'X-Parse-REST-API-Key' : 'rest' ,
3259+ } ,
3260+ json :
{ email :
"[email protected] " , password :
'yolopass2' } 3261+ }
3262+ return rp . get ( options ) ;
3263+ } ) . then ( done . fail ) . catch ( done ) ;
3264+ } ) ;
3265+
3266+ it ( 'can login with email through query string' , ( done ) => {
3267+ const user = new Parse . User ( ) ;
3268+ user . save ( {
3269+ username : 'yolo' ,
3270+ password : 'yolopass' ,
3271+ 3272+ } ) . then ( ( ) => {
3273+ const options = {
3274+ url :
`http://localhost:8378/1/[email protected] &password=yolopass` , 3275+ headers : {
3276+ 'X-Parse-Application-Id' : Parse . applicationId ,
3277+ 'X-Parse-REST-API-Key' : 'rest' ,
3278+ } ,
3279+ }
3280+ return rp . get ( options ) ;
3281+ } ) . then ( done ) . catch ( done . fail ) ;
3282+ } ) ;
3283+
3284+ it ( 'can login when both email and username are passed' , ( done ) => {
3285+ const user = new Parse . User ( ) ;
3286+ user . save ( {
3287+ username : 'yolo' ,
3288+ password : 'yolopass' ,
3289+ 3290+ } ) . then ( ( ) => {
3291+ const options = {
3292+ url :
`http://localhost:8378/1/[email protected] &username=yolo&password=yolopass` , 3293+ headers : {
3294+ 'X-Parse-Application-Id' : Parse . applicationId ,
3295+ 'X-Parse-REST-API-Key' : 'rest' ,
3296+ } ,
3297+ }
3298+ return rp . get ( options ) ;
3299+ } ) . then ( done ) . catch ( done . fail ) ;
3300+ } ) ;
3301+
3302+ it ( "fails to login when username doesn't match email" , ( done ) => {
3303+ const user = new Parse . User ( ) ;
3304+ user . save ( {
3305+ username : 'yolo' ,
3306+ password : 'yolopass' ,
3307+ 3308+ } ) . then ( ( ) => {
3309+ const options = {
3310+ url :
`http://localhost:8378/1/[email protected] &username=yolo2&password=yolopass` , 3311+ headers : {
3312+ 'X-Parse-Application-Id' : Parse . applicationId ,
3313+ 'X-Parse-REST-API-Key' : 'rest' ,
3314+ } ,
3315+ json : true ,
3316+ }
3317+ return rp . get ( options ) ;
3318+ } ) . then ( done . fail ) . catch ( ( err ) => {
3319+ expect ( err . response . body . error ) . toEqual ( 'Invalid username/password.' ) ;
3320+ done ( ) ;
3321+ } ) ;
3322+ } ) ;
3323+
3324+ it ( "fails to login when email doesn't match username" , ( done ) => {
3325+ const user = new Parse . User ( ) ;
3326+ user . save ( {
3327+ username : 'yolo' ,
3328+ password : 'yolopass' ,
3329+ 3330+ } ) . then ( ( ) => {
3331+ const options = {
3332+ url :
`http://localhost:8378/1/[email protected] &username=yolo&password=yolopass` , 3333+ headers : {
3334+ 'X-Parse-Application-Id' : Parse . applicationId ,
3335+ 'X-Parse-REST-API-Key' : 'rest' ,
3336+ } ,
3337+ json : true ,
3338+ }
3339+ return rp . get ( options ) ;
3340+ } ) . then ( done . fail ) . catch ( ( err ) => {
3341+ expect ( err . response . body . error ) . toEqual ( 'Invalid username/password.' ) ;
3342+ done ( ) ;
3343+ } ) ;
3344+ } ) ;
3345+
3346+ it ( 'fails to login when email and username are not provided' , ( done ) => {
3347+ const user = new Parse . User ( ) ;
3348+ user . save ( {
3349+ username : 'yolo' ,
3350+ password : 'yolopass' ,
3351+ 3352+ } ) . then ( ( ) => {
3353+ const options = {
3354+ url : `http://localhost:8378/1/login?password=yolopass` ,
3355+ headers : {
3356+ 'X-Parse-Application-Id' : Parse . applicationId ,
3357+ 'X-Parse-REST-API-Key' : 'rest' ,
3358+ } ,
3359+ json : true ,
3360+ }
3361+ return rp . get ( options ) ;
3362+ } ) . then ( done . fail ) . catch ( ( err ) => {
3363+ expect ( err . response . body . error ) . toEqual ( 'username/email is required.' ) ;
3364+ done ( ) ;
3365+ } ) ;
3366+ } ) ;
3367+
3368+ it ( 'fails to login when password is not provided' , ( done ) => {
3369+ const user = new Parse . User ( ) ;
3370+ user . save ( {
3371+ username : 'yolo' ,
3372+ password : 'yolopass' ,
3373+ 3374+ } ) . then ( ( ) => {
3375+ const options = {
3376+ url : `http://localhost:8378/1/login?username=yolo` ,
3377+ headers : {
3378+ 'X-Parse-Application-Id' : Parse . applicationId ,
3379+ 'X-Parse-REST-API-Key' : 'rest' ,
3380+ } ,
3381+ json : true ,
3382+ }
3383+ return rp . get ( options ) ;
3384+ } ) . then ( done . fail ) . catch ( ( err ) => {
3385+ expect ( err . response . body . error ) . toEqual ( 'password is required.' ) ;
3386+ done ( ) ;
3387+ } ) ;
3388+ } ) ;
32273389} ) ;
0 commit comments