func (w *Worker) Login(from *ip.IP, user *user.User) error { if from.IsBlacklisted() || user.IsBlacklisted() { return w.LoginWithBlocked(from, user) } n := rand.Intn(10) if n < 6 && from.D()%3 == 0 { return w.LoginWithSuccess(from, user) } else { return w.LoginWithFail(from, user) } }
func (w *Worker) LoginWithBlocked(from *ip.IP, user *user.User) error { defer w.Reset() defer func() { from.Fail() user.Fail() }() topPage := NewScenario("GET", "/") topPage.IP = from topPage.ExpectedStatusCode = 200 topPage.ExpectedSelectors = []string{"//input[@name='login']", "//input[@name='password']", "//*[@type='submit']"} topPage.ExpectedAssets = defaultExpectedAssets err := topPage.Play(w) if err != nil { return err } login := NewScenario("POST", "/login") login.IP = from login.PostData = map[string]string{ "login": user.Name, "password": user.RightPassword, } login.ExpectedStatusCode = 200 login.ExpectedLocation = "/" login.ExpectedHTML = map[string]string{ "//*[@id='notice-message']": "This account is locked.", } if from.IsBlacklisted() { login.ExpectedHTML["//*[@id='notice-message']"] = "You're banned." } login.ExpectedAssets = defaultExpectedAssets err = login.Play(w) return err }