첫 커밋: 로컬 프로젝트 업로드
This commit is contained in:
42
baron-sso/backend/cmd/keto_test/main.go
Normal file
42
baron-sso/backend/cmd/keto_test/main.go
Normal file
@@ -0,0 +1,42 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"baron-sso-backend/internal/service"
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
)
|
||||
|
||||
func main() {
|
||||
// KetoService 초기화
|
||||
// KETO_READ_URL과 KETO_WRITE_URL은 컨테이너 외부 포트 또는 내부 주소에 맞게 설정 필요
|
||||
os.Setenv("KETO_READ_URL", "http://keto:4466")
|
||||
os.Setenv("KETO_WRITE_URL", "http://keto:4467")
|
||||
|
||||
keto := service.NewKetoService()
|
||||
ctx := context.Background()
|
||||
|
||||
userID := "test-user-id"
|
||||
tenantID := "test-tenant-id"
|
||||
|
||||
fmt.Println("--- Keto ReBAC Test Start ---")
|
||||
|
||||
// 1. 초기 권한 체크 (당연히 거부되어야 함)
|
||||
allowed, _ := keto.CheckPermission(ctx, userID, "Tenant", tenantID, "view")
|
||||
fmt.Printf("1. Initial Check (view): %v (Expected: false)\n", allowed)
|
||||
|
||||
// 2. 관계(Relation) 추가
|
||||
fmt.Println("2. Adding relation: User is member of Tenant...")
|
||||
err := keto.CreateRelation(ctx, "Tenant", tenantID, "members", userID)
|
||||
if err != nil {
|
||||
fmt.Printf("Failed to create relation: %v\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
// 3. 다시 권한 체크 (허용되어야 함)
|
||||
// OPL 정의에 의해 members는 view 권한을 포함함
|
||||
allowed, _ = keto.CheckPermission(ctx, userID, "Tenant", tenantID, "view")
|
||||
fmt.Printf("3. Final Check (view): %v (Expected: true)\n", allowed)
|
||||
|
||||
fmt.Println("--- Test Completed ---")
|
||||
}
|
||||
Reference in New Issue
Block a user