-
Notifications
You must be signed in to change notification settings - Fork 105
feat(gotrue): add resend api to request confirmation code #435
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
diegofesanto
wants to merge
11
commits into
supabase:master
Choose a base branch
from
diegofesanto:feature/missing-resend
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
e7c01ca
fix(gotrue): change following review
diegofesanto 1c2044b
Merge remote-tracking branch 'origin/master' into feature/missing-resend
diegofesanto 7b59aaa
fix(gotrue): remove full path of parameter
diegofesanto 5fe607b
feat(gotrue): improve patterns and tests
diegofesanto fc6ee98
Merge remote-tracking branch 'origin/master' into feature/missing-resend
diegofesanto 009268b
feat(gotrue): update public api file
diegofesanto faa43a3
chore(gotrue): fix styles
diegofesanto 8cb570c
test(gotrue): create contract tests
diegofesanto 0a9c609
test(gotrue): add contract tests
diegofesanto a13ff1f
feat(gotrue): move creation of the body to the dto
diegofesanto 1a0b39e
Merge remote-tracking branch 'origin/master' into feature/missing-resend
diegofesanto File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
...ractTests.ResendRequest_ShouldSerializeCaptchaToExpectedPayload_GivenOptions.verified.txt
This file contains hidden or 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 @@ | ||
| {"type":"signup","email":"user@supabase.com","gotrue_meta_security":{"captcha_token":"captcha-token"}} |
1 change: 1 addition & 0 deletions
1
...actTests.ResendRequest_ShouldSerializeToExpectedPayload_GivenEmailChangeType.verified.txt
This file contains hidden or 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 @@ | ||
| {"type":"email_change","email":"user@supabase.com"} |
1 change: 1 addition & 0 deletions
1
...actTests.ResendRequest_ShouldSerializeToExpectedPayload_GivenPhoneChangeType.verified.txt
This file contains hidden or 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 @@ | ||
| {"type":"phone_change","phone":"+5544998989898"} |
1 change: 1 addition & 0 deletions
1
...ContractTests.ResendRequest_ShouldSerializeToExpectedPayload_GivenSignUpType.verified.txt
This file contains hidden or 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 @@ | ||
| {"type":"signup","email":"user@supabase.com"} |
1 change: 1 addition & 0 deletions
1
...ersContractTests.ResendRequest_ShouldSerializeToExpectedPayload_GivenSmsType.verified.txt
This file contains hidden or 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 @@ | ||
| {"type":"sms","phone":"+5544998989898"} |
89 changes: 89 additions & 0 deletions
89
packages/Gotrue/Gotrue.Tests/Authentication/ResendParametersContractTests.cs
This file contains hidden or 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,89 @@ | ||
| using System.Threading.Tasks; | ||
| using Gotrue.Tests.Support; | ||
| using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
| using Supabase.Gotrue.Resend; | ||
|
|
||
| namespace Gotrue.Tests.Authentication; | ||
|
|
||
| /// <summary> | ||
| /// Pins the exact bytes the resend requests put on the wire, including the <c>type</c> enum mappings | ||
| /// (<c>signup</c>, <c>sms</c>, <c>phone_change</c>, <c>email_change</c>) and whether the target is sent | ||
| /// as <c>email</c> or <c>phone</c>. | ||
| /// </summary> | ||
| [TestClass] | ||
| [TestCategory("Contract")] | ||
| public class ResendParametersContractTests : RequestApprovalFixture | ||
| { | ||
| [TestMethod] | ||
| public async Task ResendRequest_ShouldSerializeToExpectedPayload_GivenSignUpType() | ||
| { | ||
| const string email = "user@supabase.com"; | ||
| var resend = new ResendParameters( | ||
| type: ResendType.SignUp, | ||
| email: email, | ||
| phone: null, | ||
| options: null | ||
| ); | ||
| await this.Api.Resend(resend); | ||
|
|
||
| await this.Verify(this.EmittedRequestBody).UseDirectory("Data"); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public async Task ResendRequest_ShouldSerializeToExpectedPayload_GivenEmailChangeType() | ||
| { | ||
| const string email = "user@supabase.com"; | ||
| var resend = new ResendParameters( | ||
| type: ResendType.EmailChange, | ||
| email: email, | ||
| phone: null, | ||
| options: null | ||
| ); | ||
| await this.Api.Resend(resend); | ||
|
|
||
| await this.Verify(this.EmittedRequestBody).UseDirectory("Data"); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public async Task ResendRequest_ShouldSerializeToExpectedPayload_GivenPhoneChangeType() | ||
| { | ||
| var resend = new ResendParameters( | ||
| type: ResendType.PhoneChange, | ||
| email: null, | ||
| phone: "+5544998989898", | ||
| options: null | ||
| ); | ||
| await this.Api.Resend(resend); | ||
|
|
||
| await this.Verify(this.EmittedRequestBody).UseDirectory("Data"); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public async Task ResendRequest_ShouldSerializeToExpectedPayload_GivenSmsType() | ||
| { | ||
| var resend = new ResendParameters( | ||
| type: ResendType.Sms, | ||
| email: null, | ||
| phone: "+5544998989898", | ||
| options: null | ||
| ); | ||
| await this.Api.Resend(resend); | ||
|
|
||
| await this.Verify(this.EmittedRequestBody).UseDirectory("Data"); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public async Task ResendRequest_ShouldSerializeCaptchaToExpectedPayload_GivenOptions() | ||
| { | ||
| var resend = new ResendParameters( | ||
| type: ResendType.SignUp, | ||
| email: "user@supabase.com", | ||
| phone: null, | ||
| options: new ResendOptions(captchaToken: "captcha-token", emailRedirectTo: null) | ||
| ); | ||
|
|
||
| await this.Api.Resend(resend); | ||
|
|
||
| await this.Verify(this.EmittedRequestBody).UseDirectory("Data"); | ||
| } | ||
| } |
143 changes: 143 additions & 0 deletions
143
packages/Gotrue/Gotrue.Tests/Authentication/ResendParametersTests.cs
This file contains hidden or 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,143 @@ | ||
| using System.Net; | ||
| using System.Threading.Tasks; | ||
| using Gotrue.Tests.Support; | ||
| using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
| using Supabase.Gotrue.Exceptions; | ||
| using Supabase.Gotrue.Resend; | ||
| using static Gotrue.Tests.TestUtils; | ||
|
|
||
| namespace Gotrue.Tests.Authentication; | ||
|
|
||
| [TestClass] | ||
| [TestCategory("E2E")] | ||
| public class ResendParametersTests : AuthClientFixture | ||
| { | ||
| [TestMethod] | ||
| public async Task Resend_ShouldRequestConfirmationCode_GivenSignUpType() | ||
| { | ||
| var email = RandomEmail(); | ||
| var resend = new ResendParameters( | ||
| type: ResendType.SignUp, | ||
| email: email, | ||
| phone: null, | ||
| options: null | ||
| ); | ||
| var response = await this.Client.Resend(resend); | ||
|
|
||
| Assert.IsNotNull(response); | ||
| Assert.AreEqual(HttpStatusCode.OK, response.ResponseMessage?.StatusCode); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public async Task Resend_ShouldRequestConfirmationCode_GivenSmsType() | ||
| { | ||
| var resend = new ResendParameters( | ||
| type: ResendType.Sms, | ||
| email: null, | ||
| phone: "5544989899898", | ||
| options: null | ||
| ); | ||
| var response = await this.Client.Resend(resend); | ||
|
|
||
| Assert.IsNotNull(response); | ||
| Assert.AreEqual(HttpStatusCode.OK, response.ResponseMessage?.StatusCode); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public async Task Resend_ShouldRequestConfirmationCode_GivenPhoneChangeType() | ||
| { | ||
| var resend = new ResendParameters( | ||
| type: ResendType.PhoneChange, | ||
| email: null, | ||
| phone: "5544989899898", | ||
| options: null | ||
| ); | ||
| var response = await this.Client.Resend(resend); | ||
|
|
||
| Assert.IsNotNull(response); | ||
| Assert.AreEqual(HttpStatusCode.OK, response.ResponseMessage?.StatusCode); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public async Task Resend_ShouldRequestConfirmationCode_GivenEmailChangeType() | ||
| { | ||
| var resend = new ResendParameters( | ||
| type: ResendType.EmailChange, | ||
| email: RandomEmail(), | ||
| phone: null, | ||
| options: null | ||
| ); | ||
| var response = await this.Client.Resend(resend); | ||
|
|
||
| Assert.IsNotNull(response); | ||
| Assert.AreEqual(HttpStatusCode.OK, response.ResponseMessage?.StatusCode); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public async Task Resend_ShouldThrowErrorWhenParameterAreInvalid_GivenPhoneForTypeEmail() | ||
| { | ||
| var resend = new ResendParameters( | ||
| type: ResendType.EmailChange, | ||
| email: null, | ||
| phone: "5544989899898", | ||
| options: null | ||
| ); | ||
|
|
||
| var action = async () => await this.Client.Resend(resend); | ||
|
|
||
| var exception = await Assert.ThrowsAsync<GotrueException>(action); | ||
| Assert.Contains("Missing email address or phone number", exception.Message); | ||
| Assert.Contains("400", exception.Message); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public async Task Resend_ShouldThrowErrorWhenParameterAreInvalid_GivenEmailForTypePhone() | ||
| { | ||
| var resend = new ResendParameters( | ||
| type: ResendType.Sms, | ||
| email: RandomEmail(), | ||
| phone: null, | ||
| options: null | ||
| ); | ||
|
|
||
| var action = async () => await this.Client.Resend(resend); | ||
|
|
||
| var exception = await Assert.ThrowsAsync<GotrueException>(action); | ||
| Assert.Contains("Type provided requires a phone number", exception.Message); | ||
| Assert.Contains("400", exception.Message); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public async Task Resend_ShouldThrowErrorWhenParameterAreInvalid_GivenNothingForTypeEmail() | ||
| { | ||
| var resend = new ResendParameters( | ||
| type: ResendType.EmailChange, | ||
| email: null, | ||
| phone: null, | ||
| options: null | ||
| ); | ||
|
|
||
| var action = async () => await this.Client.Resend(resend); | ||
|
|
||
| var exception = await Assert.ThrowsAsync<GotrueException>(action); | ||
| Assert.Contains("Missing email address or phone number", exception.Message); | ||
| Assert.Contains("400", exception.Message); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public async Task Resend_ShouldThrowErrorWhenParameterAreInvalid_GivenNothingForTypePhone() | ||
| { | ||
| var resend = new ResendParameters( | ||
| type: ResendType.Sms, | ||
| email: null, | ||
| phone: null, | ||
| options: null | ||
| ); | ||
|
|
||
| var action = async () => await this.Client.Resend(resend); | ||
|
|
||
| var exception = await Assert.ThrowsAsync<GotrueException>(action); | ||
| Assert.Contains("Type provided requires a phone number", exception.Message); | ||
| Assert.Contains("400", exception.Message); | ||
| } | ||
| } | ||
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.