Esempio n. 1
0
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
}
Esempio n. 2
0
func (w *Worker) LoginWithFail(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.WrongPassword,
	}
	login.ExpectedStatusCode = 200
	login.ExpectedLocation = "/"
	login.ExpectedHTML = map[string]string{
		"//*[@id='notice-message']": "Wrong username or password",
	}
	login.ExpectedAssets = defaultExpectedAssets

	err = login.Play(w)

	return err
}