How to use _is_in_allowed_origins method in localstack

Best Python code snippet using localstack_python

generic_proxy.py

Source:generic_proxy.py Github

copy

Full Screen

...192def cors_error_response():193 response = Response()194 response.status_code = 403195 return response196def _is_in_allowed_origins(allowed_origins, origin):197 for allowed_origin in allowed_origins:198 if allowed_origin == "*" or origin == allowed_origin:199 return True200 return False201def is_cors_origin_allowed(headers, allowed_origins=None):202 """Returns true if origin is allowed to perform cors requests, false otherwise"""203 allowed_origins = ALLOWED_CORS_ORIGINS if allowed_origins is None else allowed_origins204 origin = headers.get("origin")205 referer = headers.get("referer")206 if origin:207 return _is_in_allowed_origins(allowed_origins, origin)208 elif referer:209 referer_uri = "{uri.scheme}://{uri.netloc}".format(uri=urlparse(referer))210 return _is_in_allowed_origins(allowed_origins, referer_uri)211 # If both headers are not set, let it through (awscli etc. do not send these headers)212 return True213def should_enforce_self_managed_service(method, path, headers, data):214 if config.DISABLE_CUSTOM_CORS_S3 and config.DISABLE_CUSTOM_CORS_APIGATEWAY:215 return True216 # allow only certain api calls without checking origin217 import localstack.services.edge218 api, _ = localstack.services.edge.get_api_from_custom_rules(method, path, data, headers) or (219 "",220 None,221 )222 if not config.DISABLE_CUSTOM_CORS_S3 and api == "s3":223 return False224 if not config.DISABLE_CUSTOM_CORS_APIGATEWAY and api == "apigateway":...

Full Screen

Full Screen

cors.py

Source:cors.py Github

copy

Full Screen

...119 """Returns true if origin is allowed to perform cors requests, false otherwise."""120 origin = headers.get("origin")121 referer = headers.get("referer")122 if origin:123 return CorsEnforcer._is_in_allowed_origins(ALLOWED_CORS_ORIGINS, origin)124 elif referer:125 referer_uri = "{uri.scheme}://{uri.netloc}".format(uri=urlparse(referer))126 return CorsEnforcer._is_in_allowed_origins(ALLOWED_CORS_ORIGINS, referer_uri)127 # If both headers are not set, let it through (awscli etc. do not send these headers)128 return True129 @staticmethod130 def _is_in_allowed_origins(allowed_origins: List[str], origin: str) -> bool:131 """Returns true if the `origin` is in the `allowed_origins`."""132 for allowed_origin in allowed_origins:133 if allowed_origin == "*" or origin == allowed_origin:134 return True135 return False136class CorsResponseEnricher(Handler):137 """138 ResponseHandler which adds Cross-Origin-Request-Sharing (CORS) headers (Access-Control-*) to the response.139 """140 def __call__(self, chain: HandlerChain, context: RequestContext, response: Response):141 # use this config to disable returning CORS headers entirely (more restrictive security setting)142 if config.DISABLE_CORS_HEADERS:143 return144 request_headers = context.request.headers...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run localstack automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful