-
Notifications
You must be signed in to change notification settings - Fork 98
Expand file tree
/
Copy pathauthorization-server.ts
More file actions
76 lines (63 loc) · 2.08 KB
/
Copy pathauthorization-server.ts
File metadata and controls
76 lines (63 loc) · 2.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import { promises as fs } from 'fs';
import path from 'path';
import { ConformanceCheck } from '../types';
import { getClientScenarioForAuthorizationServer } from '../scenarios';
import { createResultDir } from './utils';
import { AuthorizationServerOptions } from '../schemas';
export async function runAuthorizationServerConformanceTest(
option: AuthorizationServerOptions,
scenarioName: string,
details: Record<string, unknown>,
outputDir?: string
): Promise<{
checks: ConformanceCheck[];
resultDir?: string;
scenarioDescription: string;
}> {
let resultDir: string | undefined;
if (outputDir) {
resultDir = createResultDir(
outputDir,
scenarioName,
'authorization-server'
);
await fs.mkdir(resultDir, { recursive: true });
}
// Scenario is guaranteed to exist by CLI validation
const scenario = getClientScenarioForAuthorizationServer(scenarioName)!;
console.log(
`Running client scenario for authorization server '${scenarioName}' against server: ${option.url}`
);
const checks = await scenario.run(option, details);
if (resultDir) {
await fs.writeFile(
path.join(resultDir, 'checks.json'),
JSON.stringify(checks, null, 2)
);
console.log(`Results saved to ${resultDir}`);
}
return {
checks,
resultDir,
scenarioDescription: scenario.description
};
}
export function printAuthorizationServerSummary(
allResults: { scenario: string; checks: ConformanceCheck[] }[]
): { totalPassed: number; totalFailed: number } {
console.log('\n\n=== SUMMARY ===');
let totalPassed = 0;
let totalFailed = 0;
for (const result of allResults) {
const passed = result.checks.filter((c) => c.status === 'SUCCESS').length;
const failed = result.checks.filter((c) => c.status === 'FAILURE').length;
totalPassed += passed;
totalFailed += failed;
const status = failed === 0 ? '✓' : '✗';
console.log(
`${status} ${result.scenario}: ${passed} passed, ${failed} failed`
);
}
console.log(`\nTotal: ${totalPassed} passed, ${totalFailed} failed`);
return { totalPassed, totalFailed };
}