|
8 | 8 | */ |
9 | 9 |
|
10 | 10 | import { ProjectRoutingAccess } from '@kbn/cps-utils'; |
11 | | -import { |
12 | | - getProjectRoutingAccess, |
13 | | - DEFAULT_ACCESS_CONTROL_CONFIG, |
14 | | - type AccessControlConfig, |
15 | | -} from './access_control'; |
| 11 | +import { ACCESS_CONTROL_CONFIG, getProjectRoutingAccess } from './access_control'; |
16 | 12 |
|
17 | 13 | describe('Access Control Configuration', () => { |
18 | 14 | describe('getProjectRoutingAccess', () => { |
@@ -65,85 +61,33 @@ describe('Access Control Configuration', () => { |
65 | 61 | }); |
66 | 62 | }); |
67 | 63 |
|
68 | | - describe('with custom configuration', () => { |
69 | | - const customConfig: AccessControlConfig = { |
70 | | - myApp: { |
71 | | - defaultAccess: ProjectRoutingAccess.EDITABLE, |
72 | | - }, |
73 | | - customApp: { |
74 | | - defaultAccess: ProjectRoutingAccess.DISABLED, |
75 | | - routeRules: [ |
76 | | - { |
77 | | - pattern: /^#\/special/, |
78 | | - access: ProjectRoutingAccess.EDITABLE, |
79 | | - }, |
80 | | - ], |
81 | | - }, |
82 | | - }; |
83 | | - |
84 | | - it('should use custom app configuration', () => { |
85 | | - expect(getProjectRoutingAccess('myApp', '#/anything', customConfig)).toBe( |
86 | | - ProjectRoutingAccess.EDITABLE |
87 | | - ); |
88 | | - }); |
89 | | - |
90 | | - it('should match route rules before defaultAccess', () => { |
91 | | - expect(getProjectRoutingAccess('customApp', '#/special/page', customConfig)).toBe( |
| 64 | + describe('route rule priority', () => { |
| 65 | + it('should check rules in order and match pattern before defaulting', () => { |
| 66 | + // Rule matches: type:vega pattern -> EDITABLE (overrides DISABLED default) |
| 67 | + expect(getProjectRoutingAccess('visualize', '#/edit/123?type:vega')).toBe( |
92 | 68 | ProjectRoutingAccess.EDITABLE |
93 | 69 | ); |
94 | | - expect(getProjectRoutingAccess('customApp', '#/normal/page', customConfig)).toBe( |
| 70 | + // No rule match: falls back to defaultAccess -> DISABLED |
| 71 | + expect(getProjectRoutingAccess('visualize', '#/edit/456?type:lens')).toBe( |
95 | 72 | ProjectRoutingAccess.DISABLED |
96 | 73 | ); |
97 | | - }); |
98 | | - |
99 | | - it('should return DISABLED for unconfigured apps', () => { |
100 | | - expect(getProjectRoutingAccess('unknownApp', '#/', customConfig)).toBe( |
101 | | - ProjectRoutingAccess.DISABLED |
102 | | - ); |
103 | | - }); |
104 | | - }); |
105 | | - |
106 | | - describe('route rule priority', () => { |
107 | | - const config: AccessControlConfig = { |
108 | | - testApp: { |
109 | | - defaultAccess: ProjectRoutingAccess.DISABLED, |
110 | | - routeRules: [ |
111 | | - { |
112 | | - pattern: /^#\/admin/, |
113 | | - access: ProjectRoutingAccess.READONLY, |
114 | | - }, |
115 | | - { |
116 | | - pattern: /^#\/edit/, |
117 | | - access: ProjectRoutingAccess.EDITABLE, |
118 | | - }, |
119 | | - ], |
120 | | - }, |
121 | | - }; |
122 | | - |
123 | | - it('should check rules in order', () => { |
124 | | - expect(getProjectRoutingAccess('testApp', '#/admin/settings', config)).toBe( |
125 | | - ProjectRoutingAccess.READONLY |
126 | | - ); |
127 | | - expect(getProjectRoutingAccess('testApp', '#/edit/document', config)).toBe( |
128 | | - ProjectRoutingAccess.EDITABLE |
129 | | - ); |
130 | | - expect(getProjectRoutingAccess('testApp', '#/view/document', config)).toBe( |
| 74 | + expect(getProjectRoutingAccess('visualize', '#/create')).toBe( |
131 | 75 | ProjectRoutingAccess.DISABLED |
132 | 76 | ); |
133 | 77 | }); |
134 | 78 | }); |
135 | 79 | }); |
136 | 80 |
|
137 | | - describe('DEFAULT_ACCESS_CONTROL_CONFIG', () => { |
| 81 | + describe('ACCESS_CONTROL_CONFIG', () => { |
138 | 82 | it('should have configuration for expected apps', () => { |
139 | | - expect(DEFAULT_ACCESS_CONTROL_CONFIG).toHaveProperty('dashboards'); |
140 | | - expect(DEFAULT_ACCESS_CONTROL_CONFIG).toHaveProperty('discover'); |
141 | | - expect(DEFAULT_ACCESS_CONTROL_CONFIG).toHaveProperty('visualize'); |
142 | | - expect(DEFAULT_ACCESS_CONTROL_CONFIG).toHaveProperty('lens'); |
| 83 | + expect(ACCESS_CONTROL_CONFIG).toHaveProperty('dashboards'); |
| 84 | + expect(ACCESS_CONTROL_CONFIG).toHaveProperty('discover'); |
| 85 | + expect(ACCESS_CONTROL_CONFIG).toHaveProperty('visualize'); |
| 86 | + expect(ACCESS_CONTROL_CONFIG).toHaveProperty('lens'); |
143 | 87 | }); |
144 | 88 |
|
145 | 89 | it('should have route rules for dashboards', () => { |
146 | | - expect(DEFAULT_ACCESS_CONTROL_CONFIG.dashboards.routeRules).toHaveLength(1); |
| 90 | + expect(ACCESS_CONTROL_CONFIG.dashboards.routeRules).toHaveLength(1); |
147 | 91 | }); |
148 | 92 | }); |
149 | 93 | }); |
0 commit comments