How to use validate_metadata method in mailosaur-python

Best Python code snippet using mailosaur-python_python

metadata.py

Source:metadata.py Github

copy

Full Screen

...45 'Content-Type': 'application/json',46 'Access-Control-Allow-Origin': '*',47 }48 return headers, json.dumps(self.claims), 20049 def validate_metadata(self, array, key, is_required=False, is_list=False, is_url=False, is_issuer=False):50 if not self.raise_errors:51 return52 if key not in array:53 if is_required:54 raise ValueError("key {} is a mandatory metadata.".format(key))55 elif is_issuer:56 if not array[key].startswith("https"):57 raise ValueError("key {}: {} must be an HTTPS URL".format(key, array[key]))58 if "?" in array[key] or "&" in array[key] or "#" in array[key]:59 raise ValueError("key {}: {} must not contain query or fragment components".format(key, array[key]))60 elif is_url:61 if not array[key].startswith("http"):62 raise ValueError("key {}: {} must be an URL".format(key, array[key]))63 elif is_list:64 if not isinstance(array[key], list):65 raise ValueError("key {}: {} must be an Array".format(key, array[key]))66 for elem in array[key]:67 if not isinstance(elem, str):68 raise ValueError("array {}: {} must contains only string (not {})".format(key, array[key], elem))69 def validate_metadata_token(self, claims, endpoint):70 """71 If the token endpoint is used in the grant type, the value of this72 parameter MUST be the same as the value of the "grant_type"73 parameter passed to the token endpoint defined in the grant type74 definition.75 """76 self._grant_types.extend(endpoint._grant_types.keys())77 claims.setdefault("token_endpoint_auth_methods_supported", ["client_secret_post", "client_secret_basic"])78 self.validate_metadata(claims, "token_endpoint_auth_methods_supported", is_list=True)79 self.validate_metadata(claims, "token_endpoint_auth_signing_alg_values_supported", is_list=True)80 self.validate_metadata(claims, "token_endpoint", is_required=True, is_url=True)81 def validate_metadata_authorization(self, claims, endpoint):82 claims.setdefault("response_types_supported",83 list(filter(lambda x: x != "none", endpoint._response_types.keys())))84 claims.setdefault("response_modes_supported", ["query", "fragment"])85 # The OAuth2.0 Implicit flow is defined as a "grant type" but it is not86 # using the "token" endpoint, as such, we have to add it explicitly to87 # the list of "grant_types_supported" when enabled.88 if "token" in claims["response_types_supported"]:89 self._grant_types.append("implicit")90 self.validate_metadata(claims, "response_types_supported", is_required=True, is_list=True)91 self.validate_metadata(claims, "response_modes_supported", is_list=True)92 if "code" in claims["response_types_supported"]:93 code_grant = endpoint._response_types["code"]94 if not isinstance(code_grant, grant_types.AuthorizationCodeGrant) and hasattr(code_grant, "default_grant"):95 code_grant = code_grant.default_grant96 claims.setdefault("code_challenge_methods_supported",97 list(code_grant._code_challenge_methods.keys()))98 self.validate_metadata(claims, "code_challenge_methods_supported", is_list=True)99 self.validate_metadata(claims, "authorization_endpoint", is_required=True, is_url=True)100 def validate_metadata_revocation(self, claims, endpoint):101 claims.setdefault("revocation_endpoint_auth_methods_supported",102 ["client_secret_post", "client_secret_basic"])103 self.validate_metadata(claims, "revocation_endpoint_auth_methods_supported", is_list=True)104 self.validate_metadata(claims, "revocation_endpoint_auth_signing_alg_values_supported", is_list=True)105 self.validate_metadata(claims, "revocation_endpoint", is_required=True, is_url=True)106 def validate_metadata_introspection(self, claims, endpoint):107 claims.setdefault("introspection_endpoint_auth_methods_supported",108 ["client_secret_post", "client_secret_basic"])109 self.validate_metadata(claims, "introspection_endpoint_auth_methods_supported", is_list=True)110 self.validate_metadata(claims, "introspection_endpoint_auth_signing_alg_values_supported", is_list=True)111 self.validate_metadata(claims, "introspection_endpoint", is_required=True, is_url=True)112 def validate_metadata_server(self):113 """114 Authorization servers can have metadata describing their115 configuration. The following authorization server metadata values116 are used by this specification. More details can be found in117 `RFC8414 section 2`_ :118 issuer119 REQUIRED120 authorization_endpoint121 URL of the authorization server's authorization endpoint122 [`RFC6749#Authorization`_]. This is REQUIRED unless no grant types are supported123 that use the authorization endpoint.124 token_endpoint125 URL of the authorization server's token endpoint [`RFC6749#Token`_]. This126 is REQUIRED unless only the implicit grant type is supported.127 scopes_supported128 RECOMMENDED.129 response_types_supported130 REQUIRED.131 Other OPTIONAL fields:132 jwks_uri,133 registration_endpoint,134 response_modes_supported135 grant_types_supported136 OPTIONAL. JSON array containing a list of the OAuth 2.0 grant137 type values that this authorization server supports. The array138 values used are the same as those used with the "grant_types"139 parameter defined by "OAuth 2.0 Dynamic Client Registration140 Protocol" [`RFC7591`_]. If omitted, the default value is141 "["authorization_code", "implicit"]".142 token_endpoint_auth_methods_supported143 token_endpoint_auth_signing_alg_values_supported144 service_documentation145 ui_locales_supported146 op_policy_uri147 op_tos_uri148 revocation_endpoint149 revocation_endpoint_auth_methods_supported150 revocation_endpoint_auth_signing_alg_values_supported151 introspection_endpoint152 introspection_endpoint_auth_methods_supported153 introspection_endpoint_auth_signing_alg_values_supported154 code_challenge_methods_supported155 Additional authorization server metadata parameters MAY also be used.156 Some are defined by other specifications, such as OpenID Connect157 Discovery 1.0 [`OpenID.Discovery`_].158 .. _`RFC8414 section 2`: https://tools.ietf.org/html/rfc8414#section-2159 .. _`RFC6749#Authorization`: https://tools.ietf.org/html/rfc6749#section-3.1160 .. _`RFC6749#Token`: https://tools.ietf.org/html/rfc6749#section-3.2161 .. _`RFC7591`: https://tools.ietf.org/html/rfc7591162 .. _`OpenID.Discovery`: https://openid.net/specs/openid-connect-discovery-1_0.html163 """164 claims = copy.deepcopy(self.initial_claims)165 self.validate_metadata(claims, "issuer", is_required=True, is_issuer=True)166 self.validate_metadata(claims, "jwks_uri", is_url=True)167 self.validate_metadata(claims, "scopes_supported", is_list=True)168 self.validate_metadata(claims, "service_documentation", is_url=True)169 self.validate_metadata(claims, "ui_locales_supported", is_list=True)170 self.validate_metadata(claims, "op_policy_uri", is_url=True)171 self.validate_metadata(claims, "op_tos_uri", is_url=True)172 self._grant_types = []173 for endpoint in self.endpoints:174 if isinstance(endpoint, TokenEndpoint):175 self.validate_metadata_token(claims, endpoint)176 if isinstance(endpoint, AuthorizationEndpoint):177 self.validate_metadata_authorization(claims, endpoint)178 if isinstance(endpoint, RevocationEndpoint):179 self.validate_metadata_revocation(claims, endpoint)180 if isinstance(endpoint, IntrospectEndpoint):181 self.validate_metadata_introspection(claims, endpoint)182 # "grant_types_supported" is a combination of all OAuth2 grant types183 # allowed in the current provider implementation.184 claims.setdefault("grant_types_supported", self._grant_types)185 self.validate_metadata(claims, "grant_types_supported", is_list=True)...

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 mailosaur-python 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