Ejemplo n.º 1
0
def test_htpasswd_save(htpasswd_file):
    credentials = htpasswd.Htpasswd(htpasswd_file).load()

    saved_file = htpasswd_file.with_suffix(".saved")
    htpasswd.Htpasswd(saved_file).save(credentials)

    assert htpasswd_file.open(encoding="utf-8").read() == saved_file.open(
        encoding="utf-8").read()
Ejemplo n.º 2
0
def fixture_test_config(tmp_path):
    file_path = tmp_path / "htpasswd"
    htpwd = htpasswd.Htpasswd(file_path)

    htpwd.save({
        "non-unicode": "non-unicode",
        u"abcä": "bbbä",
    })

    return htpwd
Ejemplo n.º 3
0
def test_user_connector_verify_password(htpasswd_file, monkeypatch):
    c = htpasswd.HtpasswdUserConnector({})
    monkeypatch.setattr(c, "_get_htpasswd", lambda: htpasswd.Htpasswd(htpasswd_file))

    assert c.check_credentials(u"cmkadmin", u"cmk") == u"cmkadmin"
    assert c.check_credentials(u"bärnd", u"cmk") == u"bärnd"
    assert c.check_credentials(u"sha256user", u"cmk") == u"sha256user"
    assert c.check_credentials(u"harry", u"cmk") == u"harry"
    assert c.check_credentials(u"dingeling", u"aaa") is None
    assert c.check_credentials(u"locked", u"locked") is False
def test_user_connector_verify_password(htpasswd_file: Path,
                                        monkeypatch: MonkeyPatch) -> None:
    c = htpasswd.HtpasswdUserConnector({})
    monkeypatch.setattr(c, "_get_htpasswd",
                        lambda: htpasswd.Htpasswd(htpasswd_file))

    assert c.check_credentials(UserId("cmkadmin"), "cmk") == "cmkadmin"
    assert c.check_credentials(UserId("bärnd"), "cmk") == "bärnd"
    assert c.check_credentials(UserId("sha256user"), "cmk") == "sha256user"
    assert c.check_credentials(UserId("harry"), "cmk") == "harry"
    assert c.check_credentials(UserId("bcrypt_user"), "cmk") == "bcrypt_user"
    assert c.check_credentials(UserId("dingeling"), "aaa") is None
    assert c.check_credentials(UserId("locked"), "locked") is False
Ejemplo n.º 5
0
def test_save(tmp_path):
    file_path = tmp_path / "htpasswd"
    htpwd = htpasswd.Htpasswd(file_path)

    htpwd.save({
        "non-unicode": "non-unicode",
        u"abcä": "bbbä",
    })

    loaded = htpwd.load()
    assert loaded == {
        u"non-unicode": u"non-unicode",
        u"abcä": u"bbbä",
    }
Ejemplo n.º 6
0
def test_save(tmp_path):
    file_path = tmp_path / "htpasswd"
    htpwd = htpasswd.Htpasswd(file_path)

    htpwd.save({
        UserId("non-unicode"): "non-unicode",
        UserId("abcä"): "bbbä",
    })

    loaded = htpwd.load()
    assert loaded == {
        UserId("non-unicode"): "non-unicode",
        UserId("abcä"): "bbbä",
    }
Ejemplo n.º 7
0
def test_check_credentials_local_user_create_htpasswd_user_ad_hoc() -> None:
    user_id = UserId("someuser")
    assert userdb.user_exists(user_id) is False
    assert userdb._user_exists_according_to_profile(user_id) is False
    assert user_id not in _load_users_uncached(lock=False)

    htpasswd.Htpasswd(Path(cmk.utils.paths.htpasswd_file)).save(
        {user_id: htpasswd.hash_password("cmk")})
    # Once a user exists in the htpasswd, the GUI treats the user as existing user and will
    # automatically initialize the missing data structures
    assert userdb.user_exists(user_id) is True
    assert userdb._user_exists_according_to_profile(user_id) is False
    assert str(user_id) in _load_users_uncached(lock=False)

    assert userdb.check_credentials(user_id, "cmk") == user_id

    # Nothing changes during regular access
    assert userdb.user_exists(user_id) is True
    assert userdb._user_exists_according_to_profile(user_id) is False
    assert str(user_id) in _load_users_uncached(lock=False)
Ejemplo n.º 8
0
def test_htpasswd_load(htpasswd_file):
    credentials = htpasswd.Htpasswd(htpasswd_file).load()
    assert credentials["cmkadmin"] == "NEr3kqi287FQc"
    assert isinstance(credentials["cmkadmin"], str)
    assert credentials["bärnd"] == "$apr1$/FU.SwEZ$Ye0XG1Huf2j7Jws7KD.h2/"
Ejemplo n.º 9
0
def test_htpasswd_exists(htpasswd_file):
    assert htpasswd.Htpasswd(htpasswd_file).exists("cmkadmin")
    assert htpasswd.Htpasswd(htpasswd_file).exists("locked")
    assert not htpasswd.Htpasswd(htpasswd_file).exists("not-existing")
    assert not htpasswd.Htpasswd(htpasswd_file).exists("")
    assert htpasswd.Htpasswd(htpasswd_file).exists("bärnd")
def test_htpasswd_load(htpasswd_file: Path) -> None:
    credentials = htpasswd.Htpasswd(htpasswd_file).load()
    assert credentials[UserId("cmkadmin")] == "NEr3kqi287FQc"
    assert isinstance(credentials[UserId("cmkadmin")], str)
    assert credentials[UserId(
        "bärnd")] == "$apr1$/FU.SwEZ$Ye0XG1Huf2j7Jws7KD.h2/"