Beispiel #1
0
func TestFailAuthorization(t *testing.T) {

	n := negroni.New(httphead.New(), session.New(), authorize())
	n.UseHandler(testReader())
	tr := httptest.NewServer(n)
	defer tr.Close()

	redirectPolicyFunc := func(req *http.Request, via []*http.Request) error {
		return nil
	}

	rq, err := http.NewRequest("GET", tr.URL, nil)
	rq.Header.Add("Accept-Language", "en-US")
	c := &http.Client{CheckRedirect: redirectPolicyFunc}
	_, err = c.Do(rq)
	//fmt.Println(rs.Location())
	assert.NoError(t, err, "Should not contain any error")

}
Beispiel #2
0
func TestAuthorizationReader(t *testing.T) {

	tw := httptest.NewServer(testWriter())
	n := negroni.New(httphead.New(), session.New(), authorize())
	n.UseHandler(testReader())
	tr := httptest.NewServer(n)
	defer tw.Close()
	defer tr.Close()

	c := &http.Client{}
	rs, err := c.Get(tw.URL)
	assert.NoError(t, err, "Should not contain any error")

	rq, err := http.NewRequest("GET", tr.URL, nil)
	assert.NoError(t, err, "Should not contain any error")
	rq.AddCookie(rs.Cookies()[0])
	rs.Header.Add("Accept-Language", "en-US")
	rs, err = c.Do(rq)

	buffer := new(bytes.Buffer)
	io.Copy(buffer, rs.Body)
	assert.Contains(t, buffer.String(), "You are signed", "User should be signed.")

}
Beispiel #3
0
// Return all middlwares
func New() []negroni.Handler {
	return []negroni.Handler{session.New(), httphead.New(), security.New(), auth.New()}
}