Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
belenios
belenios
Commits
b8a7eb9f
Commit
b8a7eb9f
authored
Aug 29, 2019
by
Stephane Glondu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add estimation of shuffle time
parent
735fb390
Pipeline
#91509
passed with stages
in 27 minutes and 1 second
Changes
5
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
73 additions
and
11 deletions
+73
-11
src/tool/tool_js_common.ml
src/tool/tool_js_common.ml
+4
-0
src/tool/tool_js_shuffle.ml
src/tool/tool_js_shuffle.ml
+55
-7
src/web/web_templates.ml
src/web/web_templates.ml
+5
-2
tests/test_scenario_3.py
tests/test_scenario_3.py
+2
-2
tests/util/selenium_tools.py
tests/util/selenium_tools.py
+7
-0
No files found.
src/tool/tool_js_common.ml
View file @
b8a7eb9f
...
...
@@ -92,6 +92,10 @@ let clear_content (e : #Dom.node Js.t) =
()
done
let
clear_content_by_id
id
=
document
##
getElementById
(
Js
.
string
id
)
>>==
fun
e
->
clear_content
e
let
run_handler
handler
()
=
(
try
handler
()
with
e
->
...
...
src/tool/tool_js_shuffle.ml
View file @
b8a7eb9f
...
...
@@ -24,28 +24,76 @@ open Serializable_j
open
Common
open
Tool_js_common
let
eta
=
ref
0
let
shuffle
election
ciphertexts
=
let
election
=
Election
.(
get_group
(
of_string
election
))
in
let
module
W
=
(
val
election
)
in
let
module
E
=
Election
.
Make
(
W
)
(
LwtJsRandom
)
in
let
ciphertexts
=
nh_ciphertexts_of_string
E
.
G
.
read
ciphertexts
in
let
%
lwt
shuffle
=
E
.
shuffle_ciphertexts
ciphertexts
in
Lwt
.
return
(
string_of_shuffle
E
.
G
.
write
shuffle
)
let
full_shuffle
()
=
let
id
=
if
!
eta
>
0
then
let
start
=
(
new
%
js
Js
.
date_now
)
##
valueOf
in
let
stop
=
start
+.
float_of_int
!
eta
*.
1000
.
in
let
update
()
=
let
now
=
(
new
%
js
Js
.
date_now
)
##
valueOf
in
let
eta
=
max
0
(
int_of_float
(
ceil
((
stop
-.
now
)
/.
1000
.
)))
in
clear_content_by_id
"estimation"
;
set_content
"estimation"
(
Printf
.
sprintf
"Estimated remaining time: %d second(s)"
eta
)
in
Some
(
Dom_html
.
window
##
setInterval
(
Js
.
wrap_callback
update
)
500
.
)
else
None
in
let
%
lwt
shuffle
=
E
.
shuffle_ciphertexts
ciphertexts
in
let
r
=
string_of_shuffle
E
.
G
.
write
shuffle
in
let
()
=
match
id
with
|
Some
x
->
Dom_html
.
window
##
clearInterval
x
;
clear_content_by_id
"estimation"
;
|
None
->
()
in
Lwt
.
return
r
in
let
bench_shuffle
()
=
let
n
=
Array
.
fold_left
(
fun
accu
x
->
accu
+
Array
.
length
x
)
0
ciphertexts
in
let
%
lwt
x
=
LwtJsRandom
.
random
E
.
G
.
q
in
let
start
=
new
%
js
Js
.
date_now
in
let
_
=
E
.
G
.(
g
**~
x
)
in
let
stop
=
new
%
js
Js
.
date_now
in
set_element_display
"controls_div"
"block"
;
set_element_display
"wait_div"
"none"
;
let
delta
=
(
stop
##
valueOf
-.
start
##
valueOf
)
/.
1000
.
in
(* cost is 11n+7 modpows, we add another n for the overhead *)
eta
:=
int_of_float
(
ceil
(
delta
*.
float_of_int
(
12
*
n
+
7
)));
clear_content_by_id
"estimation"
;
set_content
"estimation"
(
Printf
.
sprintf
"Estimated computation time: %d second(s)"
!
eta
);
Lwt
.
return_unit
in
Lwt
.
async
bench_shuffle
;
full_shuffle
let
()
=
Lwt
.
async
(
fun
()
->
let
%
lwt
_
=
Lwt_js_events
.
onload
()
in
let
uuid
=
List
.
assoc
"uuid"
(
get_params
()
)
in
let
open
Lwt_xmlHttpRequest
in
let
%
lwt
election
=
get
(
"../elections/"
^
uuid
^
"/election.json"
)
in
let
%
lwt
ciphertexts
=
get
(
"../election/nh-ciphertexts?uuid="
^
uuid
)
in
let
full_shuffle
=
shuffle
election
.
content
ciphertexts
.
content
in
match
Dom_html
.
getElementById_coerce
"compute_shuffle"
Dom_html
.
CoerceTo
.
button
with
|
None
->
Lwt
.
return_unit
|
Some
btn
->
let
%
lwt
_
=
Lwt_js_events
.
click
btn
in
set_element_display
"controls_div"
"none"
;
set_element_display
"wait_div"
"block"
;
let
uuid
=
List
.
assoc
"uuid"
(
get_params
()
)
in
let
open
Lwt_xmlHttpRequest
in
let
%
lwt
election
=
get
(
"../elections/"
^
uuid
^
"/election.json"
)
in
let
%
lwt
ciphertexts
=
get
(
"../election/nh-ciphertexts?uuid="
^
uuid
)
in
let
%
lwt
shuffle
=
shuffle
election
.
content
ciphertexts
.
content
in
let
%
lwt
shuffle
=
full_shuffle
()
in
set_textarea
"shuffle"
shuffle
;
set_element_display
"wait_div"
"none"
;
set_content
"hash"
(
Platform
.
sha256_b64
shuffle
);
...
...
src/web/web_templates.ml
View file @
b8a7eb9f
...
...
@@ -2592,10 +2592,13 @@ let shuffle election token =
let
title
=
params
.
e_name
^
" — Shuffle"
in
let
content
=
[
div
[
pcdata
"It is now time to shuffle encrypted ballots."
];
div
~
a
:
[
a_id
"controls_div"
]
[
div
~
a
:
[
a_id
"estimation"
]
[
pcdata
"Estimating computation time..."
;
];
div
~
a
:
[
a_id
"controls_div"
;
a_style
"display: none;"
]
[
button_no_value
~
button_type
:
`Button
~
a
:
[
a_id
"compute_shuffle"
]
[
pcdata
"Compute shuffle"
];
];
div
~
a
:
[
a_id
"wait_div"
;
a_style
"display:none;"
]
[
div
~
a
:
[
a_id
"wait_div"
]
[
pcdata
"Please wait... "
;
img
~
src
:
(
static
"encrypting.gif"
)
~
alt
:
"Loading..."
()
;
];
...
...
tests/test_scenario_3.py
View file @
b8a7eb9f
...
...
@@ -6,7 +6,7 @@ import os
import
sys
from
distutils.util
import
strtobool
from
util.fake_sent_emails_manager
import
FakeSentEmailsManager
from
util.selenium_tools
import
wait_for_element_exists
,
wait_for_an_element_with_partial_link_text_exists
,
wait_for_element_exists_and_has_non_empty_attribute
,
wait_for_element_exists_and_contains_expected_text
from
util.selenium_tools
import
wait_for_element_exists
,
wait_for_an_element_with_partial_link_text_exists
,
wait_for_element_exists_and_has_non_empty_attribute
,
wait_for_element_exists_and_contains_expected_text
,
wait_for_element_visible
from
util.election_testing
import
console_log
,
remove_database_folder
,
wait_a_bit
,
build_css_selector_to_find_buttons_in_page_content_by_value
,
initialize_server
,
initialize_browser
,
verify_election_consistency
,
create_election_data_snapshot
,
delete_election_data_snapshot
,
log_in_as_administrator
,
log_out
from
util.election_test_base
import
BeleniosElectionTestBase
import
settings
...
...
@@ -82,7 +82,7 @@ class BeleniosTestElectionScenario1(BeleniosElectionTestBase):
wait_a_bit
()
# She clicks on the "Compute shuffle" button
wait_for_element_
exists
(
browser
,
"#compute_shuffle"
,
settings
.
EXPLICIT_WAIT_TIMEOUT
).
click
()
wait_for_element_
visible
(
browser
,
"#compute_shuffle"
,
settings
.
EXPLICIT_WAIT_TIMEOUT
).
click
()
wait_a_bit
()
# She waits for the "shuffle" textarea to be filled
...
...
tests/util/selenium_tools.py
View file @
b8a7eb9f
...
...
@@ -143,6 +143,13 @@ def wait_for_element_exists(browser, css_selector, wait_duration=DEFAULT_WAIT_DU
except
Exception
as
e
:
raise
Exception
(
"Could not find expected DOM element '"
+
css_selector
+
"' until timeout of "
+
str
(
wait_duration
)
+
" seconds"
)
from
e
def
wait_for_element_visible
(
browser
,
css_selector
,
wait_duration
=
DEFAULT_WAIT_DURATION
):
try
:
return
WebDriverWait
(
browser
,
wait_duration
).
until
(
EC
.
visibility_of_element_located
((
By
.
CSS_SELECTOR
,
css_selector
))
)
except
Exception
as
e
:
raise
Exception
(
"Could not find expected visible DOM element '"
+
css_selector
+
"' until timeout of "
+
str
(
wait_duration
)
+
" seconds"
)
from
e
def
wait_for_elements_exist
(
browser
,
css_selector
,
wait_duration
=
DEFAULT_WAIT_DURATION
):
try
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment