示例#1
0
def test_user_using_one_invalid_attached_providers(invalid_authentication_data,
                                                    user_configuration_with_providers):
    """Ensure that a storage provider with invalid authentication data is not added."""

    # Add a storage provider with invalid authentication data.
    user_configuration_with_providers['csps'].append({
        'csp_id': 'invalid.1234',
        'display_name': 'Invalid Storage',
        'authentication_data': invalid_authentication_data,
        'type': 'invalid'
    })
    # The user configuration should now have both a valid and an invalid storage
    # configuration.
    assert len(user_configuration_with_providers.get('csps', [])) == 2

    # The User object be created with all relevant information.
    user = User.using(user_configuration_with_providers)
    assert user.id == '11-22-33'
    assert user.email == '*****@*****.**'
    assert user.is_enabled
    assert 'user' in user.roles
    assert 'administrator' in user.roles
    assert user.organization.display_name == "crosscloud"

    # However the list of configured/available storages should not contain the
    # invalid storage account.
    assert len(user.configured_storage_providers) == 1
    assert 'invalid.1234' not in user.configured_storage_providers
示例#2
0
def test_user_using_empty_providers(user_configuration_empty_providers):
    """Ensure that an empty 'csps' list still creates a valid 'User' object."""
    user = User.using(user_configuration_empty_providers)
    assert user.id == '11-22-33'
    assert user.email == '*****@*****.**'
    assert user.is_enabled
    assert 'user' in user.roles
    assert 'administrator' in user.roles
    assert user.organization.display_name == "crosscloud"
    assert len(user.configured_storage_providers) == 0
示例#3
0
def test_get_storage(configuration, expected_storage_value, user_configuration_empty_providers, test_application):

    # Prepare empty user
    current_user = User.using(user_configuration_empty_providers)
    assert len(current_user.configured_storage_providers) == 0
    current_user.configured_storage_providers[configuration.storage_id] = configuration
    assert len(current_user.configured_storage_providers) == 1

    with test_application.app_context():
        storage = current_user.get_storage(configuration.storage_id)
        assert storage is None
示例#4
0
def test_user_using(user_configuration_with_providers):

    user = User.using(user_configuration_with_providers)
    assert user.id == '11-22-33'
    assert user.email == '*****@*****.**'
    assert user.is_enabled
    assert 'user' in user.roles
    assert 'administrator' in user.roles
    assert user.organization.display_name == "crosscloud"

    assert len(user.configured_storage_providers) == 1
    assert 'dropbox.1234' in user.configured_storage_providers

    storage = user.configured_storage_providers['dropbox.1234']
    assert storage.storage_id == 'dropbox.1234'
    assert storage.display_name == "Dropbox 1"
    assert storage.type == 'dropbox'
    assert storage.authentication_data is not None
    assert isinstance(json.loads(storage.authentication_data), dict)
示例#5
0
def test_user_using_with_invalid_attached_providers(invalid_authentication_data,
                                                    user_configuration_with_providers):
    """Ensure that a storage provider with invalid authentication data is not added."""

    # Set the test providers authentication data to an invalid value.
    config = user_configuration_with_providers['csps'][0]
    config['authentication_data'] = invalid_authentication_data

    # The User object should still be created with all relevant information.
    user = User.using(user_configuration_with_providers)
    assert user.id == '11-22-33'
    assert user.email == '*****@*****.**'
    assert user.is_enabled
    assert 'user' in user.roles
    assert 'administrator' in user.roles
    assert user.organization.display_name == "crosscloud"

    # However the list of configured/available storages should be empty.
    assert len(user.configured_storage_providers) == 0
示例#6
0
def test_token_writer_sends_token_to_backend(test_application, user_configuration_with_providers, mocker):
    """Ensure that the updated tokens are sent to the backend."""

    my_user = User.using(user_configuration_with_providers)
    # This currently needs to be done manually as it is not part of the "using" (yet).
    my_user.authentication_token = "valid_auth_token"

    # FIXME: Remove this when update_storage becomes obsolete!
    mocker.patch("webdav.utils.update_storage", new=mock.Mock())

    with user_set(test_application, my_user):
        with test_application.test_request_context():
            storage = utils.prepare_storage_provider(
                StorageConfiguration(
                  storage_id="gdrive_1499686470.097055",
                  authentication_data="\"old_authentication_data\"",
                  display_name="Google Drive 1",
                  type="gdrive")
            )
            assert storage.storage_display_name == 'Google Drive 1'

            # Mock the call to the backend.
            with requests_mock.Mocker() as rmock:
                rmock.register_uri('POST', 'http://api:3030/graphql', json={})
                assert storage.oauth_session.token_updater("test") == json.dumps('test')

                # Ensure the mock was called and the last request is also present.
                assert rmock.called
                assert rmock.last_request

                # Extract the mutation variables from the last request to the rmock.
                request_variables = json.loads(rmock.last_request._request.body.decode('utf-8')).get("variables")
                assert request_variables is not None

                # Ensure the variables passed to the mutation are correct.
                assert request_variables.get('csp_id', storage.storage_id)
                assert request_variables.get('old', storage.oauth_session.token)
                assert request_variables.get('new', "test")
示例#7
0
def test_get_supported_storage(configuration, cls_name,
                               user_configuration_empty_providers, test_application,
                               mocker):

    # this patch can be removed once ~jars#15 has been resolved.
    mocker.patch('webdav.utils.update_storage')


    # Prepare empty user
    current_user = User.using(user_configuration_empty_providers)
    current_user.authentication_token = 'test'

    assert len(current_user.configured_storage_providers) == 0
    current_user.configured_storage_providers[configuration.storage_id] = configuration
    assert len(current_user.configured_storage_providers) == 1

    with user_set(test_application, current_user):
        with test_application.app_context():
            storage = current_user.get_storage(configuration.storage_id)
            assert isinstance(storage, jars.BasicStorage)
            assert storage.__class__.__name__ == cls_name
            assert storage.storage_id == configuration.storage_id
            assert storage.storage_display_name == configuration.display_name
            assert storage.storage_name == configuration.type
示例#8
0
def example_user(user_configuration_with_providers):
    user = User.using(user_configuration_with_providers)
    assert len(user.configured_storage_providers) > 0
    return user
示例#9
0
def user_with_storage(user_configuration_with_providers):
    user = User.using(user_configuration_with_providers)
    return user