-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add password validation via POST request for user with unverifi…
…ed email using master key and option `ignoreEmailVerification` (#8895)
- Loading branch information
Showing
2 changed files
with
95 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -585,4 +585,83 @@ describe('Verify User Password', () => { | |
done(); | ||
}); | ||
}); | ||
|
||
it('verify password of user with unverified email with master key and ignoreEmailVerification=true', async () => { | ||
await reconfigureServer({ | ||
publicServerURL: 'http://localhost:8378/', | ||
appName: 'emailVerify', | ||
verifyUserEmails: true, | ||
preventLoginWithUnverifiedEmail: true, | ||
emailAdapter: MockEmailAdapterWithOptions({ | ||
fromAddress: '[email protected]', | ||
apiKey: 'k', | ||
domain: 'd', | ||
}), | ||
}); | ||
|
||
const user = new Parse.User(); | ||
user.setUsername('user'); | ||
user.setPassword('pass'); | ||
user.setEmail('[email protected]'); | ||
await user.signUp(); | ||
|
||
const { data: res } = await request({ | ||
method: 'POST', | ||
url: Parse.serverURL + '/verifyPassword', | ||
headers: { | ||
'X-Parse-Master-Key': Parse.masterKey, | ||
'X-Parse-Application-Id': Parse.applicationId, | ||
'X-Parse-REST-API-Key': 'rest', | ||
'Content-Type': 'application/json', | ||
}, | ||
body: { | ||
username: 'user', | ||
password: 'pass', | ||
ignoreEmailVerification: true, | ||
}, | ||
json: true, | ||
}); | ||
expect(res.objectId).toBe(user.id); | ||
expect(Object.prototype.hasOwnProperty.call(res, 'sessionToken')).toEqual(false); | ||
expect(Object.prototype.hasOwnProperty.call(res, 'password')).toEqual(false); | ||
}); | ||
|
||
it('fails to verify password of user with unverified email with master key and ignoreEmailVerification=false', async () => { | ||
await reconfigureServer({ | ||
publicServerURL: 'http://localhost:8378/', | ||
appName: 'emailVerify', | ||
verifyUserEmails: true, | ||
preventLoginWithUnverifiedEmail: true, | ||
emailAdapter: MockEmailAdapterWithOptions({ | ||
fromAddress: '[email protected]', | ||
apiKey: 'k', | ||
domain: 'd', | ||
}), | ||
}); | ||
|
||
const user = new Parse.User(); | ||
user.setUsername('user'); | ||
user.setPassword('pass'); | ||
user.setEmail('[email protected]'); | ||
await user.signUp(); | ||
|
||
const res = await request({ | ||
method: 'POST', | ||
url: Parse.serverURL + '/verifyPassword', | ||
headers: { | ||
'X-Parse-Master-Key': Parse.masterKey, | ||
'X-Parse-Application-Id': Parse.applicationId, | ||
'X-Parse-REST-API-Key': 'rest', | ||
'Content-Type': 'application/json', | ||
}, | ||
body: { | ||
username: 'user', | ||
password: 'pass', | ||
ignoreEmailVerification: false, | ||
}, | ||
json: true, | ||
}).catch(e => e); | ||
expect(res.status).toBe(400); | ||
expect(res.text).toMatch(/User email is not verified/); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters