package system import ( "context" "errors" "golang.org/x/crypto/bcrypt" "testing" "time" ) func TestBusinessReviewStateBlocksPasswordAndExistingSession(t *testing.T) { hash, err := bcrypt.GenerateFromPassword([]byte("secret"), bcrypt.MinCost) if err != nil { t.Fatal(err) } for _, status := range []int{1, 2, 3} { user := &User{ID: 7, Username: "business", Password: string(hash), Enable: 1, BusinessStatus: status} security := NewSecurityUsecase(&authenticationSecurityRepo{}, &authenticationCache{}, &authenticationSettings{}, nil) uc := NewAuthenticationUsecase(NewUserUsecase(&authenticationUserRepo{user: user}), security, &authenticationIssuer{}, nil) if _, err := uc.Login(context.Background(), &LoginAttempt{Username: "business", Password: "secret", IP: "127.0.0.1"}); !errors.Is(err, ErrUserDisabled) { t.Fatalf("审核状态 %d 的登录应被拒绝: %v", status, err) } if _, err := uc.currentTokenUser(context.Background(), &AuthClaims{ID: 7, Username: "business", UUID: "uuid", IssuedAt: time.Now()}); !errors.Is(err, ErrUserDisabled) { t.Fatalf("审核状态 %d 的现有会话应被拒绝: %v", status, err) } } }