Пример #1
0
 def sastoken(self, request, signing_mechanism):
     token_type = request.param
     if token_type == "Device Token":
         return RenewableSasToken(uri=fake_uri,
                                  signing_mechanism=signing_mechanism)
     elif token_type == "Service Token":
         return RenewableSasToken(uri=fake_uri,
                                  signing_mechanism=signing_mechanism,
                                  key_name=fake_key_name)
Пример #2
0
def connection_string_to_sas_token(conn_str):
    """
    parse an IoTHub service connection string and return the host and a shared access
    signature that can be used to connect to the given hub
    """
    conn_str_obj = ConnectionString(conn_str)
    signing_mechanism = SymmetricKeySigningMechanism(conn_str_obj.get("SharedAccessKey"))
    sas_token = RenewableSasToken(
        uri=conn_str_obj.get("HostName"),
        signing_mechanism=signing_mechanism,
        key_name=conn_str_obj.get("SharedAccessKeyName"),
    )

    return {"host": conn_str_obj.get("HostName"), "sas": str(sas_token)}
Пример #3
0
    def test_expiry_time(self, mocker, signing_mechanism):
        fake_current_time = 1000
        mocker.patch.object(time, "time", return_value=fake_current_time)

        s = RenewableSasToken(fake_uri, signing_mechanism)
        assert s.expiry_time == fake_current_time + s.ttl
Пример #4
0
 def test_custom_key_name(self, signing_mechanism):
     s = RenewableSasToken(fake_uri,
                           signing_mechanism,
                           key_name=fake_key_name)
     assert s._key_name == fake_key_name
Пример #5
0
 def test_default_key_name(self, signing_mechanism):
     s = RenewableSasToken(fake_uri, signing_mechanism)
     assert s._key_name is None
Пример #6
0
 def test_custom_ttl(self, signing_mechanism):
     custom_ttl = 4747
     s = RenewableSasToken(fake_uri, signing_mechanism, ttl=custom_ttl)
     assert s.ttl == custom_ttl
Пример #7
0
 def test_default_ttl(self, signing_mechanism):
     s = RenewableSasToken(fake_uri, signing_mechanism)
     assert s.ttl == 3600
Пример #8
0
 def test_refresh_on_instantiation(self, mocker, signing_mechanism):
     refresh_mock = mocker.spy(RenewableSasToken, "refresh")
     assert refresh_mock.call_count == 0
     RenewableSasToken(fake_uri, signing_mechanism)
     assert refresh_mock.call_count == 1