Skip to content

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

Merged
merged 6 commits into from
Sep 6, 2018

Conversation

msohailhussain
Copy link
Contributor

No description provided.

[Test]
public void TestCreateThrowsWithUnsopportedDatafileVersion()
{
var unsupportedConfig = ProjectConfig.Create(TestData.Datafile, null, null);
Copy link
Contributor Author

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.

@@ -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);
Copy link
Contributor Author

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.

Copy link
Contributor

Choose a reason for hiding this comment

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

Done.

Copy link
Contributor

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

if (configData == null)
throw new ConfigParseException("Unable to parse null datafile.");

if (configData.Length == 0)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

use string.isnullorempty

@@ -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);
Copy link
Contributor

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


var config = JsonConvert.DeserializeObject<ProjectConfig>(configData);

if (SupportedVersions.TrueForAll((obj) => !(((int)obj).ToString() == config.Version)))
Copy link
Contributor

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);
Copy link
Contributor

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

Copy link
Contributor

@mikeproeng37 mikeproeng37 left a 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()
Copy link
Contributor

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

Copy link
Contributor

@mikeproeng37 mikeproeng37 left a 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

Copy link
Contributor

@mikeproeng37 mikeproeng37 left a comment

Choose a reason for hiding this comment

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

lgtm

@mikeproeng37 mikeproeng37 merged commit 108067d into master Sep 6, 2018
@mfahadahmed mfahadahmed deleted the sohail/rejectunsupportedversion branch September 17, 2018 08:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants