コード例 #1
0
ファイル: test_guest_views.py プロジェクト: vinchu/poppet
def test_guest_portal1(session):
    """Check if configuring different auth_methods gives out proper landing pages"""
    site1 = Wifisite.query.filter_by(id=1).first()
    mac = randomMAC()
    ap_mac = randomMAC()
    site1.auth_method = AUTH_TYPE_SOCIAL + AUTH_TYPE_SMS + AUTH_TYPE_EMAIL + AUTH_TYPE_VOUCHER
    db.session.commit()
    url = get_guest_url(site1, mac, ap_mac, demo=0)
    check_multi_login_page(url)

    site1.auth_method = AUTH_TYPE_SOCIAL
    db.session.commit()
    url = get_guest_url(site1, mac, ap_mac, demo=0)
    check_facebook_login_page(url)

    site1.auth_method = AUTH_TYPE_SMS
    db.session.commit()
    url = get_guest_url(site1, mac, ap_mac, demo=0)
    check_phone_login_page(url)

    site1.auth_method = AUTH_TYPE_EMAIL
    db.session.commit()
    url = get_guest_url(site1, mac, ap_mac, demo=0)
    check_email_login_page(url)

    site1.auth_method = AUTH_TYPE_VOUCHER
    db.session.commit()
    url = get_guest_url(site1, mac, ap_mac, demo=0)
    check_voucher_login_page(url)
コード例 #2
0
ファイル: test_guest_views.py プロジェクト: pedritss/poppet
def test_guest_portal1(session):
    '''Check if configuring different auth_methods gives out proper landing pages'''
    site1 = Wifisite.query.filter_by(id=1).first()
    mac = randomMAC()
    ap_mac = randomMAC()    
    site1.auth_method = AUTH_TYPE_SOCIAL + AUTH_TYPE_SMS + AUTH_TYPE_EMAIL +AUTH_TYPE_VOUCHER
    db.session.commit()
    url = get_guest_url(site1,mac,ap_mac,demo=0)
    check_multi_login_page(url)

    site1.auth_method = AUTH_TYPE_SOCIAL 
    db.session.commit()
    url = get_guest_url(site1,mac,ap_mac,demo=0)
    check_facebook_login_page(url)

    site1.auth_method = AUTH_TYPE_SMS 
    db.session.commit()
    url = get_guest_url(site1,mac,ap_mac,demo=0)
    check_phone_login_page(url)

    site1.auth_method = AUTH_TYPE_EMAIL 
    db.session.commit()
    url = get_guest_url(site1,mac,ap_mac,demo=0)
    check_email_login_page(url)

    site1.auth_method = AUTH_TYPE_VOUCHER 
    db.session.commit()
    url = get_guest_url(site1,mac,ap_mac,demo=0)
    check_voucher_login_page(url)
コード例 #3
0
ファイル: test_guest_views.py プロジェクト: vinchu/poppet
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"
コード例 #4
0
ファイル: test_guest_views.py プロジェクト: vinchu/poppet
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))
コード例 #5
0
ファイル: test_guest_views.py プロジェクト: vinchu/poppet
def test_guest_portal3(session):
    """Same user visiting multiple sites
    
    """
    site1 = Wifisite.query.filter_by(unifi_id="site1").first()
    site2 = Wifisite.query.filter_by(unifi_id="site2").first()
    site3 = Wifisite.query.filter_by(unifi_id="site3").first()
    site1.auth_method = AUTH_TYPE_SOCIAL + AUTH_TYPE_SMS + AUTH_TYPE_EMAIL + AUTH_TYPE_VOUCHER
    site2.auth_method = AUTH_TYPE_SOCIAL + AUTH_TYPE_SMS + AUTH_TYPE_EMAIL + AUTH_TYPE_VOUCHER
    site3.auth_method = AUTH_TYPE_SOCIAL + AUTH_TYPE_SMS + AUTH_TYPE_EMAIL + AUTH_TYPE_VOUCHER
    mac = randomMAC()
    ap_mac1 = randomMAC()
    ap_mac2 = randomMAC()
    ap_mac3 = randomMAC()
    url1 = get_guest_url(site1, mac, ap_mac1, demo=0)
    url2 = get_guest_url(site2, mac, ap_mac2, demo=0)
    url3 = get_guest_url(site3, mac, ap_mac3, demo=0)

    check_multi_login_page(url1)
    check_multi_login_page(url1)
    check_multi_login_page(url2)
    check_multi_login_page(url2)
    check_multi_login_page(url3)
    check_multi_login_page(url3)
    assert (
        2 == Guesttrack.query.filter_by(site_id=site1.id).count()
    ), "Same device visiting 3 sites twice, 2 Guesttrack PER SITE  needed"
    assert (
        2 == Guesttrack.query.filter_by(site_id=site2.id).count()
    ), "Same device visiting 3 sites twice, 2 Guesttrack PER SITE needed"
    assert (
        2 == Guesttrack.query.filter_by(site_id=site3.id).count()
    ), "Same device visiting 3 sites twice, 2 Guesttrack PER SITE needed"
    assert 3 == Device.query.count(), "Same device visiting 3 sites, 3 Device needed"
コード例 #6
0
ファイル: test_guest_views.py プロジェクト: pedritss/poppet
def test_guest_portal3(session):
    '''Same user visiting multiple sites
    
    ''' 
    site1        = Wifisite.query.filter_by(unifi_id='site1').first() 
    site2        = Wifisite.query.filter_by(unifi_id='site2').first() 
    site3        = Wifisite.query.filter_by(unifi_id='site3').first() 
    site1.auth_method = AUTH_TYPE_SOCIAL + AUTH_TYPE_SMS + AUTH_TYPE_EMAIL +AUTH_TYPE_VOUCHER      
    site2.auth_method = AUTH_TYPE_SOCIAL + AUTH_TYPE_SMS + AUTH_TYPE_EMAIL +AUTH_TYPE_VOUCHER      
    site3.auth_method = AUTH_TYPE_SOCIAL + AUTH_TYPE_SMS + AUTH_TYPE_EMAIL +AUTH_TYPE_VOUCHER      
    mac = randomMAC()
    ap_mac1 = randomMAC()
    ap_mac2 = randomMAC()
    ap_mac3 = randomMAC()
    url1 = get_guest_url(site1,mac,ap_mac1,demo=0)    
    url2 = get_guest_url(site2,mac,ap_mac2,demo=0)    
    url3 = get_guest_url(site3,mac,ap_mac3,demo=0)    

    check_multi_login_page(url1)    
    check_multi_login_page(url1)    
    check_multi_login_page(url2)    
    check_multi_login_page(url2)    
    check_multi_login_page(url3)    
    check_multi_login_page(url3)    
    assert 2 == Guesttrack.query.filter_by(site_id=site1.id).count(), "Same device visiting 3 sites twice, 2 Guesttrack PER SITE  needed" 
    assert 2 == Guesttrack.query.filter_by(site_id=site2.id).count(), "Same device visiting 3 sites twice, 2 Guesttrack PER SITE needed" 
    assert 2 == Guesttrack.query.filter_by(site_id=site3.id).count(), "Same device visiting 3 sites twice, 2 Guesttrack PER SITE needed" 
    assert 3 == Device.query.count(), "Same device visiting 3 sites, 3 Device needed" 
コード例 #7
0
ファイル: test_guest_views.py プロジェクト: vinchu/poppet
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"
コード例 #8
0
ファイル: test_guest_views.py プロジェクト: pedritss/poppet
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"
コード例 #9
0
ファイル: test_guest_views.py プロジェクト: vinchu/poppet
def test_authorize_guest2(session):
    """ authorize_guest check if parameters are correctly configured """
    # create a guest visitor
    site1 = Wifisite.query.filter_by(id=1).first()
    mac = randomMAC()
    ap_mac = randomMAC()
    site1.auth_method = AUTH_TYPE_SOCIAL + AUTH_TYPE_SMS + AUTH_TYPE_EMAIL + AUTH_TYPE_VOUCHER
    db.session.commit()
    url = get_guest_url(site1, mac, ap_mac, demo=0)
    check_multi_login_page(url)

    guest_track = Guesttrack.query.first()

    # authorize session
    guest_track.state = GUESTRACK_SOCIAL_AUTH

    auth_url = url_for("guest.authorize_guest", track_id=guest_track.track_id)
    result = current_app.test_client().get(auth_url, follow_redirects=True)
    assert "200 OK" == result.status, "authorize_guest  getting:%s instead of  200 OK while trying to View URL:%s" % (
        result.status,
        url,
    )

    # 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_AUTH, " guest_session state is not GUESTRACK_SOCIAL_AUTH"
コード例 #10
0
ファイル: test_guest_views.py プロジェクト: pedritss/poppet
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"
コード例 #11
0
ファイル: test_guest_views.py プロジェクト: pedritss/poppet
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))   
コード例 #12
0
ファイル: test_analytics.py プロジェクト: pedritss/poppet
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()
コード例 #13
0
ファイル: test_guest_views.py プロジェクト: vinchu/poppet
def test_guest_portal4(session):
    """User with demo flag set is visiting
    
    """
    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)
    check_multi_login_page(url1)

    guest_track1 = Guesttrack.query.filter(and_(Guesttrack.device_mac == mac, Guesttrack.site_id == site1.id)).first()
    guest_device1 = Device.query.filter(and_(Device.mac == mac, Device.site_id == site1.id)).first()

    assert 1 == guest_track1.demo, "Demo flag is not set for guest_track for URL:%s" % url1
    assert 1 == guest_device1.demo, "Demo flag is not set for guest_device for URL:%s" % url1
コード例 #14
0
ファイル: test_guest_views.py プロジェクト: pedritss/poppet
def test_guest_portal4(session):
    '''User with demo flag set is visiting
    
    ''' 
    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)   
    check_multi_login_page(url1) 

    guest_track1   = Guesttrack.query.filter( and_(Guesttrack.device_mac==mac,Guesttrack.site_id==site1.id)).first()
    guest_device1  = Device.query.filter( and_(Device.mac==mac,Device.site_id==site1.id)).first()

    assert 1 == guest_track1.demo,'Demo flag is not set for guest_track for URL:%s'%url1
    assert 1 == guest_device1.demo,'Demo flag is not set for guest_device for URL:%s'%url1
コード例 #15
0
ファイル: test_guest_views.py プロジェクト: pedritss/poppet
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() 
コード例 #16
0
ファイル: test_guest_views.py プロジェクト: vinchu/poppet
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)
コード例 #17
0
ファイル: test_guest_views.py プロジェクト: vinchu/poppet
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
ファイル: test_guest_views.py プロジェクト: pedritss/poppet
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)
コード例 #19
0
ファイル: test_guest_views.py プロジェクト: vinchu/poppet
def test_social_login2(session, guest_logged):
    """Test social_login view with pre authorized guest

     """
    site1 = Wifisite.query.filter_by(unifi_id="site1").first()
    site1.auth_method = AUTH_TYPE_SOCIAL
    guest_device = Device.query.first()
    mac = guest_device.mac
    guest_device.state = DEVICE_AUTH
    guest_track = Guesttrack.query.first()
    db.session.commit()
    ap_mac1 = randomMAC()

    check_url_responce(url_for("guest.social_login", track_id=guest_track.track_id), "Login Using Facebook")
コード例 #20
0
ファイル: test_guest_views.py プロジェクト: pedritss/poppet
def test_guest_portal2(session):
    '''Check if guest_track creations are done properly or not'''
    site1 = Wifisite.query.filter_by(id=1).first()
    site1.auth_method = AUTH_TYPE_SOCIAL + AUTH_TYPE_SMS + AUTH_TYPE_EMAIL +AUTH_TYPE_VOUCHER
    db.session.commit()
    mac = randomMAC()
    ap_mac = randomMAC()
    url = get_guest_url(site1,mac,ap_mac,demo=0)
    check_multi_login_page(url)

    # test if the device is created for this user
    test_device  = Device.query.filter( and_(Device.mac==mac,Device.site_id==site1.id)).first()
    assert isinstance(test_device, Device), "Device is not created when a new user visits"   
    #same user visit multiple times without session expiry, no new sessions should be created
    time.sleep(1)
    check_multi_login_page(url)
    check_multi_login_page(url)
    check_multi_login_page(url)
    check_multi_login_page(url)
    num_device  = Device.query.filter( and_(Device.mac==mac,Device.site_id==site1.id)).count()
    assert num_device == 1 , "User visiting twice without session expiry: Device shouldn't be created twice"
    #
    assert 5 == Guesttrack.query.count() , "User visiting  without session expiry: Guesttrack should be created eachtime"   
コード例 #21
0
ファイル: test_guest_views.py プロジェクト: vinchu/poppet
def test_guest_portal2(session):
    """Check if guest_track creations are done properly or not"""
    site1 = Wifisite.query.filter_by(id=1).first()
    site1.auth_method = AUTH_TYPE_SOCIAL + AUTH_TYPE_SMS + AUTH_TYPE_EMAIL + AUTH_TYPE_VOUCHER
    db.session.commit()
    mac = randomMAC()
    ap_mac = randomMAC()
    url = get_guest_url(site1, mac, ap_mac, demo=0)
    check_multi_login_page(url)

    # test if the device is created for this user
    test_device = Device.query.filter(and_(Device.mac == mac, Device.site_id == site1.id)).first()
    assert isinstance(test_device, Device), "Device is not created when a new user visits"
    # same user visit multiple times without session expiry, no new sessions should be created
    time.sleep(1)
    check_multi_login_page(url)
    check_multi_login_page(url)
    check_multi_login_page(url)
    check_multi_login_page(url)
    num_device = Device.query.filter(and_(Device.mac == mac, Device.site_id == site1.id)).count()
    assert num_device == 1, "User visiting twice without session expiry: Device shouldn't be created twice"
    #
    assert 5 == Guesttrack.query.count(), "User visiting  without session expiry: Guesttrack should be created eachtime"
コード例 #22
0
ファイル: test_guest_views.py プロジェクト: pedritss/poppet
def test_social_login2(session,guest_logged):
    '''Test social_login view with pre authorized guest

     '''
    site1               = Wifisite.query.filter_by(unifi_id='site1').first() 
    site1.auth_method   = AUTH_TYPE_SOCIAL    
    guest_device        = Device.query.first()  
    mac                 = guest_device.mac
    guest_device.state  = DEVICE_AUTH 
    guest_track         = Guesttrack.query.first()
    db.session.commit()     
    ap_mac1             = randomMAC() 

    check_url_responce(url_for('guest.social_login',track_id=guest_track.track_id),'Login Using Facebook') 
コード例 #23
0
ファイル: test_guest_views.py プロジェクト: pedritss/poppet
def test_authorize_guest2(session):
    ''' authorize_guest check if parameters are correctly configured '''
    #create a guest visitor
    site1 = Wifisite.query.filter_by(id=1).first()
    mac = randomMAC()
    ap_mac = randomMAC()    
    site1.auth_method = AUTH_TYPE_SOCIAL + AUTH_TYPE_SMS + AUTH_TYPE_EMAIL +AUTH_TYPE_VOUCHER
    db.session.commit()
    url = get_guest_url(site1,mac,ap_mac,demo=0)
    check_multi_login_page(url)  

    guest_track = Guesttrack.query.first()  

    #authorize session
    guest_track.state = GUESTRACK_SOCIAL_AUTH
    
    auth_url = url_for('guest.authorize_guest',track_id =guest_track.track_id)
    result = current_app.test_client().get(auth_url,follow_redirects=True)
    assert '200 OK' == result.status, 'authorize_guest  getting:%s instead of  200 OK while trying to View URL:%s'%(result.status,url)

    #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_AUTH, " guest_session state is not GUESTRACK_SOCIAL_AUTH"
コード例 #24
0
ファイル: test_analytics.py プロジェクト: pedritss/poppet
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)
コード例 #25
0
ファイル: test_analytics.py プロジェクト: vinchu/poppet
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)
コード例 #26
0
ファイル: test_analytics.py プロジェクト: vinchu/poppet
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()