Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

runmodes: suricata hint missing runmode -v1 #9674

Closed
wants to merge 1 commit into from

Conversation

comfort619
Copy link
Contributor

Ticket: 5711

Link to redmine ticket:

Describe changes:
-Suricata when run does not provide feedback when the runmode is missing, leading to confusion for users
-Added missing runmode error

SV_BRANCH=OISF/suricata-verify#1434

@github-actions
Copy link

NOTE: This PR may contain new authors:

Comfort <comfortamaechi619@gmail.com>

@jufajardini jufajardini added the outreachy Contributions made by Outreachy applicants label Oct 22, 2023
@jufajardini
Copy link
Contributor

NOTE: This PR may contain new authors:

Comfort <comfortamaechi619@gmail.com>

@comfort619 Can you please keep the author name as you have for your other merged contribution? It was Comfort Amaechi. This helps our checks know that you're not actually a new author ;)

Copy link
Contributor

@jufajardini jufajardini left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for addressing this!

Some changes needed, from my end.

As this repo is for Suricata, we don't need to mention it in the commit message. Something like

runmodes: clear hint when runmode is not indicated

would work, imho.

Please also check the inline comments.

I've left some considerations about the added unit test, which I don't think we'll need.

Comment on lines +1 to +19
#include "suricata-common.h"
#include "util-running-modes.h"
#include "util-conf.h"
#include "runmodes.h"
#include "util-unittest.h"

void test_missing_run_mode(void) {
// Simulate missing run mode and check error message
SCInstance suri;
char *argv[] = {"suricata", NULL};

int result = FinalizeRunMode(&suri, argv);

FAIL_IF(result != TM_ECODE_FAILED);
// Add checks to verify the error message, if possible
PASS;
}

UtRegisterTest("RunModeTest", test_missing_run_mode);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Considering you've created a Suricata-verify test for this addition, I think we don't need a unit test for it, but thanks for thinking about this! :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we were to add this test and a new file, we'd need to:

  • ensure we have added the Copyright note, adjusting it to the current year (you'll see it in basically all of our code files, for instance, check src/tests/detect-snmp-community.c )
  • In case we did not have any unittests for this module, you would need to declare a new function following the convention ModuleRegisterTests, in which you would add the UtRegisterTest call that you have on line 19.
  • add the function that registers the RunMode unittest to the runmodes-unittests.c file, to ensure that your unittests is indeed run when Suricata runs the unittests. Check https://github.com/OISF/suricata/blob/master/src/runmode-unittests.c#L130
  • adapt the unittest name to our naming conventions for C. We use camel case, as you'll notice from the other functions on that file ;)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, thank you for the feedback. Should I go ahead and make the changes for the unit test considering you indicated the probability of it being added

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I really don't think we'll need them in this case, I just gave the feedback as extra info that can be useful and expanded to any other similar contributions. :)

I would say the best path here is to remove the unittest and focus on having a good SV test.

@@ -2369,6 +2369,7 @@ static int FinalizeRunMode(SCInstance *suri, char **argv)
{
switch (suri->run_mode) {
case RUNMODE_UNKNOWN:
SCLogError("Error: Missing run mode. Please specify a capture runmode.");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: there's no need to use Error in the message itself, for the usage of SCLogError will ensure that the log output will indicate that this is an error message.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
outreachy Contributions made by Outreachy applicants
2 participants