File: 03_dbi.t

package info (click to toggle)
libcrypt-mysql-perl 0.04-7
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid, trixie
  • size: 116 kB
  • sloc: perl: 20; makefile: 2
file content (43 lines) | stat: -rw-r--r-- 929 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
use strict;
use Test::More;

use Crypt::MySQL ();

unless (eval { require DBD::mysql } && eval { require DBI }) {
    plan skip_all => "no DBD::mysql";
}
else {
    plan tests => 1;
}

SKIP: {
    my $dbh = eval { 
        DBI->connect("dbi:mysql:test", "root", "", {
            RaiseError => 1, PrintError => 1
        });
    };
    skip "could not connect to MySQL", 1 unless $dbh;

    my $tm = time. "";
    
    my $sth = $dbh->prepare("SELECT PASSWORD(?)");
    $sth->execute($tm);
    my($real_mysql) = $sth->fetchrow_array;
    $sth->finish;
    
    my $sth2 = $dbh->prepare('SELECT VERSION()');
    $sth2->execute;
    my($verstr) = $sth2->fetchrow_array;
    $sth2->finish;
    
    $dbh->disconnect;

    my($ver) = $verstr =~ m/^([0-9]+\.[0-9]+)/;
    
    if ($ver >= 4.1) {
        is($real_mysql, Crypt::MySQL::password41($tm));
    }
    else {
        is($real_mysql, Crypt::MySQL::password($tm));  
    } 
}