refactor: вынести VK-авторизацию в client/internal/vkauth
Этап 2 плана рефакторинга. Выносит слой VK credentials/captcha/throttle/
lockout из client/main.go в отдельный пакет с инжектируемым хуком token-chain
для тестов.
Интерфейс:
- vkauth.Client{GetCredentials, HandleAuthError, ResetErrors, LockoutUntilUnix}
- vkauth.IsAuthError (package-level)
- vkauth.DefaultAutoSolve / AutoSolveFunc / ManualSolveFunc
Wire-формат и флаги CLI не изменены. client/main.go: 1967 → 1380.
This commit is contained in:
1 parent
322e8db4fa
commit
5bf6dd0399
9 files changed
+1035
-633
No files matched your search
@@ -0,0 +1,38 @@
|
||||
package vkauth
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestCaptchaSolveModeForAttempt(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
t.Run("default flow", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
mode, ok := CaptchaSolveModeForAttempt(0, false)
|
||||
if !ok || mode != CaptchaSolveModeAuto {
|
||||
t.Fatalf("expected first attempt to use auto captcha, got mode=%v ok=%v", mode, ok)
|
||||
}
|
||||
|
||||
mode, ok = CaptchaSolveModeForAttempt(1, false)
|
||||
if !ok || mode != CaptchaSolveModeManual {
|
||||
t.Fatalf("expected second attempt to use manual captcha, got mode=%v ok=%v", mode, ok)
|
||||
}
|
||||
|
||||
if _, ok = CaptchaSolveModeForAttempt(2, false); ok {
|
||||
t.Fatal("expected only two attempts in default flow")
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("manual only flow", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
mode, ok := CaptchaSolveModeForAttempt(0, true)
|
||||
if !ok || mode != CaptchaSolveModeManual {
|
||||
t.Fatalf("expected manual mode on first attempt, got mode=%v ok=%v", mode, ok)
|
||||
}
|
||||
|
||||
if _, ok = CaptchaSolveModeForAttempt(1, true); ok {
|
||||
t.Fatal("expected only one manual captcha attempt when manual mode is forced")
|
||||
}
|
||||
})
|
||||
}
|
||||
Reference in new issue
Block a user