]> Dogcows Code - chaz/p5-File-KDBX/blob - t/safe.t
Add key file saving and refactor some stuff
[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 File::KDBX::Safe;
11 use Test::Deep;
12 use Test::More;
13
14 my $secret = 'secret';
15
16 my @strings = (
17 {
18 value => 'classified',
19 },
20 {
21 value => 'bar',
22 meh => 'ignored',
23 },
24 {
25 value => '你好',
26 },
27 );
28
29 my $safe = File::KDBX::Safe->new([@strings, \$secret]);
30 cmp_deeply \@strings, [
31 {
32 value => undef,
33 },
34 {
35 value => undef,
36 meh => 'ignored',
37 },
38 {
39 value => undef,
40 },
41 ], 'Encrypt strings in a safe' or diag explain \@strings;
42 is $secret, undef, 'Scalar was set to undef';
43
44 my $val = $safe->peek($strings[1]);
45 is $val, 'bar', 'Peek at a string';
46
47 $safe->unlock;
48 cmp_deeply \@strings, [
49 {
50 value => 'classified',
51 },
52 {
53 value => 'bar',
54 meh => 'ignored',
55 },
56 {
57 value => '你好',
58 },
59 ], 'Decrypt strings in a safe' or diag explain \@strings;
60 is $secret, 'secret', 'Scalar was set back to secret';
61
62 done_testing;
This page took 0.03647 seconds and 4 git commands to generate.