File: open_pgp.t

package info (click to toggle)
libdbix-class-encodedcolumn-perl 0.00020-3
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 268 kB
  • sloc: perl: 618; sql: 48; makefile: 2
file content (64 lines) | stat: -rw-r--r-- 1,925 bytes parent folder | download | duplicates (4)
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
use strict;
use warnings;
use Test::More;

use Dir::Self;
use File::Spec;
use File::Temp 'tempdir';
use lib File::Spec->catdir(__DIR__, 'lib');
use DigestTest::Schema;

BEGIN {
  my $math_pari = $ENV{'NO_MATH_PARI'} ? 1 : eval 'require Math::Pari';
  if( eval 'require Crypt::OpenPGP' && $math_pari ){
    plan tests => 8;
  } else {
    plan skip_all => 'Crypt::OpenPGP not available';
    exit;
  }
}

#1
DigestTest::Schema->load_classes('PGP');

my $tmp = tempdir( CLEANUP => 1 );
my $db_file = File::Spec->catfile($tmp, 'testdb.sqlite');
my $schema = DigestTest::Schema->connect("dbi:SQLite:dbname=${db_file}");
$schema->deploy({}, File::Spec->catdir(__DIR__, 'var'));

my $row = $schema->resultset('PGP')->create( {
  dummy_col           => 'Dummy Column',
  pgp_col_passphrase  => 'Test Encrypted Column with Passphrase',
  pgp_col_key         => 'Test Encrypted Column with Key Exchange',
  pgp_col_key_ps      => 'Test Encrypted Column with Key Exchange + Pass',
  pgp_col_rijndael256 => 'Test Encrypted Column with Rijndael256 Cipher',
} );

like($row->pgp_col_passphrase, qr/BEGIN PGP MESSAGE/, 'Passphrase encrypted');
like($row->pgp_col_key, qr/BEGIN PGP MESSAGE/, 'Key encrypted');
like($row->pgp_col_key_ps, qr/BEGIN PGP MESSAGE/, 'Key+Passphrase encrypted');
like($row->pgp_col_rijndael256, qr/BEGIN PGP MESSAGE/, 'Rijndael encrypted');

is(
  $row->decrypt_pgp_passphrase('Secret Words'),
  'Test Encrypted Column with Passphrase',
  'Passphrase decryption/encryption'
);

is(
  $row->decrypt_pgp_key,
  'Test Encrypted Column with Key Exchange',
  'Key Exchange decryption/encryption'
);

is(
  $row->decrypt_pgp_key_ps('Secret Words'),
  'Test Encrypted Column with Key Exchange + Pass',
  'Secured Key Exchange decryption/encryption'
);

is(
  $row->decrypt_pgp_rijndael256('Secret Words'),
  'Test Encrypted Column with Rijndael256 Cipher',
  'Passphrase decryption/encryption with Rijndael256 Cipher'
);