Skip to content

🌱 Testing: Add unit tests for NetworkPolicy controller, fetcher, webhook, proactive restart, and negative signature verification - #191

Merged
pdettori merged 2 commits into
rossoctl:mainfrom
kevincogan:fix/agentcard-test-gaps
Mar 6, 2026
Merged

🌱 Testing: Add unit tests for NetworkPolicy controller, fetcher, webhook, proactive restart, and negative signature verification#191
pdettori merged 2 commits into
rossoctl:mainfrom
kevincogan:fix/agentcard-test-gaps

Conversation

@kevincogan

Copy link
Copy Markdown
Contributor

Summary

  • Add unit tests for the AgentCardNetworkPolicyReconciler covering enforcement toggle, permissive/restrictive policy creation, identity binding, policy status transitions, deletion cleanup, and missing workload handling
  • Add unit tests for the DefaultFetcher covering A2A card fetch, unsupported protocol, HTTP error codes, invalid JSON, and GetServiceURL formatting
  • Add unit tests for the AgentCardValidator webhook covering create/update/delete validation with and without targetRef, and wrong object type rejection
  • Add integration tests for proactive workload restart on trust bundle rotation and SVID leaf cert expiry, including the no-restart negative case
  • Add integration tests for negative signature verification covering tampered card payload rejection in enforce mode (1m requeue) and tampered card acceptance in audit mode

Related issue(s)

Closes test coverage gaps identified in the AgentCard design review for the NetworkPolicy controller, fetcher, webhook, proactive restart, and signature verification paths.

(Optional) Testing Instructions

Fast unit tests (fetcher + webhook)

go test ./internal/agentcard/... ./internal/webhook/... -v -count=1

Controller integration tests (requires envtest binaries)

go test ./internal/controller/... -v -count=1 -timeout 120s

…ive restart, and negative signature verification

Signed-off-by: Kevin Cogan <kevin.s.cogan@gmail.com>
@pdettori pdettori moved this from Backlog to In review / Needs Testing in Rossoctl Issue Prioritization Mar 4, 2026

@pdettori pdettori left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Review Summary

Solid set of tests (941 lines) covering critical paths: signature verification (positive/negative), network policy enforcement (permissive/restrictive/disabled), proactive restart logic, and webhook validation. Well-structured with appropriate frameworks (Ginkgo+envtest for controller tests, standard testing.T for pure functions) and good isolation with cleanup hooks and unique resource names.

Areas reviewed: Go tests, Security, Conventions
Commits: 1 commit, signed-off ✓
CI status: passing ✓

A few suggestions below for consistency and maintainability, but nothing blocking merge.

Comment thread kagenti-operator/internal/controller/negative_signature_test.go Outdated
Comment thread kagenti-operator/internal/controller/agentcard_networkpolicy_controller_test.go Outdated
Comment thread kagenti-operator/internal/controller/proactive_restart_test.go
Comment thread kagenti-operator/internal/controller/proactive_restart_test.go Outdated
…oncileTwice comment, magic number

- Add Apache 2.0 license header to agentcard_webhook_test.go
- Remove ctx := context.Background() shadows in favor of suite-level ctx
- Use apierrors.IsNotFound for deletion verification in NetworkPolicy test
- Add doc comment explaining reconcileTwice double-reconcile pattern
- Replace 5*time.Minute magic number with DefaultSVIDExpiryGracePeriod/6

Signed-off-by: Kevin Cogan <kevin.s.cogan@gmail.com>
@kevincogan

kevincogan commented Mar 5, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @pdettori! All five addressed in the latest push:

  1. license header added
  2. ctx shadows removed
  3. IsNotFound for deletion checks
  4. reconcileTwice comment
  5. magic number tied to DefaultSVIDExpiryGracePeriod

All tests pass too.

@kevincogan
kevincogan requested a review from pdettori March 5, 2026 08:58
@pdettori
pdettori merged commit b830452 into rossoctl:main Mar 6, 2026
2 checks passed
@github-project-automation github-project-automation Bot moved this from In review / Needs Testing to Done in Rossoctl Issue Prioritization Mar 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants