示例#1
0
    def setup_method(self, method):
        db.drop_all()
        db.create_all()

        # Create admin user for tests.
        admin = Users(id = "adminuser")
        admin.first_name = "Admin"
        admin.last_name = "User"
        admin.email = "*****@*****.**"
        admin.is_admin = True
        db.session.add(admin)
        db.session.commit()
        self.admin_token = admin.generate_auth()
        self.admin_token = self.admin_token.decode('ascii')

        # Create normal user for tests.
        user = Users(id = "testuser")
        user.first_name = "Test1"
        user.last_name = "User"
        user.email = "*****@*****.**"
        user.is_admin = False
        db.session.add(user)
        db.session.commit()
        self.test_user = user
        self.user_token = user.generate_auth()
        self.user_token = self.user_token.decode('ascii')

        # Create normal user for tests.
        user2 = Users(id = "testuser2")
        user2.first_name = "Test"
        user2.last_name = "User"
        user2.email = "*****@*****.**"
        user2.is_admin = False
        db.session.add(user2)
        db.session.commit()
        self.test_user2 = user2
        self.user_token2 = user2.generate_auth()
        self.user_token2 = self.user_token2.decode('ascii')

        # Create a test committee.
        committee = Committees(id = "testcommittee")
        committee.title = "Test Committee"
        committee.description = "Test Description"
        committee.location = "Test Location"
        committee.meeting_time = "1300"
        committee.meeting_day =  2
        committee.head = "testuser"
        self.committee = committee
        db.session.add(committee)
        db.session.commit()

        committee_note = CommitteeNotes(id = 10)
        committee_note.author = "testuser"
        committee_note.description = "Test Note"
        committee_note.committee = "testcommittee"
        committee_note.hidden = False
        self.committee_note = committee_note
        db.session.add(self.committee_note)
        db.session.commit()
    def setup_method(self, method):
        db.drop_all()
        db.create_all()
        self.user_data = {
            "user_id": "testuser",
            "committee_id": "testcommittee"
        }

        # Create admin user for tests.
        admin = Users(id="adminuser")
        admin.first_name = "Admin"
        admin.last_name = "User"
        admin.email = "*****@*****.**"
        admin.is_admin = True
        db.session.add(admin)
        db.session.commit()
        self.admin_token = admin.generate_auth()
        self.admin_token = self.admin_token.decode('ascii')

        # Create normal user for tests.
        user = Users(id="testuser")
        user.first_name = "Test1"
        user.last_name = "User"
        user.email = "*****@*****.**"
        user.is_admin = False
        db.session.add(user)
        db.session.commit()
        self.user_token = user.generate_auth()
        self.user_token = self.user_token.decode('ascii')
        self.user = user

        # Create second normal user for tests.
        user2 = Users(id="testuser2")
        user2.first_name = "Test2"
        user2.last_name = "User2"
        db.session.add(user2)
        db.session.commit()

        self.user_token2 = user2.generate_auth()
        self.user_token2 = self.user_token2.decode('ascii')
        self.user2 = user2

        # Create a test committee.
        self.committee = Committees(id="testcommittee")
        self.committee.title = "Test Committee"
        self.committee.description = "Test Description"
        self.committee.location = "Test Location"
        self.committee.meeting_time = "1300"
        self.committee.meeting_day = 2
        self.committee.head = "adminuser"
        db.session.add(self.committee)
        db.session.commit()

        self.invite = Invitations(id=5)
        self.invite.user_name = "newuser1"
        self.invite.committee = self.committee
        self.invite.committee_id = "testcommittee"
        self.invite.isInvite = False
示例#3
0
    def setup_method(self, method):
        db.drop_all()
        db.create_all()

        self.test_committee_dict = {
            "id": "testcommittee",
            "title": "testcommittee",
            "description": "Test Description",
            "location": "Test Location",
            "meeting_time": "1300",
            "meeting_day": 2,
            "head": "testuser",
            "committee_img":
            "R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw=="
        }
        self.test_committee = Committees(id="testcommittee")
        self.test_committee.title = self.test_committee_dict["title"]
        self.test_committee.location = self.test_committee_dict["location"]
        self.test_committee.description = self.test_committee_dict[
            "description"]
        self.test_committee.meeting_time = self.test_committee_dict[
            "meeting_time"]
        self.test_committee.meeting_day = self.test_committee_dict[
            "meeting_day"]
        self.test_committee.head = self.test_committee_dict["head"]
        com_img = base64.b64decode(self.test_committee_dict["committee_img"])
        self.test_committee.com_image = com_img

        # Create admin user for tests.
        admin = Users(id="adminuser")
        admin.first_name = "Admin"
        admin.last_name = "User"
        admin.email = "*****@*****.**"
        admin.is_admin = True
        db.session.add(admin)
        db.session.commit()
        self.admin_token = admin.generate_auth()
        self.admin_token = self.admin_token.decode('ascii')

        # Create normal user for tests.
        user = Users(id="testuser")
        user.first_name = "Test1"
        user.last_name = "User"
        user.email = "*****@*****.**"
        user.is_admin = False
        db.session.add(user)
        db.session.commit()
        self.test_user = user
        self.user_token = user.generate_auth()
        self.user_token = self.user_token.decode('ascii')
def login_from_acs(acs):
    
    if acs.get('errors'):
        return jsonify({'errors': acs.get('errors')})
    elif not acs.get('logged_in'):
        return jsonify({"error": "login failed"})
    else:
        attributes = list(acs.get("attributes"))
        username = attributes[0][1][0]
        firstname = attributes[1][1][0]
        lastname = attributes[2][1][0]
        email = attributes[3][1][0]

        user = Users.query.filter_by(id = username).first()

        if user is None:
            user = Users(id = username)
            user.first_name = firstname
            user.last_name = lastname
            user.email = email

            db.session.add(user)
            db.session.commit()
        
        login_user(user)
        return redirect('/')
示例#5
0
def login_ldap(credentials):

    ldap_server = "ldaps://ldap.rit.edu"

    if credentials.get("username", "") == "" or credentials.get(
            "password", "") == "":

        emit('auth', {'error': "Authentication error."})
        return

    user_dn = "uid=" + credentials.get("username",
                                       "") + ",ou=People,dc=rit,dc=edu"
    search_filter = "uid=" + credentials.get("username", "")
    connect = ldap.initialize(ldap_server)

    try:

        connect.bind_s(user_dn, credentials.get("password", ""))
        result = connect.search_s(user_dn, ldap.SCOPE_SUBTREE, search_filter)
        connect.unbind_s()

        values = result[0][1]
        username = values["uid"][0].decode('utf-8')
        firstname = values["givenName"][0].decode('utf-8')
        lastname = values["sn"][0].decode('utf-8')
        email = values["mail"][0].decode('utf-8')

        # Check if a user exists.
        if Users.query.filter_by(id=username).first() is not None:

            user = Users.query.filter_by(id=username).first()
            token = user.generate_auth()
            admin = user.is_admin
            emit(
                'auth', {
                    'token': token.decode('ascii'),
                    'admin': admin,
                    'super': user.is_super,
                    'username': username
                })

        else:

            user = Users(id=username)
            user.first_name = firstname
            user.last_name = lastname
            user.email = email

            db.session.add(user)
            db.session.commit()
            token = user.generate_auth()
            emit('auth', {'token': token.decode('ascii')})

    except ldap.LDAPError:
        connect.unbind_s()
        emit('auth', Response.AuthError)
        return
示例#6
0
    def setup_method(self, method):
        db.drop_all()
        db.create_all()

        # Create admin user for tests.
        admin = Users(id="adminuser")
        admin.first_name = "Admin"
        admin.last_name = "User"
        admin.email = "*****@*****.**"
        admin.is_admin = True
        db.session.add(admin)
        db.session.commit()
        self.admin_token = admin.generate_auth()
        self.admin_token = self.admin_token.decode('ascii')

        # Create normal user for tests.
        user = Users(id="testuser")
        user.first_name = "Test1"
        user.last_name = "User"
        user.email = "*****@*****.**"
        user.is_admin = False
        db.session.add(user)
        db.session.commit()
        self.test_user = user
        self.user_token = user.generate_auth()
        self.user_token = self.user_token.decode('ascii')

        # Create normal user for tests.
        user2 = Users(id="testuser2")
        user2.first_name = "Test"
        user2.last_name = "User"
        user2.email = "*****@*****.**"
        user2.is_admin = False
        db.session.add(user2)
        db.session.commit()
        self.test_user2 = user2
        self.user_token2 = user2.generate_auth()
        self.user_token2 = self.user_token2.decode('ascii')

        # Create normal user for tests.
        user3 = Users(id="activemember")
        user3.first_name = "Active"
        user3.last_name = "Member"
        user3.email = "*****@*****.**"
        user3.is_admin = False
        db.session.add(user2)
        db.session.commit()
        self.test_user3 = user3
        self.user_token3 = user3.generate_auth()
        self.user_token3 = self.user_token3.decode('ascii')

        # Create a test committee.
        committee = Committees(id="testcommittee")
        committee.title = "Test Committee"
        committee.description = "Test Description"
        committee.location = "Test Location"
        committee.meeting_time = "1300"
        committee.meeting_day = 2
        committee.head = "testuser"
        self.committee = committee

        # Create a test committee.
        committee2 = Committees(id="testcommittee2")
        committee2.title = "Test Committee2"
        committee2.description = "Test Description"
        committee2.location = "Test Location"
        committee2.meeting_time = "1300"
        committee2.meeting_day = 2
        committee2.head = "testuser"
        self.committee2 = committee2

        # Add user3 to committee.
        role = Members(role=Roles.ActiveMember)
        role.member = self.test_user3
        self.committee.members.append(role)
        db.session.add(self.committee)
        db.session.add(self.committee2)
        db.session.commit()

        self.charge_dict = {
            'id': 10,
            'title': 'Test Charge',
            'description': 'Test Description',
            'committee': 'testcommittee',
            'status': 0,
            'priority': 0,
            'private': True,
            'paw_links': "https://testlink.com"
        }

        # Create a test charge.
        charge = Charges(id=10)
        charge.author = "testuser"
        charge.title = "Test Charge"
        charge.description = "Test Description"
        charge.committee = "testcommittee"
        charge.paw_links = "https://testlink.com"
        charge.priority = 0
        charge.status = 0
        charge.private = True
        self.charge = charge

        db.session.add(charge)
        db.session.commit()
        self.charge_dict["created_at"] = self.charge.created_at.isoformat()
示例#7
0
    def setup_method(self, method):
        db.drop_all()
        db.create_all()
        self.socketio = socketio.test_client(app)
        self.socketio.connect()

        db.event.remove(Committees, "after_insert", new_committee)
        db.event.remove(Actions, "after_insert", new_action)

        # Create admin user for tests.
        admin = Users(id="adminuser")
        admin.first_name = "Admin"
        admin.last_name = "User"
        admin.email = "*****@*****.**"
        admin.is_admin = True
        db.session.add(admin)
        db.session.commit()
        self.admin_token = admin.generate_auth()
        self.admin_token = self.admin_token.decode('ascii')

        # Create normal user for tests.
        user = Users(id="testuser")
        user.first_name = "Test1"
        user.last_name = "User"
        user.email = "*****@*****.**"
        user.is_admin = False
        db.session.add(user)
        db.session.commit()
        self.test_user = user
        self.user_token = user.generate_auth()
        self.user_token = self.user_token.decode('ascii')

        # Create normal user for tests.
        user_two = Users(id="testuser2")
        user_two.first_name = "Test2"
        user_two.last_name = "User"
        user_two.email = "*****@*****.**"
        user_two.is_admin = False
        db.session.add(user_two)
        db.session.commit()
        self.test_user_two = user_two
        self.user_token_two = user_two.generate_auth()
        self.user_token_two = self.user_token_two.decode('ascii')

        # Create a test committee.
        committee = Committees(id="testcommittee")
        committee.title = "Test Committee"
        committee.description = "Test Description"
        committee.location = "Test Location"
        committee.meeting_time = "1300"
        committee.meeting_day = 2
        committee.head = "testuser"
        self.committee = committee
        db.session.add(committee)
        db.session.commit()

        # Create a test charge.
        charge = Charges(id=10)
        charge.author = "testuser"
        charge.title = "Test Charge"
        charge.description = "Test Description"
        charge.committee = "testcommittee"
        charge.paw_links = "https://testlink.com"
        charge.priority = 0
        charge.status = 0
        self.charge = charge
        db.session.add(charge)
        db.session.commit()

        # Create a test action.
        action = Actions(id=10)
        action.author = admin.id
        action.title = "Test Action"
        action.description = "Test Description"
        action.charge = 10
        action.status = 0
        self.test_action = action
        db.session.add(self.test_action)
        db.session.commit()

        db.event.listen(Committees, "after_insert", new_committee)
        db.event.listen(Actions, "after_insert", new_action)

        # Test committee dictionary
        self.test_committee_dict = {
            "id": "testcommittee1",
            "title": "testcommittee1",
            "description": "Test Description",
            "location": "Test Location",
            "meeting_time": "1300",
            "meeting_day": 2,
            "head": "testuser",
            "committee_img":
            "R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw=="
        }

        # Test action dict
        self.test_action_dict = {
            "token": self.user_token,
            "charge": 10,
            "assigned_to": "testuser",
            "title": "test title",
            "description": "test description"
        }
示例#8
0
    def setup_method(self, method):
        db.drop_all()
        db.create_all()

        # Create admin user for tests.
        admin = Users(id="adminuser")
        admin.first_name = "Admin"
        admin.last_name = "User"
        admin.email = "*****@*****.**"
        admin.is_admin = True
        db.session.add(admin)
        db.session.commit()
        self.admin_token = admin.generate_auth()
        self.admin_token = self.admin_token.decode('ascii')

        # Create normal member for tests.
        self.normal_member = Users(id="testuser")
        self.normal_member.first_name = "Test1"
        self.normal_member.last_name = "User"
        self.normal_member.email = "*****@*****.**"
        self.normal_member.is_admin = False
        db.session.add(self.normal_member)
        db.session.commit()
        self.normal_member_token = self.normal_member.generate_auth()
        self.normal_member_token = self.normal_member_token.decode('ascii')

        # Create normal minute taker for tests.
        self.minute_taker = Users(id="test2user")
        self.minute_taker.first_name = "Test2"
        self.minute_taker.last_name = "User"
        self.minute_taker.email = "*****@*****.**"
        self.minute_taker.is_admin = False
        db.session.add(self.minute_taker)
        db.session.commit()
        self.minute_taker_token = self.minute_taker.generate_auth()
        self.minute_taker_token = self.minute_taker_token.decode('ascii')

        # Create normal minute taker for tests.
        self.not_member = Users(id="test3user")
        self.not_member.first_name = "Test3"
        self.not_member.last_name = "User"
        self.not_member.email = "*****@*****.**"
        self.not_member.is_admin = False
        db.session.add(self.not_member)
        db.session.commit()
        self.not_member_token = self.not_member.generate_auth()
        self.not_member_token = self.not_member_token.decode('ascii')

        # Create a test committee.
        self.committee = Committees(id="testcommittee")
        self.committee.title = "Test Committee"
        self.committee.description = "Test Description"
        self.committee.location = "Test Location"
        self.committee.meeting_time = "1200"
        self.committee.meeting_day = 2
        self.committee.head = "adminuser"

        # Add user to committee as normal member.
        normal_role = Members(role=Roles.NormalMember)
        normal_role.member = self.normal_member
        self.committee.members.append(normal_role)

        minute_taker_role = Members(role=Roles.MinuteTaker)
        minute_taker_role.member = self.minute_taker
        self.committee.members.append(minute_taker_role)

        db.session.add(self.committee)

        self.user_data = {
            "token": self.admin_token,
            "committee_id": self.committee.id,
            "title": "New Minute",
            "body": "This is a test body.",
            "date": 565745465,
            "private": False
        }

        # Create a test charge.
        charge = Charges(id=10)
        charge.author = "testuser"
        charge.title = "Test Charge"
        charge.description = "Test Description"
        charge.committee = "testcommittee"
        charge.paw_links = "https://testlink.com"
        charge.priority = 0
        charge.status = 0
        self.charge = charge
        db.session.add(charge)

        # Create a new test charge.
        new_charge = Charges(id=11)
        new_charge.author = "testuser"
        new_charge.title = "Test Charge"
        new_charge.description = "Test Description"
        new_charge.committee = "testcommittee"
        new_charge.paw_links = "https://testlink.com"
        new_charge.priority = 0
        new_charge.status = 0
        self.new_charge = new_charge
        db.session.add(new_charge)

        self.minute = Minutes(title="Test Minute",
                              body="TestBody",
                              date=282827,
                              private=True)
        self.minute.charges.append(self.charge)
        self.committee.minutes.append(self.minute)

        self.public_minute = Minutes(title="Public Test Minute",
                                     body="PublicTestBody",
                                     date=282827,
                                     private=False)
        self.public_minute.charges.append(self.charge)
        self.committee.minutes.append(self.public_minute)

        db.session.commit()
示例#9
0
    def setup_method(self, method):
        db.drop_all()
        db.create_all()

        # Create admin user for tests.
        admin = Users(id = "adminuser")
        admin.first_name = "Admin"
        admin.last_name = "User"
        admin.email = "*****@*****.**"
        admin.is_admin = True
        db.session.add(admin)
        db.session.commit()
        self.test_admin = admin
        self.admin_token = admin.generate_auth()
        self.admin_token = self.admin_token.decode('ascii')

        # Create normal user for tests.
        user = Users(id = "testuser")
        user.first_name = "Test1"
        user.last_name = "User"
        user.email = "*****@*****.**"
        user.is_admin = False
        db.session.add(user)
        db.session.commit()
        self.test_user = user
        self.user_token = user.generate_auth()
        self.user_token = self.user_token.decode('ascii')


        # Create normal user for tests.
        user2 = Users(id = "testuser2")
        user2.first_name = "Test2"
        user2.last_name = "User2"
        user2.email = "*****@*****.**"
        user2.is_admin = False
        db.session.add(user2)
        db.session.commit()
        self.test_user2 = user2
        self.user_token2 = user2.generate_auth()
        self.user_token2 = self.user_token2.decode('ascii')

        self.test_committee_dict = {
            "id" : "testcommittee",
            "title": "testcommittee",
            "description": "Test Description",
            "location": "Test Location",
            "meeting_time": "1300",
            "meeting_day": 2,
            "head": "testuser",
            "committee_img": "R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw=="
        }
        self.test_committee = Committees(id = "testcommittee")
        self.test_committee.title = self.test_committee_dict["title"]
        self.test_committee.location = self.test_committee_dict["location"]
        self.test_committee.description = self.test_committee_dict["description"]
        self.test_committee.meeting_time = self.test_committee_dict["meeting_time"]
        self.test_committee.meeting_day = self.test_committee_dict["meeting_day"]
        self.test_committee.head = self.test_committee_dict["head"]
        com_img = base64.b64decode(self.test_committee_dict["committee_img"])
        self.test_committee.com_image = com_img

        db.session.add(self.test_committee)
        db.session.commit()

        # Create a test charge.
        charge = Charges(id = 10)
        charge.author = "testuser"
        charge.title = "Test Charge"
        charge.description = "Test Description"
        charge.committee = "testcommittee"
        charge.priority = 0
        charge.status = 0
        self.test_charge = charge
        db.session.add(self.test_charge)
        db.session.commit()

        # Create a test action.
        action = Actions(id = 10)
        action.author = self.test_admin.id
        action.assigned_to = self.test_user.id
        action.title = "Test Action"
        action.description = "Test Description"
        action.charge = 10
        action.status = 0
        self.test_action = action
        db.session.add(self.test_action)
        db.session.commit()
示例#10
0
    def setup_method(self, method):
        db.drop_all()
        db.create_all()

        self.user_data = {
            "user_id": "testuser",
            "committee_id": "testcommittee",
            "role": "NormalMember"
        }

        # Create admin user for tests.
        admin = Users(id = "adminuser")
        admin.first_name = "Admin"
        admin.last_name = "User"
        admin.email = "*****@*****.**"
        admin.is_admin = True
        db.session.add(admin)
        #db.session.expunge(admin)
        db.session.commit()
        self.admin_token = admin.generate_auth()
        self.admin_token = self.admin_token.decode('ascii')

        # Create normal user for tests.
        self.user = Users(id = "testuser")
        self.user.first_name = "Test1"
        self.user.last_name = "User"
        self.user.email = "*****@*****.**"
        self.user.is_admin = False
        db.session.add(self.user)
        db.session.commit()
        self.user_token = self.user.generate_auth()
        self.user_token = self.user_token.decode('ascii')

        # Create normal user2 for tests.
        self.user2 = Users(id = "test2user")
        self.user2.first_name = "Test2"
        self.user2.last_name = "User"
        self.user2.email = "*****@*****.**"
        self.user2.is_admin = False
        db.session.add(self.user2)
        db.session.commit()
        self.user2_token = self.user2.generate_auth()
        self.user2_token = self.user2_token.decode('ascii')

        # Create a test committee.
        self.committee = Committees(id = "testcommittee")
        self.committee.title = "Test Committee"
        self.committee.description = "Test Description"
        self.committee.location = "Test Location"
        self.committee.meeting_time = "1200"
        self.committee.meeting_day = 2
        self.committee.head = "adminuser"

        # Create a seconnd test committee.
        self.committee2 = Committees(id = "testcommittee2")
        self.committee2.title = "Test Committee"
        self.committee2.description = "Test Description"
        self.committee2.location = "Test Location"
        self.committee2.meeting_time = "1200"
        self.committee2.meeting_day = 2
        self.committee2.head = "adminuser"

        # Add user2 to committee.
        role = Members(role= Roles.NormalMember)
        role.member = self.user2
        self.committee.members.append(role)
        db.session.add(self.committee)
        db.session.add(self.committee2)

        db.session.commit()