[LON-CAPA-cvs] cvs: modules /goltermann/internalTest/t UserRelated.pm

goltermann goltermann at source.lon-capa.org
Tue May 7 06:36:20 EDT 2013


goltermann		Tue May  7 10:36:20 2013 EDT

  Added files:                 
    /modules/goltermann/internalTest/t	UserRelated.pm 
  Log:
  initial commit
  stable version
  
  

Index: modules/goltermann/internalTest/t/UserRelated.pm
+++ modules/goltermann/internalTest/t/UserRelated.pm
#! perl
use strict;
use warnings;
package UserRelated;
use lib('/home/httpd/lib/perl');
use Test::More;
use Apache::lonnet;
use Smart::Comments;


sub run(){
    shift;
    my %config = @_;

    my $user = $config{'user'};
    my $pw = $config{'pw'};
    my $tmppw = 'tmppw12345';           # if something breaks while chaning the pw (it shouldnt) you might need the temp password to set your old pw back manually
    my $domain = $config{'domain'};


    # Test 1,2
    # Trying to write a testhash
    is(&Apache::lonnet::appenv(%config), 'ok', 'writing %config in appenv');
    is(&Apache::lonnet::delenv(%config), 'ok', 'deleting %config in appenv');
    # i dont think this is a good 'clean' test
    #

    # Test 3, 4
    # trying to determine hostserver of user
    my $homeserver = &Apache::lonnet::homeserver($user,$domain);
    # my $homeserver = &Apache::lonnet::homeserver($user,'fhwfdev133');   # wrong data for testing
    ok($homeserver ne 'no_host', 'host found '.$homeserver);
    ok($homeserver ne 'no_account_on_host', 'account found');
    #

    # Test 5
    # checking if authentication is possible
    my $authenticate = &Apache::lonnet::authenticate($user,$pw,$domain);
    ok($authenticate ne 'no_host', 'authentication');
    #

    # Test 6, 7, 8, 9
    # changes the password and see if it works
    isnt(&Apache::lonnet::changepass($user, $domain, 'somebadpwwhichshouldnotwork', $homeserver), 'ok', 'trying wrong pw');
    is(&Apache::lonnet::changepass($user,$domain,$pw,'tmppw12345',$homeserver), 'ok', 'change pw');
    isnt(&Apache::lonnet::authenticate($user,$tmppw,$domain), 'no_host', 'authenticate with new pw');
    is(&Apache::lonnet::changepass($user,$domain,$tmppw,$pw,$homeserver), 'ok', 'changing to old pw');

    # Test 10
    # overrides old id without asking. thats ok when using a specially created testuser, but
    # DONT USE WITH A PRODUCTIVE USER (if you dont know what you are doing)
    my $uniqueId = localtime;
    &Apache::lonnet::idput($domain, ($user => $uniqueId));
    # checks if ID successfully set
    my %idrget = &Apache::lonnet::idrget($domain, ($user));
    ok($idrget{$user} eq $uniqueId, 'set new id');
    #


}

END{
    # TODO test if repair function is needed
    # if (errors){
    #     repair
    # }
}

1;




More information about the LON-CAPA-cvs mailing list