func TestPut(t *testing.T) { if !active { t.Skip() } secretID, err := uuid.GenerateV4String() if err != nil { t.Fatalf("%v", err) } var secret = []byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0} err = c.Put(secretID, secret) if err != nil { t.Fatalf("%v", err) } out, err := c.Get(secretID) if err != nil { t.Fatalf("%v", err) } if !bytes.Equal(out, secret) { fmt.Printf("out = %x\nsecret = %x\n", out, secret) t.Fatal("secret doesn't match original") } putSecret = secretID }
func TestProvision(t *testing.T) { if !active { t.Skip() } secretID, err := uuid.GenerateV4String() if err != nil { t.Fatalf("%v", err) } secret, err := c.Provision(secretID, 32) if err != nil { t.Fatalf("%v", err) } out, err := c.Get(secretID) if err != nil { t.Fatalf("%v", err) } if !bytes.Equal(out, secret) { fmt.Printf("out = %x\nsecret = %x\n", out, secret) t.Fatal("secret doesn't match original") } provSecret = secretID }
// NewSession creates a new session without authenticating. This should // be used if you are authentication in some way other than // Authenticate. func (store *SessionStore) NewSession() (c *http.Cookie, err error) { var session_id string session_id, err = uuid.GenerateV4String() if err != nil { return } t := time.Now().Add(DefaultExpire) store.Sessions[session_id] = &t c = new(http.Cookie) c.Name = store.Name c.Value = session_id c.Path = "/" c.Secure = false c.HttpOnly = true return }
// NewPSession creates a persistent session, i.e. one that survives the // current session. func (store *SessionStore) NewPSession(age string) (c *http.Cookie, err error) { var session_id string session_id, err = uuid.GenerateV4String() if err != nil { return } dur, err := time.ParseDuration(age) if err != nil { return } t := time.Now().Add(dur) store.Sessions[session_id] = &t c = new(http.Cookie) c.Name = store.Name c.Value = session_id c.Path = "/" c.Expires = *store.Sessions[session_id] c.Secure = false c.HttpOnly = true return }