mirror of
https://github.com/ultravioletrs/cocos.git
synced 2026-06-23 04:10:25 +00:00
27db9b29eb
CI / lint (push) Has been cancelled
CI / test (agent) (push) Has been cancelled
CI / test (cli) (push) Has been cancelled
CI / test (cmd) (push) Has been cancelled
CI / test (internal) (push) Has been cancelled
CI / test (manager, true) (push) Has been cancelled
CI / test (pkg) (push) Has been cancelled
CI / upload-coverage (push) Has been cancelled
* Added GPU evidence collection * Added GPU evidence verification * Added make command for nvattest helper * Added command for installing all services * changed attestion-service.service so it knows where the helper is * Possible IGVM script bug * Possible bug * Bug * bug * Revert "bug" This reverts commitd81d67e73d. * Revert "Bug" This reverts commit5e566d53c1. * Revert "Possible bug" This reverts commit47d13fe583. * Revert "Possible IGVM script bug" This reverts commit3fb1b79537. * Revert "changed attestion-service.service so it knows where the helper is" This reverts commitf9f11ed183. * Revert "Added command for installing all services" This reverts commit5dcf7a5c0a. * NOISSUE - Enforce binding label check (#589) * NOISSUE - Implement extensible resource downloader framework with support for S3, GCS, and OCI sources (#590) * feat: implement extensible resource downloader framework with support for S3, GCS, and OCI sources Signed-off-by: SammyOina <sammyoina@gmail.com> * refactor: improve resource URL parsing and add support for bare OCI image references Signed-off-by: Sammy Oina <sammyoina@gmail.com> * fix: add empty string check and slash requirement for OCI image inference, and update python unit tests with event mock expectations Signed-off-by: Sammy Oina <sammyoina@gmail.com> * refactor: introduce OCIClient interface, add test coverage for decryption, and improve resource download error handling Signed-off-by: Sammy Oina <sammyoina@gmail.com> * chore: remove trailing whitespace in OCI downloader and HTTP tests Signed-off-by: Sammy Oina <sammyoina@gmail.com> --------- Signed-off-by: SammyOina <sammyoina@gmail.com> Signed-off-by: Sammy Oina <sammyoina@gmail.com> * Refactored baed on comments * Added GPU evidence collection * Added GPU evidence verification * Added make command for nvattest helper * Added command for installing all services * changed attestion-service.service so it knows where the helper is * Possible IGVM script bug * Possible bug * Bug * bug * Revert "bug" This reverts commitd81d67e73d. * Revert "Bug" This reverts commit5e566d53c1. * Revert "Possible bug" This reverts commit47d13fe583. * Revert "Possible IGVM script bug" This reverts commit3fb1b79537. * Revert "changed attestion-service.service so it knows where the helper is" This reverts commitf9f11ed183. * Revert "Added command for installing all services" This reverts commit5dcf7a5c0a. * Refactored baed on comments * fixed lint error * fixed tests * Fixed according to comments * COCOS-584 - Support multiple kbs (#587) * feat: Implement per-resource KBS configuration, allowing algorithms and datasets to specify individual KBS URLs. Signed-off-by: Sammy Oina <sammyoina@gmail.com> * refactor: Encapsulate CLI error handling and CVM certificate paths within the CLI struct, and add algorithm type to agent's algorithm structure. Signed-off-by: Sammy Oina <sammyoina@gmail.com> * style: Remove blank lines and fix indentation in CLI commands. Signed-off-by: Sammy Oina <sammyoina@gmail.com> * refactor: Update downloadAndDecryptGenericResource to accept KBS URL as a parameter and adjust related tests Signed-off-by: Sammy Oina <sammyoina@gmail.com> * refactor: group CLI configuration into structured types and simplify skopeo decryption key handling Signed-off-by: Sammy Oina <sammyoina@gmail.com> --------- Signed-off-by: Sammy Oina <sammyoina@gmail.com> * Added GPU evidence collection * Added GPU evidence verification * Added make command for nvattest helper * Added command for installing all services * changed attestion-service.service so it knows where the helper is * Possible IGVM script bug * Possible bug * Bug * bug * Revert "bug" This reverts commitd81d67e73d. * Revert "Bug" This reverts commit5e566d53c1. * Revert "Possible bug" This reverts commit47d13fe583. * Revert "Possible IGVM script bug" This reverts commit3fb1b79537. * Revert "changed attestion-service.service so it knows where the helper is" This reverts commitf9f11ed183. * Revert "Added command for installing all services" This reverts commit5dcf7a5c0a. * Refactored baed on comments * Added GPU evidence collection * Added GPU evidence verification * Added make command for nvattest helper * Added command for installing all services * changed attestion-service.service so it knows where the helper is * Possible IGVM script bug * Possible bug * Bug * bug * Revert "bug" This reverts commitd81d67e73d. * Revert "Bug" This reverts commit5e566d53c1. * Revert "Possible bug" This reverts commit47d13fe583. * Revert "Possible IGVM script bug" This reverts commit3fb1b79537. * Revert "changed attestion-service.service so it knows where the helper is" This reverts commitf9f11ed183. * Revert "Added command for installing all services" This reverts commit5dcf7a5c0a. * Refactored baed on comments * fixed lint error * fixed tests * Fixed according to comments --------- Signed-off-by: SammyOina <sammyoina@gmail.com> Signed-off-by: Sammy Oina <sammyoina@gmail.com> Co-authored-by: Danko Miladinovic <72250944+danko-miladinovic@users.noreply.github.com> Co-authored-by: Sammy Kerata Oina <44265300+SammyOina@users.noreply.github.com>
226 lines
4.7 KiB
Go
226 lines
4.7 KiB
Go
// Copyright (c) Ultraviolet
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package eat
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/ultravioletrs/cocos/pkg/attestation"
|
|
)
|
|
|
|
func TestNewEATClaims(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
nonce []byte
|
|
expectedErr string
|
|
}{
|
|
{
|
|
name: "Valid nonce",
|
|
nonce: []byte("12345678"),
|
|
expectedErr: "",
|
|
},
|
|
{
|
|
name: "Nonce too short",
|
|
nonce: []byte("1234567"),
|
|
expectedErr: "eat_nonce must be at least 8 bytes long",
|
|
},
|
|
{
|
|
name: "Empty nonce",
|
|
nonce: []byte{},
|
|
expectedErr: "eat_nonce must be at least 8 bytes long",
|
|
},
|
|
{
|
|
name: "Nil nonce",
|
|
nonce: nil,
|
|
expectedErr: "eat_nonce must be at least 8 bytes long",
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
_, err := NewEATClaims([]byte("dummy report"), tt.nonce, attestation.NoCC)
|
|
if tt.expectedErr != "" {
|
|
assert.EqualError(t, err, tt.expectedErr)
|
|
} else {
|
|
assert.NoError(t, err)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestSanitize(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
claims *EATClaims
|
|
expected *EATClaims
|
|
}{
|
|
{
|
|
name: "All dependencies present",
|
|
claims: &EATClaims{
|
|
OEMID: 123,
|
|
HWModel: []byte("ValidModel"),
|
|
HWVersion: "1.0",
|
|
},
|
|
expected: &EATClaims{
|
|
OEMID: 123,
|
|
HWModel: []byte("ValidModel"),
|
|
HWVersion: "1.0",
|
|
},
|
|
},
|
|
{
|
|
name: "Missing OEMID clears HWModel and HWVersion",
|
|
claims: &EATClaims{
|
|
OEMID: 0,
|
|
HWModel: []byte("ValidModel"),
|
|
HWVersion: "1.0",
|
|
},
|
|
expected: &EATClaims{
|
|
OEMID: 0,
|
|
HWModel: nil,
|
|
HWVersion: "",
|
|
},
|
|
},
|
|
{
|
|
name: "Missing HWModel clears HWVersion",
|
|
claims: &EATClaims{
|
|
OEMID: 123,
|
|
HWModel: nil,
|
|
HWVersion: "1.0",
|
|
},
|
|
expected: &EATClaims{
|
|
OEMID: 123,
|
|
HWModel: nil,
|
|
HWVersion: "",
|
|
},
|
|
},
|
|
{
|
|
name: "Missing HWModel (empty bytes) clears HWVersion",
|
|
claims: &EATClaims{
|
|
OEMID: 123,
|
|
HWModel: []byte{},
|
|
HWVersion: "1.0",
|
|
},
|
|
expected: &EATClaims{
|
|
OEMID: 123,
|
|
HWModel: []byte{}, // Should remain empty slice
|
|
HWVersion: "",
|
|
},
|
|
},
|
|
{
|
|
name: "Independent fields unaffected",
|
|
claims: &EATClaims{
|
|
OEMID: 0,
|
|
DebugStatus: DebugEnabled,
|
|
},
|
|
expected: &EATClaims{
|
|
OEMID: 0,
|
|
DebugStatus: DebugEnabled,
|
|
},
|
|
},
|
|
{
|
|
name: "Missing SWName clears SWVersion",
|
|
claims: &EATClaims{
|
|
SWName: "",
|
|
SWVersion: "1.0.0",
|
|
},
|
|
expected: &EATClaims{
|
|
SWName: "",
|
|
SWVersion: "",
|
|
},
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
tt.claims.Sanitize()
|
|
assert.Equal(t, tt.expected, tt.claims)
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestNewEATClaims_Platforms(t *testing.T) {
|
|
nonce := []byte("12345678")
|
|
dummyReport := make([]byte, 1200) // Large enough for SNP
|
|
|
|
tests := []struct {
|
|
name string
|
|
platform attestation.PlatformType
|
|
expectError bool
|
|
expectedName string
|
|
}{
|
|
{
|
|
name: "SNP",
|
|
platform: attestation.SNP,
|
|
expectError: false,
|
|
expectedName: "SNP",
|
|
},
|
|
{
|
|
name: "vTPM",
|
|
platform: attestation.VTPM,
|
|
expectError: false,
|
|
expectedName: "vTPM",
|
|
},
|
|
{
|
|
name: "Azure",
|
|
platform: attestation.Azure,
|
|
expectError: false,
|
|
expectedName: "Azure",
|
|
},
|
|
{
|
|
name: "NoCC",
|
|
platform: attestation.NoCC,
|
|
expectError: false,
|
|
expectedName: "NoCC",
|
|
},
|
|
{
|
|
name: "Unknown",
|
|
platform: attestation.PlatformType(99),
|
|
expectError: false,
|
|
expectedName: "Unknown",
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
report := dummyReport
|
|
if tt.name == "SNP" {
|
|
report = make([]byte, 2000)
|
|
report[0] = 1 // Version
|
|
}
|
|
claims, err := NewEATClaims(report, nonce, tt.platform)
|
|
if tt.expectError {
|
|
assert.Error(t, err)
|
|
} else if err != nil {
|
|
// Special case for platforms that might fail with dummy data (like TDX)
|
|
t.Logf("Platform %s failed with error: %v (expected for dummy data)", tt.name, err)
|
|
} else {
|
|
assert.NotNil(t, claims)
|
|
assert.Equal(t, tt.expectedName, claims.PlatformType)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestNewEATClaims_WithGPU(t *testing.T) {
|
|
gpuEvidence := &GPUExtensions{
|
|
Vendor: "nvidia",
|
|
EvidenceFormat: "nvat-json",
|
|
Nonce: []byte("gpu-nonce"),
|
|
EvidenceJSON: []byte(`{"evidence":"gpu"}`),
|
|
}
|
|
|
|
claims, err := NewEATClaims(
|
|
[]byte("dummy report"),
|
|
[]byte("12345678"),
|
|
attestation.NoCC,
|
|
WithGPU(gpuEvidence),
|
|
)
|
|
assert.NoError(t, err)
|
|
assert.NotNil(t, claims.GPUExtensions)
|
|
assert.Equal(t, gpuEvidence, claims.GPUExtensions)
|
|
assert.Contains(t, claims.Submods, "gpu")
|
|
assert.Equal(t, gpuEvidence, claims.Submods["gpu"])
|
|
}
|