[glom] test_selfhosting_new_empty_then_users: Improvements.
- From: Murray Cumming <murrayc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glom] test_selfhosting_new_empty_then_users: Improvements.
- Date: Wed, 1 Feb 2012 10:05:42 +0000 (UTC)
commit 4ad252ec0b5ce3d0ebfd2ce49ef940da0ecac550
Author: Murray Cumming <murrayc murrayc com>
Date: Wed Feb 1 11:05:33 2012 +0100
test_selfhosting_new_empty_then_users: Improvements.
* tests/test_selfhosting_new_empty_then_users.cc:
Add tables that will be affected.
Test strange characters in group and user names.
ChangeLog | 8 ++
tests/test_selfhosting_new_empty_then_users.cc | 103 ++++++++++++++++++-----
2 files changed, 88 insertions(+), 23 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 480a1c7..e8d3eb2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,13 @@
2012-02-01 Murray Cumming <murrayc murrayc com>
+ test_selfhosting_new_empty_then_users: Improvements.
+
+ * tests/test_selfhosting_new_empty_then_users.cc:
+ Add tables that will be affected.
+ Test strange characters in group and user names.
+
+2012-02-01 Murray Cumming <murrayc murrayc com>
+
Add test_selfhosting_new_empty_then_users
* glom/mode_design/users/dialog_groups_list.cc: on_button_group_new():
diff --git a/tests/test_selfhosting_new_empty_then_users.cc b/tests/test_selfhosting_new_empty_then_users.cc
index 21ae210..99b2197 100644
--- a/tests/test_selfhosting_new_empty_then_users.cc
+++ b/tests/test_selfhosting_new_empty_then_users.cc
@@ -36,6 +36,48 @@ bool contains(const T_Container& container, const T_Value& name)
return iter != container.end();
}
+static bool test_add_group(const Glom::Document& document, const Glib::ustring& group)
+{
+ if(!Glom::DbUtils::add_group(&document, group))
+ {
+ std::cerr << "DbUtils::add_group() failed." << std::endl;
+ return false;
+ }
+
+ const Glom::Privs::type_vec_strings group_list = Glom::Privs::get_database_groups();
+ if(!contains(group_list, group))
+ {
+ std::cerr << "Privs::get_database_groups() does not contain the expected group." << std::endl;
+ std::cerr << " group: " << group << std::endl;
+ return false;
+ }
+
+ return true;
+}
+
+static bool test_add_user(const Glom::Document& document, const Glib::ustring& user, const Glib::ustring& group)
+{
+ //Add an operator user, adding it to the group:
+ if(!Glom::DbUtils::add_user(&document, user, "somepassword", group))
+ {
+ std::cerr << "DbUtils::add_user() failed." << std::endl;
+ test_selfhosting_cleanup();
+ return false;
+ }
+
+ const Glom::Privs::type_vec_strings user_list = Glom::Privs::get_database_users(group);
+ if(!contains(user_list, user))
+ {
+ std::cerr << "Privs::get_database_groups() does not contain the expected user:" << std::endl;
+ std::cerr << " group: " << group << std::endl;
+ std::cerr << " user: " << user << std::endl;
+ return false;
+ }
+
+ return true;
+}
+
+
static bool test(Glom::Document::HostingMode hosting_mode)
{
//Create and self-host the document:
@@ -46,6 +88,26 @@ static bool test(Glom::Document::HostingMode hosting_mode)
return false;
}
+ //Add some tables, for the groups to have rights for:
+ if(!Glom::DbUtils::create_table_with_default_fields(&document, "sometable1"))
+ {
+ std::cerr << "Failure: create_table_with_default_fields() failed." << std::endl;
+ return false;
+ }
+
+ if(!Glom::DbUtils::create_table_with_default_fields(&document, "sometable with space characters"))
+ {
+ std::cerr << "Failure: create_table_with_default_fields() failed." << std::endl;
+ return false;
+ }
+
+ if(!Glom::DbUtils::create_table_with_default_fields(&document, "sometable with a \" quote character"))
+ {
+ std::cerr << "Failure: create_table_with_default_fields() failed." << std::endl;
+ return false;
+ }
+
+
//Check that only one group exists (the developer group):
const Glom::Privs::type_vec_strings group_list_original = Glom::Privs::get_database_groups();
if(group_list_original.empty())
@@ -60,22 +122,18 @@ static bool test(Glom::Document::HostingMode hosting_mode)
return false;
}
- //Add a group:
- const Glib::ustring group_name = "somegroup";
- if(!Glom::DbUtils::add_group(&document, group_name))
- {
- std::cerr << "DbUtils::add_group() failed." << std::endl;
- test_selfhosting_cleanup();
+ //Add groups:
+ if(!test_add_group(document, "somegroup"))
return false;
- }
- const Glom::Privs::type_vec_strings group_list_after = Glom::Privs::get_database_groups();
- if(group_list_after.size() <= group_list_original.size())
- {
- std::cerr << "The new group list is not larger than the old group list." << std::endl;
+ if(!test_add_group(document, "somegroup with space characters"))
return false;
- }
+ if(!test_add_group(document, "somegroup with a \" character"))
+ return false;
+
+
+ const Glib::ustring group_name = "somegroup";
const Glom::Privs::type_vec_strings user_list_original = Glom::Privs::get_database_users(group_name);
if(!user_list_original.empty())
{
@@ -83,20 +141,19 @@ static bool test(Glom::Document::HostingMode hosting_mode)
return false;
}
- //Add an operator user, adding it to the group:
- if(!Glom::DbUtils::add_user(&document, "someuser", "somepassword", group_name))
- {
- std::cerr << "DbUtils::add_user() failed." << std::endl;
- test_selfhosting_cleanup();
+
+ //Add users:
+ //TODO: Test strange group names here.
+ //TODO: Test strange passwords.
+ if(!test_add_user(document, "someuser", group_name))
return false;
- }
- const Glom::Privs::type_vec_strings user_list_after = Glom::Privs::get_database_users(group_name);
- if(user_list_after.size() != 1)
- {
- std::cerr << "The user list has an unexpected size: " << user_list_after.size() << std::endl;
+ if(!test_add_user(document, "someuser with space characters", group_name))
return false;
- }
+
+ if(!test_add_user(document, "someuser with a \" character", group_name))
+ return false;
+
test_selfhosting_cleanup(false /* do not delete the file. */);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]