summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2010-12-21 13:22:37 -0600
committerJesse Luehrs <doy@tozt.net>2010-12-21 13:22:37 -0600
commit92056f41392f3efef9a57b6a56cb3788b1969a21 (patch)
tree6c29315bbb72e27ad2f48207c17b9053e3a12dae
parentfe4c6e3e5b0875cc287eceb701ef751f3511dc6b (diff)
downloadkiokudb-serializer-crypt-92056f41392f3efef9a57b6a56cb3788b1969a21.tar.gz
kiokudb-serializer-crypt-92056f41392f3efef9a57b6a56cb3788b1969a21.zip
basic test
-rw-r--r--t/01-basic.t55
1 files changed, 55 insertions, 0 deletions
diff --git a/t/01-basic.t b/t/01-basic.t
new file mode 100644
index 0000000..5a36839
--- /dev/null
+++ b/t/01-basic.t
@@ -0,0 +1,55 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+use Test::More;
+use Test::Requires 'Crypt::Rijndael';
+use Test::Requires 'Crypt::CFB';
+use Test::Requires 'JSON';
+
+use Crypt::Util;
+use KiokuDB;
+use KiokuDB::Util;
+use KiokuDB::Serializer::Crypt;
+
+{
+ my $backend = KiokuDB::Backend::Hash->new(
+ serializer => KiokuDB::Serializer::Crypt->new(
+ crypt_key => 's3cr3t',
+ serializer => 'json',
+ ),
+ );
+ my $d = KiokuDB->new(backend => $backend);
+
+ {
+ my $s = $d->new_scope;
+ my $foo = Moose::Meta::Class->create('Foo')->new_object;
+ $d->insert(foo => $foo);
+ }
+
+ {
+ my $storage = $d->backend->storage;
+ my $serialized_foo = $storage->{foo};
+
+ my $crypt = Crypt::Util->new(default_key => 's3cr3t');
+ my $decrypted = $crypt->decrypt_string($serialized_foo);
+ my $data = JSON->new->decode($decrypted);
+ is_deeply(
+ $data,
+ {
+ __CLASS__ => 'Foo',
+ root => 'true',
+ id => 'foo',
+ data => {},
+ },
+ "encrypted properly"
+ );
+ }
+
+ {
+ my $s = $d->new_scope;
+ my $foo = $d->lookup('foo');
+ isa_ok($foo, 'Foo');
+ }
+}
+
+done_testing;