Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Mike Perry
Tor
Commits
b47139d7
Commit
b47139d7
authored
Jul 24, 2017
by
George Kadianakis
Committed by
Nick Mathewson
Aug 08, 2017
Browse files
test: Unit tests for the revision counter state file codethe
Signed-off-by:
David Goulet
<
dgoulet@torproject.org
>
parent
6f046b21
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/or/hs_service.c
View file @
b47139d7
...
...
@@ -924,7 +924,7 @@ load_service_keys(hs_service_t *service)
}
/* Free a given service descriptor object and all key material is wiped. */
static
void
STATIC
void
service_descriptor_free
(
hs_service_descriptor_t
*
desc
)
{
if
(
!
desc
)
{
...
...
@@ -1947,7 +1947,7 @@ upload_descriptor_to_hsdir(const hs_service_t *service,
*
* HidServRevCounter <blinded_pubkey> <rev_counter>
*/
static
char
*
STATIC
char
*
encode_desc_rev_counter_for_state
(
const
hs_service_descriptor_t
*
desc
)
{
char
*
state_str
=
NULL
;
...
...
@@ -2009,7 +2009,7 @@ update_revision_counters_in_state(void)
* with <b>blinded_pubkey</b>. Set <b>service_found_out</b> to True if the
* line is relevant to this service, and return the cached revision
* counter. Else set <b>service_found_out</b> to False. */
static
uint64_t
STATIC
uint64_t
check_state_line_for_service_rev_counter
(
const
char
*
state_line
,
ed25519_public_key_t
*
blinded_pubkey
,
int
*
service_found_out
)
...
...
src/or/hs_service.h
View file @
b47139d7
...
...
@@ -325,6 +325,16 @@ STATIC void build_all_descriptors(time_t now);
STATIC
void
update_all_descriptors
(
time_t
now
);
STATIC
void
run_upload_descriptor_event
(
time_t
now
);
STATIC
char
*
encode_desc_rev_counter_for_state
(
const
hs_service_descriptor_t
*
desc
);
STATIC
void
service_descriptor_free
(
hs_service_descriptor_t
*
desc
);
STATIC
uint64_t
check_state_line_for_service_rev_counter
(
const
char
*
state_line
,
ed25519_public_key_t
*
blinded_pubkey
,
int
*
service_found_out
);
#endif
/* TOR_UNIT_TESTS */
#endif
/* HS_SERVICE_PRIVATE */
...
...
src/test/test_hs_service.c
View file @
b47139d7
...
...
@@ -1194,6 +1194,65 @@ test_upload_desctriptors(void *arg)
UNMOCK
(
hs_overlap_mode_is_active
);
}
/** Test the functions that save and load HS revision counters to state. */
static
void
test_revision_counter_state
(
void
*
arg
)
{
char
*
state_line_one
=
NULL
;
char
*
state_line_two
=
NULL
;
hs_service_descriptor_t
*
desc_one
=
service_descriptor_new
();
hs_service_descriptor_t
*
desc_two
=
service_descriptor_new
();
(
void
)
arg
;
/* Prepare both descriptors */
desc_one
->
desc
->
plaintext_data
.
revision_counter
=
42
;
desc_two
->
desc
->
plaintext_data
.
revision_counter
=
240
;
memset
(
&
desc_one
->
blinded_kp
.
pubkey
.
pubkey
,
'\x42'
,
sizeof
(
desc_one
->
blinded_kp
.
pubkey
.
pubkey
));
memset
(
&
desc_two
->
blinded_kp
.
pubkey
.
pubkey
,
'\xf0'
,
sizeof
(
desc_one
->
blinded_kp
.
pubkey
.
pubkey
));
/* Turn the descriptor rev counters into state lines */
state_line_one
=
encode_desc_rev_counter_for_state
(
desc_one
);
tt_str_op
(
state_line_one
,
OP_EQ
,
"QkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkI 42"
);
state_line_two
=
encode_desc_rev_counter_for_state
(
desc_two
);
tt_str_op
(
state_line_two
,
OP_EQ
,
"8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PA 240"
);
/* Now let's test our state parsing function: */
int
service_found
;
uint64_t
cached_rev_counter
;
/* First's try with wrong pubkey and check that no service was found */
cached_rev_counter
=
check_state_line_for_service_rev_counter
(
state_line_one
,
&
desc_two
->
blinded_kp
.
pubkey
,
&
service_found
);
tt_int_op
(
service_found
,
OP_EQ
,
0
);
/* Now let's try with the right pubkeys */
cached_rev_counter
=
check_state_line_for_service_rev_counter
(
state_line_one
,
&
desc_one
->
blinded_kp
.
pubkey
,
&
service_found
);
tt_int_op
(
service_found
,
OP_EQ
,
1
);
tt_int_op
(
cached_rev_counter
,
OP_EQ
,
42
);
cached_rev_counter
=
check_state_line_for_service_rev_counter
(
state_line_two
,
&
desc_two
->
blinded_kp
.
pubkey
,
&
service_found
);
tt_int_op
(
service_found
,
OP_EQ
,
1
);
tt_int_op
(
cached_rev_counter
,
OP_EQ
,
240
);
done:
tor_free
(
state_line_one
);
tor_free
(
state_line_two
);
service_descriptor_free
(
desc_one
);
service_descriptor_free
(
desc_two
);
}
struct
testcase_t
hs_service_tests
[]
=
{
{
"e2e_rend_circuit_setup"
,
test_e2e_rend_circuit_setup
,
TT_FORK
,
NULL
,
NULL
},
...
...
@@ -1221,6 +1280,8 @@ struct testcase_t hs_service_tests[] = {
NULL
,
NULL
},
{
"upload_desctriptors"
,
test_upload_desctriptors
,
TT_FORK
,
NULL
,
NULL
},
{
"revision_counter_state"
,
test_revision_counter_state
,
TT_FORK
,
NULL
,
NULL
},
END_OF_TESTCASES
};
...
...
Write
Preview
Supports
Markdown
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