Browse Source

Removed -config processing. Added checks for specification of -auth

or -id (but not both) with another command.


git-svn-id: https://svn.microneil.com/svn/SNFUtility/trunk@26 aa37657e-1934-4a5f-aa6d-2d8eab27ff7c
master
adeniz 12 years ago
parent
commit
a71d368b6f

+ 12
- 35
Common/UtilityConfig.cpp View File

} }
void
UtilityConfig::CheckAndSetConfigFileName(const std::string DefaultFile) {
string SpecifiedConfigFile = GetConfigFileName();
if (SpecifiedConfigFile.length() > 0) {
return;
}
SetConfigFileName(DefaultFile);
}
void void
UtilityConfig::CreateDefaultConfigFile(std::string SampleConfigFile) { UtilityConfig::CreateDefaultConfigFile(std::string SampleConfigFile) {
} else if (0 == OneInput.find(AuthenticationKey)) { } else if (0 == OneInput.find(AuthenticationKey)) {
Authentication = Trim(OneInput.substr(AuthenticationKey.length()));
AuthenticationIsSpecified = true;
TempString = Trim(OneInput.substr(AuthenticationKey.length())); // Copy only if not null after trimming.
if (!TempString.empty()) {
Authentication = TempString;
AuthenticationIsSpecified = true;
} else {
ValidCommand = false;
}
} else { } else {
bool bool
UtilityConfig::CommandLineIsOkay() { UtilityConfig::CommandLineIsOkay() {
std::string ConfigFile = GetConfigFileName();
bool NoCredentialSpecified = !(AuthenticationIsSpecified || LicenseIdIsSpecified);
int NumCommandsSpecified = 0;
if (UpdateCredentialsSpecified()) {
if (ConfigFile.length() > 0) {
return false;
}
NumCommandsSpecified++;
}
// AVD modified to here.
return true;
return (AuthenticationIsSpecified == LicenseIdIsSpecified);
} }
Desc += " -auth=authentication Specifies the Authentication\n"; Desc += " -auth=authentication Specifies the Authentication\n";
Desc += " -start Start the sniffer\n"; Desc += " -start Start the sniffer\n";
Desc += " -stop Stop the sniffer\n"; Desc += " -stop Stop the sniffer\n";
Desc += " -config=snf-config-file Specifies the configuration file\n";
Desc += " -v Provide verbose output\n"; Desc += " -v Provide verbose output\n";
Desc += " -explain Provide an explaination of the actions\n"; Desc += " -explain Provide an explaination of the actions\n";
Desc += " without executing any commands\n"; Desc += " without executing any commands\n";

+ 7
- 16
Common/UtilityConfig.hpp View File

/// Object to back up and restore files. /// Object to back up and restore files.
FileBackup SaveFile; FileBackup SaveFile;
/// Set the config file name to the default if it wasn't specified.
//
// If the configuration file wasn't specified by
// SetConfigFileName() on the command line, then this method sets
// the config file to the specified default.
//
// If the configuration file was specified by SetConfigFileName()
// or on the command line, then this method does nothing.
//
// \param[in] DefaultFile is the default file name.
//
void CheckAndSetConfigFileName(const std::string DefaultFile);
/// If the configuration file doesn't exist, create it from the /// If the configuration file doesn't exist, create it from the
/// sample file. In any case, set the owner and mode. /// sample file. In any case, set the owner and mode.
// //
// This method creates the default configuration file if the // This method creates the default configuration file if the
// specified configuration file doesn't exist. // specified configuration file doesn't exist.
// //
// The method CheckAndSetConfigFileName must be called before this
// The method SetConfigFileName must be called before this
// method. // method.
// //
// \param[in] SampleConfigFile is the name of the sample // \param[in] SampleConfigFile is the name of the sample
// //
// \note The configuration information must be loaded before calling this method. // \note The configuration information must be loaded before calling this method.
// //
// \see CheckAndSetConfigFileName.
// \see SetConfigFileName.
// //
// \see CreateDefaultConfigFile. // \see CreateDefaultConfigFile.
// //
/// Check whether the command-line parameters were specified /// Check whether the command-line parameters were specified
/// correctly. /// correctly.
// //
// This function check that either both the LicenseID and
// This method checks that either both the LicenseID and
// Authentication were specified, or neither were. // Authentication were specified, or neither were.
// //
// This method does not check for multiple commands specified on
// the command line.
//
// \returns if the command-line parameters were specified // \returns if the command-line parameters were specified
// correctly, false otherwise. // correctly, false otherwise.
//
bool CommandLineIsOkay(void); bool CommandLineIsOkay(void);
/// Output the legal command-line input. /// Output the legal command-line input.

+ 7
- 8
SNFMilterConfig/SNFMilterConfig.cpp View File

<< UtilityConfig::HelpCommandLine(ExclusiveCommands) << "\n\n" << UtilityConfig::HelpCommandLine(ExclusiveCommands) << "\n\n"
<< "SNFMilterConfig " << "SNFMilterConfig "
<< UtilityConfig::HelpDescription(ExclusiveCommandsHelp) << "\n" << UtilityConfig::HelpDescription(ExclusiveCommandsHelp) << "\n"
<< "If snf-config-file is not specified, then the following file is used if it exists:\n\n"
<< "The configuration file name is:\n\n"
<< " " << DefaultConfigFile << "\n\n" << " " << DefaultConfigFile << "\n\n"
<< "If snf-config-file is not specified and the above file doesn't exist, then it is\n"
<< "copied from the following file:\n\n"
<< "If the above file doesn't exist, then it is copied from the following file:\n\n"
<< " " << SampleConfigFile << "\n\n" << " " << SampleConfigFile << "\n\n"
<< "If integration with an MTA is specified, that MTA is started if it isn't running,\n" << "If integration with an MTA is specified, that MTA is started if it isn't running,\n"
<< "or the MTA's configuration is reloaded if it is running.\n\n"; << "or the MTA's configuration is reloaded if it is running.\n\n";
} }
return (NumCommandsFound == 1);
return ( (NumCommandsFound == 1) && CommandLineIsOkay() );
} }
case SetupRepairCommand: case SetupRepairCommand:
CheckAndSetConfigFileName(DefaultConfigFile); // Load the config file name if not specified.
SetConfigFileName(DefaultConfigFile);
CreateDefaultConfigFile(SampleConfigFile); // Create the file if it doesn't exist, CreateDefaultConfigFile(SampleConfigFile); // Create the file if it doesn't exist,
// Set owner and mode in any case. // Set owner and mode in any case.
LoadConfig(); LoadConfig();
case UpdateCredentialsCommand: case UpdateCredentialsCommand:
CheckAndSetConfigFileName(DefaultConfigFile); // Load the config file name if not specified.
SetConfigFileName(DefaultConfigFile);
LoadConfig(); LoadConfig();
LoadInfo(); // Load the file paths. LoadInfo(); // Load the file paths.
LoadSocketInfo(); // Load the socket path. LoadSocketInfo(); // Load the socket path.
case StartSnifferCommand: case StartSnifferCommand:
CheckAndSetConfigFileName(DefaultConfigFile);
SetConfigFileName(DefaultConfigFile);
LoadConfig(); LoadConfig();
LoadInfo(); LoadInfo();
LoadSocketInfo(); LoadSocketInfo();
case StopSnifferCommand: case StopSnifferCommand:
CheckAndSetConfigFileName(DefaultConfigFile);
SetConfigFileName(DefaultConfigFile);
LoadConfig(); LoadConfig();
LoadInfo(); LoadInfo();
LoadSocketInfo(); LoadSocketInfo();

+ 26
- 47
SNFMilterConfig/SNFMilterConfigTests.txt View File



Result: Pass. Result: Pass.


CONFLICT-05: Run with -config=SNFMilter_second.xml -start. Verify
that help message is output, and that SNFMilterConfig takes no action.

Result: Pass.

Setup/Repair functionality Setup/Repair functionality
-------------------------- --------------------------


Result: Pass? Exception thrown (as expected) when attempting to read Result: Pass? Exception thrown (as expected) when attempting to read
configuration file that doesn't exist. configuration file that doesn't exist.


Config file specification
-------------------------

CONF-01: Start with no configuration files, and copy the sample
configuration file to test.xml. Run with "-setup -config=test.xml",
and verify that all configuration files except
/etc/snf-milter/SNFMilter.xml are created.

Result: Pass.

CONF-02: Repeat with -v and verify the same behavior.

Result: Pass.

CONF-03: Repeat with -explain.

Result: Pass.

Credential Functionality Credential Functionality
------------------------ ------------------------


Start/stop functionality with XCI enabled Start/stop functionality with XCI enabled
----------------------------------------- -----------------------------------------


START_STOP_XCI-01: Install default configuration files, and ensure
that SNFMilter is stoped. Create a configuration file
SNFMilter_xci.xml as follows:
START_STOP_XCI-01: Install configuration file SNFMilter_xci.xml with
the following configuration:


1) Enable XCI. 1) Enable XCI.




Do the following, specifying the configuration file SNFMilter_xci.xml: Do the following, specifying the configuration file SNFMilter_xci.xml:


1) Run SNFMilterConfig with "-start", and verify that SNFMilter starts.
1) Run SNFMilterConfig with "-v -start", and verify that SNFMilter
starts.


2) Run SNFMilterConfig with "-start" again and verify that SNFMilter
is not started again.
2) Run SNFMilterConfig with "-start -v" again and verify that
SNFMilter is still running.


3) Run SNFMitlerConfig with "-stop" and verify that SNFMilter stops.
3) Run SNFMitlerConfig with "-stop -v" and verify that SNFMilter
stops.


4) Run SNFMitlerConfig with "-stop" again and verify that SNFMilter
is not stopped again.
4) Run SNFMitlerConfig with "-stop -v" again and verify that
SNFMilter is still stopped.


Result: Pass Result: Pass


START_STOP_XCI-02: Repeat START_STOP_XCI-01 but with "-v" in the command-line.
START_STOP_XCI-02: Repeat START_STOP_XCI-01 but without "-v" in the
command-line.


Result: Pass
Result:


START_STOP_XCI-03: Configure as for START_STOP_XCI-01, and do the following: START_STOP_XCI-03: Configure as for START_STOP_XCI-01, and do the following:


1) Run SNFMilterConfig with "-start -explain". Verify correct 1) Run SNFMilterConfig with "-start -explain". Verify correct
output, and that SNFMilterConfig doesn't start SNFMilter.
output, and that SNFMilter isn't started.


2) Run SNFMilterConfig with "-stop -explain". Verify correct 2) Run SNFMilterConfig with "-stop -explain". Verify correct
output, and that SNFMilterConfig doesn't stop SNFMilter.
output, and that SNFMilter isn't started.


3) Start SNFMilter. 3) Start SNFMilter.


4) Run SNFMilterConfig with "-start -explain". Verify correct 4) Run SNFMilterConfig with "-start -explain". Verify correct
output, and that SNFMilterConfig doesn't start SNFMilter.
output, and that SNFMilter is still running.


5) Run SNFMilterConfig with "-stop -explain". Verify correct 5) Run SNFMilterConfig with "-stop -explain". Verify correct
output, and that SNFMilterConfig doesn't stop SNFMilter.
output, and that SNFMilter is still running.


Result: Pass
Result:


Start/stop functionality with XCI disabled, status.second enabled Start/stop functionality with XCI disabled, status.second enabled
----------------------------------------------------------------- -----------------------------------------------------------------


Do the following, specifying the configuration file SNFMilter_minute.xml: Do the following, specifying the configuration file SNFMilter_minute.xml:


1) Run "SNFMilterConfig -config=SNFMilter_minute.xml -start", and verify that SNFMilter starts.
1) Run "SNFMilterConfig -start -v", and verify that SNFMilter
starts.


2) Run "SNFMilterConfig -config=SNFMilter_minute.xml -start" again
and verify that SNFMilter is not started again.
2) Run "SNFMilterConfig -v -start" again and verify that SNFMilter
is not started again.


3) Run "SNFMilterConfig -config=SNFMilter_minute.xml -stop" and
verify that SNFMilter stops.
3) Run "SNFMilterConfig -v -stop" and verify that SNFMilter stops.


4) Run "SNFMilterConfig -config=SNFMilter_minute.xml -stop" again
and verify that SNFMilter is not stopped again.
4) Run "SNFMilterConfig -stop -v" again and verify that SNFMilter is
not stopped again.


Result: Result:


START_STOP_MIN-02: Repeat START_STOP_MIN-01 but with "-v" in the
START_STOP_MIN-02: Repeat START_STOP_MIN-01 but without "-v" in the
command-line. command-line.


Result: Result:

Loading…
Cancel
Save