+ test disable auditor
This commit is contained in:
parent
05cfa7a5b1
commit
f3c6424ec9
8 changed files with 90 additions and 73 deletions
|
|
@ -153,24 +153,22 @@ module Auditors = struct
|
|||
h_auditor_url= Hash.Cstring.H64.hash auditor_url;
|
||||
}
|
||||
|
||||
(* TODO monotonic time *)
|
||||
let do_ ~db_conn v =
|
||||
let auditor_pub = v.AuditorSetupMessage.auditor_pub in
|
||||
let validity_start = v.AuditorSetupMessage.validity_start in
|
||||
let* last_date_opt =
|
||||
Pg.get_auditor_timestamp db_conn auditor_pub |> unwrap_err_caqti
|
||||
in
|
||||
match last_date_opt with
|
||||
let* opt = Pg.find_auditor db_conn auditor_pub |> unwrap_err_caqti in
|
||||
match opt with
|
||||
| None ->
|
||||
let+ () = Pg.insert_auditor db_conn v |> unwrap_err_caqti in
|
||||
let auditor = Auditor.of_setup_message v in
|
||||
let+ () = Pg.update_auditor db_conn auditor |> unwrap_err_caqti in
|
||||
Logs.info (fun m -> m "enabled auditor");
|
||||
()
|
||||
| Some last_date ->
|
||||
if Timestamp.compare last_date validity_start > 0 then
|
||||
| Some auditor ->
|
||||
if Timestamp.compare auditor.last_change validity_start > 0 then
|
||||
Error
|
||||
"database has more recent auditor data for this auditor public key"
|
||||
else
|
||||
let+ () = Pg.update_auditor db_conn v |> unwrap_err_caqti in
|
||||
let+ () = Pg.update_auditor db_conn auditor |> unwrap_err_caqti in
|
||||
Logs.info (fun m -> m "updated auditor");
|
||||
()
|
||||
|
||||
|
|
@ -198,26 +196,36 @@ module Auditors_disable = struct
|
|||
|
||||
let do_ ~db_conn auditor_pub
|
||||
AuditorTeardownMessage.{ master_sig= _; validity_end } =
|
||||
let* last_date_opt =
|
||||
Pg.get_auditor_timestamp db_conn auditor_pub |> unwrap_err_caqti
|
||||
in
|
||||
match last_date_opt with
|
||||
let* opt = Pg.find_auditor db_conn auditor_pub |> unwrap_err_caqti in
|
||||
match opt with
|
||||
| None -> Error "auditor not found"
|
||||
| Some last_date ->
|
||||
if Timestamp.compare last_date validity_end > 0 then
|
||||
Error
|
||||
"database has more recent auditor data for this auditor public key"
|
||||
else
|
||||
let+ () =
|
||||
Pg.disable_auditor db_conn ~auditor_pub ~change_date:validity_end
|
||||
|> unwrap_err_caqti
|
||||
in
|
||||
()
|
||||
| Some auditor -> (
|
||||
match Timestamp.compare auditor.last_change validity_end > 0 with
|
||||
| true ->
|
||||
Error
|
||||
"database has more recent auditor data for this auditor public \
|
||||
key"
|
||||
| false -> (
|
||||
match auditor.is_active with
|
||||
| false ->
|
||||
Logs.info (fun m -> m "auditor was already revoked");
|
||||
Ok ()
|
||||
| true ->
|
||||
let auditor =
|
||||
{ auditor with last_change= validity_end; is_active= false }
|
||||
in
|
||||
let+ () =
|
||||
Pg.update_auditor db_conn auditor |> unwrap_err_caqti
|
||||
in
|
||||
Logs.info (fun m ->
|
||||
m "revoked auditor `%s`"
|
||||
(Crypto.EddsaPublicKey.to_b32 auditor_pub));
|
||||
()))
|
||||
|
||||
let jsont = AuditorTeardownMessage.jsont
|
||||
|
||||
let f req auditor_pub server _env =
|
||||
Logs.info (fun m -> m "POST /management/auditors/$AUDITOR_PUB/revoke/");
|
||||
Logs.info (fun m -> m "POST /management/auditors/$AUDITOR_PUB/disable/");
|
||||
let keys = Vif.Server.device Devices.keys server in
|
||||
let db_conn = Vif.Server.device Devices.db_connection server in
|
||||
let res =
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue