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.
allowed specifying non-context auth model for the file token endpoint
- Loading branch information
1 parent
c937c06
commit a7d5a06
Showing
2 changed files
with
28 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ import ( | |
"testing" | ||
|
||
"github.com/labstack/echo/v5" | ||
"github.com/pocketbase/pocketbase/core" | ||
"github.com/pocketbase/pocketbase/daos" | ||
"github.com/pocketbase/pocketbase/tests" | ||
"github.com/pocketbase/pocketbase/tools/types" | ||
|
@@ -20,8 +21,32 @@ func TestFileToken(t *testing.T) { | |
Name: "unauthorized", | ||
Method: http.MethodPost, | ||
Url: "/api/files/token", | ||
ExpectedStatus: 401, | ||
ExpectedStatus: 400, | ||
ExpectedContent: []string{`"data":{}`}, | ||
ExpectedEvents: map[string]int{ | ||
"OnFileBeforeTokenRequest": 1, | ||
}, | ||
}, | ||
{ | ||
Name: "unauthorized with model and token via hook", | ||
Method: http.MethodPost, | ||
Url: "/api/files/token", | ||
BeforeTestFunc: func(t *testing.T, app *tests.TestApp, e *echo.Echo) { | ||
app.OnFileBeforeTokenRequest().Add(func(e *core.FileTokenEvent) error { | ||
record, _ := app.Dao().FindAuthRecordByEmail("users", "[email protected]") | ||
e.Model = record | ||
e.Token = "test" | ||
return nil | ||
}) | ||
}, | ||
ExpectedStatus: 200, | ||
ExpectedContent: []string{ | ||
`"token":"test"`, | ||
}, | ||
ExpectedEvents: map[string]int{ | ||
"OnFileBeforeTokenRequest": 1, | ||
"OnFileAfterTokenRequest": 1, | ||
}, | ||
}, | ||
{ | ||
Name: "auth record", | ||
|