Example #1
0
def test_delete_basic_auth(session, clean_kong):
    consumer = add("consumers",
                   session,
                   username="******",
                   custom_id="1234")
    ba = consumers.add_basic_auth(session, consumer["id"], "some.username",
                                  "password")
    consumers.delete_basic_auth(session, consumer["id"], ba["id"])
    assert [] == consumers.basic_auths(session, consumer["id"])
Example #2
0
def test_add_basic_auth(session, clean_kong, kong_version):
    consumer = add("consumers",
                   session,
                   username="******",
                   custom_id="1234")
    ba = consumers.add_basic_auth(session, consumer["id"], "some.username",
                                  "password")
    assert [ba] == consumers.basic_auths(session, consumer["id"])
    if kong_version >= 0.15:
        assert ba["consumer"]["id"] == consumer["id"]
    else:
        assert ba["consumer_id"] == consumer["id"]
    assert ba["username"] == "some.username"
    assert ba["password"] != "password"  # some hash
Example #3
0
def test_update_basic_auth_password(session, clean_kong):
    consumer = add("consumers",
                   session,
                   username="******",
                   custom_id="1234")
    ba = consumers.add_basic_auth(session, consumer["id"], "some.username",
                                  "password")
    consumers.update_basic_auth(session,
                                consumer["id"],
                                ba["id"],
                                password="******")
    bas = consumers.basic_auths(session, consumer["id"])
    assert len(bas) == 1
    assert ba.pop("password") != bas[0].pop("password")
    assert ba == bas[0]
Example #4
0
def test_basic_auth_update(invoke, sample, session, username, passwd):
    service, route, consumer = sample
    ba = consumers.add_basic_auth(session, consumer["id"], "user", "passwd")
    result = invoke([
        "--font",
        "cyberlarge",
        "--tablefmt",
        "psql",
        "consumers",
        "basic-auth",
        "update",
        consumer["id"],
        ba["id"],
        "--username",
        username,
        "--password",
        passwd,
    ])

    assert result.exit_code == 0
    lines = result.output.split("\n")
    assert len(lines) == 6
    assert [v.strip() for v in lines[1].split("|")] == [
        "",
        "consumer.id",
        "created_at",
        "id",
        "password",
        "tags",
        "username",
        "",
    ]
    values = [v.strip() for v in lines[3].split("|")][1:-1]
    assert values[0] == consumer["id"]
    assert datetime.strptime(
        values[1],
        "%Y-%m-%dT%H:%M:%S+00:00") <= datetime.now() + timedelta(seconds=1)
    id_ = values[2]
    bas = consumers.basic_auths(session, consumer["id"])
    ba = next(k for k in bas if k["id"] == id_)
    assert ba["password"] == values[3]
    assert ba["password"] == passwd or "passwd"
    assert ba["username"] == values[5]
    assert ba["username"] == username or "user"
Example #5
0
def test_update_basic_auth_username(session, clean_kong, kong_version):
    consumer = add("consumers",
                   session,
                   username="******",
                   custom_id="1234")
    ba = consumers.add_basic_auth(session, consumer["id"], "some.username",
                                  "password")
    consumers.update_basic_auth(session,
                                consumer["id"],
                                ba["id"],
                                username="******")
    bas = consumers.basic_auths(session, consumer["id"])
    assert len(bas) == 1
    assert "username.some" == bas[0].pop("username")
    ba.pop("username")
    if kong_version >= 0.15:
        # apparently, if no password field is given in 1.0, the empty password is set
        ba.pop("password")
        bas[0].pop("password")
    assert ba == bas[0]
Example #6
0
def test_basic_auth_delete(invoke, sample, session):
    service, route, consumer = sample
    ba = consumers.add_basic_auth(session, consumer["id"], "user", "passwd")
    result = invoke([
        "--font",
        "cyberlarge",
        "--tablefmt",
        "psql",
        "consumers",
        "basic-auth",
        "delete",
        consumer["id"],
        ba["id"],
    ])

    assert result.exit_code == 0
    assert (
        result.output ==
        f"Deleted credentials `{ba['id']}` of consumer `{consumer['id']}`!\n")
    bas = consumers.basic_auths(session, consumer["id"])
    assert bas == []
Example #7
0
def test_no_basic_auths(session, clean_kong):
    consumer = add("consumers",
                   session,
                   username="******",
                   custom_id="1234")
    assert [] == consumers.basic_auths(session, consumer["id"])