Exemplo n.º 1
0
func TestEncode(t *testing.T) {
	c := NewCookieSigner("TESTSECRET")

	e.Expect(t, "Cookie value", c.encodeValue("Foo"), "Rm9v.shZ0lvgf-z5Rh7sfuzRZatPN0Y1LCJ54GCf0Tq8X0f8=")
	e.Expect(t, "Full cookie string", c.EncodeCookie(http.Cookie{Name: "userid", Value: "Foo"}).String(), "userid=Rm9v.shZ0lvgf-z5Rh7sfuzRZatPN0Y1LCJ54GCf0Tq8X0f8=")

	cookie, _ := c.DecodeCookie(http.Cookie{Name: "userid", Value: "Rm9v.shZ0lvgf-z5Rh7sfuzRZatPN0Y1LCJ54GCf0Tq8X0f8="})
	e.Expect(t, "Decode valid cookie string", cookie.Value, "Foo")

	_, err := c.DecodeCookie(http.Cookie{Name: "userid", Value: "Rm9av.shZ0lvgf-z5Rh7sfuzRZatPN0Y1LCJ54GCf0Tq8X0f8="})
	e.Expect(t, "Decode invalid cookie string", err.Error(), "illegal base64 data at input byte 4")
}
Exemplo n.º 2
0
func TestParse(t *testing.T) {
	sampleConfig := `
{
  "BindAddress": ":8008",
  "DatabaseConnectionString": "contests/auth/auth",
  "Clients": [
    {
      "Name": "contests",
      "Key": "ContestsAuthDevelopmentPSK"
    }
  ]
}
  `
	var c ApplicationConfig
	Parse([]byte(sampleConfig), &c)
	e.Expect(t, "Bind address", c.BindAddress, ":8008")
	e.Expect(t, "DB connection string", c.DatabaseConnectionString, "contests/auth/auth")
	e.Expect(t, "Number of clients", len(c.Clients), 1)
	e.Expect(t, "Client URI", c.Clients[0].Key, "ContestsAuthDevelopmentPSK")
	e.Expect(t, "Client URI", c.Clients[0].Name, "contests")
}