bzp2010 commented on code in PR #2589:
URL: https://github.com/apache/apisix-dashboard/pull/2589#discussion_r952299187


##########
api/internal/filter/iam/iam_test.go:
##########
@@ -0,0 +1,79 @@
+package iam
+
+import (
+       "errors"
+       "github.com/apache/apisix-dashboard/api/internal/config"
+       "github.com/gin-gonic/gin"
+       "github.com/stretchr/testify/assert"
+       "net/http"
+       "net/http/httptest"
+       "testing"
+)
+
+var cfg = config.NewDefaultConfig()
+
+func performRequest(r http.Handler, method, path string) 
*httptest.ResponseRecorder {
+       req := httptest.NewRequest(method, path, nil)
+       w := httptest.NewRecorder()
+       r.ServeHTTP(w, req)
+       return w
+}
+
+func TestFilter(t *testing.T) {
+       r := gin.Default()
+       r.Use(func(c *gin.Context) {
+               c.Set("identity", "user")
+       })
+       r.Use(Filter(cfg))
+       r.POST("/apisix/admin/user/login", func(ctx *gin.Context) {})
+       r.PUT("/apisix/admin/global_rules/:id", func(ctx *gin.Context) {})
+       r.DELETE("/apisix/admin/stream_routes/:ids", func(ctx *gin.Context) {})
+       r.GET("/*path", func(ctx *gin.Context) {})
+       r.POST("/success", func(ctx *gin.Context) {})
+
+       w := performRequest(r, "POST", "/apisix/admin/user/login")
+       assert.Equal(t, http.StatusOK, w.Code)
+
+       w = performRequest(r, "PUT", "/apisix/admin/global_rules/12")

Review Comment:
   ditto



##########
api/internal/filter/iam/iam_test.go:
##########
@@ -0,0 +1,79 @@
+package iam
+
+import (
+       "errors"
+       "github.com/apache/apisix-dashboard/api/internal/config"
+       "github.com/gin-gonic/gin"
+       "github.com/stretchr/testify/assert"
+       "net/http"
+       "net/http/httptest"
+       "testing"
+)
+
+var cfg = config.NewDefaultConfig()
+
+func performRequest(r http.Handler, method, path string) 
*httptest.ResponseRecorder {
+       req := httptest.NewRequest(method, path, nil)
+       w := httptest.NewRecorder()
+       r.ServeHTTP(w, req)
+       return w
+}
+
+func TestFilter(t *testing.T) {
+       r := gin.Default()
+       r.Use(func(c *gin.Context) {
+               c.Set("identity", "user")
+       })
+       r.Use(Filter(cfg))
+       r.POST("/apisix/admin/user/login", func(ctx *gin.Context) {})
+       r.PUT("/apisix/admin/global_rules/:id", func(ctx *gin.Context) {})
+       r.DELETE("/apisix/admin/stream_routes/:ids", func(ctx *gin.Context) {})
+       r.GET("/*path", func(ctx *gin.Context) {})
+       r.POST("/success", func(ctx *gin.Context) {})
+
+       w := performRequest(r, "POST", "/apisix/admin/user/login")

Review Comment:
   We can replace "POST" to http.MethodPost



##########
api/internal/filter/iam/iam_test.go:
##########
@@ -0,0 +1,79 @@
+package iam
+
+import (
+       "errors"
+       "github.com/apache/apisix-dashboard/api/internal/config"
+       "github.com/gin-gonic/gin"
+       "github.com/stretchr/testify/assert"
+       "net/http"
+       "net/http/httptest"
+       "testing"
+)
+
+var cfg = config.NewDefaultConfig()
+
+func performRequest(r http.Handler, method, path string) 
*httptest.ResponseRecorder {
+       req := httptest.NewRequest(method, path, nil)
+       w := httptest.NewRecorder()
+       r.ServeHTTP(w, req)
+       return w
+}
+
+func TestFilter(t *testing.T) {
+       r := gin.Default()
+       r.Use(func(c *gin.Context) {
+               c.Set("identity", "user")
+       })
+       r.Use(Filter(cfg))
+       r.POST("/apisix/admin/user/login", func(ctx *gin.Context) {})
+       r.PUT("/apisix/admin/global_rules/:id", func(ctx *gin.Context) {})
+       r.DELETE("/apisix/admin/stream_routes/:ids", func(ctx *gin.Context) {})
+       r.GET("/*path", func(ctx *gin.Context) {})
+       r.POST("/success", func(ctx *gin.Context) {})
+
+       w := performRequest(r, "POST", "/apisix/admin/user/login")
+       assert.Equal(t, http.StatusOK, w.Code)
+
+       w = performRequest(r, "PUT", "/apisix/admin/global_rules/12")
+       assert.Equal(t, http.StatusForbidden, w.Code)
+
+       w = performRequest(r, "DELETE", "/apisix/admin/stream_routes/67")
+       assert.Equal(t, http.StatusForbidden, w.Code)
+
+       w = performRequest(r, "GET", "/apisix/admin/ssl/98")
+       assert.Equal(t, http.StatusOK, w.Code)
+
+       w = performRequest(r, "POST", "/success")
+       assert.Equal(t, http.StatusOK, w.Code)
+}
+
+type test struct{}

Review Comment:
   Add `var _ iamDef.Access = test{}` to ensure it follow the definition of 
Access



##########
api/internal/filter/iam/iam_test.go:
##########
@@ -0,0 +1,79 @@
+package iam
+
+import (
+       "errors"
+       "github.com/apache/apisix-dashboard/api/internal/config"
+       "github.com/gin-gonic/gin"
+       "github.com/stretchr/testify/assert"
+       "net/http"
+       "net/http/httptest"
+       "testing"
+)
+
+var cfg = config.NewDefaultConfig()
+
+func performRequest(r http.Handler, method, path string) 
*httptest.ResponseRecorder {
+       req := httptest.NewRequest(method, path, nil)
+       w := httptest.NewRecorder()
+       r.ServeHTTP(w, req)
+       return w
+}
+
+func TestFilter(t *testing.T) {
+       r := gin.Default()
+       r.Use(func(c *gin.Context) {
+               c.Set("identity", "user")
+       })
+       r.Use(Filter(cfg))
+       r.POST("/apisix/admin/user/login", func(ctx *gin.Context) {})
+       r.PUT("/apisix/admin/global_rules/:id", func(ctx *gin.Context) {})
+       r.DELETE("/apisix/admin/stream_routes/:ids", func(ctx *gin.Context) {})
+       r.GET("/*path", func(ctx *gin.Context) {})
+       r.POST("/success", func(ctx *gin.Context) {})
+
+       w := performRequest(r, "POST", "/apisix/admin/user/login")

Review Comment:
   We can replace "POST" to http.MethodPost



##########
api/test/docker/Dockerfile:
##########
@@ -44,7 +44,7 @@ RUN mkdir -p /go/manager-api \
    && apk add ca-certificates \
    && update-ca-certificates \
    && apk add --no-cache libc6-compat \
-   && echo "hosts: files dns" > /etc/nsswitch.conf \
+   && echo "hosts: srcFiles dns" > /etc/nsswitch.conf \

Review Comment:
   don‘t modify it



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to