-
Notifications
You must be signed in to change notification settings - Fork 20
fix(datafile-parsing): Prevent newer versions datafile #101
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
Conversation
…has version other than supported versions
[Test] | ||
public void TestCreateThrowsWithUnsopportedDatafileVersion() | ||
{ | ||
var unsupportedConfig = ProjectConfig.Create(TestData.Datafile, null, null); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please change this testcase. First Deserialize into JSON object and make a change, serialize into JSON string and passing to ProjectConfig. Don't serialize & deserialize project config object.
OptimizelySDK/Optimizely.cs
Outdated
@@ -111,9 +112,15 @@ public class Optimizely : IOptimizely | |||
IsValid = true; | |||
DecisionService = new DecisionService(Bucketer, ErrorHandler, Config, userProfileService, Logger); | |||
} | |||
catch (ConfigParseException configException) | |||
{ | |||
Logger.Log(LogLevel.ERROR, configException.Message); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add unit test in optimizely class and expect handleerror is called.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's consolidate these two catches into one and handle the logging based on the type of the exception. We can avoid duplicating some of the code, like passing the error to the error handler
OptimizelySDK/ProjectConfig.cs
Outdated
if (configData == null) | ||
throw new ConfigParseException("Unable to parse null datafile."); | ||
|
||
if (configData.Length == 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use string.isnullorempty
OptimizelySDK/Optimizely.cs
Outdated
@@ -111,9 +112,15 @@ public class Optimizely : IOptimizely | |||
IsValid = true; | |||
DecisionService = new DecisionService(Bucketer, ErrorHandler, Config, userProfileService, Logger); | |||
} | |||
catch (ConfigParseException configException) | |||
{ | |||
Logger.Log(LogLevel.ERROR, configException.Message); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's consolidate these two catches into one and handle the logging based on the type of the exception. We can avoid duplicating some of the code, like passing the error to the error handler
OptimizelySDK/ProjectConfig.cs
Outdated
|
||
var config = JsonConvert.DeserializeObject<ProjectConfig>(configData); | ||
|
||
if (SupportedVersions.TrueForAll((obj) => !(((int)obj).ToString() == config.Version))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please don't use the generic variable name obj
. Instead go for supportVersion
[Test] | ||
public void TestCreateThrowsWithUnsupportedDatafileVersion() | ||
{ | ||
var unsupportedConfig = JsonConvert.DeserializeObject<ProjectConfig>(TestData.Datafile); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please create a separate mock unsupported datafile and load it into this test case
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Almost there. Just one more nit
} | ||
|
||
[Test] | ||
public void TestErrorHandlingWithInvalidConfigVersion() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please split these up into three separate unit tests. Makes it easier to read and determine what actually failed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please fix remaining issue
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
No description provided.