diff options
Diffstat (limited to 'tests/sources/remote.py')
-rw-r--r-- | tests/sources/remote.py | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/tests/sources/remote.py b/tests/sources/remote.py index d3968395f..a4a9d5965 100644 --- a/tests/sources/remote.py +++ b/tests/sources/remote.py @@ -5,6 +5,7 @@ import pytest from buildstream._exceptions import ErrorDomain from buildstream import _yaml from tests.testutils import cli +from tests.testutils.file_server import create_file_server DATA_DIR = os.path.join( os.path.dirname(os.path.realpath(__file__)), @@ -22,6 +23,16 @@ def generate_project(project_dir, tmpdir): }, project_file) +def generate_project_file_server(server, project_dir): + project_file = os.path.join(project_dir, "project.conf") + _yaml.dump({ + 'name': 'foo', + 'aliases': { + 'tmpdir': server.base_url() + } + }, project_file) + + # Test that without ref, consistency is set appropriately. @pytest.mark.datafiles(os.path.join(DATA_DIR, 'no-ref')) def test_no_ref(cli, tmpdir, datafiles): @@ -164,3 +175,35 @@ def test_executable(cli, tmpdir, datafiles): assert (mode & stat.S_IEXEC) # Assert executable by anyone assert(mode & (stat.S_IEXEC | stat.S_IXGRP | stat.S_IXOTH)) + + +@pytest.mark.parametrize('server_type', ('FTP', 'HTTP')) +@pytest.mark.datafiles(os.path.join(DATA_DIR, 'single-file')) +def test_use_netrc(cli, datafiles, server_type, tmpdir): + fake_home = os.path.join(str(tmpdir), 'fake_home') + os.makedirs(fake_home, exist_ok=True) + project = str(datafiles) + checkoutdir = os.path.join(str(tmpdir), 'checkout') + + os.environ['HOME'] = fake_home + with open(os.path.join(fake_home, '.netrc'), 'wb') as f: + os.fchmod(f.fileno(), 0o700) + f.write(b'machine 127.0.0.1\n') + f.write(b'login testuser\n') + f.write(b'password 12345\n') + + with create_file_server(server_type) as server: + server.add_user('testuser', '12345', project) + generate_project_file_server(server, project) + + server.start() + + result = cli.run(project=project, args=['fetch', 'target.bst']) + result.assert_success() + result = cli.run(project=project, args=['build', 'target.bst']) + result.assert_success() + result = cli.run(project=project, args=['checkout', 'target.bst', checkoutdir]) + result.assert_success() + + checkout_file = os.path.join(checkoutdir, 'file') + assert(os.path.exists(checkout_file)) |