view release on metacpan or search on metacpan
t/External/Apache-Sling-Authn.t view on Meta::CPAN
$sling->{'URL'} = $sling_host;
$sling->{'User'} = $super_user;
$sling->{'Log'} = $log;
# Check creating authn object fails with bad password:
$sling->{'Pass'} = 'badpasswordwillnotwork';
# Check creation with verbosity turned up:
$sling->{'Verbose'} = 3;
my $authn = Apache::Sling::Authn->new( \$sling );
isa_ok $authn, 'Apache::Sling::Authn', 'authentication';
throws_ok{ $authn->login_user() } qr%Basic Auth log in for user "$super_user" at URL "$sling_host" was unsuccessful%, 'Check authn object creation croaks with bad password and high verbosity';
# reset verbosity level:
$sling->{'Verbose'} = $verbose;
$authn = Apache::Sling::Authn->new( \$sling );
isa_ok $authn, 'Apache::Sling::Authn', 'authentication';
throws_ok{ $authn->login_user() } qr%Basic Auth log in for user "$super_user" at URL "$sling_host" was unsuccessful%, 'Check authn object creation croaks with bad password and default verbosity';
# Set the password to something that should work!
$sling->{'Pass'} = $super_pass;
# Check creating authn object fails with unsupported auth type:
$sling->{'Auth'} = 'badauthtypewillnotwork';
$authn = Apache::Sling::Authn->new( \$sling );
isa_ok $authn, 'Apache::Sling::Authn', 'authentication';
throws_ok{ $authn->login_user() } qr/Unsupported auth type: "badauthtypewillnotwork"/, 'Check authn object creation croaks with unsupported auth type';
# Set the auth type to something that should work!
$sling->{'Auth'} = undef;
# authn object:
$sling->{'Verbose'} = 3;
$authn = Apache::Sling::Authn->new( \$sling );
isa_ok $authn, 'Apache::Sling::Authn', 'authentication';
ok( $authn->login_user(), "log in successful" );
$sling->{'Verbose'} = $verbose;
t/External/Apache-Sling-Authn.t view on Meta::CPAN
# Add two users:
ok( $user->add( $test_user1, $test_pass, \@test_properties ),
"Authn Test: User \"$test_user1\" added successfully." );
ok( $user->check_exists( $test_user1 ),
"Authn Test: User \"$test_user1\" exists." );
ok( $user->add( $test_user2, $test_pass, \@test_properties ),
"Authn Test: User \"$test_user2\" added successfully." );
ok( $user->check_exists( $test_user2 ),
"Authn Test: User \"$test_user2\" exists." );
throws_ok{ $authn->switch_user( $test_user1, $test_pass, "badauthtypewillnotwork", 1 ) } qr/Unsupported auth type: "badauthtypewillnotwork"/, 'Check switch_user croaks with unsupported auth type';
throws_ok{ $authn->switch_user( "baduser", "badpassword", "basic", 1 ) } qr/Basic Auth log in for user "baduser" at URL "$sling_host" was unsuccessful/, 'Check switch_user croaks with bad credentials';
throws_ok{ $authn->switch_user( $super_user, "badpassword", "basic", 1 ) } qr/Basic Auth log in for user "$super_user" at URL "$sling_host" was unsuccessful/, 'Check switch_user croaks with bad password';
ok( $authn->switch_user( $test_user1, $test_pass, "basic", 1 ),
"Authn Test: Successfully switched to user: \"$test_user1\" with basic auth" );
ok( $authn->switch_user( $test_user1, $test_pass, "basic", 1 ),
"Authn Test: Successfully stayed as user: \"$test_user1\"" );
ok( $authn->switch_user( $test_user2, $test_pass, "basic", 1 ),
"Authn Test: Successfully switched to user: \"$test_user2\" with basic auth" );
$authn->{'Verbose'} = 3;
ok( $authn->switch_user( $super_user, $super_pass, "basic", 1 ),
"Authn Test: Successfully switched back to user: \"$super_user\" with basic auth" );
$authn->{'Verbose'} = $verbose;
t/External/Apache-Sling-Content.t view on Meta::CPAN
# You need to flush the tmp content handle to actually write data
# out to the file on disk:
close $tmp_content_handle;
my $test_path = "content_test_path_$$";
ok( ! $content->upload_file($tmp_content_name,".."), 'Check upload_file function fails with remote path that is not allowed' );
ok( $content->upload_file($tmp_content_name,$test_path), 'Check upload_file function' );
ok( ! $content->view("$test_path/this_file_does_not_exist"), 'Check view function with non-existent file' );
ok( $content->view("$test_path/$tmp_content_basename"), 'Check view function' );
ok( $content->view_file("$test_path/$tmp_content_basename"), 'Check view file function' );
ok( ! $content->view_file("$test_path/this_file_does_not_exist"), 'Check view file function with non-existent file' );
throws_ok{ $content->view_file()} qr{No file to view specified!}, 'Check view_file function croaks with a missing remote path';
ok( $content->view_full_json("$test_path/$tmp_content_basename"), 'Check view_full_json function' );
ok( ! $content->view_full_json("$test_path/this_file_does_not_exist"), 'Check view_full_json function with non-existent file' );
throws_ok{ $content->view_full_json()} qr{No file to view specified!}, 'Check view_full_json function croaks with a missing remote path';
ok( $content->upload_file($tmp_content_name,$test_path,$test_content1), 'Check upload_file function with filename specified' );
ok( $content->view("$test_path/$test_content1"), 'Check view function on named file' );
ok( $content->view_file("$test_path/$test_content1"), 'Check view file function on named file' );
my $upload = "$tmp_content_name\n";
throws_ok{ $content->upload_from_file(\$upload)} qr{Problem parsing content to add}, 'Check upload_file function croaks with a missing remote path';
$upload = "$tmp_content_name,$test_content1\n";
ok( $content->upload_from_file(\$upload,0,1), 'Check upload_from_file function' );
my ( $tmp_content2_handle, $tmp_content2_name ) = File::Temp::tempfile();
$upload .= "$tmp_content2_name,$test_content2\n";
ok( $content->upload_from_file(\$upload,1,2), 'Check upload_from_file function with two forks' );
unlink($tmp_content_name);
unlink($tmp_content2_name);
throws_ok{ $content->upload_from_file($tmp_content_name,0,1)} qr{Problem opening file: '$tmp_content_name'}, 'Check upload_file function croaks with a missing file';
# Add content item to manipulate:
ok( my $content_config = Apache::Sling::Content->config($sling), 'check content_config function' );
$content_config->{'add'} = \$test_content1;
$content_config->{'remote'} = \$test_content1;
ok( Apache::Sling::Content->run($sling,$content_config), q{check content_run function adding content $test_content1} );
# Test content additions from file:
my ( $tmp_content_additions_handle, $tmp_content_additions_name ) = File::Temp::tempfile();
ok( $content_config = Apache::Sling::Content->config($sling), 'check content_config function' );
t/External/Apache-Sling-Group.t view on Meta::CPAN
my $test_upload_group1 = "group_test_upload_group_1_$$";
my $test_upload_group2 = "group_test_upload_group_2_$$";
my $test_upload_group3 = "group_test_upload_group_3_$$";
my $test_upload_group4 = "group_test_upload_group_4_$$";
my $upload = "group\n$test_upload_group1";
ok( $group->add_from_file(\$upload,0,1), 'Check add_from_file function' );
$upload = "group\n$test_upload_group2\n$test_upload_group3\n$test_upload_group4";
ok( $group->add_from_file(\$upload,0,3), 'Check add_from_file function with three forks' );
$upload = "bad_heading\n$test_upload_group1";
throws_ok{ $group->add_from_file(\$upload,0,1); } qr%First CSV column must be the group ID, column heading must be "group". Found: "bad_heading".%, 'Check add_from_file function with bad heading';
$upload = "group\n$test_upload_group1,bad_extra_column";
throws_ok{ $group->add_from_file(\$upload,0,1); } qr%Found "2" columns. There should have been "1".%, 'Check add_from_file function with heading / data count mismatch';
$upload = "group,property\n$test_upload_group2,test";
ok( $group->add_from_file(\$upload,0,1), 'Check add_from_file function with extra property specified' );
# Cleanup Users:
ok( $user->del( $test_user ),
"Group Test: User \"$test_user\" deleted successfully." );
ok( ! $user->check_exists( $test_user ),
"Group Test: User \"$test_user\" no longer exists." );
# Cleanup Groups:
t/External/Apache-Sling-GroupMember.t view on Meta::CPAN
ok( $user->check_exists( $test_upload_user3 ),
"Group Test: User \"$test_upload_user3\" exists." );
ok( $user->check_exists( $test_upload_user4 ),
"Group Test: User \"$test_upload_user4\" exists." );
my $upload = "group,user\n$test_group3,$test_upload_user1";
ok( $group_member->add_from_file(\$upload,0,1), 'Check member add_from_file function' );
$upload = "group,user\n$test_group3,$test_upload_user2\n$test_group3,$test_upload_user3\n$test_group3,$test_upload_user4";
ok( $group_member->add_from_file(\$upload,0,3), 'Check member add_from_file function with three forks' );
$upload = "group,bad_heading\n$test_group3,$test_upload_user1";
throws_ok{ $group_member->add_from_file(\$upload,0,1); } qr%Second CSV column must be the user ID, column heading must be "user". Found: "bad_heading".%, 'Check member add_from_file function with bad second heading';
$upload = "group,user\n$test_group3,$test_upload_user1,bad_extra_column";
throws_ok{ $group_member->add_from_file(\$upload,0,1); } qr%Found "3" columns. There should have been "2".%, 'Check member add_from_file function with heading / data count mismatch';
$upload = "group,user,property\n$test_group3,$test_upload_user2,test";
ok( $group_member->add_from_file(\$upload,0,1), 'Check member add_from_file function with extra property specified' );
ok( ! $group_member->view( "non-existent-$test_group1" ),
"Group Test: Test for members in non-existent group." );
ok( ! $group_member->check_exists( "non-existent-$test_group1", $test_user ),
"Group Test: Test member exists in non-existent group." );
ok( $group_member->add( $test_group2, $test_user ),
"Group Test: Member \"$test_user\" added to \"$test_group2\"." );
t/External/Apache-Sling-JsonQueryServlet.t view on Meta::CPAN
# sling object:
my $sling = Apache::Sling->new();
isa_ok $sling, 'Apache::Sling', 'sling';
$sling->{'URL'} = $sling_host;
$sling->{'User'} = $super_user;
$sling->{'Pass'} = $super_pass;
$sling->{'Verbose'} = $verbose;
$sling->{'Log'} = $log;
# Check error is thrown without auth:
throws_ok{ my $jsonqueryobject = Apache::Sling::JsonQueryServlet->new(); } qr%no authn provided!%, 'Check JSON query servlet creation croaks with authn missing';
# authn object:
my $authn = Apache::Sling::Authn->new( \$sling );
isa_ok $authn, 'Apache::Sling::Authn', 'authentication';
ok( $authn->login_user(), "log in successful" );
# json query object:
my $jsonqueryobject = Apache::Sling::JsonQueryServlet->new( \$authn, $verbose, $log );
isa_ok $jsonqueryobject, 'Apache::Sling::JsonQueryServlet', 'jsonqueryservlet';
$jsonqueryobject = Apache::Sling::JsonQueryServlet->new( \$authn );
t/External/Apache-Sling-User.t view on Meta::CPAN
# sling object:
my $sling = Apache::Sling->new();
isa_ok $sling, 'Apache::Sling', 'sling';
$sling->{'URL'} = $sling_host;
$sling->{'User'} = $super_user;
$sling->{'Pass'} = $super_pass;
$sling->{'Verbose'} = $verbose;
$sling->{'Log'} = $log;
# Check error is thrown without auth:
throws_ok{ my $user = Apache::Sling::User->new(); } qr%no authn provided!%, 'Check user creation croaks with authn missing';
# authn object:
my $authn = Apache::Sling::Authn->new( \$sling );
isa_ok $authn, 'Apache::Sling::Authn', 'authentication';
ok( $authn->login_user(), "log in successful" );
# user object:
my $user = Apache::Sling::User->new( \$authn, $verbose, $log );
isa_ok $user, 'Apache::Sling::User', 'user';
# group object:
my $group = Apache::Sling::Group->new( \$authn, $verbose, $log );
t/External/Apache-Sling-User.t view on Meta::CPAN
my $test_upload_user1 = "user_test_upload_user_1_$$";
my $test_upload_user2 = "user_test_upload_user_2_$$";
my $test_upload_user3 = "user_test_upload_user_3_$$";
my $test_upload_user4 = "user_test_upload_user_4_$$";
my $upload = "user,password\n$test_upload_user1,$test_pass";
ok( $user->add_from_file(\$upload,0,1), 'Check add_from_file function' );
$upload = "user,password\n$test_upload_user2,$test_pass\n$test_upload_user3,$test_pass\n$test_upload_user4,$test_pass";
ok( $user->add_from_file(\$upload,0,3), 'Check add_from_file function with three forks' );
$upload = "user,bad_heading\n$test_upload_user1,$test_pass";
throws_ok{ $user->add_from_file(\$upload,0,1); } qr%Second CSV column must be the user password, column heading must be "password". Found: "bad_heading".%, 'Check add_from_file function with bad second heading';
$upload = "user,password\n$test_upload_user1,$test_pass,bad_extra_column";
throws_ok{ $user->add_from_file(\$upload,0,1); } qr%Found "3" columns. There should have been "2".%, 'Check add_from_file function with heading / data count mismatch';
$upload = "user,password,property\n$test_upload_user2,$test_pass,test";
ok( $user->add_from_file(\$upload,0,1), 'Check add_from_file function with extra property specified' );
# Check user deletion:
ok( ! $user->del( "non-existent-$test_user" ),
"User Test: non-existent user not deleted successfully." );
ok( $user->del( $test_user ),
"User Test: User \"$test_user\" deleted successfully." );
ok( $user->del( $test_upload_user1 ),
"User Test: User \"$test_upload_user1\" deleted successfully." );
t/Local/Apache-Sling-Authn.t view on Meta::CPAN
$sling->{'Referer'} = '/test/referer';
$authn = new Apache::Sling::Authn(\$sling);
isa_ok $authn, 'Apache::Sling::Authn', 'authn';
ok( $authn->{ 'Type' } eq 'advanced', 'Check Auth type set' );
ok( $authn->{ 'Username' } eq 'testuser', 'Check Auth user set' );
$authn->{'BaseURL'} = undef;
ok( ! defined $authn->{ 'BaseURL' }, 'Check base URL not defined' );
ok( $authn->login_user, 'Check login user returns fine with no base URL set');
throws_ok { $authn->switch_user } qr/New username to switch to not defined/, 'Check switch_user function croaks without new username';
throws_ok { $authn->switch_user('new_username') } qr/New password to use in switch not defined/, 'Check switch_user function croaks without new password';
t/Local/Apache-Sling-AuthnUtil.t view on Meta::CPAN
use warnings;
use Test::More tests => 5;
use Test::Exception;
BEGIN { use_ok( 'Apache::Sling::AuthnUtil' ); }
BEGIN { use_ok( 'HTTP::Response' ); }
ok( Apache::Sling::AuthnUtil::basic_login_setup( 'http://localhost:8080' ) eq
'get http://localhost:8080/system/sling/login?sling:authRequestLogin=1', 'Check basic_login_setup function' );
throws_ok { Apache::Sling::AuthnUtil::basic_login_setup() } qr/No base url defined!/, 'Check basic_login_setup function croaks without base url';
my $res = HTTP::Response->new( '200' );
ok( Apache::Sling::AuthnUtil::basic_login_eval( \$res ), 'Check basic_login_eval function' );
t/Local/Apache-Sling-Authz.t view on Meta::CPAN
BEGIN { use_ok( 'Apache::Sling' ); }
BEGIN { use_ok( 'Apache::Sling::Authn' ); }
BEGIN { use_ok( 'Apache::Sling::Authz' ); }
# sling object:
my $sling = Apache::Sling->new();
isa_ok $sling, 'Apache::Sling', 'sling';
my $authn = new Apache::Sling::Authn(\$sling);
throws_ok { my $authz = new Apache::Sling::Authz() } qr/no authn provided!/, 'Check authz creation fails without authn provided';
my $authz = new Apache::Sling::Authz(\$authn,'1','log.txt');
isa_ok $authz, 'Apache::Sling::Authz', 'authz';
ok( $authz->{ 'BaseURL' } eq 'http://localhost:8080', 'Check BaseURL set' );
ok( $authz->{ 'Log' } eq 'log.txt', 'Check Log set' );
ok( $authz->{ 'Message' } eq '', 'Check Message set' );
ok( $authz->{ 'Verbose' } == 1, 'Check Verbosity set' );
ok( defined $authz->{ 'Response' }, 'Check response defined' );
$authz->set_results( 'Test Message', undef );
ok( $authz->{ 'Message' } eq 'Test Message', 'Message now set' );
ok( ! defined $authz->{ 'Response' }, 'Check response no longer defined' );
ok( my $authz_config = Apache::Sling::Authz->config($sling), 'check config function' );
ok( Apache::Sling::Authz->run($sling, $authz_config), 'check run function' );
throws_ok { Apache::Sling::Authz->run() } qr/No authz config supplied!/, 'check run function croaks with no config supplied';
t/Local/Apache-Sling-AuthzUtil.t view on Meta::CPAN
use Test::Exception;
BEGIN { use_ok( 'Apache::Sling::AuthzUtil' ); }
BEGIN { use_ok( 'HTTP::Response' ); }
my $res = HTTP::Response->new( '200' );
# get_acl
ok( Apache::Sling::AuthzUtil::get_acl_setup( 'http://localhost:8080', 'dest' ) eq
'get http://localhost:8080/dest.acl.json', 'Check get_acl_setup function' );
throws_ok { Apache::Sling::AuthzUtil::get_acl_setup('http://localhost:8080') } qr/No destination to view ACL for defined!/, 'Check get_acl_setup function croaks without remote destination';
throws_ok { Apache::Sling::AuthzUtil::get_acl_setup() } qr/No base url defined!/, 'Check get_acl_setup function croaks without base URL';
ok( Apache::Sling::AuthzUtil::get_acl_eval( \$res ), 'Check get_acl_eval function' );
# delete
ok( Apache::Sling::AuthzUtil::delete_setup( 'http://localhost:8080', 'dest', 'principal' ) eq
"post http://localhost:8080/dest.deleteAce.html \$post_variables = [':applyTo','principal']", 'Check delete_setup function' );
throws_ok { Apache::Sling::AuthzUtil::delete_setup('http://localhost:8080','dest') } qr/No principal to delete ACL for defined!/, 'Check delete_setup function croaks without principal';
throws_ok { Apache::Sling::AuthzUtil::delete_setup('http://localhost:8080') } qr/No destination to delete ACL for defined!/, 'Check delete_setup function croaks without remote destination';
throws_ok { Apache::Sling::AuthzUtil::delete_setup() } qr/No base url defined!/, 'Check delete_setup function croaks without base URL';
ok( Apache::Sling::AuthzUtil::delete_eval( \$res ), 'Check delete_eval function' );
# modify_privilege
my @grant_privileges;
my @deny_privileges;
ok( Apache::Sling::AuthzUtil::modify_privilege_setup( 'http://localhost:8080', 'dest', 'principal', \@grant_privileges, \@deny_privileges ) eq
"post http://localhost:8080/dest.modifyAce.html \$post_variables = ['principalId','principal']", 'Check modify_privilege_setup function' );
throws_ok { Apache::Sling::AuthzUtil::modify_privilege_setup('http://localhost:8080','dest') } qr/No principal to modify privilege for defined!/, 'Check modify_privilege_setup function croaks without principal';
throws_ok { Apache::Sling::AuthzUtil::modify_privilege_setup('http://localhost:8080') } qr/No destination to modify privilege for defined!/, 'Check modify_privilege_setup function croaks without remote destination';
throws_ok { Apache::Sling::AuthzUtil::modify_privilege_setup() } qr/No base url defined!/, 'Check modify_privilege_setup function croaks without base URL';
ok( Apache::Sling::AuthzUtil::modify_privilege_eval( \$res ), 'Check modify_privilege_eval function' );
push @grant_privileges, 'broken_privilege';
throws_ok { Apache::Sling::AuthzUtil::modify_privilege_setup('http://localhost:8080', 'dest', 'principal', \@grant_privileges, \@deny_privileges) } qr/Unsupported grant privilege: "broken_privilege" supplied!/, 'Check modify_privilege_setup function ...
shift @grant_privileges;
push @deny_privileges, 'broken_privilege';
throws_ok { Apache::Sling::AuthzUtil::modify_privilege_setup('http://localhost:8080', 'dest', 'principal', \@grant_privileges, \@deny_privileges) } qr/Unsupported deny privilege: "broken_privilege" supplied!/, 'Check modify_privilege_setup function c...
shift @deny_privileges;
push @grant_privileges, 'read';
push @deny_privileges, 'modifyProperties';
ok( Apache::Sling::AuthzUtil::modify_privilege_setup( 'http://localhost:8080', 'dest', 'principal', \@grant_privileges, \@deny_privileges ) eq
"post http://localhost:8080/dest.modifyAce.html \$post_variables = ['principalId','principal','privilege\@jcr:read','granted','privilege\@jcr:modifyProperties','denied']", 'Check modify_privilege_setup function with two privileges used' );
push @grant_privileges, 'addChildNodes';
push @deny_privileges, 'removeNode';
ok( Apache::Sling::AuthzUtil::modify_privilege_setup( 'http://localhost:8080', 'dest', 'principal', \@grant_privileges, \@deny_privileges ) eq
"post http://localhost:8080/dest.modifyAce.html \$post_variables = ['principalId','principal','privilege\@jcr:read','granted','privilege\@jcr:addChildNodes','granted','privilege\@jcr:modifyProperties','denied','privilege\@jcr:removeNode','denied']"...
push @grant_privileges, 'removeChildNodes';
t/Local/Apache-Sling-Content.t view on Meta::CPAN
use Test::Exception;
BEGIN { use_ok( 'Apache::Sling' ); }
BEGIN { use_ok( 'Apache::Sling::Authn' ); }
BEGIN { use_ok( 'Apache::Sling::Content' ); }
# sling object:
my $sling = Apache::Sling->new();
isa_ok $sling, 'Apache::Sling', 'sling';
my $authn = new Apache::Sling::Authn(\$sling);
throws_ok { my $content = new Apache::Sling::Content() } qr/no authn provided!/, 'Check creating content croaks without authn provided';
my $content = new Apache::Sling::Content(\$authn,'1','log.txt');
ok( $content->{ 'BaseURL' } eq 'http://localhost:8080', 'Check BaseURL set' );
ok( $content->{ 'Log' } eq 'log.txt', 'Check Log set' );
ok( $content->{ 'Message' } eq '', 'Check Message set' );
ok( $content->{ 'Verbose' } == 1, 'Check Verbosity set' );
ok( defined $content->{ 'Authn' }, 'Check authn defined' );
ok( defined $content->{ 'Response' }, 'Check response defined' );
$content->set_results( 'Test Message', undef );
ok( $content->{ 'Message' } eq 'Test Message', 'Message now set' );
ok( ! defined $content->{ 'Response' }, 'Check response no longer defined' );
throws_ok { $content->add() } qr/No position or ID to perform action for specified!/, 'Check add function croaks without remote_dest specified';
throws_ok { $content->copy() } qr/No content source to copy from defined!/, 'Check copy function croaks without remote_src specified';
throws_ok { $content->del() } qr/No content destination to delete defined!/, 'Check del function croaks without remote_dest specified';
throws_ok { $content->check_exists() } qr/No position or ID to perform exists for specified!/, 'Check check_exists function croaks without remote_dest specified';
throws_ok { $content->move() } qr/No content source to move from defined!/, 'Check move function croaks without remote_src specified';
throws_ok { $content->upload_file() } qr/No local file to upload defined!/, 'Check upload_file function croaks without file specified';
throws_ok { $content->view() } qr/No position or ID to perform exists for specified!/, 'Check view function croaks without remote_dest specified';
throws_ok { $content->view_file() } qr/No file to view specified!/, 'Check view_file function croaks without remote_dest specified';
my $file = "\n";
throws_ok { $content->upload_from_file() } qr/File to upload from not defined/, 'Check upload_from_file function croaks without file specified';
throws_ok { $content->upload_from_file(\$file) } qr/Problem parsing content to add/, 'Check upload_from_file function croaks with blank file';
throws_ok { $content->upload_from_file('/tmp/__non__--__tnetsixe__') } qr{Problem opening file: '/tmp/__non__--__tnetsixe__'}, 'Check upload_from_file function croaks with non-existent file specified';
ok( my $content_config = Apache::Sling::Content->config($sling), 'check content_config function' );
ok( Apache::Sling::Content->run($sling,$content_config), 'check run function' );
throws_ok { Apache::Sling::Content->run() } qr/No content config supplied!/, 'check run function croaks with no config supplied';
t/Local/Apache-Sling-ContentUtil.t view on Meta::CPAN
BEGIN { use_ok( 'HTTP::Response' ); }
my $res = HTTP::Response->new( '200' );
my @properties = '';
ok( Apache::Sling::ContentUtil::add_setup( 'http://localhost:8080', 'remote/', \@properties) eq
'post http://localhost:8080/remote/ $post_variables = []', 'Check add_setup function' );
push @properties, "a=b";
ok( Apache::Sling::ContentUtil::add_setup( 'http://localhost:8080', 'remote/', \@properties) eq
"post http://localhost:8080/remote/ \$post_variables = ['a','b']", 'Check add_setup function with variables' );
throws_ok { Apache::Sling::ContentUtil::add_setup() } qr/No base URL provided!/, 'Check add_setup function croaks without base url';
throws_ok { Apache::Sling::ContentUtil::add_setup( 'http://localhost:8080' ) } qr/No position or ID to perform action for specified!/, 'Check add_setup function croaks without remote_dest';
ok( Apache::Sling::ContentUtil::add_eval( \$res ), 'Check add_eval function' );
ok( Apache::Sling::ContentUtil::copy_setup('http://localhost:8080','remoteSrc/', 'remoteDest/') eq
"post http://localhost:8080/remoteSrc/ \$post_variables = [':dest','remoteDest/',':operation','copy']", 'Check copy_setup function without replace defined' );
ok(Apache::Sling::ContentUtil::copy_setup('http://localhost:8080','remoteSrc/','remoteDest/',1) eq
"post http://localhost:8080/remoteSrc/ \$post_variables = [':dest','remoteDest/',':operation','copy',':replace','true']", 'Check copy_setup function with replace defined' );
throws_ok { Apache::Sling::ContentUtil::copy_setup() } qr/No base url defined!/, 'Check copy_setup function croaks without base url';
throws_ok { Apache::Sling::ContentUtil::copy_setup( 'http://localhost:8080' ) } qr/No content source to copy from defined!/, 'Check copy_setup function croaks without remote_src';
throws_ok { Apache::Sling::ContentUtil::copy_setup( 'http://localhost:8080','remoteSrc/' ) } qr/No content destination to copy to defined!/, 'Check copy_setup function croaks without remote_dest';
ok( Apache::Sling::ContentUtil::copy_eval( \$res ), 'Check copy_eval function' );
ok(Apache::Sling::ContentUtil::delete_setup('http://localhost:8080','remote/') eq
"post http://localhost:8080/remote/ \$post_variables = [':operation','delete']", 'Check delete_setup function' );
throws_ok { Apache::Sling::ContentUtil::delete_setup() } qr/No base url defined!/, 'Check delete_setup function croaks without base url';
throws_ok { Apache::Sling::ContentUtil::delete_setup('http://localhost:8080') } qr/No content destination to delete defined!/, 'Check delete_setup function croaks without remote_dest';
ok( Apache::Sling::ContentUtil::delete_eval( \$res ), 'Check delete_eval function' );
ok(Apache::Sling::ContentUtil::exists_setup('http://localhost:8080','remote') eq
"get http://localhost:8080/remote.json", 'Check exists_setup function' );
throws_ok { Apache::Sling::ContentUtil::exists_setup() } qr/No base url defined!/, 'Check exists_setup function croaks without base url';
throws_ok { Apache::Sling::ContentUtil::exists_setup('http://localhost:8080') } qr/No position or ID to perform exists for specified!/, 'Check exists_setup function croaks without remote_dest';
ok( Apache::Sling::ContentUtil::exists_eval( \$res ), 'Check exists_eval function' );
ok(Apache::Sling::ContentUtil::full_json_setup('http://localhost:8080','remote') eq "get http://localhost:8080/remote.infinity.json", 'Check full_json_setup function' );
throws_ok { Apache::Sling::ContentUtil::full_json_setup() } qr/No base url defined!/, 'Check full_json_setup function croaks without base url';
throws_ok { Apache::Sling::ContentUtil::full_json_setup('http://localhost:8080')
} qr/No position or ID to retrieve full json for specified!/, 'Check full_json_setup function croaks without remote_dest';
ok( Apache::Sling::ContentUtil::full_json_eval( \$res ), 'Check full_json_eval function' );
ok( Apache::Sling::ContentUtil::move_setup('http://localhost:8080','remoteSrc/', 'remoteDest/') eq
"post http://localhost:8080/remoteSrc/ \$post_variables = [':dest','remoteDest/',':operation','move']", 'Check move_setup function without replace defined' );
ok(Apache::Sling::ContentUtil::move_setup('http://localhost:8080','remoteSrc/','remoteDest/',1) eq
"post http://localhost:8080/remoteSrc/ \$post_variables = [':dest','remoteDest/',':operation','move',':replace','true']", 'Check move_setup function with replace defined' );
throws_ok { Apache::Sling::ContentUtil::move_setup() } qr/No base url defined!/, 'Check move_setup function croaks without base url';
throws_ok { Apache::Sling::ContentUtil::move_setup('http://localhost:8080') } qr/No content source to move from defined!/, 'Check move_setup function croaks without remote_src';
throws_ok { Apache::Sling::ContentUtil::move_setup('http://localhost:8080','remoteSrc/') } qr/No content destination to move to defined!/, 'Check move_setup function croaks without remote_dest';
ok( Apache::Sling::ContentUtil::move_eval( \$res ), 'Check move_eval function' );
ok(Apache::Sling::ContentUtil::upload_file_setup('http://localhost:8080','./local','remote','') eq
"fileupload http://localhost:8080/remote ./* ./local \$post_variables = []", 'Check upload_file_setup function' );
ok(Apache::Sling::ContentUtil::upload_file_setup('http://localhost:8080','./local','remote','file') eq
"fileupload http://localhost:8080/remote file ./local \$post_variables = []", 'Check upload_file_setup function' );
throws_ok { Apache::Sling::ContentUtil::upload_file_setup() } qr/No base URL provided to upload against!/, 'Check upload_file_setup function croaks without base url';
throws_ok { Apache::Sling::ContentUtil::upload_file_setup('http://localhost:8080') } qr/No local file to upload defined!/, 'Check upload_file_setup function croaks without local_path';
throws_ok { Apache::Sling::ContentUtil::upload_file_setup('http://localhost:8080','local') } qr/No remote path to upload to defined for file local!/, 'Check upload_file_setup function croaks without remote_dest';
ok( Apache::Sling::ContentUtil::upload_file_eval( \$res ), 'Check upload_file_eval function' );
t/Local/Apache-Sling-Group.t view on Meta::CPAN
BEGIN { use_ok( 'Apache::Sling' ); }
BEGIN { use_ok( 'Apache::Sling::Authn' ); }
BEGIN { use_ok( 'Apache::Sling::Group' ); }
# sling object:
my $sling = Apache::Sling->new();
isa_ok $sling, 'Apache::Sling', 'sling';
my $authn = new Apache::Sling::Authn(\$sling);
throws_ok { my $group = new Apache::Sling::Group() } qr/no authn provided!/, 'Check creating group croaks without authn provided';
my $group = new Apache::Sling::Group(\$authn,'1','log.txt');
ok( $group->{ 'BaseURL' } eq 'http://localhost:8080', 'Check BaseURL set' );
ok( $group->{ 'Log' } eq 'log.txt', 'Check Log set' );
ok( $group->{ 'Message' } eq '', 'Check Message set' );
ok( $group->{ 'Verbose' } == 1, 'Check Verbosity set' );
ok( defined $group->{ 'Authn' }, 'Check authn defined' );
ok( defined $group->{ 'Response' }, 'Check response defined' );
$group->set_results( 'Test Message', undef );
ok( $group->{ 'Message' } eq 'Test Message', 'Message now set' );
ok( ! defined $group->{ 'Response' }, 'Check response no longer defined' );
throws_ok { $group->add() } qr/No group name defined to add!/, 'Check add function croaks without group specified';
throws_ok { $group->del() } qr/No group name defined to delete!/, 'Check del function croaks without group specified';
throws_ok { $group->check_exists() } qr/No group to check existence of defined!/, 'Check check_exists function croaks without group specified';
throws_ok { $group->view() } qr/No group to view defined!/, 'Check view function croaks without group specified';
my $file = "\n";
throws_ok { $group->add_from_file() } qr/File to upload from not defined/, 'Check add_from_file function croaks without file';
throws_ok { $group->add_from_file(\$file) } qr/First CSV column must be the group ID, column heading must be "group". Found: ""./, 'Check add_from_file function croaks with blank file';
throws_ok { $group->add_from_file('/tmp/__non__--__tnetsixe__') } qr{Problem opening file: '/tmp/__non__--__tnetsixe__'}, 'Check add_from_file function croaks with non-existent file specified';
ok( my $group_config = Apache::Sling::Group->config($sling), 'check config function' );
ok( Apache::Sling::Group->run($sling,$group_config), 'check run function' );
throws_ok { Apache::Sling::Group->run() } qr/No group config supplied!/, 'check run function croaks with no config supplied';
t/Local/Apache-Sling-GroupMember.t view on Meta::CPAN
BEGIN { use_ok( 'Apache::Sling' ); }
BEGIN { use_ok( 'Apache::Sling::Authn' ); }
BEGIN { use_ok( 'Apache::Sling::GroupMember' ); }
# sling object:
my $sling = Apache::Sling->new();
isa_ok $sling, 'Apache::Sling', 'sling';
my $authn = new Apache::Sling::Authn(\$sling);
throws_ok { my $group_member = new Apache::Sling::GroupMember() } qr/no authn provided!/, 'Check creating group croaks without authn provided';
my $group_member = new Apache::Sling::GroupMember(\$authn,'1','log.txt');
ok( $group_member->{ 'BaseURL' } eq 'http://localhost:8080', 'Check BaseURL set' );
ok( $group_member->{ 'Log' } eq 'log.txt', 'Check Log set' );
ok( $group_member->{ 'Message' } eq '', 'Check Message set' );
ok( $group_member->{ 'Verbose' } == 1, 'Check Verbosity set' );
ok( defined $group_member->{ 'Authn' }, 'Check authn defined' );
ok( defined $group_member->{ 'Response' }, 'Check response defined' );
throws_ok { $group_member->add() } qr/No group name defined to add to!/, 'Check add function croaks without group specified';
throws_ok { $group_member->del() } qr/No group name defined to delete from!/, 'Check delete function croaks without group specified';
throws_ok { $group_member->check_exists() } qr/No group to view defined!/, 'Check exists function croaks without group specified';
throws_ok { $group_member->view() } qr/No group to view defined!/, 'Check view function croaks without group specified';
my $file = "\n";
throws_ok { $group_member->add_from_file() } qr/File to upload from not defined/, 'Check add_from_file function croaks without file';
throws_ok { $group_member->add_from_file(\$file) } qr/First CSV column must be the group ID, column heading must be "group". Found: ""./, 'Check add_from_file function croaks with blank file';
throws_ok { $group_member->add_from_file('/tmp/__non__--__tnetsixe__') } qr{Problem opening file: '/tmp/__non__--__tnetsixe__'}, 'Check add_from_file function croaks with non-existent file specified';
ok( my $group_member_config = Apache::Sling::GroupMember->config($sling), 'check config function' );
ok( Apache::Sling::GroupMember->run($sling,$group_member_config), 'check run function' );
throws_ok { Apache::Sling::GroupMember->run() } qr/No group_member config supplied!/, 'check run function croaks with no config supplied';
t/Local/Apache-Sling-GroupMemberUtil.t view on Meta::CPAN
ok(Apache::Sling::GroupMemberUtil::add_setup('http://localhost:8080','group','user') eq
"post http://localhost:8080/system/userManager/group/group.update.html \$post_variables = [':member','/system/userManager/user/user']",'Check add_setup function' );
ok(Apache::Sling::GroupMemberUtil::delete_setup('http://localhost:8080','group','user') eq
"post http://localhost:8080/system/userManager/group/group.update.html \$post_variables = [':member\@Delete','/system/userManager/user/user']",'Check delete_setup function' );
my $res = HTTP::Response->new( '200' );
ok( Apache::Sling::GroupMemberUtil::add_eval( \$res ), 'Check add_eval function' );
ok( ! Apache::Sling::GroupMemberUtil::delete_eval( \$res ), 'Check delete_eval function no content' );
$res->content("OK");
ok( Apache::Sling::GroupMemberUtil::delete_eval( \$res ), 'Check delete_eval function' );
throws_ok { Apache::Sling::GroupMemberUtil::add_setup() } qr/No base url defined to add against!/, 'Check add_setup function croaks without base_url specified';
throws_ok { Apache::Sling::GroupMemberUtil::add_setup('http://localhost:8080','group') } qr/Group addition detail missing!/, 'Check add_setup function croaks without add_member specified';
throws_ok { Apache::Sling::GroupMemberUtil::delete_setup() } qr/No base url defined to delete against!/, 'Check delete_setup function croaks without base_url specified';
throws_ok { Apache::Sling::GroupMemberUtil::delete_setup('http://localhost:8080') } qr/No group name defined to delete from!/, 'Check delete_setup function croaks without group specified';
throws_ok { Apache::Sling::GroupMemberUtil::delete_setup('http://localhost:8080','group') } qr/Group deletion detail missing!/, 'Check delete_setup function croaks without member specified';
t/Local/Apache-Sling-GroupUtil.t view on Meta::CPAN
"get http://localhost:8080/system/userManager/group/group.json", 'Check exists_setup function' );
ok(Apache::Sling::GroupUtil::view_setup('http://localhost:8080','group') eq
"get http://localhost:8080/system/userManager/group/group.tidy.json",'Check view_setup function' );
my $res = HTTP::Response->new( '200' );
ok( Apache::Sling::GroupUtil::add_eval( \$res ), 'Check add_eval function' );
ok( Apache::Sling::GroupUtil::delete_eval( \$res ), 'Check delete_eval function' );
ok( Apache::Sling::GroupUtil::exists_eval( \$res ), 'Check exists_eval function' );
ok( ! Apache::Sling::GroupUtil::view_eval( \$res ), 'Check view_eval function no content' );
$res->content("OK");
ok( Apache::Sling::GroupUtil::view_eval( \$res ), 'Check view_eval function' );
throws_ok { Apache::Sling::GroupUtil::add_setup() } qr/No base url defined to add against!/, 'Check add_setup function croaks without base_url specified';
throws_ok { Apache::Sling::GroupUtil::delete_setup() } qr/No base url defined to delete against!/, 'Check delte_setup function croaks without base_url specified';
throws_ok { Apache::Sling::GroupUtil::exists_setup() } qr/No base url to check existence against!/, 'Check exists_setup function croaks without base_url specified';
throws_ok { Apache::Sling::GroupUtil::view_setup() } qr/No base url to view with defined!/, 'Check view_setup function croaks without base_url specified';
throws_ok { Apache::Sling::GroupUtil::view_setup() } qr/No base url to view with defined!/, 'Check view_setup function croaks without base_url specified';
t/Local/Apache-Sling-JsonQueryServlet.t view on Meta::CPAN
BEGIN { use_ok( 'Apache::Sling' ); }
BEGIN { use_ok( 'Apache::Sling::Authn' ); }
BEGIN { use_ok( 'Apache::Sling::JsonQueryServlet' ); }
# sling object:
my $sling = Apache::Sling->new();
isa_ok $sling, 'Apache::Sling', 'sling';
my $authn = new Apache::Sling::Authn(\$sling);
throws_ok { my $json_query_servlet = new Apache::Sling::JsonQueryServlet() } qr/no authn provided!/, 'Check creating JsonQueryServlet croaks without authn provided';
my $json_query_servlet = new Apache::Sling::JsonQueryServlet(\$authn,'1','log.txt');
ok( $json_query_servlet->{ 'BaseURL' } eq 'http://localhost:8080', 'Check BaseURL set' );
ok( $json_query_servlet->{ 'Log' } eq 'log.txt', 'Check Log set' );
ok( $json_query_servlet->{ 'Message' } eq '', 'Check Message set' );
ok( $json_query_servlet->{ 'Verbose' } == 1, 'Check Verbosity set' );
ok( defined $json_query_servlet->{ 'Authn' }, 'Check authn defined' );
ok( defined $json_query_servlet->{ 'Response' }, 'Check response defined' );
$json_query_servlet->set_results( 'Test Message', undef );
ok( $json_query_servlet->{ 'Message' } eq 'Test Message', 'Message now set' );
ok( ! defined $json_query_servlet->{ 'Response' }, 'Check response no longer defined' );
ok( my $json_query_servlet_config = Apache::Sling::JsonQueryServlet->config($sling), 'check config function' );
ok( Apache::Sling::JsonQueryServlet->run($sling,$json_query_servlet_config), 'check run function' );
throws_ok { Apache::Sling::JsonQueryServlet->run() } qr/No json query servlet config supplied!/, 'check run function croaks with no config supplied';
t/Local/Apache-Sling-JsonQueryServletUtil.t view on Meta::CPAN
use warnings;
use Test::More tests => 5;
use Test::Exception;
BEGIN { use_ok( 'Apache::Sling::JsonQueryServletUtil' ); }
BEGIN { use_ok( 'HTTP::Response' ); }
my $res = HTTP::Response->new( '200' );
ok( Apache::Sling::JsonQueryServletUtil::all_nodes_setup( 'http://localhost:8080') eq
'get http://localhost:8080/content.query.json?queryType=xpath&statement=//*', 'Check all_nodes_setup function' );
throws_ok { Apache::Sling::JsonQueryServletUtil::all_nodes_setup() } qr/No base url defined!/, 'Check all_nodes_setup function croaks without base url';
ok( Apache::Sling::JsonQueryServletUtil::all_nodes_eval( \$res ), 'Check all_nodes_eval function' );
t/Local/Apache-Sling-LDAPSynch.t view on Meta::CPAN
use Test::More tests => 13;
use Test::Exception;
BEGIN { use_ok( 'Apache::Sling' ); }
BEGIN { use_ok( 'Apache::Sling::Authn' ); }
BEGIN { use_ok( 'Apache::Sling::LDAPSynch' ); }
# sling object:
my $sling = Apache::Sling->new();
isa_ok $sling, 'Apache::Sling', 'sling';
my $authn = new Apache::Sling::Authn(\$sling);
throws_ok { my $ldap_synch = new Apache::Sling::LDAPSynch() } qr/no authn provided!/, 'Check creating ldap_synch object croaks without authn';
my $ldap_synch = new Apache::Sling::LDAPSynch('','','','','',\$authn);
isa_ok $ldap_synch, 'Apache::Sling::LDAPSynch', 'ldap_synch';
ok( Apache::Sling::LDAPSynch::parse_attributes(), 'Check parse_attributes function without args' );
my $ldap_attrs = 'a,b';
my $sling_attrs = 'c,d';
my @ldap_attrs_array;
my @sling_attrs_array;
ok( Apache::Sling::LDAPSynch::parse_attributes($ldap_attrs, $sling_attrs, \@ldap_attrs_array, \@sling_attrs_array), 'Check parse_attributes function with args' );
$sling_attrs = 'c,d,e';
throws_ok { Apache::Sling::LDAPSynch::parse_attributes($ldap_attrs, $sling_attrs, \@ldap_attrs_array, \@sling_attrs_array) } qr/Number of ldap attributes must match number of sling attributes, 2 != 3/, 'Check parse_attributes function with mismatched...
ok( $ldap_synch->check_for_property_modifications(), 'Check check_for_property_modifications function' );
ok( my $ldap_synch_config = Apache::Sling::LDAPSynch->config($sling), 'check config function' );
ok( Apache::Sling::LDAPSynch->run($sling,$ldap_synch_config), 'check run function' );
throws_ok { Apache::Sling::LDAPSynch->run() } qr/No ldap_synch config supplied!/, 'check run function croaks with no config supplied';
t/Local/Apache-Sling-Print.t view on Meta::CPAN
BEGIN { use_ok( 'Apache::Sling' ); }
BEGIN { use_ok( 'Apache::Sling::Content' ); }
BEGIN { use_ok( 'Apache::Sling::Print' ); }
ok( Apache::Sling::Print::print_lock('Check print_lock function'), 'Check print_lock function' );
ok( Apache::Sling::Print::print_with_lock('Check print_with_lock function'), 'Check print_with_lock function' );
my ( $tmp_print_file_handle, $tmp_print_file_name ) = File::Temp::tempfile();
ok( Apache::Sling::Print::print_with_lock('Check print_with_lock function',$tmp_print_file_name), 'Check print_with_lock function to file' );
ok( Apache::Sling::Print::print_file_lock('Check print_file_lock function',$tmp_print_file_name), 'Check print_file_lock function' );
my $file;
throws_ok{ Apache::Sling::Print::print_with_lock('Check print_with_lock function',\$file); } qr%%, 'Check print_with_lock function to in memory file fails';
close $tmp_print_file_handle;
unlink($tmp_print_file_name);
ok( Apache::Sling::Print::date_time('Check date_time function'), 'Check date_time function' );
ok( Apache::Sling::Print::date_string(1, 1, 100, 1, 1, 1, 1), 'Check date_string function single figure units' );
ok( Apache::Sling::Print::date_string(1, 1, 100, 1, 1, 30, 30), 'Check date_string function double figure units' );
# sling object:
my $sling = Apache::Sling->new();
isa_ok $sling, 'Apache::Sling', 'sling';
my $authn = new Apache::Sling::Authn(\$sling);
t/Local/Apache-Sling-Request.t view on Meta::CPAN
use Test::More tests => 18;
use Test::Exception;
BEGIN { use_ok( 'Apache::Sling' ); }
BEGIN { use_ok( 'Apache::Sling::Request' ); }
BEGIN { use_ok( 'Apache::Sling::Content' ); }
my $sling = Apache::Sling->new();
my $authn = new Apache::Sling::Authn(\$sling);
my $content = new Apache::Sling::Content(\$authn,'1','log.txt');
throws_ok { Apache::Sling::Request::string_to_request() } qr/No string defined to turn into request!/, 'Checking string_to_request function string undefined';
throws_ok { Apache::Sling::Request::string_to_request('',\$authn) } qr/Error generating request for blank target!/, 'Checking string_to_request function blank string';
ok ( Apache::Sling::Request::string_to_request("post http://localhost:8080 \$post_variables = ['a','b']",\$authn), 'Checking string_to_request function for post action' );
ok ( Apache::Sling::Request::string_to_request("data http://localhost:8080 \$post_variables = ['a','b']",\$authn), 'Checking string_to_request function for data action' );
my ( $tmp_print_file_handle, $tmp_print_file_name ) = File::Temp::tempfile();
ok ( Apache::Sling::Request::string_to_request("fileupload http://localhost:8080 filename $tmp_print_file_name \$post_variables = []",\$authn), 'Checking string_to_request function for file upload action' );
throws_ok { Apache::Sling::Request::string_to_request("fileupload http://localhost:8080 filename $tmp_print_file_name \$post_variables = ['a',",\$authn) } qr//, 'Checking string_to_request function for fileupload action fails with broken post variabl...
unlink($tmp_print_file_name);
$authn->{'Username'} = 'user';
$authn->{'Password'} = 'pass';
ok ( Apache::Sling::Request::string_to_request("put http://localhost:8080",\$authn), 'Checking string_to_request function for put action' );
ok ( Apache::Sling::Request::string_to_request("delete http://localhost:8080",\$authn), 'Checking string_to_request function for delete action' );
$authn->{'Verbose'} = 2;
ok ( Apache::Sling::Request::string_to_request("get http://localhost:8080",\$authn), 'Checking string_to_request function for get action' );
throws_ok { Apache::Sling::Request::request(\$content,'') } qr/Error generating request for blank target!/, 'Checking request function blank string';
throws_ok { Apache::Sling::Request::request() } qr/No reference to a suitable object supplied!/, 'Check request function croaks without object';
throws_ok { Apache::Sling::Request::request(\$content) } qr/No string defined to turn into request!/, 'Check request function croaks without string';
throws_ok { Apache::Sling::Request::string_to_request("post http://localhost:8080 \$post_variables = ['a',",\$authn) } qr//, 'Checking string_to_request function for post action fails with broken post variables';
throws_ok { Apache::Sling::Request::string_to_request("data http://localhost:8080 \$post_variables = ['a',",\$authn) } qr//, 'Checking string_to_request function for data action fails with broken post variables';
$authn->{'LWP'} = undef;
throws_ok { Apache::Sling::Request::string_to_request("post http://localhost:8080 \$post_variables = ['a','b']",\$authn) } qr//, 'Checking string_to_request function for post action fails without LWP defined';
t/Local/Apache-Sling-User.t view on Meta::CPAN
ok( $user->{ 'Log' } eq 'log.txt', 'Check Log set' );
ok( $user->{ 'Message' } eq '', 'Check Message set' );
ok( $user->{ 'Verbose' } == 1, 'Check Verbosity set' );
ok( defined $user->{ 'Authn' }, 'Check authn defined' );
ok( defined $user->{ 'Response' }, 'Check response defined' );
$user->set_results( 'Test Message', undef );
ok( $user->{ 'Message' } eq 'Test Message', 'Message now set' );
ok( ! defined $user->{ 'Response' }, 'Check response no longer defined' );
throws_ok { $user->add() } qr/No user name defined to add!/, 'Check add function croaks without user specified';
throws_ok { $user->change_password() } qr/No user name defined to change password for!/, 'Check check_exists function croaks without user specified';
throws_ok { $user->check_exists() } qr/No user to check existence of defined!/, 'Check check_exists function croaks without user specified';
throws_ok { $user->del() } qr/No user name defined to delete!/, 'Check del function croaks without user specified';
throws_ok { $user->update() } qr/No user name defined to update!/, 'Check update function croaks without user specified';
throws_ok { $user->view() } qr/No user to check existence of defined!/, 'Check view function croaks without user specified';
my $file = "\n";
throws_ok { $user->add_from_file() } qr/File to upload from not defined/, 'Check add_from_file function croaks without file specified';
throws_ok { $user->add_from_file(\$file) } qr/First CSV column must be the user ID, column heading must be "user". Found: ""./, 'Check add_from_file function croaks with blank file';
throws_ok { $user->add_from_file('/tmp/__non__--__tnetsixe__') } qr{Problem opening file: '/tmp/__non__--__tnetsixe__'}, 'Check add_from_file function croaks with non-existent file specified';
ok( my $user_config = Apache::Sling::User->config($sling), 'check config function' );
ok( Apache::Sling::User->run($sling,$user_config), 'check run function' );
throws_ok { Apache::Sling::User->run() } qr/No user config supplied!/, 'check run function croaks with no config supplied';
t/Local/Apache-Sling-UserUtil.t view on Meta::CPAN
BEGIN { use_ok( 'HTTP::Response' ); }
my $res = HTTP::Response->new( '200' );
my @properties = '';
ok( Apache::Sling::UserUtil::add_setup( 'http://localhost:8080', 'user', 'pass', \@properties) eq
"post http://localhost:8080/system/userManager/user.create.html \$post_variables = [':name','user','pwd','pass','pwdConfirm','pass']", 'Check add_setup function' );
ok( Apache::Sling::UserUtil::update_setup('http://localhost:8080','user',\@properties ) eq "post http://localhost:8080/system/userManager/user/user.update.html \$post_variables = []", 'Check update_setup function without any properties' );
push @properties, 'a=b';
ok( Apache::Sling::UserUtil::add_setup( 'http://localhost:8080', 'user', 'pass', \@properties) eq
"post http://localhost:8080/system/userManager/user.create.html \$post_variables = [':name','user','pwd','pass','pwdConfirm','pass','a','b']", 'Check add_setup function with properties' );
throws_ok { Apache::Sling::UserUtil::add_setup() } qr/No base url defined to add against!/, 'Check add_setup function croaks without base url';
throws_ok { Apache::Sling::UserUtil::add_setup('http://localhost:8080') } qr/No user name defined to add!/, 'Check add_setup function croaks without act_on_user';
throws_ok { Apache::Sling::UserUtil::add_setup('http://localhost:8080','testuser') } qr/No user password defined to add for user testuser!/, 'Check add_setup function croaks without act_on_pass';
ok( Apache::Sling::UserUtil::add_eval( \$res ), 'Check add_eval function' );
ok( Apache::Sling::UserUtil::change_password_setup( 'http://localhost:8080', 'user', 'pass1', 'pass2', 'pass2' ) eq
"post http://localhost:8080/system/userManager/user/user.changePassword.html \$post_variables = ['oldPwd','pass1','newPwd','pass2','newPwdConfirm','pass2']", 'Check change_password_setup function' );
throws_ok { Apache::Sling::UserUtil::change_password_setup() } qr/No base url defined!/, 'Check change_password_setup function croaks without base url';
throws_ok { Apache::Sling::UserUtil::change_password_setup('http://localhost:8080') } qr/No user name defined to change password for!/, 'Check change_password_setup function croaks without act_on_user';
throws_ok { Apache::Sling::UserUtil::change_password_setup('http://localhost:8080','user') } qr/No current password defined for user!/, 'Check change_password_setup function croaks without act_on_pass';
throws_ok { Apache::Sling::UserUtil::change_password_setup('http://localhost:8080','user','pass') } qr/No new password defined for user!/, 'Check change_password_setup function croaks without new_pass';
throws_ok { Apache::Sling::UserUtil::change_password_setup('http://localhost:8080','user','pass1','pass2') } qr/No confirmation of new password defined for user!/, 'Check change_password_setup function croaks without new_pass_confirm';
ok( Apache::Sling::UserUtil::change_password_eval( \$res ), 'Check change_password_eval function' );
ok( Apache::Sling::UserUtil::delete_setup( 'http://localhost:8080', 'user' ) eq
"post http://localhost:8080/system/userManager/user/user.delete.html \$post_variables = []", 'Check delete_setup function' );
throws_ok { Apache::Sling::UserUtil::delete_setup('http://localhost:8080') } qr/No user name defined to delete!/, 'Check delete_setup function croaks without user to delete specified';
throws_ok { Apache::Sling::UserUtil::delete_setup() } qr/No base url defined to delete against!/, 'Check delete_setup function croaks without base URL specified';
ok( Apache::Sling::UserUtil::delete_eval( \$res ), 'Check delete_eval function' );
ok( Apache::Sling::UserUtil::exists_setup( 'http://localhost:8080', 'user' ) eq
"get http://localhost:8080/system/userManager/user/user.tidy.json", 'Check exists_setup function' );
throws_ok { Apache::Sling::UserUtil::exists_setup() } qr/No base url to check existence against!/, 'Check exists_setup function croaks without base URL specified';
ok( Apache::Sling::UserUtil::exists_eval( \$res ), 'Check exists_eval function' );
ok( Apache::Sling::UserUtil::update_setup( 'http://localhost:8080','user',\@properties ) eq "post http://localhost:8080/system/userManager/user/user.update.html \$post_variables = ['a','b']", 'Check update_setup function' );
throws_ok { Apache::Sling::UserUtil::update_setup() } qr/No base url defined to update against!/, 'Check update_setup function croaks without base URL specified';
ok( Apache::Sling::UserUtil::exists_eval( \$res ), 'Check exists_eval function' );
ok( Apache::Sling::UserUtil::update_eval( \$res ), 'Check update_eval function' );