Skip to content

fix: 権限チェック追加に追従していなかったユニットテストを直す - #1942

Open
mhaya wants to merge 2 commits into
develop_v2.1.0from
fix/ci-unit-test-failures
Open

mhaya wants to merge 2 commits into
develop_v2.1.0from
fix/ci-unit-test-failures

Conversation

@mhaya

@mhaya mhaya commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

概要

9月29日頃から Unit Tests で継続して落ちていた4モジュールを直す。いずれもセキュリティ修正で挙動が変わったのにテスト(と一部の呼び出し元)が追従していなかったもの。修正自体は戻さず、新しい挙動に合わせている。

モジュール 原因の変更 対応
weko-groups 11b05274c(管理者ロール必須化、grouplist のログイン必須化、招待を OPEN のみに) 期待値を更新。users fixture の一般ユーザ枠が sysadmin になっていたのを修正。1要求ごとにセッションが片付き fixture のユーザが detach されるため、403 の確認は要求1回で終える(test_new_member_4 に分離)
invenio-resourcesyncserver 91a34caa3(_export_item が権限なしレコードに {} を返す) コード修正: ResourceListHandler / ChangeListHandler で {} なら None を返す(呼び出し元3箇所のうちこの2箇所が未対応で、例外経由で None になりエラーログが出ていた)。テストは非公開レコードが書き出されないことと、公開扱いでの成功経路を確認
weko-search-ui 121eb345e(@check_index_permission 追加) デコレータは kwargs しか見ないため、journal_detail(index_id=33) で呼ぶ
weko-workflow 121eb345e(get_feedback_maillist に @check_authority 追加) 申請者でない contributor では本体に届かないため sysadmin で確認

動作確認

scripts/ci/run-local.sh と同じ compose 構成・イメージで実行(作業ツリーの所有者の都合で、同じ差分を当てた別 worktree で実行)。

  • weko-groups: 112 passed
  • invenio-resourcesyncserver: 107 passed, 2 xfailed
  • weko-search-ui: CI で落ちていたシャード 6/6 のみ — 92 passed, 2 xfailed
  • weko-workflow: CI で落ちていたシャード 6/8 のみ — 102 passed

search-ui / workflow は全シャードを回していないので、最終確認は CI で行う。flake8 は変更前後で新規の指摘なし。

このPRで扱わないもの

  • API Inventory Drift の G2(3件): weko-swordserver の @roles_required → @check_deposit_role()(229ad779a、内部で roles_required を呼ぶ)の意図的な置き換え。docs/RULE.md に従い、private 側の台帳とベースライン更新で対応する。

🤖 Generated with Claude Code

Summary by Sourcery

Bring authorization-sensitive code paths and unit tests into alignment with the latest permission checks and record visibility rules.

Bug Fixes:

  • Update unit tests and resource sync handling to align with newly enforced authorization and visibility behavior.

Enhancements:

  • Ensure resource sync handlers skip records that cannot be exported and preserve successful export behavior for publicly accessible records.
  • Align group, search UI, and workflow tests with updated role, login, invitation, and authority requirements.

Tests:

  • Update affected module tests and fixtures to validate the revised authorization outcomes and avoid session-related test interference.

@sourcery-ai

sourcery-ai Bot commented Oct 18, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

セキュリティ修正で導入された認証・認可挙動に合わせ、4モジュールのユニットテストを更新した。加えて、権限のないレコードを同期出力から安全に除外する未対応の呼び出し元を修正し、各権限境界と成功経路を検証している。

Sequence diagram for permission-filtered resource synchronization

sequenceDiagram
    participant Client
    participant Handler as ResourceListHandler_or_ChangeListHandler
    participant Exporter as _export_item

    Client->>Handler: get_record_content_file(record_id)
    Handler->>Exporter: _export_item(...)
    alt exported_item is empty
        Exporter-->>Handler: {}
        Handler-->>Client: None
    else record is exportable
        Exporter-->>Handler: exported_item
        Handler-->>Client: synchronization content
    end
Loading

File-Level Changes

Change Details Files
権限変更後の期待値とテスト用ユーザ設定を更新し、グループ機能の認証・ロール・招待ポリシーを現行仕様に合わせた。
  • 一般ユーザfixtureがsysadminを誤参照しないよう修正
  • 管理者ロール必須化、ログイン必須化、招待制限に合わせてステータスコードと判定を更新
  • 要求後のセッション切り離しを避けるため権限境界の確認をテスト分割
modules/weko-groups/tests/conftest.py
modules/weko-groups/tests/test_models.py
modules/weko-groups/tests/test_views.py
modules/weko-groups/tests/test_weko_groups.py
権限のないレコードをリソース同期の出力へ追加しないよう呼び出し元を修正し、公開・非公開の経路をテストした。
  • ResourceListHandlerとChangeListHandlerで_export_itemの空辞書をNoneとして扱うよう変更
  • 非公開レコードが出力されないことと、公開扱いの成功経路を検証
modules/invenio-resourcesyncserver/invenio_resourcesyncserver/api.py
modules/invenio-resourcesyncserver/tests/test_api.py
インデックス権限チェックの引数解決に対応するよう検索UIテストの呼び出し形式を修正した。
  • journal_detailをindex_idのキーワード引数で呼び出すよう変更
modules/weko-search-ui/tests/test_views.py
フィードバックメール一覧の権限チェックを通過して本体処理を検証できるユーザにテスト対象を変更した。
  • 申請者ではないsysadminによる成功経路にパラメータ化テストを限定
  • 詳細な権限境界は既存のACLテストに委ねる構成に整理
modules/weko-workflow/tests/test_views.py

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

@coderabbitai

coderabbitai Bot commented Oct 18, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: c332c886-61dc-41b6-aeec-2c86bcd1157b

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@github-actions

Copy link
Copy Markdown

🔍 Claude レビュー統合

指摘はありません。


次にすること: 既存のレビュー指摘は、要約と「レビュー省略」の通知だけで、裁定する指摘スレッドはありませんでした。api.py の修正は妥当です。_export_item は権限がないと ({}, {}) を返します(weko_items_ui/utils.py:2871-2872)。修正前は exported_item.get('item_type_id') が None になり、後続処理が例外で止まっていました。修正後は2つの get_record_content_file(api.py:530-532 と 1228-1230)が早期に None を返し、権限のないレコードは書き出されません。認可の後退や入力検証の欠落は見つかりませんでした。テスト側の変更は、今回の確認範囲では問題を見つけていません。


モデル sonnet / 2 回実行して和集合 / コスト $0.2210。同じ入力でも結果が揺れるため複数回まわし、一部のパスでしか挙がらなかったものには回数を添えています

他レビューを踏まえた自動レビューです。誤りが含まれることがあります。

@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.

Hey - I've found 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="modules/invenio-resourcesyncserver/tests/test_api.py" line_range="377" />
<code_context>

+        # 閲覧権限のないレコードは _export_item が {} を返す
+        with patch("invenio_resourcesyncserver.api._export_item", return_value=({}, {})):
+            assert test.get_record_content_file(1) is None
+

</code_context>
<issue_to_address>
**Empty-export regression goes undetected**

When the empty-export guard is removed, removing the new empty-export guard still lets this assertion pass: `ItemTypes.get_by_id(None)` is followed by an attribute access that raises, and the handler catches that exception and returns `None`. The test therefore does not catch a regression to the exception-and-error-log path it is intended to prevent.

Also assert that the downstream item-type lookup is not reached for an empty export.
</issue_to_address>

Sourcery assessment

Approval pending. 1 finding to address first.

Blocking findings: modules/invenio-resourcesyncserver/tests/test_api.py:377


Sourcery is free for open source - if you like our reviews please consider sharing them ✨


# 閲覧権限のないレコードは _export_item が {} を返す
with patch("invenio_resourcesyncserver.api._export_item", return_value=({}, {})):
assert test.get_record_content_file(1) is None

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 · Empty-export regression goes undetected

When the empty-export guard is removed, removing the new empty-export guard still lets this assertion pass: ItemTypes.get_by_id(None) is followed by an attribute access that raises, and the handler catches that exception and returns None. The test therefore does not catch a regression to the exception-and-error-log path it is intended to prevent.

Also assert that the downstream item-type lookup is not reached for an empty export.

Prompt for AI agents
In `modules/invenio-resourcesyncserver/tests/test_api.py` at line 377:

**Empty-export regression goes undetected**

When the empty-export guard is removed, removing the new empty-export guard still lets this assertion pass: `ItemTypes.get_by_id(None)` is followed by an attribute access that raises, and the handler catches that exception and returns `None`. The test therefore does not catch a regression to the exception-and-error-log path it is intended to prevent.

Also assert that the downstream item-type lookup is not reached for an empty export.

Masaharu Hayashi and others added 2 commits October 18, 2026 16:01
91a34ca で weko-items-ui の _export_item は閲覧権限のないレコードに
{} を返すようになったが、呼び出し元のうち対応したのは export_items
だけで、ResourceListHandler / ChangeListHandler は取り残されていた。
{} のまま ItemTypes.get_by_id(None) に進んで AttributeError になり、
except で None が返るので結果は同じだが、例外経由でエラーログと
トレースバックが毎回出ていた。空なら明示的に None を返す。

テストは、es_records のレコードが非公開(publish_status "1")のため
匿名では書き出されないことを確認し、書き出しの成功経路は
check_publish_status を patch して公開扱いで確認する。

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- weko-groups (11b0527): 管理者ロール必須化・grouplist のログイン必須化・
  招待を OPEN のグループに限定した変更に期待値を合わせる。users fixture の
  一般ユーザ枠が sysadmin になっていたのを直す。1要求ごとにセッションが
  片付き fixture のユーザが detach されるため、403 の確認は要求1回で終える
- weko-search-ui (121eb34): check_index_permission は kwargs しか見ない
  ため、journal_detail をルーティングと同じく index_id= で呼ぶ
- weko-workflow (121eb34): get_feedback_maillist に check_authority が
  付いたため、申請者でない contributor では本体に届かない。sysadmin で確認する

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

API インベントリ差分(件数のみ)

台帳ブランチ: develop_v2.1.0

明細は公開できないため件数のみ表示しています。該当箇所はプライベートリポジトリ側の台帳・レポートで確認してください。

ベースラインとの差分

API インベントリ差分レポート

  • 旧: b572c442d v2.0.4-577-gb572c442d (profile=default) endpoints=933 (外部ライブラリ由来 359)
  • 新: 03546146a v2.0.4-676-g03546146a (profile=default) endpoints=933 (外部ライブラリ由来 359)

判定: ❌ FAIL (FAIL 1 / WARN 3)

サマリ

分類 件数
ADDED 0
REMOVED 0
RULE_CHANGED 0
METHODS_CHANGED 0
AUTH_CHANGED 35
IMPL_CHANGED 9
ATTRS_UNKNOWN_NEW 0
ModelView 追加 0
ModelView 削除 0
ModelView フラグ変化 0
config 変化 2
コメントアウト認証の増加 0
依存パッケージの版変化 2

[FAIL] G2 認証系デコレータが削除された — 3件

件数のみ。該当の経路名はプライベートリポジトリ側の完全版レポートを参照。

[WARN] W2 実装本体が変化(data_op / 情報露出を再確認) — 9件

件数のみ。該当の経路名はプライベートリポジトリ側の完全版レポートを参照。

[WARN] W6 依存パッケージの版が変化した — 2件

  • distlib — 0.4.3 -> 0.4.4
  • pbr — 7.0.3 -> 7.1.3

[WARN] W5 監視対象 config が変化した — 2件

件数のみ。該当の経路名はプライベートリポジトリ側の完全版レポートを参照。


台帳との突き合わせ

(生成されませんでした)

ソース由来の経路検知

(生成されませんでした)

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