Ejemplo n.º 1
0
func TestAuthenticate(t *testing.T) {
	setUp()
	defer tearDown()

	w := httptest.NewRecorder()

	// Register.

	pro := New()
	auth.Register("appengine_openid", pro)

	// Round 1: Now User.

	req, _ := http.NewRequest("GET",
		"http://*****:*****@example.org")
	// 	req.Header.Set("X-AppEngine-Inbound-User-Federated-Identity", "gmail.com")
	// 	req.Header.Set("X-AppEngine-Inbound-User-Federated-Provider", "google")
	// 	req.Header.Set("X-AppEngine-Inbound-User-Id", "12345")
	// 	req.Header.Set("X-AppEngine-Inbound-User-Is-Admin", "0")
	//
	// 	// Process.
	//
	// 	up = user_profile.New()
	// 	url, err = pro.Authenticate(w, req, up)
	//
	// 	// Check.
	//
	// 	t.Fatalf(`up.Person: %v`, up.Person)
	//
	// 	if x := up.ProviderURL; x != "gmail.com" {
	// 		t.Errorf(`ProviderURL: %q, want %v`, x, "gmail.com")
	// 	}
	// 	if x := up.Person.Emails[0].Value; x != "*****@*****.**" {
	// 		t.Errorf(`Email.Value: %v, want %v`, x, "*****@*****.**")
	// 	}
}
Ejemplo n.º 2
0
func setup() *Provider {
	// Register.
	pro := New()
	startOnce.Do(func() {
		auth.Register("password", pro)
	})
	return pro
}
Ejemplo n.º 3
0
func TestAuthenticate(t *testing.T) {
	setUp()
	defer tearDown()

	w := httptest.NewRecorder()

	// Register.

	pro := New()
	auth.Register("dev", pro)

	// Post.
	v := url.Values{}
	v.Set("ID", "1")
	v.Set("Gender", "male")
	v.Set("Name.GivenName", "Barack")
	v.Set("Name.FamilyName", "Obama")
	v.Set("AboutMe", "This is a bio about me.")
	body := strings.NewReader(v.Encode())

	req, _ := http.NewRequest("POST", "http://localhost:8080/-/auth/dev", body)

	req.Header.Set("Content-Type", "application/x-www-form-urlencoded;")

	// TODO(kylefinley) for some reason is if this isn't call here the form will
	// be empty in the Authentication method? Perhaps this is a bug.
	if id := req.FormValue("ID"); id != "1" {
		t.Errorf(`req.FormValue("ID") = %q, want "1"`, id)
	}

	// Process.

	up, url, err := pro.Authenticate(w, req)

	// Check.

	if url != "" {
		t.Errorf(`url: %v, want: ""`, url)
	}
	if err != nil {
		t.Errorf(`err: %v, want: %v`, err, nil)
	}

	per := up.Person

	if x := per.Name.GivenName; x != "Barack" {
		t.Errorf(`per.Name.GivenName: %q, want %v`, x, "Barack")
	}
	if x := per.Name.FamilyName; x != "Obama" {
		t.Errorf(`per.Name.FamilyName: %q, want %v`, x, "Obama")
	}
}