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
73
74
|
-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."
%% FIXME: This way, if a test fails, we don't stop plop. The tests
%% must run and be validated in strict order though.
adding_verifying_test() ->
%%Pid = start(),
Pubkey = plop:testing_get_pubkey(),
add(0, Pubkey),
add(1, Pubkey),
sth(0, Pubkey).
%%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(0, Pubkey) ->
Msg = <<"some data">>,
Entry = #timestamped_entry{timestamp = 4711,
entry = #plop_entry{type = test,
data = Msg}},
SPT = plop:add(Entry),
<<Version:8, _LogID:256, Timestamp:64, Signature/binary>> = SPT,
Signed = <<1:8, 0:8, 4711:64, 2:16, Msg/binary>>,
?assertEqual(1, Version),
?assertEqual(4711, Timestamp),
?assert(public_key:verify(Signed, sha256, Signature, Pubkey));
add(1, Pubkey) ->
Msg = <<"some more data">>,
Entry = #timestamped_entry{timestamp = 4712,
entry = #plop_entry{type = test,
data = Msg}},
<<Version:8, _LogID:256, Timestamp:64, Signature/binary>> = plop:add(Entry),
Signed = <<1:8, 0:8, 4712:64, 2:16, Msg/binary>>,
?assertEqual(1, Version),
?assertEqual(4712, Timestamp),
?assert(public_key:verify(Signed, sha256, Signature, Pubkey)).
%% add(2) ->
%% TestVector = <<>>,
%% %% Same data as in 0, should not result in new database entry.
%% Entry = #timestamped_entry{timestamp = 4713, entry_type = test, entry = <<"some data">>},
%% SPT = plop:add(#spt{signature_type = test, entry = Entry}),
%% ?assertEqual(TestVector, SPT),
%% ?assertEqual(fixme, fixme).
sth(0, Pubkey) ->
STH = plop:sth(),
%%io:format(element(2, file:open("testdata", write)), "~p", [STH]),
<<Treesize:64,
Timestamp:64,
Roothash:256,
Signature/binary>> = STH,
?assertEqual(2, Treesize),
Data = <<1:8, 1:8, Timestamp:64, Treesize:64, Roothash:256>>,
?assert(public_key:verify(Data, sha256, Signature, Pubkey)).
|