Exemple #1
0
def test_delete_session(new_session):
    """
    Given a session,
    when the session_dao.delete_session method is called,
    check the session was removed from the database correctly.
    """
    try:
        session_dao.delete_session(new_session.uid)
    except Exception as e:
        pytest.fail("session_dao.delete_session returned an exception: " + str(e))
    assert session_dao.get_session(new_session.uid) is None
Exemple #2
0
def session_remove():
    """End an active session."""
    session_uid = request.form.get('session_uid')

    if not session_uid:
        flash('Invalid session UID', 'danger')
        return redirect(url_for('sessions'))

    # kill connection to C2
    owner_sessions = c2.sessions.get(current_user.username, {})

    if session_uid and session_uid in owner_sessions:
        session_thread = owner_sessions[session_uid]
        try:
            session_thread.kill()
        except Exception as e:
            return "Error ending session - please try again."

    # remove session from database
    s = session_dao.delete_session(session_uid)
    return "Session {} removed.".format(session_uid)