=?utf-8?b?W2xpYmdkYXRhXSBjb3JlOiBGaXggcGFyc2luZyBvZiDigJhkZWZhdWx04oCZ?= =?utf-8?q?_ACL_rule_scopes?=
- From: Philip Withnall <pwithnall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgdata] core: Fix parsing of âdefaultâ ACL rule scopes
- Date: Mon, 20 Aug 2012 21:39:31 +0000 (UTC)
commit 7c1f8ffaf330827129c5b01f34377ba2ed5a0530
Author: Philip Withnall <philip tecnocode co uk>
Date: Mon Aug 20 22:36:34 2012 +0100
core: Fix parsing of âdefaultâ ACL rule scopes
As found by Meg Ford, libgdata was expecting <gAcl:scope> elements to have
a âvalueâ property, when the documentation
(https://developers.google.com/google-apps/calendar/v2/reference#gacl_reference)
explicitly says they shouldnât have one. Whoops.
This fixes it and adds a test. Note that the code doesnât check that
there _isnât_ a âvalueâ property, because Google might go and change it in
future.
gdata/gdata-access-rule.c | 16 ++++++++++++----
gdata/tests/general.c | 40 ++++++++++++++++++++++++++++++++++++++++
2 files changed, 52 insertions(+), 4 deletions(-)
---
diff --git a/gdata/gdata-access-rule.c b/gdata/gdata-access-rule.c
index a0a27aa..f9a898d 100644
--- a/gdata/gdata-access-rule.c
+++ b/gdata/gdata-access-rule.c
@@ -122,6 +122,8 @@ gdata_access_rule_class_init (GDataAccessRuleClass *klass)
* A value representing the user who is represented by the access rule, such as an
* e-mail address for users, or a domain name for domains.
*
+ * This must be %NULL if and only if #GDataAccessRule:scope-type is %GDATA_ACCESS_SCOPE_DEFAULT.
+ *
* Since: 0.3.0
**/
g_object_class_install_property (gobject_class, PROP_SCOPE_VALUE,
@@ -305,7 +307,9 @@ parse_xml (GDataParsable *parsable, xmlDoc *doc, xmlNode *node, gpointer user_da
scope_value = xmlGetProp (node, (xmlChar*) "value");
- if (xmlStrcmp (scope_type, (xmlChar*) GDATA_ACCESS_SCOPE_DEFAULT) == 0 && scope_value == NULL) {
+ /* The @value property is required for all scope types except "default".
+ * See: https://developers.google.com/google-apps/calendar/v2/reference#gacl_reference */
+ if (xmlStrcmp (scope_type, (xmlChar*) GDATA_ACCESS_SCOPE_DEFAULT) != 0 && scope_value == NULL) {
xmlFree (scope_type);
return gdata_parser_error_required_property_missing (node, "value", error);
}
@@ -343,6 +347,10 @@ get_xml (GDataParsable *parsable, GString *xml_string)
} else {
gdata_parser_string_append_escaped (xml_string, "<gAcl:scope value='", priv->scope_value, "'/>");
}
+ } else {
+ /* gAcl:scope of type GDATA_ACCESS_SCOPE_DEFAULT. */
+ g_assert (priv->scope_type != NULL && strcmp (priv->scope_type, GDATA_ACCESS_SCOPE_DEFAULT) == 0);
+ g_string_append (xml_string, "<gAcl:scope type='default'/>");
}
}
@@ -414,7 +422,7 @@ gdata_access_rule_get_role (GDataAccessRule *self)
* gdata_access_rule_set_scope:
* @self: a #GDataAccessRule
* @type: a new scope type
- * @value: a new scope value, or %NULL
+ * @value: (allow-none): a new scope value, or %NULL
*
* Sets the #GDataAccessRule:scope-type property to @type and the #GDataAccessRule:scope-value property to @value.
*
@@ -448,8 +456,8 @@ gdata_access_rule_set_scope (GDataAccessRule *self, const gchar *type, const gch
/**
* gdata_access_rule_get_scope:
* @self: a #GDataAccessRule
- * @type: (out callee-allocates) (transfer none): return location for the scope type, or %NULL
- * @value: (out callee-allocates) (transfer none): return location for the scope value, or %NULL
+ * @type: (out callee-allocates) (transfer none) (allow-none): return location for the scope type, or %NULL
+ * @value: (out callee-allocates) (transfer none) (allow-none): return location for the scope value, or %NULL
*
* Gets the #GDataAccessRule:scope-type and #GDataAccessRule:scope-value properties.
*
diff --git a/gdata/tests/general.c b/gdata/tests/general.c
index aff6bbc..93e5bb2 100644
--- a/gdata/tests/general.c
+++ b/gdata/tests/general.c
@@ -1137,6 +1137,44 @@ test_access_rule_get_xml (void)
g_object_unref (rule);
g_object_unref (rule2);
+
+ /* Check that a rule with scope type 'default' doesn't have a value.
+ * See: https://developers.google.com/google-apps/calendar/v2/reference#gacl_reference */
+ rule = gdata_access_rule_new ("another-id");
+ gdata_access_rule_set_role (rule, GDATA_ACCESS_ROLE_NONE);
+ gdata_access_rule_set_scope (rule, GDATA_ACCESS_SCOPE_DEFAULT, NULL);
+
+ /* Check the generated XML's OK */
+ gdata_test_assert_xml (rule,
+ "<?xml version='1.0' encoding='UTF-8'?>"
+ "<entry xmlns='http://www.w3.org/2005/Atom' "
+ "xmlns:gd='http://schemas.google.com/g/2005' "
+ "xmlns:gAcl='http://schemas.google.com/acl/2007'>"
+ "<title type='text'>none</title>"
+ "<id>another-id</id>"
+ "<category term='http://schemas.google.com/acl/2007#accessRule' scheme='http://schemas.google.com/g/2005#kind'/>"
+ "<gAcl:role value='none'/>"
+ "<gAcl:scope type='default'/>"
+ "</entry>");
+
+ /* Check by re-parsing the XML to a GDataAccessRule */
+ xml = gdata_parsable_get_xml (GDATA_PARSABLE (rule));
+ rule2 = GDATA_ACCESS_RULE (gdata_parsable_new_from_xml (GDATA_TYPE_ACCESS_RULE, xml, -1, &error));
+ g_assert_no_error (error);
+ g_assert (GDATA_IS_ACCESS_RULE (rule2));
+ g_clear_error (&error);
+ g_free (xml);
+
+ g_assert_cmpstr (gdata_access_rule_get_role (rule), ==, gdata_access_rule_get_role (rule2));
+ gdata_access_rule_get_scope (rule, &scope_type, &scope_value);
+ gdata_access_rule_get_scope (rule2, &scope_type2, &scope_value2);
+ g_assert_cmpstr (scope_type, ==, scope_type2);
+ g_assert_cmpstr (scope_value, ==, scope_value2);
+ edited = gdata_access_rule_get_edited (rule2);
+ g_assert_cmpuint (edited, ==, -1); /* unspecified in XML */
+
+ g_object_unref (rule);
+ g_object_unref (rule2);
}
static void
@@ -1158,6 +1196,8 @@ test_access_rule_error_handling (void)
/* scope */
TEST_XML_ERROR_HANDLING ("<gAcl:scope/>"); /* missing type */
+ TEST_XML_ERROR_HANDLING ("<gAcl:scope type='user'/>"); /* missing value */
+ TEST_XML_ERROR_HANDLING ("<gAcl:scope type='domain'/>"); /* missing value */
/* edited */
TEST_XML_ERROR_HANDLING ("<app:edited/>"); /* missing date */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]