Skip to content

fix: make authorization tests independent of host PIDs - #200

Closed
fly602 wants to merge 1 commit into
linuxdeepin:masterfrom
fly602:master
Closed

fix: make authorization tests independent of host PIDs#200
fly602 wants to merge 1 commit into
linuxdeepin:masterfrom
fly602:master

Conversation

@fly602

@fly602 fly602 commented Aug 19, 2026

Copy link
Copy Markdown
Contributor
  1. Inject the process start-time reader into allowCallerRegistry.
  2. Keep getProcessStartTime as the production implementation.
  3. Stub start-time reads in tests to remove /proc PID dependencies.

Log: No user-facing changes

Influence:

  1. Run locale-helper tests in an isolated PID namespace.
  2. Verify non-root authorization still detects PID reuse.
  3. Build the package on architectures using isolated build workers.

fix: 修复授权测试依赖构建机进程的问题

  1. 为 allowCallerRegistry 注入进程启动时间读取函数。
  2. 生产环境仍使用 getProcessStartTime 读取 /proc。
  3. 测试使用固定启动时间,消除对构建机 PID 的依赖。

Log: 无用户可见变化

Influence:

  1. 在隔离 PID 命名空间中运行 locale-helper 测试。
  2. 验证非 root 授权仍能检测 PID 复用。
  3. 在使用隔离构建容器的各架构上执行软件包构建。

PMS: TASK-393313

Summary by Sourcery

Decouple authorization tests from build-host process IDs while preserving production PID-reuse detection.

Bug Fixes:

  • Remove authorization test dependence on host /proc PID start times by using deterministic test values.

Enhancements:

  • Inject process start-time lookup into the authorization registry while retaining the production /proc-based implementation and PID-reuse protection.

Tests:

  • Make allow-caller tests deterministic across isolated PID namespaces and build environments.

1. Inject the process start-time reader into allowCallerRegistry.
2. Keep getProcessStartTime as the production implementation.
3. Stub start-time reads in tests to remove /proc PID dependencies.

Log: No user-facing changes

Influence:
1. Run locale-helper tests in an isolated PID namespace.
2. Verify non-root authorization still detects PID reuse.
3. Build the package on architectures using isolated build workers.

fix: 修复授权测试依赖构建机进程的问题

1. 为 allowCallerRegistry 注入进程启动时间读取函数。
2. 生产环境仍使用 getProcessStartTime 读取 /proc。
3. 测试使用固定启动时间,消除对构建机 PID 的依赖。

Log: 无用户可见变化

Influence:
1. 在隔离 PID 命名空间中运行 locale-helper 测试。
2. 验证非 root 授权仍能检测 PID 复用。
3. 在使用隔离构建容器的各架构上执行软件包构建。

PMS: TASK-393313

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Sorry @fly602, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

@sourcery-ai

sourcery-ai Bot commented Aug 19, 2026

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

This PR injects a process start-time reader into the allowCallerRegistry so tests can stub PID start times, making authorization tests independent of host /proc PIDs while keeping the production implementation unchanged.

Sequence diagram for injected processStartTime in authorizeRegistrar

sequenceDiagram
    participant Test
    participant allowCallerRegistry
    participant processStartTime

    Test->>allowCallerRegistry: authorizeRegistrar(sender, uniqueName)
    allowCallerRegistry->>processStartTime: processStartTime(senderPID)
    processStartTime-->>allowCallerRegistry: senderStartTime
    allowCallerRegistry->>processStartTime: processStartTime(senderPID)
    processStartTime-->>allowCallerRegistry: checkStartTime
    allowCallerRegistry-->>Test: authorization result
Loading

File-Level Changes

Change Details Files
Inject a configurable process start-time reader into allowCallerRegistry and use it in authorization logic.
  • Add processStartTime function field to allowCallerRegistry struct
  • Initialize processStartTime with getProcessStartTime in newAllowCallerRegistryWithConfig
  • Replace direct getProcessStartTime calls in authorizeRegistrar with the injected processStartTime function
locale-helper/allow_caller.go
Stub process start-time reads in tests and assert the new dependency is wired correctly.
  • Override processStartTime in test registry helper with a deterministic stub
  • Add non-nil assertion for processStartTime in registry construction test
locale-helper/allow_caller_test.go

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@fly602 fly602 closed this Aug 19, 2026
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.

1 participant