def test_key_auth_add(invoke, sample, session): service, route, consumer = sample result = invoke([ "--font", "cyberlarge", "--tablefmt", "psql", "consumers", "key-auth", "add", consumer["id"], ]) 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", "key", "tags", "ttl", "", ] 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] keys = consumers.key_auths(session, consumer["id"]) key = next(k for k in keys if k["id"] == id_) assert values[3] == key["key"]
def test_delete_key_auth(session, clean_kong): consumer = add("consumers", session, username="******", custom_id="1234") ba = consumers.add_key_auth(session, consumer["id"]) consumers.delete_key_auth(session, consumer["id"], ba["id"]) assert [] == consumers.key_auths(session, consumer["id"])
def test_lots_of_key_auths(session, clean_kong): consumer = add("consumers", session, username="******", custom_id="1234") for _i in range(1000): consumers.add_key_auth(session, consumer["id"]) assert 1000 == len(consumers.key_auths(session, consumer["id"]))
def test_update_key_auth(session, clean_kong): consumer = add("consumers", session, username="******", custom_id="1234") ka = consumers.add_key_auth(session, consumer["id"]) consumers.update_key_auth(session, consumer["id"], ka["id"], key="4321") kas = consumers.key_auths(session, consumer["id"]) assert len(kas) == 1 assert "4321" == kas[0].pop("key") ka.pop("key") assert ka == kas[0]
def test_add_key_auth_with_key(session, clean_kong, kong_version): consumer = add("consumers", session, username="******", custom_id="1234") ka = consumers.add_key_auth(session, consumer["id"], key="1234567890") assert [ka] == consumers.key_auths(session, consumer["id"]) if kong_version >= 0.15: assert ka["consumer"]["id"] == consumer["id"] else: assert ka["consumer_id"] == consumer["id"] assert "1234567890" == ka["key"]
def test_key_auth_delete(invoke, sample, session): service, route, consumer = sample key = consumers.add_key_auth(session, consumer["id"]) result = invoke([ "--font", "cyberlarge", "--tablefmt", "psql", "consumers", "key-auth", "delete", consumer["id"], key["id"], ]) assert result.exit_code == 0 assert (result.output == f"Deleted key `{key['id']}` of consumer `{consumer['id']}`!\n") keys = consumers.key_auths(session, consumer["id"]) assert keys == []
def test_no_key_auths(session, clean_kong): consumer = add("consumers", session, username="******", custom_id="1234") assert [] == consumers.key_auths(session, consumer["id"])