-
Notifications
You must be signed in to change notification settings - Fork 555
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: authentication flow should abort early (#888)
* fix: finish connection once we send auth response * removed interface for now * handle authentication in each route group * tags api tests * typo * testutil improvements * bookmarks api auth * cache update requires owner
- Loading branch information
Showing
9 changed files
with
161 additions
and
39 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
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 |
---|---|---|
@@ -1 +1,47 @@ | ||
package api_v1 | ||
|
||
import ( | ||
"context" | ||
"net/http" | ||
"testing" | ||
"time" | ||
|
||
"github.com/gin-gonic/gin" | ||
"github.com/go-shiori/shiori/internal/http/middleware" | ||
"github.com/go-shiori/shiori/internal/model" | ||
"github.com/go-shiori/shiori/internal/testutil" | ||
"github.com/sirupsen/logrus" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestUpdateBookmarkCache(t *testing.T) { | ||
logger := logrus.New() | ||
ctx := context.TODO() | ||
|
||
g := gin.New() | ||
|
||
_, deps := testutil.GetTestConfigurationAndDependencies(t, ctx, logger) | ||
g.Use(middleware.AuthMiddleware(deps)) | ||
|
||
router := NewBookmarksAPIRoutes(logger, deps) | ||
router.Setup(g.Group("/")) | ||
|
||
account := model.Account{ | ||
Username: "test", | ||
Password: "test", | ||
Owner: false, | ||
} | ||
require.NoError(t, deps.Database.SaveAccount(ctx, account)) | ||
token, err := deps.Domains.Auth.CreateTokenForAccount(&account, time.Now().Add(time.Minute)) | ||
require.NoError(t, err) | ||
|
||
t.Run("require authentication", func(t *testing.T) { | ||
w := testutil.PerformRequest(g, "PUT", "/cache") | ||
require.Equal(t, http.StatusUnauthorized, w.Code) | ||
}) | ||
|
||
t.Run("require owner", func(t *testing.T) { | ||
w := testutil.PerformRequest(g, "PUT", "/cache", testutil.WithHeader(model.AuthorizationHeader, model.AuthorizationTokenType+" "+token)) | ||
require.Equal(t, http.StatusForbidden, w.Code) | ||
}) | ||
} |
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