summaryrefslogtreecommitdiff
path: root/src/test/plop_test.erl
blob: 87329c62a9face48a82d252cf4dc3f80c68dafbd (plain)
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
68
69
70
71
72
-module(plop_test).
-include("plop.hrl").
-include_lib("eunit/include/eunit.hrl").

start_stop_test_() ->
    {"The server can be started, stopped and is regsitered",
     {setup, fun start/0, fun stop/1, fun is_registered/1}}.

%% "Entries can be added and the STH changes."
adding_verifying_test() ->
    Pid = start(),
    add(),
    sth(),
    %% TODO: add one more and verify that the STH changes
    %% add(),
    %% sth(),
    stop(Pid).
     
%%% Setup.
start() ->
    {ok, Pid} = plop:start_link("test/rsakey.pem", "sikrit"),
    Pid.

stop(_) ->
    plop:stop().

%%% Tests.
is_registered(Pid) ->
    [?_assert(erlang:is_process_alive(Pid)),
     ?_assertEqual(Pid, whereis(plop))].

%%% Helpers.
add() ->
    TestVector =
        <<1,247,141,118,3,148,171,128,29,143,106,97,200,179,204,166,242,98,70,185,231,
          78,193,39,12,245,82,254,230,136,69,69,0,0,0,0,0,0,0,18,103,69,73,8,105,107,
          47,97,130,137,92,201,148,11,68,203,103,216,217,249,38,109,208,23,55,107,21,
          110,128,207,151,46,4,178,228,74,5,247,64,180,85,122,236,127,97,226,50,124,
          212,251,227,65,248,18,36,124,252,103,24,35,99,180,207,126,63,116,149,21,86,
          255,197,248,212,93,100,123,161,159,94,29,112,23,246,98,3,124,89,135,234,71,
          246,21,93,152,214,209,58,25,52,132,219,22,0,38,237,226,118,1,168,86,218,18,
          112,227,11,25,199,15,151,246,253,7,91,72,88,169,164,79,143,160,157,241,168,
          15,230,1,216,93,67,24,230,106,203,61,115,100,172,238,165,236,198,222,33,126,
          12,163,226,165,161,232,106,39,94,93,247,2,164,163,72,34,236,228,168,53,19,
          128,111,78,34,54,166,95,78,11,131,241,191,254,82,225,72,68,111,229,169,24,75,
          90,254,167,119,10,136,211,20,178,251,244,124,87,223,61,102,244,143,98,213,59,
          217,84,80,64,22,209,1,63,64,185,63,13,115,43,36,143,93,19,206,234,100,181,
          203,214,189,144,145,21,247,165,125,192,43,94,247,209,81,50,100>>,
    Entry = #plop_entry{type = test, data = <<"some data">>},
    SPT = #spt{signature_type = test, timestamp = 4711, entry = Entry},
    ?assertEqual(TestVector, plop:add(SPT)).

sth() ->
    TestVector =
        <<0,0,0,0,0,0,0,1,0,0,0,0,0,0,18,103,93,90,159,157,211,129,96,54,161,145,226,
          218,28,127,43,87,221,243,153,101,255,249,156,114,234,50,84,163,183,64,215,
          227,16,126,61,255,54,243,5,185,250,149,18,30,228,16,48,168,252,213,27,205,
          254,157,72,230,112,65,150,187,18,215,17,249,72,18,38,159,217,49,159,177,153,
          175,86,139,158,29,24,202,126,203,88,216,19,205,237,172,48,9,113,228,231,170,
          131,38,155,185,188,232,215,15,54,93,254,173,100,13,115,172,161,7,106,226,180,
          168,81,245,47,10,59,14,25,26,23,80,11,227,147,115,216,173,93,63,232,50,213,
          43,148,71,149,104,32,10,217,108,182,194,88,12,153,187,42,190,154,203,114,200,
          24,137,106,65,51,25,162,178,24,199,155,215,208,115,5,239,64,189,69,0,196,55,
          211,91,12,83,132,131,84,92,146,124,125,117,74,62,7,162,230,37,13,45,122,183,
          112,207,227,240,152,190,181,168,96,210,252,59,144,12,141,46,18,18,51,226,14,
          218,17,255,212,136,198,154,69,64,232,234,249,2,232,45,165,206,157,195,77,254,
          126,173,10,12,184,21,55,111,183,15,2,251,177,220,139,35,20,148,219,137,78,
          187,221,242,23,254,196,182,98,110,150,95,126,53,42,243,123,198,30,247,79,17,
          172,129>>,
    STH = plop:sth(#sth{timestamp = 4711}),
    %%io:format(element(2, file:open("foo", write)), "~p", [STH]),
    ?assertEqual(TestVector, STH).