Skip to content
This repository has been archived by the owner on Aug 7, 2023. It is now read-only.

Commit

Permalink
chore: bring back middleware test
Browse files Browse the repository at this point in the history
  • Loading branch information
ImSoZRious committed Jun 29, 2023
1 parent ea04dc3 commit 9499a02
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 358 deletions.
128 changes: 0 additions & 128 deletions internal/middleware/auth/auth.middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,131 +36,3 @@ func (g *Guard) Validate(ctx rctx.Context) bool {

return true
}

// import (
// "net/http"
// "strings"

// "github.com/isd-sgcu/rpkm66-gateway/internal/dto"
// "github.com/isd-sgcu/rpkm66-gateway/internal/handler/auth"
// "github.com/isd-sgcu/rpkm66-gateway/internal/utils"
// "github.com/isd-sgcu/rpkm66-gateway/config"
// phase "github.com/isd-sgcu/rpkm66-gateway/constant/auth"
// "github.com/isd-sgcu/rpkm66-gateway/pkg/rctx"
// )

// type Guard struct {
// service auth.IService
// excludes map[string]struct{}
// conf config.App
// isValidate bool
// }

// func NewAuthGuard(s auth.IService, e map[string]struct{}, conf config.App) Guard {
// return Guard{
// service: s,
// excludes: e,
// conf: conf,
// isValidate: true,
// }
// }

// func (m *Guard) Use(ctx rctx.Context) {
// m.isValidate = true

// m.Validate(ctx)

// if !m.isValidate {
// return
// }

// if !m.conf.Debug {
// m.CheckConfig(ctx)

// if !m.isValidate {
// return
// }
// }

// ctx.Next()

// }

// func (m *Guard) Validate(ctx rctx.Context) {
// method := ctx.Method()
// path := ctx.Path()

// ids := utils.FindIDFromPath(path)

// path = utils.FormatPath(method, path, ids)
// if utils.IsExisted(m.excludes, path) {
// ctx.Next()
// return
// }

// token := ctx.Token()
// if token == "" {
// ctx.JSON(http.StatusUnauthorized, &dto.ResponseErr{
// StatusCode: http.StatusUnauthorized,
// Message: "Invalid token",
// })
// m.isValidate = false
// return
// }

// payload, errRes := m.service.Validate(token)
// if errRes != nil {
// ctx.JSON(errRes.StatusCode, errRes)
// m.isValidate = false
// return
// }

// ctx.StoreValue("UserId", payload.UserId)
// ctx.Next()
// }

// func (m *Guard) CheckConfig(ctx rctx.Context) {
// method := ctx.Method()
// path := ctx.Path()

// //check whether there is a token in path
// //if token exist, replace token with ":token"
// pathSlice := strings.Split(path, "/")
// //paths which can have a token is "/group/token"
// if pathSlice[1] == "group" {
// if len(pathSlice) > 2 && pathSlice[2] != "members" && pathSlice[2] != "leave" {
// token := pathSlice[2]
// path = strings.Replace(path, token, ":token", 1)
// }
// }

// ids := utils.FindIDFromPath(path)

// path = utils.FormatPath(method, path, ids)

// if utils.IsExisted(m.excludes, path) {
// ctx.Next()
// return
// }

// phses, ok := phase.MapPath2Phase[path]
// if !ok {
// ctx.Next()
// return
// }

// currentPhase := m.conf.Phase
// for _, phs := range phses {
// if phs == currentPhase {
// ctx.Next()
// return
// }
// }

// ctx.JSON(http.StatusForbidden, &dto.ResponseErr{
// StatusCode: http.StatusForbidden,
// Message: "Forbidden Resource",
// Data: nil,
// })
// m.isValidate = false
// }
Loading

0 comments on commit 9499a02

Please sign in to comment.