-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from caru-ini/feat/forgot-password-server
パスワードリセット機能の実装
- Loading branch information
Showing
5 changed files
with
169 additions
and
0 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
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
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
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
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 |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import assert from 'assert'; | ||
import { InbucketAPIClient } from 'inbucket-js-client'; | ||
import { DEFAULT_USER_POOL_CLIENT_ID } from 'service/envValues'; | ||
import { ulid } from 'ulid'; | ||
import { expect, test } from 'vitest'; | ||
import { deleteUser, noCookieClient, testUserName } from './apiClient'; | ||
|
||
test('ForgotPassword', async () => { | ||
const email = `${ulid()}@example.com`; | ||
|
||
await noCookieClient.post({ | ||
headers: { 'x-amz-target': 'AWSCognitoIdentityProviderService.SignUp' }, | ||
body: { | ||
Username: testUserName, | ||
Password: 'Test-client-password2', | ||
UserAttributes: [{ Name: 'email', Value: email }], | ||
ClientId: DEFAULT_USER_POOL_CLIENT_ID, | ||
}, | ||
}); | ||
|
||
await noCookieClient.post({ | ||
headers: { 'x-amz-target': 'AWSCognitoIdentityProviderService.ResendConfirmationCode' }, | ||
body: { ClientId: DEFAULT_USER_POOL_CLIENT_ID, Username: testUserName }, | ||
}); | ||
|
||
assert(process.env.INBUCKET_URL); | ||
|
||
const inbucketClient = new InbucketAPIClient(process.env.INBUCKET_URL); | ||
const inbox = await inbucketClient.mailbox(email); | ||
const message = await inbucketClient.message(email, inbox[0].id); | ||
const res1 = await noCookieClient.post({ | ||
headers: { 'x-amz-target': 'AWSCognitoIdentityProviderService.ConfirmSignUp' }, | ||
body: { | ||
ClientId: DEFAULT_USER_POOL_CLIENT_ID, | ||
ConfirmationCode: message.body.text.trim().split(' ').at(-1) ?? '', | ||
Username: testUserName, | ||
}, | ||
}); | ||
|
||
expect(res1.status).toBe(200); | ||
|
||
await inbucketClient.deleteMessage(email, inbox[0].id); | ||
await inbucketClient.deleteMessage(email, inbox[1].id); | ||
|
||
const res2 = await noCookieClient.$post({ | ||
headers: { 'x-amz-target': 'AWSCognitoIdentityProviderService.ForgotPassword' }, | ||
body: { | ||
ClientId: DEFAULT_USER_POOL_CLIENT_ID, | ||
Username: testUserName, | ||
}, | ||
}); | ||
assert('CodeDeliveryDetails' in res2); | ||
|
||
const inbox2 = await inbucketClient.mailbox(email); | ||
const message2 = await inbucketClient.message(email, inbox2[0].id); | ||
|
||
const res3 = await noCookieClient.post({ | ||
headers: { 'x-amz-target': 'AWSCognitoIdentityProviderService.ConfirmForgotPassword' }, | ||
body: { | ||
ClientId: DEFAULT_USER_POOL_CLIENT_ID, | ||
ConfirmationCode: message2.body.text.trim().split(' ').at(-1) ?? '', | ||
Password: 'Test-client-password2', | ||
Username: testUserName, | ||
}, | ||
}); | ||
|
||
await inbucketClient.deleteMessage(email, inbox2[0].id); | ||
|
||
expect(res3.status).toBe(200); | ||
|
||
await deleteUser(); | ||
}); |