ソースを参照

update auth path test

zhangbiao 5 年 前
コミット
bdbe486e1e
1 ファイル変更26 行追加0 行削除
  1. 26 0
      gtoken/gtoken_test.go

+ 26 - 0
gtoken/gtoken_test.go

@@ -37,6 +37,32 @@ func TestAuthPath(t *testing.T) {
 	authPath(gfToken, t)
 }
 
+func TestAuthPathNoExclude(t *testing.T) {
+	t.Log("auth no exclude path test ")
+	// 启动gtoken
+	gfToken := &gtoken.GfToken{
+		//Timeout:         10 * 1000,
+		AuthPaths:        g.SliceStr{"/user", "/system"}, // 这里是按照前缀拦截,拦截/user /user/list /user/add ...
+		GlobalMiddleware: true,                           // 关闭全局拦截
+	}
+
+	authFlag := gfToken.AuthPath
+	if authFlag("/test") {
+		t.Error("/test auth path error")
+	}
+	if !authFlag("/system/dept") {
+		t.Error("/system/dept auth path error")
+	}
+
+	if !authFlag("/user/info") {
+		t.Error("/user/info auth path error")
+	}
+
+	if !authFlag("/system/user") {
+		t.Error("/system/user auth path error")
+	}
+}
+
 func TestAuthPathExclude(t *testing.T) {
 	t.Log("auth path test ")
 	// 启动gtoken