-
Notifications
You must be signed in to change notification settings - Fork 9
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 #374 from MadAppGang/test_reset_password
add test to reset password function
- Loading branch information
Showing
5 changed files
with
122 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-04/schema#", | ||
"type": "object", | ||
"properties": { | ||
"result": { | ||
"type": "string" | ||
} | ||
}, | ||
"required": [ | ||
"result" | ||
] | ||
} | ||
|
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,101 @@ | ||
package api_test | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestResetPasswordWithCustomURL(t *testing.T) { | ||
data := fmt.Sprintf(` | ||
{ | ||
"email": "%s", | ||
"reset_page_url": "%s" | ||
}`, cfg.User1, "https://customurl.com") | ||
signature, _ := Signature(data, cfg.AppSecret) | ||
|
||
request.Post("/auth/request_reset_password"). | ||
SetHeader("X-Identifo-ClientID", cfg.AppID). | ||
SetHeader("Digest", "SHA-256="+signature). | ||
SetHeader("Content-Type", "application/json"). | ||
BodyString(data). | ||
Expect(t). | ||
AssertFunc(dumpResponse). | ||
Type("json"). | ||
Status(200). | ||
JSONSchema("../../test/artifacts/api/response_ok.json"). | ||
Done() | ||
|
||
// if running local server (the email sever will not be nil then), check the email content | ||
if emailService != nil { | ||
messages := emailService.Messages() | ||
require.GreaterOrEqual(t, len(messages), 1) // at least one message should be send | ||
lastMessage := messages[len(messages)-1] | ||
assert.Contains(t, lastMessage, cfg.User1) | ||
assert.Contains(t, lastMessage, "href=\"https://customurl.com?") | ||
assert.Contains(t, lastMessage, fmt.Sprintf("appId=%s", cfg.AppID)) | ||
fmt.Printf("\nEmail:\n%s\n", lastMessage) | ||
} | ||
} | ||
|
||
func TestResetPasswordWithAppSpecificURL(t *testing.T) { | ||
data := fmt.Sprintf(` | ||
{ | ||
"email": "%s" | ||
}`, cfg.User1) | ||
signature, _ := Signature(data, cfg.AppSecret2) | ||
|
||
request.Post("/auth/request_reset_password"). | ||
SetHeader("X-Identifo-ClientID", cfg.AppID2). | ||
SetHeader("Digest", "SHA-256="+signature). | ||
SetHeader("Content-Type", "application/json"). | ||
BodyString(data). | ||
Expect(t). | ||
AssertFunc(dumpResponse). | ||
Type("json"). | ||
Status(200). | ||
JSONSchema("../../test/artifacts/api/response_ok.json"). | ||
Done() | ||
|
||
// if running local server (the email sever will not be nil then), check the email content | ||
if emailService != nil { | ||
messages := emailService.Messages() | ||
require.GreaterOrEqual(t, len(messages), 1) // at least one message should be send | ||
lastMessage := messages[len(messages)-1] | ||
assert.Contains(t, lastMessage, cfg.User1) | ||
assert.Contains(t, lastMessage, "href=\"http://rewrite.com/login/cusom?") | ||
assert.Contains(t, lastMessage, fmt.Sprintf("appId=%s", cfg.AppID2)) | ||
} | ||
} | ||
|
||
func TestResetPasswordWithDefaultURL(t *testing.T) { | ||
data := fmt.Sprintf(` | ||
{ | ||
"email": "%s" | ||
}`, cfg.User1) | ||
signature, _ := Signature(data, cfg.AppSecret) | ||
|
||
request.Post("/auth/request_reset_password"). | ||
SetHeader("X-Identifo-ClientID", cfg.AppID). | ||
SetHeader("Digest", "SHA-256="+signature). | ||
SetHeader("Content-Type", "application/json"). | ||
BodyString(data). | ||
Expect(t). | ||
AssertFunc(dumpResponse). | ||
Type("json"). | ||
Status(200). | ||
JSONSchema("../../test/artifacts/api/response_ok.json"). | ||
Done() | ||
|
||
// if running local server (the email sever will not be nil then), check the email content | ||
if emailService != nil { | ||
messages := emailService.Messages() | ||
require.GreaterOrEqual(t, len(messages), 1) // at least one message should be send | ||
lastMessage := messages[len(messages)-1] | ||
assert.Contains(t, lastMessage, cfg.User1) | ||
assert.Contains(t, lastMessage, "href=\"http://localhost:8081/web/password/reset?") | ||
assert.Contains(t, lastMessage, fmt.Sprintf("appId=%s", cfg.AppID)) | ||
} | ||
} |