def test_basic(self): cid = CaseInsensitiveDict({}) cid['a'] = 'b' cid['c'] = 'd' del cid['c'] self.assertEqual(cid['A'], 'b') self.assertEqual(cid['a'], 'b')
class MsSessionConfig: """Dataclass-configuration for creating 'MsRequestsSession' Dataclass attributes: client_id: client ID. client_secret: client secret. tenant: ID of the authority for "authority_host_url" that is responsible for token issuing. verification_url: you service url to call. verification_element: key in json that should be returned in the response on the first json "level". verify_on_startup: when verification_url is specified the default is to perform verification in constructor. verify_on_startup = False will skip verification even when url is specified. You can still perform verification manually with the verify() method. do_adal: if True -> use 'adal' method to fetch access token; otherwise use 'MSAL'. resource: uri/identifier of the resource to which you're going to make calls to. authority_host_url: base authority to issuing the token. scope: scope of the permissions that will be given (for adal only). auto_adding_headers: headers that will be automatically added to each request made by the "session". Existing headers will be overwritten be headers in this field. """ client_id: str client_secret: str tenant: str verification_url: Optional[str] = None verification_element: Optional[str] = None verify_on_startup: bool = True do_adal: bool = True resource: str = "https://management.core.windows.net/" authority_host_url: str = "https://login.microsoftonline.com" scope: List[str] = field(default_factory=lambda: ["read", "write"]) auto_adding_headers: CaseInsensitiveDict = field(default_factory=lambda: CaseInsensitiveDict({}))
def _raise_on_bad_post_request(self, request): """Raise if invalid POST request received """ if request.http_method.upper() == 'POST': query_params = CaseInsensitiveDict( dict(urldecode(request.uri_query))) for key in query_params: if key not in OAUTHLIB_ALLOWED_POST_QUERY_PARAMS: raise InvalidRequestError( request=request, description=( 'URL query parameters are not allowed for key {key}' .format(key=key)))
def _create_request(self, uri, http_method, body, headers): # Only include body data from x-www-form-urlencoded requests headers = CaseInsensitiveDict(headers or {}) if ( "Content-Type" in headers and CONTENT_TYPE_FORM_URLENCODED in headers["Content-Type"] ): request = Request(uri, http_method, body, headers) else: request = Request(uri, http_method, "", headers) signature_type, params, oauth_params = self._get_signature_type_and_params( request ) # The server SHOULD return a 400 (Bad Request) status code when # receiving a request with duplicated protocol parameters. if len(dict(oauth_params)) != len(oauth_params): raise errors.InvalidRequestError(description="Duplicate OAuth1 entries.") oauth_params = dict(oauth_params) request.signature = oauth_params.get("oauth_signature") request.client_key = oauth_params.get("oauth_consumer_key") request.resource_owner_key = oauth_params.get("oauth_token") request.nonce = oauth_params.get("oauth_nonce") request.timestamp = oauth_params.get("oauth_timestamp") request.redirect_uri = oauth_params.get("oauth_callback") request.verifier = oauth_params.get("oauth_verifier") request.signature_method = oauth_params.get("oauth_signature_method") request.realm = dict(params).get("realm") request.oauth_params = oauth_params # Parameters to Client depend on signature method which may vary # for each request. Note that HMAC-SHA1 and PLAINTEXT share parameters request.params = [(k, v) for k, v in params if k != "oauth_signature"] if "realm" in request.headers.get("Authorization", ""): request.params = [(k, v) for k, v in request.params if k != "realm"] return request
def test_update(self): cid = CaseInsensitiveDict({}) cid.update({'KeY': 'value'}) self.assertEqual(cid['kEy'], 'value')