Skip to content

Android certificates resend generate resent_certificate#49249

Merged
ksykulev merged 3 commits into
mainfrom
49007-android-activity-fix
Jul 14, 2026
Merged

Android certificates resend generate resent_certificate#49249
ksykulev merged 3 commits into
mainfrom
49007-android-activity-fix

Conversation

@ksykulev

@ksykulev ksykulev commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

This resent_certificate activity is generated from the edit user flow in fleet server.

Related issue: Resolves #49007

Testing

  • Added/updated automated tests
  • QA'd all new/changed functionality manually

For unreleased bug fixes in a release candidate, one of:

  • Confirmed that the fix is not expected to adversely impact load test results

Summary by CodeRabbit

  • New Features

    • Device-to-identity-provider mapping changes can now generate certificate resend activities when applicable.
    • Certificate resend activities can now be marked as automated versus manual.
  • Improvements

    • Certificate resend details are produced when SCIM host-user mappings are added, updated, or removed.
    • If creating the associated resend activities fails, the mapping change still proceeds; errors are handled non-blockingly.

@ksykulev ksykulev requested a review from a team as a code owner July 13, 2026 22:43
Copilot AI review requested due to automatic review settings July 13, 2026 22:43
@ksykulev ksykulev changed the title Android certificates resend generate resent certificate Android certificates resend generate resent_certificate Jul 13, 2026

Copilot AI left a comment

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.

Pull request overview

This PR extends the SCIM→host mapping / variable-triggered resend flow to surface resent_certificate activity details when certificate templates are automatically resent due to IdP/SCIM-driven host variable changes.

Changes:

  • Updated SCIM host-mapping datastore APIs to return []ActivityTypeResentCertificate for any triggered automatic resends.
  • Marked auto-resend ActivityTypeResentCertificate details as automated (via WasFromAutomation) so activities can be attributed to Fleet automation.
  • Wired some service entrypoints/tests to handle the updated datastore signatures (and added activity emission in SetHostDeviceMapping).

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
server/service/osquery_utils/queries.go Adjusts SCIM mapping calls for new return signature (currently discards returned activities).
server/service/osquery_utils/queries_test.go Updates mocks to match new datastore method signatures.
server/service/orbit.go Adjusts EUA enrollment SCIM mapping calls for new return signature (should emit returned activities).
server/service/hosts.go Emits resent_certificate activities from returned SCIM mapping resend list (needs actor/error handling fixes).
server/service/hosts_test.go Updates mocks for new signatures; should assert the new activity emission behavior.
server/mock/datastore_mock.go Updates datastore mock function types and method signatures.
server/fleet/datastore.go Updates datastore interface signatures and comments to return resent cert activities.
server/fleet/activities.go Adds automation marker plumbing for ActivityTypeResentCertificate.
server/datastore/mysql/scim.go Selects affected cert templates for resend and marks returned activities as automated.
server/datastore/mysql/scim_test.go Updates SCIM datastore tests for signature changes / activity return values.
server/datastore/mysql/hosts.go Returns resent cert activities from SCIM mapping set/delete helpers.
server/datastore/mysql/hosts_test.go Updates tests for changed helper return signatures.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread server/service/hosts.go
Comment thread server/service/hosts.go
Comment thread server/service/osquery_utils/queries.go
Comment on lines +4330 to 4332
ds.SetOrUpdateHostSCIMUserMappingFunc = func(ctx context.Context, hostID uint, scimUserID uint) ([]fleet.ActivityTypeResentCertificate, error) {
return nil, nil
}
Comment thread server/service/orbit.go
Comment thread server/service/orbit.go
@coderabbitai

coderabbitai Bot commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

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: 87e65649-7a60-4225-803b-c9cb18a0ef8a

📥 Commits

Reviewing files that changed from the base of the PR and between 2e20036 and e479133.

📒 Files selected for processing (2)
  • server/datastore/mysql/hosts.go
  • server/service/hosts.go
🚧 Files skipped from review as they are similar to previous changes (2)
  • server/service/hosts.go
  • server/datastore/mysql/hosts.go

Walkthrough

SCIM host mapping datastore methods now return resent-certificate activities alongside errors. Automatic profile resend logic marks returned activities as automated. Host device mapping creates resent_certificate activities from these results, while other callers discard the additional return value. Interfaces, mocks, and affected tests were updated for the new signatures.

Possibly related PRs

  • fleetdm/fleet#48278: Extends SCIM variable-change handling for certificate-template resends and related configuration.
  • fleetdm/fleet#48351: Changes SCIM user association across matching hosts, affecting host-mapping resend activity generation.
  • fleetdm/fleet#49171: Propagates resent-certificate results through the SCIM host-mapping resend pipeline.
🚥 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 is concise and points to the main change: adding resent_certificate generation for Android certificate resends.
Description check ✅ Passed The description includes the related issue and testing notes, which is mostly complete for this repository's template.
Linked Issues check ✅ Passed The code adds resent_certificate activity emission for automatic SCIM-driven resends and preserves existing manual resend behavior.
Out of Scope Changes check ✅ Passed The changes stay within SCIM host-mapping, resend activity emission, and the matching tests and mocks.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch 49007-android-activity-fix

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.

@coderabbitai coderabbitai Bot left a comment

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.

Actionable comments posted: 2

🧹 Nitpick comments (1)
server/datastore/mysql/scim_test.go (1)

2637-2766: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add coverage for the new resentCerts return value.

Every call to ds.SetOrUpdateHostSCIMUserMapping here discards the returned []fleet.ActivityTypeResentCertificate and only checks host_scim_user state/errors. Since generating this slice correctly (and not duplicating/over-triggering it) is the actual behavior this PR introduces, consider adding a scenario with host_certificate_templates/mdm_configuration_profile_variables/fleet_variables fixtures that asserts on the returned certs — including re-calling with the same scimUserID to confirm no spurious/duplicate resend is triggered when nothing changed.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@server/datastore/mysql/scim_test.go` around lines 2637 - 2766, Extend
testSetOrUpdateHostSCIMUserMapping to exercise the returned
[]fleet.ActivityTypeResentCertificate value, using host_certificate_templates,
mdm_configuration_profile_variables, and fleet_variables fixtures that cause
certificate resends. Capture and assert the returned certificates for an
applicable mapping update, then call SetOrUpdateHostSCIMUserMapping again with
the same scimUserID and verify no duplicate or spurious certificates are
returned while preserving the existing mapping assertions.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@server/datastore/mysql/hosts.go`:
- Around line 4934-4979: The deleteHostSCIMUserMapping function should skip
certificate selection and profile resend work when the DELETE affects no rows.
Capture the DELETE result, check RowsAffected(), and return an empty resend list
immediately when it is zero; preserve the existing error handling and resend
flow when a mapping was removed.

In `@server/service/orbit.go`:
- Around line 347-352: The SCIM mapping flows discard
ActivityTypeResentCertificate results, preventing audit activities. In
server/service/orbit.go lines 347-352, capture the returned certificates from
SetOrUpdateHostSCIMUserMapping and DeleteHostSCIMUserMapping and forward them to
svc.NewActivity, matching the existing hosts.go behavior. In
server/service/osquery_utils/queries.go lines 3185-3191, surface those
certificates to the caller or emit the corresponding activity there so the
Windows MDM path records them.

---

Nitpick comments:
In `@server/datastore/mysql/scim_test.go`:
- Around line 2637-2766: Extend testSetOrUpdateHostSCIMUserMapping to exercise
the returned []fleet.ActivityTypeResentCertificate value, using
host_certificate_templates, mdm_configuration_profile_variables, and
fleet_variables fixtures that cause certificate resends. Capture and assert the
returned certificates for an applicable mapping update, then call
SetOrUpdateHostSCIMUserMapping again with the same scimUserID and verify no
duplicate or spurious certificates are returned while preserving the existing
mapping assertions.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 20b660e1-d61a-4994-8873-f4bdf352a089

📥 Commits

Reviewing files that changed from the base of the PR and between ca1acc2 and 2e20036.

📒 Files selected for processing (12)
  • server/datastore/mysql/hosts.go
  • server/datastore/mysql/hosts_test.go
  • server/datastore/mysql/scim.go
  • server/datastore/mysql/scim_test.go
  • server/fleet/activities.go
  • server/fleet/datastore.go
  • server/mock/datastore_mock.go
  • server/service/hosts.go
  • server/service/hosts_test.go
  • server/service/orbit.go
  • server/service/osquery_utils/queries.go
  • server/service/osquery_utils/queries_test.go

Comment thread server/datastore/mysql/hosts.go
Comment thread server/service/orbit.go
@codecov

codecov Bot commented Jul 13, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 60.00000% with 34 lines in your changes missing coverage. Please review.
✅ Project coverage is 68.07%. Comparing base (dc48aca) to head (33c7a1d).

Files with missing lines Patch % Lines
server/datastore/mysql/hosts.go 73.58% 7 Missing and 7 partials ⚠️
server/service/hosts.go 16.66% 4 Missing and 6 partials ⚠️
server/datastore/mysql/scim.go 62.50% 4 Missing and 2 partials ⚠️
server/service/orbit.go 0.00% 1 Missing and 1 partial ⚠️
server/service/osquery_utils/queries.go 0.00% 0 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #49249      +/-   ##
==========================================
- Coverage   68.08%   68.07%   -0.01%     
==========================================
  Files        3784     3784              
  Lines      239232   239271      +39     
  Branches    12423    12458      +35     
==========================================
+ Hits       162885   162894       +9     
- Misses      61571    61586      +15     
- Partials    14776    14791      +15     
Flag Coverage Δ
backend 69.56% <60.00%> (-0.01%) ⬇️

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

☔ View full report in Codecov by Harness.
📢 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.

@ksykulev ksykulev merged commit 1318b3c into main Jul 14, 2026
43 of 44 checks passed
@ksykulev ksykulev deleted the 49007-android-activity-fix branch July 14, 2026 00:03
ksykulev added a commit that referenced this pull request Jul 14, 2026
Original issue #49007
Original PR: #49249

## Testing

- [x] Added/updated automated tests
- [x] QA'd all new/changed functionality manually
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.

Android certificates: automatic (variable-triggered) resend records installed_certificate but not resent_certificate activity

3 participants