Use regular expressions when matching expected and actual text.

This commit is contained in:
Todd C. Miller
2020-04-07 14:03:58 -06:00
parent 8a2c0d784f
commit a77ef93f8a
11 changed files with 57 additions and 39 deletions

View File

@@ -22,6 +22,7 @@
#include "config.h"
#include "sudo_compat.h"
#include <regex.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

View File

@@ -1,4 +1,4 @@
SudoGroupPlugin.__init__ was called with arguments: () {'args': ('ModulePath=SRC_DIR/example_group_plugin.py', 'ClassName=SudoGroupPlugin'), 'version': '1.0'}
.*
SudoGroupPlugin.__init__ returned result: <example_group_plugin.SudoGroupPlugin object>
SudoGroupPlugin.query was called with arguments: ('user', 'group', ('pw_name', 'pw_passwd', 1001, 101, 'pw_gecos', 'pw_dir', 'pw_shell'))
SudoGroupPlugin.query returned result: RC.REJECT

View File

@@ -1,9 +1,9 @@
-- Plugin STARTED --
EXEC id --help
EXEC info [
EXEC info \[
"command=/bin/id",
"runas_uid=0"
]
\]
STD IN some standard input
STD OUT some standard output
STD ERR some standard error

View File

@@ -1,9 +1,9 @@
-- Plugin STARTED --
EXEC id --help
EXEC info [
EXEC info \[
"command=/bin/id",
"runas_uid=0"
]
\]
STD IN stdin for plugin 1
STD OUT stdout for plugin 1
STD ERR stderr for plugin 1

View File

@@ -1,9 +1,9 @@
-- Plugin STARTED --
EXEC whoami
EXEC info [
EXEC info \[
"command=/bin/whoami",
"runas_uid=1"
]
\]
STD IN stdin for plugin 2
STD OUT stdout for plugin 2
STD ERR stderr for plugin 2

View File

@@ -1,8 +1,8 @@
-- Plugin STARTED --
EXEC cmd
EXEC info [
EXEC info \[
"command=/usr/share/cmd",
"runas_uid=0"
]
\]
CLOSE Failed to execute, execve returned 1 (EPERM)
-- Plugin DESTROYED --

View File

@@ -1 +1 @@
Failed to construct plugin instance: (FileNotFoundError) [Errno 2] No such file or directory: '/some/not/writable/directory/sudo.log'
Failed to construct plugin instance: (FileNotFoundError) \[Errno 2\] No such file or directory: '/some/not/writable/directory/sudo.log'

View File

@@ -1 +1 @@
Failed during loading plugin class: (ModuleNotFoundError) No module named 'wrong_path'
Failed during loading plugin class: ([^)]*) No module named 'wrong_path'

View File

@@ -1,61 +1,61 @@
(APPROVAL 1) Constructed:
{
"plugin_options": [
"plugin_options": \[
"ModulePath=SRC_DIR/regress/plugin_approval_test.py",
"ClassName=ApprovalTestPlugin",
"Id=1"
],
\],
"version": "1.15",
"settings": [
"settings": \[
"SETTING1=VALUE1",
"setting2=value2"
],
"user_env": [
\],
"user_env": \[
"USER_ENV1=VALUE1",
"USER_ENV2=value2"
],
"user_info": [
\],
"user_info": \[
"INFO1=VALUE1",
"info2=value2"
],
\],
"submit_optind": 3,
"submit_argv": [
"submit_argv": \[
"sudo",
"-u",
"user",
"whoami",
"--help"
],
\],
"_id": "(APPROVAL 1)"
}
(APPROVAL 2) Constructed:
{
"plugin_options": [
"plugin_options": \[
"ModulePath=SRC_DIR/regress/plugin_approval_test.py",
"ClassName=ApprovalTestPlugin",
"Id=2"
],
\],
"version": "1.15",
"settings": [
"settings": \[
"SETTING1=VALUE1",
"setting2=value2"
],
"user_env": [
\],
"user_env": \[
"USER_ENV1=VALUE1",
"USER_ENV2=value2"
],
"user_info": [
\],
"user_info": \[
"INFO1=VALUE1",
"info2=value2"
],
\],
"submit_optind": 3,
"submit_argv": [
"submit_argv": \[
"sudo",
"-u",
"user",
"whoami",
"--help"
],
\],
"_id": "(APPROVAL 2)"
}
(APPROVAL 1) Show version was called with arguments: (0,)

View File

@@ -1,4 +1,4 @@
PATH before: [] (should be empty)
PATH set: ['path_for_first_plugin']
PATH before: [] (should be empty)
PATH set: ['path_for_second_plugin']
PATH before: \[\] (should be empty)
PATH set: \['path_for_first_plugin'\]
PATH before: \[\] (should be empty)
PATH set: \['path_for_second_plugin'\]

View File

@@ -111,10 +111,27 @@ char ** create_str_array(size_t count, ...);
#define VERIFY_STR(actual, expected) \
do { \
const char *actual_str = actual; \
if (!actual_str || strcmp(actual_str, expected) != 0) { \
VERIFY_PRINT_MSG("%s", #actual, actual_str ? actual_str : "(null)", #expected, expected, "expected to be"); \
return false; \
} \
regex_t regex; \
int result = 0; \
if (!actual_str) { \
result = -1; \
} else if (*expected == '\0') { \
result = strcmp(actual_str, expected); \
} else { \
if ((result = regcomp(&regex, expected, REG_NOSUB)) != 0) { \
char errbuf[1024]; \
regerror(result, &regex, errbuf, sizeof(errbuf)); \
fprintf(stderr, "regcomp failed at %s:%d: %s\npattern: %s\n", \
__FILE__, __LINE__, errbuf, expected); \
} else { \
result = regexec(&regex, actual_str, 0, NULL, 0); \
regfree(&regex); \
} \
} \
if (result != 0) { \
VERIFY_PRINT_MSG("%s", #actual, actual_str ? actual_str : "(null)", #expected, expected, "expected to be"); \
return false; \
} \
} while(false)
#define VERIFY_STR_CONTAINS(actual, expected) \