account_handler_spark_shadow_test.go 1.0 KB

1234567891011121314151617181920212223242526272829
  1. package admin
  2. import (
  3. "context"
  4. "net/http"
  5. "testing"
  6. infraerrors "github.com/Wei-Shaw/sub2api/internal/pkg/errors"
  7. "github.com/Wei-Shaw/sub2api/internal/service"
  8. "github.com/stretchr/testify/require"
  9. )
  10. // TestRefreshSingleAccount_RejectsShadow 验证外审第6轮:手动刷新对 spark 影子在调用上游前早拒
  11. // (影子凭据由母账号管理、自身恒空,刷新无意义)。该守卫同时覆盖单账号与批量刷新两入口。
  12. func TestRefreshSingleAccount_RejectsShadow(t *testing.T) {
  13. h := &AccountHandler{} // 影子在使用任何依赖前即返回,无需注入
  14. parentID := int64(5)
  15. shadow := &service.Account{
  16. ID: 9,
  17. Platform: service.PlatformOpenAI,
  18. Type: service.AccountTypeOAuth, // IsOAuth()=true,确保不是先撞 NOT_OAUTH
  19. ParentAccountID: &parentID,
  20. QuotaDimension: service.QuotaDimensionSpark,
  21. }
  22. _, _, err := h.refreshSingleAccount(context.Background(), shadow)
  23. require.Error(t, err, "影子刷新应被早拒")
  24. require.Equal(t, http.StatusBadRequest, infraerrors.Code(err))
  25. }