]> Dogcows Code - chaz/p5-File-KDBX/blob - t/safe.t
add initial WIP
[chaz/p5-File-KDBX] / t / safe.t
1 #!/usr/bin/env perl
2
3 use utf8;
4 use warnings;
5 use strict;
6
7 use lib 't/lib';
8 use TestCommon;
9
10 use Test::Deep;
11 use Test::More;
12
13 BEGIN { use_ok 'File::KDBX::Safe' }
14
15 my $secret = 'secret';
16
17 my @strings = (
18 {
19 value => 'classified',
20 },
21 {
22 value => 'bar',
23 meh => 'ignored',
24 },
25 {
26 value => '你好',
27 },
28 );
29
30 my $safe = File::KDBX::Safe->new([@strings, \$secret]);
31 cmp_deeply \@strings, [
32 {
33 value => undef,
34 },
35 {
36 value => undef,
37 meh => 'ignored',
38 },
39 {
40 value => undef,
41 },
42 ], 'Encrypt strings in a safe' or diag explain \@strings;
43 is $secret, undef, 'Scalar was set to undef';
44
45 my $val = $safe->peek($strings[1]);
46 is $val, 'bar', 'Peek at a string';
47
48 $safe->unlock;
49 cmp_deeply \@strings, [
50 {
51 value => 'classified',
52 },
53 {
54 value => 'bar',
55 meh => 'ignored',
56 },
57 {
58 value => '你好',
59 },
60 ], 'Decrypt strings in a safe' or diag explain \@strings;
61 is $secret, 'secret', 'Scalar was set back to secret';
62
63 done_testing;
This page took 0.033574 seconds and 4 git commands to generate.