[SSSD] [PATCH] util-tests: Add validation of internal error messages
Lukas Slebodnik
lslebodn at redhat.com
Fri May 29 06:25:43 UTC 2015
ehlo,
I noticed that some internal error messages has "." at the end.
We should do the same as strerror; return just a string and not a sentence.
simple test is attached.
LS
-------------- next part --------------
>From 83e99b466e617a7249b8d046685955de1016ca14 Mon Sep 17 00:00:00 2001
From: Lukas Slebodnik <lslebodn at redhat.com>
Date: Fri, 29 May 2015 08:13:30 +0200
Subject: [PATCH] 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()
---
src/tests/util-tests.c | 24 ++++++++++++++++++++++++
src/util/util_errors.c | 8 ++++----
2 files changed, 28 insertions(+), 4 deletions(-)
diff --git a/src/tests/util-tests.c b/src/tests/util-tests.c
index 24ee6ab494a0bb3b86e67be87b8d45ff01f646e9..3d42f0193a677200d5cb4a46805892bed978305c 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 64c52b57c24e32e87eb12ecb60bd3ce2cc5e24fb..97c54a5b3352f7982a129ddea3e65f08d0351ea3 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 */
};
--
2.4.1
More information about the sssd-devel
mailing list