forked from pocketbase/pocketbase
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d5775ff
commit 9b880f5
Showing
102 changed files
with
3,664 additions
and
957 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,6 +48,20 @@ func TestAdminAuthWithEmail(t *testing.T) { | |
ExpectedStatus: 400, | ||
ExpectedContent: []string{`"data":{}`}, | ||
}, | ||
{ | ||
Name: "valid email/password (guest)", | ||
Method: http.MethodPost, | ||
Url: "/api/admins/auth-with-password", | ||
Body: strings.NewReader(`{"identity":"[email protected]","password":"1234567890"}`), | ||
ExpectedStatus: 200, | ||
ExpectedContent: []string{ | ||
`"admin":{"id":"sywbhecnh46rhm0"`, | ||
`"token":`, | ||
}, | ||
ExpectedEvents: map[string]int{ | ||
"OnAdminAuthRequest": 1, | ||
}, | ||
}, | ||
{ | ||
Name: "valid email/password (already authorized)", | ||
Method: http.MethodPost, | ||
|
@@ -56,14 +70,6 @@ func TestAdminAuthWithEmail(t *testing.T) { | |
RequestHeaders: map[string]string{ | ||
"Authorization": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6InN5d2JoZWNuaDQ2cmhtMCIsInR5cGUiOiJhZG1pbiIsImV4cCI6MjIwODk4MTYwMH0.han3_sG65zLddpcX2ic78qgy7FKecuPfOpFa8Dvi5Bg", | ||
}, | ||
ExpectedStatus: 400, | ||
ExpectedContent: []string{`"message":"The request can be accessed only by guests.","data":{}`}, | ||
}, | ||
{ | ||
Name: "valid email/password (guest)", | ||
Method: http.MethodPost, | ||
Url: "/api/admins/auth-with-password", | ||
Body: strings.NewReader(`{"identity":"[email protected]","password":"1234567890"}`), | ||
ExpectedStatus: 200, | ||
ExpectedContent: []string{ | ||
`"admin":{"id":"sywbhecnh46rhm0"`, | ||
|
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 |
---|---|---|
|
@@ -66,26 +66,6 @@ func TestRecordAuthMethodsList(t *testing.T) { | |
|
||
func TestRecordAuthWithPassword(t *testing.T) { | ||
scenarios := []tests.ApiScenario{ | ||
{ | ||
Name: "authenticated record", | ||
Method: http.MethodPost, | ||
Url: "/api/collections/users/auth-with-password", | ||
RequestHeaders: map[string]string{ | ||
"Authorization": "eyJhbGciOiJIUzI1NiJ9.eyJpZCI6IjRxMXhsY2xtZmxva3UzMyIsInR5cGUiOiJhdXRoUmVjb3JkIiwiY29sbGVjdGlvbklkIjoiX3BiX3VzZXJzX2F1dGhfIiwiZXhwIjoyMjA4OTg1MjYxfQ.UwD8JvkbQtXpymT09d7J6fdA0aP9g4FJ1GPh_ggEkzc", | ||
}, | ||
ExpectedStatus: 400, | ||
ExpectedContent: []string{`"data":{}`}, | ||
}, | ||
{ | ||
Name: "authenticated admin", | ||
Method: http.MethodPost, | ||
Url: "/api/collections/users/auth-with-password", | ||
RequestHeaders: map[string]string{ | ||
"Authorization": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6InN5d2JoZWNuaDQ2cmhtMCIsInR5cGUiOiJhZG1pbiIsImV4cCI6MjIwODk4NTI2MX0.M1m--VOqGyv0d23eeUc0r9xE8ZzHaYVmVFw1VZW6gT8", | ||
}, | ||
ExpectedStatus: 400, | ||
ExpectedContent: []string{`"data":{}`}, | ||
}, | ||
{ | ||
Name: "invalid body format", | ||
Method: http.MethodPost, | ||
|
@@ -226,6 +206,52 @@ func TestRecordAuthWithPassword(t *testing.T) { | |
"OnRecordAuthRequest": 1, | ||
}, | ||
}, | ||
|
||
// with already authenticated record or admin | ||
{ | ||
Name: "authenticated record", | ||
Method: http.MethodPost, | ||
Url: "/api/collections/users/auth-with-password", | ||
RequestHeaders: map[string]string{ | ||
"Authorization": "eyJhbGciOiJIUzI1NiJ9.eyJpZCI6IjRxMXhsY2xtZmxva3UzMyIsInR5cGUiOiJhdXRoUmVjb3JkIiwiY29sbGVjdGlvbklkIjoiX3BiX3VzZXJzX2F1dGhfIiwiZXhwIjoyMjA4OTg1MjYxfQ.UwD8JvkbQtXpymT09d7J6fdA0aP9g4FJ1GPh_ggEkzc", | ||
}, | ||
Body: strings.NewReader(`{ | ||
"identity":"[email protected]", | ||
"password":"1234567890" | ||
}`), | ||
ExpectedStatus: 200, | ||
ExpectedContent: []string{ | ||
`"record":{`, | ||
`"token":"`, | ||
`"id":"4q1xlclmfloku33"`, | ||
`"email":"[email protected]"`, | ||
}, | ||
ExpectedEvents: map[string]int{ | ||
"OnRecordAuthRequest": 1, | ||
}, | ||
}, | ||
{ | ||
Name: "authenticated admin", | ||
Method: http.MethodPost, | ||
Url: "/api/collections/users/auth-with-password", | ||
RequestHeaders: map[string]string{ | ||
"Authorization": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6InN5d2JoZWNuaDQ2cmhtMCIsInR5cGUiOiJhZG1pbiIsImV4cCI6MjIwODk4NTI2MX0.M1m--VOqGyv0d23eeUc0r9xE8ZzHaYVmVFw1VZW6gT8", | ||
}, | ||
Body: strings.NewReader(`{ | ||
"identity":"[email protected]", | ||
"password":"1234567890" | ||
}`), | ||
ExpectedStatus: 200, | ||
ExpectedContent: []string{ | ||
`"record":{`, | ||
`"token":"`, | ||
`"id":"4q1xlclmfloku33"`, | ||
`"email":"[email protected]"`, | ||
}, | ||
ExpectedEvents: map[string]int{ | ||
"OnRecordAuthRequest": 1, | ||
}, | ||
}, | ||
} | ||
|
||
for _, scenario := range scenarios { | ||
|
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
Oops, something went wrong.