Skip to content

Extract Apple APNs/SCEP pair validation onto MDMConfig#46166

Merged
MagnusHJensen merged 1 commit into
fleetdm:mainfrom
raju249:33370-mdm-apple-apns-scep-validation
May 25, 2026
Merged

Extract Apple APNs/SCEP pair validation onto MDMConfig#46166
MagnusHJensen merged 1 commit into
fleetdm:mainfrom
raju249:33370-mdm-apple-apns-scep-validation

Conversation

@raju249
Copy link
Copy Markdown
Contributor

@raju249 raju249 commented May 25, 2026

Extracts the Apple APNs/SCEP both-or-neither check out of runServeCmd and puts it on MDMConfig as ValidateAppleAPNSAndSCEPPair(initFatal). Same pattern as ConditionalAccessConfig.Validate, AndroidAgentConfig.Validate, and the validators added in #45583.

The call site (inside the existing if len(toInsert) > 0 gate) goes from six lines of inline conditional initFatal calls to one method call. Behavior, error messages, and gating are unchanged.

Tests live in server/config/config_test.go: one smoke case plus two error branches (APNs-only and SCEP-only). Skipped the "neither set" case on purpose — the outer if config.MDM.IsAppleAPNsSet() || config.MDM.IsAppleSCEPSet() gate in runServeCmd guarantees at least one is set before the validator is ever reached.

This is the last pure config validation left in runServeCmd per the broader-plan note on #45583. Remaining initFatal sites are runtime failure paths (datastore init, Redis init, MDM init wiring) which need the injection from #45343 — those would be the next slice.

Related issue: Refs #33370

Checklist for submitter

  • Added/updated automated tests
  • Input validation (validator method plus tests; no SQL/JS/shell paths involved)
  • Changes file: not applicable, internal refactor with no user-visible behavior change

Summary by CodeRabbit

  • Bug Fixes
    • Improved Apple MDM configuration validation to ensure APNs and SCEP certificates are properly paired during setup.

Review Change Stack

Move the both-or-neither check for Apple APNs and SCEP out of runServeCmd and onto a ValidateAppleAPNSAndSCEPPair(initFatal) method on MDMConfig, matching the pattern used by ConditionalAccessConfig.Validate and the validators added in fleetdm#45583. Behavior is preserved; error messages and gating are unchanged. Part of fleetdm#33370.
@raju249 raju249 requested a review from a team as a code owner May 25, 2026 15:21
Copy link
Copy Markdown

@claude claude Bot left a comment

Choose a reason for hiding this comment

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

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

@raju249
Copy link
Copy Markdown
Contributor Author

raju249 commented May 25, 2026

Hello @getvictor - This is another installment for the coverage improvement in cmd/fleet/serve.go. Do you mind taking a look, please?

Thanks! 🙏 🙇

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 25, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: cff99d97-7d61-4f8c-ae91-3b7d12b3ba4b

📥 Commits

Reviewing files that changed from the base of the PR and between 8f43cae and ddde616.

📒 Files selected for processing (3)
  • cmd/fleet/serve.go
  • server/config/config.go
  • server/config/config_test.go

Walkthrough

This PR extracts Apple MDM APNs/SCEP configuration validation from inline checks in the APNs/SCEP reconciliation flow into a centralized method on MDMConfig. The new ValidateAppleAPNSAndSCEPPair method enforces that both APNs and SCEP are configured together or both are absent, invoking the provided error callback when exactly one is set. A test exercises the three cases: both configured (passes), only SCEP configured (fails), and only APNs configured (fails). The serve flow now calls this validator before parsing certificates.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: extracting validation logic for Apple APNs/SCEP configuration into a dedicated method on MDMConfig.
Description check ✅ Passed The description covers the refactoring objective, implementation details, testing strategy, and references related issue #33370. It acknowledges that a changes file is not applicable for this internal refactor.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@MagnusHJensen MagnusHJensen self-requested a review May 25, 2026 15:30
@codecov
Copy link
Copy Markdown

codecov Bot commented May 25, 2026

Codecov Report

❌ Patch coverage is 87.50000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 66.83%. Comparing base (8f43cae) to head (ddde616).

Files with missing lines Patch % Lines
cmd/fleet/serve.go 0.00% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main   #46166   +/-   ##
=======================================
  Coverage   66.82%   66.83%           
=======================================
  Files        2755     2755           
  Lines      220203   220205    +2     
  Branches    11045    11045           
=======================================
+ Hits       147160   147165    +5     
+ Misses      59749    59742    -7     
- Partials    13294    13298    +4     
Flag Coverage Δ
backend 68.63% <87.50%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown
Member

@MagnusHJensen MagnusHJensen left a comment

Choose a reason for hiding this comment

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

Thanks @raju249 for this change!

I reviewed this one, since most US folks is out for the holiday today.

@MagnusHJensen MagnusHJensen merged commit d94e380 into fleetdm:main May 25, 2026
36 checks passed
getvictor pushed a commit that referenced this pull request May 29, 2026
Extracts the OTEL trace, metric, and log provider setup out of
`runServeCmd` and into `initOTELProviders` in a new `cmd/fleet/otel.go`.
Same pattern as the prior extractions on this issue (#44929, #45343,
#45583, #46166). Side effects (`otel.SetTracerProvider`,
`otel.SetMeterProvider`) are preserved inside the extracted function, so
runtime behavior is identical.

Three unit tests in `cmd/fleet/otel_test.go`:
- OTEL disabled (the common production path) returns `(nil, nil, nil)`
and never calls `initFatal`.
- OTEL enabled without log export returns non-nil trace and meter
providers; logger provider stays nil.
- Log export enabled returns all three providers non-nil.

One honest note on coverage: the four `initFatal` sites inside the
function are paranoid wrapping for OTEL SDK constructors that don't dial
at construction time, so the error paths are hard to drive in tests
without mocking the SDK. The tests above exercise the success paths and
the disabled gate, which is the bulk of the realistic flow.

This continues the path toward `serve.go` >60% coverage per the
discussion on #33370 — `serve.go` is now ~100 lines shorter and the OTEL
phase is testable as a unit. Remaining slices per the broader plan: MDM
Apple init, datastore init, Redis init.

**Related issue:** Refs #33370

# Checklist for submitter

- [x] Added/updated automated tests
- Changes file: not applicable — internal refactor with no user-visible
behavior change


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **Refactor**
* Centralized OpenTelemetry provider initialization into a single setup
path, simplifying startup and shutdown behavior and making observability
configuration clearer.

* **Tests**
* Added unit tests covering disabled/enabled telemetry paths and
optional log export, plus cleanup logic to ensure providers are shut
down correctly.

<!-- review_stack_entry_start -->

[![Review Change
Stack](https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg)](https://app.coderabbit.ai/change-stack/fleetdm/fleet/pull/46421?utm_source=github_walkthrough&utm_medium=github&utm_campaign=change_stack)

<!-- review_stack_entry_end -->
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
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