@@ -15,6 +15,7 @@ describe('User', function() {
1515 var validCredentials = { email : validCredentialsEmail , password : 'bar' } ;
1616 var validCredentialsEmailVerified = { email :
'[email protected] ' , password :
'bar1' , emailVerified :
true } ; 1717 var validCredentialsEmailVerifiedOverREST = { email :
'[email protected] ' , password :
'bar2' , emailVerified :
true } ; 18+ var validCredentialsWithRealm = { email :
'[email protected] ' , password :
'bar' , realm :
'foobar' } ; 1819 var validCredentialsWithTTL = { email :
'[email protected] ' , password :
'bar' , ttl :
3600 } ; 1920 var validCredentialsWithTTLAndScope = { email :
'[email protected] ' , password :
'bar' , ttl :
3600 , scope :
'all' } ; 2021 var validMixedCaseEmailCredentials = { email :
'[email protected] ' , password :
'bar' } ; @@ -1878,6 +1879,58 @@ describe('User', function() {
18781879 } ) ;
18791880 } ) ;
18801881 } ) ;
1882+
1883+ describe ( 'User.resetPassword(options, cb) requiring realm' , function ( ) {
1884+ var realmUser ;
1885+
1886+ beforeEach ( function ( done ) {
1887+ User . create ( validCredentialsWithRealm , function ( err , u ) {
1888+ if ( err ) return done ( err ) ;
1889+
1890+ realmUser = u ;
1891+ done ( ) ;
1892+ } ) ;
1893+ } ) ;
1894+
1895+ it ( 'Reports when email is not found in realm' , function ( done ) {
1896+ User . resetPassword ( {
1897+ email : realmUser . email ,
1898+ realm : 'unknown'
1899+ } , function ( err ) {
1900+ assert ( err ) ;
1901+ assert . equal ( err . code , 'EMAIL_NOT_FOUND' ) ;
1902+ assert . equal ( err . statusCode , 404 ) ;
1903+
1904+ done ( ) ;
1905+ } ) ;
1906+ } ) ;
1907+
1908+ it ( 'Creates a temp accessToken to allow a user in realm to change password' , function ( done ) {
1909+ var calledBack = false ;
1910+
1911+ User . resetPassword ( {
1912+ email : realmUser . email ,
1913+ realm : realmUser . realm
1914+ } , function ( ) {
1915+ calledBack = true ;
1916+ } ) ;
1917+
1918+ User . once ( 'resetPasswordRequest' , function ( info ) {
1919+ assert ( info . email ) ;
1920+ assert ( info . accessToken ) ;
1921+ assert ( info . accessToken . id ) ;
1922+ assert . equal ( info . accessToken . ttl / 60 , 15 ) ;
1923+ assert ( calledBack ) ;
1924+ info . accessToken . user ( function ( err , user ) {
1925+ if ( err ) return done ( err ) ;
1926+
1927+ assert . equal ( user . email , realmUser . email ) ;
1928+
1929+ done ( ) ;
1930+ } ) ;
1931+ } ) ;
1932+ } ) ;
1933+ } ) ;
18811934 } ) ;
18821935
18831936 describe ( 'Email Update' , function ( ) {
0 commit comments