def test_put_over_missing_role(client, database, cleanup):
    new_role = create_role(*admin_role)
    database.session.add(new_role)

    new_role = create_role(*owner_role)
    database.session.add(new_role)

    new_user = create_user(*user_2)
    database.session.add(new_user)

    database.session.commit()

    token = jwt.encode({"id": 1}, app.config["SECRET_KEY"])
    headers = {
        "private_key": "3c777d6e1cece1e78aa9c26ae7fa2ecf33a6d3fb1db7c1313e7b79ef3ee884eb",
        "token": token.decode("UTF-8"),
    }
    result = client.put(
        "/roles/3",
        data=dumps(payload),
        content_type="application/json",
        headers=headers,
    )

    assert result.status_code == 404
    assert result.get_json()["error"] == "Role ID not found!"
Exemplo n.º 2
0
def test_put_role_success(client, database, cleanup):
    new_role = create_role(*admin_role)
    database.session.add(new_role)

    new_role = create_role(*owner_role)
    database.session.add(new_role)

    new_user = create_user(*user_2)
    database.session.add(new_user)

    database.session.commit()

    token = jwt.encode({"id": 1}, app.config["SECRET_KEY"])
    payload = {
        "id": 1,
        "role": role,
        "private-key":
        "3c777d6e1cece1e78aa9c26ae7fa2ecf33a6d3fb1db7c1313e7b79ef3ee884eb",
        "token": token.decode("UTF-8"),
    }
    result = put_role_socket(payload)
    result = loads(result)

    expected_role = role
    expected_role["id"] = 1

    assert result["role"] == expected_role
def test_put_role_success(client, database, cleanup):
    new_role = create_role(*admin_role)
    database.session.add(new_role)

    new_role = create_role(*owner_role)
    database.session.add(new_role)

    new_user = create_user(*user_2)
    database.session.add(new_user)

    database.session.commit()

    token = jwt.encode({"id": 1}, app.config["SECRET_KEY"])
    headers = {
        "private_key": "3c777d6e1cece1e78aa9c26ae7fa2ecf33a6d3fb1db7c1313e7b79ef3ee884eb",
        "token": token.decode("UTF-8"),
    }
    result = client.put(
        "/roles/1",
        data=dumps(payload),
        content_type="application/json",
        headers=headers,
    )

    expected_role = payload.copy()
    expected_role["id"] = 1

    assert result.status_code == 200
    assert result.get_json()["role"] == expected_role
Exemplo n.º 4
0
def test_put_role_missing_key(client, database, cleanup):
    new_user = create_user(*user_1)

    database.session.add(new_user)
    database.session.commit()

    token = jwt.encode({"id": 1}, app.config["SECRET_KEY"])
    payload = {"role": role, "id": 1, "token": token.decode("UTF-8")}
    result = put_role_socket(payload)
    result = loads(result)

    assert result["error"] == "Missing request key!"
def test_post_role_invalid_key(client, database, cleanup):
    new_user = create_user(*user_1)

    database.session.add(new_user)
    database.session.commit()

    token = jwt.encode({"id": 1}, app.config["SECRET_KEY"])
    headers = {"private-key": "IdoNotExist", "token": token.decode("UTF-8")}
    result = client.post(
        "/roles", data=dumps(payload), content_type="application/json", headers=headers
    )

    assert result.status_code == 403
    assert result.get_json()["error"] == "Invalid credentials!"
Exemplo n.º 6
0
def test_put_role_missing_token(client, database, cleanup):
    new_user = create_user(*user_1)

    database.session.add(new_user)
    database.session.commit()

    payload = {
        "private-key":
        "3c777d6e1cece1e78aa9c26ae7fa2ecf33a6d3fb1db7c1313e7b79ef3ee884eb"
    }
    result = put_role_socket(payload)
    result = loads(result)

    assert result["error"] == "Missing request key!"
def test_delete_role_missing_key(client, database, cleanup):
    new_role = create_role(*owner_role)
    database.session.add(new_role)
    new_role = create_role(*admin_role)
    database.session.add(new_role)
    new_user = create_user(*user_1)
    database.session.add(new_user)
    database.session.commit()

    token = jwt.encode({"id": 1}, app.config["SECRET_KEY"])
    headers = {"token": token.decode("UTF-8")}
    result = client.delete("/roles/2", content_type="application/json", headers=headers)

    assert result.status_code == 400
    assert result.get_json()["error"] == "Missing request key!"
Exemplo n.º 8
0
def test_get_role_invalid_key(client, database, cleanup):
    new_user = create_user(*user_1)
    database.session.add(new_user)
    database.session.commit()

    token = jwt.encode({"id": 1}, app.config["SECRET_KEY"])
    payload = {
        "id": 1,
        "private-key": "IdoNotExist",
        "token": token.decode("UTF-8")
    }
    result = get_role_socket(payload)
    result = loads(result)

    assert result["error"] == "Invalid credentials!"
def test_put_role_missing_key(client, database, cleanup):
    new_user = create_user(*user_1)

    database.session.add(new_user)
    database.session.commit()

    token = jwt.encode({"id": 1}, app.config["SECRET_KEY"])
    headers = {"token": token.decode("UTF-8")}
    result = client.put(
        "/roles/1",
        data=dumps(payload),
        headers=headers,
        content_type="application/json",
    )
    assert result.status_code == 400
    assert result.get_json()["error"] == "Missing request key!"
Exemplo n.º 10
0
def test_delete_role_missing_token(client, database, cleanup):
    new_role = create_role(*owner_role)
    database.session.add(new_role)
    new_role = create_role(*admin_role)
    database.session.add(new_role)
    new_user = create_user(*user_1)
    database.session.add(new_user)
    database.session.commit()

    headers = {
        "private_key": "3c777d6e1cece1e78aa9c26ae7fa2ecf33a6d3fb1db7c1313e7b79ef3ee884eb"
    }
    result = client.delete("/roles/2", content_type="application/json", headers=headers)

    assert result.status_code == 400
    assert result.get_json()["error"] == "Missing request key!"
Exemplo n.º 11
0
def test_get_role_missing_role(client, database, cleanup):
    new_user = create_user(*user_1)
    database.session.add(new_user)
    database.session.commit()

    token = jwt.encode({"id": 1}, app.config["SECRET_KEY"])
    payload = {
        "id": 1,
        "private-key":
        "3c777d6e1cece1e78aa9c26ae7fa2ecf33a6d3fb1db7c1313e7b79ef3ee884eb",
        "token": token.decode("UTF-8"),
    }
    result = get_role_socket(payload)
    result = loads(result)

    assert result["error"] == "Role ID not found!"
Exemplo n.º 12
0
def test_delete_role_unauthorized_user(client, database, cleanup):
    new_role = create_role(*admin_role)
    new_user = create_user(*user_1)
    database.session.add(new_role)
    database.session.add(new_user)
    database.session.commit()

    token = jwt.encode({"id": 1}, app.config["SECRET_KEY"])
    headers = {
        "private_key": "3c777d6e1cece1e78aa9c26ae7fa2ecf33a6d3fb1db7c1313e7b79ef3ee884eb",
        "token": token.decode("UTF-8"),
    }
    result = client.delete("/roles/1", headers=headers, content_type="application/json")

    assert result.status_code == 403
    assert result.get_json()["error"] == "User is not authorized for this operation!"
Exemplo n.º 13
0
def test_get_all_roles_user_with_missing_role(client, database, cleanup):

    new_user = create_user(*user_1)

    database.session.add(new_user)
    database.session.commit()

    token = jwt.encode({"id": 1}, app.config["SECRET_KEY"])
    headers = {
        "private-key": "3c777d6e1cece1e78aa9c26ae7fa2ecf33a6d3fb1db7c1313e7b79ef3ee884eb",
        "token": token.decode("UTF-8"),
    }
    result = client.get("/roles", content_type="application/json", headers=headers)

    assert result.status_code == 404
    assert result.get_json()["error"] == "Role ID not found!"
Exemplo n.º 14
0
def test_post_role_invalid_token(client, database, cleanup):
    new_user = create_user(*user_1)

    database.session.add(new_user)
    database.session.commit()

    token = jwt.encode({"asdsadad": 124356}, app.config["SECRET_KEY"])
    headers = {
        "private_key": "3c777d6e1cece1e78aa9c26ae7fa2ecf33a6d3fb1db7c1313e7b79ef3ee884eb",
        "token": token.decode("UTF-8"),
    }
    result = client.post(
        "/roles", data=dumps(payload), content_type="application/json", headers=headers
    )

    assert result.status_code == 403
    assert result.get_json()["error"] == "Invalid credentials!"
Exemplo n.º 15
0
def test_post_role_bad_data(client, database, cleanup):
    new_user = create_user(*user_1)

    database.session.add(new_user)
    database.session.commit()

    token = jwt.encode({"id": 1}, app.config["SECRET_KEY"])
    headers = {
        "private_key": "3c777d6e1cece1e78aa9c26ae7fa2ecf33a6d3fb1db7c1313e7b79ef3ee884eb",
        "token": token.decode("UTF-8"),
    }

    result = client.post(
        "/roles", data="{bad", headers=headers, content_type="application/json"
    )
    assert result.status_code == 400
    assert result.get_json()["error"] == JSON_DECODE_ERR_MSG
Exemplo n.º 16
0
def test_post_role_invalid_token(client, database, cleanup):
    new_user = create_user(*user_1)

    database.session.add(new_user)
    database.session.commit()

    token = jwt.encode({"asdsadad": 124356}, app.config["SECRET_KEY"])
    payload = {
        "role": role,
        "private-key":
        "3c777d6e1cece1e78aa9c26ae7fa2ecf33a6d3fb1db7c1313e7b79ef3ee884eb",
        "token": token.decode("UTF-8"),
    }
    result = create_role_socket(payload)
    result = loads(result)

    assert result["error"] == "Invalid credentials!"
Exemplo n.º 17
0
def test_put_role_missing_token(client, database, cleanup):
    new_user = create_user(*user_1)

    database.session.add(new_user)
    database.session.commit()

    headers = {
        "private_key": "3c777d6e1cece1e78aa9c26ae7fa2ecf33a6d3fb1db7c1313e7b79ef3ee884eb"
    }
    result = client.put(
        "/roles/1",
        data=dumps(payload),
        headers=headers,
        content_type="application/json",
    )
    assert result.status_code == 400
    assert result.get_json()["error"] == "Missing request key!"
Exemplo n.º 18
0
def test_delete_role_invalid_token(client, database, cleanup):
    new_role = create_role(*owner_role)
    database.session.add(new_role)
    new_role = create_role(*admin_role)
    database.session.add(new_role)
    new_user = create_user(*user_1)
    database.session.add(new_user)
    database.session.commit()

    token = jwt.encode({"id": 1}, "213p4u4trgsvczxnwdaere67yiukyhj")
    headers = {
        "private_key": "3c777d6e1cece1e78aa9c26ae7fa2ecf33a6d3fb1db7c1313e7b79ef3ee884eb",
        "token": token.decode("UTF-8"),
    }
    result = client.delete("/roles/2", content_type="application/json", headers=headers)

    assert result.status_code == 403
    assert result.get_json()["error"] == "Invalid credentials!"
Exemplo n.º 19
0
def test_delete_role_invalid_key(client, database, cleanup):
    new_role = create_role(*owner_role)
    database.session.add(new_role)
    new_role = create_role(*admin_role)
    database.session.add(new_role)
    new_user = create_user(*user_1)
    database.session.add(new_user)
    database.session.commit()

    token = jwt.encode({"id": 1}, app.config["SECRET_KEY"])
    headers = {
        "private_key": "1230896843rtfsvdjb123453212098792171766n",
        "token": token.decode("UTF-8"),
    }
    result = client.delete("/roles/2", content_type="application/json", headers=headers)

    assert result.status_code == 403
    assert result.get_json()["error"] == "Invalid credentials!"
Exemplo n.º 20
0
def test_delete_role_unauthorized_user(client, database, cleanup):
    new_role = create_role(*admin_role)
    new_user = create_user(*user_1)
    database.session.add(new_role)
    database.session.add(new_user)
    database.session.commit()

    token = jwt.encode({"id": 1}, app.config["SECRET_KEY"])
    payload = {
        "id": 1,
        "private-key":
        "3c777d6e1cece1e78aa9c26ae7fa2ecf33a6d3fb1db7c1313e7b79ef3ee884eb",
        "token": token.decode("UTF-8"),
    }
    result = delete_role_socket(payload)
    result = loads(result)

    assert result["error"] == "User is not authorized for this operation!"
Exemplo n.º 21
0
def test_delete_role_invalid_key(client, database, cleanup):
    new_role = create_role(*owner_role)
    database.session.add(new_role)
    new_role = create_role(*admin_role)
    database.session.add(new_role)
    new_user = create_user(*user_1)
    database.session.add(new_user)
    database.session.commit()

    token = jwt.encode({"id": 1}, app.config["SECRET_KEY"])
    payload = {
        "id": 2,
        "private-key": "1230896843rtfsvdjb123453212098792171766n",
        "token": token.decode("UTF-8"),
    }
    result = delete_role_socket(payload)
    result = loads(result)

    assert result["error"] == "Invalid credentials!"
Exemplo n.º 22
0
def test_put_role_invalid_key(client, database, cleanup):
    new_role = create_role(*owner_role)

    new_user = create_user(*user_1)

    database.session.add(new_role)
    database.session.add(new_user)
    database.session.commit()

    token = jwt.encode({"id": 1}, app.config["SECRET_KEY"])
    payload = {
        "id": 1,
        "role": role,
        "private-key": "dsapksasdp12-04290u83t5r752tyvdwhbsacnxz",
        "token": token.decode("UTF-8"),
    }
    result = put_role_socket(payload)
    result = loads(result)

    assert result["error"] == "Invalid credentials!"
Exemplo n.º 23
0
def test_delete_role_invalid_token(client, database, cleanup):
    new_role = create_role(*owner_role)
    database.session.add(new_role)
    new_role = create_role(*admin_role)
    database.session.add(new_role)
    new_user = create_user(*user_1)
    database.session.add(new_user)
    database.session.commit()

    token = jwt.encode({"id": 1}, "213p4u4trgsvczxnwdaere67yiukyhj")
    payload = {
        "id": 2,
        "private-key":
        "3c777d6e1cece1e78aa9c26ae7fa2ecf33a6d3fb1db7c1313e7b79ef3ee884eb",
        "token": token.decode("UTF-8"),
    }
    result = delete_role_socket(payload)
    result = loads(result)

    assert result["error"] == "Invalid credentials!"
Exemplo n.º 24
0
def test_get_all_roles_invalid_key(client, database, cleanup):
    new_role = create_role(*admin_role)
    database.session.add(new_role)
    new_role = create_role(*owner_role)
    database.session.add(new_role)

    new_user = create_user(*user_2)
    database.session.add(new_user)

    database.session.commit()

    token = jwt.encode({"id": 1}, app.config["SECRET_KEY"])
    payload = {
        "private-key": "siohfigdadANDVBSIAWE0WI21Y8OR1082ORHFEDNSLCSADIJOKA",
        "token": token.decode("UTF-8"),
    }
    result = get_all_roles_socket(payload)
    result = loads(result)

    assert result["error"] == "Invalid credentials!"
Exemplo n.º 25
0
def test_delete_role_success(client, database, cleanup):
    new_role = create_role(*admin_role)
    database.session.add(new_role)

    new_role = create_role(*owner_role)
    database.session.add(new_role)

    new_user = create_user(*user_2)
    database.session.add(new_user)

    database.session.commit()

    token = jwt.encode({"id": 1}, app.config["SECRET_KEY"])
    headers = {
        "private_key": "3c777d6e1cece1e78aa9c26ae7fa2ecf33a6d3fb1db7c1313e7b79ef3ee884eb",
        "token": token.decode("UTF-8"),
    }
    result = client.delete("/roles/1", headers=headers, content_type="application/json")

    assert result.status_code == 200
    assert database.session.query(Role).get(1) is None
Exemplo n.º 26
0
def test_get_all_roles_invalid_token(client, database, cleanup):
    new_role = create_role(*admin_role)
    database.session.add(new_role)
    new_role = create_role(*owner_role)
    database.session.add(new_role)

    new_user = create_user(*user_2)
    database.session.add(new_user)

    database.session.commit()

    token = jwt.encode({"id": 1}, "totally a secret, trust me")
    payload = {
        "private-key":
        "3c777d6e1cece1e78aa9c26ae7fa2ecf33a6d3fb1db7c1313e7b79ef3ee884eb",
        "token": token.decode("UTF-8"),
    }
    result = get_all_roles_socket(payload)
    result = loads(result)

    assert result["error"] == "Invalid credentials!"
Exemplo n.º 27
0
def test_put_role_invalid_token(client, database, cleanup):
    new_role = create_role(*owner_role)

    new_user = create_user(*user_1)

    database.session.add(new_role)
    database.session.add(new_user)
    database.session.commit()

    token = jwt.encode({"id": 1}, "1029382trytdfsvcbxz")
    payload = {
        "id": 1,
        "role": role,
        "private-key":
        "3c777d6e1cece1e78aa9c26ae7fa2ecf33a6d3fb1db7c1313e7b79ef3ee884eb",
        "token": token.decode("UTF-8"),
    }
    result = put_role_socket(payload)
    result = loads(result)

    assert result["error"] == "Invalid credentials!"
Exemplo n.º 28
0
def test_get_all_roles_invalid_key(client, database, cleanup):
    new_role = create_role(*admin_role)
    database.session.add(new_role)
    new_role = create_role(*owner_role)
    database.session.add(new_role)

    new_user = create_user(*user_2)
    database.session.add(new_user)

    database.session.commit()

    token = jwt.encode({"id": 1}, app.config["SECRET_KEY"])
    headers = {
        "private_key": "siohfigdadANDVBSIAWE0WI21Y8OR1082ORHFEDNSLCSADIJOKA",
        "token": token.decode("UTF-8"),
    }
    result = client.get(
        "/roles", data=dumps(payload), headers=headers, content_type="application/json"
    )

    assert result.status_code == 403
    assert result.get_json()["error"] == "Invalid credentials!"
Exemplo n.º 29
0
def test_put_role_invalid_token(client, database, cleanup):
    new_role = create_role(*owner_role)

    new_user = create_user(*user_1)

    database.session.add(new_role)
    database.session.add(new_user)
    database.session.commit()

    token = jwt.encode({"id": 1}, "1029382trytdfsvcbxz")
    headers = {
        "private_key": "3c777d6e1cece1e78aa9c26ae7fa2ecf33a6d3fb1db7c1313e7b79ef3ee884eb",
        "token": token.decode("UTF-8"),
    }
    result = client.put(
        "/roles/1",
        data=dumps(payload),
        headers=headers,
        content_type="application/json",
    )
    assert result.status_code == 403
    assert result.get_json()["error"] == "Invalid credentials!"
Exemplo n.º 30
0
def test_put_role_invalid_key(client, database, cleanup):
    new_role = create_role(*owner_role)

    new_user = create_user(*user_1)

    database.session.add(new_role)
    database.session.add(new_user)
    database.session.commit()

    token = jwt.encode({"id": 1}, app.config["SECRET_KEY"])
    headers = {
        "private_key": "dsapksasdp12-04290u83t5r752tyvdwhbsacnxz",
        "token": token.decode("UTF-8"),
    }
    result = client.put(
        "/roles/1",
        data=dumps(payload),
        headers=headers,
        content_type="application/json",
    )
    assert result.status_code == 403
    assert result.get_json()["error"] == "Invalid credentials!"