示例#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"
示例#2
0
def test_update_daily_stat3(session, populate_analytics):
    '''Check if update_daily_stat is able to gather correct analytics when tracks which are atleast 2hrs apart'''
    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 similar tracks as track 1 with 3hr timestamp difference
    for i in range(3):
        timestamp = starttime.replace(hours=+(3 * i + 3))
        track = Guesttrack(ap_mac=track1.ap_mac,
                           device_mac=track1.device_mac,
                           site=site1,
                           state=GUESTRACK_INIT,
                           orig_url='',
                           track_id=str(uuid.uuid4()))
        db.session.add(track)
        track.timestamp = timestamp.naive
        db.session.commit()

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

    assert 0 == sitestat.get_total_logins(
    ), 'Num Logins is :%s instead of expected :%s' % (
        sitestat.get_total_logins(), 0)
    assert 23 == sitestat.num_visits, 'Num visits is :%s instead of expected :%s' % (
        sitestat.num_visits, 20)
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()
示例#4
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"
示例#5
0
def test_update_daily_stat3(session, populate_analytics):
    """Check if update_daily_stat is able to gather correct analytics when tracks which are atleast 2hrs apart"""
    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 similar tracks as track 1 with 3hr timestamp difference
    for i in range(3):
        timestamp = starttime.replace(hours=+(3 * i + 3))
        track = Guesttrack(
            ap_mac=track1.ap_mac,
            device_mac=track1.device_mac,
            site=site1,
            state=GUESTRACK_INIT,
            orig_url="",
            track_id=str(uuid.uuid4()),
        )
        db.session.add(track)
        track.timestamp = timestamp.naive
        db.session.commit()

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

    assert 0 == sitestat.get_total_logins(), "Num Logins is :%s instead of expected :%s" % (
        sitestat.get_total_logins(),
        0,
    )
    assert 23 == sitestat.num_visits, "Num visits is :%s instead of expected :%s" % (sitestat.num_visits, 20)
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    
示例#7
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
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_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'
示例#10
0
def populate_analytics(request):
    '''fixture used to populate guest_tracks to test analytics function

        
    '''
    site1 = Wifisite.query.filter_by(unifi_id='site1').first()
    tracks = []

    tzinfo = tz.gettz(site1.timezone)
    day_start = arrow.now(tzinfo).floor('day').to('UTC')

    ap_mac = randomMAC()

    #create 20 tracks, starting from day start and spaced 1minutes apart
    for i in range(20):
        track = Guesttrack(ap_mac=ap_mac,
                           device_mac=randomMAC(),
                           site=site1,
                           state=GUESTRACK_INIT,
                           orig_url='',
                           track_id=str(uuid.uuid4()))
        db.session.add(track)
        track.timestamp = day_start.replace(minutes=+i * 1).naive
        tracks.append(track)
        #create device
    db.session.commit()

    day_start = arrow.now(tzinfo).floor('day').to('UTC').replace(days=-1)
    #create 20 tracks, starting from day start and spaced 1minutes apart on previous day
    for i in range(20):
        track = Guesttrack(ap_mac=ap_mac,
                           device_mac=randomMAC(),
                           site=site1,
                           state=GUESTRACK_INIT,
                           orig_url='',
                           track_id=str(uuid.uuid4()))
        db.session.add(track)
        track.timestamp = day_start.replace(minutes=+i * 1).naive
        tracks.append(track)
        #create device
    db.session.commit()

    day_start = arrow.now(tzinfo).floor('day').to('UTC').replace(days=+1)
    #create 20 tracks, starting from day start and spaced 1minutes apart on next day
    for i in range(20):
        track = Guesttrack(ap_mac=ap_mac,
                           device_mac=randomMAC(),
                           site=site1,
                           state=GUESTRACK_INIT,
                           orig_url='',
                           track_id=str(uuid.uuid4()))
        db.session.add(track)
        track.timestamp = day_start.replace(minutes=+i * 1).naive
        tracks.append(track)
        #create device
    db.session.commit()
示例#11
0
def test_social_login1(session):
    '''Test social_login view with in valid parameters and non authorized device

     '''

    site1        = Wifisite.query.filter_by(unifi_id='site1').first() 
    site1.auth_method = AUTH_TYPE_SOCIAL      
    mac = randomMAC()
    ap_mac1 = randomMAC()
    url1 = get_guest_url(site1,mac,ap_mac1,1)      

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

    #test valid trackid but no session
    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.social_login',track_id=track_id))    


    #Create device 
    guest_device = Device(mac=mac,site=site1,state=DEVICE_INIT)
    site1.devices.append(guest_device)
    db.session.add(guest_device)
    db.session.commit() 
    check_url_responce(url_for('guest.social_login',track_id=track_id),'Login Using Facebook')   

    #validate guesttrack
    guest_track =  Guesttrack.query.first()
    assert GUESTRACK_SOCIAL_PREAUTH == guest_track.state, "Guesttrack state is not GUESTRACK_SOCIAL_PREAUTH"
示例#12
0
def test_voucher_login1(session,create_vouchers):
    '''Test voucher_login view with in valid parameters

     '''

    site1        = Wifisite.query.filter_by(unifi_id='site1').first() 
    site1.auth_method = AUTH_TYPE_EMAIL     
    mac = randomMAC()
    ap_mac1 = randomMAC()
   

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

    #test valid trackid but no session
    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.voucher_login',track_id=track_id))    

    #Create device 
    guest_device = Device(mac=mac,site=site1,state=DEVICE_INIT)
    site1.devices.append(guest_device)
    db.session.add(guest_device)
    db.session.commit() 
    check_voucher_login_page(url_for('guest.voucher_login',track_id=track_id))   
示例#13
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
示例#14
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)
示例#15
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)
示例#16
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()
示例#17
0
def guest_logged(request):
    '''fixture used to create a logged in instance of guest. It creates guesttrack,guestsession and guestdevice

        
    '''
    site1        = Wifisite.query.filter_by(unifi_id='site1').first()  
    mac = randomMAC()
    ap_mac1 = randomMAC()
    #create a track id, sesssion and 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)
    #create device  
    guest_device = Device(mac=mac,site=site1,state=DEVICE_INIT)
    site1.devices.append(guest_device)
    db.session.add(guest_device)
    db.session.commit() 
示例#18
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)
示例#19
0
def populate_analytics(request):
    """fixture used to populate guest_tracks to test analytics function

        
    """
    site1 = Wifisite.query.filter_by(unifi_id="site1").first()
    tracks = []

    tzinfo = tz.gettz(site1.timezone)
    day_start = arrow.now(tzinfo).floor("day").to("UTC")

    ap_mac = randomMAC()

    # create 20 tracks, starting from day start and spaced 1minutes apart
    for i in range(20):
        track = Guesttrack(
            ap_mac=ap_mac,
            device_mac=randomMAC(),
            site=site1,
            state=GUESTRACK_INIT,
            orig_url="",
            track_id=str(uuid.uuid4()),
        )
        db.session.add(track)
        track.timestamp = day_start.replace(minutes=+i * 1).naive
        tracks.append(track)
        # create device
    db.session.commit()

    day_start = arrow.now(tzinfo).floor("day").to("UTC").replace(days=-1)
    # create 20 tracks, starting from day start and spaced 1minutes apart on previous day
    for i in range(20):
        track = Guesttrack(
            ap_mac=ap_mac,
            device_mac=randomMAC(),
            site=site1,
            state=GUESTRACK_INIT,
            orig_url="",
            track_id=str(uuid.uuid4()),
        )
        db.session.add(track)
        track.timestamp = day_start.replace(minutes=+i * 1).naive
        tracks.append(track)
        # create device
    db.session.commit()

    day_start = arrow.now(tzinfo).floor("day").to("UTC").replace(days=+1)
    # create 20 tracks, starting from day start and spaced 1minutes apart on next day
    for i in range(20):
        track = Guesttrack(
            ap_mac=ap_mac,
            device_mac=randomMAC(),
            site=site1,
            state=GUESTRACK_INIT,
            orig_url="",
            track_id=str(uuid.uuid4()),
        )
        db.session.add(track)
        track.timestamp = day_start.replace(minutes=+i * 1).naive
        tracks.append(track)
        # create device
    db.session.commit()
示例#20
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'
示例#21
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)