diff options
author | Claudio Saavedra <csaavedra@igalia.com> | 2019-08-05 15:47:07 +0300 |
---|---|---|
committer | Claudio Saavedra <csaavedra@igalia.com> | 2019-08-05 14:19:10 +0000 |
commit | d0f97bd67f21a214d396b01fa8b293d0d89cb5ab (patch) | |
tree | 9939b95e3dceebdd1336d5f0c90b959cf02af7d6 /tests | |
parent | 6c06d60074a808ded76b9fd47d77c3562ee0330f (diff) | |
download | libsoup-d0f97bd67f21a214d396b01fa8b293d0d89cb5ab.tar.gz |
HSTS: Add API to retrieve a list of policies in an enforcer
Add soup_hsts_enforcer_get_policies(). This API is needed for WebKit's
website data manager to handle HSTS policies.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/hsts-test.c | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/tests/hsts-test.c b/tests/hsts-test.c index 5918ee39..ba919c81 100644 --- a/tests/hsts-test.c +++ b/tests/hsts-test.c @@ -503,6 +503,50 @@ do_hsts_get_domains_test (void) g_object_unref (enforcer); } +static void +do_hsts_get_policies_test (void) +{ + SoupHSTSEnforcer *enforcer = soup_hsts_enforcer_new (); + SoupHSTSPolicy *policy; + GList* policies; + + g_assert_null (soup_hsts_enforcer_get_policies (enforcer, TRUE)); + g_assert_null (soup_hsts_enforcer_get_policies (enforcer, FALSE)); + + policy = soup_hsts_policy_new ("gnome.org", 3600, FALSE); + g_assert_nonnull (policy); + soup_hsts_enforcer_set_policy (enforcer, policy); + soup_hsts_policy_free (policy); + + policy = soup_hsts_policy_new_session_policy ("freedesktop.org", FALSE); + g_assert_nonnull (policy); + soup_hsts_enforcer_set_policy (enforcer, policy); + soup_hsts_policy_free (policy); + + policies = soup_hsts_enforcer_get_policies (enforcer, TRUE); + g_assert_nonnull (policies); + g_assert_cmpint (g_list_length (policies), ==, 2); + g_list_free_full (policies, (GDestroyNotify)soup_hsts_policy_free); + + policies = soup_hsts_enforcer_get_policies (enforcer, FALSE); + g_assert_nonnull (policies); + g_assert_cmpint (g_list_length (policies), ==, 1); + policy = (SoupHSTSPolicy*)policies->data; + g_assert_cmpstr (policy->domain, ==, "gnome.org"); + g_list_free_full (policies, (GDestroyNotify)soup_hsts_policy_free); + + policy = soup_hsts_policy_new ("gnome.org", SOUP_HSTS_POLICY_MAX_AGE_PAST, FALSE); + soup_hsts_enforcer_set_policy (enforcer, policy); + soup_hsts_policy_free (policy); + + policies = soup_hsts_enforcer_get_policies (enforcer, TRUE); + g_assert_cmpint (g_list_length (policies), ==, 1); + policy = (SoupHSTSPolicy*)policies->data; + g_assert_cmpstr (policy->domain, ==, "freedesktop.org"); + g_list_free_full (policies, (GDestroyNotify)soup_hsts_policy_free); + g_object_unref(enforcer); +} + int main (int argc, char **argv) { @@ -549,6 +593,7 @@ main (int argc, char **argv) g_test_add_func ("/hsts/session-policy", do_hsts_session_policy_test); g_test_add_func ("/hsts/idna-addresses", do_hsts_idna_addresses_test); g_test_add_func ("/hsts/get-domains", do_hsts_get_domains_test); + g_test_add_func ("/hsts/get-policies", do_hsts_get_policies_test); ret = g_test_run (); |