Skip to content

Commit d5e72d4

Browse files
committed
docs: add test specifications documentation
1 parent 9b162e7 commit d5e72d4

File tree

1 file changed

+210
-0
lines changed

1 file changed

+210
-0
lines changed

docs/requirements/test_specs.md

Lines changed: 210 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,210 @@
1+
# Test Structure Specification
2+
3+
## 1. テストの基本構造
4+
5+
### 1.1 ディレクトリ構成
6+
```
7+
test/
8+
├── / # 基本的なユーティリティテスト
9+
├── auth_time/ # 認証時刻関連のテスト
10+
├── authorization_code/ # 認可コードフローのテスト
11+
├── backchannel_logout/ # バックチャネルログアウトのテスト
12+
├── base_token/ # トークン基本機能のテスト
13+
├── certificate_bound_access_tokens/ # 証明書バインドトークンのテスト
14+
├── ciba/ # Client Initiated Backchannel Authenticationのテスト
15+
├── claim_types/ # クレームタイプのテスト
16+
├── claims/ # クレーム処理のテスト
17+
├── client_auth/ # クライアント認証のテスト
18+
├── client_credentials/ # クライアントクレデンシャルフローのテスト
19+
├── client_id_uri/ # クライアントIDとURIのテスト
20+
├── configuration/ # プロバイダー設定のテスト
21+
├── core/ # コア機能のテスト
22+
├── cors/ # CORS機能のテスト
23+
├── custom_grants/ # カスタムグラントタイプのテスト
24+
├── custom_response_modes/ # カスタムレスポンスモードのテスト
25+
├── device_code/ # デバイスコードフローのテスト
26+
├── discovery/ # ディスカバリーエンドポイントのテスト
27+
├── dpop/ # DPoP (Demonstrating Proof of Possession) のテスト
28+
├── dynamic_registration/ # 動的クライアント登録のテスト
29+
├── dynamic_token_ttl/ # 動的トークンTTLのテスト
30+
├── encryption/ # 暗号化機能のテスト
31+
├── end_session/ # セッション終了のテスト
32+
├── errors/ # エラーハンドリングのテスト
33+
├── external_signing/ # 外部署名のテスト
34+
├── fapi/ # Financial-grade API のテスト
35+
├── form_post/ # フォームポストレスポンスモードのテスト
36+
├── formats/ # トークンフォーマットのテスト
37+
├── helpers/ # テストヘルパー関数
38+
├── id_token_claims/ # IDトークンクレームのテスト
39+
├── interaction/ # ユーザー対話のテスト
40+
├── introspection/ # トークンイントロスペクションのテスト
41+
├── iss/ # Issuer関連のテスト
42+
├── jwt/ # JWTトークンのテスト
43+
├── jwt_introspection/ # JWTイントロスペクションのテスト
44+
├── jwt_response_modes/# JWTレスポンスモードのテスト
45+
├── oauth/ # OAuth2.0コア機能のテスト
46+
├── oauth_native_apps/ # ネイティブアプリケーション向けOAuthのテスト
47+
├── pairwise/ # Pairwise Subject Identifiersのテスト
48+
├── pkce/ # PKCE (Proof Key for Code Exchange) のテスト
49+
├── provider/ # OIDCプロバイダーコアのテスト
50+
├── pushed_authorization_requests/ # PARのテスト
51+
├── refresh/ # リフレッシュトークンのテスト
52+
├── registration_management/ # クライアント登録管理のテスト
53+
├── registration_policies/ # 登録ポリシーのテスト
54+
├── request/ # リクエスト処理のテスト
55+
├── resource_indicators/ # リソースインジケーターのテスト
56+
├── revocation/ # トークン失効のテスト
57+
├── routing/ # ルーティングのテスト
58+
├── session_bound_tokens/ # セッションバインドトークンのテスト
59+
├── sessions/ # セッション管理のテスト
60+
├── signatures/ # 署名処理のテスト
61+
├── userinfo/ # ユーザー情報エンドポイントのテスト
62+
└── web_message/ # Webメッセージレスポンスモードのテスト
63+
```
64+
65+
### 1.2 共通ファイル
66+
- `test_helper.js`: テストのセットアップと共通機能を提供
67+
- `default.config.js`: デフォルトのプロバイダー設定を定義
68+
- `models.js`: テスト用のモデル定義を提供
69+
- `keys.js`: テスト用の暗号鍵を定義
70+
- `run.js`: テスト実行のエントリーポイント
71+
- `capture_output.js`: テスト出力のキャプチャ機能
72+
- `ci.js`: CI環境用の設定
73+
- `client.sig.key.js`: クライアント署名キーの定義
74+
75+
## 2. テストの基本パターン
76+
77+
### 2.1 テストファイルの構造
78+
```javascript
79+
import { expect } from 'chai';
80+
import sinon from 'sinon';
81+
import bootstrap from '../test_helper.js';
82+
83+
describe('機能カテゴリ', () => {
84+
before(bootstrap(import.meta.url));
85+
afterEach(sinon.restore);
86+
87+
context('テストシナリオ', () => {
88+
beforeEach(async function() {
89+
// テストの前準備
90+
});
91+
92+
it('期待される動作', async function() {
93+
// テストケース
94+
});
95+
});
96+
});
97+
```
98+
99+
### 2.2 設定ファイルの構造
100+
```javascript
101+
// {feature}.config.js
102+
export default {
103+
config: {
104+
features: {
105+
// 機能固有の設定
106+
},
107+
// その他の設定
108+
},
109+
client: {
110+
// テストクライアントの設定
111+
}
112+
};
113+
```
114+
115+
## 3. テストカテゴリ別の実装パターン
116+
117+
### 3.1 認証フローテスト
118+
- 認可コードフロー
119+
- クライアントクレデンシャル
120+
- デバイスフロー
121+
- CIBAフロー
122+
123+
### 3.2 セキュリティテスト
124+
- PKCE
125+
- DPoP
126+
- FAPI
127+
- 証明書バインド
128+
129+
### 3.3 トークン管理テスト
130+
- 発行
131+
- 検証
132+
- 失効
133+
- イントロスペクション
134+
135+
### 3.4 セッション管理テスト
136+
- セッション作成
137+
- セッション更新
138+
- セッション終了
139+
- バックチャネルログアウト
140+
141+
## 4. テストヘルパーの利用
142+
143+
### 4.1 プロバイダーの初期化
144+
```javascript
145+
const provider = new Provider('http://localhost', {
146+
clients: [...],
147+
features: {...},
148+
// その他の設定
149+
});
150+
```
151+
152+
### 4.2 テストエージェントの利用
153+
```javascript
154+
const agent = supertest(provider.app);
155+
await agent
156+
.get('/auth')
157+
.query(params)
158+
.expect(200);
159+
```
160+
161+
## 5. テスト実行
162+
163+
### 5.1 実行コマンド
164+
```bash
165+
# すべてのテストを実行
166+
npm test
167+
168+
# 特定のカテゴリのテストを実行
169+
mocha test/authorization_code/**/*.test.js
170+
171+
# カバレッジレポートの生成
172+
npm run test:coverage
173+
```
174+
175+
### 5.2 CI/CD環境での実行
176+
```bash
177+
# CI環境での実行
178+
NODE_ENV=test npm test
179+
180+
# デバッグ出力の有効化
181+
DEBUG=oidc-provider:* npm test
182+
```
183+
184+
## 6. テスト拡張のガイドライン
185+
186+
### 6.1 新機能のテスト追加
187+
1. 適切なディレクトリを選択または作成
188+
2. 設定ファイルを作成 (`{feature}.config.js`)
189+
3. テストファイルを作成 (`{feature}.test.js`)
190+
4. 共通ヘルパーを活用
191+
192+
### 6.2 テストカバレッジ
193+
1. 正常系のテスト
194+
2. エラーケースのテスト
195+
3. エッジケースのテスト
196+
4. セキュリティ要件のテスト
197+
198+
## 7. ベストプラクティス
199+
200+
### 7.1 テスト設計
201+
1. 一つのテストファイルは一つの機能に集中
202+
2. 適切な記述的なテスト名を使用
203+
3. テストの前提条件を明確に記述
204+
4. モック/スタブを適切に使用
205+
206+
### 7.2 テストメンテナンス
207+
1. 重複コードを避ける
208+
2. テストデータを分離
209+
3. 設定を再利用可能にする
210+
4. テストの依存関係を明確にする

0 commit comments

Comments
 (0)