Skip to content

test(tls): add unit tests for pkg/tls#1515

Open
mkowalski wants to merge 1 commit into
nmstate:mainfrom
mkowalski:tls-unit-tests
Open

test(tls): add unit tests for pkg/tls#1515
mkowalski wants to merge 1 commit into
nmstate:mainfrom
mkowalski:tls-unit-tests

Conversation

@mkowalski
Copy link
Copy Markdown
Member

Summary

  • Adds Ginkgo v2 + Gomega unit tests for the pkg/tls package: parseTLSSecurityProfile, GetTLSProfileSpec, FetchAPIServerTLSConfig, NewTLSConfigFromProfile (including the documented TLS-1.3 CipherSuites sentinel-untouched contract), and exact pinning of TLSProfiles[Old|Intermediate|Modern] cipher lists + MinTLSVersion.
  • Covers the cipher helpers (tlsVersion, tlsVersionOrDie, cipherSuite, openSSLToIANACipherSuites, cipherCode, cipherCodes) and SecurityProfileWatcher.Reconcile across APIServer-absent, profile-only-change, adherence-only-change, both-change, steady-state, nil-callback, and parse-error paths.
  • No production code changes; uses a controller-runtime fake client.

Note

This PR depends on the tlsAdherence production-code work (introducing TLSAdherencePolicy, parseTLSAdherence, FetchAPIServerTLSConfig, and SecurityProfileWatcher.InitialTLSAdherencePolicy). It will compile and pass once that change lands; opened now to keep the test coverage ready for review alongside it.

76 specs, all passing locally against the adherence branch.

Cover parseTLSSecurityProfile, GetTLSProfileSpec, FetchAPIServerTLSConfig,
NewTLSConfigFromProfile (including the TLS-1.3 CipherSuites sentinel
assertion), and exact pinning of the canned TLSProfiles[Old|Intermediate|
Modern] cipher lists and MinTLSVersion. Also cover the cipher helpers
(tlsVersion, tlsVersionOrDie, cipherSuite, openSSLToIANACipherSuites,
cipherCode, cipherCodes) and SecurityProfileWatcher.Reconcile across the
APIServer-absent, profile-only, adherence-only, both-change, steady-state,
nil-callback, and parse-error paths.

Tests use Ginkgo v2 + Gomega and a controller-runtime fake client; no
production code changes.

Signed-off-by: Mat Kowalski <mko@redhat.com>
@kubevirt-bot
Copy link
Copy Markdown
Collaborator

Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@kubevirt-bot kubevirt-bot requested a review from emy May 15, 2026 09:20
@kubevirt-bot kubevirt-bot added the dco-signoff: yes Indicates the PR's author has DCO signed all their commits. label May 15, 2026
@kubevirt-bot kubevirt-bot requested a review from qinqon May 15, 2026 09:20
@kubevirt-bot kubevirt-bot added the do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. label May 15, 2026
@kubevirt-bot
Copy link
Copy Markdown
Collaborator

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign mkowalski for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@mkowalski
Copy link
Copy Markdown
Member Author

/hold

@kubevirt-bot kubevirt-bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label May 15, 2026
Copy link
Copy Markdown

@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 suite of tests for the TLS package, covering cipher suite mapping, version resolution, and the security profile controller. Feedback identifies a critical signature mismatch in the SecurityProfileWatcher callback recorder that will lead to compilation errors. Additionally, a suggestion was provided to correct misleading comments regarding the contents of the cipher translation table to accurately reflect the inclusion of TLS 1.3 IANA names.

newAdherence TLSAdherencePolicy
}

func (r *callbackRecorder) fn() func(ctx context.Context, oldProfile, newProfile TLSProfileSpec, oldAdherence, newAdherence TLSAdherencePolicy) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

The callback signature in callbackRecorder.fn includes oldAdherence and newAdherence parameters, but the OnProfileChange field in the SecurityProfileWatcher struct (as defined in pkg/tls/controller.go) currently only accepts three arguments: ctx, oldTLSProfileSpec, and newTLSProfileSpec. This mismatch will cause a compilation error. Ensure the production code is updated to match this signature before merging.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

#1514 will merge before this

Comment thread pkg/tls/ciphers_test.go
Comment on lines +112 to +114
It("does not pass through an IANA name directly (only OpenSSL names are in the table)", func() {
// Sanity check: the table is OpenSSL-keyed, so feeding an IANA-style
// name yields no output. cipherCode() compensates by trying IANA first.
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The comment and test description are slightly misleading. The openSSLToIANA table in pkg/tls/ciphers.go actually contains IANA names as keys for TLS 1.3 cipher suites (e.g., "TLS_AES_128_GCM_SHA256"). The test correctly identifies that TLS 1.2 IANA names are missing from the keys, but the generalization that "only OpenSSL names are in the table" is incorrect.

Suggested change
It("does not pass through an IANA name directly (only OpenSSL names are in the table)", func() {
// Sanity check: the table is OpenSSL-keyed, so feeding an IANA-style
// name yields no output. cipherCode() compensates by trying IANA first.
It("does not pass through a TLS 1.2 IANA name directly (only OpenSSL and TLS 1.3 IANA names are in the table)", func() {
// Sanity check: the table is primarily OpenSSL-keyed (except for TLS 1.3),
// so feeding a TLS 1.2 IANA-style name yields no output. cipherCode() compensates by trying IANA first.

@kubevirt-bot
Copy link
Copy Markdown
Collaborator

@mkowalski: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
pull-kubernetes-nmstate-unit-test 86ea5f4 link true /test pull-kubernetes-nmstate-unit-test
Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dco-signoff: yes Indicates the PR's author has DCO signed all their commits. do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. size/XL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants