Skip to content

Commit ad20227

Browse files
kleshKlesh Wong
andauthored
feat: require authentication for /proceed-db-migration endpoint if auth was enabled (#8893)
* feat: require authentication for /proceed-db-migration endpoint if auth was enabled * fix: linting * fix: disable codespell due to it is blocked by asf runner --------- Co-authored-by: Klesh Wong <kleshwong@gmail.com>
1 parent 4ac2c42 commit ad20227

4 files changed

Lines changed: 12 additions & 12 deletions

File tree

.github/workflows/codespell.yml renamed to .github/workflows/codespell.yml.action-blocked-by-asf

File renamed without changes.

backend/server/api/api.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,8 @@ func SetupApiServer(router *gin.Engine) {
127127
router.UseRawPath = true
128128
// router.UnescapePathValues = false
129129

130-
// Endpoint to proceed database migration
131-
router.GET("/proceed-db-migration", func(ctx *gin.Context) {
130+
// Endpoint to proceed database migration (now requires authentication)
131+
router.GET("/proceed-db-migration", auth.RequireAuth(), func(ctx *gin.Context) {
132132
// Execute database migration
133133
errors.Must(services.ExecuteMigration())
134134
// Return success response

backend/server/api/auth/middleware.go

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,15 @@ import (
3434
// and clear its session even when the cookie has lapsed; both handlers
3535
// short-circuit gracefully when no user is set.
3636
var publicPaths = map[string]struct{}{
37-
"/ping": {},
38-
"/ready": {},
39-
"/health": {},
40-
"/version": {},
41-
"/proceed-db-migration": {},
42-
PathMethods: {},
43-
PathLogin: {},
44-
PathCallback: {},
45-
PathLogout: {},
46-
PathUserInfo: {},
37+
"/ping": {},
38+
"/ready": {},
39+
"/health": {},
40+
"/version": {},
41+
PathMethods: {},
42+
PathLogin: {},
43+
PathCallback: {},
44+
PathLogout: {},
45+
PathUserInfo: {},
4746
}
4847

4948
func OIDCAuthentication() gin.HandlerFunc { return defaultService.OIDCAuthentication() }

backend/test/helper/client.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ func ConnectLocalServer(t *testing.T, clientConfig *LocalClientConfig) *DevlakeC
180180
api.CreateAndRunApiServer()
181181
})
182182
}()
183+
// NOTE: /proceed-db-migration now requires authentication. If AUTH_ENABLED=true, this test must provide credentials.
183184
req, err2 := http.NewRequest(http.MethodGet, fmt.Sprintf("%s/proceed-db-migration", addr), nil)
184185
require.NoError(t, err2)
185186
d.forceSendHttpRequest(100, req, func(err errors.Error) bool {

0 commit comments

Comments
 (0)