File: errors.t

package info (click to toggle)
libsession-storage-secure-perl 1.000-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 228 kB
  • sloc: perl: 345; makefile: 2
file content (67 lines) | stat: -rw-r--r-- 1,494 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
use 5.008001;
use strict;
use warnings;
use Test::More 0.96;
use Test::Fatal;

use Session::Storage::Secure;

my $data = {
    foo => 'bar',
    baz => 'bam',
};

my $secret = "serenade viscount secretary frail";

sub _gen_store {
    my ($config) = @_;
    local $Test::Builder::Level = $Test::Builder::Level + 1;
    my $store = Session::Storage::Secure->new(
        secret_key => $secret,
        %{ $config || {} },
    );
    ok( $store, "created a storage object" );
    return $store;
}

sub _replace {
    my ( $string, $index, $value ) = @_;
    my @parts = split qr/~/, $string;
    $parts[$index] = $value;
    return join "~", @parts;
}

subtest "bad data" => sub {
    my $store = _gen_store;
    like(
        exception { $store->encode( { foo => bless {} } ) },
        qr/Encoding error/,
        "Invalid data throws encoding error",
    );
};

subtest "bad protocol version" => sub {
    for my $pv ( -1, 0, 3 ) {
        like(
            exception {
                Session::Storage::Secure->new(
                    secret_key       => $secret,
                    protocol_version => $pv,
                )
            },
            qr/Invalid protocol version for encoding/,
            "Invalid protocol_version $pv throws error",
        );
    }
};

done_testing;
#
# This file is part of Session-Storage-Secure
#
# This software is Copyright (c) 2013 by David Golden.
#
# This is free software, licensed under:
#
#   The Apache License, Version 2.0, January 2004
#