Esempio n. 1
0
func TestExtractFormFromURL(t *testing.T) {
	form, err := sweet.FromURL("https://github.com/login").SelectForm(".auth-form form")

	if err != nil {
		t.Errorf("Expected nil, got", err)
	}

	expectedFormAction := "/session"
	expectedFormMethod := "POST"

	if form.Action != expectedFormAction {
		t.Errorf("Expected %v, got %v", expectedFormAction, form.Action)
	}

	if form.Method != expectedFormMethod {
		t.Errorf("Expected %v, got %v", expectedFormMethod, form.Method)
	}

	if form.Fields.Get("login") != "" {
		t.Errorf("Expected empty, got %v", form.Fields.Get("login"))
	}

	if form.Fields.Get("password") != "" {
		t.Errorf("Expected empty, got %v", form.Fields.Get("password"))
	}

	if form.Fields.Get("authenticity_token") == "" {
		t.Errorf("Expected not empty")
	}
}
Esempio n. 2
0
func TestTwitterLogin(t *testing.T) {
	form, err := sweet.FromURL("https://twitter.com/login").SelectForm("form.signin")
	if err != nil {
		t.Errorf("Expected nil, got", err)
	}

	form.Fields.Set("session[username_or_email]", "user")
	form.Fields.Set("session[password]", "pass")

	_, session, err := form.Submit()
	if err != nil {
		t.Errorf("Expected nil, got", err)
	}

	if _, authTokenFound := session["auth_token"]; !authTokenFound {
		t.Error("Expected response to have cookie auth_token")
	}
}
Esempio n. 3
0
func TestGithubLogin(t *testing.T) {
	form, err := sweet.FromURL("https://github.com/login").SelectForm(".auth-form form")
	if err != nil {
		t.Errorf("Expected nil, got", err)
	}

	form.Fields.Set("login", "user")
	form.Fields.Set("password", "pass")

	_, session, err := form.SetEndpoint("https://github.com").Submit()
	if err != nil {
		t.Errorf("Expected nil, got", err)
	}

	if _, userSession := session["user_session"]; !userSession {
		t.Error("Expected response to have cookie user_session")
	}
}