NOISSUE - Refactor attestation handling: rename AttestationResult to AzureAttestationToken (#504)

* Refactor attestation handling: rename AttestationResult to AzureAttestationToken

- Updated the protobuf definition to change azureAttestationResponse to azureAttestationToken.
- Refactored the Service interface and its implementation to replace AttestationResult with AzureAttestationToken.
- Modified mock functions and tests to reflect the new naming and functionality.
- Adjusted CLI commands to use the new AzureAttestationToken method.
- Removed the AzureToken constant from the attestation package as it is no longer needed.

Signed-off-by: Sammy Oina <sammyoina@gmail.com>

* Remove redundant data checks and logging in SendData and sendData methods

Signed-off-by: Sammy Oina <sammyoina@gmail.com>

* Update agent/api/grpc/server_test.go

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update agent/api/grpc/endpoint_test.go

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Refactor attestation handling: rename AttestationToken to AzureAttestationToken in server and test files

Signed-off-by: Sammy Oina <sammyoina@gmail.com>

* Refactor attestation command output messages for clarity and consistency

Signed-off-by: Sammy Oina <sammyoina@gmail.com>

* Rename AttestationToken to AzureAttestationToken in TestAttestationToken for consistency

Signed-off-by: Sammy Oina <sammyoina@gmail.com>

* Refactor TestChangeAttestationConfiguration to use vtpm.ConvertPolicyToJSON for JSON conversion

Signed-off-by: Sammy Oina <sammyoina@gmail.com>

* Fix: reset temporary file pointer after zipping directory

Signed-off-by: Sammy Oina <sammyoina@gmail.com>

---------

Signed-off-by: Sammy Oina <sammyoina@gmail.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
Sammy Kerata Oina
2025-08-26 15:42:33 +03:00
committed by GitHub
parent 654e22bba5
commit 4b27b98edb
26 changed files with 398 additions and 411 deletions
-1
View File
@@ -20,7 +20,6 @@ const (
SNP PlatformType = iota
VTPM
SNPvTPM
AzureToken
Azure
TDX
NoCC
+6 -6
View File
@@ -28,7 +28,7 @@ type SDK interface {
Result(ctx context.Context, privKey any, resultFile *os.File) error
Attestation(ctx context.Context, reportData [size64]byte, nonce [size32]byte, attType int, attestationFile *os.File) error
IMAMeasurements(ctx context.Context, resultFile *os.File) ([]byte, error)
AttestationResult(ctx context.Context, nonce [size32]byte, attType int, attestationFile *os.File) error
AttestationToken(ctx context.Context, nonce [size32]byte, attType int, attestationFile *os.File) error
}
const (
@@ -157,20 +157,20 @@ func (sdk *agentSDK) Attestation(ctx context.Context, reportData [size64]byte, n
return pb.ReceiveAttestation(attestationProgressDescription, fileSize, stream, attestationFile)
}
func (sdk *agentSDK) AttestationResult(ctx context.Context, nonce [size32]byte, attType int, attestationResultFile *os.File) error {
request := &agent.AttestationResultRequest{
func (sdk *agentSDK) AttestationToken(ctx context.Context, nonce [size32]byte, attType int, attestationTokenFile *os.File) error {
request := &agent.AttestationTokenRequest{
TokenNonce: nonce[:],
Type: int32(attType),
}
result, err := sdk.client.AttestationResult(ctx, request)
result, err := sdk.client.AzureAttestationToken(ctx, request)
if err != nil {
return errors.Wrap(errors.New("failed to fetch attestation token"), err)
}
_, err = attestationResultFile.Write(result.GetFile())
_, err = attestationTokenFile.Write(result.GetFile())
if err != nil {
return errors.Wrap(errors.New("failed to write attestation result to file"), err)
return errors.Wrap(errors.New("failed to write attestation token to file"), err)
}
return nil
+9 -9
View File
@@ -220,7 +220,7 @@ func TestData(t *testing.T) {
Hash: dataHash,
},
userKey: dataProvider1Key,
svcErr: errors.New("dataset CSV file is required"),
svcErr: errors.New("dataset is required"),
},
}
@@ -475,7 +475,7 @@ func TestAttestation(t *testing.T) {
}
}
func TestAttestationResult(t *testing.T) {
func TestAttestationToken(t *testing.T) {
reportData := make([]byte, 64)
nonce := make([]byte, 64)
report := []byte{
@@ -499,23 +499,23 @@ func TestAttestationResult(t *testing.T) {
cases := []struct {
name string
nonce [vtpm.Nonce]byte
response *agent.AttestationResultResponse
response *agent.AttestationTokenResponse
svcRes []byte
err error
}{
{
name: "fetch attestation report successfully",
name: "fetch attestation token successfully",
nonce: [vtpm.Nonce]byte(nonce),
response: &agent.AttestationResultResponse{
response: &agent.AttestationTokenResponse{
File: report,
},
svcRes: report,
err: nil,
},
{
name: "failed to fetch attestation report",
name: "failed to fetch attestation token",
nonce: [vtpm.Nonce]byte(nonce),
response: &agent.AttestationResultResponse{
response: &agent.AttestationTokenResponse{
File: []byte{},
},
err: nil,
@@ -524,7 +524,7 @@ func TestAttestationResult(t *testing.T) {
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
svcCall := svc.On("AttestationResult", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(tc.svcRes, tc.err)
svcCall := svc.On("AzureAttestationToken", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(tc.svcRes, tc.err)
file, err := os.CreateTemp("", "attestation")
require.NoError(t, err)
@@ -533,7 +533,7 @@ func TestAttestationResult(t *testing.T) {
os.Remove(file.Name())
})
err = sdk.AttestationResult(context.Background(), tc.nonce, 0, file)
err = sdk.AttestationToken(context.Background(), tc.nonce, 0, file)
require.NoError(t, file.Close())
+11 -11
View File
@@ -124,12 +124,12 @@ func (_c *SDK_Attestation_Call) RunAndReturn(run func(context.Context, [64]byte,
return _c
}
// AttestationResult provides a mock function with given fields: ctx, nonce, attType, attestationFile
func (_m *SDK) AttestationResult(ctx context.Context, nonce [32]byte, attType int, attestationFile *os.File) error {
// AttestationToken provides a mock function with given fields: ctx, nonce, attType, attestationFile
func (_m *SDK) AttestationToken(ctx context.Context, nonce [32]byte, attType int, attestationFile *os.File) error {
ret := _m.Called(ctx, nonce, attType, attestationFile)
if len(ret) == 0 {
panic("no return value specified for AttestationResult")
panic("no return value specified for AttestationToken")
}
var r0 error
@@ -142,33 +142,33 @@ func (_m *SDK) AttestationResult(ctx context.Context, nonce [32]byte, attType in
return r0
}
// SDK_AttestationResult_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'AttestationResult'
type SDK_AttestationResult_Call struct {
// SDK_AttestationToken_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'AttestationToken'
type SDK_AttestationToken_Call struct {
*mock.Call
}
// AttestationResult is a helper method to define mock.On call
// AttestationToken is a helper method to define mock.On call
// - ctx context.Context
// - nonce [32]byte
// - attType int
// - attestationFile *os.File
func (_e *SDK_Expecter) AttestationResult(ctx interface{}, nonce interface{}, attType interface{}, attestationFile interface{}) *SDK_AttestationResult_Call {
return &SDK_AttestationResult_Call{Call: _e.mock.On("AttestationResult", ctx, nonce, attType, attestationFile)}
func (_e *SDK_Expecter) AttestationToken(ctx interface{}, nonce interface{}, attType interface{}, attestationFile interface{}) *SDK_AttestationToken_Call {
return &SDK_AttestationToken_Call{Call: _e.mock.On("AttestationToken", ctx, nonce, attType, attestationFile)}
}
func (_c *SDK_AttestationResult_Call) Run(run func(ctx context.Context, nonce [32]byte, attType int, attestationFile *os.File)) *SDK_AttestationResult_Call {
func (_c *SDK_AttestationToken_Call) Run(run func(ctx context.Context, nonce [32]byte, attType int, attestationFile *os.File)) *SDK_AttestationToken_Call {
_c.Call.Run(func(args mock.Arguments) {
run(args[0].(context.Context), args[1].([32]byte), args[2].(int), args[3].(*os.File))
})
return _c
}
func (_c *SDK_AttestationResult_Call) Return(_a0 error) *SDK_AttestationResult_Call {
func (_c *SDK_AttestationToken_Call) Return(_a0 error) *SDK_AttestationToken_Call {
_c.Call.Return(_a0)
return _c
}
func (_c *SDK_AttestationResult_Call) RunAndReturn(run func(context.Context, [32]byte, int, *os.File) error) *SDK_AttestationResult_Call {
func (_c *SDK_AttestationToken_Call) RunAndReturn(run func(context.Context, [32]byte, int, *os.File) error) *SDK_AttestationToken_Call {
_c.Call.Return(run)
return _c
}