Skip to content
Merged
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
19 changes: 4 additions & 15 deletions coordinator/manifest/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (

"github.com/edgelesssys/marblerun/coordinator/quote"
"github.com/edgelesssys/marblerun/coordinator/user"
"github.com/edgelesssys/marblerun/util"
"go.uber.org/zap"
)

Expand Down Expand Up @@ -94,26 +95,14 @@ type Marble struct {

// Equal returns true if two Marble definitions are equal.
func (m Marble) Equal(other Marble) bool {
if len(m.TLS) != len(other.TLS) {
if !util.SliceEqualElements(m.TLS, other.TLS) {
return false
}

mTLS := make([]string, len(m.TLS))
copy(mTLS, m.TLS)
otherTLS := make([]string, len(other.TLS))
copy(otherTLS, other.TLS)

sort.Strings(mTLS)
sort.Strings(otherTLS)
for i := range mTLS {
if mTLS[i] != otherTLS[i] {
return false
}
}

return m.Package == other.Package &&
m.MaxActivations == other.MaxActivations &&
m.Parameters.Equal(other.Parameters)
m.Parameters.Equal(other.Parameters) &&
m.DisableSecretBinding == other.DisableSecretBinding
}

// Parameters contains lists for files, environment variables and commandline arguments that should be passed to an application.
Expand Down
6 changes: 6 additions & 0 deletions coordinator/quote/ert.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"fmt"
"strings"

"github.com/edgelesssys/marblerun/util"
"github.com/google/go-cmp/cmp"
)

Expand Down Expand Up @@ -68,6 +69,11 @@ func (p PackageProperties) Equal(other PackageProperties) bool {
return false
}

if !util.SliceEqualElements(p.AcceptedAdvisories, other.AcceptedAdvisories) ||
!util.SliceEqualElements(p.AcceptedTCBStatuses, other.AcceptedTCBStatuses) {
return false
}

return true
}

Expand Down
15 changes: 15 additions & 0 deletions util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ SPDX-License-Identifier: BUSL-1.1
package util

import (
"cmp"
"crypto/rand"
"crypto/rsa"
"crypto/sha256"
Expand All @@ -19,6 +20,7 @@ import (
"log"
"net"
"os"
"slices"

"golang.org/x/crypto/hkdf"
)
Expand Down Expand Up @@ -181,3 +183,16 @@ func IsRawSGXQuote(quote []byte) bool {

return true
}

// SliceEqualElements checks if a slice contains the same elements as another slice.
// Order of elements does not matter.
// Elements must be of type [cmp.Ordered].
func SliceEqualElements[T cmp.Ordered](a, b []T) bool {
aCopy := make([]T, len(a))
bCopy := make([]T, len(b))
copy(aCopy, a)
copy(bCopy, b)
slices.Sort(aCopy)
slices.Sort(bCopy)
return slices.Equal(aCopy, bCopy)
}
37 changes: 37 additions & 0 deletions util/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,3 +150,40 @@ func TestIsRawSGXQuote(t *testing.T) {
})
}
}

func TestSliceEqualElements(t *testing.T) {
testCases := map[string]struct {
sliceA, sliceB []string
want bool
}{
"empty slices": {
sliceA: []string{},
sliceB: []string{},
want: true,
},
"one empty slice": {
sliceA: []string{"foo"},
sliceB: []string{},
want: false,
},
"equal slices": {
sliceA: []string{"foo", "bar"},
sliceB: []string{"foo", "bar"},
want: true,
},
"element order doesn't matter": {
sliceA: []string{"foo", "bar"},
sliceB: []string{"bar", "foo"},
want: true,
},
}

for name, tc := range testCases {
t.Run(name, func(t *testing.T) {
assert := assert.New(t)

assert.Equal(tc.want, SliceEqualElements(tc.sliceA, tc.sliceB))
assert.Equal(tc.want, SliceEqualElements(tc.sliceB, tc.sliceA))
})
}
}