예제 #1
0
def test_authorize_guest1(session):
    ''' authorize_guest with invalid parameters '''
    site1        = Wifisite.query.filter_by(unifi_id='site1').first() 
    site1.auth_method = AUTH_TYPE_SOCIAL + AUTH_TYPE_SMS + AUTH_TYPE_EMAIL +AUTH_TYPE_VOUCHER       
    mac = randomMAC()
    ap_mac1 = randomMAC()
    url1 = get_guest_url(site1,mac,ap_mac1,1)  

    #invalid guestrack id
    check_404(url_for('guest.authorize_guest',track_id=str(uuid.uuid4())))

    #test valid trackid but no device
    track_id = str(uuid.uuid4())
    guest_track = Guesttrack(ap_mac=ap_mac1,device_mac=mac,site=site1,state=GUESTRACK_INIT,orig_url='',track_id=track_id)
    db.session.add(guest_track)
    db.session.commit()
    check_404(url_for('guest.authorize_guest',track_id=track_id))


    #Create device but not authorized 
    guest_device = Device(mac=mac,site=site1,state=DEVICE_INIT)
    site1.devices.append(guest_device)
    db.session.add(guest_device)
    guest_track.state   = GUESTRACK_NO_AUTH
    guest_device.state  = DEVICE_AUTH   
    db.session.commit()    
    check_404(url_for('guest.authorize_guest',track_id=track_id))

    #ensure that no sessions are created
    assert 0 == Guestsession.query.count(),"Guestsessions are created even though authorize_guest is not called properly"
def test_email_login1(session):
    '''Email login with invalid parameters and authorized device
    
    '''
    device_mac      = '00:de:ad:be:ef:da'
    ap_mac          = '00:22:00:00:00:01'
    site            = Wifisite.query.filter_by(unifi_id='site3').first() 
   
    #invalid track ID
    assert '404 NOT FOUND' == current_app.test_client().get('/guest/email/guest/67yte7ey51wy167w2816i2351835').status

    #test valid trackid but no session
    track_id = str(uuid.uuid4())
    guest_track = Guesttrack(ap_mac=ap_mac,device_mac=device_mac,site=site,state=GUESTRACK_INIT,orig_url='',track_id=track_id)
    session.add(guest_track)
    session.commit()
    assert '404 NOT FOUND' == current_app.test_client().get('/guest/email/check/%s'%track_id).status
    #create session but no device
    guest_session = Guestsession(mac=device_mac,state=SESSION_INIT,site=site)
    session.add(guest_session)
    site.sessions.append(guest_session)
    guest_track.session = guest_session
    guest_session.guesttracks.append(guest_track)
    guest_track.state = GUESTRACK_SESSION    
    session.commit()
    assert '404 NOT FOUND' == current_app.test_client().get('/guest/email/guest/%s'%track_id).status
    #with session and authorized device
    guest_device = Device(mac=device_mac,site=site,state=DEVICE_AUTH)
    site.devices.append(guest_device)
    session.add(guest_device)
    guest_device.sessions.append(guest_session) 
    session.commit()
    assert '/guest/auth/guest/%s'%track_id in current_app.test_client().get('/guest/email/guest/%s'%track_id).data
    assert guest_session.state == SESSION_AUTHORIZED
    assert   guest_track.state   == GUESTRACK_SOCIAL_PREAUTH
def test_social_login2(session):
    '''Social login with unauthorized device
    
    '''
    device_mac      = '00:de:ad:be:ef:ca'
    ap_mac          = '00:22:00:00:00:01'
    site            = Wifisite.query.filter_by(unifi_id='site1').first() 
   
    #test valid trackid but no session
    track_id = str(uuid.uuid4())
    guest_track = Guesttrack(ap_mac=ap_mac,device_mac=device_mac,site=site,state=GUESTRACK_INIT,orig_url='',track_id=track_id)
    db.session.add(guest_track)
    db.session.commit()
    #create session 
    guest_session = Guestsession(mac=device_mac,state=SESSION_INIT,site=site)
    db.session.add(guest_session)
    site.sessions.append(guest_session)
    guest_track.session = guest_session
    guest_session.guesttracks.append(guest_track)
    guest_track.state = GUESTRACK_SESSION    
    db.session.commit()
    #with session and unauthorized device
    guest_device = Device(mac=device_mac,site=site,state=DEVICE_INIT)
    site.devices.append(guest_device)
    db.session.add(guest_device)
    guest_device.sessions.append(guest_session)
    db.session.commit()
    assert '200 OK' == current_app.test_client().get('/guest/social/guest/%s'%track_id).status
    assert guest_session.state == SESSION_TEMP_AUTH    
예제 #4
0
def test_social_login2(session):
    '''Social login with unauthorized device
    
    '''
    device_mac = '00:de:ad:be:ef:ca'
    ap_mac = '00:22:00:00:00:01'
    site = Wifisite.query.filter_by(unifi_id='site1').first()

    #test valid trackid but no session
    track_id = str(uuid.uuid4())
    guest_track = Guesttrack(ap_mac=ap_mac,
                             device_mac=device_mac,
                             site=site,
                             state=GUESTRACK_INIT,
                             orig_url='',
                             track_id=track_id)
    db.session.add(guest_track)
    db.session.commit()
    #create session
    guest_session = Guestsession(mac=device_mac, state=SESSION_INIT, site=site)
    db.session.add(guest_session)
    site.sessions.append(guest_session)
    guest_track.session = guest_session
    guest_session.guesttracks.append(guest_track)
    guest_track.state = GUESTRACK_SESSION
    db.session.commit()
    #with session and unauthorized device
    guest_device = Device(mac=device_mac, site=site, state=DEVICE_INIT)
    site.devices.append(guest_device)
    db.session.add(guest_device)
    guest_device.sessions.append(guest_session)
    db.session.commit()
    assert '200 OK' == current_app.test_client().get('/guest/social/guest/%s' %
                                                     track_id).status
    assert guest_session.state == SESSION_TEMP_AUTH
예제 #5
0
def test_authorize_guest1(session):
    """ authorize_guest with invalid parameters """
    site1 = Wifisite.query.filter_by(unifi_id="site1").first()
    site1.auth_method = AUTH_TYPE_SOCIAL + AUTH_TYPE_SMS + AUTH_TYPE_EMAIL + AUTH_TYPE_VOUCHER
    mac = randomMAC()
    ap_mac1 = randomMAC()
    url1 = get_guest_url(site1, mac, ap_mac1, 1)

    # invalid guestrack id
    check_404(url_for("guest.authorize_guest", track_id=str(uuid.uuid4())))

    # test valid trackid but no device
    track_id = str(uuid.uuid4())
    guest_track = Guesttrack(
        ap_mac=ap_mac1, device_mac=mac, site=site1, state=GUESTRACK_INIT, orig_url="", track_id=track_id
    )
    db.session.add(guest_track)
    db.session.commit()
    check_404(url_for("guest.authorize_guest", track_id=track_id))

    # Create device but not authorized
    guest_device = Device(mac=mac, site=site1, state=DEVICE_INIT)
    site1.devices.append(guest_device)
    db.session.add(guest_device)
    guest_track.state = GUESTRACK_NO_AUTH
    guest_device.state = DEVICE_AUTH
    db.session.commit()
    check_404(url_for("guest.authorize_guest", track_id=track_id))

    # ensure that no sessions are created
    assert (
        0 == Guestsession.query.count()
    ), "Guestsessions are created even though authorize_guest is not called properly"
def test_facebook_login1(session):
    '''Facebook login with invalid parameters and no fb cookies
    
    '''
    device_mac      = '00:de:ad:be:ef:da'
    ap_mac          = '00:22:00:00:00:01'
    site            = Wifisite.query.filter_by(unifi_id='site1').first() 
   
    #invalid track ID
    assert '404 NOT FOUND' == current_app.test_client().get('/guest/facebook/check/67yte7ey51wy167w2816i2351835').status

    #test valid trackid but no session
    track_id = str(uuid.uuid4())
    guest_track = Guesttrack(ap_mac=ap_mac,device_mac=device_mac,site=site,state=GUESTRACK_INIT,orig_url='',track_id=track_id)
    db.session.add(guest_track)
    db.session.commit()
    assert '404 NOT FOUND' == current_app.test_client().get('/guest/facebook/check/%s'%track_id).status
    #create session but no device
    guest_session = Guestsession(mac=device_mac,state=SESSION_INIT,site=site)
    db.session.add(guest_session)
    site.sessions.append(guest_session)
    guest_track.session = guest_session
    guest_session.guesttracks.append(guest_track)
    guest_track.state = GUESTRACK_SESSION    
    db.session.commit()
    assert '404 NOT FOUND' == current_app.test_client().get('/guest/facebook/check/%s'%track_id).status
    #with session and authorized device
    guest_device = Device(mac=device_mac,site=site,state=DEVICE_INIT)
    site.devices.append(guest_device)
    db.session.add(guest_device)
    guest_device.sessions.append(guest_session) 
    db.session.commit()
def test_email_login2(session):
    '''Email login with invalid parameters and non  authorized device
    
    '''
    device_mac      = '00:de:ad:be:ef:df'
    ap_mac          = '00:22:00:00:00:01'
    site            = Wifisite.query.filter_by(unifi_id='site3').first() 
   
    #invalid track ID
    assert '404 NOT FOUND' == current_app.test_client().get('/guest/email/guest/67yte7ey51wy167w2816i2351835').status

    #test valid trackid but no session
    track_id = str(uuid.uuid4())
    guest_track = Guesttrack(ap_mac=ap_mac,device_mac=device_mac,site=site,state=GUESTRACK_INIT,orig_url='',track_id=track_id)
    session.add(guest_track)
    session.commit()
    assert '404 NOT FOUND' == current_app.test_client().get('/guest/email/check/%s'%track_id).status
    #create session but no device
    guest_session = Guestsession(mac=device_mac,state=SESSION_INIT,site=site)
    session.add(guest_session)
    site.sessions.append(guest_session)
    guest_track.session = guest_session
    guest_session.guesttracks.append(guest_track)
    guest_track.state = GUESTRACK_SESSION    
    session.commit()
    assert '404 NOT FOUND' == current_app.test_client().get('/guest/email/guest/%s'%track_id).status
    #with session and authorized device
    guest_device = Device(mac=device_mac,site=site,state=DEVICE_INIT)
    site.devices.append(guest_device)
    session.add(guest_device)
    guest_device.sessions.append(guest_session) 
    session.commit()
    assert '200 OK' == current_app.test_client().get('/guest/email/guest/%s'%track_id).status
    #post data
    form_data = {'firstname':'First Name','email':"*****@*****.**",'lastname':'Last Name'}
    #incomplete data
    assert '302 FOUND' == current_app.test_client().post('/guest/email/guest/%s'%track_id,data=form_data).status    
    #invalid
    form_data['phonenumber'] ='+1234567890'
    form_data['email'] ='not email'
    assert '302 FOUND' == current_app.test_client().post('/guest/email/guest/%s'%track_id,data=form_data).status    
    #valid data
    form_data['email'] ='*****@*****.**'
    assert '/guest/auth/guest/%s'%track_id in current_app.test_client().post('/guest/email/guest/%s'%track_id,data=form_data).data
    assert   guest_session.state == SESSION_AUTHORIZED
    assert   guest_track.state   == GUESTRACK_NEW_AUTH
    assert   guest_device.state  == DEVICE_AUTH
    guest_entry = Guest.query.filter_by().first()
    assert guest_entry.firstname == 'First Name'
    assert guest_entry.lastname == 'Last Name'
    assert guest_entry.email == '*****@*****.**'
    assert guest_entry.phonenumber == '+1234567890'
예제 #8
0
def test_social_login1(session):
    '''Social login test with valid invalid values of guest_track and guest session and authorized device
    
    '''
    device_mac = '00:de:ad:be:ef:da'
    ap_mac = '00:22:00:00:00:01'
    site = Wifisite.query.filter_by(unifi_id='site1').first()

    #invalid track ID
    assert '404 NOT FOUND' == current_app.test_client().get(
        '/guest/social/guest/67yte7ey51wy167w2816i2351835').status

    #test valid trackid but no session
    track_id = str(uuid.uuid4())
    guest_track = Guesttrack(ap_mac=ap_mac,
                             device_mac=device_mac,
                             site=site,
                             state=GUESTRACK_INIT,
                             orig_url='',
                             track_id=track_id)
    db.session.add(guest_track)
    db.session.commit()
    assert '404 NOT FOUND' == current_app.test_client().get(
        '/guest/social/guest/%s' % track_id).status
    #create session but no device
    guest_session = Guestsession(mac=device_mac, state=SESSION_INIT, site=site)
    db.session.add(guest_session)
    site.sessions.append(guest_session)
    guest_track.session = guest_session
    guest_session.guesttracks.append(guest_track)
    guest_track.state = GUESTRACK_SESSION
    db.session.commit()
    assert '404 NOT FOUND' == current_app.test_client().get(
        '/guest/social/guest/%s' % track_id).status
    #with session and authorized device
    guest_device = Device(mac=device_mac, site=site, state=DEVICE_INIT)
    site.devices.append(guest_device)
    db.session.add(guest_device)
    guest_device.sessions.append(guest_session)
    guest_device.state = DEVICE_AUTH
    db.session.commit()
    assert '302 FOUND' == current_app.test_client().get(
        '/guest/social/guest/%s' % track_id).status
    assert guest_session.state == SESSION_AUTHORIZED
    assert guest_track.state == GUESTRACK_SOCIAL_PREAUTH
예제 #9
0
def test_temp_authorize_guest1(session):
    """ authorize_guest with invalid parameters """
    site1 = Wifisite.query.filter_by(unifi_id="site1").first()
    site1.auth_method = AUTH_TYPE_SOCIAL + AUTH_TYPE_SMS + AUTH_TYPE_EMAIL + AUTH_TYPE_VOUCHER
    mac = randomMAC()
    ap_mac1 = randomMAC()
    url1 = get_guest_url(site1, mac, ap_mac1, 1)

    auth_pass_status = {"status": 1, "msg": "DEBUG enabled"}
    auth_fail_status = {"status": 0, "msg": "Error"}
    auth_fail_status1 = {"status": 0, "msg": "You have already used up temporary logins for today"}

    # invalid guestrack id
    check_json_response(url_for("guest.temp_authorize_guest", track_id=str(uuid.uuid4())), auth_fail_status)

    # test valid trackid but not pre_auth
    track_id = str(uuid.uuid4())
    guest_track = Guesttrack(
        ap_mac=ap_mac1, device_mac=mac, site=site1, state=GUESTRACK_INIT, orig_url="", track_id=track_id
    )
    db.session.add(guest_track)
    db.session.commit()
    check_json_response(url_for("guest.temp_authorize_guest", track_id=track_id), auth_fail_status)

    # Create device and authorize session
    guest_device = Device(mac=mac, site=site1, state=DEVICE_INIT)
    site1.devices.append(guest_device)
    db.session.add(guest_device)
    guest_track.state = GUESTRACK_SOCIAL_PREAUTH
    db.session.commit()
    check_json_response(url_for("guest.temp_authorize_guest", track_id=track_id), auth_pass_status)

    # check if guest_session is created
    guest_session = Guestsession.query.first()
    assert isinstance(guest_session, Guestsession), "Guestsession is not created when calling authorize_guest"
    assert guest_session.state == GUESTRACK_SOCIAL_PREAUTH, " guest_session state is not GUESTRACK_SOCIAL_PREAUTH"

    # make max number of tries
    check_json_response(url_for("guest.temp_authorize_guest", track_id=track_id), auth_pass_status)
    check_json_response(url_for("guest.temp_authorize_guest", track_id=track_id), auth_pass_status)
    check_json_response(url_for("guest.temp_authorize_guest", track_id=track_id), auth_pass_status)
    check_json_response(url_for("guest.temp_authorize_guest", track_id=track_id), auth_pass_status)
    check_json_response(url_for("guest.temp_authorize_guest", track_id=track_id), auth_fail_status1)
예제 #10
0
def test_temp_authorize_guest1(session):
    ''' authorize_guest with invalid parameters '''
    site1        = Wifisite.query.filter_by(unifi_id='site1').first() 
    site1.auth_method = AUTH_TYPE_SOCIAL + AUTH_TYPE_SMS + AUTH_TYPE_EMAIL +AUTH_TYPE_VOUCHER       
    mac = randomMAC()
    ap_mac1 = randomMAC()
    url1 = get_guest_url(site1,mac,ap_mac1,1)  

    auth_pass_status = {'status':1,'msg': "DEBUG enabled"}
    auth_fail_status = {'status':0,'msg': "Error"}
    auth_fail_status1 = {'status':0,'msg': "You have already used up temporary logins for today"}

    #invalid guestrack id
    check_json_response(url_for('guest.temp_authorize_guest',track_id=str(uuid.uuid4())),auth_fail_status)

    #test valid trackid but not pre_auth
    track_id = str(uuid.uuid4())
    guest_track = Guesttrack(ap_mac=ap_mac1,device_mac=mac,site=site1,state=GUESTRACK_INIT,orig_url='',track_id=track_id)
    db.session.add(guest_track)
    db.session.commit()
    check_json_response(url_for('guest.temp_authorize_guest',track_id=track_id),auth_fail_status)

    #Create device and authorize session
    guest_device = Device(mac=mac,site=site1,state=DEVICE_INIT)
    site1.devices.append(guest_device)
    db.session.add(guest_device)
    guest_track.state = GUESTRACK_SOCIAL_PREAUTH
    db.session.commit() 
    check_json_response(url_for('guest.temp_authorize_guest',track_id=track_id),auth_pass_status)

    #check if guest_session is created
    guest_session = Guestsession.query.first()
    assert isinstance(guest_session,Guestsession) ,'Guestsession is not created when calling authorize_guest'
    assert guest_session.state == GUESTRACK_SOCIAL_PREAUTH, " guest_session state is not GUESTRACK_SOCIAL_PREAUTH"

    #make max number of tries   
    check_json_response(url_for('guest.temp_authorize_guest',track_id=track_id),auth_pass_status)
    check_json_response(url_for('guest.temp_authorize_guest',track_id=track_id),auth_pass_status)
    check_json_response(url_for('guest.temp_authorize_guest',track_id=track_id),auth_pass_status)
    check_json_response(url_for('guest.temp_authorize_guest',track_id=track_id),auth_pass_status)
    check_json_response(url_for('guest.temp_authorize_guest',track_id=track_id),auth_fail_status1)
예제 #11
0
def test_facebook_login1(session):
    '''Facebook login with invalid parameters and no fb cookies
    
    '''
    device_mac = '00:de:ad:be:ef:da'
    ap_mac = '00:22:00:00:00:01'
    site = Wifisite.query.filter_by(unifi_id='site1').first()

    #invalid track ID
    assert '404 NOT FOUND' == current_app.test_client().get(
        '/guest/facebook/check/67yte7ey51wy167w2816i2351835').status

    #test valid trackid but no session
    track_id = str(uuid.uuid4())
    guest_track = Guesttrack(ap_mac=ap_mac,
                             device_mac=device_mac,
                             site=site,
                             state=GUESTRACK_INIT,
                             orig_url='',
                             track_id=track_id)
    db.session.add(guest_track)
    db.session.commit()
    assert '404 NOT FOUND' == current_app.test_client().get(
        '/guest/facebook/check/%s' % track_id).status
    #create session but no device
    guest_session = Guestsession(mac=device_mac, state=SESSION_INIT, site=site)
    db.session.add(guest_session)
    site.sessions.append(guest_session)
    guest_track.session = guest_session
    guest_session.guesttracks.append(guest_track)
    guest_track.state = GUESTRACK_SESSION
    db.session.commit()
    assert '404 NOT FOUND' == current_app.test_client().get(
        '/guest/facebook/check/%s' % track_id).status
    #with session and authorized device
    guest_device = Device(mac=device_mac, site=site, state=DEVICE_INIT)
    site.devices.append(guest_device)
    db.session.add(guest_device)
    guest_device.sessions.append(guest_session)
    db.session.commit()
예제 #12
0
def test_update_daily_stat4(session, populate_analytics):
    '''Check if update_daily_stat is able to gather correct analytics when tracks different types of tracks are present'''
    site1 = Wifisite.query.filter_by(id=1).first()

    tzinfo = tz.gettz(site1.timezone)
    daydate = arrow.now(tzinfo)
    starttime = daydate.floor('day').to('UTC')
    track1 = Guesttrack.query.first()

    #create 5 SMS tracks with unique MACs
    for i in range(5):
        timestamp = starttime.replace(hours=+5, minutes=+5 * i)
        track = Guesttrack(ap_mac=track1.ap_mac,
                           device_mac=randomMAC(),
                           site=site1,
                           state=GUESTRACK_INIT,
                           orig_url='',
                           track_id=str(uuid.uuid4()))
        db.session.add(track)
        track.timestamp = timestamp.naive
        track.state = GUESTRACK_SMS_AUTH
        db.session.commit()

    #create 8 Email tracks with unique MACs
    for i in range(8):
        timestamp = starttime.replace(hours=+5, minutes=+5 * i)
        track = Guesttrack(ap_mac=track1.ap_mac,
                           device_mac=randomMAC(),
                           site=site1,
                           state=GUESTRACK_INIT,
                           orig_url='',
                           track_id=str(uuid.uuid4()))
        db.session.add(track)
        track.timestamp = timestamp.naive
        track.state = GUESTRACK_EMAIL_AUTH
        db.session.commit()

    #create 4 Voucher tracks with unique MACs
    for i in range(4):
        timestamp = starttime.replace(hours=+5, minutes=+5 * i)
        track = Guesttrack(ap_mac=track1.ap_mac,
                           device_mac=randomMAC(),
                           site=site1,
                           state=GUESTRACK_INIT,
                           orig_url='',
                           track_id=str(uuid.uuid4()))
        db.session.add(track)
        track.timestamp = timestamp.naive
        track.state = GUESTRACK_VOUCHER_AUTH
        db.session.commit()

    #create 11 returning tracks with unique MACs
    for i in range(11):
        timestamp = starttime.replace(hours=+5, minutes=+5 * i)
        track = Guesttrack(ap_mac=track1.ap_mac,
                           device_mac=randomMAC(),
                           site=site1,
                           state=GUESTRACK_INIT,
                           orig_url='',
                           track_id=str(uuid.uuid4()))
        db.session.add(track)
        track.timestamp = timestamp.naive
        track.state = GUESTRACK_PREAUTH
        db.session.commit()

    #create 20 FB tracks with unique MACs
    for i in range(20):
        timestamp = starttime.replace(hours=+5, minutes=+5 * i)
        track = Guesttrack(ap_mac=track1.ap_mac,
                           device_mac=randomMAC(),
                           site=site1,
                           state=GUESTRACK_INIT,
                           orig_url='',
                           track_id=str(uuid.uuid4()))
        db.session.add(track)
        track.timestamp = timestamp.naive
        track.state = GUESTRACK_SOCIAL_AUTH
        db.session.commit()

    update_daily_stat(site1.id, daydate)
    sitestat = Sitestat.query.first()

    assert 48 == sitestat.get_total_logins(
    ), 'Num Logins is :%s instead of expected :%s' % (
        sitestat.get_total_logins(), 48)
    assert 68 == sitestat.num_visits, 'Num visits is :%s instead of expected :%s' % (
        sitestat.num_visits, 68)
    assert 11 == sitestat.num_repeats, 'num_repeats is :%s instead of expected :%s' % (
        sitestat.num_repeats, 11)
    assert 8 == sitestat.num_emails, 'num_emails is :%s instead of expected :%s' % (
        sitestat.num_emails, 8)
    assert 20 == sitestat.num_fb, 'num_fb is :%s instead of expected :%s' % (
        sitestat.num_fb, 20)
    assert 4 == sitestat.num_vouchers, 'num_vouchers is :%s instead of expected :%s' % (
        sitestat.num_vouchers, 20)
    assert 5 == sitestat.num_phones, 'num_phones is :%s instead of expected :%s' % (
        sitestat.num_phones, 5)
예제 #13
0
def test_update_daily_stat4(session, populate_analytics):
    """Check if update_daily_stat is able to gather correct analytics when tracks different types of tracks are present"""
    site1 = Wifisite.query.filter_by(id=1).first()

    tzinfo = tz.gettz(site1.timezone)
    daydate = arrow.now(tzinfo)
    starttime = daydate.floor("day").to("UTC")
    track1 = Guesttrack.query.first()

    # create 5 SMS tracks with unique MACs
    for i in range(5):
        timestamp = starttime.replace(hours=+5, minutes=+5 * i)
        track = Guesttrack(
            ap_mac=track1.ap_mac,
            device_mac=randomMAC(),
            site=site1,
            state=GUESTRACK_INIT,
            orig_url="",
            track_id=str(uuid.uuid4()),
        )
        db.session.add(track)
        track.timestamp = timestamp.naive
        track.state = GUESTRACK_SMS_AUTH
        db.session.commit()

    # create 8 Email tracks with unique MACs
    for i in range(8):
        timestamp = starttime.replace(hours=+5, minutes=+5 * i)
        track = Guesttrack(
            ap_mac=track1.ap_mac,
            device_mac=randomMAC(),
            site=site1,
            state=GUESTRACK_INIT,
            orig_url="",
            track_id=str(uuid.uuid4()),
        )
        db.session.add(track)
        track.timestamp = timestamp.naive
        track.state = GUESTRACK_EMAIL_AUTH
        db.session.commit()

    # create 4 Voucher tracks with unique MACs
    for i in range(4):
        timestamp = starttime.replace(hours=+5, minutes=+5 * i)
        track = Guesttrack(
            ap_mac=track1.ap_mac,
            device_mac=randomMAC(),
            site=site1,
            state=GUESTRACK_INIT,
            orig_url="",
            track_id=str(uuid.uuid4()),
        )
        db.session.add(track)
        track.timestamp = timestamp.naive
        track.state = GUESTRACK_VOUCHER_AUTH
        db.session.commit()

    # create 11 returning tracks with unique MACs
    for i in range(11):
        timestamp = starttime.replace(hours=+5, minutes=+5 * i)
        track = Guesttrack(
            ap_mac=track1.ap_mac,
            device_mac=randomMAC(),
            site=site1,
            state=GUESTRACK_INIT,
            orig_url="",
            track_id=str(uuid.uuid4()),
        )
        db.session.add(track)
        track.timestamp = timestamp.naive
        track.state = GUESTRACK_PREAUTH
        db.session.commit()

    # create 20 FB tracks with unique MACs
    for i in range(20):
        timestamp = starttime.replace(hours=+5, minutes=+5 * i)
        track = Guesttrack(
            ap_mac=track1.ap_mac,
            device_mac=randomMAC(),
            site=site1,
            state=GUESTRACK_INIT,
            orig_url="",
            track_id=str(uuid.uuid4()),
        )
        db.session.add(track)
        track.timestamp = timestamp.naive
        track.state = GUESTRACK_SOCIAL_AUTH
        db.session.commit()

    update_daily_stat(site1.id, daydate)
    sitestat = Sitestat.query.first()

    assert 48 == sitestat.get_total_logins(), "Num Logins is :%s instead of expected :%s" % (
        sitestat.get_total_logins(),
        48,
    )
    assert 68 == sitestat.num_visits, "Num visits is :%s instead of expected :%s" % (sitestat.num_visits, 68)
    assert 11 == sitestat.num_repeats, "num_repeats is :%s instead of expected :%s" % (sitestat.num_repeats, 11)
    assert 8 == sitestat.num_emails, "num_emails is :%s instead of expected :%s" % (sitestat.num_emails, 8)
    assert 20 == sitestat.num_fb, "num_fb is :%s instead of expected :%s" % (sitestat.num_fb, 20)
    assert 4 == sitestat.num_vouchers, "num_vouchers is :%s instead of expected :%s" % (sitestat.num_vouchers, 20)
    assert 5 == sitestat.num_phones, "num_phones is :%s instead of expected :%s" % (sitestat.num_phones, 5)
예제 #14
0
def test_email_login2(session):
    '''Email login with invalid parameters and non  authorized device
    
    '''
    device_mac = '00:de:ad:be:ef:df'
    ap_mac = '00:22:00:00:00:01'
    site = Wifisite.query.filter_by(unifi_id='site3').first()

    #invalid track ID
    assert '404 NOT FOUND' == current_app.test_client().get(
        '/guest/email/guest/67yte7ey51wy167w2816i2351835').status

    #test valid trackid but no session
    track_id = str(uuid.uuid4())
    guest_track = Guesttrack(ap_mac=ap_mac,
                             device_mac=device_mac,
                             site=site,
                             state=GUESTRACK_INIT,
                             orig_url='',
                             track_id=track_id)
    session.add(guest_track)
    session.commit()
    assert '404 NOT FOUND' == current_app.test_client().get(
        '/guest/email/check/%s' % track_id).status
    #create session but no device
    guest_session = Guestsession(mac=device_mac, state=SESSION_INIT, site=site)
    session.add(guest_session)
    site.sessions.append(guest_session)
    guest_track.session = guest_session
    guest_session.guesttracks.append(guest_track)
    guest_track.state = GUESTRACK_SESSION
    session.commit()
    assert '404 NOT FOUND' == current_app.test_client().get(
        '/guest/email/guest/%s' % track_id).status
    #with session and authorized device
    guest_device = Device(mac=device_mac, site=site, state=DEVICE_INIT)
    site.devices.append(guest_device)
    session.add(guest_device)
    guest_device.sessions.append(guest_session)
    session.commit()
    assert '200 OK' == current_app.test_client().get('/guest/email/guest/%s' %
                                                     track_id).status
    #post data
    form_data = {
        'firstname': 'First Name',
        'email': "*****@*****.**",
        'lastname': 'Last Name'
    }
    #incomplete data
    assert '302 FOUND' == current_app.test_client().post(
        '/guest/email/guest/%s' % track_id, data=form_data).status
    #invalid
    form_data['phonenumber'] = '+1234567890'
    form_data['email'] = 'not email'
    assert '302 FOUND' == current_app.test_client().post(
        '/guest/email/guest/%s' % track_id, data=form_data).status
    #valid data
    form_data['email'] = '*****@*****.**'
    assert '/guest/auth/guest/%s' % track_id in current_app.test_client().post(
        '/guest/email/guest/%s' % track_id, data=form_data).data
    assert guest_session.state == SESSION_AUTHORIZED
    assert guest_track.state == GUESTRACK_NEW_AUTH
    assert guest_device.state == DEVICE_AUTH
    guest_entry = Guest.query.filter_by().first()
    assert guest_entry.firstname == 'First Name'
    assert guest_entry.lastname == 'Last Name'
    assert guest_entry.email == '*****@*****.**'
    assert guest_entry.phonenumber == '+1234567890'