summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLukas Slebodnik <lslebodn@redhat.com>2015-05-29 08:13:30 +0200
committerJakub Hrozek <jhrozek@redhat.com>2015-06-01 15:29:19 +0200
commit7a4e3e29196e3abc1746714fcf93624edae89f93 (patch)
tree20b22cbdbf6daf740fc5e9255bf7e3baa2dcc70c
parent40bc389bc79bc41429b5a92d5ce75955f8eefaf5 (diff)
downloadsssd-7a4e3e29196e3abc1746714fcf93624edae89f93.tar.gz
sssd-7a4e3e29196e3abc1746714fcf93624edae89f93.tar.xz
sssd-7a4e3e29196e3abc1746714fcf93624edae89f93.zip
util-tests: Add validation of internal error messages
The function sss_strerror() should not return a sentence. It shoudl return string; the same as strerror() Reviewed-by: Pavel Březina <pbrezina@redhat.com>
-rw-r--r--src/tests/util-tests.c24
-rw-r--r--src/util/util_errors.c8
2 files changed, 28 insertions, 4 deletions
diff --git a/src/tests/util-tests.c b/src/tests/util-tests.c
index 24ee6ab49..3d42f0193 100644
--- a/src/tests/util-tests.c
+++ b/src/tests/util-tests.c
@@ -29,6 +29,7 @@
#include <sys/stat.h>
#include <fcntl.h>
#include <stdlib.h>
+#include <ctype.h>
#include "util/util.h"
#include "util/sss_utf8.h"
@@ -1076,6 +1077,28 @@ START_TEST(test_sss_strerror_err_last)
}
END_TEST
+START_TEST(test_sss_strerror_string_validation)
+{
+ enum sssd_errors idx;
+ const char *error;
+ size_t len;
+ char last_character;
+
+ for (idx = ERR_BASE; idx < ERR_LAST; ++idx) {
+ error = sss_strerror(idx);
+ fail_if(error == NULL, "sss_strerror returned NULL for valid index");
+
+ len = strlen(error);
+ fail_if(len == 0, "sss_strerror returned empty string");
+
+ last_character = error[len - 1];
+ fail_if(isalpha(last_character) == 0 && last_character != ')',
+ "Error string [%s] must finish with alphabetic character\n",
+ error);
+ }
+}
+END_TEST
+
Suite *util_suite(void)
{
Suite *s = suite_create("util");
@@ -1131,6 +1154,7 @@ Suite *util_suite(void)
TCase *tc_sss_strerror = tcase_create("sss_strerror");
tcase_add_test(tc_sss_strerror, test_sss_strerror_err_last);
+ tcase_add_test(tc_sss_strerror, test_sss_strerror_string_validation);
suite_add_tcase (s, tc_util);
suite_add_tcase (s, tc_utf8);
diff --git a/src/util/util_errors.c b/src/util/util_errors.c
index 64c52b57c..97c54a5b3 100644
--- a/src/util/util_errors.c
+++ b/src/util/util_errors.c
@@ -48,7 +48,7 @@ struct err_string error_to_str[] = {
{ "Host Access Denied" }, /* ERR_ACCESS_DENIED */
{ "SRV record not found" }, /* ERR_SRV_NOT_FOUND */
{ "SRV lookup error" }, /* ERR_SRV_LOOKUP_ERROR */
- { "SRV lookup did not return any new server "}, /* ERR_SRV_DUPLICATES */
+ { "SRV lookup did not return any new server" }, /* ERR_SRV_DUPLICATES */
{ "Dynamic DNS update failed" }, /* ERR_DYNDNS_FAILED */
{ "Dynamic DNS update timed out" }, /* ERR_DYNDNS_TIMEOUT */
{ "Dynamic DNS update not possible while offline" }, /* ERR_DYNDNS_OFFLINE */
@@ -62,7 +62,7 @@ struct err_string error_to_str[] = {
{ "Malformed extra attribute" }, /* ERR_INVALID_EXTRA_ATTR */
{ "Cannot get bus message sender" }, /* ERR_SBUS_GET_SENDER_ERROR */
{ "Bus message has no sender" }, /* ERR_SBUS_NO_SENDER */
- { "Invalid SBUS path provided." }, /* ERR_SBUS_INVALID_PATH */
+ { "Invalid SBUS path provided" }, /* ERR_SBUS_INVALID_PATH */
{ "User/Group SIDs not found" }, /* ERR_NO_SIDS */
{ "Bus method not supported" }, /* ERR_SBUS_NOSUP */
{ "Cannot connect to system bus" }, /* ERR_NO_SYSBUS */
@@ -70,10 +70,10 @@ struct err_string error_to_str[] = {
{ "Error setting SELinux user context" }, /* ERR_SELINUX_CONTEXT */
{ "Username format not allowed by re_expression" }, /* ERR_REGEX_NOMATCH */
{ "Time specification not supported" }, /* ERR_TIMESPEC_NOT_SUPPORTED */
- { "Invalid SSSD configuration detected." }, /* ERR_INVALID_CONFIG */
+ { "Invalid SSSD configuration detected" }, /* ERR_INVALID_CONFIG */
{ "Malformed cache entry" }, /* ERR_MALFORMED_ENTRY */
{ "Unexpected cache entry type" }, /* ERR_UNEXPECTED_ENTRY_TYPE */
- { "Failed to resolve one of user groups." }, /* ERR_SIMPLE_GROUPS_MISSING */
+ { "Failed to resolve one of user groups" }, /* ERR_SIMPLE_GROUPS_MISSING */
{ "ERR_LAST" } /* ERR_LAST */
};