forked from halfgaar/FlashMQ
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The config parser was rather liberal in what it accepted. For example these three settings would all be accepted and interpreted as 180 seconds: expire_sessions_after_seconds 180s expire_sessions_after_seconds 180h expire_sessions_after_seconds 180 hours This changeset will cause these things to get rejected.
- Loading branch information
Showing
6 changed files
with
201 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
#include "maintests.h" | ||
#include "testhelpers.h" | ||
#include "conffiletemp.h" | ||
#include "exceptions.h" | ||
|
||
void MainTests::test_loading_second_value() | ||
{ | ||
/* this is expected to work*/ | ||
{ | ||
ConfFileTemp config; | ||
config.writeLine("bridge {"); | ||
config.writeLine(" address localhost"); | ||
config.writeLine(" publish send/this 1"); // this value should be different from the default (0) | ||
config.writeLine("}"); | ||
config.closeFile(); | ||
|
||
ConfigFileParser *parser = new ConfigFileParser(config.getFilePath()); | ||
parser->loadFile(false); | ||
|
||
Settings settings = parser->getSettings(); | ||
|
||
std::shared_ptr<BridgeConfig> bridge = settings.stealBridges().front(); | ||
|
||
FMQ_COMPARE(bridge->publishes[0].topic, "send/this"); | ||
FMQ_COMPARE(bridge->publishes[0].qos, (uint8_t)1); | ||
} | ||
|
||
/* this is expecte to fail because "address" doesn't take a second value */ | ||
{ | ||
ConfFileTemp config; | ||
config.writeLine("bridge {"); | ||
config.writeLine(" address localhost thisisnotok"); | ||
config.writeLine(" publish send/this 1"); | ||
config.writeLine("}"); | ||
config.closeFile(); | ||
|
||
ConfigFileParser *parser = new ConfigFileParser(config.getFilePath()); | ||
try | ||
{ | ||
parser->loadFile(false); | ||
FMQ_FAIL("The config parser is too liberal"); | ||
} | ||
catch (ConfigFileException ex) | ||
{ | ||
/* Excellent, what we wanted */ | ||
} | ||
} | ||
} | ||
|
||
void MainTests::test_parsing_numbers() | ||
{ | ||
/* this should work: 180 */ | ||
{ | ||
ConfFileTemp config; | ||
config.writeLine("expire_sessions_after_seconds 180"); | ||
config.closeFile(); | ||
|
||
ConfigFileParser *parser = new ConfigFileParser(config.getFilePath()); | ||
parser->loadFile(false); | ||
|
||
Settings settings = parser->getSettings(); | ||
|
||
FMQ_COMPARE(settings.expireSessionsAfterSeconds, (uint32_t)180); | ||
} | ||
|
||
/* this should fail: 180days */ | ||
{ | ||
ConfFileTemp config; | ||
config.writeLine("expire_sessions_after_seconds 180days"); | ||
config.closeFile(); | ||
|
||
ConfigFileParser *parser = new ConfigFileParser(config.getFilePath()); | ||
try | ||
{ | ||
parser->loadFile(false); | ||
FMQ_FAIL("The parser was too liberal"); | ||
} | ||
catch (ConfigFileException) | ||
{ | ||
/* Good! This is where we want to end up in */ | ||
} | ||
} | ||
|
||
/* this should also fail: 180 days */ | ||
{ | ||
ConfFileTemp config; | ||
config.writeLine("expire_sessions_after_seconds 180 days"); | ||
config.closeFile(); | ||
|
||
ConfigFileParser *parser = new ConfigFileParser(config.getFilePath()); | ||
try | ||
{ | ||
parser->loadFile(false); | ||
FMQ_FAIL("The parser was too liberal"); | ||
} | ||
catch (ConfigFileException) | ||
{ | ||
/* Good! This is where we want to end up in */ | ||
} | ||
} | ||
|
||
/* Last one that should fail: 180 days and a bit */ | ||
{ | ||
ConfFileTemp config; | ||
config.writeLine("expire_sessions_after_seconds 180 days and a bit more"); | ||
config.closeFile(); | ||
|
||
ConfigFileParser *parser = new ConfigFileParser(config.getFilePath()); | ||
try | ||
{ | ||
parser->loadFile(false); | ||
FMQ_FAIL("The parser was too liberal"); | ||
} | ||
catch (ConfigFileException) | ||
{ | ||
/* Good! This is where we want to end up in */ | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.