BVB Source Codes

parse-server Show EmailVerificationToken.spec.js Source code

Return Download parse-server: download EmailVerificationToken.spec.js Source code - Download parse-server Source code - Type:.js
  1. "use strict";
  2.  
  3. const request = require('request');
  4. const requestp = require('request-promise');
  5. const Config = require('../src/Config');
  6.  
  7. describe("Email Verification Token Expiration: ", () => {
  8.  
  9.   it('show the invalid verification link page, if the user clicks on the verify email link after the email verify token expires', done => {
  10.     var user = new Parse.User();
  11.     var sendEmailOptions;
  12.     var emailAdapter = {
  13.       sendVerificationEmail: options => {
  14.         sendEmailOptions = options;
  15.       },
  16.       sendPasswordResetEmail: () => Promise.resolve(),
  17.       sendMail: () => {}
  18.     }
  19.     reconfigureServer({
  20.       appName: 'emailVerifyToken',
  21.       verifyUserEmails: true,
  22.       emailAdapter: emailAdapter,
  23.       emailVerifyTokenValidityDuration: 0.5, // 0.5 second
  24.       publicServerURL: "http://localhost:8378/1"
  25.     })
  26.     .then(() => {
  27.       user.setUsername("testEmailVerifyTokenValidity");
  28.       user.setPassword("expiringToken");
  29.       user.set('email', 'user@parse.com');
  30.       return user.signUp();
  31.     }).then(() => {
  32.       // wait for 1 second - simulate user behavior to some extent
  33.       setTimeout(() => {
  34.         expect(sendEmailOptions).not.toBeUndefined();
  35.  
  36.         request.get(sendEmailOptions.link, {
  37.           followRedirect: false,
  38.         }, (error, response) => {
  39.           expect(response.statusCode).toEqual(302);
  40.           expect(response.body).toEqual('Found. Redirecting to http://localhost:8378/1/apps/invalid_verification_link.html?username=testEmailVerifyTokenValidity&appId=test');
  41.           done();
  42.         });
  43.       }, 1000);
  44.     }).catch((err) => {
  45.       jfail(err);
  46.       done();
  47.     });
  48.   });
  49.  
  50.   it('emailVerified should set to false, if the user does not verify their email before the email verify token expires', done => {
  51.     var user = new Parse.User();
  52.     var sendEmailOptions;
  53.     var emailAdapter = {
  54.       sendVerificationEmail: options => {
  55.         sendEmailOptions = options;
  56.       },
  57.       sendPasswordResetEmail: () => Promise.resolve(),
  58.       sendMail: () => {}
  59.     }
  60.     reconfigureServer({
  61.       appName: 'emailVerifyToken',
  62.       verifyUserEmails: true,
  63.       emailAdapter: emailAdapter,
  64.       emailVerifyTokenValidityDuration: 0.5, // 0.5 second
  65.       publicServerURL: "http://localhost:8378/1"
  66.     })
  67.     .then(() => {
  68.       user.setUsername("testEmailVerifyTokenValidity");
  69.       user.setPassword("expiringToken");
  70.       user.set('email', 'user@parse.com');
  71.       return user.signUp();
  72.     }).then(() => {
  73.       // wait for 1 second - simulate user behavior to some extent
  74.       setTimeout(() => {
  75.         expect(sendEmailOptions).not.toBeUndefined();
  76.  
  77.         request.get(sendEmailOptions.link, {
  78.           followRedirect: false,
  79.         }, (error, response) => {
  80.           expect(response.statusCode).toEqual(302);
  81.           user.fetch()
  82.           .then(() => {
  83.             expect(user.get('emailVerified')).toEqual(false);
  84.             done();
  85.           })
  86.           .catch(() => {
  87.             jfail(error);
  88.             done();
  89.           });
  90.         });
  91.       }, 1000);
  92.     }).catch((error) => {
  93.       jfail(error);
  94.       done();
  95.     });
  96.   });
  97.  
  98.   it('if user clicks on the email verify link before email verification token expiration then show the verify email success page', done => {
  99.     var user = new Parse.User();
  100.     var sendEmailOptions;
  101.     var emailAdapter = {
  102.       sendVerificationEmail: options => {
  103.         sendEmailOptions = options;
  104.       },
  105.       sendPasswordResetEmail: () => Promise.resolve(),
  106.       sendMail: () => {}
  107.     }
  108.     reconfigureServer({
  109.       appName: 'emailVerifyToken',
  110.       verifyUserEmails: true,
  111.       emailAdapter: emailAdapter,
  112.       emailVerifyTokenValidityDuration: 5, // 5 seconds
  113.       publicServerURL: "http://localhost:8378/1"
  114.     })
  115.     .then(() => {
  116.       user.setUsername("testEmailVerifyTokenValidity");
  117.       user.setPassword("expiringToken");
  118.       user.set('email', 'user@parse.com');
  119.       return user.signUp();
  120.     }).then(() => {
  121.       request.get(sendEmailOptions.link, {
  122.         followRedirect: false,
  123.       }, (error, response) => {
  124.         expect(response.statusCode).toEqual(302);
  125.         expect(response.body).toEqual('Found. Redirecting to http://localhost:8378/1/apps/verify_email_success.html?username=testEmailVerifyTokenValidity');
  126.         done();
  127.       });
  128.     }).catch((error) => {
  129.       jfail(error);
  130.       done();
  131.     });
  132.   });
  133.  
  134.   it('if user clicks on the email verify link before email verification token expiration then emailVerified should be true', done => {
  135.     var user = new Parse.User();
  136.     var sendEmailOptions;
  137.     var emailAdapter = {
  138.       sendVerificationEmail: options => {
  139.         sendEmailOptions = options;
  140.       },
  141.       sendPasswordResetEmail: () => Promise.resolve(),
  142.       sendMail: () => {}
  143.     }
  144.     reconfigureServer({
  145.       appName: 'emailVerifyToken',
  146.       verifyUserEmails: true,
  147.       emailAdapter: emailAdapter,
  148.       emailVerifyTokenValidityDuration: 5, // 5 seconds
  149.       publicServerURL: "http://localhost:8378/1"
  150.     })
  151.     .then(() => {
  152.       user.setUsername("testEmailVerifyTokenValidity");
  153.       user.setPassword("expiringToken");
  154.       user.set('email', 'user@parse.com');
  155.       return user.signUp();
  156.     }).then(() => {
  157.       request.get(sendEmailOptions.link, {
  158.         followRedirect: false,
  159.       }, (error, response) => {
  160.         expect(response.statusCode).toEqual(302);
  161.         user.fetch()
  162.         .then(() => {
  163.           expect(user.get('emailVerified')).toEqual(true);
  164.           done();
  165.         })
  166.         .catch((error) => {
  167.           jfail(error);
  168.           done();
  169.         });
  170.       });
  171.     }).catch((error) => {
  172.       jfail(error);
  173.       done();
  174.     });
  175.   });
  176.  
  177.   it('if user clicks on the email verify link before email verification token expiration then user should be able to login', done => {
  178.     var user = new Parse.User();
  179.     var sendEmailOptions;
  180.     var emailAdapter = {
  181.       sendVerificationEmail: options => {
  182.         sendEmailOptions = options;
  183.       },
  184.       sendPasswordResetEmail: () => Promise.resolve(),
  185.       sendMail: () => {}
  186.     }
  187.     reconfigureServer({
  188.       appName: 'emailVerifyToken',
  189.       verifyUserEmails: true,
  190.       emailAdapter: emailAdapter,
  191.       emailVerifyTokenValidityDuration: 5, // 5 seconds
  192.       publicServerURL: "http://localhost:8378/1"
  193.     })
  194.     .then(() => {
  195.       user.setUsername("testEmailVerifyTokenValidity");
  196.       user.setPassword("expiringToken");
  197.       user.set('email', 'user@parse.com');
  198.       return user.signUp();
  199.     }).then(() => {
  200.       request.get(sendEmailOptions.link, {
  201.         followRedirect: false,
  202.       }, (error, response) => {
  203.         expect(response.statusCode).toEqual(302);
  204.         Parse.User.logIn("testEmailVerifyTokenValidity", "expiringToken")
  205.         .then(user => {
  206.           expect(typeof user).toBe('object');
  207.           expect(user.get('emailVerified')).toBe(true);
  208.           done();
  209.         })
  210.         .catch((error) => {
  211.           jfail(error);
  212.           done();
  213.         });
  214.       });
  215.     }).catch((error) => {
  216.       jfail(error);
  217.       done();
  218.     });
  219.   });
  220.  
  221.   it('sets the _email_verify_token_expires_at and _email_verify_token fields after user SignUp', done => {
  222.     var user = new Parse.User();
  223.     var sendEmailOptions;
  224.     var emailAdapter = {
  225.       sendVerificationEmail: options => {
  226.         sendEmailOptions = options;
  227.       },
  228.       sendPasswordResetEmail: () => Promise.resolve(),
  229.       sendMail: () => {}
  230.     }
  231.     reconfigureServer({
  232.       appName: 'emailVerifyToken',
  233.       verifyUserEmails: true,
  234.       emailAdapter: emailAdapter,
  235.       emailVerifyTokenValidityDuration: 5, // 5 seconds
  236.       publicServerURL: 'http://localhost:8378/1'
  237.     })
  238.     .then(() => {
  239.       user.setUsername('sets_email_verify_token_expires_at');
  240.       user.setPassword('expiringToken');
  241.       user.set('email', 'user@parse.com');
  242.       return user.signUp();
  243.     })
  244.     .then(() => {
  245.       const config = new Config('test');
  246.       return config.database.find('_User', {username: 'sets_email_verify_token_expires_at'});
  247.     })
  248.     .then(results => {
  249.       expect(results.length).toBe(1);
  250.       const user = results[0];
  251.       expect(typeof user).toBe('object');
  252.       expect(user.emailVerified).toEqual(false);
  253.       expect(typeof user._email_verify_token).toBe('string');
  254.       expect(typeof user._email_verify_token_expires_at).toBe('object');
  255.       expect(sendEmailOptions).toBeDefined();
  256.       done();
  257.     })
  258.     .catch(error => {
  259.       jfail(error);
  260.       done();
  261.     });
  262.   });
  263.  
  264.   it('unsets the _email_verify_token_expires_at and _email_verify_token fields in the User class if email verification is successful', done => {
  265.     var user = new Parse.User();
  266.     var sendEmailOptions;
  267.     var emailAdapter = {
  268.       sendVerificationEmail: options => {
  269.         sendEmailOptions = options;
  270.       },
  271.       sendPasswordResetEmail: () => Promise.resolve(),
  272.       sendMail: () => {}
  273.     }
  274.     reconfigureServer({
  275.       appName: 'emailVerifyToken',
  276.       verifyUserEmails: true,
  277.       emailAdapter: emailAdapter,
  278.       emailVerifyTokenValidityDuration: 5, // 5 seconds
  279.       publicServerURL: "http://localhost:8378/1"
  280.     })
  281.     .then(() => {
  282.       user.setUsername("unsets_email_verify_token_expires_at");
  283.       user.setPassword("expiringToken");
  284.       user.set('email', 'user@parse.com');
  285.       return user.signUp();
  286.     })
  287.     .then(() => {
  288.       request.get(sendEmailOptions.link, {
  289.         followRedirect: false,
  290.       }, (error, response) => {
  291.         expect(response.statusCode).toEqual(302);
  292.         const config = new Config('test');
  293.         return config.database.find('_User', {username: 'unsets_email_verify_token_expires_at'}).then((results) => {
  294.           expect(results.length).toBe(1);
  295.           return results[0];
  296.         })
  297.         .then(user => {
  298.           expect(typeof user).toBe('object');
  299.           expect(user.emailVerified).toEqual(true);
  300.           expect(typeof user._email_verify_token).toBe('undefined');
  301.           expect(typeof user._email_verify_token_expires_at).toBe('undefined');
  302.           done();
  303.         })
  304.         .catch(error => {
  305.           jfail(error);
  306.           done();
  307.         });
  308.       });
  309.     })
  310.     .catch(error => {
  311.       jfail(error);
  312.       done();
  313.     });
  314.   });
  315.  
  316.   it('clicking on the email verify link by an email VERIFIED user that was setup before enabling the expire email verify token should show email verify email success', done => {
  317.     var user = new Parse.User();
  318.     var sendEmailOptions;
  319.     var emailAdapter = {
  320.       sendVerificationEmail: options => {
  321.         sendEmailOptions = options;
  322.       },
  323.       sendPasswordResetEmail: () => Promise.resolve(),
  324.       sendMail: () => {}
  325.     }
  326.     var serverConfig = {
  327.       appName: 'emailVerifyToken',
  328.       verifyUserEmails: true,
  329.       emailAdapter: emailAdapter,
  330.       publicServerURL: "http://localhost:8378/1"
  331.     };
  332.  
  333.     // setup server WITHOUT enabling the expire email verify token flag
  334.     reconfigureServer(serverConfig)
  335.     .then(() => {
  336.       user.setUsername("testEmailVerifyTokenValidity");
  337.       user.setPassword("expiringToken");
  338.       user.set('email', 'user@parse.com');
  339.       return user.signUp();
  340.     })
  341.     .then(() => {
  342.       return new Promise((resolve, reject) => {
  343.         request.get(sendEmailOptions.link, { followRedirect: false, })
  344.         .on('error', error => reject(error))
  345.         .on('response', (response) => {
  346.           expect(response.statusCode).toEqual(302);
  347.           resolve(user.fetch());
  348.         });
  349.       });
  350.     })
  351.     .then(() => {
  352.       expect(user.get('emailVerified')).toEqual(true);
  353.       // RECONFIGURE the server i.e., ENABLE the expire email verify token flag
  354.       serverConfig.emailVerifyTokenValidityDuration = 5; // 5 seconds
  355.       return reconfigureServer(serverConfig);
  356.     })
  357.     .then(() => {
  358.       request.get(sendEmailOptions.link, {
  359.         followRedirect: false,
  360.       }, (error, response) => {
  361.         expect(response.statusCode).toEqual(302);
  362.         expect(response.body).toEqual('Found. Redirecting to http://localhost:8378/1/apps/verify_email_success.html?username=testEmailVerifyTokenValidity');
  363.         done();
  364.       });
  365.     })
  366.     .catch((error) => {
  367.       jfail(error);
  368.       done();
  369.     });
  370.   });
  371.  
  372.   it('clicking on the email verify link by an email UNVERIFIED user that was setup before enabling the expire email verify token should show invalid verficiation link page', done => {
  373.     var user = new Parse.User();
  374.     var sendEmailOptions;
  375.     var emailAdapter = {
  376.       sendVerificationEmail: options => {
  377.         sendEmailOptions = options;
  378.       },
  379.       sendPasswordResetEmail: () => Promise.resolve(),
  380.       sendMail: () => {}
  381.     }
  382.     var serverConfig = {
  383.       appName: 'emailVerifyToken',
  384.       verifyUserEmails: true,
  385.       emailAdapter: emailAdapter,
  386.       publicServerURL: "http://localhost:8378/1"
  387.     };
  388.  
  389.     // setup server WITHOUT enabling the expire email verify token flag
  390.     reconfigureServer(serverConfig)
  391.     .then(() => {
  392.       user.setUsername("testEmailVerifyTokenValidity");
  393.       user.setPassword("expiringToken");
  394.       user.set('email', 'user@parse.com');
  395.       return user.signUp();
  396.     })
  397.     .then(() => {
  398.       // just get the user again - DO NOT email verify the user
  399.       return user.fetch();
  400.     })
  401.     .then(() => {
  402.       expect(user.get('emailVerified')).toEqual(false);
  403.       // RECONFIGURE the server i.e., ENABLE the expire email verify token flag
  404.       serverConfig.emailVerifyTokenValidityDuration = 5; // 5 seconds
  405.       return reconfigureServer(serverConfig);
  406.     })
  407.     .then(() => {
  408.       request.get(sendEmailOptions.link, {
  409.         followRedirect: false,
  410.       }, (error, response) => {
  411.         expect(response.statusCode).toEqual(302);
  412.         expect(response.body).toEqual('Found. Redirecting to http://localhost:8378/1/apps/invalid_verification_link.html?username=testEmailVerifyTokenValidity&appId=test');
  413.         done();
  414.       });
  415.     })
  416.     .catch((error) => {
  417.       jfail(error);
  418.       done();
  419.     });
  420.   });
  421.  
  422.   it('setting the email on the user should set a new email verification token and new expiration date for the token when expire email verify token flag is set', done => {
  423.  
  424.     const user = new Parse.User();
  425.     let userBeforeEmailReset;
  426.  
  427.     let sendEmailOptions;
  428.     const emailAdapter = {
  429.       sendVerificationEmail: options => {
  430.         sendEmailOptions = options;
  431.       },
  432.       sendPasswordResetEmail: () => Promise.resolve(),
  433.       sendMail: () => {}
  434.     };
  435.     const serverConfig = {
  436.       appName: 'emailVerifyToken',
  437.       verifyUserEmails: true,
  438.       emailAdapter: emailAdapter,
  439.       emailVerifyTokenValidityDuration: 5, // 5 seconds
  440.       publicServerURL: "http://localhost:8378/1"
  441.     };
  442.  
  443.     reconfigureServer(serverConfig)
  444.     .then(() => {
  445.       user.setUsername("newEmailVerifyTokenOnEmailReset");
  446.       user.setPassword("expiringToken");
  447.       user.set('email', 'user@parse.com');
  448.       return user.signUp();
  449.     })
  450.     .then(() => {
  451.       const config = new Config('test');
  452.       return config.database.find('_User', {username: 'newEmailVerifyTokenOnEmailReset'}).then((results) => {
  453.         return results[0];
  454.       });
  455.     })
  456.     .then(userFromDb => {
  457.       expect(typeof userFromDb).toBe('object');
  458.       userBeforeEmailReset = userFromDb;
  459.  
  460.       // trigger another token generation by setting the email
  461.       user.set('email', 'user@parse.com');
  462.       return new Promise((resolve) => {
  463.         // wait for half a sec to get a new expiration time
  464.         setTimeout(() => resolve(user.save()), 500);
  465.       });
  466.     })
  467.     .then(() => {
  468.       const config = new Config('test');
  469.       return config.database.find('_User', {username: 'newEmailVerifyTokenOnEmailReset'}).then((results) => {
  470.         return results[0];
  471.       });
  472.     })
  473.     .then(userAfterEmailReset => {
  474.       expect(typeof userAfterEmailReset).toBe('object');
  475.       expect(userBeforeEmailReset._email_verify_token).not.toEqual(userAfterEmailReset._email_verify_token);
  476.       expect(userBeforeEmailReset._email_verify_token_expires_at).not.toEqual(userAfterEmailReset.__email_verify_token_expires_at);
  477.       expect(sendEmailOptions).toBeDefined();
  478.       done();
  479.     })
  480.     .catch((error) => {
  481.       jfail(error);
  482.       done();
  483.     });
  484.   });
  485.  
  486.   it('should send a new verification email when a resend is requested and the user is UNVERIFIED', done => {
  487.     var user = new Parse.User();
  488.     var sendEmailOptions;
  489.     var sendVerificationEmailCallCount = 0;
  490.     var emailAdapter = {
  491.       sendVerificationEmail: options => {
  492.         sendEmailOptions = options;
  493.         sendVerificationEmailCallCount++;
  494.       },
  495.       sendPasswordResetEmail: () => Promise.resolve(),
  496.       sendMail: () => {}
  497.     }
  498.     reconfigureServer({
  499.       appName: 'emailVerifyToken',
  500.       verifyUserEmails: true,
  501.       emailAdapter: emailAdapter,
  502.       emailVerifyTokenValidityDuration: 5, // 5 seconds
  503.       publicServerURL: 'http://localhost:8378/1'
  504.     })
  505.     .then(() => {
  506.       user.setUsername('resends_verification_token');
  507.       user.setPassword('expiringToken');
  508.       user.set('email', 'user@parse.com');
  509.       return user.signUp();
  510.     })
  511.     .then(() => {
  512.       expect(sendVerificationEmailCallCount).toBe(1);
  513.  
  514.       return requestp.post({
  515.         uri: 'http://localhost:8378/1/verificationEmailRequest',
  516.         body: {
  517.           email: 'user@parse.com'
  518.         },
  519.         headers: {
  520.           'X-Parse-Application-Id': Parse.applicationId,
  521.           'X-Parse-REST-API-Key': 'rest',
  522.         },
  523.         json: true,
  524.         resolveWithFullResponse: true,
  525.         simple: false // this promise is only rejected if the call itself failed
  526.       })
  527.       .then((response) => {
  528.         expect(response.statusCode).toBe(200);
  529.         expect(sendVerificationEmailCallCount).toBe(2);
  530.         expect(sendEmailOptions).toBeDefined();
  531.         done();
  532.       });
  533.     })
  534.     .catch(error => {
  535.       jfail(error);
  536.       done();
  537.     });
  538.   });
  539.  
  540.   it('should not send a new verification email when a resend is requested and the user is VERIFIED', done => {
  541.     var user = new Parse.User();
  542.     var sendEmailOptions;
  543.     var sendVerificationEmailCallCount = 0;
  544.     var emailAdapter = {
  545.       sendVerificationEmail: options => {
  546.         sendEmailOptions = options;
  547.         sendVerificationEmailCallCount++;
  548.       },
  549.       sendPasswordResetEmail: () => Promise.resolve(),
  550.       sendMail: () => {}
  551.     }
  552.     reconfigureServer({
  553.       appName: 'emailVerifyToken',
  554.       verifyUserEmails: true,
  555.       emailAdapter: emailAdapter,
  556.       emailVerifyTokenValidityDuration: 5, // 5 seconds
  557.       publicServerURL: 'http://localhost:8378/1'
  558.     })
  559.     .then(() => {
  560.       user.setUsername('no_new_verification_token_once_verified');
  561.       user.setPassword('expiringToken');
  562.       user.set('email', 'user@parse.com');
  563.       return user.signUp();
  564.     })
  565.     .then(() => {
  566.       return requestp.get({
  567.         url: sendEmailOptions.link,
  568.         followRedirect: false,
  569.         resolveWithFullResponse: true,
  570.         simple: false
  571.       })
  572.       .then((response) => {
  573.         expect(response.statusCode).toEqual(302);
  574.       });
  575.     })
  576.     .then(() => {
  577.       expect(sendVerificationEmailCallCount).toBe(1);
  578.  
  579.       return requestp.post({
  580.         uri: 'http://localhost:8378/1/verificationEmailRequest',
  581.         body: {
  582.           email: 'user@parse.com'
  583.         },
  584.         headers: {
  585.           'X-Parse-Application-Id': Parse.applicationId,
  586.           'X-Parse-REST-API-Key': 'rest',
  587.         },
  588.         json: true,
  589.         resolveWithFullResponse: true,
  590.         simple: false // this promise is only rejected if the call itself failed
  591.       })
  592.       .then((response) => {
  593.         expect(response.statusCode).toBe(400);
  594.         expect(sendVerificationEmailCallCount).toBe(1);
  595.         done();
  596.       });
  597.     })
  598.     .catch(error => {
  599.       jfail(error);
  600.       done();
  601.     });
  602.   });
  603.  
  604.   it('should not send a new verification email if this user does not exist', done => {
  605.     var sendEmailOptions;
  606.     var sendVerificationEmailCallCount = 0;
  607.     var emailAdapter = {
  608.       sendVerificationEmail: options => {
  609.         sendEmailOptions = options;
  610.         sendVerificationEmailCallCount++;
  611.       },
  612.       sendPasswordResetEmail: () => Promise.resolve(),
  613.       sendMail: () => {}
  614.     }
  615.     reconfigureServer({
  616.       appName: 'emailVerifyToken',
  617.       verifyUserEmails: true,
  618.       emailAdapter: emailAdapter,
  619.       emailVerifyTokenValidityDuration: 5, // 5 seconds
  620.       publicServerURL: 'http://localhost:8378/1'
  621.     })
  622.     .then(() => {
  623.       return requestp.post({
  624.         uri: 'http://localhost:8378/1/verificationEmailRequest',
  625.         body: {
  626.           email: 'user@parse.com'
  627.         },
  628.         headers: {
  629.           'X-Parse-Application-Id': Parse.applicationId,
  630.           'X-Parse-REST-API-Key': 'rest',
  631.         },
  632.         json: true,
  633.         resolveWithFullResponse: true,
  634.         simple: false
  635.       })
  636.       .then(response => {
  637.         expect(response.statusCode).toBe(400);
  638.         expect(sendVerificationEmailCallCount).toBe(0);
  639.         expect(sendEmailOptions).not.toBeDefined();
  640.         done();
  641.       });
  642.     })
  643.     .catch(error => {
  644.       jfail(error);
  645.       done();
  646.     });
  647.   });
  648.  
  649.   it('should fail if no email is supplied', done => {
  650.     var sendEmailOptions;
  651.     var sendVerificationEmailCallCount = 0;
  652.     var emailAdapter = {
  653.       sendVerificationEmail: options => {
  654.         sendEmailOptions = options;
  655.         sendVerificationEmailCallCount++;
  656.       },
  657.       sendPasswordResetEmail: () => Promise.resolve(),
  658.       sendMail: () => {}
  659.     }
  660.     reconfigureServer({
  661.       appName: 'emailVerifyToken',
  662.       verifyUserEmails: true,
  663.       emailAdapter: emailAdapter,
  664.       emailVerifyTokenValidityDuration: 5, // 5 seconds
  665.       publicServerURL: 'http://localhost:8378/1'
  666.     })
  667.     .then(() => {
  668.       request.post({
  669.         uri: 'http://localhost:8378/1/verificationEmailRequest',
  670.         body: {},
  671.         headers: {
  672.           'X-Parse-Application-Id': Parse.applicationId,
  673.           'X-Parse-REST-API-Key': 'rest',
  674.         },
  675.         json: true,
  676.         resolveWithFullResponse: true,
  677.         simple: false
  678.       }, (err, response) => {
  679.         expect(response.statusCode).toBe(400);
  680.         expect(response.body.code).toBe(Parse.Error.EMAIL_MISSING);
  681.         expect(response.body.error).toBe('you must provide an email');
  682.         expect(sendVerificationEmailCallCount).toBe(0);
  683.         expect(sendEmailOptions).not.toBeDefined();
  684.         done();
  685.       });
  686.     })
  687.     .catch(error => {
  688.       jfail(error);
  689.       done();
  690.     });
  691.   });
  692.  
  693.   it('should fail if email is not a string', done => {
  694.     var sendEmailOptions;
  695.     var sendVerificationEmailCallCount = 0;
  696.     var emailAdapter = {
  697.       sendVerificationEmail: options => {
  698.         sendEmailOptions = options;
  699.         sendVerificationEmailCallCount++;
  700.       },
  701.       sendPasswordResetEmail: () => Promise.resolve(),
  702.       sendMail: () => {}
  703.     }
  704.     reconfigureServer({
  705.       appName: 'emailVerifyToken',
  706.       verifyUserEmails: true,
  707.       emailAdapter: emailAdapter,
  708.       emailVerifyTokenValidityDuration: 5, // 5 seconds
  709.       publicServerURL: 'http://localhost:8378/1'
  710.     })
  711.     .then(() => {
  712.       request.post({
  713.         uri: 'http://localhost:8378/1/verificationEmailRequest',
  714.         body: {email: 3},
  715.         headers: {
  716.           'X-Parse-Application-Id': Parse.applicationId,
  717.           'X-Parse-REST-API-Key': 'rest',
  718.         },
  719.         json: true,
  720.         resolveWithFullResponse: true,
  721.         simple: false
  722.       }, (err, response) => {
  723.         expect(response.statusCode).toBe(400);
  724.         expect(response.body.code).toBe(Parse.Error.INVALID_EMAIL_ADDRESS);
  725.         expect(response.body.error).toBe('you must provide a valid email string');
  726.         expect(sendVerificationEmailCallCount).toBe(0);
  727.         expect(sendEmailOptions).not.toBeDefined();
  728.         done();
  729.       });
  730.     })
  731.     .catch(error => {
  732.       jfail(error);
  733.       done();
  734.     });
  735.   });
  736.  
  737.   it('client should not see the _email_verify_token_expires_at field', done => {
  738.     var user = new Parse.User();
  739.     var sendEmailOptions;
  740.     var emailAdapter = {
  741.       sendVerificationEmail: options => {
  742.         sendEmailOptions = options;
  743.       },
  744.       sendPasswordResetEmail: () => Promise.resolve(),
  745.       sendMail: () => {}
  746.     }
  747.     reconfigureServer({
  748.       appName: 'emailVerifyToken',
  749.       verifyUserEmails: true,
  750.       emailAdapter: emailAdapter,
  751.       emailVerifyTokenValidityDuration: 5, // 5 seconds
  752.       publicServerURL: "http://localhost:8378/1"
  753.     })
  754.     .then(() => {
  755.       user.setUsername("testEmailVerifyTokenValidity");
  756.       user.setPassword("expiringToken");
  757.       user.set('email', 'user@parse.com');
  758.       return user.signUp();
  759.     })
  760.     .then(() => {
  761.  
  762.       user.fetch()
  763.       .then(() => {
  764.         expect(user.get('emailVerified')).toEqual(false);
  765.         expect(typeof user.get('_email_verify_token_expires_at')).toBe('undefined');
  766.         expect(sendEmailOptions).toBeDefined();
  767.         done();
  768.       })
  769.       .catch(error => {
  770.         jfail(error);
  771.         done();
  772.       });
  773.  
  774.     }).catch((error) => {
  775.       jfail(error);
  776.       done();
  777.     });
  778.   });
  779.  
  780. })
  781.  
downloadEmailVerificationToken.spec.js Source code - Download parse-server Source code
Related Source Codes/Software:
react-boilerplate - 2017-06-07
webtorrent - Streaming torrent client for the web ... 2017-06-06
machine-learning-for-software-engineers - A complete daily plan for studying to become a mac... 2017-06-06
upterm - A terminal emulator for the 21st century. 2017-06-06
lottie-android - Render After Effects animations natively on Androi... 2017-06-07
AsyncDisplayKit - Smooth asynchronous user interfaces for iOS apps. ... 2017-06-07
ionicons - The premium icon font for Ionic ... 2017-06-07
storybook - 2017-06-07
prettier - Prettier is an opinionated JavaScript formatter. ... 2017-06-08
CRYENGINE - CRYENGINE is a powerful real-time game development... 2017-06-11
postal - 2017-06-11
reactide - Reactide is the first dedicated IDE for React web ... 2017-06-11
rkt - rkt is a pod-native container engine for Linux. It... 2017-06-11
uWebSockets - Tiny WebSockets https://for... 2017-06-11
realworld - TodoMVC for the RealWorld - Exemplary fullstack Me... 2017-06-11
goreplay - GoReplay is an open-source tool for capturing and ... 2017-06-10
pyenv - Simple Python version management 2017-06-10
redux-saga - An alternative side effect model for Redux apps ... 2017-06-10
angular-starter - 2017-06-10

 Back to top