Skip to content

Commit

Permalink
Add IsEnclave to facilitate testing.
Browse files Browse the repository at this point in the history
This allows unit tests to skip a test if we're not running inside an
enclave.
  • Loading branch information
NullHypothesis committed Oct 19, 2024
1 parent dcdef70 commit 387575e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
14 changes: 11 additions & 3 deletions internal/enclave/pcr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,17 @@ import (
)

func TestGetPCRs(t *testing.T) {
_, err := getPCRs()
// We expect an error when asking for PCRs outside of an enclave.
require.Error(t, err)
if !IsEnclave() {
t.Skip("skipping test; not running in an enclave")
}

pcrs1, err := getPCRs()
require.NoError(t, err)

pcrs2, err := getPCRs()
require.NoError(t, err)

assert.False(t, pcrs1.Equal(pcrs2))
}

func TestPCRsEqual(t *testing.T) {
Expand Down
11 changes: 11 additions & 0 deletions internal/enclave/util.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package enclave

// IsEnclave returns true if the current process is running in an enclave.
func IsEnclave() bool {
// The most straightforward way to determine if we're running in an enclave
// is to try and request an attestation document.
if _, err := getPCRs(); err == nil {
return true
}
return false
}

0 comments on commit 387575e

Please sign in to comment.