From 92056f41392f3efef9a57b6a56cb3788b1969a21 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Tue, 21 Dec 2010 13:22:37 -0600 Subject: basic test --- t/01-basic.t | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 t/01-basic.t 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; -- cgit v1.2.3-54-g00ecf