Skip to content
9 changes: 6 additions & 3 deletions BrowserCache/SessionStorageCacheTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ private void RunTest(WebDriver driver, bool enableCookies)
ClientServerUrl,
_app.BaseUrl.ToString(),
BuildPage(enableCookies),
ExampleApps.JsonEndpointPath,
ExampleApps.JsonEndpointPaths,
clientServerTokenSource.Token);
clientServer = serverListener.Listener;
clientHttpServer = serverListener.Server;
Expand Down Expand Up @@ -265,9 +265,12 @@ private static void AssertSameResults(

private int CountJsonPosts()
{
var expected = $"POST {ExampleApps.JsonEndpointPath}";
var expected = ExampleApps.JsonEndpointPaths
.Select(p => $"POST {p}")
.ToList();
return clientHttpServer.RequestLog
.Count(r => string.Equals(r, expected, StringComparison.OrdinalIgnoreCase));
.Count(r => expected.Any(e => string.Equals(
r, e, StringComparison.OrdinalIgnoreCase)));
}

private static List<string> GetSessionStorageKeys(IJavaScriptExecutor js)
Expand Down
26 changes: 25 additions & 1 deletion Examples/ExampleApps.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,25 @@ public static class ExampleApps
? descriptor.JsonEndpointPath
: "/51dpipeline/json";

/// <summary>
/// Every path the selected language's client-side script may post to,
/// being <see cref="JsonEndpointPath"/> and any older path the
/// language still answers.
/// </summary>
public static IReadOnlyList<string> JsonEndpointPaths
{
get
{
var paths = new List<string> { JsonEndpointPath };
if (Descriptors.TryGetValue(SelectedLang, out var descriptor)
&& descriptor.AlternativeJsonEndpointPaths != null)
{
paths.AddRange(descriptor.AlternativeJsonEndpointPaths);
}
return paths;
}
}

/// <summary>
/// Element the selected language's page renders its client-side results
/// into. Read from the descriptor so it is available for the CI case
Expand Down Expand Up @@ -219,8 +238,13 @@ public static ExampleAppOptions BuildOptions(
StartupTimeoutSeconds: 180,
BuildEnv: o => new Dictionary<string, string>
{
// The example reads the _51DEGREES_ names. Released
// versions of it read the two older names, so both
// are set until every language has released.
["_51DEGREES_RESOURCE_KEY"] = o.ResourceKey,
["SUPER_RESOURCE_KEY"] = o.ResourceKey,
// the endpoint must include the api/v4 path
["_51DEGREES_CLOUD_ENDPOINT"] = new Uri(o.CloudEndpoint, "api/v4/").ToString(),
["FIFTYONE_CLOUD_ENDPOINT"] = new Uri(o.CloudEndpoint, "api/v4/").ToString(),
["ASPNETCORE_URLS"] = $"http://localhost:{o.Port}",
// run on a newer .NET runtime if the exact one isn't installed
Expand All @@ -245,7 +269,7 @@ public static ExampleAppOptions BuildOptions(
BuildArgs: new[] { "-pl", "web/getting-started.cloud", "-am", "package", "-DskipTests" },
RunArtifactGlob: "web/getting-started.cloud/target/*-jar-with-dependencies.jar",
BuildTimeoutSeconds: 600,
JsonEndpointPath: "/51Degrees.core.json",
AlternativeJsonEndpointPaths: new[] { "/51Degrees.core.json" },
// the java page renders the client-side results into its
// Apple detection section rather than the shared container
ClientResultsElementId: "apple-detection"),
Expand Down
20 changes: 20 additions & 0 deletions Examples/ExampleAppsTests.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;

Expand Down Expand Up @@ -74,5 +76,23 @@ public void Descriptors_Rust_BuildsAndRunsWithCargo()
Assert.IsTrue(rust.Args.Contains("dd-web-getting-started-cloud"),
"run args should target the cloud getting-started web binary");
}

[TestMethod]
public void Descriptors_Dotnet_SetsTheUnderscoreNames()
{
var dotnet = ExampleApps.Descriptors["dotnet"];
var env = dotnet.BuildEnv(new ExampleAppOptions(
Port: 5123,
CloudEndpoint: new Uri("https://cloud.example.test/"),
ResourceKey: "key",
ExtraEnv: new Dictionary<string, string>()));
Assert.AreEqual("key", env["_51DEGREES_RESOURCE_KEY"],
"the example reads the resource key from this name");
Assert.AreEqual(
"https://cloud.example.test/api/v4/",
env["_51DEGREES_CLOUD_ENDPOINT"],
"the example reads the endpoint, with its api/v4 path, "
+ "from this name");
}
}
}
10 changes: 8 additions & 2 deletions Examples/ExampleDescriptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,12 @@ namespace FiftyOne.Pipeline.Cloud.SeleniumTests.Examples
/// integration picks its own, so a test that proxies or counts those
/// requests has to ask the descriptor rather than assume one: dotnet and
/// rust use the default, java uses /51Degrees.core.json, and node, python
/// and php use /json.
/// and php use /json, and java uses the default and still answers the
/// older /51Degrees.core.json.
/// </param>
/// <param name="AlternativeJsonEndpointPaths">
/// Older paths the integration still answers, so a test accepts a build
/// whose script uses either.
/// </param>
/// <param name="ClientResultsElementId">
/// Id of the element the example's page asks the shared examples helper to
Expand All @@ -44,5 +49,6 @@ public sealed record ExampleDescriptor(
string RunArtifactGlob = null,
int BuildTimeoutSeconds = 0,
string JsonEndpointPath = "/51dpipeline/json",
string ClientResultsElementId = "content");
string ClientResultsElementId = "content",
IReadOnlyList<string> AlternativeJsonEndpointPaths = null);
}
22 changes: 13 additions & 9 deletions TestsCommon/Helpers/TestHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,28 +103,32 @@ public static ServerListener ReverseProxyListener(
/// Creates an HttpListener that serves <paramref name="pageData"/>
/// for page paths and proxies the 51Degrees script and pipeline
/// endpoints to <paramref name="exampleUrl"/> without caching.
/// <paramref name="jsonEndpointPath"/> is the path the client-side
/// script posts refreshed evidence to, which differs per web
/// integration, so the caller supplies the one its example uses.
/// <paramref name="jsonEndpointPaths"/> are the paths the client-side
/// script may post refreshed evidence to, which differ per web
/// integration, so the caller supplies the ones its example uses.
/// </summary>
public static ServerListener ExampleProxyListener(
string clientUrl,
string exampleUrl,
string pageData,
string jsonEndpointPath,
IEnumerable<string> jsonEndpointPaths,
CancellationToken token)
{
var listener = new HttpListener();
listener.Prefixes.Add(clientUrl);
listener.Start();

var routes = new Dictionary<string, string>
{
["/51Degrees.core.js"] = exampleUrl,
};
foreach (var path in jsonEndpointPaths)
{
routes[path] = exampleUrl;
}
var server = new HttpServer(listener, pageData)
{
ProxyRoutes = new Dictionary<string, string>
{
["/51Degrees.core.js"] = exampleUrl,
[jsonEndpointPath] = exampleUrl,
},
ProxyRoutes = routes,
ProxiedHeaderOverrides = new Dictionary<string, string>
{
["Cache-Control"] = "no-store",
Expand Down
Loading