Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ require (
github.com/google/go-cmp v0.2.0
golang.org/x/crypto v0.0.0-20180723164146-c126467f60eb
)

go 1.13
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
github.com/frankban/quicktest v1.0.0 h1:QgmxFbprE29UG4oL88tGiiL/7VuiBl5xCcz+wJcJhc0=
github.com/frankban/quicktest v1.0.0/go.mod h1:R98jIehRai+d1/3Hv2//jOVCTJhW1VBavT6B6CuGq2k=
github.com/google/go-cmp v0.2.0 h1:+dTQ8DZQJz0Mb/HjFlkptS1FeQ4cWSnN941F8aEG4SQ=
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
Expand Down
2 changes: 1 addition & 1 deletion macaroon.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func (m *Macaroon) Clone() *Macaroon {
m1 := *m
// Ensure that if any caveats are appended to the new
// macaroon, it will copy the caveats.
m1.caveats = m1.caveats[0:len(m1.caveats):len(m1.caveats)]
m1.caveats = append([]Caveat{}, m1.caveats...)
return &m1
}

Expand Down
30 changes: 30 additions & 0 deletions macaroon_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,36 @@ func TestSetLocation(t *testing.T) {
c.Assert(m.Location(), qt.Equals, "another location")
}

func TestClone(t *testing.T) {
c := qt.New(t)
rootKey := []byte("secret")
m := MustNew(rootKey, []byte("some id"), "a location", macaroon.LatestVersion)

caveats := map[string]bool{
"a caveat": true,
}
for cav := range caveats {
m.AddFirstPartyCaveat([]byte(cav))
}

m1 := m.Clone()

c.Assert(m.Location(), qt.Equals, "a location")
c.Assert(m.Caveats()[0].Location, qt.Equals, "")
c.Assert(m1.Location(), qt.Equals, "a location")
c.Assert(m1.Caveats()[0].Location, qt.Equals, "")

// Modify the caveat, causes a change to m, but not m1
m.SetLocation("new location")
m.Caveats()[0].Location = "mars"

c.Assert(m.Location(), qt.Equals, "new location")
c.Assert(m.Caveats()[0].Location, qt.Equals, "mars")
c.Assert(m1.Location(), qt.Equals, "a location")
c.Assert(m1.Caveats()[0].Location, qt.Equals, "")

}

var equalTests = []struct {
about string
m1, m2 macaroonSpec
Expand Down