+ test disable-auditor/wire/drain
This commit is contained in:
parent
c04fda0f1e
commit
7c989e590a
9 changed files with 386 additions and 193 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 =
|
||||
|
|
@ -367,22 +375,37 @@ module Wire = struct
|
|||
payto_uri;
|
||||
master_sig_wire;
|
||||
master_sig_add;
|
||||
conversion_url;
|
||||
credit_restrictions;
|
||||
debit_restrictions;
|
||||
validity_start;
|
||||
bank_label= _;
|
||||
priority= _;
|
||||
} =
|
||||
(* TODO are those read from payto_uri? *)
|
||||
let conversion_url = "" in
|
||||
let credit_restrictions = "" in
|
||||
let debit_restrictions = "" in
|
||||
(* TODO wire
|
||||
hash over json, hash over string option? *)
|
||||
let* () =
|
||||
match (credit_restrictions, debit_restrictions) with
|
||||
| [], [] -> Ok ()
|
||||
| _ ->
|
||||
Fmt.error
|
||||
"wire setup: credit_restrictions and debit_restrictions are not \
|
||||
supported"
|
||||
in
|
||||
let h_wire_details = Hash.FullPaytoHash.hash payto_uri in
|
||||
let h_conversion_url =
|
||||
Hash.Cstring.H64.hash ((* ?? *) Option.value ~default:"" conversion_url)
|
||||
in
|
||||
let h_credit_restrictions = Hash.Cstring.H64.hash "" in
|
||||
let h_debit_restrictions = Hash.Cstring.H64.hash "" in
|
||||
let* () =
|
||||
let open Signatures.MasterWireDetails in
|
||||
verify Config.master_public_key master_sig_wire
|
||||
{
|
||||
h_wire_details= FullPaytoHash.hash payto_uri;
|
||||
h_conversion_url= Hash.Cstring.H64.hash conversion_url;
|
||||
h_credit_restrictions= Hash.Cstring.H64.hash credit_restrictions;
|
||||
h_debit_restrictions= Hash.Cstring.H64.hash debit_restrictions;
|
||||
h_wire_details;
|
||||
h_conversion_url;
|
||||
h_credit_restrictions;
|
||||
h_debit_restrictions;
|
||||
}
|
||||
in
|
||||
let* () =
|
||||
|
|
@ -390,38 +413,56 @@ module Wire = struct
|
|||
verify Config.master_public_key master_sig_add
|
||||
{
|
||||
start_date= validity_start;
|
||||
h_wire= FullPaytoHash.hash payto_uri;
|
||||
h_conversion_url= Hash.Cstring.H64.hash conversion_url;
|
||||
h_credit_restrictions= Hash.Cstring.H64.hash credit_restrictions;
|
||||
h_debit_restrictions= Hash.Cstring.H64.hash debit_restrictions;
|
||||
h_wire= h_wire_details;
|
||||
h_conversion_url;
|
||||
h_credit_restrictions;
|
||||
h_debit_restrictions;
|
||||
}
|
||||
in
|
||||
Ok ()
|
||||
|
||||
let do_ ~db_conn v =
|
||||
let* last_change_opt =
|
||||
let payto_uri = v.WireSetupMessage.payto_uri in
|
||||
Pg.get_wire_timestamp db_conn ~payto_uri |> unwrap_err_caqti
|
||||
in
|
||||
match last_change_opt with
|
||||
| Some _ -> Error "wire already setup"
|
||||
let do_ ~db_conn
|
||||
WireSetupMessage.
|
||||
{
|
||||
payto_uri;
|
||||
master_sig_wire;
|
||||
master_sig_add= _;
|
||||
conversion_url;
|
||||
credit_restrictions;
|
||||
debit_restrictions;
|
||||
validity_start;
|
||||
bank_label;
|
||||
priority;
|
||||
} =
|
||||
let* opt = Pg.find_wire db_conn ~payto_uri |> unwrap_err_caqti in
|
||||
match opt with
|
||||
| Some wire ->
|
||||
let+ () =
|
||||
Pg.update_wire db_conn ~is_active:true ~last_change:validity_start
|
||||
wire
|
||||
|> unwrap_err_caqti
|
||||
in
|
||||
Logs.info (fun m -> m "updated wire method");
|
||||
()
|
||||
| None ->
|
||||
let r =
|
||||
let wire =
|
||||
ExchangeWireAccount.
|
||||
{
|
||||
payto_uri= v.payto_uri;
|
||||
conversion_url= None;
|
||||
debit_restrictions= [];
|
||||
credit_restrictions= [];
|
||||
master_sig= v.master_sig_wire;
|
||||
bank_label= v.bank_label;
|
||||
priority= v.priority;
|
||||
payto_uri;
|
||||
conversion_url;
|
||||
credit_restrictions;
|
||||
debit_restrictions;
|
||||
master_sig= master_sig_wire;
|
||||
bank_label;
|
||||
priority;
|
||||
}
|
||||
in
|
||||
let+ () =
|
||||
Pg.insert_wire db_conn ~last_change:v.validity_start r
|
||||
Pg.update_wire db_conn ~is_active:true ~last_change:validity_start
|
||||
wire
|
||||
|> unwrap_err_caqti
|
||||
in
|
||||
Logs.info (fun m -> m "added wire method");
|
||||
()
|
||||
|
||||
let jsont = WireSetupMessage.jsont
|
||||
|
|
@ -448,15 +489,15 @@ module Wire_disable = struct
|
|||
|
||||
let do_ ~db_conn
|
||||
WireTeardownMessage.{ payto_uri; master_sig_del= _; validity_end } =
|
||||
let* last_change_opt =
|
||||
Pg.get_wire_timestamp db_conn ~payto_uri |> unwrap_err_caqti
|
||||
in
|
||||
match last_change_opt with
|
||||
let* opt = Pg.find_wire db_conn ~payto_uri |> unwrap_err_caqti in
|
||||
match opt with
|
||||
| None -> Error "wire not found"
|
||||
| Some _ ->
|
||||
| Some wire ->
|
||||
let+ () =
|
||||
Pg.disable_wire db_conn ~payto_uri ~validity_end |> unwrap_err_caqti
|
||||
Pg.update_wire db_conn ~is_active:false ~last_change:validity_end wire
|
||||
|> unwrap_err_caqti
|
||||
in
|
||||
Logs.info (fun m -> m "disabled wire method");
|
||||
()
|
||||
|
||||
let jsont = WireTeardownMessage.jsont
|
||||
|
|
@ -496,8 +537,18 @@ module Drain = struct
|
|||
}
|
||||
|
||||
let do_ ~db_conn v =
|
||||
let+ () = Pg.insert_drain_profit db_conn v |> unwrap_err_caqti in
|
||||
()
|
||||
let* opt =
|
||||
Pg.find_drain_profit db_conn v.DrainProfitsMessage.wtid
|
||||
|> unwrap_err_caqti
|
||||
in
|
||||
match opt with
|
||||
| Some _ ->
|
||||
Logs.info (fun m -> m "drain profit message already added to database");
|
||||
Ok ()
|
||||
| None ->
|
||||
let+ () = Pg.insert_drain_profit db_conn v |> unwrap_err_caqti in
|
||||
Logs.info (fun m -> m "added drain profit message to database");
|
||||
()
|
||||
|
||||
let jsont = DrainProfitsMessage.jsont
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue