Пример #1
0
def test_create_client():
    to = mock.MagicMock()
    to.max_retries = None

    sa = azops.StorageAccount('name', 'AAAAAA==', 'core.windows.net', 10, to,
                              mock.MagicMock())
    client = ops.create_client(sa, to, mock.MagicMock())
    assert client is not None
    assert isinstance(client, azure.storage.blob.BlockBlobService)
    assert isinstance(
        client.authentication,
        azure.storage.common._auth._StorageSharedKeyAuthentication)
    assert client._USER_AGENT_STRING.startswith('blobxfer/{}'.format(
        blobxfer.version.__version__))
    assert client._httpclient.proxies is not None

    sa = azops.StorageAccount('name', '?key&sig=key', 'core.windows.net', 10,
                              to, None)
    client = ops.create_client(sa, to, None)
    assert client is not None
    assert isinstance(client, azure.storage.blob.BlockBlobService)
    assert isinstance(client.authentication,
                      azure.storage.common._auth._StorageSASAuthentication)
    assert client._USER_AGENT_STRING.startswith('blobxfer/{}'.format(
        blobxfer.version.__version__))
    assert client._httpclient.proxies is None
Пример #2
0
def test_credential_allows_object_write():
    to = mock.MagicMock()
    to.max_retries = None

    a = azops.StorageAccount(
        'name', '?sv=0&sr=1&srt=co&sp=w&sig=2', 'core.windows.net', 10, to,
        None)
    assert a._credential_allows_object_write()
    assert a.can_write_object

    a = azops.StorageAccount(
        'name', '?sv=0&si=policy&sig=2', 'core.windows.net', 10, to, None)
    assert a._credential_allows_object_write()
    assert a.can_write_object

    a = azops.StorageAccount(
        'name', '?sv=0&sr=1&srt=co&sp=r&sig=2', 'core.windows.net', 10, to,
        None)
    assert not a._credential_allows_object_write()
    assert not a.can_write_object

    a = azops.StorageAccount(
        'name', 'AAAAAA==', 'core.windows.net', 10, to, None)
    assert a._credential_allows_object_write()
    assert a.can_write_object
Пример #3
0
def test_ensure_object_manipulation_allowed():
    to = mock.MagicMock()
    to.max_retries = None

    with pytest.raises(ValueError):
        azops.StorageAccount(
            'name', '?sv=0&sr=1&srt=c&sig=2', 'core.windows.net', 10, to, None)

    a = azops.StorageAccount(
        'name', 'AAAAAA==', 'core.windows.net', 10, to, None)
    assert a._ensure_object_manipulation_allowed()
def test_container_creation_allowed():
    a = azops.StorageAccount('name', 'abcdef', 'endpoint', 10,
                             mock.MagicMock())
    assert a._container_creation_allowed()

    a = azops.StorageAccount('name', '?sv=0&sr=1&sig=2', 'endpoint', 10,
                             mock.MagicMock())
    assert not a._container_creation_allowed()

    a = azops.StorageAccount('name', '?sv=0&sr=1&srt=a&sig=2', 'endpoint', 10,
                             mock.MagicMock())
    assert not a._container_creation_allowed()

    a = azops.StorageAccount('name', '?sv=0&sr=1&srt=c&sig=2', 'endpoint', 10,
                             mock.MagicMock())
    assert a._container_creation_allowed()
def test_credential_allows_container_list():
    to = mock.MagicMock()
    to.max_retries = None

    a = azops.StorageAccount('name', '?sv=0&sr=1&srt=co&sp=l&sig=2',
                             'core.windows.net', 10, to, None)
    assert a._credential_allows_container_list()
    assert a.can_list_container_objects

    a = azops.StorageAccount('name', '?sv=0&sr=1&srt=co&sp=r&sig=2',
                             'core.windows.net', 10, to, None)
    assert not a._credential_allows_container_list()
    assert not a.can_list_container_objects

    a = azops.StorageAccount('name', 'AAAAAA==', 'core.windows.net', 10, to,
                             None)
    assert a._credential_allows_container_list()
    assert a.can_list_container_objects
Пример #6
0
def test_container_manipulation_allowed():
    to = mock.MagicMock()
    to.max_retries = None

    a = azops.StorageAccount(
        'name', 'AAAAAA==', 'core.windows.net', 10, to, None)
    assert a._container_manipulation_allowed()

    a = azops.StorageAccount(
        'name', '?sv=0&sr=1&sig=2', 'core.windows.net', 10, to, None)
    assert not a._container_manipulation_allowed()

    a = azops.StorageAccount(
        'name', '?sv=0&sr=1&srt=ao&sig=2', 'core.windows.net', 10, to, None)
    assert not a._container_manipulation_allowed()

    a = azops.StorageAccount(
        'name', '?sv=0&sr=1&srt=co&sig=2', 'core.windows.net', 10, to, None)
    assert a._container_manipulation_allowed()
def test_create_client():
    sa = azops.StorageAccount('name', 'key', 'endpoint', 10, mock.MagicMock())
    client = ops.create_client(sa, mock.MagicMock())
    assert client is not None
    assert isinstance(client, azure.storage.blob.AppendBlobService)
    assert isinstance(
        client.authentication,
        azure.storage.common._auth._StorageSharedKeyAuthentication)
    assert client._USER_AGENT_STRING.startswith('blobxfer/{}'.format(
        blobxfer.version.__version__))

    sa = azops.StorageAccount('name', '?key&sig=key', 'endpoint', 10,
                              mock.MagicMock())
    client = ops.create_client(sa, mock.MagicMock())
    assert client is not None
    assert isinstance(client, azure.storage.blob.AppendBlobService)
    assert isinstance(client.authentication,
                      azure.storage.common._auth._StorageSASAuthentication)
    assert client._USER_AGENT_STRING.startswith('blobxfer/{}'.format(
        blobxfer.version.__version__))
Пример #8
0
def test_key_is_sas():
    to = mock.MagicMock()
    to.max_retries = None

    a = azops.StorageAccount(
        'name', 'AAAAAA==', 'core.windows.net', 10, to, mock.MagicMock())
    assert not a.is_sas

    with pytest.raises(ValueError):
        a = azops.StorageAccount(
            'name', 'abcdef&blah', 'core.windows.net', 10, to, None)

    a = azops.StorageAccount(
        'name', '?abcdef', 'core.windows.net', 10, to, None)
    assert a.is_sas

    a = azops.StorageAccount(
        'name', '?sv=0&sr=1&sig=2', 'core.windows.net', 10, to, None)
    assert a.is_sas

    a = azops.StorageAccount(
        'name', 'sv=0&sr=1&sig=2', 'core.windows.net', 10, to, None)
    assert a.is_sas

    a = azops.StorageAccount(
        'name', 'sig=0&sv=0&sr=1&se=2', 'core.windows.net', 10, to, None)
    assert a.is_sas
def test_key_is_sas():
    a = azops.StorageAccount('name', 'abcdef', 'endpoint', 10,
                             mock.MagicMock())
    assert not a.is_sas

    a = azops.StorageAccount('name', 'abcdef&blah', 'endpoint', 10,
                             mock.MagicMock())
    assert not a.is_sas

    a = azops.StorageAccount('name', '?abcdef', 'endpoint', 10,
                             mock.MagicMock())
    assert a.is_sas

    a = azops.StorageAccount('name', '?sv=0&sr=1&sig=2', 'endpoint', 10,
                             mock.MagicMock())
    assert a.is_sas

    a = azops.StorageAccount('name', 'sv=0&sr=1&sig=2', 'endpoint', 10,
                             mock.MagicMock())
    assert a.is_sas

    a = azops.StorageAccount('name', 'sig=0&sv=0&sr=1&se=2', 'endpoint', 10,
                             mock.MagicMock())
    assert a.is_sas