summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/v1.erl12
-rw-r--r--test/ctls_test.erl17
2 files changed, 26 insertions, 3 deletions
diff --git a/src/v1.erl b/src/v1.erl
index 8948d1d..73f7c28 100644
--- a/src/v1.erl
+++ b/src/v1.erl
@@ -28,7 +28,17 @@ add_pre_chain(SessionID, _Env, _Input) ->
niy(SessionID).
get_sth(SessionID, _Env, _Input) ->
- niy(SessionID).
+ #sth{
+ treesize = Treesize,
+ timestamp = Timestamp,
+ roothash = Roothash,
+ signature = Signature} = plop:sth(),
+ R = [{treesize, Treesize},
+ {timestamp, Timestamp},
+ {sha256_root_hash, base64:encode(Roothash)},
+ {tree_head_signature, base64:encode(Signature)}],
+ mod_esi:deliver(SessionID, binary_to_list(jiffy:encode({R}))).
+
get_sth_consistency(SessionID, _Env, _Input) ->
niy(SessionID).
get_proof_by_hash(SessionID, _Env, _Input) ->
diff --git a/test/ctls_test.erl b/test/ctls_test.erl
index d859b6e..bd477de 100644
--- a/test/ctls_test.erl
+++ b/test/ctls_test.erl
@@ -4,12 +4,13 @@
%% Requires that ctls is running (or, at the moment, that v1 has been
%% installed as an mod_esi module -- use https_server:start()).
+-define(URL, "https://flimsytest:8080/ct/v1/add_chain").
+
add_chain_test_() ->
{setup,
fun() ->
- Url = "https://flimsytest:8080/ct/v1/add_chain",
Input = "{\"chain\": [\"some test data\"]}",
- {OK, {{_, RC, _}, _, _}} = httpc:request(post, {Url, [], [], Input}, [], []),
+ {OK, {{_, RC, _}, _, _}} = httpc:request(post, {?URL, [], [], Input}, [], []),
%% TODO: Verify signature.
{OK, RC}
end,
@@ -18,3 +19,15 @@ add_chain_test_() ->
[?_assertEqual(ok, OK),
?_assertEqual(RC, 200)]
end}.
+
+add_sth_test_() ->
+ {setup,
+ fun() ->
+ {OK, {{_, RC, _}, _, _}} = httpc:request(get, {?URL, []}, [], []),
+ {OK, RC}
+ end,
+ fun(_) -> ok end,
+ fun({OK, RC}) ->
+ [?_assertEqual(ok, OK),
+ ?_assertEqual(RC, 200)]
+ end}.