Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

COCOS-365-Add igvm measurement #379

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

COCOS-365-Add igvm measurement #379

wants to merge 4 commits into from

Conversation

dorcaslitunya
Copy link
Contributor

What type of PR is this?

This is a feature because it adds the following functionality: Igvm measurement functionality

What does this do?

Change the CLI so it calculates the measurement based on the vTPM and OVMF used.

Which issue(s) does this PR fix/relate to?

Have you included tests for your changes?

No, I have not included tests because I am waiting for the first review.

Did you document any new/modified feature?

No, I have not updated the documentation but I will focus on documentation next.

Copy link

codecov bot commented Feb 24, 2025

Codecov Report

Attention: Patch coverage is 83.33333% with 11 lines in your changes missing coverage. Please review.

Project coverage is 59.29%. Comparing base (bb0ad29) to head (51900a8).
Report is 5 commits behind head on main.

Files with missing lines Patch % Lines
cli/attestation.go 73.91% 4 Missing and 2 partials ⚠️
pkg/attestation/igvmmeasure/igvmmeasure.go 88.37% 4 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #379      +/-   ##
==========================================
- Coverage   59.57%   59.29%   -0.29%     
==========================================
  Files          54       57       +3     
  Lines        4574     4761     +187     
==========================================
+ Hits         2725     2823      +98     
- Misses       1564     1640      +76     
- Partials      285      298      +13     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Comment on lines +31 to +43
_, err := NewIgvmMeasurement("", nil, nil)
if err == nil {
t.Errorf("expected error for empty pathToFile, got nil")
}

igvm, err := NewIgvmMeasurement("/valid/path", nil, nil)
if err != nil {
t.Errorf("unexpected error: %v", err)
}
if igvm == nil {
t.Errorf("expected non-nil IgvmMeasurement")
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use assertions for expectations

Comment on lines +45 to +89
func TestIgvmMeasurement_Run_Success(t *testing.T) {
mockOutput := "measurement successful" // Ensure it's a **single-line output**

m := &IgvmMeasurement{
pathToFile: "/valid/path",
execCommand: func(name string, arg ...string) *exec.Cmd {
cmd := exec.Command("sh", "-c", "echo '"+mockOutput+"'") // Single line output
return cmd
},
}

err := m.Run("/mock/igvmBinary")
if err != nil {
t.Errorf("expected no error, got %v", err)
}
}

func TestIgvmMeasurement_Run_Error(t *testing.T) {
mockOutput := "some error occurred"

m := &IgvmMeasurement{
pathToFile: "/invalid/path",
execCommand: func(name string, arg ...string) *exec.Cmd {
cmd := exec.Command("sh", "-c", "echo '"+mockOutput+"' && echo 'extra line' && exit 1") // Simulate multiline error
return cmd
},
}

err := m.Run("/mock/igvmBinary")

if err == nil {
t.Errorf("expected an error, got nil")
} else if !strings.Contains(err.Error(), "error: "+mockOutput) {
t.Errorf("expected error message to contain 'error: %s', got: %s", mockOutput, err)
}
}

func TestIgvmMeasurement_Stop_NoProcess(t *testing.T) {
m := &IgvmMeasurement{}

err := m.Stop()
if err == nil || err.Error() != "no running process to stop" {
t.Errorf("expected 'no running process to stop' error, got: %v", err)
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

combine tests into a single test with multiple test cases as we do for other tests

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature: Change the CLI so it calculates the measurement based on the vTPM and OVMF used
2 participants