]> Dogcows Code - chaz/p5-File-KDBX/blobdiff - t/safe.t
add initial WIP
[chaz/p5-File-KDBX] / t / safe.t
diff --git a/t/safe.t b/t/safe.t
new file mode 100644 (file)
index 0000000..79d8e4c
--- /dev/null
+++ b/t/safe.t
@@ -0,0 +1,63 @@
+#!/usr/bin/env perl
+
+use utf8;
+use warnings;
+use strict;
+
+use lib 't/lib';
+use TestCommon;
+
+use Test::Deep;
+use Test::More;
+
+BEGIN { use_ok 'File::KDBX::Safe' }
+
+my $secret = 'secret';
+
+my @strings = (
+    {
+        value => 'classified',
+    },
+    {
+        value => 'bar',
+        meh   => 'ignored',
+    },
+    {
+        value => '你好',
+    },
+);
+
+my $safe = File::KDBX::Safe->new([@strings, \$secret]);
+cmp_deeply \@strings, [
+    {
+        value => undef,
+    },
+    {
+        value => undef,
+        meh   => 'ignored',
+    },
+    {
+        value => undef,
+    },
+], 'Encrypt strings in a safe' or diag explain \@strings;
+is $secret, undef, 'Scalar was set to undef';
+
+my $val = $safe->peek($strings[1]);
+is $val, 'bar', 'Peek at a string';
+
+$safe->unlock;
+cmp_deeply \@strings, [
+    {
+        value => 'classified',
+    },
+    {
+        value => 'bar',
+        meh   => 'ignored',
+    },
+    {
+        value => '你好',
+    },
+], 'Decrypt strings in a safe' or diag explain \@strings;
+is $secret, 'secret', 'Scalar was set back to secret';
+
+done_testing;
This page took 0.021823 seconds and 4 git commands to generate.