Best Python code snippet using localstack_python
generic_proxy.py
Source: generic_proxy.py
...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":...
cors.py
Source: cors.py
...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...
Check out the latest blogs from LambdaTest on this topic:
The fact is not alien to us anymore that cross browser testing is imperative to enhance your application’s user experience. Enhanced knowledge of popular and highly acclaimed testing frameworks goes a long way in developing a new app. It holds more significance if you are a full-stack developer or expert programmer.
QA testers have a unique role and responsibility to serve the customer. Serving the customer in software testing means protecting customers from application defects, failures, and perceived failures from missing or misunderstood requirements. Testing for known requirements based on documentation or discussion is the core of the testing profession. One unique way QA testers can both differentiate themselves and be innovative occurs when senseshaping is used to improve the application user experience.
Having a good web design can empower business and make your brand stand out. According to a survey by Top Design Firms, 50% of users believe that website design is crucial to an organization’s overall brand. Therefore, businesses should prioritize website design to meet customer expectations and build their brand identity. Your website is the face of your business, so it’s important that it’s updated regularly as per the current web design trends.
Enterprise resource planning (ERP) is a form of business process management software—typically a suite of integrated applications—that assists a company in managing its operations, interpreting data, and automating various back-office processes. The introduction of a new ERP system is analogous to the introduction of a new product into the market. If the product is not handled appropriately, it will fail, resulting in significant losses for the business. Most significantly, the employees’ time, effort, and morale would suffer as a result of the procedure.
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!