Skip to content

Commit

Permalink
add accessor methods Name and Key
Browse files Browse the repository at this point in the history
  • Loading branch information
chmike committed Apr 15, 2020
1 parent 7b40d15 commit 759bbb8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
10 changes: 10 additions & 0 deletions securecookie.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,11 @@ func checkChars(s string, isValid func(c byte) bool) error {
return nil
}

// Name return the securecookie name field value.
func (o *Obj) Name() string {
return o.name
}

// Path returns the securecookie path field value.
func (o *Obj) Path() string {
return o.path
Expand All @@ -336,6 +341,11 @@ func (o *Obj) Secure() bool {
return o.secure
}

// Key returns the securecookie Key.
func (o *Obj) Key() []byte {
return o.key
}

// SetValue adds the securecookie with the value v to the server response w.
// The value v is encrypted, signed with a MAC, and encoded in base64.
func (o *Obj) SetValue(w http.ResponseWriter, v []byte) error {
Expand Down
9 changes: 8 additions & 1 deletion securecookie_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"fmt"
"net/http"
"net/http/httptest"
"reflect"
"strings"
"testing"

Expand Down Expand Up @@ -203,7 +204,7 @@ func TestNew(t *testing.T) {
}

func TestAccessorsMethods(t *testing.T) {
key := make([]byte, KeyLen)
key := MustGenerateRandomKey()
name := "test"
params := Params{
Path: "path",
Expand Down Expand Up @@ -231,6 +232,12 @@ func TestAccessorsMethods(t *testing.T) {
if obj.Secure() != params.Secure {
t.Errorf("got secure %t, expected %t", obj.Secure(), params.Secure)
}
if obj.Name() != name {
t.Errorf("got name '%s', expected '%s'", obj.Name(), name)
}
if !reflect.DeepEqual(obj.Key(), key) {
t.Errorf("got key %v, expected %v", obj.Key(), key)
}
}

func TestEncodeBase64(t *testing.T) {
Expand Down

0 comments on commit 759bbb8

Please sign in to comment.