def test_teams_join_when_already_on_team():
    """Test that a user cannot join another team"""
    app = create_ctfd(user_mode="teams")
    with app.app_context():
        gen_user(app.db, name="user")
        gen_team(app.db, email="team1@examplectf.com", name="team1")
        gen_team(app.db, email="team2@examplectf.com", name="team2")
        with login_as_user(app) as client:
            r = client.get("/teams/join")
            assert r.status_code == 200
            with client.session_transaction() as sess:
                data = {
                    "name": "team1",
                    "password": "password",
                    "nonce": sess.get("nonce"),
                }
            r = client.post("/teams/join", data=data)
            assert r.status_code == 302

            # Try to join another team while on a team
            r = client.get("/teams/join")
            assert r.status_code == 200
            with client.session_transaction() as sess:
                data = {
                    "name": "team2",
                    "password": "password",
                    "nonce": sess.get("nonce"),
                }
            r = client.post("/teams/join", data=data)
            assert r.status_code == 403
            user = Users.query.filter_by(name="user").first()
            assert user.team.name == "team1"
    destroy_ctfd(app)
Test that a user cannot join another team
tests/teams/test_auth.py