# Test Script for Bug 29900 # based off https://wiki.koha-community.org/wiki/REST_API:_Checking_username_and_password # # Change API_USERNAME and API_PASSWORD to your test "apibasic" user's koha username and password. # # See bottom for expected output of a successful validation # run the script on your KTD or koha installation using #>perl api_basic_test.pl use Modern::Perl; use LWP::UserAgent; use HTTP::Request::Common; use JSON; use Data::Dumper; $Data::Dumper::Sortkeys = 1; my $domain = 'localhost:8080'; my $username = 'API_USERNAME'; #CHANGE ME my $password = 'API_PASSWORD'; #CHANGE ME my %data = ( 'userid' => 'koha', 'password' => 'koha', ); my $ua = LWP::UserAgent->new(); my $request = HTTP::Request::Common::POST( "http://$domain/api/v1/auth/password/validation", Content_Type => 'application/json', Content => to_json( \%data ) ); $request->authorization_basic( $username, $password ); say Dumper $request; my $response = $ua->request($request); say $response->as_string(); # Expected output for successful validation# # # # $VAR1 = bless( { # '_content' => '{"password":"koha","userid":"koha"}', # '_headers' => bless( { # 'authorization' => 'Basic YXBpYmFzaWM6QWJjZDEyMzQ=', # 'content-length' => 35, # 'content-type' => 'application/json' # }, 'HTTP::Headers' ), # '_max_body_size' => undef, # '_method' => 'POST', # '_uri' => bless( do{\(my $o = 'http://localhost:8080/api/v1/auth/password/validation')}, 'URI::http' ) # }, 'HTTP::Request' ); # # HTTP/1.1 201 Created # Connection: close # Date: Tue, 19 Aug 2025 20:48:01 GMT # Server: Apache/2.4.62 (Debian) # Vary: User-Agent # ontent-Length: 50 # Content-Type: application/json;charset=UTF-8 # Client-Date: Tue, 19 Aug 2025 20:48:01 GMT # Client-Peer: 127.0.0.1:8080 # lient-Response-Num: 1 # # {"cardnumber":"42","patron_id":51,"userid":"koha"}