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

[FSSDK-9533] Log error & reject on track event with null, empty or whitespace event key #362

Closed
wants to merge 13 commits into from

Conversation

mikechu-optimizely
Copy link
Contributor

Summary

  • Prevent track events from being sent without a name/key
  • Update method docs to highlight that this param must not be whitespace, null, or empty string values

Test plan

  • Updated existing tests to check for invalid event keys
  • All other existing tests should also pass

Issues

  • FSSDK-9533

@mikechu-optimizely
Copy link
Contributor Author

This will need to be part of a cherry-pick and release for a v3.11.4 along with #361

@mikechu-optimizely mikechu-optimizely marked this pull request as ready for review July 25, 2023 17:30
@mikechu-optimizely mikechu-optimizely requested a review from a team as a code owner July 25, 2023 17:30
Copy link
Contributor

@jaeopt jaeopt left a comment

Choose a reason for hiding this comment

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

Can we create a test case to reproduce the suspected failure cases first? The current solution looks fine and also validated with FSC tests as well.

Comment on lines -349 to -351
var config = ProjectConfigManager?.GetConfig();

if (config == null)
Copy link
Contributor

Choose a reason for hiding this comment

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

can we remove this config ready check?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If we're going to call .GetEvent(eventKey) later (L365 below on this older version) to check if the provided eventKey is in the datafile, I think we'd probably still need this check, right?

Comment on lines -365 to -367
var eevent = config.GetEvent(eventKey);

if (eevent.Key == null)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think these 2 lines will filter out null or empty eventKey cases.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think I see what you're talking about: The eventKey must be in the datafile before it can be tracked anyway, regardless of whether it's not null, empty, or whitespace.

@@ -338,54 +339,60 @@ private bool ValidateInputs(string datafile, bool skipJsonValidation)
/// <summary>
/// Sends conversion event to Optimizely.
/// </summary>
/// <param name="eventKey">Event key representing the event which needs to be recorded</param>
/// <param name="eventKey">Event key representing the event (must not be null, empty, or whitespace)</param>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I guess this should read: "Event key representing the event in the datafile which must not be null, empty, or whitespace"

var config = ProjectConfigManager?.GetConfig();

if (config == null)
if (eventKey == null || Regex.IsMatch(eventKey, @"^\s*$"))
Copy link
Contributor Author

@mikechu-optimizely mikechu-optimizely Jul 26, 2023

Choose a reason for hiding this comment

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

I added an earlier eventKey check since it's cheaper before digging into the ProjectConfig to see if the eventKey is present in the datafile since it's required per the docs.

@mikechu-optimizely mikechu-optimizely deleted the mike/track-event-event-key branch November 20, 2023 21:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants