Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .github/workflows/csharp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ jobs:
with:
# Full git history is needed to get a proper list of changed files
fetch-depth: 0
persist-credentials: false
- name: Run Super-Linter
uses: github/super-linter@v7
env:
Expand All @@ -40,6 +41,8 @@ jobs:
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
persist-credentials: false
- name: Add msbuild to PATH
uses: microsoft/setup-msbuild@v1
- name: Setup NuGet
Expand Down Expand Up @@ -104,6 +107,8 @@ jobs:
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
persist-credentials: false
- name: Setup .NET
uses: actions/setup-dotnet@v2
with:
Expand All @@ -127,6 +132,8 @@ jobs:
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
persist-credentials: false
- name: Setup .NET
uses: actions/setup-dotnet@v2
with:
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/csharp_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ jobs:
uses: actions/checkout@v4
with:
ref: ${{ needs.variables.outputs.tag }}
persist-credentials: false
- name: Add msbuild to PATH
uses: microsoft/setup-msbuild@v2
- name: Setup NuGet
Expand Down Expand Up @@ -109,6 +110,7 @@ jobs:
uses: actions/checkout@v4
with:
ref: ${{ needs.variables.outputs.tag }}
persist-credentials: false
- name: Setup .NET
uses: actions/setup-dotnet@v4
- name: Restore dependencies
Expand All @@ -131,6 +133,7 @@ jobs:
uses: actions/checkout@v4
with:
ref: ${{ needs.variables.outputs.tag }}
persist-credentials: false
- name: Setup .NET
uses: actions/setup-dotnet@v4
- name: Restore dependencies
Expand All @@ -155,6 +158,7 @@ jobs:
uses: actions/checkout@v4
with:
ref: ${{ needs.variables.outputs.tag }}
persist-credentials: false
- name: Install mono
run: |
sudo apt update
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/integration_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ jobs:
repository: 'optimizely/ci-helper-tools'
path: 'home/runner/ci-helper-tools'
ref: 'master'
# The token is only needed for this checkout. Later steps pass it explicitly via env
# and do not use git, so do not leave it in .git/config.
persist-credentials: false
- name: set SDK Branch if PR
env:
HEAD_REF: ${{ github.head_ref }}
Expand Down
6 changes: 6 additions & 0 deletions OptimizelySDK.DemoApp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,9 @@ Finally, the "Messages" page lists the logs generated by Optimizely SDK in chron

* Developer Docs: https://developers.optimizely.com/x/solutions/sdks/reference/index.html?language=csharp
* Questions? Shoot us an email at [email protected]

## Third-party code

This demo app is not part of the published SDK package. It contains third-party libraries copied into `Scripts` (jQuery, jQuery Validation, Bootstrap, Modernizr, Respond.js). Security scanners report findings in them, such as `innerHTML` or non-literal regular expressions. These are the libraries' own code, run only in this demo app, and are not changed here. To update a library, update its package in `packages.config` and replace the files in `Scripts`.

`log4net` stays at 2.0.13. The advisory for versions before 3.3.0 is about `XmlLayout`, and this app only uses `PatternLayout` (see `Log4Net.config`). The fixed log4net 3.x needs .NET Framework 4.6.2 or newer, and this app targets 4.5.
4 changes: 2 additions & 2 deletions OptimizelySDK.DemoApp/Scripts/jquery.validate-vsdoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* intended to be used only for design-time IntelliSense. Please use the
* standard jQuery library for all production use.

* Comment version: 1.19.5
* Comment version: 1.20.1
*/

/*
Expand All @@ -15,7 +15,7 @@
* for informational purposes only and are not the license terms under
* which Microsoft distributed this file.
*
* jQuery Validation Plugin - v1.19.5 - 12/5/2016
* jQuery Validation Plugin - v1.20.1 - 12/5/2016
* https://github.com/jzaefferer/jquery-validation
* Copyright (c) 2013 Jörn Zaefferer; Licensed MIT
*
Expand Down
90 changes: 66 additions & 24 deletions OptimizelySDK.DemoApp/Scripts/jquery.validate.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/*!
* jQuery Validation Plugin v1.19.5
* jQuery Validation Plugin v1.21.0
*
* https://jqueryvalidation.org/
*
* Copyright (c) 2022 Jörn Zaefferer
* Copyright (c) 2024 Jörn Zaefferer
* Released under the MIT license
*/
(function( factory ) {
Expand Down Expand Up @@ -293,6 +293,7 @@ $.extend( $.validator, {
onsubmit: true,
ignore: ":hidden",
ignoreTitle: false,
customElements: [],
onfocusin: function( element ) {
this.lastActive = element;

Expand Down Expand Up @@ -440,17 +441,17 @@ $.extend( $.validator, {
settings[ eventType ].call( validator, this, event );
}
}

var focusListeners = [ ":text", "[type='password']", "[type='file']", "select", "textarea", "[type='number']", "[type='search']",
"[type='tel']", "[type='url']", "[type='email']", "[type='datetime']", "[type='date']", "[type='month']",
"[type='week']", "[type='time']", "[type='datetime-local']", "[type='range']", "[type='color']",
"[type='radio']", "[type='checkbox']", "[contenteditable]", "[type='button']" ];
var clickListeners = [ "select", "option", "[type='radio']", "[type='checkbox']" ];
$( this.currentForm )
.on( "focusin.validate focusout.validate keyup.validate",
":text, [type='password'], [type='file'], select, textarea, [type='number'], [type='search'], " +
"[type='tel'], [type='url'], [type='email'], [type='datetime'], [type='date'], [type='month'], " +
"[type='week'], [type='time'], [type='datetime-local'], [type='range'], [type='color'], " +
"[type='radio'], [type='checkbox'], [contenteditable], [type='button']", delegate )
.on( "focusin.validate focusout.validate keyup.validate", focusListeners.concat( this.settings.customElements ).join( ", " ), delegate )

// Support: Chrome, oldIE
// "select" is provided as event.target when clicking a option
.on( "click.validate", "select, option, [type='radio'], [type='checkbox']", delegate );
.on( "click.validate", clickListeners.concat( this.settings.customElements ).join( ", " ), delegate );

if ( this.settings.invalidHandler ) {
$( this.currentForm ).on( "invalid-form.validate", this.settings.invalidHandler );
Expand Down Expand Up @@ -647,11 +648,12 @@ $.extend( $.validator, {

elements: function() {
var validator = this,
rulesCache = {};
rulesCache = {},
selectors = [ "input", "select", "textarea", "[contenteditable]" ];

// Select all valid inputs inside the form (no submit or reset buttons)
return $( this.currentForm )
.find( "input, select, textarea, [contenteditable]" )
.find( selectors.concat( this.settings.customElements ).join( ", " ) )
.not( ":submit, :reset, :image, :disabled" )
.not( this.settings.ignore )
.filter( function() {
Expand Down Expand Up @@ -774,6 +776,9 @@ $.extend( $.validator, {
val = this.elementValue( element ),
result, method, rule, normalizer;

// Abort any pending Ajax request from a previous call to this method.
this.abortRequest( element );

// Prioritize the local normalizer defined for this element over the global one
// if the former exists, otherwise user the global one in case it exists.
if ( typeof rules.normalizer === "function" ) {
Expand Down Expand Up @@ -960,14 +965,23 @@ $.extend( $.validator, {
error.removeClass( this.settings.validClass ).addClass( this.settings.errorClass );

// Replace message on existing label
error.html( message );
if ( this.settings && this.settings.escapeHtml ) {
error.text( message || "" );
} else {
error.html( message || "" );
}
} else {

// Create error element
error = $( "<" + this.settings.errorElement + ">" )
.attr( "id", elementID + "-error" )
.addClass( this.settings.errorClass )
.html( message || "" );
.addClass( this.settings.errorClass );

if ( this.settings && this.settings.escapeHtml ) {
error.text( message || "" );
} else {
error.html( message || "" );
}

// Maintain reference to the element to be placed into the DOM
place = error;
Expand Down Expand Up @@ -1113,6 +1127,10 @@ $.extend( $.validator, {
return !$.validator.methods.required.call( this, val, element ) && "dependency-mismatch";
},

elementAjaxPort: function( element ) {
return "validate" + element.name;
},

startRequest: function( element ) {
if ( !this.pending[ element.name ] ) {
this.pendingRequest++;
Expand Down Expand Up @@ -1148,6 +1166,25 @@ $.extend( $.validator, {
}
},

abortRequest: function( element ) {
var port;

if ( this.pending[ element.name ] ) {
port = this.elementAjaxPort( element );
$.ajaxAbort( port );

this.pendingRequest--;

// Sometimes synchronization fails, make sure pendingRequest is never < 0
if ( this.pendingRequest < 0 ) {
this.pendingRequest = 0;
}

delete this.pending[ element.name ];
$( element ).removeClass( this.settings.pendingClass );
}
},

previousValue: function( element, method ) {
method = typeof method === "string" && method || "remote";

Expand Down Expand Up @@ -1466,7 +1503,7 @@ $.extend( $.validator, {

// https://jqueryvalidation.org/number-method/
number: function( value, element ) {
return this.optional( element ) || /^(?:-?\d+|-?\d{1,3}(?:,\d{3})+)?(?:\.\d+)?$/.test( value );
return this.optional( element ) || /^(?:-?\d+|-?\d{1,3}(?:,\d{3})+)?(?:-?\.\d+)?$/.test( value );
},

// https://jqueryvalidation.org/digits-method/
Expand Down Expand Up @@ -1577,18 +1614,19 @@ $.extend( $.validator, {

param = typeof param === "string" && { url: param } || param;
optionDataString = $.param( $.extend( { data: value }, param.data ) );
if ( previous.old === optionDataString ) {
if ( previous.valid !== null && previous.old === optionDataString ) {
return previous.valid;
}

previous.old = optionDataString;
previous.valid = null;
validator = this;
this.startRequest( element );
data = {};
data[ element.name ] = value;
$.ajax( $.extend( true, {
mode: "abort",
port: "validate" + element.name,
port: this.elementAjaxPort( element ),
dataType: "json",
data: data,
context: validator.currentForm,
Expand All @@ -1599,7 +1637,6 @@ $.extend( $.validator, {
validator.settings.messages[ element.name ][ method ] = previous.originalMessage;
if ( valid ) {
submitted = validator.formSubmitted;
validator.resetInternals();
validator.toHide = validator.errorsFor( element );
validator.formSubmitted = submitted;
validator.successList.push( element );
Expand All @@ -1624,6 +1661,7 @@ $.extend( $.validator, {

// Ajax mode: abort
// usage: $.ajax({ mode: "abort"[, port: "uniqueport"]});
// $.ajaxAbort( port );
// if mode:"abort" is used, the previous request on that port (port can be undefined) is aborted via XMLHttpRequest.abort()

var pendingRequests = {},
Expand All @@ -1634,9 +1672,7 @@ if ( $.ajaxPrefilter ) {
$.ajaxPrefilter( function( settings, _, xhr ) {
var port = settings.port;
if ( settings.mode === "abort" ) {
if ( pendingRequests[ port ] ) {
pendingRequests[ port ].abort();
}
$.ajaxAbort( port );
pendingRequests[ port ] = xhr;
}
} );
Expand All @@ -1648,14 +1684,20 @@ if ( $.ajaxPrefilter ) {
var mode = ( "mode" in settings ? settings : $.ajaxSettings ).mode,
port = ( "port" in settings ? settings : $.ajaxSettings ).port;
if ( mode === "abort" ) {
if ( pendingRequests[ port ] ) {
pendingRequests[ port ].abort();
}
$.ajaxAbort( port );
pendingRequests[ port ] = ajax.apply( this, arguments );
return pendingRequests[ port ];
}
return ajax.apply( this, arguments );
};
}

// Abort the previous request without sending a new one
$.ajaxAbort = function( port ) {
if ( pendingRequests[ port ] ) {
pendingRequests[ port ].abort();
delete pendingRequests[ port ];
}
};
return $;
}));
6 changes: 3 additions & 3 deletions OptimizelySDK.DemoApp/Scripts/jquery.validate.min.js

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions OptimizelySDK.DemoApp/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<package id="Antlr" version="3.4.1.9004" targetFramework="net45" />
<package id="bootstrap" version="5.3.0" targetFramework="net45" />
<package id="jQuery" version="3.7.0" targetFramework="net45" />
<package id="jQuery.Validation" version="1.19.5" targetFramework="net45" />
<package id="jQuery.Validation" version="1.21.0" targetFramework="net45" />
<package id="log4net" version="2.0.13" targetFramework="net45" />
<package id="Microsoft.AspNet.Mvc" version="5.2.3" targetFramework="net45" />
<package id="Microsoft.AspNet.Razor" version="3.2.3" targetFramework="net45" />
Expand All @@ -17,7 +17,6 @@
<package id="murmurhash-signed" version="1.0.2" targetFramework="net45" />
<package id="Newtonsoft.Json" version="13.0.2" targetFramework="net45" />
<package id="NJsonSchema" version="10.8.0" targetFramework="net45" />
<package id="Optimizely.SDK" version="3.2.0" targetFramework="net45" />
<package id="popper.js" version="1.12.9" targetFramework="net45" />
<package id="Respond" version="1.2.0" targetFramework="net45" />
<package id="WebGrease" version="1.5.2" targetFramework="net45" />
Expand Down
21 changes: 21 additions & 0 deletions OptimizelySDK.Tests/CmabTests/DefaultCmabServiceTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,27 @@ public void SameUserRuleCombinationUsesConsistentLock()
Assert.AreEqual(index2, index3, "Same user/rule should always use same lock");
}

[Test]
public void HashAttributesIsSha256OfAttributesSortedByKey()
{
var inOneOrder = new UserAttributes(new Dictionary<string, object>
{
{ "a", 1 },
{ "b", "x" },
});
var inOtherOrder = new UserAttributes(new Dictionary<string, object>
{
{ "b", "x" },
{ "a", 1 },
});

// SHA256 of the text {"a":1,"b":"x"}
const string expected =
"ecf9e98ec0641e23113ff3ce8bdc78d0ddd249886517fd4a7f68cc83d4e65667";
Assert.AreEqual(expected, DefaultCmabService.HashAttributes(inOneOrder));
Assert.AreEqual(expected, DefaultCmabService.HashAttributes(inOtherOrder));
}

[Test]
public void LockStripingDistribution()
{
Expand Down
23 changes: 23 additions & 0 deletions OptimizelySDK.Tests/ConfigTest/HttpProjectConfigManagerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,29 @@ public void TestHttpConfigManagerRetrieveProjectConfigBySDKKey()
httpManager.Dispose();
}

[Test]
public void TestHttpConfigManagerEscapesSdkKeyInDatafileUrl()
{
var t = MockSendAsync(TestData.Datafile);

var httpManager = new HttpProjectConfigManager.Builder().WithSdkKey("key?x=1#frag")
.WithLogger(LoggerMock.Object)
.WithPollingInterval(TimeSpan.FromMilliseconds(1000))
.WithBlockingTimeoutPeriod(TimeSpan.FromMilliseconds(500))
.WithStartByDefault()
.Build(true);

t.Wait(1000);
// "?" and "#" in the key must stay part of the path, not start a query or a fragment.
HttpClientMock.Verify(_ => _.SendAsync(
It.Is<HttpRequestMessage>(requestMessage =>
requestMessage.RequestUri.Host == "cdn.optimizely.com" &&
requestMessage.RequestUri.Query == "" &&
requestMessage.RequestUri.Fragment == ""
)));
httpManager.Dispose();
}

[Test]
public void TestHttpConfigManagerRetrieveProjectConfigByFormat()
{
Expand Down
Loading
Loading