@@ -289,6 +289,165 @@ def test_url(self):
289289 )
290290
291291
292+ @pytest .mark .parametrize (
293+ 'task_options' ,
294+ (
295+ WebTaskOptions (
296+ correlation_id = 'correlation_id' ,
297+ reply_to = 'reply_to' ,
298+ api_key = 'api_key' ,
299+ installation_id = 'installation_id' ,
300+ ),
301+ WebTaskOptions (
302+ correlation_id = 'correlation_id' ,
303+ reply_to = 'reply_to' ,
304+ api_key = 'api_key' ,
305+ installation_id = 'installation_id' ,
306+ connect_correlation_id = 'connect_correlation_id' ,
307+ user_id = 'user_id' ,
308+ account_id = 'account_id' ,
309+ account_role = 'account_role' ,
310+ call_type = 'user' ,
311+ call_source = 'ui' ,
312+ ),
313+ ),
314+ )
315+ @pytest .mark .asyncio
316+ async def test_http_call_redirect (mocker , ws_server , unused_port , settings_payload , task_options ):
317+ setup_response = copy .deepcopy (settings_payload )
318+ setup_response ['logging' ]['logging_api_key' ] = 'logging_api_key'
319+ setup_response ['logging' ]['log_level' ] = None
320+ mocker .patch (
321+ 'connect.eaas.runner.config.get_environment' ,
322+ return_value = {
323+ 'ws_address' : f'127.0.0.1:{ unused_port } ' ,
324+ 'api_address' : f'127.0.0.1:{ unused_port } ' ,
325+ 'api_key' : 'SU-000:XXXX' ,
326+ 'environment_id' : 'ENV-000-0001' ,
327+ 'instance_id' : 'INS-000-0002' ,
328+ 'background_task_max_execution_time' : 300 ,
329+ 'interactive_task_max_execution_time' : 120 ,
330+ 'scheduled_task_max_execution_time' : 43200 ,
331+ 'webapp_port' : 53575 ,
332+ },
333+ )
334+
335+ ui_modules = {
336+ 'settings' : {
337+ 'label' : 'Settings' ,
338+ 'url' : '/static/settings.html' ,
339+ },
340+ }
341+
342+ @account_settings_page ('Settings' , '/static/settings.html' )
343+ @web_app (router )
344+ class MyExtension (WebApplicationBase ):
345+ @classmethod
346+ def get_descriptor (cls ):
347+ return {
348+ 'readme_url' : 'https://read.me' ,
349+ 'changelog_url' : 'https://change.log' ,
350+ }
351+
352+ @classmethod
353+ def get_static_root (cls ):
354+ return None
355+
356+ @router .get ('/test/url' )
357+ def test_url (self ):
358+ return {'test' : 'ok' }
359+
360+ mocker .patch .object (
361+ WebApp ,
362+ 'load_application' ,
363+ return_value = MyExtension ,
364+ )
365+
366+ mocker .patch ('connect.eaas.runner.workers.web.get_version' , return_value = '24.1' )
367+
368+ web_task = WebTask (
369+ options = task_options ,
370+ request = HttpRequest (
371+ method = 'GET' ,
372+ url = '/api/test/url/' ,
373+ headers = {
374+ 'X-Forwarded-Host' : 'my.proxy.host' ,
375+ 'X-Forwarded-Proto' : 'https' ,
376+ },
377+ ),
378+ )
379+
380+ data_to_send = [
381+ Message (
382+ version = 2 ,
383+ message_type = MessageType .SETUP_RESPONSE ,
384+ data = SetupResponse (** setup_response ),
385+ ).dict (),
386+ Message (
387+ version = 2 ,
388+ message_type = MessageType .WEB_TASK ,
389+ data = web_task ,
390+ ).dict (),
391+ ]
392+
393+ handler = WSHandler (
394+ '/public/v1/devops/ws/ENV-000-0001/INS-000-0002/webapp' ,
395+ data_to_send ,
396+ ['receive' , 'send' , 'send' , 'receive' ],
397+ )
398+
399+ config = ConfigHelper (secure = False )
400+ ext_handler = WebApp (config )
401+
402+ worker = None
403+ async with ws_server (handler ):
404+ worker = WebWorker (ext_handler , mocker .MagicMock (), mocker .MagicMock (), mocker .MagicMock ())
405+ task = asyncio .create_task (worker .start ())
406+ await asyncio .sleep (.5 )
407+ worker .stop ()
408+ await task
409+
410+ handler .assert_received (
411+ Message (
412+ version = 2 ,
413+ message_type = MessageType .SETUP_REQUEST ,
414+ data = SetupRequest (
415+ event_subscriptions = None ,
416+ ui_modules = ui_modules ,
417+ variables = [],
418+ schedulables = None ,
419+ repository = {
420+ 'readme_url' : 'https://read.me' ,
421+ 'changelog_url' : 'https://change.log' ,
422+ },
423+ runner_version = '24.1' ,
424+ ),
425+ ),
426+ )
427+ handler .assert_received (
428+ Message (
429+ version = 2 ,
430+ message_type = MessageType .WEB_TASK ,
431+ data = WebTask (
432+ options = task_options ,
433+ request = HttpRequest (
434+ method = 'GET' ,
435+ url = '/api/test/url/' ,
436+ headers = {},
437+ ),
438+ response = HttpResponse (
439+ status = 307 ,
440+ headers = {
441+ 'content-length' : '0' ,
442+ 'location' : 'https://my.proxy.host/api/test/url' ,
443+ },
444+ content = '' ,
445+ ),
446+ ),
447+ ),
448+ )
449+
450+
292451@pytest .mark .asyncio
293452async def test_http_call_exception (mocker , ws_server , unused_port , settings_payload ):
294453 setup_response = copy .deepcopy (settings_payload )
0 commit comments