Ejemplo n.º 1
0
func (s *AccessSuite) TestNotAllowedIP(c *C) {
	mc := httputils.NewMockContext()
	mc.GetHttpRequest().RemoteAddr = "127.0.0.2:80"
	resp, err := s.access.ProcessRequest(mc)
	c.Assert(resp, IsNil)
	c.Assert(err.(*errors.HttpError).GetStatusCode(), Equals, http.StatusForbidden)
}
Ejemplo n.º 2
0
func (s *AccessSuite) TestHappyPath(c *C) {
	mc := httputils.NewMockContext()
	mc.GetHttpRequest().RemoteAddr = "127.0.0.1:80"
	resp, err := s.access.ProcessRequest(mc)
	c.Assert(resp, IsNil)
	c.Assert(err, IsNil)
}
Ejemplo n.º 3
0
func (s *BasicAuthSuite) TestIncorrectFormat(c *C) {
	mc := httputils.NewMockContext()
	mc.GetHttpRequest().Header = make(map[string][]string)
	mc.GetHttpRequest().Header.Set("Authorization", "d3Jvbmc6d3Jvbmc=") //missing the prefix `Basic`
	resp, err := s.ba.ProcessRequest(mc)
	c.Assert(resp, IsNil)
	c.Assert(err.(*errors.HttpError).GetStatusCode(), Equals, http.StatusBadRequest)
}
Ejemplo n.º 4
0
func (s *BasicAuthSuite) TestWrongCredentials(c *C) {
	mc := httputils.NewMockContext()
	mc.GetHttpRequest().Header = make(map[string][]string)
	mc.GetHttpRequest().Header.Set("Authorization", "Basic d3Jvbmc6d3Jvbmc=") //wrong:wrong
	resp, err := s.ba.ProcessRequest(mc)
	c.Assert(resp, IsNil)
	c.Assert(err.(*errors.HttpError).GetStatusCode(), Equals, http.StatusForbidden)
}
Ejemplo n.º 5
0
func (s *BasicAuthSuite) TestHappyPath(c *C) {
	mc := httputils.NewMockContext()
	mc.GetHttpRequest().Header = make(map[string][]string)
	mc.GetHttpRequest().Header.Set("Authorization", "Basic anRlZGlsbGE6cGFzcw==")
	resp, err := s.ba.ProcessRequest(mc)
	c.Assert(resp, IsNil)
	c.Assert(err, IsNil)
}