Exemple #1
0
 def test_instantiates_with_custom_ttl(self, kwargs):
     kwargs = copy.copy(kwargs)
     kwargs["ttl"] = 9000
     s = SasToken(**kwargs)
     assert s._uri == kwargs.get("uri")
     assert s._key == kwargs.get("key")
     assert s._key_name == kwargs.get("key_name")
     assert s.ttl == 9000
 def _create_shared_access_signature(self):
     """
     Construct SAS tokens that have a hashed signature formed using the symmetric key of this security client.
     This signature is recreated by the Device Provisioning Service to verify whether a security token presented
     during attestation is authentic or not.
     :return: A string representation of the shared access signature which is of the form
     SharedAccessSignature sig={signature}&se={expiry}&skn={policyName}&sr={URL-encoded-resourceURI}
     """
     uri = self._id_scope + "/registrations/" + self._registration_id
     key = self._symmetric_key
     time_to_live = 3600
     keyname = "registration"
     return SasToken(uri, key, keyname, time_to_live)
Exemple #3
0
 def test_raises_sastoken_error_if_key_is_not_base64(self):
     non_b64_key = "this is not base64"
     with pytest.raises(SasTokenError):
         SasToken(uri, non_b64_key)
Exemple #4
0
    def test_url_encodes_utf8_characters_in_uri(self):
        utf8_uri = "my châteu.host.name"
        s = SasToken(utf8_uri, key)

        expected_uri = "my+ch%C3%A2teu.host.name"
        assert s._uri == expected_uri
Exemple #5
0
 def test_instantiates_with_default_ttl_3600(self, kwargs):
     s = SasToken(**kwargs)
     assert s._uri == kwargs.get("uri")
     assert s._key == kwargs.get("key")
     assert s._key_name == kwargs.get("key_name")
     assert s.ttl == 3600
Exemple #6
0
def sastoken(request):
    token_type = request.param
    if token_type == "Device Token":
        return SasToken(uri, key)
    elif token_type == "Service Token":
        return SasToken(uri, key, key_name)