Skip to content

Add test enrollz-1#5484

Open
ijernoiu wants to merge 1 commit into
openconfig:mainfrom
open-traffic-generator:otg-enrollz-1
Open

Add test enrollz-1#5484
ijernoiu wants to merge 1 commit into
openconfig:mainfrom
open-traffic-generator:otg-enrollz-1

Conversation

@ijernoiu
Copy link
Copy Markdown
Contributor

@ijernoiu ijernoiu requested review from a team as code owners May 18, 2026 23:16
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a new test suite to validate the enrollz TPM 2.0 HMAC enrollment process. The changes include necessary infrastructure updates, such as adding the go-tpm dependency, defining a new topology binding for test environments, and extending the gnsi client interface to facilitate the new test cases. These additions ensure robust verification of the enrollment workflow and its error handling.

Highlights

  • New Test Suite: Added a comprehensive test suite for enrollz TPM 2.0 HMAC enrollment, covering various success and failure scenarios.
  • Dependency Update: Added the github.com/google/go-tpm dependency to the project to support TPM-related operations.
  • Topology Configuration: Introduced a new topology binding file for enrollz testing environments.
  • Interface Extension: Extended the gnsiConn interface to include the Enrollz client, enabling service interaction in tests.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a comprehensive test suite for TPM 2.0 HMAC enrollment, including a new test file, updates to the GNSI binding, and a sample topology for Arista devices. Feedback focuses on improving robustness by handling ignored errors in cryptographic and file system operations to prevent potential panics. Additionally, the review identifies several style guide violations where vendor-specific logic and CLI configurations must be abstracted into the deviations or cfgplugins packages to maintain test portability. A placeholder path in the topology binding also requires correction.

Comment on lines +426 to +427
wrongKey, _ := rsa.GenerateKey(rand.Reader, rsaKeyBits)
wrongPub, _ := x509.MarshalPKIXPublicKey(&wrongKey.PublicKey)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

Errors from rsa.GenerateKey and x509.MarshalPKIXPublicKey are ignored. If key generation fails, wrongKey will be nil, leading to a panic. Additionally, this logic is repeated later in the file; consider refactoring into a helper function to improve maintainability.

Suggested change
wrongKey, _ := rsa.GenerateKey(rand.Reader, rsaKeyBits)
wrongPub, _ := x509.MarshalPKIXPublicKey(&wrongKey.PublicKey)
wrongKey, err := rsa.GenerateKey(rand.Reader, rsaKeyBits)
if err != nil {
return fmt.Errorf("failed to generate RSA key: %w", err)
}
wrongPub, err := x509.MarshalPKIXPublicKey(&wrongKey.PublicKey)
if err != nil {
return fmt.Errorf("failed to marshal public key: %w", err)
}
References
  1. Simplify identical logic for different entities or repeated blocks by using a single loop or a helper function to improve maintainability.

Comment on lines +440 to +441
wrongKey, _ := rsa.GenerateKey(rand.Reader, rsaKeyBits)
wrongPub, _ := x509.MarshalPKIXPublicKey(&wrongKey.PublicKey)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

Errors from rsa.GenerateKey and x509.MarshalPKIXPublicKey are ignored. This can lead to a nil pointer dereference if key generation fails. Since this logic is identical to the block at line 426, consider refactoring it into a helper function to improve maintainability.

Suggested change
wrongKey, _ := rsa.GenerateKey(rand.Reader, rsaKeyBits)
wrongPub, _ := x509.MarshalPKIXPublicKey(&wrongKey.PublicKey)
wrongKey, err := rsa.GenerateKey(rand.Reader, rsaKeyBits)
if err != nil {
return fmt.Errorf("failed to generate RSA key: %w", err)
}
wrongPub, err := x509.MarshalPKIXPublicKey(&wrongKey.PublicKey)
if err != nil {
return fmt.Errorf("failed to marshal public key: %w", err)
}
References
  1. Simplify identical logic for different entities or repeated blocks by using a single loop or a helper function to improve maintainability.

Comment on lines +203 to +205
cwd, _ := os.Getwd()
enrollzCert = filepath.Join(cwd, enrollzCertFilename)
enrollzKey = filepath.Join(cwd, enrollzKeyFilename)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The error from os.Getwd() is ignored. It is better to handle it to avoid using an empty or incorrect path for the certificates. Using t.Fatalf is preferred here to fail fast as subsequent steps depend on this path.

Suggested change
cwd, _ := os.Getwd()
enrollzCert = filepath.Join(cwd, enrollzCertFilename)
enrollzKey = filepath.Join(cwd, enrollzKeyFilename)
cwd, err := os.Getwd()
if err != nil {
t.Fatalf("os.Getwd() failed: %v", err)
}
enrollzCert = filepath.Join(cwd, enrollzCertFilename)
enrollzKey = filepath.Join(cwd, enrollzKeyFilename)
References
  1. In tests, t.Fatalf is preferred over t.Errorf when a failure makes subsequent test steps meaningless, as this fails fast and reduces overall test execution time.

}

func fetchPPKPubFromDut(c *ROTDBClient, ctx context.Context) (*biz.FetchEKResp, error) {
switch c.dut.Vendor() {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Avoid using dut.Vendor() for vendor-specific logic in tests. This logic should be abstracted using the deviations package to maintain test portability across different platforms.

References
  1. Avoid using "dut.Vendor()" for vendor-specific logic or configurations in tests. Instead, use the "deviations" package to maintain test abstraction and portability across different vendors.


func reconfigureEnrollzService(t *testing.T, dut *ondatra.DUTDevice, sslProfileParams *sslProfileParams) {
t.Helper()
switch dut.Vendor() {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Vendor-specific CLI configuration should be abstracted via the deviations package or implemented as a configuration plugin (cfgplugins) to ensure the test remains vendor-neutral.

References
  1. Avoid using "dut.Vendor()" for vendor-specific logic or configurations in tests. Instead, use the "deviations" package to maintain test abstraction and portability across different vendors.

}

func newTestROTDBClient(t *testing.T, dut *ondatra.DUTDevice, keyType epb.Key) biz.ROTDBClient {
switch dut.Vendor() {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Direct use of dut.Vendor() here violates the general rule of maintaining test abstraction. Please move this logic to the deviations package.

References
  1. Avoid using "dut.Vendor()" for vendor-specific logic or configurations in tests. Instead, use the "deviations" package to maintain test abstraction and portability across different vendors.

gnmi {
target: "dut-hostname:6030"
mutual_tls: true
trust_bundle_file: "path-to-test-file/enrollz.crt"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The path path-to-test-file/enrollz.crt appears to be a placeholder. Please ensure this is replaced with a valid path or documented as a requirement for the test environment.

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.

2 participants