Ejemplo n.º 1
0
def test_directory_selinux_context():
    selinux_context = "system_u:object_r:unlabeled_t:s0"
    p = os.path.join("/tmp/", random_str())
    with Directory(p, selinux_context=selinux_context):
        output = subprocess.check_output(["ls", "-Z", "-1", "-d", p])
        assert selinux_context in output.decode("utf-8")
    assert not os.path.isdir(p)
Ejemplo n.º 2
0
def test_webserver():
    # let's setup the directory to serve first
    temp_dir_name = "shiny-%s" % random_str()
    temp_dir_path = os.path.join("/tmp", temp_dir_name)
    # helper class to create and inittialize the dir -- will be removed once we
    # leave the context manager
    with Directory(temp_dir_path, mode=0o0700):
        # let's put some file in it
        with open(os.path.join(temp_dir_path, "candle"), "w") as fd:
            fd.write("You no take candle!")
        container = run_container(temp_dir_path)
        try:
            # we need to wait for the webserver to start serving
            container.wait_for_port(port)
            # GET on /
            http_response = container.http_request(path="/", port=port)
            assert http_response.ok
            assert '<a href="candle">candle</a>' in http_response.content.decode(
                "utf-8")
            # now GETting the file
            assert 'You no take candle!' in container.http_request(
                path="/candle", port=port).content.decode("utf-8")
        finally:
            container.kill()
            container.delete()
Ejemplo n.º 3
0
def test_directory_basic():
    with Directory(os.path.join("/tmp/", random_str())) as d:
        with open(os.path.join(str(d), "file"), "w") as fd:
            fd.write("hi!")
        with open(os.path.join(str(d), "file")) as fd:
            assert fd.read() == "hi!"
    assert not os.path.isdir(str(d))
Ejemplo n.º 4
0
def test_directory_selinux_type():
    selinux_type = "container_file_t"
    p = os.path.join("/tmp/", random_str())
    with Directory(p, selinux_type=selinux_type):
        output = subprocess.check_output(["ls", "-Z", "-1", "-d", p])
        assert selinux_type in output.decode("utf-8")
    assert not os.path.isdir(p)
Ejemplo n.º 5
0
def test_directory_selinux_bad():
    selinux_type = "voodoo_file_t"
    selinux_context = "janko_u:beer_r:spilled_all_over_the_table_t:s0"
    p = os.path.join("/tmp/", random_str())
    with pytest.raises(ConuException):
        Directory(p,
                  selinux_type=selinux_type,
                  selinux_context=selinux_context)
    assert not os.path.isdir(p)
Ejemplo n.º 6
0
def test_directory_mode():
    p = os.path.join("/tmp/", random_str())
    d = Directory(p, mode=0o0700)
    try:
        d.initialize()
        m = os.stat(p).st_mode
        print(m)
        assert oct(m)[-4:] == "0700"
    finally:
        d.clean()
    assert not os.path.isdir(p)
Ejemplo n.º 7
0
def test_list_containers(buildah_backend):
    image = buildah_backend.ImageClass(
        FEDORA_MINIMAL_REPOSITORY,
        tag=FEDORA_MINIMAL_REPOSITORY_TAG,
        pull_policy=BuildahImagePullPolicy.NEVER)
    container_name = random_str()
    c = image.run_via_binary(
        BuildahRunBuilder(additional_opts=['--name', container_name]))
    try:
        container_list = buildah_backend.list_containers()
        l = len(container_list)
        assert l >= 1
        cont_under_test = [
            x for x in container_list if x.metadata.name == container_name
        ][0]
        assert cont_under_test.metadata.image
        assert cont_under_test.metadata.image.get_full_name(
        ) == FEDORA_MINIMAL_REPOSITORY_DIGEST
        assert cont_under_test.metadata.command
    finally:
        c.delete(force=True)
Ejemplo n.º 8
0
def test_user_ownership_int():
    p = os.path.join("/tmp/", random_str())
    with Directory(p, user_owner=99) as d:
        s = os.stat(d.path)
        assert s.st_uid == 99
Ejemplo n.º 9
0
def test_directory_acl():
    p = os.path.join("/tmp/", random_str())
    with Directory(p, facl_rules=["u:26:rwx"]) as d:
        x = subprocess.check_output(["getfacl", str(d)]).decode("utf-8")
        assert "user:26:rwx" in x.split("\n")
    assert not os.path.isdir(str(d))
Ejemplo n.º 10
0
def test_random_str():
    assert random_str()
    assert random_str() != random_str()
    assert len(random_str(size=42)) == 42
    assert len(random_str(2)) == 2
Ejemplo n.º 11
0
def test_ownership():
    p = os.path.join("/tmp/", random_str())
    with Directory(p, user_owner="nobody", group_owner="nobody") as d:
        s = os.stat(d.path)
        assert s.st_gid == 99
        assert s.st_uid == 99
Ejemplo n.º 12
0
def test_group_ownership_404():
    p = os.path.join("/tmp/", random_str())
    with pytest.raises(ConuException):
        Directory(p, group_owner="illuminati")
Ejemplo n.º 13
0
def test_group_ownership():
    p = os.path.join("/tmp/", random_str())
    with Directory(p, group_owner=99) as d:
        s = os.stat(d.path)
        assert s.st_gid == 99
Ejemplo n.º 14
0
def test_user_ownership_404():
    p = os.path.join("/tmp/", random_str())
    with pytest.raises(ConuException):
        Directory(p, user_owner="waldo")
     "options": [
         "-e", "POSTGRESQL_USER=0invalid", "-e",
         "POSTGRESQL_PASSWORD=pass", "-e", "POSTGRESQL_DATABASE=db",
         "-e", "POSTGRESQL_ADMIN_PASSWORD=admin_pass"
     ]
 },
 {
     "description":
     "database name too long",
     "options": [
         "-e",
         "POSTGRESQL_USER=user",
         "-e",
         "POSTGRESQL_PASSWORD=pass",
         "-e",
         "POSTGRESQL_DATABASE=" + random_str(size=64),
         # "-e", "POSTGRESQL_DATABASE=db",
         "-e",
         "POSTGRESQL_ADMIN_PASSWORD=admin_pass"
     ]
 },
 {
     "description":
     "backslash in admin password",
     "options": [
         "-e", "POSTGRESQL_USER=user", "-e", "POSTGRESQL_PASSWORD=pass",
         "-e", "POSTGRESQL_DATABASE=db", "-e",
         "POSTGRESQL_ADMIN_PASSWORD=\""
     ]
 },
 {