Ejemplo n.º 1
0
)

var testParams = map[string]interface{}{
	"username": "******",
	"password": "******",
}

// go test -test.run="^TestBasicAuth"
func TestBasicAuth(t *testing.T) { TestingT(t) }

type BasicAuthSuite struct {
	ba *BasicAuth
}

var _ = Suite(&BasicAuthSuite{
	ba: NewBasicAuth(modules.ToModuleParams(testParams)),
})

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)
}

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
Ejemplo n.º 2
0
)

var testParams = map[string]interface{}{
	"allow": "127.0.0.1, :::1",
	"deny":  "all",
}

// go test -test.run="^TestAccess$"
func TestAccess(t *testing.T) { TestingT(t) }

type AccessSuite struct {
	access *Access
}

var _ = Suite(&AccessSuite{
	access: NewAccess(modules.ToModuleParams(testParams)),
})

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)
}

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)