@@ -60,8 +60,8 @@ describe('plugin-endpoint', () => {
60
60
const collector = new PluginPermissionMetadataCollector (
61
61
mockPluginEndpointDiscovery ,
62
62
backendPluginIDsProviderMock ,
63
- config ,
64
63
logger ,
64
+ config ,
65
65
) ;
66
66
const policiesMetadata = await collector . getPluginPolicies ( ) ;
67
67
@@ -79,8 +79,8 @@ describe('plugin-endpoint', () => {
79
79
const collector = new PluginPermissionMetadataCollector (
80
80
mockPluginEndpointDiscovery ,
81
81
backendPluginIDsProviderMock ,
82
- config ,
83
82
logger ,
83
+ config ,
84
84
) ;
85
85
const policiesMetadata = await collector . getPluginPolicies ( ) ;
86
86
@@ -109,8 +109,8 @@ describe('plugin-endpoint', () => {
109
109
const collector = new PluginPermissionMetadataCollector (
110
110
mockPluginEndpointDiscovery ,
111
111
backendPluginIDsProviderMock ,
112
- config ,
113
112
logger ,
113
+ config ,
114
114
) ;
115
115
const policiesMetadata = await collector . getPluginPolicies ( ) ;
116
116
@@ -148,8 +148,8 @@ describe('plugin-endpoint', () => {
148
148
const collector = new PluginPermissionMetadataCollector (
149
149
mockPluginEndpointDiscovery ,
150
150
backendPluginIDsProviderMock ,
151
- config ,
152
151
logger ,
152
+ config ,
153
153
) ;
154
154
const policiesMetadata = await collector . getPluginPolicies ( ) ;
155
155
@@ -163,7 +163,7 @@ describe('plugin-endpoint', () => {
163
163
] ) ;
164
164
} ) ;
165
165
166
- it ( 'should throw error when it is not possible to retrieve permission metadata for known endpoint' , async ( ) => {
166
+ it ( 'should log error when it is not possible to retrieve permission metadata for known endpoint' , async ( ) => {
167
167
backendPluginIDsProviderMock . getPluginIds . mockReturnValue ( [
168
168
'permission' ,
169
169
'catalog' ,
@@ -184,16 +184,69 @@ describe('plugin-endpoint', () => {
184
184
'{"permissions":[{"type":"resource","name":"policy.entity.read","attributes":{"action":"read"}}]}' ,
185
185
) ;
186
186
187
+ const errorSpy = jest . spyOn ( logger , 'error' ) . mockClear ( ) ;
187
188
const collector = new PluginPermissionMetadataCollector (
188
189
mockPluginEndpointDiscovery ,
189
190
backendPluginIDsProviderMock ,
190
- config ,
191
191
logger ,
192
+ config ,
192
193
) ;
193
- await expect ( collector . getPluginPolicies ( ) ) . rejects . toThrow (
194
- 'Unexpected error' ,
194
+
195
+ const policiesMetadata = await collector . getPluginPolicies ( ) ;
196
+
197
+ expect ( policiesMetadata . length ) . toEqual ( 1 ) ;
198
+ expect ( policiesMetadata [ 0 ] . pluginId ) . toEqual ( 'permission' ) ;
199
+ expect ( policiesMetadata [ 0 ] . policies ) . toEqual ( [
200
+ {
201
+ permission : 'policy.entity.read' ,
202
+ policy : 'read' ,
203
+ } ,
204
+ ] ) ;
205
+
206
+ expect ( errorSpy ) . toHaveBeenCalledWith (
207
+ 'Failed to retrieve permission metadata for catalog. Error: Unexpected error' ,
195
208
) ;
196
209
} ) ;
210
+
211
+ it ( 'should not log error caused by non json permission metadata for known endpoint' , async ( ) => {
212
+ backendPluginIDsProviderMock . getPluginIds . mockReturnValue ( [
213
+ 'permission' ,
214
+ 'catalog' ,
215
+ ] ) ;
216
+
217
+ mockUrlReaderService . readUrl = jest
218
+ . fn ( )
219
+ . mockImplementation ( async ( _wellKnownURL : string ) => {
220
+ return mockReadUrlResponse ;
221
+ } ) ;
222
+ bufferMock . toString
223
+ . mockReturnValueOnce (
224
+ '{"permissions":[{"type":"resource","name":"policy.entity.read","attributes":{"action":"read"}}]}' ,
225
+ )
226
+ . mockReturnValueOnce ( 'non json data' ) ;
227
+
228
+ const errorSpy = jest . spyOn ( logger , 'error' ) . mockClear ( ) ;
229
+
230
+ const collector = new PluginPermissionMetadataCollector (
231
+ mockPluginEndpointDiscovery ,
232
+ backendPluginIDsProviderMock ,
233
+ logger ,
234
+ config ,
235
+ ) ;
236
+ const policiesMetadata = await collector . getPluginPolicies ( ) ;
237
+
238
+ expect ( policiesMetadata . length ) . toEqual ( 1 ) ;
239
+ expect ( policiesMetadata [ 0 ] . pluginId ) . toEqual ( 'permission' ) ;
240
+ expect ( policiesMetadata [ 0 ] . policies ) . toEqual ( [
241
+ {
242
+ permission : 'policy.entity.read' ,
243
+ policy : 'read' ,
244
+ } ,
245
+ ] ) ;
246
+
247
+ // workaround for https://issues.redhat.com/browse/RHIDP-1456
248
+ expect ( errorSpy ) . not . toHaveBeenCalled ( ) ;
249
+ } ) ;
197
250
} ) ;
198
251
199
252
describe ( 'Test list plugin condition rules' , ( ) => {
@@ -203,8 +256,8 @@ describe('plugin-endpoint', () => {
203
256
const collector = new PluginPermissionMetadataCollector (
204
257
mockPluginEndpointDiscovery ,
205
258
backendPluginIDsProviderMock ,
206
- config ,
207
259
logger ,
260
+ config ,
208
261
) ;
209
262
const conditionRulesMetadata = await collector . getPluginConditionRules ( ) ;
210
263
@@ -222,8 +275,8 @@ describe('plugin-endpoint', () => {
222
275
const collector = new PluginPermissionMetadataCollector (
223
276
mockPluginEndpointDiscovery ,
224
277
backendPluginIDsProviderMock ,
225
- config ,
226
278
logger ,
279
+ config ,
227
280
) ;
228
281
const conditionRulesMetadata = await collector . getPluginConditionRules ( ) ;
229
282
0 commit comments